@catheadowl/pathscope 0.0.0-stage → 0.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/CHANGELOG.md +90 -0
- package/LICENSE +21 -0
- package/README.md +127 -2
- package/dist/cascade.d.ts +16 -0
- package/dist/cascade.js +69 -0
- package/dist/cascade.js.map +1 -0
- package/dist/cjs/cascade.d.ts +16 -0
- package/dist/cjs/discover.d.ts +11 -0
- package/dist/cjs/engine.d.ts +6 -0
- package/dist/cjs/exclusion-engine.d.ts +79 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +2102 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/paths.d.ts +13 -0
- package/dist/cjs/presets.d.ts +28 -0
- package/dist/cjs/types.d.ts +235 -0
- package/dist/cjs/universe.d.ts +27 -0
- package/dist/discover.d.ts +11 -0
- package/dist/discover.js +66 -0
- package/dist/discover.js.map +1 -0
- package/dist/engine.d.ts +6 -0
- package/dist/engine.js +117 -0
- package/dist/engine.js.map +1 -0
- package/dist/exclusion-engine.d.ts +79 -0
- package/dist/exclusion-engine.js +352 -0
- package/dist/exclusion-engine.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +13 -0
- package/dist/paths.js +28 -0
- package/dist/paths.js.map +1 -0
- package/dist/presets.d.ts +28 -0
- package/dist/presets.js +77 -0
- package/dist/presets.js.map +1 -0
- package/dist/types.d.ts +235 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/universe.d.ts +27 -0
- package/dist/universe.js +219 -0
- package/dist/universe.js.map +1 -0
- package/docs/glossary.md +59 -0
- package/docs/semantics.md +73 -0
- package/package.json +53 -4
|
@@ -0,0 +1,2102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
try {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw mod = 0, e;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// node_modules/.pnpm/fdir@6.5.0/node_modules/fdir/dist/index.cjs
|
|
38
|
+
var require_dist = __commonJS({
|
|
39
|
+
"node_modules/.pnpm/fdir@6.5.0/node_modules/fdir/dist/index.cjs"(exports2) {
|
|
40
|
+
var __create2 = Object.create;
|
|
41
|
+
var __defProp2 = Object.defineProperty;
|
|
42
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
43
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
44
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
45
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
46
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
47
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
48
|
+
key = keys[i];
|
|
49
|
+
if (!__hasOwnProp2.call(to, key) && key !== except) __defProp2(to, key, {
|
|
50
|
+
get: ((k) => from[k]).bind(null, key),
|
|
51
|
+
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return to;
|
|
55
|
+
};
|
|
56
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", {
|
|
57
|
+
value: mod,
|
|
58
|
+
enumerable: true
|
|
59
|
+
}) : target, mod));
|
|
60
|
+
var path3 = __toESM2(require("path"));
|
|
61
|
+
var fs2 = __toESM2(require("fs"));
|
|
62
|
+
function cleanPath(path$1) {
|
|
63
|
+
let normalized = (0, path3.normalize)(path$1);
|
|
64
|
+
if (normalized.length > 1 && normalized[normalized.length - 1] === path3.sep) normalized = normalized.substring(0, normalized.length - 1);
|
|
65
|
+
return normalized;
|
|
66
|
+
}
|
|
67
|
+
var SLASHES_REGEX = /[\\/]/g;
|
|
68
|
+
function convertSlashes(path$1, separator) {
|
|
69
|
+
return path$1.replace(SLASHES_REGEX, separator);
|
|
70
|
+
}
|
|
71
|
+
var WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
|
72
|
+
function isRootDirectory(path$1) {
|
|
73
|
+
return path$1 === "/" || WINDOWS_ROOT_DIR_REGEX.test(path$1);
|
|
74
|
+
}
|
|
75
|
+
function normalizePath(path$1, options) {
|
|
76
|
+
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
|
77
|
+
const pathNeedsCleaning = process.platform === "win32" && path$1.includes("/") || path$1.startsWith(".");
|
|
78
|
+
if (resolvePaths) path$1 = (0, path3.resolve)(path$1);
|
|
79
|
+
if (normalizePath$1 || pathNeedsCleaning) path$1 = cleanPath(path$1);
|
|
80
|
+
if (path$1 === ".") return "";
|
|
81
|
+
const needsSeperator = path$1[path$1.length - 1] !== pathSeparator;
|
|
82
|
+
return convertSlashes(needsSeperator ? path$1 + pathSeparator : path$1, pathSeparator);
|
|
83
|
+
}
|
|
84
|
+
function joinPathWithBasePath(filename, directoryPath) {
|
|
85
|
+
return directoryPath + filename;
|
|
86
|
+
}
|
|
87
|
+
function joinPathWithRelativePath(root, options) {
|
|
88
|
+
return function(filename, directoryPath) {
|
|
89
|
+
const sameRoot = directoryPath.startsWith(root);
|
|
90
|
+
if (sameRoot) return directoryPath.slice(root.length) + filename;
|
|
91
|
+
else return convertSlashes((0, path3.relative)(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function joinPath(filename) {
|
|
95
|
+
return filename;
|
|
96
|
+
}
|
|
97
|
+
function joinDirectoryPath(filename, directoryPath, separator) {
|
|
98
|
+
return directoryPath + filename + separator;
|
|
99
|
+
}
|
|
100
|
+
function build$7(root, options) {
|
|
101
|
+
const { relativePaths, includeBasePath } = options;
|
|
102
|
+
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
|
103
|
+
}
|
|
104
|
+
function pushDirectoryWithRelativePath(root) {
|
|
105
|
+
return function(directoryPath, paths) {
|
|
106
|
+
paths.push(directoryPath.substring(root.length) || ".");
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function pushDirectoryFilterWithRelativePath(root) {
|
|
110
|
+
return function(directoryPath, paths, filters) {
|
|
111
|
+
const relativePath = directoryPath.substring(root.length) || ".";
|
|
112
|
+
if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
var pushDirectory = (directoryPath, paths) => {
|
|
116
|
+
paths.push(directoryPath || ".");
|
|
117
|
+
};
|
|
118
|
+
var pushDirectoryFilter = (directoryPath, paths, filters) => {
|
|
119
|
+
const path$1 = directoryPath || ".";
|
|
120
|
+
if (filters.every((filter) => filter(path$1, true))) paths.push(path$1);
|
|
121
|
+
};
|
|
122
|
+
var empty$2 = () => {
|
|
123
|
+
};
|
|
124
|
+
function build$6(root, options) {
|
|
125
|
+
const { includeDirs, filters, relativePaths } = options;
|
|
126
|
+
if (!includeDirs) return empty$2;
|
|
127
|
+
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
|
128
|
+
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
|
129
|
+
}
|
|
130
|
+
var pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
|
131
|
+
if (filters.every((filter) => filter(filename, false))) counts.files++;
|
|
132
|
+
};
|
|
133
|
+
var pushFileFilter = (filename, paths, _counts, filters) => {
|
|
134
|
+
if (filters.every((filter) => filter(filename, false))) paths.push(filename);
|
|
135
|
+
};
|
|
136
|
+
var pushFileCount = (_filename, _paths, counts, _filters) => {
|
|
137
|
+
counts.files++;
|
|
138
|
+
};
|
|
139
|
+
var pushFile = (filename, paths) => {
|
|
140
|
+
paths.push(filename);
|
|
141
|
+
};
|
|
142
|
+
var empty$1 = () => {
|
|
143
|
+
};
|
|
144
|
+
function build$5(options) {
|
|
145
|
+
const { excludeFiles, filters, onlyCounts } = options;
|
|
146
|
+
if (excludeFiles) return empty$1;
|
|
147
|
+
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
|
148
|
+
else if (onlyCounts) return pushFileCount;
|
|
149
|
+
else return pushFile;
|
|
150
|
+
}
|
|
151
|
+
var getArray = (paths) => {
|
|
152
|
+
return paths;
|
|
153
|
+
};
|
|
154
|
+
var getArrayGroup = () => {
|
|
155
|
+
return [""].slice(0, 0);
|
|
156
|
+
};
|
|
157
|
+
function build$4(options) {
|
|
158
|
+
return options.group ? getArrayGroup : getArray;
|
|
159
|
+
}
|
|
160
|
+
var groupFiles = (groups, directory, files) => {
|
|
161
|
+
groups.push({
|
|
162
|
+
directory,
|
|
163
|
+
files,
|
|
164
|
+
dir: directory
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
var empty = () => {
|
|
168
|
+
};
|
|
169
|
+
function build$3(options) {
|
|
170
|
+
return options.group ? groupFiles : empty;
|
|
171
|
+
}
|
|
172
|
+
var resolveSymlinksAsync = function(path$1, state, callback$1) {
|
|
173
|
+
const { queue, fs: fs$1, options: { suppressErrors } } = state;
|
|
174
|
+
queue.enqueue();
|
|
175
|
+
fs$1.realpath(path$1, (error, resolvedPath) => {
|
|
176
|
+
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
|
177
|
+
fs$1.stat(resolvedPath, (error$1, stat) => {
|
|
178
|
+
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
|
179
|
+
if (stat.isDirectory() && isRecursive(path$1, resolvedPath, state)) return queue.dequeue(null, state);
|
|
180
|
+
callback$1(stat, resolvedPath);
|
|
181
|
+
queue.dequeue(null, state);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
var resolveSymlinks = function(path$1, state, callback$1) {
|
|
186
|
+
const { queue, fs: fs$1, options: { suppressErrors } } = state;
|
|
187
|
+
queue.enqueue();
|
|
188
|
+
try {
|
|
189
|
+
const resolvedPath = fs$1.realpathSync(path$1);
|
|
190
|
+
const stat = fs$1.statSync(resolvedPath);
|
|
191
|
+
if (stat.isDirectory() && isRecursive(path$1, resolvedPath, state)) return;
|
|
192
|
+
callback$1(stat, resolvedPath);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
if (!suppressErrors) throw e;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
function build$2(options, isSynchronous) {
|
|
198
|
+
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
|
199
|
+
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
|
200
|
+
}
|
|
201
|
+
function isRecursive(path$1, resolved, state) {
|
|
202
|
+
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
|
203
|
+
let parent = (0, path3.dirname)(path$1);
|
|
204
|
+
let depth = 1;
|
|
205
|
+
while (parent !== state.root && depth < 2) {
|
|
206
|
+
const resolvedPath = state.symlinks.get(parent);
|
|
207
|
+
const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
|
|
208
|
+
if (isSameRoot) depth++;
|
|
209
|
+
else parent = (0, path3.dirname)(parent);
|
|
210
|
+
}
|
|
211
|
+
state.symlinks.set(path$1, resolved);
|
|
212
|
+
return depth > 1;
|
|
213
|
+
}
|
|
214
|
+
function isRecursiveUsingRealPaths(resolved, state) {
|
|
215
|
+
return state.visited.includes(resolved + state.options.pathSeparator);
|
|
216
|
+
}
|
|
217
|
+
var onlyCountsSync = (state) => {
|
|
218
|
+
return state.counts;
|
|
219
|
+
};
|
|
220
|
+
var groupsSync = (state) => {
|
|
221
|
+
return state.groups;
|
|
222
|
+
};
|
|
223
|
+
var defaultSync = (state) => {
|
|
224
|
+
return state.paths;
|
|
225
|
+
};
|
|
226
|
+
var limitFilesSync = (state) => {
|
|
227
|
+
return state.paths.slice(0, state.options.maxFiles);
|
|
228
|
+
};
|
|
229
|
+
var onlyCountsAsync = (state, error, callback$1) => {
|
|
230
|
+
report(error, callback$1, state.counts, state.options.suppressErrors);
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
233
|
+
var defaultAsync = (state, error, callback$1) => {
|
|
234
|
+
report(error, callback$1, state.paths, state.options.suppressErrors);
|
|
235
|
+
return null;
|
|
236
|
+
};
|
|
237
|
+
var limitFilesAsync = (state, error, callback$1) => {
|
|
238
|
+
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
|
239
|
+
return null;
|
|
240
|
+
};
|
|
241
|
+
var groupsAsync = (state, error, callback$1) => {
|
|
242
|
+
report(error, callback$1, state.groups, state.options.suppressErrors);
|
|
243
|
+
return null;
|
|
244
|
+
};
|
|
245
|
+
function report(error, callback$1, output, suppressErrors) {
|
|
246
|
+
if (error && !suppressErrors) callback$1(error, output);
|
|
247
|
+
else callback$1(null, output);
|
|
248
|
+
}
|
|
249
|
+
function build$1(options, isSynchronous) {
|
|
250
|
+
const { onlyCounts, group, maxFiles } = options;
|
|
251
|
+
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
|
252
|
+
else if (group) return isSynchronous ? groupsSync : groupsAsync;
|
|
253
|
+
else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
|
254
|
+
else return isSynchronous ? defaultSync : defaultAsync;
|
|
255
|
+
}
|
|
256
|
+
var readdirOpts = { withFileTypes: true };
|
|
257
|
+
var walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
|
258
|
+
state.queue.enqueue();
|
|
259
|
+
if (currentDepth < 0) return state.queue.dequeue(null, state);
|
|
260
|
+
const { fs: fs$1 } = state;
|
|
261
|
+
state.visited.push(crawlPath);
|
|
262
|
+
state.counts.directories++;
|
|
263
|
+
fs$1.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
|
|
264
|
+
callback$1(entries, directoryPath, currentDepth);
|
|
265
|
+
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
var walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
|
269
|
+
const { fs: fs$1 } = state;
|
|
270
|
+
if (currentDepth < 0) return;
|
|
271
|
+
state.visited.push(crawlPath);
|
|
272
|
+
state.counts.directories++;
|
|
273
|
+
let entries = [];
|
|
274
|
+
try {
|
|
275
|
+
entries = fs$1.readdirSync(crawlPath || ".", readdirOpts);
|
|
276
|
+
} catch (e) {
|
|
277
|
+
if (!state.options.suppressErrors) throw e;
|
|
278
|
+
}
|
|
279
|
+
callback$1(entries, directoryPath, currentDepth);
|
|
280
|
+
};
|
|
281
|
+
function build(isSynchronous) {
|
|
282
|
+
return isSynchronous ? walkSync : walkAsync;
|
|
283
|
+
}
|
|
284
|
+
var Queue = class {
|
|
285
|
+
count = 0;
|
|
286
|
+
constructor(onQueueEmpty) {
|
|
287
|
+
this.onQueueEmpty = onQueueEmpty;
|
|
288
|
+
}
|
|
289
|
+
enqueue() {
|
|
290
|
+
this.count++;
|
|
291
|
+
return this.count;
|
|
292
|
+
}
|
|
293
|
+
dequeue(error, output) {
|
|
294
|
+
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
|
295
|
+
this.onQueueEmpty(error, output);
|
|
296
|
+
if (error) {
|
|
297
|
+
output.controller.abort();
|
|
298
|
+
this.onQueueEmpty = void 0;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var Counter = class {
|
|
304
|
+
_files = 0;
|
|
305
|
+
_directories = 0;
|
|
306
|
+
set files(num) {
|
|
307
|
+
this._files = num;
|
|
308
|
+
}
|
|
309
|
+
get files() {
|
|
310
|
+
return this._files;
|
|
311
|
+
}
|
|
312
|
+
set directories(num) {
|
|
313
|
+
this._directories = num;
|
|
314
|
+
}
|
|
315
|
+
get directories() {
|
|
316
|
+
return this._directories;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @deprecated use `directories` instead
|
|
320
|
+
*/
|
|
321
|
+
/* c8 ignore next 3 */
|
|
322
|
+
get dirs() {
|
|
323
|
+
return this._directories;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
var Aborter = class {
|
|
327
|
+
aborted = false;
|
|
328
|
+
abort() {
|
|
329
|
+
this.aborted = true;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var Walker = class {
|
|
333
|
+
root;
|
|
334
|
+
isSynchronous;
|
|
335
|
+
state;
|
|
336
|
+
joinPath;
|
|
337
|
+
pushDirectory;
|
|
338
|
+
pushFile;
|
|
339
|
+
getArray;
|
|
340
|
+
groupFiles;
|
|
341
|
+
resolveSymlink;
|
|
342
|
+
walkDirectory;
|
|
343
|
+
callbackInvoker;
|
|
344
|
+
constructor(root, options, callback$1) {
|
|
345
|
+
this.isSynchronous = !callback$1;
|
|
346
|
+
this.callbackInvoker = build$1(options, this.isSynchronous);
|
|
347
|
+
this.root = normalizePath(root, options);
|
|
348
|
+
this.state = {
|
|
349
|
+
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
|
350
|
+
paths: [""].slice(0, 0),
|
|
351
|
+
groups: [],
|
|
352
|
+
counts: new Counter(),
|
|
353
|
+
options,
|
|
354
|
+
queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
|
|
355
|
+
symlinks: /* @__PURE__ */ new Map(),
|
|
356
|
+
visited: [""].slice(0, 0),
|
|
357
|
+
controller: new Aborter(),
|
|
358
|
+
fs: options.fs || fs2
|
|
359
|
+
};
|
|
360
|
+
this.joinPath = build$7(this.root, options);
|
|
361
|
+
this.pushDirectory = build$6(this.root, options);
|
|
362
|
+
this.pushFile = build$5(options);
|
|
363
|
+
this.getArray = build$4(options);
|
|
364
|
+
this.groupFiles = build$3(options);
|
|
365
|
+
this.resolveSymlink = build$2(options, this.isSynchronous);
|
|
366
|
+
this.walkDirectory = build(this.isSynchronous);
|
|
367
|
+
}
|
|
368
|
+
start() {
|
|
369
|
+
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
|
370
|
+
this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
|
|
371
|
+
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
|
|
372
|
+
}
|
|
373
|
+
walk = (entries, directoryPath, depth) => {
|
|
374
|
+
const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
|
375
|
+
if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
|
376
|
+
const files = this.getArray(this.state.paths);
|
|
377
|
+
for (let i = 0; i < entries.length; ++i) {
|
|
378
|
+
const entry = entries[i];
|
|
379
|
+
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
|
380
|
+
const filename = this.joinPath(entry.name, directoryPath);
|
|
381
|
+
this.pushFile(filename, files, this.state.counts, filters);
|
|
382
|
+
} else if (entry.isDirectory()) {
|
|
383
|
+
let path$1 = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
|
384
|
+
if (exclude && exclude(entry.name, path$1)) continue;
|
|
385
|
+
this.pushDirectory(path$1, paths, filters);
|
|
386
|
+
this.walkDirectory(this.state, path$1, path$1, depth - 1, this.walk);
|
|
387
|
+
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
|
388
|
+
let path$1 = joinPathWithBasePath(entry.name, directoryPath);
|
|
389
|
+
this.resolveSymlink(path$1, this.state, (stat, resolvedPath) => {
|
|
390
|
+
if (stat.isDirectory()) {
|
|
391
|
+
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
|
392
|
+
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path$1 + pathSeparator)) return;
|
|
393
|
+
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path$1 + pathSeparator, depth - 1, this.walk);
|
|
394
|
+
} else {
|
|
395
|
+
resolvedPath = useRealPaths ? resolvedPath : path$1;
|
|
396
|
+
const filename = (0, path3.basename)(resolvedPath);
|
|
397
|
+
const directoryPath$1 = normalizePath((0, path3.dirname)(resolvedPath), this.state.options);
|
|
398
|
+
resolvedPath = this.joinPath(filename, directoryPath$1);
|
|
399
|
+
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
this.groupFiles(this.state.groups, directoryPath, files);
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
function promise(root, options) {
|
|
408
|
+
return new Promise((resolve$1, reject) => {
|
|
409
|
+
callback(root, options, (err, output) => {
|
|
410
|
+
if (err) return reject(err);
|
|
411
|
+
resolve$1(output);
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function callback(root, options, callback$1) {
|
|
416
|
+
let walker = new Walker(root, options, callback$1);
|
|
417
|
+
walker.start();
|
|
418
|
+
}
|
|
419
|
+
function sync(root, options) {
|
|
420
|
+
const walker = new Walker(root, options);
|
|
421
|
+
return walker.start();
|
|
422
|
+
}
|
|
423
|
+
var APIBuilder = class {
|
|
424
|
+
constructor(root, options) {
|
|
425
|
+
this.root = root;
|
|
426
|
+
this.options = options;
|
|
427
|
+
}
|
|
428
|
+
withPromise() {
|
|
429
|
+
return promise(this.root, this.options);
|
|
430
|
+
}
|
|
431
|
+
withCallback(cb) {
|
|
432
|
+
callback(this.root, this.options, cb);
|
|
433
|
+
}
|
|
434
|
+
sync() {
|
|
435
|
+
return sync(this.root, this.options);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
var pm = null;
|
|
439
|
+
try {
|
|
440
|
+
require.resolve("picomatch");
|
|
441
|
+
pm = require("picomatch");
|
|
442
|
+
} catch {
|
|
443
|
+
}
|
|
444
|
+
var Builder = class {
|
|
445
|
+
globCache = {};
|
|
446
|
+
options = {
|
|
447
|
+
maxDepth: Infinity,
|
|
448
|
+
suppressErrors: true,
|
|
449
|
+
pathSeparator: path3.sep,
|
|
450
|
+
filters: []
|
|
451
|
+
};
|
|
452
|
+
globFunction;
|
|
453
|
+
constructor(options) {
|
|
454
|
+
this.options = {
|
|
455
|
+
...this.options,
|
|
456
|
+
...options
|
|
457
|
+
};
|
|
458
|
+
this.globFunction = this.options.globFunction;
|
|
459
|
+
}
|
|
460
|
+
group() {
|
|
461
|
+
this.options.group = true;
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
withPathSeparator(separator) {
|
|
465
|
+
this.options.pathSeparator = separator;
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
withBasePath() {
|
|
469
|
+
this.options.includeBasePath = true;
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
withRelativePaths() {
|
|
473
|
+
this.options.relativePaths = true;
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
withDirs() {
|
|
477
|
+
this.options.includeDirs = true;
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
480
|
+
withMaxDepth(depth) {
|
|
481
|
+
this.options.maxDepth = depth;
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
withMaxFiles(limit) {
|
|
485
|
+
this.options.maxFiles = limit;
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
withFullPaths() {
|
|
489
|
+
this.options.resolvePaths = true;
|
|
490
|
+
this.options.includeBasePath = true;
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
withErrors() {
|
|
494
|
+
this.options.suppressErrors = false;
|
|
495
|
+
return this;
|
|
496
|
+
}
|
|
497
|
+
withSymlinks({ resolvePaths = true } = {}) {
|
|
498
|
+
this.options.resolveSymlinks = true;
|
|
499
|
+
this.options.useRealPaths = resolvePaths;
|
|
500
|
+
return this.withFullPaths();
|
|
501
|
+
}
|
|
502
|
+
withAbortSignal(signal) {
|
|
503
|
+
this.options.signal = signal;
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
normalize() {
|
|
507
|
+
this.options.normalizePath = true;
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
filter(predicate) {
|
|
511
|
+
this.options.filters.push(predicate);
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
onlyDirs() {
|
|
515
|
+
this.options.excludeFiles = true;
|
|
516
|
+
this.options.includeDirs = true;
|
|
517
|
+
return this;
|
|
518
|
+
}
|
|
519
|
+
exclude(predicate) {
|
|
520
|
+
this.options.exclude = predicate;
|
|
521
|
+
return this;
|
|
522
|
+
}
|
|
523
|
+
onlyCounts() {
|
|
524
|
+
this.options.onlyCounts = true;
|
|
525
|
+
return this;
|
|
526
|
+
}
|
|
527
|
+
crawl(root) {
|
|
528
|
+
return new APIBuilder(root || ".", this.options);
|
|
529
|
+
}
|
|
530
|
+
withGlobFunction(fn) {
|
|
531
|
+
this.globFunction = fn;
|
|
532
|
+
return this;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* @deprecated Pass options using the constructor instead:
|
|
536
|
+
* ```ts
|
|
537
|
+
* new fdir(options).crawl("/path/to/root");
|
|
538
|
+
* ```
|
|
539
|
+
* This method will be removed in v7.0
|
|
540
|
+
*/
|
|
541
|
+
/* c8 ignore next 4 */
|
|
542
|
+
crawlWithOptions(root, options) {
|
|
543
|
+
this.options = {
|
|
544
|
+
...this.options,
|
|
545
|
+
...options
|
|
546
|
+
};
|
|
547
|
+
return new APIBuilder(root || ".", this.options);
|
|
548
|
+
}
|
|
549
|
+
glob(...patterns) {
|
|
550
|
+
if (this.globFunction) return this.globWithOptions(patterns);
|
|
551
|
+
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
|
552
|
+
}
|
|
553
|
+
globWithOptions(patterns, ...options) {
|
|
554
|
+
const globFn = this.globFunction || pm;
|
|
555
|
+
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
|
556
|
+
var isMatch = this.globCache[patterns.join("\0")];
|
|
557
|
+
if (!isMatch) {
|
|
558
|
+
isMatch = globFn(patterns, ...options);
|
|
559
|
+
this.globCache[patterns.join("\0")] = isMatch;
|
|
560
|
+
}
|
|
561
|
+
this.options.filters.push((path$1) => isMatch(path$1));
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
exports2.fdir = Builder;
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
// node_modules/.pnpm/ignore@7.0.13/node_modules/ignore/index.js
|
|
570
|
+
var require_ignore = __commonJS({
|
|
571
|
+
"node_modules/.pnpm/ignore@7.0.13/node_modules/ignore/index.js"(exports2, module2) {
|
|
572
|
+
function makeArray(subject) {
|
|
573
|
+
return Array.isArray(subject) ? subject : [subject];
|
|
574
|
+
}
|
|
575
|
+
var UNDEFINED = void 0;
|
|
576
|
+
var EMPTY = "";
|
|
577
|
+
var SPACE = " ";
|
|
578
|
+
var ESCAPE = "\\";
|
|
579
|
+
var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
580
|
+
var BOM = "\uFEFF";
|
|
581
|
+
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
582
|
+
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
583
|
+
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
584
|
+
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
585
|
+
var DOUBLE_SLASH = "//";
|
|
586
|
+
var SLASH_CODE = 47;
|
|
587
|
+
var DOT_CODE = 46;
|
|
588
|
+
var SLASH = "/";
|
|
589
|
+
var TMP_KEY_IGNORE = "node-ignore";
|
|
590
|
+
if (typeof Symbol !== "undefined") {
|
|
591
|
+
TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
|
|
592
|
+
}
|
|
593
|
+
var KEY_IGNORE = TMP_KEY_IGNORE;
|
|
594
|
+
var define = (object, key, value) => {
|
|
595
|
+
Object.defineProperty(object, key, { value });
|
|
596
|
+
return value;
|
|
597
|
+
};
|
|
598
|
+
var RETURN_FALSE = () => false;
|
|
599
|
+
var POSIX_CLASSES = {
|
|
600
|
+
alnum: "0-9A-Za-z",
|
|
601
|
+
alpha: "A-Za-z",
|
|
602
|
+
blank: " \\t",
|
|
603
|
+
cntrl: "\\x00-\\x1f\\x7f",
|
|
604
|
+
digit: "0-9",
|
|
605
|
+
graph: "!-.0-~",
|
|
606
|
+
lower: "a-z",
|
|
607
|
+
print: " -.0-~",
|
|
608
|
+
punct: "!-.:-@\\[-`{-~",
|
|
609
|
+
// git's `sane-ctype.h` classifies \v and \f as control, not space,
|
|
610
|
+
// unlike C's `isspace`
|
|
611
|
+
space: " \\t\\n\\r",
|
|
612
|
+
upper: "A-Z",
|
|
613
|
+
xdigit: "0-9A-Fa-f"
|
|
614
|
+
};
|
|
615
|
+
var CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
|
|
616
|
+
var escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
|
|
617
|
+
var NON_SLASH = "(?!\\/)";
|
|
618
|
+
var classSource = (negated, body) => {
|
|
619
|
+
if (negated) {
|
|
620
|
+
return `[^\\/${body}]`;
|
|
621
|
+
}
|
|
622
|
+
const source = `[${body}]`;
|
|
623
|
+
return new RegExp(source).test("/") ? NON_SLASH + source : source;
|
|
624
|
+
};
|
|
625
|
+
var scanBracket = (pattern, start) => {
|
|
626
|
+
const { length } = pattern;
|
|
627
|
+
let index = start + 1;
|
|
628
|
+
let negated = EMPTY;
|
|
629
|
+
const lead = pattern[index];
|
|
630
|
+
if (lead === "!" || lead === "^") {
|
|
631
|
+
negated = "^";
|
|
632
|
+
index++;
|
|
633
|
+
}
|
|
634
|
+
let body = EMPTY;
|
|
635
|
+
let prev = EMPTY;
|
|
636
|
+
for (; ; ) {
|
|
637
|
+
const char = pattern[index];
|
|
638
|
+
if (char === UNDEFINED) {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
if (char === ESCAPE) {
|
|
642
|
+
const escaped = pattern[index + 1];
|
|
643
|
+
if (escaped === UNDEFINED) {
|
|
644
|
+
return null;
|
|
645
|
+
}
|
|
646
|
+
body += escapeMember(escaped);
|
|
647
|
+
prev = escaped;
|
|
648
|
+
index++;
|
|
649
|
+
} else if (char === "-" && prev && index + 1 < length && pattern[index + 1] !== "]") {
|
|
650
|
+
index++;
|
|
651
|
+
let to = pattern[index];
|
|
652
|
+
if (to === ESCAPE) {
|
|
653
|
+
to = pattern[index += 1];
|
|
654
|
+
}
|
|
655
|
+
if (prev <= to) {
|
|
656
|
+
body += `-${escapeMember(to)}`;
|
|
657
|
+
}
|
|
658
|
+
prev = EMPTY;
|
|
659
|
+
} else if (char === "[" && pattern[index + 1] === ":") {
|
|
660
|
+
const nameStart = index + 2;
|
|
661
|
+
let end = nameStart;
|
|
662
|
+
while (end < length && pattern[end] !== "]") {
|
|
663
|
+
end++;
|
|
664
|
+
}
|
|
665
|
+
if (end === length) {
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
if (end > nameStart && pattern[end - 1] === ":") {
|
|
669
|
+
const name = pattern.slice(nameStart, end - 1);
|
|
670
|
+
if (!Object.prototype.hasOwnProperty.call(POSIX_CLASSES, name)) {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
body += POSIX_CLASSES[name];
|
|
674
|
+
prev = EMPTY;
|
|
675
|
+
index = end;
|
|
676
|
+
} else {
|
|
677
|
+
body += escapeMember("[");
|
|
678
|
+
prev = "[";
|
|
679
|
+
index = nameStart - 2;
|
|
680
|
+
}
|
|
681
|
+
} else {
|
|
682
|
+
body += escapeMember(char);
|
|
683
|
+
prev = char;
|
|
684
|
+
}
|
|
685
|
+
index++;
|
|
686
|
+
if (pattern[index] === "]") {
|
|
687
|
+
return {
|
|
688
|
+
end: index,
|
|
689
|
+
source: classSource(negated, body)
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
var NEVER_MATCH = "[]";
|
|
695
|
+
var PLACEHOLDER = "\0";
|
|
696
|
+
var REGEX_RESTORE_PLACEHOLDER = new RegExp(
|
|
697
|
+
`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`,
|
|
698
|
+
"g"
|
|
699
|
+
);
|
|
700
|
+
var TRAILING_WILDCARD = "\uE000";
|
|
701
|
+
var TRAILING_DOUBLESTAR = "\uE001";
|
|
702
|
+
var isReserved = (char) => char === PLACEHOLDER || char === TRAILING_WILDCARD || char === TRAILING_DOUBLESTAR;
|
|
703
|
+
var extractBrackets = (pattern) => {
|
|
704
|
+
const sources = [];
|
|
705
|
+
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
706
|
+
const { length } = pattern;
|
|
707
|
+
let out = EMPTY;
|
|
708
|
+
let index = 0;
|
|
709
|
+
while (index < length) {
|
|
710
|
+
const char = pattern[index];
|
|
711
|
+
if (char === ESCAPE) {
|
|
712
|
+
const escaped = pattern[index + 1];
|
|
713
|
+
if (escaped === UNDEFINED || escaped === SLASH && index + 2 === length) {
|
|
714
|
+
out += hold(NEVER_MATCH);
|
|
715
|
+
} else if (escaped === "*" || escaped === "[" || escaped === SPACE) {
|
|
716
|
+
out += pattern.slice(index, index + 2);
|
|
717
|
+
} else {
|
|
718
|
+
out += hold(
|
|
719
|
+
REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : isReserved(escaped) ? `[${escaped}]` : escaped
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
index += 2;
|
|
723
|
+
} else if (isReserved(char)) {
|
|
724
|
+
out += hold(`[${char}]`);
|
|
725
|
+
index++;
|
|
726
|
+
} else if (char === "[") {
|
|
727
|
+
const scanned = scanBracket(pattern, index);
|
|
728
|
+
if (scanned === null) {
|
|
729
|
+
out += hold(NEVER_MATCH);
|
|
730
|
+
index = length;
|
|
731
|
+
} else {
|
|
732
|
+
out += hold(scanned.source);
|
|
733
|
+
index = scanned.end + 1;
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
736
|
+
out += char;
|
|
737
|
+
index++;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return {
|
|
741
|
+
source: out,
|
|
742
|
+
sources
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
var DIRECT = null;
|
|
746
|
+
var REGEX_INNER_SLASH = /\/(?!$)/;
|
|
747
|
+
var REPLACERS = [
|
|
748
|
+
// Replace (\ ) with ' '
|
|
749
|
+
// Only a space: an escaped tab or other whitespace is already a literal by
|
|
750
|
+
// the time it reaches here, and a bare tab must be left as one, not turned
|
|
751
|
+
// into a space.
|
|
752
|
+
// (\ ) -> ' '
|
|
753
|
+
// (\\ ) -> '\\ '
|
|
754
|
+
// (\\\ ) -> '\\ '
|
|
755
|
+
[
|
|
756
|
+
// A run of backslashes is taken whole, from its first one, so no match
|
|
757
|
+
// ever starts again inside it -- `(\\+?) ` did, which made a long run
|
|
758
|
+
// quadratic.
|
|
759
|
+
/(\\+)( ?)/g,
|
|
760
|
+
(_, run, space) => space ? run.slice(0, run.length - run.length % 2) + SPACE : run,
|
|
761
|
+
ESCAPE + SPACE
|
|
762
|
+
],
|
|
763
|
+
// Escape metacharacters
|
|
764
|
+
// which is written down by users but means special for regular expressions.
|
|
765
|
+
// > There are 12 characters with special meanings:
|
|
766
|
+
// > - the backslash \,
|
|
767
|
+
// > - the caret ^,
|
|
768
|
+
// > - the dollar sign $,
|
|
769
|
+
// > - the period or dot .,
|
|
770
|
+
// > - the vertical bar or pipe symbol |,
|
|
771
|
+
// > - the question mark ?,
|
|
772
|
+
// > - the asterisk or star *,
|
|
773
|
+
// > - the plus sign +,
|
|
774
|
+
// > - the opening parenthesis (,
|
|
775
|
+
// > - the closing parenthesis ),
|
|
776
|
+
// > - and the opening square bracket [,
|
|
777
|
+
// > - the opening curly brace {,
|
|
778
|
+
// > These special characters are often called "metacharacters".
|
|
779
|
+
[
|
|
780
|
+
/[\\$.|*+(){^]/g,
|
|
781
|
+
(match) => `\\${match}`
|
|
782
|
+
],
|
|
783
|
+
[
|
|
784
|
+
// > a question mark (?) matches a single character
|
|
785
|
+
/(?!\\)\?/g,
|
|
786
|
+
() => "[^/]",
|
|
787
|
+
"?"
|
|
788
|
+
],
|
|
789
|
+
// leading slash
|
|
790
|
+
[
|
|
791
|
+
// > A leading slash matches the beginning of the pathname.
|
|
792
|
+
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
|
793
|
+
// A leading slash matches the beginning of the pathname
|
|
794
|
+
/^\//,
|
|
795
|
+
() => "^",
|
|
796
|
+
SLASH
|
|
797
|
+
],
|
|
798
|
+
// replace special metacharacter slash after the leading slash
|
|
799
|
+
[
|
|
800
|
+
/\//g,
|
|
801
|
+
() => "\\/",
|
|
802
|
+
SLASH
|
|
803
|
+
],
|
|
804
|
+
[
|
|
805
|
+
// > A leading "**" followed by a slash means match in all directories.
|
|
806
|
+
// > For example, "**/foo" matches file or directory "foo" anywhere,
|
|
807
|
+
// > the same as pattern "foo".
|
|
808
|
+
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
809
|
+
// > under directory "foo".
|
|
810
|
+
// Notice that the '*'s have been replaced as '\\*'
|
|
811
|
+
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
812
|
+
// '**/foo' <-> 'foo'
|
|
813
|
+
() => "^(?:.*\\/)?",
|
|
814
|
+
"*"
|
|
815
|
+
],
|
|
816
|
+
// starting
|
|
817
|
+
[
|
|
818
|
+
// there will be no leading '/'
|
|
819
|
+
// (which has been replaced by section "leading slash")
|
|
820
|
+
// If starts with '**', adding a '^' to the regular expression also works
|
|
821
|
+
DIRECT,
|
|
822
|
+
(source, pattern) => {
|
|
823
|
+
if (!source || source[0] === "^") {
|
|
824
|
+
return source;
|
|
825
|
+
}
|
|
826
|
+
const anchor = !REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^";
|
|
827
|
+
return anchor + source;
|
|
828
|
+
}
|
|
829
|
+
],
|
|
830
|
+
// two globstars
|
|
831
|
+
[
|
|
832
|
+
// Use lookahead assertions so that we could match more than one `'/**'`
|
|
833
|
+
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
834
|
+
// Zero, one or several directories
|
|
835
|
+
// should not use '*', or it will be replaced by the next replacer
|
|
836
|
+
// Check if it is not the last `'/**'`
|
|
837
|
+
(_, index, str) => index + 6 < str.length ? str.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : `\\/${TRAILING_DOUBLESTAR}`,
|
|
838
|
+
"*"
|
|
839
|
+
],
|
|
840
|
+
// normal intermediate wildcards
|
|
841
|
+
[
|
|
842
|
+
// Never replace escaped '*'
|
|
843
|
+
// ignore rule '\*' will match the path '*'
|
|
844
|
+
// 'abc.*/' -> go
|
|
845
|
+
// 'abc.*' -> skip this rule,
|
|
846
|
+
// coz trailing single wildcard will be handed by [trailing wildcard]
|
|
847
|
+
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
848
|
+
// '*.js' matches '.js'
|
|
849
|
+
// '*.js' doesn't match 'abc'
|
|
850
|
+
(_, p1, p2) => {
|
|
851
|
+
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
852
|
+
return p1 + unescaped;
|
|
853
|
+
},
|
|
854
|
+
"*"
|
|
855
|
+
],
|
|
856
|
+
// trailing wildcard, held apart from a literal star
|
|
857
|
+
[
|
|
858
|
+
// The step above leaves a trailing `*` alone, so a single `\*` is all that
|
|
859
|
+
// can be left at the end here, and what stands in front of it says which
|
|
860
|
+
// kind it is. A wildcard arrives as the escaper wrote it, `\*` with
|
|
861
|
+
// nothing before it; a literal arrives as the user's own escape, which
|
|
862
|
+
// the escaper doubled, and then the star's own -- `\\` and then `\*`.
|
|
863
|
+
// There is no third case: every backslash still reaching the chain is
|
|
864
|
+
// one `\*`, `\[` or `\ ` carries itself, and each is followed by its
|
|
865
|
+
// own character, so a longer run can never form. This runs while the
|
|
866
|
+
// two are still distinct, before the unescape steps below collapse the
|
|
867
|
+
// literal onto the very `\*` a wildcard leaves behind.
|
|
868
|
+
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
869
|
+
(match, p1, p2) => p2 === EMPTY ? p1 + TRAILING_WILDCARD : match,
|
|
870
|
+
"*"
|
|
871
|
+
],
|
|
872
|
+
[
|
|
873
|
+
// unescape, revert step 3 except for back slash
|
|
874
|
+
// For example, if a user escape a '\\*',
|
|
875
|
+
// after step 3, the result will be '\\\\\\*'
|
|
876
|
+
/\\\\\\(?=[$.|*+(){^])/g,
|
|
877
|
+
() => ESCAPE,
|
|
878
|
+
ESCAPE + ESCAPE
|
|
879
|
+
],
|
|
880
|
+
[
|
|
881
|
+
// '\\\\' -> '\\'
|
|
882
|
+
/\\\\/g,
|
|
883
|
+
() => ESCAPE,
|
|
884
|
+
ESCAPE + ESCAPE
|
|
885
|
+
],
|
|
886
|
+
[
|
|
887
|
+
// Every real bracket expression -- POSIX classes included -- has already
|
|
888
|
+
// been held aside by `extractBrackets`, so the only `[` left in the
|
|
889
|
+
// pattern is an escaped, literal one.
|
|
890
|
+
// A backslash could only stand at the end of the range if it quoted the
|
|
891
|
+
// `]`, and `\]` is held aside long before this.
|
|
892
|
+
/\\\[([^\]/]*?)($|\])/g,
|
|
893
|
+
// '\\[bar]' -> '\\\\[bar]'
|
|
894
|
+
(match, range, close) => `\\[${range}${close}`,
|
|
895
|
+
"["
|
|
896
|
+
],
|
|
897
|
+
// ending
|
|
898
|
+
[
|
|
899
|
+
// 'js' will not match 'js.'
|
|
900
|
+
// 'ab' will not match 'abc'
|
|
901
|
+
DIRECT,
|
|
902
|
+
// WTF!
|
|
903
|
+
// https://git-scm.com/docs/gitignore
|
|
904
|
+
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
|
905
|
+
// which re-fixes #24, #38
|
|
906
|
+
// > If there is a separator at the end of the pattern then the pattern
|
|
907
|
+
// > will only match directories, otherwise the pattern can match both
|
|
908
|
+
// > files and directories.
|
|
909
|
+
// 'js*' will not match 'a.js'
|
|
910
|
+
// 'js/' will not match 'a.js'
|
|
911
|
+
// 'js' will match 'a.js' and 'a.js/'
|
|
912
|
+
(source) => {
|
|
913
|
+
const last = source[source.length - 1];
|
|
914
|
+
if (!last || last === TRAILING_WILDCARD || last === TRAILING_DOUBLESTAR) {
|
|
915
|
+
return source;
|
|
916
|
+
}
|
|
917
|
+
return last === SLASH ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
918
|
+
}
|
|
919
|
+
]
|
|
920
|
+
];
|
|
921
|
+
var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
|
|
922
|
+
var MODE_IGNORE = "regex";
|
|
923
|
+
var MODE_CHECK_IGNORE = "checkRegex";
|
|
924
|
+
var UNDERSCORE = "_";
|
|
925
|
+
var replaceTrailingWildcard = (_, p1) => {
|
|
926
|
+
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
927
|
+
return `${prefix}(?=$|\\/$)`;
|
|
928
|
+
};
|
|
929
|
+
var REGEX_REPLACE_TRAILING_DOUBLESTAR = /\uE001$/;
|
|
930
|
+
var replaceTrailingDoublestar = () => ".+(?=$|\\/$)";
|
|
931
|
+
var WILDCARD = "[^\\/]*";
|
|
932
|
+
var separatorAfter = (run, at) => {
|
|
933
|
+
let separator = EMPTY;
|
|
934
|
+
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
935
|
+
separator += run[index].single;
|
|
936
|
+
}
|
|
937
|
+
return separator;
|
|
938
|
+
};
|
|
939
|
+
var pinWildcards = (source) => {
|
|
940
|
+
if (source.indexOf(WILDCARD) < 0) {
|
|
941
|
+
return source;
|
|
942
|
+
}
|
|
943
|
+
const tokens = [];
|
|
944
|
+
const { length } = source;
|
|
945
|
+
let index = 0;
|
|
946
|
+
while (index < length) {
|
|
947
|
+
const char = source[index];
|
|
948
|
+
if (source.startsWith(WILDCARD, index)) {
|
|
949
|
+
tokens.push({ wildcard: true });
|
|
950
|
+
index += WILDCARD.length;
|
|
951
|
+
} else if (char === "[") {
|
|
952
|
+
let end = index + 1;
|
|
953
|
+
if (source[end] === "^") {
|
|
954
|
+
end++;
|
|
955
|
+
}
|
|
956
|
+
if (source[end] === "]") {
|
|
957
|
+
end++;
|
|
958
|
+
}
|
|
959
|
+
while (end < length && source[end] !== "]") {
|
|
960
|
+
end += source[end] === ESCAPE ? 2 : 1;
|
|
961
|
+
}
|
|
962
|
+
end++;
|
|
963
|
+
tokens.push({ single: source.slice(index, end) });
|
|
964
|
+
index = end;
|
|
965
|
+
} else if (char === ESCAPE) {
|
|
966
|
+
tokens.push({ single: source.slice(index, index + 2) });
|
|
967
|
+
index += 2;
|
|
968
|
+
} else if (char === "(") {
|
|
969
|
+
let depth = 0;
|
|
970
|
+
let end = index;
|
|
971
|
+
do {
|
|
972
|
+
if (source[end] === ESCAPE) {
|
|
973
|
+
end++;
|
|
974
|
+
} else if (source[end] === "(") {
|
|
975
|
+
depth++;
|
|
976
|
+
} else if (source[end] === ")") {
|
|
977
|
+
depth--;
|
|
978
|
+
}
|
|
979
|
+
end++;
|
|
980
|
+
} while (end < length && depth > 0);
|
|
981
|
+
if ("*+?".indexOf(source[end]) >= 0) {
|
|
982
|
+
end++;
|
|
983
|
+
}
|
|
984
|
+
tokens.push({ boundary: source.slice(index, end) });
|
|
985
|
+
index = end;
|
|
986
|
+
} else if (char === "^" || char === "$") {
|
|
987
|
+
tokens.push({ boundary: char });
|
|
988
|
+
index++;
|
|
989
|
+
} else {
|
|
990
|
+
tokens.push({ single: char });
|
|
991
|
+
index++;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
let out = EMPTY;
|
|
995
|
+
let run = [];
|
|
996
|
+
const flush = () => {
|
|
997
|
+
let lastWildcard;
|
|
998
|
+
run.forEach((token, at) => {
|
|
999
|
+
if (token.wildcard) {
|
|
1000
|
+
lastWildcard = at;
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
run.forEach((token, at) => {
|
|
1004
|
+
if (!token.wildcard) {
|
|
1005
|
+
out += token.single;
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
1009
|
+
});
|
|
1010
|
+
run = [];
|
|
1011
|
+
};
|
|
1012
|
+
tokens.forEach((token) => {
|
|
1013
|
+
if (token.boundary === void 0) {
|
|
1014
|
+
run.push(token);
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
flush();
|
|
1018
|
+
out += token.boundary;
|
|
1019
|
+
});
|
|
1020
|
+
flush();
|
|
1021
|
+
return out;
|
|
1022
|
+
};
|
|
1023
|
+
var makeRegexPrefix = (pattern) => {
|
|
1024
|
+
const { source, sources } = extractBrackets(pattern);
|
|
1025
|
+
const replaced = REPLACERS.reduce(
|
|
1026
|
+
// A pass whose matcher finds nothing hands back the very string it was
|
|
1027
|
+
// given, so asking first costs a search and saves a rewrite. Ten of the
|
|
1028
|
+
// fifteen passes never fire for a typical .gitignore line, and between
|
|
1029
|
+
// them they were 45% of this chain.
|
|
1030
|
+
(prev, [matcher, replacer, required]) => {
|
|
1031
|
+
if (matcher === DIRECT) {
|
|
1032
|
+
return replacer(prev, pattern);
|
|
1033
|
+
}
|
|
1034
|
+
if (required !== UNDEFINED && prev.indexOf(required) < 0) {
|
|
1035
|
+
return prev;
|
|
1036
|
+
}
|
|
1037
|
+
return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
|
|
1038
|
+
},
|
|
1039
|
+
source
|
|
1040
|
+
);
|
|
1041
|
+
return sources.length ? replaced.replace(
|
|
1042
|
+
REGEX_RESTORE_PLACEHOLDER,
|
|
1043
|
+
(match, index) => sources[index]
|
|
1044
|
+
) : replaced;
|
|
1045
|
+
};
|
|
1046
|
+
var checkSourceOf = (body, prefix) => {
|
|
1047
|
+
if (body[body.length - 1] === SLASH) {
|
|
1048
|
+
prefix = makeRegexPrefix(body.slice(0, -1));
|
|
1049
|
+
}
|
|
1050
|
+
const head = prefix.slice(0, -1);
|
|
1051
|
+
const last = prefix[prefix.length - 1];
|
|
1052
|
+
return last === TRAILING_WILDCARD ? `${head}$` : last === TRAILING_DOUBLESTAR ? `${head}.*$` : NEVER_MATCH;
|
|
1053
|
+
};
|
|
1054
|
+
var matchesBasename = (body) => {
|
|
1055
|
+
const index = body.indexOf(SLASH);
|
|
1056
|
+
return index < 0 || index === body.length - 1;
|
|
1057
|
+
};
|
|
1058
|
+
var basenameOf = (path3) => {
|
|
1059
|
+
const end = path3.length - 1;
|
|
1060
|
+
const index = path3.lastIndexOf(
|
|
1061
|
+
SLASH,
|
|
1062
|
+
path3[end] === SLASH ? end - 1 : end
|
|
1063
|
+
);
|
|
1064
|
+
return index < 0 ? path3 : path3.slice(index + 1);
|
|
1065
|
+
};
|
|
1066
|
+
var parentOf = (path3) => {
|
|
1067
|
+
if (path3.charCodeAt(0) === SLASH_CODE || path3.indexOf(DOUBLE_SLASH) >= 0) {
|
|
1068
|
+
const slices = path3.split(SLASH).filter(Boolean);
|
|
1069
|
+
slices.pop();
|
|
1070
|
+
return slices.length ? slices.join(SLASH) + SLASH : EMPTY;
|
|
1071
|
+
}
|
|
1072
|
+
const end = path3.length - 1;
|
|
1073
|
+
const cut = path3.lastIndexOf(
|
|
1074
|
+
SLASH,
|
|
1075
|
+
path3.charCodeAt(end) === SLASH_CODE ? end - 1 : end
|
|
1076
|
+
);
|
|
1077
|
+
return cut < 0 ? EMPTY : path3.slice(0, cut + 1);
|
|
1078
|
+
};
|
|
1079
|
+
var isString = (subject) => typeof subject === "string";
|
|
1080
|
+
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern);
|
|
1081
|
+
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
1082
|
+
var IgnoreRule = class {
|
|
1083
|
+
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
1084
|
+
this.pattern = pattern;
|
|
1085
|
+
this.mark = mark;
|
|
1086
|
+
this.negative = negative;
|
|
1087
|
+
define(this, "body", body);
|
|
1088
|
+
define(this, "ignoreCase", ignoreCase);
|
|
1089
|
+
define(this, "regexPrefix", prefix);
|
|
1090
|
+
}
|
|
1091
|
+
// Worked out on first use and kept behind an own property, the way `regex`
|
|
1092
|
+
// caches itself in `_regex`. Deciding it in the constructor instead would
|
|
1093
|
+
// add a fourth `defineProperty` to every rule ever built, which cost 4% of
|
|
1094
|
+
// every compile -- including the compiles of rules that are never matched
|
|
1095
|
+
// against anything.
|
|
1096
|
+
get _basenameOnly() {
|
|
1097
|
+
return define(this, "_basenameOnly", matchesBasename(this.body));
|
|
1098
|
+
}
|
|
1099
|
+
get regex() {
|
|
1100
|
+
const key = UNDERSCORE + MODE_IGNORE;
|
|
1101
|
+
if (this[key]) {
|
|
1102
|
+
return this[key];
|
|
1103
|
+
}
|
|
1104
|
+
return this._make(MODE_IGNORE, key);
|
|
1105
|
+
}
|
|
1106
|
+
get checkRegex() {
|
|
1107
|
+
const key = UNDERSCORE + MODE_CHECK_IGNORE;
|
|
1108
|
+
if (this[key]) {
|
|
1109
|
+
return this[key];
|
|
1110
|
+
}
|
|
1111
|
+
return this._make(MODE_CHECK_IGNORE, key);
|
|
1112
|
+
}
|
|
1113
|
+
_make(mode, key) {
|
|
1114
|
+
const str = pinWildcards(
|
|
1115
|
+
mode === MODE_IGNORE ? this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, replaceTrailingWildcard).replace(REGEX_REPLACE_TRAILING_DOUBLESTAR, replaceTrailingDoublestar) : checkSourceOf(this.body, this.regexPrefix)
|
|
1116
|
+
);
|
|
1117
|
+
const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
|
|
1118
|
+
return define(this, key, regex);
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
var isLineEnd = (char) => char === "\r" || char === "\n";
|
|
1122
|
+
var trimEnd = (body) => {
|
|
1123
|
+
let end = body.length;
|
|
1124
|
+
while (end && isLineEnd(body[end - 1])) {
|
|
1125
|
+
end--;
|
|
1126
|
+
}
|
|
1127
|
+
const lineEnd = end;
|
|
1128
|
+
while (end && body[end - 1] === SPACE) {
|
|
1129
|
+
end--;
|
|
1130
|
+
}
|
|
1131
|
+
if (end === lineEnd) {
|
|
1132
|
+
return body.slice(0, end);
|
|
1133
|
+
}
|
|
1134
|
+
let backslashes = 0;
|
|
1135
|
+
while (backslashes < end && body[end - backslashes - 1] === ESCAPE) {
|
|
1136
|
+
backslashes++;
|
|
1137
|
+
}
|
|
1138
|
+
return backslashes % 2 ? body.slice(0, end - 1) + SPACE : body.slice(0, end);
|
|
1139
|
+
};
|
|
1140
|
+
var createRule = ({
|
|
1141
|
+
pattern,
|
|
1142
|
+
mark
|
|
1143
|
+
}, ignoreCase) => {
|
|
1144
|
+
let body = pattern[0] === BOM ? pattern.slice(1) : pattern;
|
|
1145
|
+
if (body[0] === "#") {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
let negative = false;
|
|
1149
|
+
if (body[0] === "!") {
|
|
1150
|
+
negative = true;
|
|
1151
|
+
body = body.slice(1);
|
|
1152
|
+
}
|
|
1153
|
+
const last = body[body.length - 1];
|
|
1154
|
+
if (last === SPACE || last === "\r" || last === "\n") {
|
|
1155
|
+
body = trimEnd(body);
|
|
1156
|
+
}
|
|
1157
|
+
if (!body) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
1161
|
+
const regexPrefix = makeRegexPrefix(body);
|
|
1162
|
+
return new IgnoreRule(
|
|
1163
|
+
pattern,
|
|
1164
|
+
mark,
|
|
1165
|
+
body,
|
|
1166
|
+
ignoreCase,
|
|
1167
|
+
negative,
|
|
1168
|
+
regexPrefix
|
|
1169
|
+
);
|
|
1170
|
+
};
|
|
1171
|
+
var RuleManager = class {
|
|
1172
|
+
constructor(ignoreCase) {
|
|
1173
|
+
this._ignoreCase = ignoreCase;
|
|
1174
|
+
this._rules = [];
|
|
1175
|
+
this._basenameCount = 0;
|
|
1176
|
+
}
|
|
1177
|
+
_add(pattern) {
|
|
1178
|
+
if (pattern && pattern[KEY_IGNORE]) {
|
|
1179
|
+
this._rules = this._rules.concat(pattern._rules._rules);
|
|
1180
|
+
this._basenameCount += pattern._rules._basenameCount;
|
|
1181
|
+
this._added = true;
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
if (isString(pattern)) {
|
|
1185
|
+
pattern = {
|
|
1186
|
+
pattern
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
const rule = checkPattern(pattern.pattern) && createRule(pattern, this._ignoreCase);
|
|
1190
|
+
if (rule) {
|
|
1191
|
+
this._added = true;
|
|
1192
|
+
this._rules.push(rule);
|
|
1193
|
+
if (matchesBasename(rule.body)) {
|
|
1194
|
+
this._basenameCount++;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
// @param {Array<string> | string | Ignore} pattern
|
|
1199
|
+
add(pattern) {
|
|
1200
|
+
this._added = false;
|
|
1201
|
+
makeArray(
|
|
1202
|
+
isString(pattern) ? splitPattern(pattern) : pattern
|
|
1203
|
+
).forEach(this._add, this);
|
|
1204
|
+
if (this._added) {
|
|
1205
|
+
this._literalRules = UNDEFINED;
|
|
1206
|
+
}
|
|
1207
|
+
return this._added;
|
|
1208
|
+
}
|
|
1209
|
+
// Match the literal 'abc/' for `checkIgnore`, last rule wins. Only a rule
|
|
1210
|
+
// ending in a wildcard can match it (see `checkSourceOf`), so the rest
|
|
1211
|
+
// are left out once, rather than tested or compiled for every path.
|
|
1212
|
+
testLiteral(path3) {
|
|
1213
|
+
const rules = this._literalRules || (this._literalRules = this._rules.filter(
|
|
1214
|
+
({ body }) => body[body.length - (body[body.length - 1] === SLASH ? 2 : 1)] === "*"
|
|
1215
|
+
));
|
|
1216
|
+
let ignored = false;
|
|
1217
|
+
let unignored = false;
|
|
1218
|
+
let matchedRule;
|
|
1219
|
+
for (let index = rules.length - 1; index >= 0; index--) {
|
|
1220
|
+
const rule = rules[index];
|
|
1221
|
+
if (rule.checkRegex.test(path3)) {
|
|
1222
|
+
ignored = !rule.negative;
|
|
1223
|
+
unignored = rule.negative;
|
|
1224
|
+
matchedRule = rule.negative ? UNDEFINED : rule;
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
const ret = {
|
|
1229
|
+
ignored,
|
|
1230
|
+
unignored
|
|
1231
|
+
};
|
|
1232
|
+
if (matchedRule) {
|
|
1233
|
+
ret.rule = matchedRule;
|
|
1234
|
+
}
|
|
1235
|
+
return ret;
|
|
1236
|
+
}
|
|
1237
|
+
// Test one single path without recursively checking parent directories
|
|
1238
|
+
//
|
|
1239
|
+
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
1240
|
+
// setting `checkUnignored` to `false` could reduce additional
|
|
1241
|
+
// path matching.
|
|
1242
|
+
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
1243
|
+
// @returns {TestResult} true if a file is ignored
|
|
1244
|
+
test(path3, checkUnignored, mode) {
|
|
1245
|
+
let ignored = false;
|
|
1246
|
+
let unignored = false;
|
|
1247
|
+
let matchedRule;
|
|
1248
|
+
const rules = this._rules;
|
|
1249
|
+
const { length } = rules;
|
|
1250
|
+
const shortcut = this._basenameCount * 2 >= length;
|
|
1251
|
+
const basename2 = shortcut ? basenameOf(path3) : path3;
|
|
1252
|
+
for (let index = 0; index < length; index++) {
|
|
1253
|
+
const rule = rules[index];
|
|
1254
|
+
const { negative } = rule;
|
|
1255
|
+
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
1256
|
+
if (!skip && rule[mode].test(
|
|
1257
|
+
shortcut && rule._basenameOnly ? basename2 : path3
|
|
1258
|
+
)) {
|
|
1259
|
+
ignored = !negative;
|
|
1260
|
+
unignored = negative;
|
|
1261
|
+
matchedRule = negative ? UNDEFINED : rule;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
const ret = {
|
|
1265
|
+
ignored,
|
|
1266
|
+
unignored
|
|
1267
|
+
};
|
|
1268
|
+
if (matchedRule) {
|
|
1269
|
+
ret.rule = matchedRule;
|
|
1270
|
+
}
|
|
1271
|
+
return ret;
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
var throwError = (message, Ctor) => {
|
|
1275
|
+
throw new Ctor(message);
|
|
1276
|
+
};
|
|
1277
|
+
var checkPath = (path3, originalPath, doThrow) => {
|
|
1278
|
+
if (!isString(path3)) {
|
|
1279
|
+
return doThrow(
|
|
1280
|
+
`path must be a string, but got \`${originalPath}\``,
|
|
1281
|
+
TypeError
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
if (!path3) {
|
|
1285
|
+
return doThrow(`path must not be empty`, TypeError);
|
|
1286
|
+
}
|
|
1287
|
+
if (checkPath.isNotRelative(path3)) {
|
|
1288
|
+
const r = "`path.relative()`d";
|
|
1289
|
+
return doThrow(
|
|
1290
|
+
`path should be a ${r} string, but got "${originalPath}"`,
|
|
1291
|
+
RangeError
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
return true;
|
|
1295
|
+
};
|
|
1296
|
+
var isNotRelative = (path3) => {
|
|
1297
|
+
const first = path3.charCodeAt(0);
|
|
1298
|
+
if (first === SLASH_CODE) {
|
|
1299
|
+
return true;
|
|
1300
|
+
}
|
|
1301
|
+
if (first !== DOT_CODE) {
|
|
1302
|
+
return false;
|
|
1303
|
+
}
|
|
1304
|
+
if (path3.length === 1) {
|
|
1305
|
+
return true;
|
|
1306
|
+
}
|
|
1307
|
+
const second = path3.charCodeAt(1);
|
|
1308
|
+
if (second === SLASH_CODE) {
|
|
1309
|
+
return true;
|
|
1310
|
+
}
|
|
1311
|
+
if (second !== DOT_CODE) {
|
|
1312
|
+
return false;
|
|
1313
|
+
}
|
|
1314
|
+
return path3.length === 2 || path3.charCodeAt(2) === SLASH_CODE;
|
|
1315
|
+
};
|
|
1316
|
+
checkPath.isNotRelative = isNotRelative;
|
|
1317
|
+
checkPath.convert = (p) => p;
|
|
1318
|
+
var Ignore = class {
|
|
1319
|
+
constructor({
|
|
1320
|
+
ignorecase = true,
|
|
1321
|
+
ignoreCase = ignorecase,
|
|
1322
|
+
allowRelativePaths = false
|
|
1323
|
+
} = {}) {
|
|
1324
|
+
define(this, KEY_IGNORE, true);
|
|
1325
|
+
this._rules = new RuleManager(ignoreCase);
|
|
1326
|
+
this._strictPathCheck = !allowRelativePaths;
|
|
1327
|
+
this._initCache();
|
|
1328
|
+
}
|
|
1329
|
+
_initCache() {
|
|
1330
|
+
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
1331
|
+
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
1332
|
+
}
|
|
1333
|
+
add(pattern) {
|
|
1334
|
+
if (this._rules.add(pattern)) {
|
|
1335
|
+
this._initCache();
|
|
1336
|
+
}
|
|
1337
|
+
return this;
|
|
1338
|
+
}
|
|
1339
|
+
// legacy
|
|
1340
|
+
addPattern(pattern) {
|
|
1341
|
+
return this.add(pattern);
|
|
1342
|
+
}
|
|
1343
|
+
// @returns {TestResult}
|
|
1344
|
+
_test(originalPath, cache, checkUnignored) {
|
|
1345
|
+
const path3 = originalPath && checkPath.convert(originalPath);
|
|
1346
|
+
checkPath(
|
|
1347
|
+
path3,
|
|
1348
|
+
originalPath,
|
|
1349
|
+
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
1350
|
+
);
|
|
1351
|
+
return this._t(path3, cache, checkUnignored);
|
|
1352
|
+
}
|
|
1353
|
+
checkIgnore(path3) {
|
|
1354
|
+
if (path3.charCodeAt(path3.length - 1) !== SLASH_CODE) {
|
|
1355
|
+
return this.test(path3);
|
|
1356
|
+
}
|
|
1357
|
+
const dir = this._t(path3, this._testCache, true);
|
|
1358
|
+
if (dir.ignored) {
|
|
1359
|
+
return dir;
|
|
1360
|
+
}
|
|
1361
|
+
const literal = this._rules.testLiteral(path3);
|
|
1362
|
+
return literal.ignored || literal.unignored ? literal : dir;
|
|
1363
|
+
}
|
|
1364
|
+
_t(path3, cache, checkUnignored) {
|
|
1365
|
+
if (path3 in cache) {
|
|
1366
|
+
return cache[path3];
|
|
1367
|
+
}
|
|
1368
|
+
const parentPath = parentOf(path3);
|
|
1369
|
+
const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
|
|
1370
|
+
return cache[path3] = parent && parent.ignored ? parent : this._rules.test(path3, checkUnignored, MODE_IGNORE);
|
|
1371
|
+
}
|
|
1372
|
+
ignores(path3) {
|
|
1373
|
+
return this._test(path3, this._ignoreCache, false).ignored;
|
|
1374
|
+
}
|
|
1375
|
+
createFilter() {
|
|
1376
|
+
return (path3) => !this.ignores(path3);
|
|
1377
|
+
}
|
|
1378
|
+
filter(paths) {
|
|
1379
|
+
return makeArray(paths).filter(this.createFilter());
|
|
1380
|
+
}
|
|
1381
|
+
// @returns {TestResult}
|
|
1382
|
+
test(path3) {
|
|
1383
|
+
return this._test(path3, this._testCache, true);
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
var factory = (options) => new Ignore(options);
|
|
1387
|
+
var isPathValid = (path3) => checkPath(path3 && checkPath.convert(path3), path3, RETURN_FALSE);
|
|
1388
|
+
var setupWindows = () => {
|
|
1389
|
+
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
1390
|
+
checkPath.convert = makePosix;
|
|
1391
|
+
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
1392
|
+
checkPath.isNotRelative = (path3) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path3) || isNotRelative(path3);
|
|
1393
|
+
};
|
|
1394
|
+
if (
|
|
1395
|
+
// Detect `process` so that it can run in browsers.
|
|
1396
|
+
typeof process !== "undefined" && process.platform === "win32"
|
|
1397
|
+
) {
|
|
1398
|
+
setupWindows();
|
|
1399
|
+
}
|
|
1400
|
+
module2.exports = factory;
|
|
1401
|
+
factory.default = factory;
|
|
1402
|
+
module2.exports.isPathValid = isPathValid;
|
|
1403
|
+
define(module2.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
|
|
1407
|
+
// src/index.ts
|
|
1408
|
+
var index_exports = {};
|
|
1409
|
+
__export(index_exports, {
|
|
1410
|
+
DEFAULT_MOUNTED_PRESETS: () => DEFAULT_MOUNTED_PRESETS,
|
|
1411
|
+
PRESETS: () => PRESETS,
|
|
1412
|
+
PathscopeConfigError: () => PathscopeConfigError,
|
|
1413
|
+
PathscopeGitError: () => PathscopeGitError,
|
|
1414
|
+
clearUniverseCache: () => clearUniverseCache,
|
|
1415
|
+
createExclusionEngine: () => createExclusionEngine,
|
|
1416
|
+
gitUniverse: () => gitUniverse,
|
|
1417
|
+
locateNearest: () => locateNearest,
|
|
1418
|
+
nodeExclusionIO: () => nodeExclusionIO,
|
|
1419
|
+
walkScope: () => walkScope
|
|
1420
|
+
});
|
|
1421
|
+
module.exports = __toCommonJS(index_exports);
|
|
1422
|
+
|
|
1423
|
+
// src/engine.ts
|
|
1424
|
+
var import_node_fs3 = require("node:fs");
|
|
1425
|
+
var import_node_path2 = require("node:path");
|
|
1426
|
+
var import_fdir = __toESM(require_dist(), 1);
|
|
1427
|
+
|
|
1428
|
+
// src/cascade.ts
|
|
1429
|
+
var import_node_fs = require("node:fs");
|
|
1430
|
+
function readGitignoreText(dirPath) {
|
|
1431
|
+
try {
|
|
1432
|
+
return (0, import_node_fs.readFileSync)(`${dirPath.replace(/\/+$/, "")}/.gitignore`, "utf8");
|
|
1433
|
+
} catch {
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
function splitLines(text) {
|
|
1438
|
+
return text.split(/\r?\n/);
|
|
1439
|
+
}
|
|
1440
|
+
function reanchorLines(lines, prefix) {
|
|
1441
|
+
const out = [];
|
|
1442
|
+
for (const line of lines) {
|
|
1443
|
+
if (line === "" || line.startsWith("#")) continue;
|
|
1444
|
+
const negative = line.startsWith("!");
|
|
1445
|
+
const body = negative ? line.slice(1) : line;
|
|
1446
|
+
if (body === "") continue;
|
|
1447
|
+
const anchored = body.startsWith("/") || body.slice(0, -1).includes("/");
|
|
1448
|
+
const reanchored = anchored ? `${prefix}/${body.startsWith("/") ? body.slice(1) : body}` : `${prefix}/**/${body}`;
|
|
1449
|
+
out.push(negative ? `!${reanchored}` : reanchored);
|
|
1450
|
+
}
|
|
1451
|
+
return out;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// src/exclusion-engine.ts
|
|
1455
|
+
var import_node_fs2 = require("node:fs");
|
|
1456
|
+
var import_node_path = require("node:path");
|
|
1457
|
+
var import_ignore = __toESM(require_ignore(), 1);
|
|
1458
|
+
|
|
1459
|
+
// src/presets.ts
|
|
1460
|
+
var PRESET_NAMES = ["vcs", "deps", "build", "caches", "agentDocs"];
|
|
1461
|
+
function isPresetName(value) {
|
|
1462
|
+
return typeof value === "string" && PRESET_NAMES.includes(value);
|
|
1463
|
+
}
|
|
1464
|
+
var PRESETS = {
|
|
1465
|
+
vcs: {
|
|
1466
|
+
// Version-control homes. `.git` here only guards the scan root's own VCS
|
|
1467
|
+
// directory as content; nested `.git` presence is the core boundary stone
|
|
1468
|
+
// and truncates regardless of presets.
|
|
1469
|
+
dirs: [".git", ".hg", ".svn"]
|
|
1470
|
+
},
|
|
1471
|
+
deps: {
|
|
1472
|
+
// Dependency homes (node ecosystem + the generic vendor tree; `.pnpm` is
|
|
1473
|
+
// pnpm's store directory, also matched wherever it appears).
|
|
1474
|
+
dirs: ["node_modules", ".pnpm", "vendor"]
|
|
1475
|
+
},
|
|
1476
|
+
build: {
|
|
1477
|
+
// Build outputs and coverage. These are collision-grade names (a project's
|
|
1478
|
+
// source can legitimately live in `lib/`) — that is exactly why they ride
|
|
1479
|
+
// the un-excludable preset channel (`!lib/` names its way out) instead of
|
|
1480
|
+
// a separate immune layer.
|
|
1481
|
+
dirs: ["dist", "build", "lib", "out", "coverage"]
|
|
1482
|
+
},
|
|
1483
|
+
caches: {
|
|
1484
|
+
// Python & front-end cache/generated trees. Vendor lineage of the entries:
|
|
1485
|
+
// - repomix `defaultIgnore.ts` (MIT): __pycache__, .mypy_cache,
|
|
1486
|
+
// .pytest_cache, .tox, .venv, .cache, .next, .nuxt, .turbo, .vite,
|
|
1487
|
+
// .parcel-cache, .svelte-kit
|
|
1488
|
+
// - watchfiles `DefaultFilter` (Python-side alignment): __pycache__,
|
|
1489
|
+
// .mypy_cache, .pytest_cache, .ruff_cache, .tox, .nox, .venv
|
|
1490
|
+
// This group is NOT in the default mount set.
|
|
1491
|
+
dirs: [
|
|
1492
|
+
"__pycache__",
|
|
1493
|
+
".mypy_cache",
|
|
1494
|
+
".pytest_cache",
|
|
1495
|
+
".ruff_cache",
|
|
1496
|
+
".tox",
|
|
1497
|
+
".venv",
|
|
1498
|
+
".cache",
|
|
1499
|
+
".next",
|
|
1500
|
+
".nuxt",
|
|
1501
|
+
".turbo",
|
|
1502
|
+
".vite",
|
|
1503
|
+
".parcel-cache",
|
|
1504
|
+
".svelte-kit",
|
|
1505
|
+
".nox",
|
|
1506
|
+
".vscode-test"
|
|
1507
|
+
]
|
|
1508
|
+
},
|
|
1509
|
+
agentDocs: {
|
|
1510
|
+
// Agent-carried instruction files: they are agent self-loading
|
|
1511
|
+
// instructions, not project content. Not in the default mount set.
|
|
1512
|
+
dirs: [],
|
|
1513
|
+
files: ["AGENTS.md", "CLAUDE.md"]
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
var DEFAULT_MOUNTED_PRESETS = ["vcs", "deps", "build"];
|
|
1517
|
+
function compilePresetPatterns(names) {
|
|
1518
|
+
const patterns = [];
|
|
1519
|
+
for (const name of names) {
|
|
1520
|
+
const preset = PRESETS[name];
|
|
1521
|
+
for (const dir of preset.dirs ?? []) patterns.push(`${dir}/`);
|
|
1522
|
+
for (const file of preset.files ?? []) patterns.push(file);
|
|
1523
|
+
}
|
|
1524
|
+
return patterns;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/paths.ts
|
|
1528
|
+
function toPosix(p) {
|
|
1529
|
+
return p.includes("\\") ? p.replace(/\\/g, "/") : p;
|
|
1530
|
+
}
|
|
1531
|
+
function joinPosix(a, b) {
|
|
1532
|
+
if (a === "") return b;
|
|
1533
|
+
if (b === "") return a;
|
|
1534
|
+
return `${a}/${b}`;
|
|
1535
|
+
}
|
|
1536
|
+
function baseNamePosix(rel) {
|
|
1537
|
+
const i = rel.lastIndexOf("/");
|
|
1538
|
+
return i === -1 ? rel : rel.slice(i + 1);
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// src/types.ts
|
|
1542
|
+
var PathscopeConfigError = class extends Error {
|
|
1543
|
+
constructor(message) {
|
|
1544
|
+
super(`[pathscope] ${message}`);
|
|
1545
|
+
this.name = "PathscopeConfigError";
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
var PathscopeGitError = class extends Error {
|
|
1549
|
+
constructor(message) {
|
|
1550
|
+
super(`[pathscope] ${message}`);
|
|
1551
|
+
this.name = "PathscopeGitError";
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
// src/exclusion-engine.ts
|
|
1556
|
+
var nodeExclusionIO = {
|
|
1557
|
+
exists: (dirKey, name) => Promise.resolve((0, import_node_fs2.existsSync)((0, import_node_path.join)(dirKey, ...name.split("/")))),
|
|
1558
|
+
readGitignore: (dirKey) => Promise.resolve(readGitignoreText(dirKey))
|
|
1559
|
+
};
|
|
1560
|
+
function validateOptions(options) {
|
|
1561
|
+
if (options.mountPresets !== void 0) {
|
|
1562
|
+
for (const name of options.mountPresets) {
|
|
1563
|
+
if (!isPresetName(name)) {
|
|
1564
|
+
throw new PathscopeConfigError(
|
|
1565
|
+
`unknown preset "${String(name)}" \u2014 the five groups are vcs | deps | build | caches | agentDocs`
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
for (const rule of options.strict ?? []) {
|
|
1571
|
+
if (typeof rule.pattern !== "string" || rule.pattern.trim() === "") {
|
|
1572
|
+
throw new PathscopeConfigError("every strict rule needs a non-empty gitignore-style pattern");
|
|
1573
|
+
}
|
|
1574
|
+
if (typeof rule.reason !== "string" || rule.reason.trim() === "") {
|
|
1575
|
+
throw new PathscopeConfigError(
|
|
1576
|
+
`strict rule "${rule.pattern}" carries no written reason \u2014 the immune channel serves outbound artifact boundaries only and does not open without one`
|
|
1577
|
+
);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
if (options.maxFiles !== void 0 && (!Number.isInteger(options.maxFiles) || options.maxFiles <= 0)) {
|
|
1581
|
+
throw new PathscopeConfigError(`maxFiles must be a positive integer, got ${String(options.maxFiles)}`);
|
|
1582
|
+
}
|
|
1583
|
+
if (options.alignment !== void 0 && options.alignment !== "git" && options.alignment !== "scanner") {
|
|
1584
|
+
throw new PathscopeConfigError(
|
|
1585
|
+
`unknown alignment "${String(options.alignment)}" \u2014 the faces are git | scanner`
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
if (options.alignment === "scanner" && options.boundaryStones?.gitignoreProxy === true) {
|
|
1589
|
+
throw new PathscopeConfigError(
|
|
1590
|
+
"gitignoreProxy is mounted under the scanner alignment face \u2014 the proxy stone treats a nested .gitignore as territory while the face treats it as rules; the contradiction is rejected instead of adjudicated"
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
for (const key of ["exclude", "override"]) {
|
|
1594
|
+
for (const entry of options[key] ?? []) {
|
|
1595
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
1596
|
+
throw new PathscopeConfigError(`${key} entries must be non-empty gitignore-style pattern strings`);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
for (const home of options.boundaryStones?.configHomes ?? []) {
|
|
1601
|
+
if (typeof home !== "string" || home.trim() === "" || home.startsWith("/") || home.split("/").includes("..")) {
|
|
1602
|
+
throw new PathscopeConfigError(
|
|
1603
|
+
`config home "${String(home)}" must be a non-empty relative name (e.g. ".specs/collect.config.toml")`
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
if (options.boundaryStones?.gitignoreProxy === true && (home === ".gitignore" || home.startsWith(".gitignore/"))) {
|
|
1607
|
+
throw new PathscopeConfigError(
|
|
1608
|
+
`config home "${home}" collides with the .gitignore proxy stone name \u2014 the degenerate collision is rejected instead of adjudicated`
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
for (const entry of options.boundaryStones?.exempt ?? []) {
|
|
1613
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
1614
|
+
throw new PathscopeConfigError(
|
|
1615
|
+
'boundaryStones.exempt entries must be non-empty gitignore-style pattern strings naming subtrees (e.g. "embedded-toolkit/")'
|
|
1616
|
+
);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
function parentDirKey(key) {
|
|
1621
|
+
const stripped = key.replace(/\/+$/, "");
|
|
1622
|
+
if (/^\/[A-Za-z]:$/.test(stripped)) return void 0;
|
|
1623
|
+
const idx = stripped.lastIndexOf("/");
|
|
1624
|
+
if (idx < 0) return void 0;
|
|
1625
|
+
const parent = stripped.slice(0, idx + 1);
|
|
1626
|
+
return parent === stripped ? void 0 : parent;
|
|
1627
|
+
}
|
|
1628
|
+
async function createExclusionEngine(rootKey, options = {}, io = nodeExclusionIO) {
|
|
1629
|
+
validateOptions(options);
|
|
1630
|
+
const respectGitignore = options.respectGitignore !== false;
|
|
1631
|
+
let top;
|
|
1632
|
+
if (respectGitignore) {
|
|
1633
|
+
let dir = rootKey;
|
|
1634
|
+
for (; ; ) {
|
|
1635
|
+
if (await io.exists(dir, ".git")) {
|
|
1636
|
+
top = dir;
|
|
1637
|
+
break;
|
|
1638
|
+
}
|
|
1639
|
+
const parent = parentDirKey(dir);
|
|
1640
|
+
if (parent === void 0) {
|
|
1641
|
+
top = dir;
|
|
1642
|
+
break;
|
|
1643
|
+
}
|
|
1644
|
+
dir = parent;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
const inheritedLines = [];
|
|
1648
|
+
if (top !== void 0 && top !== rootKey) {
|
|
1649
|
+
const ancestors = [];
|
|
1650
|
+
let cur = parentDirKey(rootKey);
|
|
1651
|
+
while (cur !== void 0) {
|
|
1652
|
+
ancestors.push(cur);
|
|
1653
|
+
if (cur === top) break;
|
|
1654
|
+
cur = parentDirKey(cur);
|
|
1655
|
+
}
|
|
1656
|
+
ancestors.reverse();
|
|
1657
|
+
for (const ancestor of ancestors) {
|
|
1658
|
+
const text = await io.readGitignore(ancestor);
|
|
1659
|
+
if (text !== null) inheritedLines.push(...splitLines(text));
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
const rootPrefix = top !== void 0 && rootKey.startsWith(top) ? top : rootKey;
|
|
1663
|
+
const offRel = rootKey.slice(rootPrefix.length).replace(/^\//, "");
|
|
1664
|
+
const toCanonical = (rel) => offRel === "" ? rel : `${offRel}/${rel}`;
|
|
1665
|
+
const mount = (patterns, relDir = "") => {
|
|
1666
|
+
const prefix = joinPosix(offRel, relDir);
|
|
1667
|
+
return prefix === "" ? patterns : reanchorLines(patterns, prefix);
|
|
1668
|
+
};
|
|
1669
|
+
const core = (0, import_ignore.default)();
|
|
1670
|
+
const presetPatterns = compilePresetPatterns(options.mountPresets ?? DEFAULT_MOUNTED_PRESETS);
|
|
1671
|
+
if (presetPatterns.length > 0) core.add(mount(presetPatterns));
|
|
1672
|
+
if (inheritedLines.length > 0) core.add(inheritedLines);
|
|
1673
|
+
const rootIgnoreText = respectGitignore ? await io.readGitignore(rootKey) : null;
|
|
1674
|
+
if (rootIgnoreText !== null) {
|
|
1675
|
+
const lines = mount(splitLines(rootIgnoreText));
|
|
1676
|
+
if (lines.length > 0) core.add(lines);
|
|
1677
|
+
}
|
|
1678
|
+
const policy = (0, import_ignore.default)();
|
|
1679
|
+
if (options.exclude !== void 0 && options.exclude.length > 0) {
|
|
1680
|
+
policy.add(mount(options.exclude));
|
|
1681
|
+
}
|
|
1682
|
+
const overrideIg = (0, import_ignore.default)();
|
|
1683
|
+
if (options.override !== void 0 && options.override.length > 0) {
|
|
1684
|
+
overrideIg.add(mount(options.override));
|
|
1685
|
+
}
|
|
1686
|
+
const strictIg = (0, import_ignore.default)();
|
|
1687
|
+
if (options.strict !== void 0 && options.strict.length > 0) {
|
|
1688
|
+
strictIg.add(mount(options.strict.map((rule) => rule.pattern)));
|
|
1689
|
+
}
|
|
1690
|
+
const configHomes = options.boundaryStones?.configHomes ?? [];
|
|
1691
|
+
const gitignoreProxy = options.boundaryStones?.gitignoreProxy === true;
|
|
1692
|
+
const stoneNames = [
|
|
1693
|
+
".git",
|
|
1694
|
+
...configHomes,
|
|
1695
|
+
...gitignoreProxy ? [".gitignore"] : []
|
|
1696
|
+
];
|
|
1697
|
+
const excludeDotEntries = options.excludeDotEntries !== false;
|
|
1698
|
+
const exemptPatterns = options.boundaryStones?.exempt ?? [];
|
|
1699
|
+
const exemptIg = exemptPatterns.length > 0 ? (0, import_ignore.default)() : null;
|
|
1700
|
+
if (exemptIg !== null) exemptIg.add(exemptPatterns);
|
|
1701
|
+
const isExemptDir = (relDir) => {
|
|
1702
|
+
if (exemptIg === null) return false;
|
|
1703
|
+
if (!exemptIg.test(`${relDir}/`).ignored) return false;
|
|
1704
|
+
const cut = relDir.lastIndexOf("/");
|
|
1705
|
+
if (cut === -1) return true;
|
|
1706
|
+
return !exemptIg.test(`${relDir.slice(0, cut)}/`).ignored;
|
|
1707
|
+
};
|
|
1708
|
+
const exemptibleNames = gitignoreProxy ? /* @__PURE__ */ new Set([".git", ".gitignore"]) : /* @__PURE__ */ new Set([".git"]);
|
|
1709
|
+
const unenforcedNames = options.alignment === "scanner" ? /* @__PURE__ */ new Set([".git"]) : null;
|
|
1710
|
+
const stoneTruncates = (hit, key) => {
|
|
1711
|
+
if (hit === true) return true;
|
|
1712
|
+
if (hit == null || !Array.isArray(hit) || hit.length === 0) return false;
|
|
1713
|
+
let names = hit;
|
|
1714
|
+
if (isExemptDir(key.slice(rootKey.length + 1))) {
|
|
1715
|
+
names = names.filter((name) => !exemptibleNames.has(name));
|
|
1716
|
+
}
|
|
1717
|
+
if (unenforcedNames !== null) {
|
|
1718
|
+
names = names.filter((name) => !unenforcedNames.has(name));
|
|
1719
|
+
}
|
|
1720
|
+
return names.length > 0;
|
|
1721
|
+
};
|
|
1722
|
+
const combinedExcludes = (canonical) => {
|
|
1723
|
+
const policyResult = policy.test(canonical);
|
|
1724
|
+
if (policyResult.ignored) return true;
|
|
1725
|
+
if (policyResult.unignored) return false;
|
|
1726
|
+
return core.test(canonical).ignored;
|
|
1727
|
+
};
|
|
1728
|
+
return {
|
|
1729
|
+
rootKey,
|
|
1730
|
+
stoneNames,
|
|
1731
|
+
excludeDirectory(name, dirPath, stoneHit) {
|
|
1732
|
+
const key = dirPath.replace(/\/+$/, "");
|
|
1733
|
+
if (key !== rootKey && stoneTruncates(stoneHit, key)) return true;
|
|
1734
|
+
const relDir = key.slice(rootKey.length + 1);
|
|
1735
|
+
const canonicalDir = toCanonical(`${relDir}/`);
|
|
1736
|
+
if (strictIg.test(canonicalDir).ignored) return true;
|
|
1737
|
+
if (overrideIg.test(canonicalDir).ignored) return false;
|
|
1738
|
+
const policyResult = policy.test(canonicalDir);
|
|
1739
|
+
if (policyResult.ignored) return true;
|
|
1740
|
+
if (policyResult.unignored) {
|
|
1741
|
+
if (core.test(canonicalDir).ignored) {
|
|
1742
|
+
core.add(`!/${canonicalDir}`);
|
|
1743
|
+
}
|
|
1744
|
+
} else if (core.test(canonicalDir).ignored) {
|
|
1745
|
+
return true;
|
|
1746
|
+
}
|
|
1747
|
+
if (excludeDotEntries && name.startsWith(".")) return true;
|
|
1748
|
+
return false;
|
|
1749
|
+
},
|
|
1750
|
+
foldGitignore(dirPath, text) {
|
|
1751
|
+
if (text == null || !respectGitignore) return;
|
|
1752
|
+
const key = dirPath.replace(/\/+$/, "");
|
|
1753
|
+
if (key === rootKey) return;
|
|
1754
|
+
const relDir = key.slice(rootKey.length + 1);
|
|
1755
|
+
const lines = mount(splitLines(text), relDir);
|
|
1756
|
+
if (lines.length > 0) core.add(lines);
|
|
1757
|
+
},
|
|
1758
|
+
admitFile(relPath) {
|
|
1759
|
+
const canonical = toCanonical(relPath);
|
|
1760
|
+
if (strictIg.test(canonical).ignored) return false;
|
|
1761
|
+
if (overrideIg.test(canonical).ignored) return true;
|
|
1762
|
+
if (combinedExcludes(canonical)) return false;
|
|
1763
|
+
if (excludeDotEntries && baseNamePosix(relPath).startsWith(".")) return false;
|
|
1764
|
+
return true;
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
// src/engine.ts
|
|
1770
|
+
var DEFAULT_MAX_FILES = 2e3;
|
|
1771
|
+
async function walkScope(root, options = {}) {
|
|
1772
|
+
validateOptions(options);
|
|
1773
|
+
const rootNative = (0, import_node_path2.resolve)(root);
|
|
1774
|
+
if (!(0, import_node_fs3.existsSync)(rootNative)) {
|
|
1775
|
+
throw new PathscopeConfigError(`scan root does not exist: ${rootNative}`);
|
|
1776
|
+
}
|
|
1777
|
+
const scanKey = rootNative.replace(/\\/g, "/");
|
|
1778
|
+
const engine = await createExclusionEngine(scanKey, options);
|
|
1779
|
+
const stoneHits = (key) => {
|
|
1780
|
+
const hits = [];
|
|
1781
|
+
for (const name of engine.stoneNames) {
|
|
1782
|
+
if ((0, import_node_fs3.existsSync)((0, import_node_path2.join)(key, ...name.split("/")))) hits.push(name);
|
|
1783
|
+
}
|
|
1784
|
+
return hits;
|
|
1785
|
+
};
|
|
1786
|
+
const diagnostics = [];
|
|
1787
|
+
const controller = new AbortController();
|
|
1788
|
+
const maxFiles = options.maxFiles ?? DEFAULT_MAX_FILES;
|
|
1789
|
+
let included = 0;
|
|
1790
|
+
let budgetCut = false;
|
|
1791
|
+
const excludeDirectory = (dirName, dirPath) => {
|
|
1792
|
+
const key = dirPath.replace(/\/+$/, "");
|
|
1793
|
+
if (engine.excludeDirectory(dirName, key, stoneHits(key))) return true;
|
|
1794
|
+
engine.foldGitignore(key, readGitignoreText(key));
|
|
1795
|
+
return false;
|
|
1796
|
+
};
|
|
1797
|
+
const keepFile = (rel) => {
|
|
1798
|
+
if (budgetCut) return false;
|
|
1799
|
+
if (!engine.admitFile(rel)) return false;
|
|
1800
|
+
if (included >= maxFiles) {
|
|
1801
|
+
budgetCut = true;
|
|
1802
|
+
controller.abort();
|
|
1803
|
+
diagnostics.push({
|
|
1804
|
+
code: "budget-exceeded",
|
|
1805
|
+
limit: maxFiles,
|
|
1806
|
+
message: `file budget of ${maxFiles} reached \u2014 traversal was cut here (never a silent cut)`
|
|
1807
|
+
});
|
|
1808
|
+
return false;
|
|
1809
|
+
}
|
|
1810
|
+
included += 1;
|
|
1811
|
+
return true;
|
|
1812
|
+
};
|
|
1813
|
+
const files = await new import_fdir.fdir({
|
|
1814
|
+
pathSeparator: "/",
|
|
1815
|
+
exclude: excludeDirectory,
|
|
1816
|
+
signal: controller.signal,
|
|
1817
|
+
resolveSymlinks: options.followSymlinks === true,
|
|
1818
|
+
// Keep descended-through-symlink paths in the scan-root universe instead
|
|
1819
|
+
// of emitting real (possibly outside-root) paths.
|
|
1820
|
+
useRealPaths: false,
|
|
1821
|
+
// Unreadable directories are skipped, ripgrep-style; the loud channel is
|
|
1822
|
+
// the budget, not per-directory I/O errors.
|
|
1823
|
+
suppressErrors: true
|
|
1824
|
+
}).withRelativePaths().filter((path3) => keepFile(path3)).crawl(rootNative).withPromise();
|
|
1825
|
+
return { files: [...files].sort(), diagnostics };
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
// src/universe.ts
|
|
1829
|
+
var import_node_child_process = require("node:child_process");
|
|
1830
|
+
var import_node_path3 = require("node:path");
|
|
1831
|
+
var import_ignore2 = __toESM(require_ignore(), 1);
|
|
1832
|
+
var repoRootCache = /* @__PURE__ */ new Map();
|
|
1833
|
+
function clearUniverseCache() {
|
|
1834
|
+
repoRootCache.clear();
|
|
1835
|
+
}
|
|
1836
|
+
function runGit(cwd, args) {
|
|
1837
|
+
const run = (0, import_node_child_process.spawnSync)("git", args, { cwd, encoding: "utf8" });
|
|
1838
|
+
if (run.error) {
|
|
1839
|
+
const code = run.error.code;
|
|
1840
|
+
if (code === "ENOENT") {
|
|
1841
|
+
throw new PathscopeGitError(
|
|
1842
|
+
'git binary not found on PATH \u2014 the universe is "ask git" and cannot be computed without it'
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
throw new PathscopeGitError(`git ${args.join(" ")} could not be spawned: ${String(run.error)}`);
|
|
1846
|
+
}
|
|
1847
|
+
if (run.status !== 0) {
|
|
1848
|
+
const stderr = String(run.stderr).trim();
|
|
1849
|
+
if (/not a git repository/i.test(stderr)) {
|
|
1850
|
+
throw new PathscopeGitError(
|
|
1851
|
+
`root is not inside a git repository: ${cwd} (git ${args.join(" ")} failed: ${stderr})`
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
throw new PathscopeGitError(
|
|
1855
|
+
`git ${args.join(" ")} failed (exit ${String(run.status)}): ${stderr}`
|
|
1856
|
+
);
|
|
1857
|
+
}
|
|
1858
|
+
return run.stdout;
|
|
1859
|
+
}
|
|
1860
|
+
function repoRootOf(rootAbs) {
|
|
1861
|
+
const key = process.platform === "win32" ? rootAbs.toLowerCase() : rootAbs;
|
|
1862
|
+
const hit = repoRootCache.get(key);
|
|
1863
|
+
if (hit !== void 0) return hit;
|
|
1864
|
+
const top = runGit(rootAbs, ["rev-parse", "--show-toplevel"]).split("\n")[0]?.trim() ?? "";
|
|
1865
|
+
if (top === "") {
|
|
1866
|
+
throw new PathscopeGitError(
|
|
1867
|
+
`git rev-parse --show-toplevel returned no repository root for ${rootAbs}`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
repoRootCache.set(key, top);
|
|
1871
|
+
return top;
|
|
1872
|
+
}
|
|
1873
|
+
function filterLsFilesStageRecords(stdout) {
|
|
1874
|
+
const kept = /* @__PURE__ */ new Set();
|
|
1875
|
+
for (const record of stdout.split("\0")) {
|
|
1876
|
+
if (record === "") continue;
|
|
1877
|
+
const tab = record.indexOf(" ");
|
|
1878
|
+
if (tab === -1) {
|
|
1879
|
+
kept.add(record);
|
|
1880
|
+
continue;
|
|
1881
|
+
}
|
|
1882
|
+
const mode = record.slice(0, tab).split(" ")[0];
|
|
1883
|
+
if (mode === "160000" || mode === "120000") continue;
|
|
1884
|
+
kept.add(record.slice(tab + 1));
|
|
1885
|
+
}
|
|
1886
|
+
return [...kept];
|
|
1887
|
+
}
|
|
1888
|
+
function filterDiffRawRecords(stdout) {
|
|
1889
|
+
const kept = /* @__PURE__ */ new Set();
|
|
1890
|
+
const tokens = stdout.split("\0");
|
|
1891
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
1892
|
+
const token = tokens[i];
|
|
1893
|
+
if (token === "" || !token.startsWith(":")) continue;
|
|
1894
|
+
const [, dstMode, , , status] = token.split(" ");
|
|
1895
|
+
const path3 = tokens[i + 1] ?? "";
|
|
1896
|
+
const destination = status === "R" || status === "C" ? tokens[i + 2] ?? "" : path3;
|
|
1897
|
+
if (dstMode !== "160000" && dstMode !== "120000") kept.add(destination);
|
|
1898
|
+
i += status === "R" || status === "C" ? 2 : 1;
|
|
1899
|
+
}
|
|
1900
|
+
return [...kept];
|
|
1901
|
+
}
|
|
1902
|
+
function rebaseToRoot(repoRootNative, rootAbs, repoRelPosix) {
|
|
1903
|
+
const rel = (0, import_node_path3.relative)(rootAbs, (0, import_node_path3.join)(repoRootNative, repoRelPosix));
|
|
1904
|
+
if (rel === "" || (0, import_node_path3.isAbsolute)(rel) || rel.startsWith("..")) return null;
|
|
1905
|
+
return toPosix(rel);
|
|
1906
|
+
}
|
|
1907
|
+
function validateFilter(filter) {
|
|
1908
|
+
for (const name of filter.mountPresets ?? []) {
|
|
1909
|
+
if (!isPresetName(name)) {
|
|
1910
|
+
throw new PathscopeConfigError(
|
|
1911
|
+
`unknown preset "${String(name)}" in universe filter \u2014 the five groups are vcs | deps | build | caches | agentDocs`
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
for (const entry of filter.exclude ?? []) {
|
|
1916
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
1917
|
+
throw new PathscopeConfigError("filter.exclude entries must be non-empty gitignore-style pattern strings");
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
function survivesFilter(file, table) {
|
|
1922
|
+
const parts = file.split("/");
|
|
1923
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
1924
|
+
const isDir = i < parts.length;
|
|
1925
|
+
const probe = parts.slice(0, i).join("/") + (isDir ? "/" : "");
|
|
1926
|
+
if (table.test(probe).ignored) return false;
|
|
1927
|
+
}
|
|
1928
|
+
return true;
|
|
1929
|
+
}
|
|
1930
|
+
async function gitUniverse(root, options = {}) {
|
|
1931
|
+
const variant = options.variant ?? "all";
|
|
1932
|
+
if (variant !== "all" && variant !== "tree" && variant !== "staged") {
|
|
1933
|
+
throw new PathscopeConfigError(
|
|
1934
|
+
`unknown variant "${String(variant)}" \u2014 the universe is all | tree | staged`
|
|
1935
|
+
);
|
|
1936
|
+
}
|
|
1937
|
+
if (options.filter !== void 0) validateFilter(options.filter);
|
|
1938
|
+
const rootAbs = (0, import_node_path3.resolve)(root);
|
|
1939
|
+
const repoRoot = repoRootOf(rootAbs);
|
|
1940
|
+
let repoRelative;
|
|
1941
|
+
if (variant === "staged") {
|
|
1942
|
+
repoRelative = filterDiffRawRecords(
|
|
1943
|
+
runGit(rootAbs, ["diff", "--cached", "-z", "--raw", "--no-renames", "--diff-filter=ACMR"])
|
|
1944
|
+
);
|
|
1945
|
+
} else {
|
|
1946
|
+
const args = ["ls-files", "-z", "--full-name", "--stage"];
|
|
1947
|
+
if (variant === "all") args.push("--cached", "--others", "--exclude-standard");
|
|
1948
|
+
repoRelative = filterLsFilesStageRecords(runGit(rootAbs, args));
|
|
1949
|
+
}
|
|
1950
|
+
let files = repoRelative.map((p) => rebaseToRoot(repoRoot, rootAbs, p)).filter((p) => p !== null).sort();
|
|
1951
|
+
if (options.filter !== void 0) {
|
|
1952
|
+
const table = (0, import_ignore2.default)();
|
|
1953
|
+
const patterns = [
|
|
1954
|
+
...compilePresetPatterns(options.filter.mountPresets ?? []),
|
|
1955
|
+
...options.filter.exclude ?? []
|
|
1956
|
+
];
|
|
1957
|
+
if (patterns.length > 0) table.add(patterns);
|
|
1958
|
+
files = files.filter((file) => survivesFilter(file, table));
|
|
1959
|
+
}
|
|
1960
|
+
return { files, repoRoot, diagnostics: [] };
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
// src/discover.ts
|
|
1964
|
+
var import_node_path6 = require("node:path");
|
|
1965
|
+
|
|
1966
|
+
// node_modules/.pnpm/find-up@8.0.0/node_modules/find-up/index.js
|
|
1967
|
+
var import_node_path5 = __toESM(require("node:path"), 1);
|
|
1968
|
+
|
|
1969
|
+
// node_modules/.pnpm/locate-path@8.0.0/node_modules/locate-path/index.js
|
|
1970
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
1971
|
+
var import_node_path4 = __toESM(require("node:path"), 1);
|
|
1972
|
+
var import_node_fs4 = __toESM(require("node:fs"), 1);
|
|
1973
|
+
var import_node_url = require("node:url");
|
|
1974
|
+
var typeMappings = {
|
|
1975
|
+
directory: "isDirectory",
|
|
1976
|
+
file: "isFile"
|
|
1977
|
+
};
|
|
1978
|
+
function checkType(type) {
|
|
1979
|
+
if (type === "both" || Object.hasOwn(typeMappings, type)) {
|
|
1980
|
+
return;
|
|
1981
|
+
}
|
|
1982
|
+
throw new Error(`Invalid type specified: ${type}`);
|
|
1983
|
+
}
|
|
1984
|
+
var matchType = (type, stat) => type === "both" ? stat.isFile() || stat.isDirectory() : stat[typeMappings[type]]();
|
|
1985
|
+
var toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
1986
|
+
function locatePathSync(paths, {
|
|
1987
|
+
cwd = import_node_process.default.cwd(),
|
|
1988
|
+
type = "file",
|
|
1989
|
+
allowSymlinks = true
|
|
1990
|
+
} = {}) {
|
|
1991
|
+
checkType(type);
|
|
1992
|
+
cwd = toPath(cwd);
|
|
1993
|
+
const statFunction = allowSymlinks ? import_node_fs4.default.statSync : import_node_fs4.default.lstatSync;
|
|
1994
|
+
for (const path_ of paths) {
|
|
1995
|
+
try {
|
|
1996
|
+
const stat = statFunction(import_node_path4.default.resolve(cwd, path_), {
|
|
1997
|
+
throwIfNoEntry: false
|
|
1998
|
+
});
|
|
1999
|
+
if (!stat) {
|
|
2000
|
+
continue;
|
|
2001
|
+
}
|
|
2002
|
+
if (matchType(type, stat)) {
|
|
2003
|
+
return path_;
|
|
2004
|
+
}
|
|
2005
|
+
} catch {
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
// node_modules/.pnpm/unicorn-magic@0.3.0/node_modules/unicorn-magic/node.js
|
|
2011
|
+
var import_node_util = require("node:util");
|
|
2012
|
+
var import_node_child_process2 = require("node:child_process");
|
|
2013
|
+
var import_node_url2 = require("node:url");
|
|
2014
|
+
var execFileOriginal = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
2015
|
+
function toPath2(urlOrPath) {
|
|
2016
|
+
return urlOrPath instanceof URL ? (0, import_node_url2.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
2017
|
+
}
|
|
2018
|
+
var TEN_MEGABYTES_IN_BYTES = 10 * 1024 * 1024;
|
|
2019
|
+
|
|
2020
|
+
// node_modules/.pnpm/find-up@8.0.0/node_modules/find-up/index.js
|
|
2021
|
+
var findUpStop = /* @__PURE__ */ Symbol("findUpStop");
|
|
2022
|
+
function findUpMultipleSync(name, options = {}) {
|
|
2023
|
+
let directory = import_node_path5.default.resolve(toPath2(options.cwd) ?? "");
|
|
2024
|
+
const { root } = import_node_path5.default.parse(directory);
|
|
2025
|
+
const stopAt = import_node_path5.default.resolve(directory, toPath2(options.stopAt) ?? root);
|
|
2026
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
2027
|
+
const paths = [name].flat();
|
|
2028
|
+
const runMatcher = (locateOptions) => {
|
|
2029
|
+
if (typeof name !== "function") {
|
|
2030
|
+
return locatePathSync(paths, locateOptions);
|
|
2031
|
+
}
|
|
2032
|
+
const foundPath = name(locateOptions.cwd);
|
|
2033
|
+
if (typeof foundPath === "string") {
|
|
2034
|
+
return locatePathSync([foundPath], locateOptions);
|
|
2035
|
+
}
|
|
2036
|
+
return foundPath;
|
|
2037
|
+
};
|
|
2038
|
+
const matches = [];
|
|
2039
|
+
while (true) {
|
|
2040
|
+
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
2041
|
+
if (foundPath === findUpStop) {
|
|
2042
|
+
break;
|
|
2043
|
+
}
|
|
2044
|
+
if (foundPath) {
|
|
2045
|
+
matches.push(import_node_path5.default.resolve(directory, foundPath));
|
|
2046
|
+
}
|
|
2047
|
+
if (directory === stopAt || matches.length >= limit) {
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
directory = import_node_path5.default.dirname(directory);
|
|
2051
|
+
}
|
|
2052
|
+
return matches;
|
|
2053
|
+
}
|
|
2054
|
+
function findUpSync(name, options = {}) {
|
|
2055
|
+
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
|
2056
|
+
return matches[0];
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/discover.ts
|
|
2060
|
+
function validateNames(names) {
|
|
2061
|
+
if (!Array.isArray(names) || names.length === 0) {
|
|
2062
|
+
throw new PathscopeConfigError("locateNearest needs a non-empty set of residence names");
|
|
2063
|
+
}
|
|
2064
|
+
for (const name of names) {
|
|
2065
|
+
if (typeof name !== "string" || name.trim() === "" || name.startsWith("/")) {
|
|
2066
|
+
throw new PathscopeConfigError(
|
|
2067
|
+
`residence name "${String(name)}" must be a non-empty relative name (e.g. ".specs/collect.config.toml")`
|
|
2068
|
+
);
|
|
2069
|
+
}
|
|
2070
|
+
if (name.split("/").includes("..")) {
|
|
2071
|
+
throw new PathscopeConfigError(`residence name "${name}" must not climb with ".."`);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
function locateNearest(names, options = {}) {
|
|
2076
|
+
validateNames(names);
|
|
2077
|
+
const found = findUpSync(names, { cwd: options.cwd, stopAt: options.stopAt });
|
|
2078
|
+
if (found === void 0) return null;
|
|
2079
|
+
const foundPosix = toPosix(found);
|
|
2080
|
+
const fold = process.platform === "win32" ? (s) => s.toLowerCase() : (s) => s;
|
|
2081
|
+
const suffixOf = (name) => `/${name}`;
|
|
2082
|
+
const hit = names.find(
|
|
2083
|
+
(name) => foundPosix.length >= suffixOf(name).length && fold(foundPosix.slice(foundPosix.length - suffixOf(name).length)) === fold(suffixOf(name))
|
|
2084
|
+
);
|
|
2085
|
+
if (hit === void 0) {
|
|
2086
|
+
return { name: (0, import_node_path6.basename)(found), path: found };
|
|
2087
|
+
}
|
|
2088
|
+
return { name: hit, path: found };
|
|
2089
|
+
}
|
|
2090
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2091
|
+
0 && (module.exports = {
|
|
2092
|
+
DEFAULT_MOUNTED_PRESETS,
|
|
2093
|
+
PRESETS,
|
|
2094
|
+
PathscopeConfigError,
|
|
2095
|
+
PathscopeGitError,
|
|
2096
|
+
clearUniverseCache,
|
|
2097
|
+
createExclusionEngine,
|
|
2098
|
+
gitUniverse,
|
|
2099
|
+
locateNearest,
|
|
2100
|
+
nodeExclusionIO,
|
|
2101
|
+
walkScope
|
|
2102
|
+
});
|