Skip to content

Commit 0182e17

Browse files
authored
fix transpile on windows (microsoft#153285)
make sure to normalize paths before entering internal TS API, also add better error logging to know what file paths fail
1 parent e5301ee commit 0182e17

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

build/lib/tsb/transpiler.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,29 @@ class Transpiler {
121121
this._allJobs = [];
122122
logFn('Transpile', `will use ${Transpiler.P} transpile worker`);
123123
this._getOutputFileName = (file) => {
124-
if (!_cmdLine.options.configFilePath) {
125-
// this is needed for the INTERNAL getOutputFileNames-call below...
126-
_cmdLine.options.configFilePath = configFilePath;
127-
}
128-
const isDts = file.endsWith('.d.ts');
129-
if (isDts) {
130-
file = file.slice(0, -5) + '.ts';
131-
_cmdLine.fileNames.push(file);
124+
try {
125+
// windows: path-sep normalizing
126+
file = ts.normalizePath(file);
127+
if (!_cmdLine.options.configFilePath) {
128+
// this is needed for the INTERNAL getOutputFileNames-call below...
129+
_cmdLine.options.configFilePath = configFilePath;
130+
}
131+
const isDts = file.endsWith('.d.ts');
132+
if (isDts) {
133+
file = file.slice(0, -5) + '.ts';
134+
_cmdLine.fileNames.push(file);
135+
}
136+
const outfile = ts.getOutputFileNames(_cmdLine, file, true)[0];
137+
if (isDts) {
138+
_cmdLine.fileNames.pop();
139+
}
140+
return outfile;
132141
}
133-
const outfile = ts.getOutputFileNames(_cmdLine, file, true)[0];
134-
if (isDts) {
135-
_cmdLine.fileNames.pop();
142+
catch (err) {
143+
console.error(file, _cmdLine.fileNames);
144+
console.error(err);
145+
throw new err;
136146
}
137-
return outfile;
138147
};
139148
}
140149
async join() {

build/lib/tsb/transpiler.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,35 @@ export class Transpiler {
166166
// very complicated logic to re-use TS internal functions to know the output path
167167
// given a TS input path and its config
168168
type InternalTsApi = typeof ts & {
169+
normalizePath(path: string): string;
169170
getOutputFileNames(commandLine: ts.ParsedCommandLine, inputFileName: string, ignoreCase: boolean): readonly string[];
170171
};
171172
this._getOutputFileName = (file) => {
172-
if (!_cmdLine.options.configFilePath) {
173-
// this is needed for the INTERNAL getOutputFileNames-call below...
174-
_cmdLine.options.configFilePath = configFilePath;
175-
}
176-
const isDts = file.endsWith('.d.ts');
177-
if (isDts) {
178-
file = file.slice(0, -5) + '.ts';
179-
_cmdLine.fileNames.push(file);
180-
}
181-
const outfile = (<InternalTsApi>ts).getOutputFileNames(_cmdLine, file, true)[0];
182-
if (isDts) {
183-
_cmdLine.fileNames.pop();
173+
try {
174+
175+
// windows: path-sep normalizing
176+
file = (<InternalTsApi>ts).normalizePath(file);
177+
178+
if (!_cmdLine.options.configFilePath) {
179+
// this is needed for the INTERNAL getOutputFileNames-call below...
180+
_cmdLine.options.configFilePath = configFilePath;
181+
}
182+
const isDts = file.endsWith('.d.ts');
183+
if (isDts) {
184+
file = file.slice(0, -5) + '.ts';
185+
_cmdLine.fileNames.push(file);
186+
}
187+
const outfile = (<InternalTsApi>ts).getOutputFileNames(_cmdLine, file, true)[0];
188+
if (isDts) {
189+
_cmdLine.fileNames.pop();
190+
}
191+
return outfile;
192+
193+
} catch (err) {
194+
console.error(file, _cmdLine.fileNames);
195+
console.error(err);
196+
throw new err;
184197
}
185-
return outfile;
186198
};
187199
}
188200

0 commit comments

Comments
 (0)