Skip to content

Commit 8081fca

Browse files
authored
feat: Add glob support for URLs (#5824)
1 parent ca5159e commit 8081fca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6202
-1087
lines changed

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"options": {
88
"trailingComma": "none"
99
}
10+
},
11+
{
12+
"files": "**/src/GlobMatcher.test.ts",
13+
"options": {
14+
"printWidth": 180
15+
}
1016
}
1117
]
1218
}

cspell.code-workspace

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@
4141
"autoAttachChildProcesses": true,
4242
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
4343
"program": "${workspaceRoot:cspell-monorepo}/node_modules/vitest/vitest.mjs",
44-
"args": ["run", "--test-timeout=600000", "${relativeFile}"],
44+
"args": [
45+
"run",
46+
"--testTimeout=600000",
47+
"--hideSkippedTests",
48+
"--reporter=basic",
49+
"--no-file-parallelism",
50+
"${relativeFile}"
51+
],
4552
"cwd": "${fileWorkspaceFolder}",
4653
"smartStep": true,
4754
"console": "integratedTerminal"

packages/cspell-gitignore/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
"node": ">=18"
5454
},
5555
"dependencies": {
56+
"@cspell/url": "workspace:*",
5657
"cspell-glob": "workspace:*",
58+
"cspell-io": "workspace:*",
5759
"find-up-simple": "^1.0.0"
5860
}
5961
}

packages/cspell-gitignore/src/GitIgnore.test.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import * as path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23

34
import { describe, expect, test } from 'vitest';
45

56
import { GitIgnore } from './GitIgnore.js';
67

7-
const pkg = path.resolve(__dirname, '..');
8-
const packages = path.resolve(pkg, '..');
9-
const gitRoot = path.resolve(packages, '..');
10-
const samples = path.resolve(pkg, 'samples');
11-
const pkgCSpellLib = path.join(packages, 'cspell-lib');
12-
const gitIgnoreFile = path.resolve(gitRoot, '.gitignore');
8+
const dirUrl = new URL('.', import.meta.url);
9+
10+
const pkgUrl = new URL('../', dirUrl);
11+
const packagesUrl = new URL('../', pkgUrl);
12+
const gitRootUrl = new URL('../', packagesUrl);
13+
const samplesUrl = new URL('samples/', pkgUrl);
14+
const pkgCSpellLibUrl = new URL('cspell-lib/', packagesUrl);
15+
const gitIgnoreFileUrl = new URL('.gitignore', gitRootUrl);
16+
17+
const pkg = fileURLToPath(pkgUrl);
18+
const packages = fileURLToPath(packagesUrl);
19+
const gitRoot = fileURLToPath(gitRootUrl);
20+
const samples = fileURLToPath(samplesUrl);
21+
const pkgCSpellLib = fileURLToPath(pkgCSpellLibUrl);
22+
const gitIgnoreFile = fileURLToPath(gitIgnoreFileUrl);
1323
// const pathSamples = path.resolve(pkg, 'samples');
1424
// const gitIgnoreSamples = path.resolve(pathSamples, '.gitignore');
1525

@@ -58,12 +68,23 @@ describe('GitIgnoreServer', () => {
5868
file | roots | expected
5969
${__filename} | ${undefined} | ${undefined}
6070
${p(samples, 'ignored/keepme.md')} | ${undefined} | ${undefined}
61-
${p(samples, 'ignored/file.txt')} | ${undefined} | ${{ glob: 'ignored/**', matched: true, line: 3, root: samples, gitIgnoreFile: p(samples, '.gitignore') }}
62-
${p(pkg, 'node_modules/bin')} | ${undefined} | ${oc({ glob: 'node_modules/', matched: true, root: gitRoot, gitIgnoreFile: gitIgnoreFile })}
71+
${p(samples, 'ignored/file.txt')} | ${undefined} | ${{ glob: 'ignored/**', matched: true, line: 3, root: pr(samples), gitIgnoreFile: p(samples, '.gitignore') }}
72+
${p(pkg, 'node_modules/bin')} | ${undefined} | ${oc({ glob: 'node_modules/', matched: true, root: pr(gitRoot), gitIgnoreFile: gitIgnoreFile })}
73+
${p(pkg, 'node_modules/')} | ${undefined} | ${oc({ glob: 'node_modules/', matched: true, root: pr(gitRoot), gitIgnoreFile: gitIgnoreFile })}
6374
${__filename} | ${[p(samples, 'ignored')]} | ${undefined}
6475
${p(samples, 'ignored/keepme.md')} | ${[p(samples, 'ignored')]} | ${undefined}
6576
${p(samples, 'ignored/file.txt')} | ${[p(samples, 'ignored')]} | ${undefined}
66-
${p(pkg, 'node_modules/bin')} | ${[p(samples, 'ignored')]} | ${oc({ glob: 'node_modules/', matched: true, root: gitRoot, gitIgnoreFile: gitIgnoreFile })}
77+
${p(pkg, 'node_modules/bin')} | ${[p(samples, 'ignored')]} | ${oc({ glob: 'node_modules/', matched: true, root: pr(gitRoot), gitIgnoreFile: gitIgnoreFile })}
78+
`('isIgnoredEx $file $roots', async ({ file, roots, expected }) => {
79+
const dir = path.dirname(file);
80+
const gs = new GitIgnore(roots);
81+
const r = await gs.findGitIgnoreHierarchy(dir);
82+
expect(r.isIgnoredEx(file)).toEqual(expected);
83+
});
84+
85+
test.each`
86+
file | roots | expected
87+
${p(pkg, 'node_modules/')} | ${undefined} | ${oc({ glob: 'node_modules/', matched: true, root: pr(gitRoot), gitIgnoreFile: gitIgnoreFile })}
6788
`('isIgnoredEx $file $roots', async ({ file, roots, expected }) => {
6889
const dir = path.dirname(file);
6990
const gs = new GitIgnore(roots);
@@ -77,6 +98,7 @@ describe('GitIgnoreServer', () => {
7798
p(samples, 'ignored/keepme.md'),
7899
p(samples, 'ignored/file.txt'),
79100
p(pkg, 'node_modules/bin'),
101+
p(pkg, 'node_modules/'),
80102
];
81103
const gs = new GitIgnore();
82104
const r = await gs.filterOutIgnored(files);
@@ -118,4 +140,8 @@ describe('GitIgnoreServer', () => {
118140
function p(dir: string, ...dirs: string[]) {
119141
return path.join(dir, ...dirs);
120142
}
143+
144+
function pr(...dirs: string[]) {
145+
return path.join(path.resolve(...dirs), './');
146+
}
121147
});

packages/cspell-gitignore/src/GitIgnoreFile.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23

34
import { GlobMatcher } from 'cspell-glob';
45
import { describe, expect, test } from 'vitest';
@@ -7,8 +8,9 @@ import { __testing__, GitIgnoreFile, GitIgnoreHierarchy, loadGitIgnore } from '.
78

89
const { mustBeHierarchical } = __testing__;
910

11+
const __dirname = fileURLToPath(new URL('./', import.meta.url));
1012
const pathPackage = path.resolve(__dirname, '..');
11-
const pathRepo = path.resolve(pathPackage, '../..');
13+
const pathRepo = path.join(path.resolve(pathPackage, '../..'), './');
1214
const gitIgnoreFile = path.resolve(pathRepo, '.gitignore');
1315

1416
const oc = (obj: unknown) => expect.objectContaining(obj);

packages/cspell-gitignore/src/__snapshots__/app.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ exports[`app > app.run [ '../node_modules' ] 1`] = `".gitignore:50:node_modules/
2929
3030
exports[`app > app.run [ '../node_modules' ] 2`] = `""`;
3131
32+
exports[`app > app.run [ '../node_modules/.bin/run.mjs' ] 1`] = `".gitignore:50:node_modules/ ../node_modules/.bin/run.mjs"`;
33+
34+
exports[`app > app.run [ '../node_modules/.bin/run.mjs' ] 2`] = `""`;
35+
3236
exports[`app > app.run [ '-r', '.' ] 1`] = `""`;
3337
3438
exports[`app > app.run [ '-r', '.' ] 2`] = `"Missing files"`;

packages/cspell-gitignore/src/app.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('app', () => {
2222
params
2323
${[path.basename(__dirname) + '/code.ts']}
2424
${['../node_modules']}
25+
${['../node_modules/.bin/run.mjs']}
2526
${['-r', '.', 'dist']}
2627
${['temp']}
2728
${['-r', '.', 'temp']}

packages/cspell-gitignore/src/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ export async function run(args: string[]): Promise<void> {
4040
for (const file of files) {
4141
const filename = path.relative(cwd, file);
4242
const pFile = gi.isIgnoredEx(file);
43-
const pDir = gi.isIgnoredEx(file + '/ ');
43+
const pDir = gi.isIgnoredEx(file + '/');
4444
const r = (await pFile) || (await pDir);
45+
console.warn('%o', { pFile: await pFile, pDir: await pDir });
4546
const gitignore = r?.gitIgnoreFile ? path.relative(repo, r.gitIgnoreFile) : '';
4647
const line = r?.line || '';
4748
const glob = r?.glob || '';

packages/cspell-gitignore/tsconfig.esm.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2-
"files": [],
3-
"references": [{ "path": "./tsconfig.esm.json" }]
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "dist",
6+
"types": ["node"]
7+
},
8+
"include": ["src"]
49
}

packages/cspell-glob/package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"license": "MIT",
1212
"type": "module",
1313
"sideEffects": false,
14-
"types": "dist/esm/index.d.ts",
15-
"module": "dist/esm/index.js",
14+
"types": "dist/index.d.ts",
15+
"module": "dist/index.js",
1616
"exports": {
1717
".": {
18-
"import": "./dist/esm/index.js"
18+
"import": "./dist/index.js"
1919
}
2020
},
2121
"files": [
@@ -25,18 +25,22 @@
2525
"!**/__mocks__",
2626
"!**/test/**",
2727
"!**/*.test.*",
28+
"!**/perf/**",
29+
"!**/*.perf.*",
2830
"!**/*.spec.*",
2931
"!**/*.map"
3032
],
3133
"scripts": {
3234
"clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
33-
"build": "tsc -b . -f",
34-
"build:esm": "tsc -p tsconfig.esm.json",
35+
"build": "tsc -p .",
3536
"clean-build": "pnpm run clean && pnpm run build",
3637
"coverage": "vitest run --coverage",
38+
"test:perf": "insight --file \"dist/perf/**/*.perf.{mjs,js}\" -t 1000",
39+
"test:perf:ts": "insight --register ts-node/esm --file \"src/perf/**/*.perf.{mts,ts}\" -t 1000",
40+
"test:perf:prof": "NODE_ENV=production node --cpu-prof ../../node_modules/perf-insight/bin.mjs --file \"dist/perf/**/*.perf.{mjs,js}\" -t 1000",
3741
"test:watch": "vitest",
3842
"test": "vitest run",
39-
"watch": "tsc -b . -w -f"
43+
"watch": "tsc -p . -w"
4044
},
4145
"repository": {
4246
"type": "git",
@@ -50,6 +54,7 @@
5054
"node": ">=18"
5155
},
5256
"dependencies": {
57+
"@cspell/url": "workspace:*",
5358
"micromatch": "^4.0.7"
5459
},
5560
"devDependencies": {

0 commit comments

Comments
 (0)