Skip to content

Commit

Permalink
feat: add skip option (#146)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
  • Loading branch information
Akiyamka and aleclarson authored Nov 4, 2024
1 parent 444ee7b commit fe5937f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Give [`vite`] the ability to resolve imports using TypeScript's path mapping.
- `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.

- `skip: (dir: string) => boolean`
A function that determines which directories to skip when searching for tsconfig.json files. While `.git` and `node_modules` directories are always skipped, this option allows you to skip additional directories, which is useful in large monorepos to improve performance.

&nbsp;

### allowJs
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ export default (opts: PluginOptions = {}): Plugin => {
: await tsconfck.findAll(workspaceRoot, {
configNames: opts.configNames || ['tsconfig.json', 'jsconfig.json'],
skip(dir) {
return dir == 'node_modules' || dir == '.git'
if (dir === '.git' || dir === 'node_modules') {
return true
}
if (typeof opts.skip === 'function') {
return opts.skip(dir)
}
return false
},
})

Expand Down Expand Up @@ -402,3 +408,4 @@ function compileGlob(glob: string) {
globstar: true,
}).regex
}

6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export interface PluginOptions {
* @default ["tsconfig.json", "jsconfig.json"]
*/
configNames?: string[]
/**
* A function that determines which directories to skip when searching for tsconfig.json files.
* While `.git` and `node_modules` directories are always skipped, this option allows you to skip
* additional directories, which is useful in large monorepos to improve performance.
*/
skip?: (dir: string) => boolean
}

export interface TSConfig {
Expand Down

0 comments on commit fe5937f

Please sign in to comment.