Skip to content

Commit 120bd69

Browse files
authored
fix: glob patterns in tsconfig.json exclude option does not work (#22)
1 parent 78c3a24 commit 120bd69

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@babel/code-frame": "^7.16.7",
3737
"@rspack/lite-tapable": "^1.0.0",
3838
"chokidar": "^3.5.3",
39+
"is-glob": "^4.0.3",
3940
"memfs": "^4.14.0",
4041
"minimatch": "^9.0.5",
4142
"picocolors": "^1.1.1"
@@ -53,6 +54,7 @@
5354
"@jest/console": "^27.0.0",
5455
"@rspack/core": "^1.1.3",
5556
"@types/babel__code-frame": "^7.0.3",
57+
"@types/is-glob": "^4.0.4",
5658
"@types/jest": "^27.4.0",
5759
"@types/mock-fs": "^4.13.1",
5860
"@types/node": "^16.4.13",

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/watch/inclusive-node-watch-file-system.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { extname } from 'path';
33
import type { FSWatcher } from 'chokidar';
44
import chokidar from 'chokidar';
55
import { minimatch } from 'minimatch';
6+
import isGlob from 'is-glob';
67
import type { Compiler } from '@rspack/core';
78

89
import { clearFilesChange, updateFilesChange } from '../files-change';
@@ -19,6 +20,16 @@ export function createIsIgnored(
1920
excluded: string[]
2021
): (path: string) => boolean {
2122
const ignoredPatterns = ignored ? (Array.isArray(ignored) ? ignored : [ignored]) : [];
23+
24+
const filteredExcluded = excluded.filter((path) => {
25+
// Use `minimatch` to check if the path is a glob pattern.
26+
if (isGlob(path)) {
27+
ignoredPatterns.push(path);
28+
return false;
29+
}
30+
return true;
31+
});
32+
2233
const ignoredFunctions = ignoredPatterns.map((pattern) => {
2334
// ensure patterns are valid - see https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/594
2435
if (typeof pattern === 'string') {
@@ -30,9 +41,11 @@ export function createIsIgnored(
3041
return () => false;
3142
}
3243
});
44+
3345
ignoredFunctions.push((path: string) =>
34-
excluded.some((excludedPath) => isInsideAnotherPath(excludedPath, path))
46+
filteredExcluded.some((excludedPath) => isInsideAnotherPath(excludedPath, path))
3547
);
48+
3649
ignoredFunctions.push((path: string) =>
3750
BUILTIN_IGNORED_DIRS.some(
3851
(ignoredDir) => path.includes(`/${ignoredDir}/`) || path.includes(`\\${ignoredDir}\\`)

test/unit/watch/inclusive-node-watch-file-system.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,34 @@ describe('createIsIgnored', () => {
2323
});
2424

2525
it('should allow to passing string path to the second argument', () => {
26+
// exclude: ["dist"] in tsconfig.json
2627
const isIgnored = createIsIgnored([], ['/path/to/dist']);
2728
expect(isIgnored(gitPath)).toBe(true);
2829
expect(isIgnored(nodeModulesPath)).toBe(false);
2930
expect(isIgnored(distModulePath)).toBe(true);
3031
expect(isIgnored(srcModulePath)).toBe(false);
3132
});
33+
34+
it('should allow to passing glob path to the second argument', () => {
35+
// exclude: ["dist/**"] in tsconfig.json
36+
const isIgnored1 = createIsIgnored([], ['/path/to/dist/**']);
37+
expect(isIgnored1(gitPath)).toBe(true);
38+
expect(isIgnored1(nodeModulesPath)).toBe(false);
39+
expect(isIgnored1(distModulePath)).toBe(true);
40+
expect(isIgnored1(srcModulePath)).toBe(false);
41+
42+
// exclude: ["**/dist/**"] in tsconfig.json
43+
const isIgnored2 = createIsIgnored([], ['/path/to/**/dist/**']);
44+
expect(isIgnored2(gitPath)).toBe(true);
45+
expect(isIgnored2(nodeModulesPath)).toBe(true);
46+
expect(isIgnored2(distModulePath)).toBe(true);
47+
expect(isIgnored2(srcModulePath)).toBe(false);
48+
49+
// exclude: ["**/dist/*"] in tsconfig.json
50+
const isIgnored3 = createIsIgnored([], ['/path/to/**/dist/*']);
51+
expect(isIgnored3(gitPath)).toBe(true);
52+
expect(isIgnored3(nodeModulesPath)).toBe(true);
53+
expect(isIgnored3(distModulePath)).toBe(true);
54+
expect(isIgnored3(srcModulePath)).toBe(false);
55+
});
3256
});

0 commit comments

Comments
 (0)