Skip to content

Commit fe5937f

Browse files
Akiyamkaaleclarson
andauthored
feat: add skip option (#146)
Co-authored-by: Alec Larson <[email protected]>
1 parent 444ee7b commit fe5937f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ Give [`vite`] the ability to resolve imports using TypeScript's path mapping.
6363
- `ignoreConfigErrors: boolean`
6464
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.
6565

66+
- `skip: (dir: string) => boolean`
67+
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.
68+
6669
&nbsp;
6770

6871
### allowJs

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ export default (opts: PluginOptions = {}): Plugin => {
6363
: await tsconfck.findAll(workspaceRoot, {
6464
configNames: opts.configNames || ['tsconfig.json', 'jsconfig.json'],
6565
skip(dir) {
66-
return dir == 'node_modules' || dir == '.git'
66+
if (dir === '.git' || dir === 'node_modules') {
67+
return true
68+
}
69+
if (typeof opts.skip === 'function') {
70+
return opts.skip(dir)
71+
}
72+
return false
6773
},
6874
})
6975

@@ -402,3 +408,4 @@ function compileGlob(glob: string) {
402408
globstar: true,
403409
}).regex
404410
}
411+

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export interface PluginOptions {
4747
* @default ["tsconfig.json", "jsconfig.json"]
4848
*/
4949
configNames?: string[]
50+
/**
51+
* A function that determines which directories to skip when searching for tsconfig.json files.
52+
* While `.git` and `node_modules` directories are always skipped, this option allows you to skip
53+
* additional directories, which is useful in large monorepos to improve performance.
54+
*/
55+
skip?: (dir: string) => boolean
5056
}
5157

5258
export interface TSConfig {

0 commit comments

Comments
 (0)