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

@@ -71,16 +71,16 @@ function createTypeScriptLanguageService(ts, options) {
// Add entrypoints
options.entryPoints.forEach(entryPoint => {
const filePath = path_1.default.join(options.sourcesRoot, entryPoint);
FILES.set(filePath, fs_1.default.readFileSync(filePath).toString());
FILES.set(path_1.default.normalize(filePath), fs_1.default.readFileSync(filePath).toString());
});
// Add fake usage files
options.inlineEntryPoints.forEach((inlineEntryPoint, index) => {
FILES.set(path_1.default.join(options.sourcesRoot, `inlineEntryPoint.${index}.ts`), inlineEntryPoint);
FILES.set(path_1.default.normalize(path_1.default.join(options.sourcesRoot, `inlineEntryPoint.${index}.ts`)), inlineEntryPoint);
});
// Add additional typings
options.typings.forEach((typing) => {
const filePath = path_1.default.join(options.sourcesRoot, typing);
FILES.set(filePath, fs_1.default.readFileSync(filePath).toString());
FILES.set(path_1.default.normalize(filePath), fs_1.default.readFileSync(filePath).toString());
});
const basePath = path_1.default.join(options.sourcesRoot, '..');
const compilerOptions = ts.convertCompilerOptionsFromJson(options.compilerOptions, basePath).options;

View File

@@ -112,18 +112,18 @@ function createTypeScriptLanguageService(ts: typeof import('typescript'), option
// Add entrypoints
options.entryPoints.forEach(entryPoint => {
const filePath = path.join(options.sourcesRoot, entryPoint);
FILES.set(filePath, fs.readFileSync(filePath).toString());
FILES.set(path.normalize(filePath), fs.readFileSync(filePath).toString());
});
// Add fake usage files
options.inlineEntryPoints.forEach((inlineEntryPoint, index) => {
FILES.set(path.join(options.sourcesRoot, `inlineEntryPoint.${index}.ts`), inlineEntryPoint);
FILES.set(path.normalize(path.join(options.sourcesRoot, `inlineEntryPoint.${index}.ts`)), inlineEntryPoint);
});
// Add additional typings
options.typings.forEach((typing) => {
const filePath = path.join(options.sourcesRoot, typing);
FILES.set(filePath, fs.readFileSync(filePath).toString());
FILES.set(path.normalize(filePath), fs.readFileSync(filePath).toString());
});
const basePath = path.join(options.sourcesRoot, '..');

View File

@@ -10,6 +10,10 @@ exports.TypeScriptLanguageServiceHost = void 0;
*--------------------------------------------------------------------------------------------*/
const typescript_1 = __importDefault(require("typescript"));
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = require("node:path");
function normalizePath(filePath) {
return (0, node_path_1.normalize)(filePath);
}
/**
* A TypeScript language service host
*/
@@ -39,6 +43,7 @@ class TypeScriptLanguageServiceHost {
return '1';
}
getScriptSnapshot(fileName) {
fileName = normalizePath(fileName);
if (this.topLevelFiles.has(fileName)) {
return this.ts.ScriptSnapshot.fromString(this.topLevelFiles.get(fileName));
}
@@ -56,12 +61,14 @@ class TypeScriptLanguageServiceHost {
return this.ts.getDefaultLibFilePath(options);
}
readFile(path, encoding) {
path = normalizePath(path);
if (this.topLevelFiles.get(path)) {
return this.topLevelFiles.get(path);
}
return typescript_1.default.sys.readFile(path, encoding);
}
fileExists(path) {
path = normalizePath(path);
if (this.topLevelFiles.has(path)) {
return true;
}

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;
}