Skip to content

Commit f6d6195

Browse files
committed
fix: 🐛 typescript imports on windows
1 parent cfe6dcb commit f6d6195

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

Diff for: src/transformers/typescript.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,34 @@ function compileFileFromMemory(
8787
let map;
8888

8989
const realHost = ts.createCompilerHost(compilerOptions, true);
90-
const dummyFilePath = filename;
90+
const dummyFileName = ts.sys.resolvePath(filename);
91+
92+
const isDummyFile = (fileName: string) => ts.sys.resolvePath(fileName) === dummyFileName
9193

9294
const host: ts.CompilerHost = {
93-
fileExists: filePath =>
94-
filePath === dummyFilePath || realHost.fileExists(filePath),
95-
getCanonicalFileName: fileName => realHost.getCanonicalFileName(fileName),
95+
fileExists: fileName =>
96+
isDummyFile(fileName) || realHost.fileExists(fileName),
97+
getCanonicalFileName: fileName => isDummyFile(fileName)
98+
? ts.sys.useCaseSensitiveFileNames
99+
? fileName
100+
: fileName.toLowerCase()
101+
: realHost.getCanonicalFileName(fileName),
96102
getSourceFile: (
97103
fileName,
98104
languageVersion,
99105
onError,
100106
shouldCreateNewSourceFile,
101107
) =>
102-
fileName === dummyFilePath
103-
? ts.createSourceFile(dummyFilePath, code, languageVersion)
108+
isDummyFile(fileName)
109+
? ts.createSourceFile(dummyFileName, code, languageVersion)
104110
: realHost.getSourceFile(
105-
fileName,
106-
languageVersion,
107-
onError,
108-
shouldCreateNewSourceFile,
109-
),
110-
readFile: filePath =>
111-
// istanbul ignore next
112-
filePath === dummyFilePath ? content : realHost.readFile(filePath),
111+
fileName,
112+
languageVersion,
113+
onError,
114+
shouldCreateNewSourceFile,
115+
),
116+
readFile: fileName =>
117+
isDummyFile(fileName) ? content : realHost.readFile(fileName),
113118
writeFile: (fileName, data) => {
114119
if (fileName.endsWith('.map')) {
115120
map = data;
@@ -130,7 +135,7 @@ function compileFileFromMemory(
130135
),
131136
};
132137

133-
const program = ts.createProgram([dummyFilePath], compilerOptions, host);
138+
const program = ts.createProgram([dummyFileName], compilerOptions, host);
134139
const emitResult = program.emit(undefined, undefined, undefined, undefined, {
135140
before: [importTransformer],
136141
});

0 commit comments

Comments
 (0)