Skip to content

chore: verify that micromatch update does not break CSpell. #5650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cspell-glob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"node": ">=18"
},
"dependencies": {
"micromatch": "4.0.5"
"micromatch": "^4.0.6"
},
"devDependencies": {
"@types/micromatch": "^4.0.7"
Expand Down
69 changes: 44 additions & 25 deletions packages/cspell-glob/src/GlobMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
GlobPatternWithOptionalRoot,
PathInterface,
} from './GlobMatcherTypes.js';
import { fileURLToPath } from 'node:url';

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

const __filename = fileURLToPath(import.meta.url);

const pathNames = new Map([
[pathWin32, 'Win32'],
[pathPosix, 'Posix'],
Expand Down Expand Up @@ -55,34 +58,37 @@ describe('Validate assumptions', () => {

describe('Validate Micromatch assumptions', () => {
test.each`
glob | filename | expectedToMatch
${'*.json'} | ${'settings.json'} | ${true}
${'*.json'} | ${'/settings.json'} | ${false}
${'*.json'} | ${'src/settings.json'} | ${false}
${'*.json'} | ${'/src/settings.json'} | ${false}
${'**/*.json'} | ${'settings.json'} | ${true}
${'**/*.json'} | ${'/settings.json'} | ${true}
${'**/*.json'} | ${'src/settings.json'} | ${true}
${'**/*.json'} | ${'/src/settings.json'} | ${true}
${'**/temp'} | ${'/src/temp/data.json'} | ${false}
${'**/temp/'} | ${'/src/temp/data.json'} | ${false}
${'**/temp/**'} | ${'/src/temp/data.json'} | ${true}
${'src/*.json'} | ${'src/settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'/settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'src/settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'src/settings.json/config'} | ${true}
${'**/{*.json,*.json/**}'} | ${'settings.json/config'} | ${true}
${'src/*.{test,spec}.ts'} | ${'src/code.test.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/code.test.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/code.spec.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/deep.code.test.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/test.ts'} | ${false}
glob | filename | expectedToMatch
${'*.json'} | ${'settings.json'} | ${true}
${'*.json'} | ${'/settings.json'} | ${false}
${'*.json'} | ${'src/settings.json'} | ${false}
${'*.json'} | ${'/src/settings.json'} | ${false}
${'**/*.json'} | ${'settings.json'} | ${true}
${'**/*.json'} | ${'/settings.json'} | ${true}
${'**/*.json'} | ${'src/settings.json'} | ${true}
${'**/*.json'} | ${'/src/settings.json'} | ${true}
${'**/temp'} | ${'/src/temp/data.json'} | ${false}
${'**/temp/'} | ${'/src/temp/data.json'} | ${false}
${'**/temp/**'} | ${'/src/temp/data.json'} | ${true}
${'src/*.json'} | ${'src/settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'/settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'src/settings.json'} | ${true}
${'**/{*.json,*.json/**}'} | ${'src/settings.json/config'} | ${true}
${'**/{*.json,*.json/**}'} | ${'settings.json/config'} | ${true}
${'src/*.{test,spec}.ts'} | ${'src/code.test.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/code.test.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/code.spec.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/deep.code.test.ts'} | ${true}
${'src/*.(test|spec).ts'} | ${'src/test.ts'} | ${false}
${filenameToGlob(__filename, 1)} | ${__filename} | ${true}
${filenameToGlob(__filename, 2)} | ${__filename} | ${true}
`(
`Micromatch glob: '$glob', filename: '$filename' expected: $expectedToMatch`,
({ glob, filename, expectedToMatch }) => {
const reg1 = mm.makeRe(glob);
expect(reg1.test(filename)).toEqual(expectedToMatch);
const reg = mm.makeRe(glob);
expect(reg.test(filename)).toEqual(expectedToMatch);
expect(mm.isMatch(filename, glob, { windows: path.sep === '\\' })).toBe(expectedToMatch);
},
);
});
Expand Down Expand Up @@ -123,6 +129,14 @@ function resolveFilename(pathInstance: PathInterface, filename: string | undefin
});
});

describe('Validate GlobMatcher on Windows', () => {
test('Make sure it works on Windows', () => {
const glob = filenameToGlob(__filename, 3);
const matcher = new GlobMatcher(glob);
expect(matcher.match(__filename)).toBe(true);
});
});

describe('Tests .gitignore file contents', () => {
const pattern = `
# This is a comment
Expand Down Expand Up @@ -692,3 +706,8 @@ function resolvePattern(p: GlobPattern | GlobPattern[], path: PathInterface): Gl
root: path.resolve(p.root),
};
}

function filenameToGlob(filename: string, segments: number = 1) {
const parts = filename.split(path.sep).slice(-segments).join('/');
return '**/' + parts;
}
2 changes: 1 addition & 1 deletion packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"@types/glob": "^8.1.0",
"@types/micromatch": "^4.0.7",
"@types/semver": "^7.5.8",
"micromatch": "^4.0.5",
"micromatch": "^4.0.6",
"minimatch": "^9.0.4"
}
}
2 changes: 1 addition & 1 deletion packages/cspell/src/app/util/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('Validate internal functions', () => {
const relToRoot = path.relative(root, file);

expect(globMatcher.match(file)).toBe(expectedToMatch);
expect(micromatch.isMatch(relToRoot, expectedGlobs)).toBe(expectedToMatch);
expect(micromatch.isMatch(relToRoot, expectedGlobs, { windows: path.sep === '\\' })).toBe(expectedToMatch);
},
);
});
52 changes: 31 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.