Skip to content

Commit 4ce7744

Browse files
committed
feat: support extends when parsing tsconfig.json file
1 parent 6976499 commit 4ce7744

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/plugin.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dirname } from 'node:path';
1+
import { basename, dirname } from 'node:path';
22
import { EOL } from 'node:os';
33

44
import { createFilter } from 'vite';
@@ -64,26 +64,31 @@ function prepareCompilerOptions(cache: Map<string, CompilerOptions>, file: strin
6464
return cache.get(key) as CompilerOptions;
6565
}
6666

67+
const compilerOptions = parseCompilerOptions(file, options);
68+
cache.set(key, compilerOptions);
69+
70+
return compilerOptions;
71+
}
72+
73+
function parseCompilerOptions(file: string, options?: Options): CompilerOptions {
6774
const location = options?.tsconfig?.location
6875
?? ts.findConfigFile(file, ts.sys.fileExists);
6976

70-
if (location) {
71-
const parsed = ts.readConfigFile(location, ts.sys.readFile);
72-
73-
if (parsed.error) {
74-
throw parsed.error;
75-
}
77+
if (!location) {
78+
throw new Error(`Could not find TypeScript configuration for ${file}`);
79+
}
7680

77-
const compilerOptions = {
78-
...parsed.config.compilerOptions,
79-
...options?.tsconfig?.override,
80-
} satisfies CompilerOptions;
81+
const { config: tsconfig, error } = ts.readConfigFile(location, ts.sys.readFile);
8182

82-
cache.set(key, compilerOptions);
83-
return compilerOptions;
83+
if (error) {
84+
throw error;
8485
}
8586

86-
throw new Error(`Could not find TypeScript configuration for ${file}`);
87+
const directory = dirname(location);
88+
const name = basename(location);
89+
const parsed = ts.parseJsonConfigFileContent(tsconfig, ts.sys, directory, undefined, name);
90+
91+
return parsed.options;
8792
}
8893

8994
export {

0 commit comments

Comments
 (0)