cspell-glob 6.1.3 → 6.2.2

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.
@@ -1,4 +1,4 @@
1
- import { PathInterface, GlobMatch, GlobPattern, GlobPatternWithRoot } from './GlobMatcherTypes';
1
+ import { PathInterface, GlobMatch, GlobPattern, GlobPatternWithRoot, GlobPatternNormalized } from './GlobMatcherTypes';
2
2
  declare type Optional<T> = {
3
3
  [P in keyof T]?: T[P] | undefined;
4
4
  };
@@ -64,7 +64,7 @@ export declare class GlobMatcher {
64
64
  readonly matchEx: (filename: string) => GlobMatch;
65
65
  readonly path: PathInterface;
66
66
  readonly patterns: GlobPatternWithRoot[];
67
- readonly patternsNormalizedToRoot: GlobPatternWithRoot[];
67
+ readonly patternsNormalizedToRoot: GlobPatternNormalized[];
68
68
  readonly root: string;
69
69
  readonly dot: boolean;
70
70
  readonly options: NormalizedGlobMatchOptions;
@@ -34,7 +34,7 @@ class GlobMatcher {
34
34
  const { mode = 'exclude' } = options;
35
35
  const isExcludeMode = mode !== 'include';
36
36
  _nodePath = options.nodePath ?? _nodePath;
37
- const { root = _nodePath.resolve(), dot = isExcludeMode, nodePath = _nodePath, nested = isExcludeMode, cwd = process.cwd(), nobrace, } = clean(options);
37
+ const { root = _nodePath.resolve(), dot = isExcludeMode, nodePath = _nodePath, nested = isExcludeMode, cwd = process.cwd(), nobrace, } = options;
38
38
  const normalizedRoot = nodePath.resolve(nodePath.normalize(root));
39
39
  this.options = { root: normalizedRoot, dot, nodePath, nested, mode, nobrace, cwd };
40
40
  patterns = Array.isArray(patterns)
@@ -104,10 +104,11 @@ function buildMatcherFn(patterns, options) {
104
104
  for (const rule of rules) {
105
105
  const pattern = rule.pattern;
106
106
  const root = pattern.root;
107
- if (!(0, globHelper_1.doesRootContainPath)(root, filename, path)) {
107
+ const isRelPat = !pattern.isGlobalPattern;
108
+ if (isRelPat && !(0, globHelper_1.doesRootContainPath)(root, filename, path)) {
108
109
  continue;
109
110
  }
110
- const relName = path.relative(root, filename);
111
+ const relName = isRelPat ? path.relative(root, filename) : filename;
111
112
  const fname = path.sep === '\\' ? relName.replace(/\\/g, '/') : relName;
112
113
  if (rule.fn(fname)) {
113
114
  return {
@@ -125,15 +126,4 @@ function buildMatcherFn(patterns, options) {
125
126
  };
126
127
  return fn;
127
128
  }
128
- function clean(obj) {
129
- if (typeof obj !== 'object')
130
- return obj;
131
- const r = obj;
132
- for (const key of Object.keys(r)) {
133
- if (r[key] === undefined) {
134
- delete r[key];
135
- }
136
- }
137
- return obj;
138
- }
139
129
  //# sourceMappingURL=GlobMatcher.js.map
@@ -41,6 +41,10 @@ export interface GlobPatternWithOptionalRoot {
41
41
  }
42
42
  export interface GlobPatternWithRoot extends GlobPatternWithOptionalRoot {
43
43
  root: string;
44
+ /**
45
+ * Global patterns do not need to be relative to the root.
46
+ */
47
+ isGlobalPattern: boolean;
44
48
  }
45
49
  export interface GlobPatternNormalized extends GlobPatternWithRoot {
46
50
  /** the original glob pattern before it was normalized */
@@ -63,9 +63,11 @@ declare function rebaseGlob(glob: string, rebaseTo: string): string | undefined;
63
63
  * @returns trimmed glob
64
64
  */
65
65
  declare function trimGlob(glob: string): string;
66
+ declare function isGlobalGlob(glob: string): boolean;
66
67
  export declare const __testing__: {
67
68
  rebaseGlob: typeof rebaseGlob;
68
69
  trimGlob: typeof trimGlob;
70
+ isGlobalGlob: typeof isGlobalGlob;
69
71
  };
70
72
  export {};
71
73
  //# sourceMappingURL=globHelper.d.ts.map
@@ -28,6 +28,8 @@ exports.__testing__ = exports.normalizeGlobToRoot = exports.normalizeGlobPattern
28
28
  const Path = __importStar(require("path"));
29
29
  const { posix } = Path;
30
30
  const relRegExp = /^\.[\\/]/;
31
+ /** test for glob patterns starting with `**` */
32
+ const isGlobalPatternRegExp = /^!*[*]{2}/;
31
33
  /**
32
34
  * This function tries its best to determine if `fileOrGlob` is a path to a file or a glob pattern.
33
35
  * @param fileOrGlob - file (with absolute path) or glob.
@@ -36,21 +38,19 @@ const relRegExp = /^\.[\\/]/;
36
38
  */
37
39
  function fileOrGlobToGlob(fileOrGlob, root, path = Path) {
38
40
  const pathToGlob = path.sep === '\\' ? (p) => p.replace(/\\/g, '/') : (p) => p;
39
- if (typeof fileOrGlob !== 'string') {
41
+ const isGlobalPattern = false;
42
+ if (isGlobPatternWithOptionalRoot(fileOrGlob)) {
40
43
  const useRoot = fileOrGlob.root ?? root;
41
- return { ...fileOrGlob, root: useRoot };
44
+ const isGlobalPattern = isGlobPatternWithRoot(fileOrGlob)
45
+ ? fileOrGlob.isGlobalPattern
46
+ : isGlobalGlob(fileOrGlob.glob);
47
+ return { ...fileOrGlob, root: useRoot, isGlobalPattern };
42
48
  }
43
49
  if (doesRootContainPath(root, fileOrGlob, path) || relRegExp.test(fileOrGlob)) {
44
50
  const rel = path.relative(root, path.resolve(root, fileOrGlob));
45
- return {
46
- glob: pathToGlob(rel),
47
- root,
48
- };
51
+ return { glob: pathToGlob(rel), root, isGlobalPattern };
49
52
  }
50
- return {
51
- glob: pathToGlob(fileOrGlob),
52
- root,
53
- };
53
+ return { glob: pathToGlob(fileOrGlob), root, isGlobalPattern };
54
54
  }
55
55
  exports.fileOrGlobToGlob = fileOrGlobToGlob;
56
56
  /**
@@ -70,7 +70,7 @@ function isGlobPatternWithOptionalRoot(g) {
70
70
  }
71
71
  exports.isGlobPatternWithOptionalRoot = isGlobPatternWithOptionalRoot;
72
72
  function isGlobPatternWithRoot(g) {
73
- return !!g.root;
73
+ return typeof g.root === 'string' && 'isGlobalPattern' in g;
74
74
  }
75
75
  exports.isGlobPatternWithRoot = isGlobPatternWithRoot;
76
76
  function isGlobPatternNormalized(g) {
@@ -150,9 +150,10 @@ function normalizeGlobPattern(g, options) {
150
150
  if (gr.root.startsWith('${cwd}')) {
151
151
  gr.root = path.resolve(gr.root.replace('${cwd}', cwd));
152
152
  }
153
+ const isGlobalPattern = isGlobalGlob(gr.glob);
153
154
  gr.root = path.resolve(root, path.normalize(gr.root));
154
155
  const globs = normalizePattern(gr.glob, nested);
155
- return globs.map((glob) => ({ ...gr, glob, rawGlob, rawRoot }));
156
+ return globs.map((glob) => ({ ...gr, glob, rawGlob, rawRoot, isGlobalPattern }));
156
157
  }
157
158
  exports.normalizeGlobPattern = normalizeGlobPattern;
158
159
  /**
@@ -174,6 +175,9 @@ function normalizeGlobToRoot(glob, root, path) {
174
175
  if (!relFromRootToGlob) {
175
176
  return glob;
176
177
  }
178
+ if (glob.isGlobalPattern) {
179
+ return { ...glob, root };
180
+ }
177
181
  const relFromGlobToRoot = path.relative(glob.root, root);
178
182
  const globIsUnderRoot = relFromRootToGlob[0] !== '.' && !path.isAbsolute(relFromRootToGlob);
179
183
  const rootIsUnderGlob = relFromGlobToRoot[0] !== '.' && !path.isAbsolute(relFromGlobToRoot);
@@ -277,8 +281,12 @@ function trimGlobLeft(glob) {
277
281
  }
278
282
  return glob.slice(i);
279
283
  }
284
+ function isGlobalGlob(glob) {
285
+ return isGlobalPatternRegExp.test(glob);
286
+ }
280
287
  exports.__testing__ = {
281
288
  rebaseGlob,
282
289
  trimGlob,
290
+ isGlobalGlob,
283
291
  };
284
292
  //# sourceMappingURL=globHelper.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-glob",
3
- "version": "6.1.3",
3
+ "version": "6.2.2",
4
4
  "description": "Glob matcher for cspell",
5
5
  "keywords": [
6
6
  "cspell",
@@ -47,8 +47,8 @@
47
47
  "devDependencies": {
48
48
  "@types/micromatch": "^4.0.2",
49
49
  "@types/node": "^18.0.0",
50
- "jest": "^28.1.1",
50
+ "jest": "^28.1.2",
51
51
  "rimraf": "^3.0.2"
52
52
  },
53
- "gitHead": "e96b313542f2ec0a38ac04d1422d97e724ded3a6"
53
+ "gitHead": "b7716e80c39a780f98cde747ad66c55247636621"
54
54
  }