Skip to content

Commit 7a97869

Browse files
jgouxaleclarson
andauthored
feat: add ignoreConfigErrors option (#109)
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
1 parent 2720bca commit 7a97869

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Give [`vite`] the ability to resolve imports using TypeScript's path mapping.
6262
600ms, due to the size of the TypeScript compiler. Only use it when
6363
necessary.
6464

65+
- `ignoreConfigErrors: boolean`
66+
When true, parsing errors encountered while loading tsconfig files will be ignored. This is useful if you have a monorepo with multiple tsconfig files, and you don't want to see errors for the ones that aren't relevant to the current project.
67+
6568
&nbsp;
6669

6770
### allowJs

src/index.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export default (opts: PluginOptions = {}): Plugin => {
7676
}
7777
}
7878

79+
let firstError: any
80+
7981
const parseOptions = {
8082
resolveWithEmptyIfConfigNotFound: true,
8183
} satisfies import('tsconfck').TSConfckParseOptions
@@ -84,12 +86,33 @@ export default (opts: PluginOptions = {}): Plugin => {
8486
(
8587
await Promise.all(
8688
projects.map((tsconfigFile) =>
87-
hasTypeScriptDep
89+
(hasTypeScriptDep
8890
? tsconfck.parseNative(tsconfigFile, parseOptions)
8991
: tsconfck.parse(tsconfigFile, parseOptions)
92+
).catch((error) => {
93+
if (!opts.ignoreConfigErrors) {
94+
config.logger.error(
95+
'[tsconfig-paths] An error occurred while parsing "' +
96+
tsconfigFile +
97+
'". See below for details.' +
98+
(firstError
99+
? ''
100+
: ' To disable this message, set the `ignoreConfigErrors` option to true.'),
101+
{ error }
102+
)
103+
if (config.logger.hasErrorLogged(error)) {
104+
console.error(error)
105+
}
106+
firstError = error
107+
}
108+
return null
109+
})
90110
)
91111
)
92112
).filter((project, i) => {
113+
if (!project) {
114+
return false
115+
}
93116
if (project.tsconfigFile !== 'no_tsconfig_file_found') {
94117
return true
95118
}

src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface PluginOptions {
3838
* necessary.
3939
*/
4040
parseNative?: boolean
41+
/**
42+
* Silence the warning about malformed `tsconfig.json` files.
43+
*/
44+
ignoreConfigErrors?: boolean
4145
}
4246

4347
export interface TSConfig {

0 commit comments

Comments
 (0)