cspell-glob 7.0.2 → 7.2.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.
@@ -1,6 +1,6 @@
1
1
  import mm from 'micromatch';
2
2
  import * as Path from 'path';
3
- import { doesRootContainPath, normalizeGlobPatterns, normalizeGlobToRoot } from './globHelper.mjs';
3
+ import { doesRootContainPath, normalizeGlobPatterns, normalizeGlobToRoot } from './globHelper.js';
4
4
  export class GlobMatcher {
5
5
  constructor(patterns, rootOrOptions, _nodePath) {
6
6
  _nodePath = _nodePath ?? Path;
@@ -99,3 +99,4 @@ function buildMatcherFn(patterns, options) {
99
99
  };
100
100
  return fn;
101
101
  }
102
+ //# sourceMappingURL=GlobMatcher.js.map
@@ -0,0 +1,3 @@
1
+ // cspell:ignore fname
2
+ export {};
3
+ //# sourceMappingURL=GlobMatcherTypes.js.map
@@ -255,3 +255,4 @@ export const __testing__ = {
255
255
  trimGlob,
256
256
  isGlobalGlob,
257
257
  };
258
+ //# sourceMappingURL=globHelper.js.map
@@ -0,0 +1,4 @@
1
+ export { fileOrGlobToGlob, isGlobPatternNormalized, isGlobPatternWithOptionalRoot, isGlobPatternWithRoot, normalizeGlobPatterns, } from './globHelper.js';
2
+ export { GlobMatcher } from './GlobMatcher.js';
3
+ export * from './GlobMatcherTypes.js';
4
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-glob",
3
- "version": "7.0.2",
3
+ "version": "7.2.0",
4
4
  "description": "Glob matcher for cspell",
5
5
  "keywords": [
6
6
  "cspell",
@@ -9,21 +9,17 @@
9
9
  "author": "Jason Dent <jason@streetsidesoftware.nl>",
10
10
  "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-glob#readme",
11
11
  "license": "MIT",
12
- "type": "commonjs",
13
- "main": "dist/cjs/index.js",
14
- "types": "dist/cjs/index.d.ts",
15
- "module": "dist/esm/index.mjs",
12
+ "type": "module",
13
+ "types": "dist/esm/index.d.ts",
14
+ "module": "dist/esm/index.js",
16
15
  "exports": {
17
16
  ".": {
18
- "import": "./dist/esm/index.mjs",
19
- "require": "./dist/cjs/index.js"
17
+ "import": "./dist/esm/index.js"
20
18
  }
21
19
  },
22
20
  "files": [
23
21
  "bin.mjs",
24
22
  "dist",
25
- "!dist/esm/**/*.js",
26
- "!dist/esm/**/*.ts",
27
23
  "!**/*.tsbuildInfo",
28
24
  "!**/__mocks__",
29
25
  "!**/test/**",
@@ -33,7 +29,7 @@
33
29
  ],
34
30
  "scripts": {
35
31
  "clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
36
- "build": "tsc -b . && ts2mjs dist/esm",
32
+ "build": "tsc -b .",
37
33
  "build:esm": "tsc -p tsconfig.esm.json",
38
34
  "clean-build": "pnpm run clean && pnpm run build",
39
35
  "coverage": "vitest run --coverage",
@@ -57,5 +53,5 @@
57
53
  "devDependencies": {
58
54
  "@types/micromatch": "^4.0.2"
59
55
  },
60
- "gitHead": "25aa083421fc81e4d5b7cedb4755f9b327120cfc"
56
+ "gitHead": "b08f7ddc3a4aa22cc80c69ca6638b2a943659a31"
61
57
  }
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.GlobMatcher = void 0;
30
- const micromatch_1 = __importDefault(require("micromatch"));
31
- const Path = __importStar(require("path"));
32
- const globHelper_js_1 = require("./globHelper.js");
33
- class GlobMatcher {
34
- constructor(patterns, rootOrOptions, _nodePath) {
35
- _nodePath = _nodePath ?? Path;
36
- const options = typeof rootOrOptions === 'string' ? { root: rootOrOptions } : rootOrOptions ?? {};
37
- const { mode = 'exclude' } = options;
38
- const isExcludeMode = mode !== 'include';
39
- _nodePath = options.nodePath ?? _nodePath;
40
- const { root = _nodePath.resolve(), dot = isExcludeMode, nodePath = _nodePath, nested = isExcludeMode, cwd = process.cwd(), nobrace, } = options;
41
- const normalizedRoot = nodePath.resolve(nodePath.normalize(root));
42
- this.options = { root: normalizedRoot, dot, nodePath, nested, mode, nobrace, cwd };
43
- patterns = Array.isArray(patterns)
44
- ? patterns
45
- : typeof patterns === 'string'
46
- ? patterns.split(/\r?\n/g)
47
- : [patterns];
48
- const globPatterns = (0, globHelper_js_1.normalizeGlobPatterns)(patterns, this.options);
49
- this.patternsNormalizedToRoot = globPatterns
50
- .map((g) => (0, globHelper_js_1.normalizeGlobToRoot)(g, normalizedRoot, nodePath))
51
- // Only keep globs that do not match the root when using exclude mode.
52
- .filter((g) => nodePath.relative(g.root, normalizedRoot) === '');
53
- this.patterns = globPatterns;
54
- this.root = normalizedRoot;
55
- this.path = nodePath;
56
- this.dot = dot;
57
- this.matchEx = buildMatcherFn(this.patterns, this.options);
58
- }
59
- /**
60
- * Check to see if a filename matches any of the globs.
61
- * If filename is relative, it is considered relative to the root.
62
- * If filename is absolute and contained within the root, it will be made relative before being tested for a glob match.
63
- * If filename is absolute and not contained within the root, it will be tested as is.
64
- * @param filename full path of the file to check.
65
- */
66
- match(filename) {
67
- return this.matchEx(filename).matched;
68
- }
69
- }
70
- exports.GlobMatcher = GlobMatcher;
71
- /**
72
- * This function attempts to emulate .gitignore functionality as much as possible.
73
- *
74
- * The resulting matcher function: (filename: string) => GlobMatch
75
- *
76
- * If filename is relative, it is considered relative to the root.
77
- * If filename is absolute and contained within the root, it will be made relative before being tested for a glob match.
78
- * If filename is absolute and not contained within the root, it will return a GlobMatchNoRule.
79
- *
80
- * @param patterns - the contents of a .gitignore style file or an array of individual glob rules.
81
- * @param options - defines root and other options
82
- * @returns a function given a filename returns true if it matches.
83
- */
84
- function buildMatcherFn(patterns, options) {
85
- const { nodePath: path, dot, nobrace } = options;
86
- const makeReOptions = { dot, nobrace };
87
- const rules = patterns
88
- .map((pattern, index) => ({ pattern, index }))
89
- .filter((r) => !!r.pattern.glob)
90
- .filter((r) => !r.pattern.glob.startsWith('#'))
91
- .map(({ pattern, index }) => {
92
- const matchNeg = pattern.glob.match(/^!/);
93
- const glob = pattern.glob.replace(/^!/, '');
94
- const isNeg = (matchNeg && matchNeg[0].length & 1 && true) || false;
95
- const reg = micromatch_1.default.makeRe(glob, makeReOptions);
96
- const fn = (filename) => {
97
- const match = filename.match(reg);
98
- return !!match;
99
- };
100
- return { pattern, index, isNeg, fn, reg };
101
- });
102
- const negRules = rules.filter((r) => r.isNeg);
103
- const posRules = rules.filter((r) => !r.isNeg);
104
- const fn = (filename) => {
105
- filename = path.resolve(path.normalize(filename));
106
- function testRules(rules, matched) {
107
- for (const rule of rules) {
108
- const pattern = rule.pattern;
109
- const root = pattern.root;
110
- const isRelPat = !pattern.isGlobalPattern;
111
- if (isRelPat && !(0, globHelper_js_1.doesRootContainPath)(root, filename, path)) {
112
- continue;
113
- }
114
- const relName = isRelPat ? path.relative(root, filename) : filename;
115
- const fname = path.sep === '\\' ? relName.replace(/\\/g, '/') : relName;
116
- if (rule.fn(fname)) {
117
- return {
118
- matched,
119
- glob: pattern.glob,
120
- root,
121
- pattern,
122
- index: rule.index,
123
- isNeg: rule.isNeg,
124
- };
125
- }
126
- }
127
- }
128
- return testRules(negRules, false) || testRules(posRules, true) || { matched: false };
129
- };
130
- return fn;
131
- }
132
- //# sourceMappingURL=GlobMatcher.js.map
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // cspell:ignore fname
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- //# sourceMappingURL=GlobMatcherTypes.js.map
@@ -1,292 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.__testing__ = exports.normalizeGlobToRoot = exports.normalizeGlobPattern = exports.normalizeGlobPatterns = exports.isGlobPatternNormalized = exports.isGlobPatternWithRoot = exports.isGlobPatternWithOptionalRoot = exports.doesRootContainPath = exports.fileOrGlobToGlob = void 0;
27
- /* eslint-disable no-irregular-whitespace */
28
- const Path = __importStar(require("path"));
29
- const { posix } = Path;
30
- const relRegExp = /^\.[\\/]/;
31
- /** test for glob patterns starting with `**` */
32
- const isGlobalPatternRegExp = /^!*[*]{2}/;
33
- /**
34
- * This function tries its best to determine if `fileOrGlob` is a path to a file or a glob pattern.
35
- * @param fileOrGlob - file (with absolute path) or glob.
36
- * @param root - absolute path to the directory that will be considered the root when testing the glob pattern.
37
- * @param path - optional node path methods - used for testing
38
- */
39
- function fileOrGlobToGlob(fileOrGlob, root, path = Path) {
40
- const pathToGlob = path.sep === '\\' ? (p) => p.replace(/\\/g, '/') : (p) => p;
41
- const isGlobalPattern = false;
42
- if (isGlobPatternWithOptionalRoot(fileOrGlob)) {
43
- const useRoot = fileOrGlob.root ?? root;
44
- const isGlobalPattern = isGlobPatternWithRoot(fileOrGlob)
45
- ? fileOrGlob.isGlobalPattern
46
- : isGlobalGlob(fileOrGlob.glob);
47
- return { ...fileOrGlob, root: useRoot, isGlobalPattern };
48
- }
49
- if (doesRootContainPath(root, fileOrGlob, path) || relRegExp.test(fileOrGlob)) {
50
- const rel = path.relative(root, path.resolve(root, fileOrGlob));
51
- return { glob: pathToGlob(rel), root, isGlobalPattern };
52
- }
53
- return { glob: pathToGlob(fileOrGlob), root, isGlobalPattern };
54
- }
55
- exports.fileOrGlobToGlob = fileOrGlobToGlob;
56
- /**
57
- * Decide if a childPath is contained within a root or at the same level.
58
- * @param root - absolute path
59
- * @param childPath - absolute path
60
- */
61
- function doesRootContainPath(root, child, path) {
62
- if (child.startsWith(root))
63
- return true;
64
- const rel = path.relative(root, child);
65
- return !rel || (rel !== child && !rel.startsWith('..') && !path.isAbsolute(rel));
66
- }
67
- exports.doesRootContainPath = doesRootContainPath;
68
- function isGlobPatternWithOptionalRoot(g) {
69
- return typeof g !== 'string' && typeof g.glob === 'string';
70
- }
71
- exports.isGlobPatternWithOptionalRoot = isGlobPatternWithOptionalRoot;
72
- function isGlobPatternWithRoot(g) {
73
- return typeof g.root === 'string' && 'isGlobalPattern' in g;
74
- }
75
- exports.isGlobPatternWithRoot = isGlobPatternWithRoot;
76
- function isGlobPatternNormalized(g) {
77
- if (!isGlobPatternWithOptionalRoot(g))
78
- return false;
79
- if (!isGlobPatternWithRoot(g))
80
- return false;
81
- const gr = g;
82
- return 'rawGlob' in gr && 'rawRoot' in gr && typeof gr.rawGlob === 'string';
83
- }
84
- exports.isGlobPatternNormalized = isGlobPatternNormalized;
85
- /**
86
- * @param pattern glob pattern
87
- * @param nested when true add `**​/<glob>/​**`
88
- * @returns the set of matching globs.
89
- */
90
- function normalizePattern(pattern, nested) {
91
- pattern = pattern.replace(/^(!!)+/, '');
92
- const isNeg = pattern.startsWith('!');
93
- const prefix = isNeg ? '!' : '';
94
- pattern = isNeg ? pattern.slice(1) : pattern;
95
- const patterns = nested ? normalizePatternNested(pattern) : normalizePatternGeneral(pattern);
96
- return patterns.map((p) => prefix + p);
97
- }
98
- function normalizePatternNested(pattern) {
99
- // no slashes will match files names or folders
100
- if (!pattern.includes('/')) {
101
- if (pattern === '**')
102
- return ['**'];
103
- return ['**/' + pattern, '**/' + pattern + '/**'];
104
- }
105
- const hasLeadingSlash = pattern.startsWith('/');
106
- pattern = hasLeadingSlash ? pattern.slice(1) : pattern;
107
- if (pattern.endsWith('/')) {
108
- // legacy behavior, if it only has a trailing slash, allow matching against a nested directory.
109
- return hasLeadingSlash || pattern.slice(0, -1).includes('/') ? [pattern + '**/*'] : ['**/' + pattern + '**/*'];
110
- }
111
- if (pattern.endsWith('**')) {
112
- return [pattern];
113
- }
114
- return [pattern, pattern + '/**'];
115
- }
116
- function normalizePatternGeneral(pattern) {
117
- pattern = pattern.startsWith('/') ? pattern.slice(1) : pattern;
118
- pattern = pattern.endsWith('/') ? pattern + '**/*' : pattern;
119
- return [pattern];
120
- }
121
- /**
122
- *
123
- * @param patterns - glob patterns to normalize.
124
- * @param options - Normalization options.
125
- */
126
- function normalizeGlobPatterns(patterns, options) {
127
- function* normalize() {
128
- for (const glob of patterns) {
129
- if (isGlobPatternNormalized(glob)) {
130
- yield glob;
131
- continue;
132
- }
133
- yield* normalizeGlobPattern(glob, options);
134
- }
135
- }
136
- return [...normalize()];
137
- }
138
- exports.normalizeGlobPatterns = normalizeGlobPatterns;
139
- function normalizeGlobPattern(g, options) {
140
- const { root, nodePath: path = Path, nested, cwd = Path.resolve() } = options;
141
- g = !isGlobPatternWithOptionalRoot(g) ? { glob: g } : g;
142
- const gr = { ...g, root: g.root ?? root };
143
- const rawRoot = gr.root;
144
- const rawGlob = g.glob;
145
- gr.glob = gr.glob.trim(); // trimGlob(g.glob);
146
- if (gr.glob.startsWith('${cwd}')) {
147
- gr.glob = gr.glob.replace('${cwd}', '');
148
- gr.root = '${cwd}';
149
- }
150
- if (gr.root.startsWith('${cwd}')) {
151
- gr.root = path.resolve(gr.root.replace('${cwd}', cwd));
152
- }
153
- const isGlobalPattern = isGlobalGlob(gr.glob);
154
- gr.root = path.resolve(root, path.normalize(gr.root));
155
- const globs = normalizePattern(gr.glob, nested);
156
- return globs.map((glob) => ({ ...gr, glob, rawGlob, rawRoot, isGlobalPattern }));
157
- }
158
- exports.normalizeGlobPattern = normalizeGlobPattern;
159
- /**
160
- * Try to adjust the root of a glob to match a new root. If it is not possible, the original glob is returned.
161
- * Note: this does NOT generate absolutely correct glob patterns. The results are intended to be used as a
162
- * first pass only filter. Followed by testing against the original glob/root pair.
163
- * @param glob - glob to map
164
- * @param root - new root to use if possible
165
- * @param path - Node Path modules to use (testing only)
166
- */
167
- function normalizeGlobToRoot(glob, root, path) {
168
- function relToGlob(relativePath) {
169
- return path.sep === '\\' ? relativePath.replace(/\\/g, '/') : relativePath;
170
- }
171
- if (glob.root === root) {
172
- return glob;
173
- }
174
- const relFromRootToGlob = path.relative(root, glob.root);
175
- if (!relFromRootToGlob) {
176
- return glob;
177
- }
178
- if (glob.isGlobalPattern) {
179
- return { ...glob, root };
180
- }
181
- const relFromGlobToRoot = path.relative(glob.root, root);
182
- const globIsUnderRoot = relFromRootToGlob[0] !== '.' && !path.isAbsolute(relFromRootToGlob);
183
- const rootIsUnderGlob = relFromGlobToRoot[0] !== '.' && !path.isAbsolute(relFromGlobToRoot);
184
- // Root and Glob are not in the same part of the directory tree.
185
- if (!globIsUnderRoot && !rootIsUnderGlob) {
186
- return glob;
187
- }
188
- const isNeg = glob.glob.startsWith('!');
189
- const g = isNeg ? glob.glob.slice(1) : glob.glob;
190
- const prefix = isNeg ? '!' : '';
191
- // prefix with root
192
- if (globIsUnderRoot) {
193
- const relGlob = relToGlob(relFromRootToGlob);
194
- return {
195
- ...glob,
196
- glob: prefix + posix.join(relGlob, g),
197
- root,
198
- };
199
- }
200
- // The root is under the glob root
201
- // The more difficult case, the glob is higher than the root
202
- // A best effort is made, but does not do advanced matching.
203
- const relGlob = relToGlob(relFromGlobToRoot) + '/';
204
- const rebasedGlob = rebaseGlob(g, relGlob);
205
- return rebasedGlob ? { ...glob, glob: prefix + rebasedGlob, root } : glob;
206
- }
207
- exports.normalizeGlobToRoot = normalizeGlobToRoot;
208
- /**
209
- * Rebase a glob string to a new prefix
210
- * @param glob - glob string
211
- * @param rebaseTo - glob prefix
212
- */
213
- function rebaseGlob(glob, rebaseTo) {
214
- if (!rebaseTo || rebaseTo === '/')
215
- return glob;
216
- if (glob.startsWith('**'))
217
- return glob;
218
- rebaseTo = rebaseTo.endsWith('/') ? rebaseTo : rebaseTo + '/';
219
- if (glob.startsWith(rebaseTo)) {
220
- return glob.slice(rebaseTo.length);
221
- }
222
- const relParts = rebaseTo.split('/');
223
- const globParts = glob.split('/');
224
- for (let i = 0; i < relParts.length && i < globParts.length; ++i) {
225
- const relSeg = relParts[i];
226
- const globSeg = globParts[i];
227
- // the empty segment due to the end relGlob / allows for us to test against an empty segment.
228
- if (!relSeg || globSeg === '**') {
229
- return globParts.slice(i).join('/');
230
- }
231
- if (relSeg !== globSeg && globSeg !== '*') {
232
- break;
233
- }
234
- }
235
- return undefined;
236
- }
237
- /**
238
- * Trims any trailing spaces, tabs, line-feeds, new-lines, and comments
239
- * @param glob - glob string
240
- * @returns trimmed glob
241
- */
242
- function trimGlob(glob) {
243
- glob = glob.replace(/(?<!\\)#.*/g, '');
244
- glob = trimGlobLeft(glob);
245
- glob = trimGlobRight(glob);
246
- return glob;
247
- }
248
- const spaces = {
249
- ' ': true,
250
- '\t': true,
251
- '\n': true,
252
- '\r': true,
253
- };
254
- /**
255
- * Trim any trailing spaces, tabs, line-feeds, or new-lines
256
- * Handles a trailing \<space>
257
- * @param glob - glob string
258
- * @returns glob string with space to the right removed.
259
- */
260
- function trimGlobRight(glob) {
261
- const lenMin1 = glob.length - 1;
262
- let i = lenMin1;
263
- while (i >= 0 && glob[i] in spaces) {
264
- --i;
265
- }
266
- if (glob[i] === '\\' && i < lenMin1) {
267
- ++i;
268
- }
269
- ++i;
270
- return i ? glob.slice(0, i) : '';
271
- }
272
- /**
273
- * Trim any leading spaces, tabs, line-feeds, or new-lines
274
- * @param glob - any string
275
- * @returns string with leading spaces removed.
276
- */
277
- function trimGlobLeft(glob) {
278
- let i = 0;
279
- while (i < glob.length && glob[i] in spaces) {
280
- ++i;
281
- }
282
- return glob.slice(i);
283
- }
284
- function isGlobalGlob(glob) {
285
- return isGlobalPatternRegExp.test(glob);
286
- }
287
- exports.__testing__ = {
288
- rebaseGlob,
289
- trimGlob,
290
- isGlobalGlob,
291
- };
292
- //# sourceMappingURL=globHelper.js.map
package/dist/cjs/index.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.GlobMatcher = exports.normalizeGlobPatterns = exports.isGlobPatternWithRoot = exports.isGlobPatternWithOptionalRoot = exports.isGlobPatternNormalized = exports.fileOrGlobToGlob = void 0;
18
- var globHelper_js_1 = require("./globHelper.js");
19
- Object.defineProperty(exports, "fileOrGlobToGlob", { enumerable: true, get: function () { return globHelper_js_1.fileOrGlobToGlob; } });
20
- Object.defineProperty(exports, "isGlobPatternNormalized", { enumerable: true, get: function () { return globHelper_js_1.isGlobPatternNormalized; } });
21
- Object.defineProperty(exports, "isGlobPatternWithOptionalRoot", { enumerable: true, get: function () { return globHelper_js_1.isGlobPatternWithOptionalRoot; } });
22
- Object.defineProperty(exports, "isGlobPatternWithRoot", { enumerable: true, get: function () { return globHelper_js_1.isGlobPatternWithRoot; } });
23
- Object.defineProperty(exports, "normalizeGlobPatterns", { enumerable: true, get: function () { return globHelper_js_1.normalizeGlobPatterns; } });
24
- var GlobMatcher_js_1 = require("./GlobMatcher.js");
25
- Object.defineProperty(exports, "GlobMatcher", { enumerable: true, get: function () { return GlobMatcher_js_1.GlobMatcher; } });
26
- __exportStar(require("./GlobMatcherTypes.js"), exports);
27
- //# sourceMappingURL=index.js.map
@@ -1,94 +0,0 @@
1
- import type { GlobMatch, GlobPattern, GlobPatternNormalized, GlobPatternWithRoot, PathInterface } from './GlobMatcherTypes.mjs';
2
- type Optional<T> = {
3
- [P in keyof T]?: T[P] | undefined;
4
- };
5
- export type GlobMatchOptions = Optional<NormalizedGlobMatchOptions>;
6
- export type MatcherMode = 'exclude' | 'include';
7
- interface NormalizedGlobMatchOptions {
8
- /**
9
- * The matcher has two modes (`include` or `exclude`) that impact how globs behave.
10
- *
11
- * `include` - designed for searching for file. By default it matches a sub-set of file.
12
- * In include mode, the globs need to be more explicit to match.
13
- * - `dot` is by default false.
14
- * - `nested` is by default false.
15
- *
16
- * `exclude` - designed to emulate `.gitignore`. By default it matches a larger range of files.
17
- * - `dot` is by default true.
18
- * - `nested` is by default true.
19
- *
20
- * @default: 'exclude'
21
- */
22
- mode: MatcherMode;
23
- /**
24
- * The default directory from which a glob is relative.
25
- * Any globs that are not relative to the root will ignored.
26
- * @default: process.cwd()
27
- */
28
- root: string;
29
- /**
30
- * The directory to use as the current working directory.
31
- * @default: process.cwd();
32
- */
33
- cwd: string;
34
- /**
35
- * Allows matching against directories with a leading `.`.
36
- *
37
- * @default: mode == 'exclude'
38
- */
39
- dot: boolean;
40
- /**
41
- * Allows matching against nested directories or files without needing to add `**`
42
- *
43
- * @default: mode == 'exclude'
44
- */
45
- nested: boolean;
46
- /**
47
- * Mostly used for testing purposes. It allows explicitly specifying `path.win32` or `path.posix`.
48
- *
49
- * @default: require('path')
50
- */
51
- nodePath: PathInterface;
52
- /**
53
- * Disable brace matching, so that `{a,b}` and `{1..3}` would be treated as literal characters.
54
- *
55
- * @default false
56
- */
57
- nobrace?: boolean | undefined;
58
- }
59
- export declare class GlobMatcher {
60
- /**
61
- * @param filename full path of file to match against.
62
- * @returns a GlobMatch - information about the match.
63
- */
64
- readonly matchEx: (filename: string) => GlobMatch;
65
- readonly path: PathInterface;
66
- readonly patterns: GlobPatternWithRoot[];
67
- readonly patternsNormalizedToRoot: GlobPatternNormalized[];
68
- readonly root: string;
69
- readonly dot: boolean;
70
- readonly options: NormalizedGlobMatchOptions;
71
- /**
72
- * Construct a `.gitignore` emulator
73
- * @param patterns - the contents of a `.gitignore` style file or an array of individual glob rules.
74
- * @param root - the working directory
75
- */
76
- constructor(patterns: GlobPattern | GlobPattern[], root?: string, nodePath?: PathInterface);
77
- /**
78
- * Construct a `.gitignore` emulator
79
- * @param patterns - the contents of a `.gitignore` style file or an array of individual glob rules.
80
- * @param options - to set the root and other options
81
- */
82
- constructor(patterns: GlobPattern | GlobPattern[], options?: GlobMatchOptions);
83
- constructor(patterns: GlobPattern | GlobPattern[], rootOrOptions?: string | GlobMatchOptions);
84
- /**
85
- * Check to see if a filename matches any of the globs.
86
- * If filename is relative, it is considered relative to the root.
87
- * If filename is absolute and contained within the root, it will be made relative before being tested for a glob match.
88
- * If filename is absolute and not contained within the root, it will be tested as is.
89
- * @param filename full path of the file to check.
90
- */
91
- match(filename: string): boolean;
92
- }
93
- export {};
94
- //# sourceMappingURL=GlobMatcher.d.mts.map
@@ -1,55 +0,0 @@
1
- export interface PathInterface {
2
- normalize(p: string): string;
3
- join(...paths: string[]): string;
4
- resolve(...paths: string[]): string;
5
- relative(from: string, to: string): string;
6
- isAbsolute(p: string): boolean;
7
- sep: string;
8
- }
9
- export type GlobMatch = GlobMatchRule | GlobMatchNoRule;
10
- export interface GlobMatchRule {
11
- matched: boolean;
12
- glob: string;
13
- root: string;
14
- pattern: GlobPatternWithRoot;
15
- index: number;
16
- isNeg: boolean;
17
- }
18
- export interface GlobMatchNoRule {
19
- matched: false;
20
- }
21
- export type GlobPattern = SimpleGlobPattern | GlobPatternWithRoot | GlobPatternWithOptionalRoot;
22
- export type SimpleGlobPattern = string;
23
- export interface GlobPatternWithOptionalRoot {
24
- /**
25
- * a glob pattern
26
- */
27
- glob: string;
28
- /**
29
- * The root from which the glob pattern is relative.
30
- * @default: options.root
31
- */
32
- root?: string | undefined;
33
- /**
34
- * Optional value useful for tracing which file a glob pattern was defined in.
35
- */
36
- source?: string | undefined;
37
- /**
38
- * Optional line number in the source
39
- */
40
- line?: number | undefined;
41
- }
42
- export interface GlobPatternWithRoot extends GlobPatternWithOptionalRoot {
43
- root: string;
44
- /**
45
- * Global patterns do not need to be relative to the root.
46
- */
47
- isGlobalPattern: boolean;
48
- }
49
- export interface GlobPatternNormalized extends GlobPatternWithRoot {
50
- /** the original glob pattern before it was normalized */
51
- rawGlob: string;
52
- /** the original root */
53
- rawRoot: string | undefined;
54
- }
55
- //# sourceMappingURL=GlobMatcherTypes.d.mts.map
@@ -1,2 +0,0 @@
1
- // cspell:ignore fname
2
- export {};
@@ -1,73 +0,0 @@
1
- import type { GlobPattern, GlobPatternNormalized, GlobPatternWithOptionalRoot, GlobPatternWithRoot, PathInterface } from './GlobMatcherTypes.mjs';
2
- /**
3
- * This function tries its best to determine if `fileOrGlob` is a path to a file or a glob pattern.
4
- * @param fileOrGlob - file (with absolute path) or glob.
5
- * @param root - absolute path to the directory that will be considered the root when testing the glob pattern.
6
- * @param path - optional node path methods - used for testing
7
- */
8
- export declare function fileOrGlobToGlob(fileOrGlob: string | GlobPattern, root: string, path?: PathInterface): GlobPatternWithRoot;
9
- /**
10
- * Decide if a childPath is contained within a root or at the same level.
11
- * @param root - absolute path
12
- * @param childPath - absolute path
13
- */
14
- export declare function doesRootContainPath(root: string, child: string, path: PathInterface): boolean;
15
- export declare function isGlobPatternWithOptionalRoot(g: GlobPattern): g is GlobPatternWithOptionalRoot;
16
- export declare function isGlobPatternWithRoot(g: GlobPatternWithRoot | GlobPatternWithOptionalRoot): g is GlobPatternWithRoot;
17
- export declare function isGlobPatternNormalized(g: GlobPattern | GlobPatternNormalized): g is GlobPatternNormalized;
18
- export interface NormalizeOptions {
19
- /**
20
- * Indicates that the glob should be modified to match nested patterns.
21
- *
22
- * Example: `node_modules` becomes `**​/node_modules/​**`, `**​/node_modules`, and `node_modules/​**`
23
- */
24
- nested: boolean;
25
- /**
26
- * This is the root to use for the glob if the glob does not already contain one.
27
- */
28
- root: string;
29
- /**
30
- * This is the replacement for `${cwd}` in either the root or in the glob.
31
- */
32
- cwd?: string;
33
- /**
34
- * Optional path interface for working with paths.
35
- */
36
- nodePath?: PathInterface;
37
- }
38
- /**
39
- *
40
- * @param patterns - glob patterns to normalize.
41
- * @param options - Normalization options.
42
- */
43
- export declare function normalizeGlobPatterns(patterns: GlobPattern[], options: NormalizeOptions): GlobPatternNormalized[];
44
- export declare function normalizeGlobPattern(g: GlobPattern, options: NormalizeOptions): GlobPatternNormalized[];
45
- /**
46
- * Try to adjust the root of a glob to match a new root. If it is not possible, the original glob is returned.
47
- * Note: this does NOT generate absolutely correct glob patterns. The results are intended to be used as a
48
- * first pass only filter. Followed by testing against the original glob/root pair.
49
- * @param glob - glob to map
50
- * @param root - new root to use if possible
51
- * @param path - Node Path modules to use (testing only)
52
- */
53
- export declare function normalizeGlobToRoot<Glob extends GlobPatternWithRoot>(glob: Glob, root: string, path: PathInterface): Glob;
54
- /**
55
- * Rebase a glob string to a new prefix
56
- * @param glob - glob string
57
- * @param rebaseTo - glob prefix
58
- */
59
- declare function rebaseGlob(glob: string, rebaseTo: string): string | undefined;
60
- /**
61
- * Trims any trailing spaces, tabs, line-feeds, new-lines, and comments
62
- * @param glob - glob string
63
- * @returns trimmed glob
64
- */
65
- declare function trimGlob(glob: string): string;
66
- declare function isGlobalGlob(glob: string): boolean;
67
- export declare const __testing__: {
68
- rebaseGlob: typeof rebaseGlob;
69
- trimGlob: typeof trimGlob;
70
- isGlobalGlob: typeof isGlobalGlob;
71
- };
72
- export {};
73
- //# sourceMappingURL=globHelper.d.mts.map
@@ -1,4 +0,0 @@
1
- export { fileOrGlobToGlob, isGlobPatternNormalized, isGlobPatternWithOptionalRoot, isGlobPatternWithRoot, normalizeGlobPatterns, NormalizeOptions, } from './globHelper.mjs';
2
- export { GlobMatcher, GlobMatchOptions } from './GlobMatcher.mjs';
3
- export * from './GlobMatcherTypes.mjs';
4
- //# sourceMappingURL=index.d.mts.map
@@ -1,3 +0,0 @@
1
- export { fileOrGlobToGlob, isGlobPatternNormalized, isGlobPatternWithOptionalRoot, isGlobPatternWithRoot, normalizeGlobPatterns, } from './globHelper.mjs';
2
- export { GlobMatcher } from './GlobMatcher.mjs';
3
- export * from './GlobMatcherTypes.mjs';
File without changes
File without changes
File without changes
File without changes