Fixes treeshaking on windows (#272899)

This commit is contained in:
Henning Dieterichs
2025-10-23 15:38:06 +02:00
committed by GitHub
parent e5e1fca76c
commit 5e18e088a9
4 changed files with 24 additions and 6 deletions

View File

@@ -5,9 +5,14 @@
import ts from 'typescript';
import fs from 'node:fs';
import { normalize } from 'node:path';
export type IFileMap = Map</*fileName*/ string, string>;
function normalizePath(filePath: string): string {
return normalize(filePath);
}
/**
* A TypeScript language service host
*/
@@ -36,6 +41,8 @@ export class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
return '1';
}
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
fileName = normalizePath(fileName);
if (this.topLevelFiles.has(fileName)) {
return this.ts.ScriptSnapshot.fromString(this.topLevelFiles.get(fileName)!);
} else {
@@ -52,12 +59,16 @@ export class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
return this.ts.getDefaultLibFilePath(options);
}
readFile(path: string, encoding?: string): string | undefined {
path = normalizePath(path);
if (this.topLevelFiles.get(path)) {
return this.topLevelFiles.get(path);
}
return ts.sys.readFile(path, encoding);
}
fileExists(path: string): boolean {
path = normalizePath(path);
if (this.topLevelFiles.has(path)) {
return true;
}