Skip to content

Commit

Permalink
feat: add ignoreConfigErrors option (#109)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Larson <[email protected]>
  • Loading branch information
jgoux and aleclarson authored Apr 12, 2023
1 parent 2720bca commit 7a97869
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Give [`vite`] the ability to resolve imports using TypeScript's path mapping.
600ms, due to the size of the TypeScript compiler. Only use it when
necessary.

- `ignoreConfigErrors: boolean`
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.

&nbsp;

### allowJs
Expand Down
25 changes: 24 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export default (opts: PluginOptions = {}): Plugin => {
}
}

let firstError: any

const parseOptions = {
resolveWithEmptyIfConfigNotFound: true,
} satisfies import('tsconfck').TSConfckParseOptions
Expand All @@ -84,12 +86,33 @@ export default (opts: PluginOptions = {}): Plugin => {
(
await Promise.all(
projects.map((tsconfigFile) =>
hasTypeScriptDep
(hasTypeScriptDep
? tsconfck.parseNative(tsconfigFile, parseOptions)
: tsconfck.parse(tsconfigFile, parseOptions)
).catch((error) => {
if (!opts.ignoreConfigErrors) {
config.logger.error(
'[tsconfig-paths] An error occurred while parsing "' +
tsconfigFile +
'". See below for details.' +
(firstError
? ''
: ' To disable this message, set the `ignoreConfigErrors` option to true.'),
{ error }
)
if (config.logger.hasErrorLogged(error)) {
console.error(error)
}
firstError = error
}
return null
})
)
)
).filter((project, i) => {
if (!project) {
return false
}
if (project.tsconfigFile !== 'no_tsconfig_file_found') {
return true
}
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface PluginOptions {
* necessary.
*/
parseNative?: boolean
/**
* Silence the warning about malformed `tsconfig.json` files.
*/
ignoreConfigErrors?: boolean
}

export interface TSConfig {
Expand Down

0 comments on commit 7a97869

Please sign in to comment.