Skip to content

Commit 5ece92b

Browse files
authored
chore: verify that micromatch update does not break CSpell. (#5650)
1 parent a57de4f commit 5ece92b

File tree

5 files changed

+78
-49
lines changed

5 files changed

+78
-49
lines changed

packages/cspell-glob/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"node": ">=18"
5151
},
5252
"dependencies": {
53-
"micromatch": "4.0.5"
53+
"micromatch": "^4.0.6"
5454
},
5555
"devDependencies": {
5656
"@types/micromatch": "^4.0.7"

packages/cspell-glob/src/GlobMatcher.test.ts

+44-25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
GlobPatternWithOptionalRoot,
1313
PathInterface,
1414
} from './GlobMatcherTypes.js';
15+
import { fileURLToPath } from 'node:url';
1516

1617
const defaultCwdWin32 = 'C:\\user\\home\\project\\testing';
1718
const defaultCwdPosix = '/user/home/project/testing';
@@ -26,6 +27,8 @@ const pathPosix: PathInterface = {
2627
resolve: (...paths) => path.posix.resolve(defaultCwdPosix, ...paths),
2728
};
2829

30+
const __filename = fileURLToPath(import.meta.url);
31+
2932
const pathNames = new Map([
3033
[pathWin32, 'Win32'],
3134
[pathPosix, 'Posix'],
@@ -55,34 +58,37 @@ describe('Validate assumptions', () => {
5558

5659
describe('Validate Micromatch assumptions', () => {
5760
test.each`
58-
glob | filename | expectedToMatch
59-
${'*.json'} | ${'settings.json'} | ${true}
60-
${'*.json'} | ${'/settings.json'} | ${false}
61-
${'*.json'} | ${'src/settings.json'} | ${false}
62-
${'*.json'} | ${'/src/settings.json'} | ${false}
63-
${'**/*.json'} | ${'settings.json'} | ${true}
64-
${'**/*.json'} | ${'/settings.json'} | ${true}
65-
${'**/*.json'} | ${'src/settings.json'} | ${true}
66-
${'**/*.json'} | ${'/src/settings.json'} | ${true}
67-
${'**/temp'} | ${'/src/temp/data.json'} | ${false}
68-
${'**/temp/'} | ${'/src/temp/data.json'} | ${false}
69-
${'**/temp/**'} | ${'/src/temp/data.json'} | ${true}
70-
${'src/*.json'} | ${'src/settings.json'} | ${true}
71-
${'**/{*.json,*.json/**}'} | ${'settings.json'} | ${true}
72-
${'**/{*.json,*.json/**}'} | ${'/settings.json'} | ${true}
73-
${'**/{*.json,*.json/**}'} | ${'src/settings.json'} | ${true}
74-
${'**/{*.json,*.json/**}'} | ${'src/settings.json/config'} | ${true}
75-
${'**/{*.json,*.json/**}'} | ${'settings.json/config'} | ${true}
76-
${'src/*.{test,spec}.ts'} | ${'src/code.test.ts'} | ${true}
77-
${'src/*.(test|spec).ts'} | ${'src/code.test.ts'} | ${true}
78-
${'src/*.(test|spec).ts'} | ${'src/code.spec.ts'} | ${true}
79-
${'src/*.(test|spec).ts'} | ${'src/deep.code.test.ts'} | ${true}
80-
${'src/*.(test|spec).ts'} | ${'src/test.ts'} | ${false}
61+
glob | filename | expectedToMatch
62+
${'*.json'} | ${'settings.json'} | ${true}
63+
${'*.json'} | ${'/settings.json'} | ${false}
64+
${'*.json'} | ${'src/settings.json'} | ${false}
65+
${'*.json'} | ${'/src/settings.json'} | ${false}
66+
${'**/*.json'} | ${'settings.json'} | ${true}
67+
${'**/*.json'} | ${'/settings.json'} | ${true}
68+
${'**/*.json'} | ${'src/settings.json'} | ${true}
69+
${'**/*.json'} | ${'/src/settings.json'} | ${true}
70+
${'**/temp'} | ${'/src/temp/data.json'} | ${false}
71+
${'**/temp/'} | ${'/src/temp/data.json'} | ${false}
72+
${'**/temp/**'} | ${'/src/temp/data.json'} | ${true}
73+
${'src/*.json'} | ${'src/settings.json'} | ${true}
74+
${'**/{*.json,*.json/**}'} | ${'settings.json'} | ${true}
75+
${'**/{*.json,*.json/**}'} | ${'/settings.json'} | ${true}
76+
${'**/{*.json,*.json/**}'} | ${'src/settings.json'} | ${true}
77+
${'**/{*.json,*.json/**}'} | ${'src/settings.json/config'} | ${true}
78+
${'**/{*.json,*.json/**}'} | ${'settings.json/config'} | ${true}
79+
${'src/*.{test,spec}.ts'} | ${'src/code.test.ts'} | ${true}
80+
${'src/*.(test|spec).ts'} | ${'src/code.test.ts'} | ${true}
81+
${'src/*.(test|spec).ts'} | ${'src/code.spec.ts'} | ${true}
82+
${'src/*.(test|spec).ts'} | ${'src/deep.code.test.ts'} | ${true}
83+
${'src/*.(test|spec).ts'} | ${'src/test.ts'} | ${false}
84+
${filenameToGlob(__filename, 1)} | ${__filename} | ${true}
85+
${filenameToGlob(__filename, 2)} | ${__filename} | ${true}
8186
`(
8287
`Micromatch glob: '$glob', filename: '$filename' expected: $expectedToMatch`,
8388
({ glob, filename, expectedToMatch }) => {
84-
const reg1 = mm.makeRe(glob);
85-
expect(reg1.test(filename)).toEqual(expectedToMatch);
89+
const reg = mm.makeRe(glob);
90+
expect(reg.test(filename)).toEqual(expectedToMatch);
91+
expect(mm.isMatch(filename, glob, { windows: path.sep === '\\' })).toBe(expectedToMatch);
8692
},
8793
);
8894
});
@@ -123,6 +129,14 @@ function resolveFilename(pathInstance: PathInterface, filename: string | undefin
123129
});
124130
});
125131

132+
describe('Validate GlobMatcher on Windows', () => {
133+
test('Make sure it works on Windows', () => {
134+
const glob = filenameToGlob(__filename, 3);
135+
const matcher = new GlobMatcher(glob);
136+
expect(matcher.match(__filename)).toBe(true);
137+
});
138+
});
139+
126140
describe('Tests .gitignore file contents', () => {
127141
const pattern = `
128142
# This is a comment
@@ -692,3 +706,8 @@ function resolvePattern(p: GlobPattern | GlobPattern[], path: PathInterface): Gl
692706
root: path.resolve(p.root),
693707
};
694708
}
709+
710+
function filenameToGlob(filename: string, segments: number = 1) {
711+
const parts = filename.split(path.sep).slice(-segments).join('/');
712+
return '**/' + parts;
713+
}

packages/cspell/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"@types/glob": "^8.1.0",
110110
"@types/micromatch": "^4.0.7",
111111
"@types/semver": "^7.5.8",
112-
"micromatch": "^4.0.5",
112+
"micromatch": "^4.0.6",
113113
"minimatch": "^9.0.4"
114114
}
115115
}

packages/cspell/src/app/util/glob.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe('Validate internal functions', () => {
264264
const relToRoot = path.relative(root, file);
265265

266266
expect(globMatcher.match(file)).toBe(expectedToMatch);
267-
expect(micromatch.isMatch(relToRoot, expectedGlobs)).toBe(expectedToMatch);
267+
expect(micromatch.isMatch(relToRoot, expectedGlobs, { windows: path.sep === '\\' })).toBe(expectedToMatch);
268268
},
269269
);
270270
});

pnpm-lock.yaml

+31-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)