|
1 | | -import { dirname } from 'node:path'; |
| 1 | +import { basename, dirname } from 'node:path'; |
2 | 2 | import { EOL } from 'node:os'; |
3 | 3 |
|
4 | 4 | import { createFilter } from 'vite'; |
@@ -64,26 +64,31 @@ function prepareCompilerOptions(cache: Map<string, CompilerOptions>, file: strin |
64 | 64 | return cache.get(key) as CompilerOptions; |
65 | 65 | } |
66 | 66 |
|
| 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 { |
67 | 74 | const location = options?.tsconfig?.location |
68 | 75 | ?? ts.findConfigFile(file, ts.sys.fileExists); |
69 | 76 |
|
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 | + } |
76 | 80 |
|
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); |
81 | 82 |
|
82 | | - cache.set(key, compilerOptions); |
83 | | - return compilerOptions; |
| 83 | + if (error) { |
| 84 | + throw error; |
84 | 85 | } |
85 | 86 |
|
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; |
87 | 92 | } |
88 | 93 |
|
89 | 94 | export { |
|
0 commit comments