Skip to content

Commit 5aa60cb

Browse files
dummdidummSimon Holthausen
and
Simon Holthausen
authored
perf: cache tsconfig (#398)
#383 Co-authored-by: Simon Holthausen <[email protected]>
1 parent 162faa4 commit 5aa60cb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: src/transformers/typescript.ts

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ type InternalTransformerOptions = TransformerArgs<Options.Typescript> & {
2525

2626
const injectedCodeSeparator = 'const $$$$$$$$ = null;';
2727

28+
/**
29+
* Map of valid tsconfigs (no errors). Key is the path.
30+
*/
31+
const tsconfigMap = new Map<string, any>();
32+
2833
function createFormatDiagnosticsHost(cwd: string): ts.FormatDiagnosticsHost {
2934
return {
3035
getCanonicalFileName: (fileName: string) =>
@@ -355,6 +360,13 @@ export function loadTsconfig(
355360

356361
basePath = dirname(tsconfigFile);
357362

363+
if (tsconfigMap.has(tsconfigFile)) {
364+
return {
365+
errors: [],
366+
options: tsconfigMap.get(tsconfigFile),
367+
};
368+
}
369+
358370
const { error, config } = ts.readConfigFile(tsconfigFile, ts.sys.readFile);
359371

360372
if (error) {
@@ -375,6 +387,10 @@ export function loadTsconfig(
375387
// Filter out "no files found error"
376388
errors = errors.filter((d) => d.code !== 18003);
377389

390+
if (errors.length === 0) {
391+
tsconfigMap.set(tsconfigFile, options);
392+
}
393+
378394
return { errors, options };
379395
}
380396

0 commit comments

Comments
 (0)