cspell-glob 7.3.9 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/GlobMatcher.js +37 -4
- package/package.json +4 -4
package/dist/esm/GlobMatcher.js
CHANGED
|
@@ -2,6 +2,17 @@ import mm from 'micromatch';
|
|
|
2
2
|
import * as Path from 'path';
|
|
3
3
|
import { doesRootContainPath, normalizeGlobPatterns, normalizeGlobToRoot } from './globHelper.js';
|
|
4
4
|
export class GlobMatcher {
|
|
5
|
+
/**
|
|
6
|
+
* @param filename full path of file to match against.
|
|
7
|
+
* @returns a GlobMatch - information about the match.
|
|
8
|
+
*/
|
|
9
|
+
matchEx;
|
|
10
|
+
path;
|
|
11
|
+
patterns;
|
|
12
|
+
patternsNormalizedToRoot;
|
|
13
|
+
root;
|
|
14
|
+
dot;
|
|
15
|
+
options;
|
|
5
16
|
constructor(patterns, rootOrOptions, _nodePath) {
|
|
6
17
|
_nodePath = _nodePath ?? Path;
|
|
7
18
|
const options = typeof rootOrOptions === 'string' ? { root: rootOrOptions } : rootOrOptions ?? {};
|
|
@@ -64,15 +75,31 @@ function buildMatcherFn(patterns, options) {
|
|
|
64
75
|
const isNeg = (matchNeg && matchNeg[0].length & 1 && true) || false;
|
|
65
76
|
const reg = mm.makeRe(glob, makeReOptions);
|
|
66
77
|
const fn = (filename) => {
|
|
67
|
-
|
|
68
|
-
return
|
|
78
|
+
reg.lastIndex = 0;
|
|
79
|
+
return reg.test(filename);
|
|
69
80
|
};
|
|
70
81
|
return { pattern, index, isNeg, fn, reg };
|
|
71
82
|
});
|
|
72
83
|
const negRules = rules.filter((r) => r.isNeg);
|
|
73
84
|
const posRules = rules.filter((r) => !r.isNeg);
|
|
85
|
+
// const negRegEx = negRules.map((r) => r.reg).map((r) => r.toString());
|
|
86
|
+
// const posRegEx = posRules.map((r) => r.reg).map((r) => r.toString());
|
|
87
|
+
// console.error('buildMatcherFn %o', { negRegEx, posRegEx, stack: new Error().stack });
|
|
88
|
+
// const negReg = joinRegExp(negRegEx);
|
|
89
|
+
// const posReg = joinRegExp(posRegEx);
|
|
74
90
|
const fn = (filename) => {
|
|
75
91
|
filename = path.resolve(path.normalize(filename));
|
|
92
|
+
const fNameNormalize = path.sep === '\\' ? filename.replace(/\\/g, '/') : filename;
|
|
93
|
+
let lastRoot = '!!!!!!';
|
|
94
|
+
let lastRel = '';
|
|
95
|
+
function relativeToRoot(root) {
|
|
96
|
+
if (root !== lastRoot) {
|
|
97
|
+
lastRoot = root;
|
|
98
|
+
const relName = path.relative(root, filename);
|
|
99
|
+
lastRel = path.sep === '\\' ? relName.replace(/\\/g, '/') : relName;
|
|
100
|
+
}
|
|
101
|
+
return lastRel;
|
|
102
|
+
}
|
|
76
103
|
function testRules(rules, matched) {
|
|
77
104
|
for (const rule of rules) {
|
|
78
105
|
const pattern = rule.pattern;
|
|
@@ -81,8 +108,7 @@ function buildMatcherFn(patterns, options) {
|
|
|
81
108
|
if (isRelPat && !doesRootContainPath(root, filename, path)) {
|
|
82
109
|
continue;
|
|
83
110
|
}
|
|
84
|
-
const
|
|
85
|
-
const fname = path.sep === '\\' ? relName.replace(/\\/g, '/') : relName;
|
|
111
|
+
const fname = isRelPat ? relativeToRoot(root) : fNameNormalize;
|
|
86
112
|
if (rule.fn(fname)) {
|
|
87
113
|
return {
|
|
88
114
|
matched,
|
|
@@ -99,4 +125,11 @@ function buildMatcherFn(patterns, options) {
|
|
|
99
125
|
};
|
|
100
126
|
return fn;
|
|
101
127
|
}
|
|
128
|
+
// function _joinRegExp(patterns: RegExp[]): RegExp | undefined {
|
|
129
|
+
// if (!patterns.length) {
|
|
130
|
+
// return undefined;
|
|
131
|
+
// }
|
|
132
|
+
// const joined = patterns.map((p) => `(?:${p.source})`).join('|');
|
|
133
|
+
// return new RegExp(joined);
|
|
134
|
+
// }
|
|
102
135
|
//# sourceMappingURL=GlobMatcher.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-glob",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Glob matcher for cspell",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cspell",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"url": "https://github.com/streetsidesoftware/cspell/labels/cspell-glob"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"micromatch": "^4.0.5"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/micromatch": "^4.0.
|
|
54
|
+
"@types/micromatch": "^4.0.6"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "28568808deaf39b9ffa71fd0f722441ff1b8c794"
|
|
57
57
|
}
|