@rslint/core 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/207.js +897 -0
- package/dist/cli.js +1 -894
- package/dist/config-loader.js +33 -2
- package/dist/index.d.ts +93 -387
- package/dist/index.js +259 -139
- package/dist/internal.d.ts +135 -0
- package/dist/internal.js +167 -0
- package/dist/service.d.ts +33 -27
- package/dist/service.js +7 -20
- package/package.json +17 -19
- package/dist/34.js +0 -33
- package/dist/browser.d.ts +0 -52
- package/dist/browser.js +0 -115
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
2
|
import node_fs from "node:fs";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
-
import picomatch from "picomatch";
|
|
5
|
-
import fs_0, * as __rspack_external_fs from "fs";
|
|
6
|
-
import path_0, { basename, dirname, normalize, posix, relative as external_path_relative, resolve, sep } from "path";
|
|
7
|
-
import { fileURLToPath } from "url";
|
|
8
|
-
import { createRequire } from "module";
|
|
9
4
|
import { loadConfigFile, collectPluginMeta, normalizeConfig } from "./config-loader.js";
|
|
5
|
+
import { filterConfigsByParentIgnores, discoverConfigs } from "./207.js";
|
|
10
6
|
function isJSConfigFile(filePath) {
|
|
11
7
|
return /\.(ts|mts|js|mjs)$/.test(filePath);
|
|
12
8
|
}
|
|
@@ -96,895 +92,6 @@ function classifyArgs(positionals, cwd) {
|
|
|
96
92
|
dirs
|
|
97
93
|
};
|
|
98
94
|
}
|
|
99
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
100
|
-
function cleanPath(path) {
|
|
101
|
-
let normalized = normalize(path);
|
|
102
|
-
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
|
|
103
|
-
return normalized;
|
|
104
|
-
}
|
|
105
|
-
const SLASHES_REGEX = /[\\/]/g;
|
|
106
|
-
function convertSlashes(path, separator) {
|
|
107
|
-
return path.replace(SLASHES_REGEX, separator);
|
|
108
|
-
}
|
|
109
|
-
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
|
110
|
-
function isRootDirectory(path) {
|
|
111
|
-
return "/" === path || WINDOWS_ROOT_DIR_REGEX.test(path);
|
|
112
|
-
}
|
|
113
|
-
function normalizePath(path, options) {
|
|
114
|
-
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
|
115
|
-
const pathNeedsCleaning = "win32" === process.platform && path.includes("/") || path.startsWith(".");
|
|
116
|
-
if (resolvePaths) path = resolve(path);
|
|
117
|
-
if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
|
|
118
|
-
if ("." === path) return "";
|
|
119
|
-
const needsSeperator = path[path.length - 1] !== pathSeparator;
|
|
120
|
-
return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
|
|
121
|
-
}
|
|
122
|
-
function joinPathWithBasePath(filename, directoryPath) {
|
|
123
|
-
return directoryPath + filename;
|
|
124
|
-
}
|
|
125
|
-
function joinPathWithRelativePath(root, options) {
|
|
126
|
-
return function(filename, directoryPath) {
|
|
127
|
-
const sameRoot = directoryPath.startsWith(root);
|
|
128
|
-
if (sameRoot) return directoryPath.slice(root.length) + filename;
|
|
129
|
-
return convertSlashes(external_path_relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
function joinPath(filename) {
|
|
133
|
-
return filename;
|
|
134
|
-
}
|
|
135
|
-
function joinDirectoryPath(filename, directoryPath, separator) {
|
|
136
|
-
return directoryPath + filename + separator;
|
|
137
|
-
}
|
|
138
|
-
function build$7(root, options) {
|
|
139
|
-
const { relativePaths, includeBasePath } = options;
|
|
140
|
-
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
|
141
|
-
}
|
|
142
|
-
function pushDirectoryWithRelativePath(root) {
|
|
143
|
-
return function(directoryPath, paths) {
|
|
144
|
-
paths.push(directoryPath.substring(root.length) || ".");
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function pushDirectoryFilterWithRelativePath(root) {
|
|
148
|
-
return function(directoryPath, paths, filters) {
|
|
149
|
-
const relativePath = directoryPath.substring(root.length) || ".";
|
|
150
|
-
if (filters.every((filter)=>filter(relativePath, true))) paths.push(relativePath);
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
const pushDirectory = (directoryPath, paths)=>{
|
|
154
|
-
paths.push(directoryPath || ".");
|
|
155
|
-
};
|
|
156
|
-
const pushDirectoryFilter = (directoryPath, paths, filters)=>{
|
|
157
|
-
const path = directoryPath || ".";
|
|
158
|
-
if (filters.every((filter)=>filter(path, true))) paths.push(path);
|
|
159
|
-
};
|
|
160
|
-
const empty$2 = ()=>{};
|
|
161
|
-
function build$6(root, options) {
|
|
162
|
-
const { includeDirs, filters, relativePaths } = options;
|
|
163
|
-
if (!includeDirs) return empty$2;
|
|
164
|
-
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
|
165
|
-
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
|
166
|
-
}
|
|
167
|
-
const pushFileFilterAndCount = (filename, _paths, counts, filters)=>{
|
|
168
|
-
if (filters.every((filter)=>filter(filename, false))) counts.files++;
|
|
169
|
-
};
|
|
170
|
-
const pushFileFilter = (filename, paths, _counts, filters)=>{
|
|
171
|
-
if (filters.every((filter)=>filter(filename, false))) paths.push(filename);
|
|
172
|
-
};
|
|
173
|
-
const pushFileCount = (_filename, _paths, counts, _filters)=>{
|
|
174
|
-
counts.files++;
|
|
175
|
-
};
|
|
176
|
-
const pushFile = (filename, paths)=>{
|
|
177
|
-
paths.push(filename);
|
|
178
|
-
};
|
|
179
|
-
const empty$1 = ()=>{};
|
|
180
|
-
function build$5(options) {
|
|
181
|
-
const { excludeFiles, filters, onlyCounts } = options;
|
|
182
|
-
if (excludeFiles) return empty$1;
|
|
183
|
-
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
|
184
|
-
if (onlyCounts) return pushFileCount;
|
|
185
|
-
return pushFile;
|
|
186
|
-
}
|
|
187
|
-
const getArray = (paths)=>paths;
|
|
188
|
-
const getArrayGroup = ()=>[
|
|
189
|
-
""
|
|
190
|
-
].slice(0, 0);
|
|
191
|
-
function build$4(options) {
|
|
192
|
-
return options.group ? getArrayGroup : getArray;
|
|
193
|
-
}
|
|
194
|
-
const groupFiles = (groups, directory, files)=>{
|
|
195
|
-
groups.push({
|
|
196
|
-
directory,
|
|
197
|
-
files,
|
|
198
|
-
dir: directory
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
const empty = ()=>{};
|
|
202
|
-
function build$3(options) {
|
|
203
|
-
return options.group ? groupFiles : empty;
|
|
204
|
-
}
|
|
205
|
-
const resolveSymlinksAsync = function(path, state, callback$1) {
|
|
206
|
-
const { queue, fs, options: { suppressErrors } } = state;
|
|
207
|
-
queue.enqueue();
|
|
208
|
-
fs.realpath(path, (error, resolvedPath)=>{
|
|
209
|
-
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
|
210
|
-
fs.stat(resolvedPath, (error$1, stat)=>{
|
|
211
|
-
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
|
212
|
-
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
|
|
213
|
-
callback$1(stat, resolvedPath);
|
|
214
|
-
queue.dequeue(null, state);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
const resolveSymlinks = function(path, state, callback$1) {
|
|
219
|
-
const { queue, fs, options: { suppressErrors } } = state;
|
|
220
|
-
queue.enqueue();
|
|
221
|
-
try {
|
|
222
|
-
const resolvedPath = fs.realpathSync(path);
|
|
223
|
-
const stat = fs.statSync(resolvedPath);
|
|
224
|
-
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
|
|
225
|
-
callback$1(stat, resolvedPath);
|
|
226
|
-
} catch (e) {
|
|
227
|
-
if (!suppressErrors) throw e;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
function build$2(options, isSynchronous) {
|
|
231
|
-
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
|
232
|
-
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
|
233
|
-
}
|
|
234
|
-
function isRecursive(path, resolved, state) {
|
|
235
|
-
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
|
236
|
-
let parent = dirname(path);
|
|
237
|
-
let depth = 1;
|
|
238
|
-
while(parent !== state.root && depth < 2){
|
|
239
|
-
const resolvedPath = state.symlinks.get(parent);
|
|
240
|
-
const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
|
|
241
|
-
if (isSameRoot) depth++;
|
|
242
|
-
else parent = dirname(parent);
|
|
243
|
-
}
|
|
244
|
-
state.symlinks.set(path, resolved);
|
|
245
|
-
return depth > 1;
|
|
246
|
-
}
|
|
247
|
-
function isRecursiveUsingRealPaths(resolved, state) {
|
|
248
|
-
return state.visited.includes(resolved + state.options.pathSeparator);
|
|
249
|
-
}
|
|
250
|
-
const onlyCountsSync = (state)=>state.counts;
|
|
251
|
-
const groupsSync = (state)=>state.groups;
|
|
252
|
-
const defaultSync = (state)=>state.paths;
|
|
253
|
-
const limitFilesSync = (state)=>state.paths.slice(0, state.options.maxFiles);
|
|
254
|
-
const onlyCountsAsync = (state, error, callback$1)=>{
|
|
255
|
-
report(error, callback$1, state.counts, state.options.suppressErrors);
|
|
256
|
-
return null;
|
|
257
|
-
};
|
|
258
|
-
const defaultAsync = (state, error, callback$1)=>{
|
|
259
|
-
report(error, callback$1, state.paths, state.options.suppressErrors);
|
|
260
|
-
return null;
|
|
261
|
-
};
|
|
262
|
-
const limitFilesAsync = (state, error, callback$1)=>{
|
|
263
|
-
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
|
264
|
-
return null;
|
|
265
|
-
};
|
|
266
|
-
const groupsAsync = (state, error, callback$1)=>{
|
|
267
|
-
report(error, callback$1, state.groups, state.options.suppressErrors);
|
|
268
|
-
return null;
|
|
269
|
-
};
|
|
270
|
-
function report(error, callback$1, output, suppressErrors) {
|
|
271
|
-
callback$1(error && !suppressErrors ? error : null, output);
|
|
272
|
-
}
|
|
273
|
-
function build$1(options, isSynchronous) {
|
|
274
|
-
const { onlyCounts, group, maxFiles } = options;
|
|
275
|
-
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
|
276
|
-
if (group) return isSynchronous ? groupsSync : groupsAsync;
|
|
277
|
-
if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
|
278
|
-
return isSynchronous ? defaultSync : defaultAsync;
|
|
279
|
-
}
|
|
280
|
-
const readdirOpts = {
|
|
281
|
-
withFileTypes: true
|
|
282
|
-
};
|
|
283
|
-
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1)=>{
|
|
284
|
-
state.queue.enqueue();
|
|
285
|
-
if (currentDepth < 0) return state.queue.dequeue(null, state);
|
|
286
|
-
const { fs } = state;
|
|
287
|
-
state.visited.push(crawlPath);
|
|
288
|
-
state.counts.directories++;
|
|
289
|
-
fs.readdir(crawlPath || ".", readdirOpts, (error, entries = [])=>{
|
|
290
|
-
callback$1(entries, directoryPath, currentDepth);
|
|
291
|
-
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1)=>{
|
|
295
|
-
const { fs } = state;
|
|
296
|
-
if (currentDepth < 0) return;
|
|
297
|
-
state.visited.push(crawlPath);
|
|
298
|
-
state.counts.directories++;
|
|
299
|
-
let entries = [];
|
|
300
|
-
try {
|
|
301
|
-
entries = fs.readdirSync(crawlPath || ".", readdirOpts);
|
|
302
|
-
} catch (e) {
|
|
303
|
-
if (!state.options.suppressErrors) throw e;
|
|
304
|
-
}
|
|
305
|
-
callback$1(entries, directoryPath, currentDepth);
|
|
306
|
-
};
|
|
307
|
-
function build(isSynchronous) {
|
|
308
|
-
return isSynchronous ? walkSync : walkAsync;
|
|
309
|
-
}
|
|
310
|
-
var Queue = class {
|
|
311
|
-
count = 0;
|
|
312
|
-
constructor(onQueueEmpty){
|
|
313
|
-
this.onQueueEmpty = onQueueEmpty;
|
|
314
|
-
}
|
|
315
|
-
enqueue() {
|
|
316
|
-
this.count++;
|
|
317
|
-
return this.count;
|
|
318
|
-
}
|
|
319
|
-
dequeue(error, output) {
|
|
320
|
-
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
|
321
|
-
this.onQueueEmpty(error, output);
|
|
322
|
-
if (error) {
|
|
323
|
-
output.controller.abort();
|
|
324
|
-
this.onQueueEmpty = void 0;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
var Counter = class {
|
|
330
|
-
_files = 0;
|
|
331
|
-
_directories = 0;
|
|
332
|
-
set files(num) {
|
|
333
|
-
this._files = num;
|
|
334
|
-
}
|
|
335
|
-
get files() {
|
|
336
|
-
return this._files;
|
|
337
|
-
}
|
|
338
|
-
set directories(num) {
|
|
339
|
-
this._directories = num;
|
|
340
|
-
}
|
|
341
|
-
get directories() {
|
|
342
|
-
return this._directories;
|
|
343
|
-
}
|
|
344
|
-
get dirs() {
|
|
345
|
-
return this._directories;
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
var Aborter = class {
|
|
349
|
-
aborted = false;
|
|
350
|
-
abort() {
|
|
351
|
-
this.aborted = true;
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
var Walker = class {
|
|
355
|
-
root;
|
|
356
|
-
isSynchronous;
|
|
357
|
-
state;
|
|
358
|
-
joinPath;
|
|
359
|
-
pushDirectory;
|
|
360
|
-
pushFile;
|
|
361
|
-
getArray;
|
|
362
|
-
groupFiles;
|
|
363
|
-
resolveSymlink;
|
|
364
|
-
walkDirectory;
|
|
365
|
-
callbackInvoker;
|
|
366
|
-
constructor(root, options, callback$1){
|
|
367
|
-
this.isSynchronous = !callback$1;
|
|
368
|
-
this.callbackInvoker = build$1(options, this.isSynchronous);
|
|
369
|
-
this.root = normalizePath(root, options);
|
|
370
|
-
this.state = {
|
|
371
|
-
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
|
372
|
-
paths: [
|
|
373
|
-
""
|
|
374
|
-
].slice(0, 0),
|
|
375
|
-
groups: [],
|
|
376
|
-
counts: new Counter(),
|
|
377
|
-
options,
|
|
378
|
-
queue: new Queue((error, state)=>this.callbackInvoker(state, error, callback$1)),
|
|
379
|
-
symlinks: /* @__PURE__ */ new Map(),
|
|
380
|
-
visited: [
|
|
381
|
-
""
|
|
382
|
-
].slice(0, 0),
|
|
383
|
-
controller: new Aborter(),
|
|
384
|
-
fs: options.fs || __rspack_external_fs
|
|
385
|
-
};
|
|
386
|
-
this.joinPath = build$7(this.root, options);
|
|
387
|
-
this.pushDirectory = build$6(this.root, options);
|
|
388
|
-
this.pushFile = build$5(options);
|
|
389
|
-
this.getArray = build$4(options);
|
|
390
|
-
this.groupFiles = build$3(options);
|
|
391
|
-
this.resolveSymlink = build$2(options, this.isSynchronous);
|
|
392
|
-
this.walkDirectory = build(this.isSynchronous);
|
|
393
|
-
}
|
|
394
|
-
start() {
|
|
395
|
-
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
|
396
|
-
this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
|
|
397
|
-
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
|
|
398
|
-
}
|
|
399
|
-
walk = (entries, directoryPath, depth)=>{
|
|
400
|
-
const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
|
401
|
-
if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
|
402
|
-
const files = this.getArray(this.state.paths);
|
|
403
|
-
for(let i = 0; i < entries.length; ++i){
|
|
404
|
-
const entry = entries[i];
|
|
405
|
-
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
|
406
|
-
const filename = this.joinPath(entry.name, directoryPath);
|
|
407
|
-
this.pushFile(filename, files, this.state.counts, filters);
|
|
408
|
-
} else if (entry.isDirectory()) {
|
|
409
|
-
let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
|
410
|
-
if (exclude && exclude(entry.name, path)) continue;
|
|
411
|
-
this.pushDirectory(path, paths, filters);
|
|
412
|
-
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
|
|
413
|
-
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
|
414
|
-
let path = joinPathWithBasePath(entry.name, directoryPath);
|
|
415
|
-
this.resolveSymlink(path, this.state, (stat, resolvedPath)=>{
|
|
416
|
-
if (stat.isDirectory()) {
|
|
417
|
-
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
|
418
|
-
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
|
|
419
|
-
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
|
|
420
|
-
} else {
|
|
421
|
-
resolvedPath = useRealPaths ? resolvedPath : path;
|
|
422
|
-
const filename = basename(resolvedPath);
|
|
423
|
-
const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
|
|
424
|
-
resolvedPath = this.joinPath(filename, directoryPath$1);
|
|
425
|
-
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
this.groupFiles(this.state.groups, directoryPath, files);
|
|
431
|
-
};
|
|
432
|
-
};
|
|
433
|
-
function promise(root, options) {
|
|
434
|
-
return new Promise((resolve$1, reject)=>{
|
|
435
|
-
callback(root, options, (err, output)=>{
|
|
436
|
-
if (err) return reject(err);
|
|
437
|
-
resolve$1(output);
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
function callback(root, options, callback$1) {
|
|
442
|
-
let walker = new Walker(root, options, callback$1);
|
|
443
|
-
walker.start();
|
|
444
|
-
}
|
|
445
|
-
function sync(root, options) {
|
|
446
|
-
const walker = new Walker(root, options);
|
|
447
|
-
return walker.start();
|
|
448
|
-
}
|
|
449
|
-
var APIBuilder = class {
|
|
450
|
-
constructor(root, options){
|
|
451
|
-
this.root = root;
|
|
452
|
-
this.options = options;
|
|
453
|
-
}
|
|
454
|
-
withPromise() {
|
|
455
|
-
return promise(this.root, this.options);
|
|
456
|
-
}
|
|
457
|
-
withCallback(cb) {
|
|
458
|
-
callback(this.root, this.options, cb);
|
|
459
|
-
}
|
|
460
|
-
sync() {
|
|
461
|
-
return sync(this.root, this.options);
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
let pm = null;
|
|
465
|
-
try {
|
|
466
|
-
__require.resolve("picomatch");
|
|
467
|
-
pm = __require("picomatch");
|
|
468
|
-
} catch {}
|
|
469
|
-
var Builder = class {
|
|
470
|
-
globCache = {};
|
|
471
|
-
options = {
|
|
472
|
-
maxDepth: 1 / 0,
|
|
473
|
-
suppressErrors: true,
|
|
474
|
-
pathSeparator: sep,
|
|
475
|
-
filters: []
|
|
476
|
-
};
|
|
477
|
-
globFunction;
|
|
478
|
-
constructor(options){
|
|
479
|
-
this.options = {
|
|
480
|
-
...this.options,
|
|
481
|
-
...options
|
|
482
|
-
};
|
|
483
|
-
this.globFunction = this.options.globFunction;
|
|
484
|
-
}
|
|
485
|
-
group() {
|
|
486
|
-
this.options.group = true;
|
|
487
|
-
return this;
|
|
488
|
-
}
|
|
489
|
-
withPathSeparator(separator) {
|
|
490
|
-
this.options.pathSeparator = separator;
|
|
491
|
-
return this;
|
|
492
|
-
}
|
|
493
|
-
withBasePath() {
|
|
494
|
-
this.options.includeBasePath = true;
|
|
495
|
-
return this;
|
|
496
|
-
}
|
|
497
|
-
withRelativePaths() {
|
|
498
|
-
this.options.relativePaths = true;
|
|
499
|
-
return this;
|
|
500
|
-
}
|
|
501
|
-
withDirs() {
|
|
502
|
-
this.options.includeDirs = true;
|
|
503
|
-
return this;
|
|
504
|
-
}
|
|
505
|
-
withMaxDepth(depth) {
|
|
506
|
-
this.options.maxDepth = depth;
|
|
507
|
-
return this;
|
|
508
|
-
}
|
|
509
|
-
withMaxFiles(limit) {
|
|
510
|
-
this.options.maxFiles = limit;
|
|
511
|
-
return this;
|
|
512
|
-
}
|
|
513
|
-
withFullPaths() {
|
|
514
|
-
this.options.resolvePaths = true;
|
|
515
|
-
this.options.includeBasePath = true;
|
|
516
|
-
return this;
|
|
517
|
-
}
|
|
518
|
-
withErrors() {
|
|
519
|
-
this.options.suppressErrors = false;
|
|
520
|
-
return this;
|
|
521
|
-
}
|
|
522
|
-
withSymlinks({ resolvePaths = true } = {}) {
|
|
523
|
-
this.options.resolveSymlinks = true;
|
|
524
|
-
this.options.useRealPaths = resolvePaths;
|
|
525
|
-
return this.withFullPaths();
|
|
526
|
-
}
|
|
527
|
-
withAbortSignal(signal) {
|
|
528
|
-
this.options.signal = signal;
|
|
529
|
-
return this;
|
|
530
|
-
}
|
|
531
|
-
normalize() {
|
|
532
|
-
this.options.normalizePath = true;
|
|
533
|
-
return this;
|
|
534
|
-
}
|
|
535
|
-
filter(predicate) {
|
|
536
|
-
this.options.filters.push(predicate);
|
|
537
|
-
return this;
|
|
538
|
-
}
|
|
539
|
-
onlyDirs() {
|
|
540
|
-
this.options.excludeFiles = true;
|
|
541
|
-
this.options.includeDirs = true;
|
|
542
|
-
return this;
|
|
543
|
-
}
|
|
544
|
-
exclude(predicate) {
|
|
545
|
-
this.options.exclude = predicate;
|
|
546
|
-
return this;
|
|
547
|
-
}
|
|
548
|
-
onlyCounts() {
|
|
549
|
-
this.options.onlyCounts = true;
|
|
550
|
-
return this;
|
|
551
|
-
}
|
|
552
|
-
crawl(root) {
|
|
553
|
-
return new APIBuilder(root || ".", this.options);
|
|
554
|
-
}
|
|
555
|
-
withGlobFunction(fn) {
|
|
556
|
-
this.globFunction = fn;
|
|
557
|
-
return this;
|
|
558
|
-
}
|
|
559
|
-
crawlWithOptions(root, options) {
|
|
560
|
-
this.options = {
|
|
561
|
-
...this.options,
|
|
562
|
-
...options
|
|
563
|
-
};
|
|
564
|
-
return new APIBuilder(root || ".", this.options);
|
|
565
|
-
}
|
|
566
|
-
glob(...patterns) {
|
|
567
|
-
if (this.globFunction) return this.globWithOptions(patterns);
|
|
568
|
-
return this.globWithOptions(patterns, {
|
|
569
|
-
dot: true
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
globWithOptions(patterns, ...options) {
|
|
573
|
-
const globFn = this.globFunction || pm;
|
|
574
|
-
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
|
575
|
-
var isMatch = this.globCache[patterns.join("\0")];
|
|
576
|
-
if (!isMatch) {
|
|
577
|
-
isMatch = globFn(patterns, ...options);
|
|
578
|
-
this.globCache[patterns.join("\0")] = isMatch;
|
|
579
|
-
}
|
|
580
|
-
this.options.filters.push((path)=>isMatch(path));
|
|
581
|
-
return this;
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
const isReadonlyArray = Array.isArray;
|
|
585
|
-
const isWin = "win32" === process.platform;
|
|
586
|
-
const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
|
|
587
|
-
function getPartialMatcher(patterns, options = {}) {
|
|
588
|
-
const patternsCount = patterns.length;
|
|
589
|
-
const patternsParts = Array(patternsCount);
|
|
590
|
-
const matchers = Array(patternsCount);
|
|
591
|
-
const globstarEnabled = !options.noglobstar;
|
|
592
|
-
for(let i = 0; i < patternsCount; i++){
|
|
593
|
-
const parts = splitPattern(patterns[i]);
|
|
594
|
-
patternsParts[i] = parts;
|
|
595
|
-
const partsCount = parts.length;
|
|
596
|
-
const partMatchers = Array(partsCount);
|
|
597
|
-
for(let j = 0; j < partsCount; j++)partMatchers[j] = picomatch(parts[j], options);
|
|
598
|
-
matchers[i] = partMatchers;
|
|
599
|
-
}
|
|
600
|
-
return (input)=>{
|
|
601
|
-
const inputParts = input.split("/");
|
|
602
|
-
if (".." === inputParts[0] && ONLY_PARENT_DIRECTORIES.test(input)) return true;
|
|
603
|
-
for(let i = 0; i < patterns.length; i++){
|
|
604
|
-
const patternParts = patternsParts[i];
|
|
605
|
-
const matcher = matchers[i];
|
|
606
|
-
const inputPatternCount = inputParts.length;
|
|
607
|
-
const minParts = Math.min(inputPatternCount, patternParts.length);
|
|
608
|
-
let j = 0;
|
|
609
|
-
while(j < minParts){
|
|
610
|
-
const part = patternParts[j];
|
|
611
|
-
if (part.includes("/")) return true;
|
|
612
|
-
const match = matcher[j](inputParts[j]);
|
|
613
|
-
if (!match) break;
|
|
614
|
-
if (globstarEnabled && "**" === part) return true;
|
|
615
|
-
j++;
|
|
616
|
-
}
|
|
617
|
-
if (j === inputPatternCount) return true;
|
|
618
|
-
}
|
|
619
|
-
return false;
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
const WIN32_ROOT_DIR = /^[A-Z]:\/$/i;
|
|
623
|
-
const isRoot = isWin ? (p)=>WIN32_ROOT_DIR.test(p) : (p)=>"/" === p;
|
|
624
|
-
function buildFormat(cwd, root, absolute) {
|
|
625
|
-
if (cwd === root || root.startsWith(`${cwd}/`)) {
|
|
626
|
-
if (absolute) {
|
|
627
|
-
const start = isRoot(cwd) ? cwd.length : cwd.length + 1;
|
|
628
|
-
return (p, isDir)=>p.slice(start, isDir ? -1 : void 0) || ".";
|
|
629
|
-
}
|
|
630
|
-
const prefix = root.slice(cwd.length + 1);
|
|
631
|
-
if (prefix) return (p, isDir)=>{
|
|
632
|
-
if ("." === p) return prefix;
|
|
633
|
-
const result = `${prefix}/${p}`;
|
|
634
|
-
return isDir ? result.slice(0, -1) : result;
|
|
635
|
-
};
|
|
636
|
-
return (p, isDir)=>isDir && "." !== p ? p.slice(0, -1) : p;
|
|
637
|
-
}
|
|
638
|
-
if (absolute) return (p)=>posix.relative(cwd, p) || ".";
|
|
639
|
-
return (p)=>posix.relative(cwd, `${root}/${p}`) || ".";
|
|
640
|
-
}
|
|
641
|
-
function buildRelative(cwd, root) {
|
|
642
|
-
if (root.startsWith(`${cwd}/`)) {
|
|
643
|
-
const prefix = root.slice(cwd.length + 1);
|
|
644
|
-
return (p)=>`${prefix}/${p}`;
|
|
645
|
-
}
|
|
646
|
-
return (p)=>{
|
|
647
|
-
const result = posix.relative(cwd, `${root}/${p}`);
|
|
648
|
-
if (p.endsWith("/") && "" !== result) return `${result}/`;
|
|
649
|
-
return result || ".";
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
const splitPatternOptions = {
|
|
653
|
-
parts: true
|
|
654
|
-
};
|
|
655
|
-
function splitPattern(path$1) {
|
|
656
|
-
var _result$parts;
|
|
657
|
-
const result = picomatch.scan(path$1, splitPatternOptions);
|
|
658
|
-
return (null == (_result$parts = result.parts) ? void 0 : _result$parts.length) ? result.parts : [
|
|
659
|
-
path$1
|
|
660
|
-
];
|
|
661
|
-
}
|
|
662
|
-
const POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
|
|
663
|
-
const WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
|
|
664
|
-
const escapePosixPath = (path$1)=>path$1.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
|
665
|
-
const escapeWin32Path = (path$1)=>path$1.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
|
666
|
-
const escapePath = isWin ? escapeWin32Path : escapePosixPath;
|
|
667
|
-
function isDynamicPattern(pattern, options) {
|
|
668
|
-
if ((null == options ? void 0 : options.caseSensitiveMatch) === false) return true;
|
|
669
|
-
const scan = picomatch.scan(pattern);
|
|
670
|
-
return scan.isGlob || scan.negated;
|
|
671
|
-
}
|
|
672
|
-
function log(...tasks) {
|
|
673
|
-
console.log(`[tinyglobby ${/* @__PURE__ */ new Date().toLocaleTimeString("es")}]`, ...tasks);
|
|
674
|
-
}
|
|
675
|
-
const PARENT_DIRECTORY = /^(\/?\.\.)+/;
|
|
676
|
-
const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
|
|
677
|
-
const BACKSLASHES = /\\/g;
|
|
678
|
-
function normalizePattern(pattern, expandDirectories, cwd, props, isIgnore) {
|
|
679
|
-
let result = pattern;
|
|
680
|
-
if (pattern.endsWith("/")) result = pattern.slice(0, -1);
|
|
681
|
-
if (!result.endsWith("*") && expandDirectories) result += "/**";
|
|
682
|
-
const escapedCwd = escapePath(cwd);
|
|
683
|
-
result = path_0.isAbsolute(result.replace(ESCAPING_BACKSLASHES, "")) ? posix.relative(escapedCwd, result) : posix.normalize(result);
|
|
684
|
-
const parentDirectoryMatch = PARENT_DIRECTORY.exec(result);
|
|
685
|
-
const parts = splitPattern(result);
|
|
686
|
-
if (null == parentDirectoryMatch ? void 0 : parentDirectoryMatch[0]) {
|
|
687
|
-
const n = (parentDirectoryMatch[0].length + 1) / 3;
|
|
688
|
-
let i = 0;
|
|
689
|
-
const cwdParts = escapedCwd.split("/");
|
|
690
|
-
while(i < n && parts[i + n] === cwdParts[cwdParts.length + i - n]){
|
|
691
|
-
result = result.slice(0, (n - i - 1) * 3) + result.slice((n - i) * 3 + parts[i + n].length + 1) || ".";
|
|
692
|
-
i++;
|
|
693
|
-
}
|
|
694
|
-
const potentialRoot = posix.join(cwd, parentDirectoryMatch[0].slice(3 * i));
|
|
695
|
-
if (!potentialRoot.startsWith(".") && props.root.length > potentialRoot.length) {
|
|
696
|
-
props.root = potentialRoot;
|
|
697
|
-
props.depthOffset = -n + i;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
if (!isIgnore && props.depthOffset >= 0) {
|
|
701
|
-
null != props.commonPath || (props.commonPath = parts);
|
|
702
|
-
const newCommonPath = [];
|
|
703
|
-
const length = Math.min(props.commonPath.length, parts.length);
|
|
704
|
-
for(let i = 0; i < length; i++){
|
|
705
|
-
const part = parts[i];
|
|
706
|
-
if ("**" === part && !parts[i + 1]) {
|
|
707
|
-
newCommonPath.pop();
|
|
708
|
-
break;
|
|
709
|
-
}
|
|
710
|
-
if (part !== props.commonPath[i] || isDynamicPattern(part) || i === parts.length - 1) break;
|
|
711
|
-
newCommonPath.push(part);
|
|
712
|
-
}
|
|
713
|
-
props.depthOffset = newCommonPath.length;
|
|
714
|
-
props.commonPath = newCommonPath;
|
|
715
|
-
props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
|
|
716
|
-
}
|
|
717
|
-
return result;
|
|
718
|
-
}
|
|
719
|
-
function processPatterns({ patterns = [
|
|
720
|
-
"**/*"
|
|
721
|
-
], ignore = [], expandDirectories = true }, cwd, props) {
|
|
722
|
-
if ("string" == typeof patterns) patterns = [
|
|
723
|
-
patterns
|
|
724
|
-
];
|
|
725
|
-
if ("string" == typeof ignore) ignore = [
|
|
726
|
-
ignore
|
|
727
|
-
];
|
|
728
|
-
const matchPatterns = [];
|
|
729
|
-
const ignorePatterns = [];
|
|
730
|
-
for (const pattern of ignore)if (pattern) {
|
|
731
|
-
if ("!" !== pattern[0] || "(" === pattern[1]) ignorePatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, true));
|
|
732
|
-
}
|
|
733
|
-
for (const pattern of patterns)if (pattern) {
|
|
734
|
-
if ("!" !== pattern[0] || "(" === pattern[1]) matchPatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, false));
|
|
735
|
-
else if ("!" !== pattern[1] || "(" === pattern[2]) ignorePatterns.push(normalizePattern(pattern.slice(1), expandDirectories, cwd, props, true));
|
|
736
|
-
}
|
|
737
|
-
return {
|
|
738
|
-
match: matchPatterns,
|
|
739
|
-
ignore: ignorePatterns
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
function formatPaths(paths, relative) {
|
|
743
|
-
for(let i = paths.length - 1; i >= 0; i--){
|
|
744
|
-
const path$1 = paths[i];
|
|
745
|
-
paths[i] = relative(path$1);
|
|
746
|
-
}
|
|
747
|
-
return paths;
|
|
748
|
-
}
|
|
749
|
-
function normalizeCwd(cwd) {
|
|
750
|
-
if (!cwd) return process.cwd().replace(BACKSLASHES, "/");
|
|
751
|
-
if (cwd instanceof URL) return fileURLToPath(cwd).replace(BACKSLASHES, "/");
|
|
752
|
-
return path_0.resolve(cwd).replace(BACKSLASHES, "/");
|
|
753
|
-
}
|
|
754
|
-
function getCrawler(patterns, inputOptions = {}) {
|
|
755
|
-
const options = process.env.TINYGLOBBY_DEBUG ? {
|
|
756
|
-
...inputOptions,
|
|
757
|
-
debug: true
|
|
758
|
-
} : inputOptions;
|
|
759
|
-
const cwd = normalizeCwd(options.cwd);
|
|
760
|
-
if (options.debug) log("globbing with:", {
|
|
761
|
-
patterns,
|
|
762
|
-
options,
|
|
763
|
-
cwd
|
|
764
|
-
});
|
|
765
|
-
if (Array.isArray(patterns) && 0 === patterns.length) return [
|
|
766
|
-
{
|
|
767
|
-
sync: ()=>[],
|
|
768
|
-
withPromise: async ()=>[]
|
|
769
|
-
},
|
|
770
|
-
false
|
|
771
|
-
];
|
|
772
|
-
const props = {
|
|
773
|
-
root: cwd,
|
|
774
|
-
commonPath: null,
|
|
775
|
-
depthOffset: 0
|
|
776
|
-
};
|
|
777
|
-
const processed = processPatterns({
|
|
778
|
-
...options,
|
|
779
|
-
patterns
|
|
780
|
-
}, cwd, props);
|
|
781
|
-
if (options.debug) log("internal processing patterns:", processed);
|
|
782
|
-
const matchOptions = {
|
|
783
|
-
dot: options.dot,
|
|
784
|
-
nobrace: false === options.braceExpansion,
|
|
785
|
-
nocase: false === options.caseSensitiveMatch,
|
|
786
|
-
noextglob: false === options.extglob,
|
|
787
|
-
noglobstar: false === options.globstar,
|
|
788
|
-
posix: true
|
|
789
|
-
};
|
|
790
|
-
const matcher = picomatch(processed.match, {
|
|
791
|
-
...matchOptions,
|
|
792
|
-
ignore: processed.ignore
|
|
793
|
-
});
|
|
794
|
-
const ignore = picomatch(processed.ignore, matchOptions);
|
|
795
|
-
const partialMatcher = getPartialMatcher(processed.match, matchOptions);
|
|
796
|
-
const format = buildFormat(cwd, props.root, options.absolute);
|
|
797
|
-
const formatExclude = options.absolute ? format : buildFormat(cwd, props.root, true);
|
|
798
|
-
const fdirOptions = {
|
|
799
|
-
filters: [
|
|
800
|
-
options.debug ? (p, isDirectory)=>{
|
|
801
|
-
const path$1 = format(p, isDirectory);
|
|
802
|
-
const matches = matcher(path$1);
|
|
803
|
-
if (matches) log(`matched ${path$1}`);
|
|
804
|
-
return matches;
|
|
805
|
-
} : (p, isDirectory)=>matcher(format(p, isDirectory))
|
|
806
|
-
],
|
|
807
|
-
exclude: options.debug ? (_, p)=>{
|
|
808
|
-
const relativePath = formatExclude(p, true);
|
|
809
|
-
const skipped = "." !== relativePath && !partialMatcher(relativePath) || ignore(relativePath);
|
|
810
|
-
skipped ? log(`skipped ${p}`) : log(`crawling ${p}`);
|
|
811
|
-
return skipped;
|
|
812
|
-
} : (_, p)=>{
|
|
813
|
-
const relativePath = formatExclude(p, true);
|
|
814
|
-
return "." !== relativePath && !partialMatcher(relativePath) || ignore(relativePath);
|
|
815
|
-
},
|
|
816
|
-
fs: options.fs ? {
|
|
817
|
-
readdir: options.fs.readdir || fs_0.readdir,
|
|
818
|
-
readdirSync: options.fs.readdirSync || fs_0.readdirSync,
|
|
819
|
-
realpath: options.fs.realpath || fs_0.realpath,
|
|
820
|
-
realpathSync: options.fs.realpathSync || fs_0.realpathSync,
|
|
821
|
-
stat: options.fs.stat || fs_0.stat,
|
|
822
|
-
statSync: options.fs.statSync || fs_0.statSync
|
|
823
|
-
} : void 0,
|
|
824
|
-
pathSeparator: "/",
|
|
825
|
-
relativePaths: true,
|
|
826
|
-
resolveSymlinks: true,
|
|
827
|
-
signal: options.signal
|
|
828
|
-
};
|
|
829
|
-
if (void 0 !== options.deep) fdirOptions.maxDepth = Math.round(options.deep - props.depthOffset);
|
|
830
|
-
if (options.absolute) {
|
|
831
|
-
fdirOptions.relativePaths = false;
|
|
832
|
-
fdirOptions.resolvePaths = true;
|
|
833
|
-
fdirOptions.includeBasePath = true;
|
|
834
|
-
}
|
|
835
|
-
if (false === options.followSymbolicLinks) {
|
|
836
|
-
fdirOptions.resolveSymlinks = false;
|
|
837
|
-
fdirOptions.excludeSymlinks = true;
|
|
838
|
-
}
|
|
839
|
-
if (options.onlyDirectories) {
|
|
840
|
-
fdirOptions.excludeFiles = true;
|
|
841
|
-
fdirOptions.includeDirs = true;
|
|
842
|
-
} else if (false === options.onlyFiles) fdirOptions.includeDirs = true;
|
|
843
|
-
props.root = props.root.replace(BACKSLASHES, "");
|
|
844
|
-
const root = props.root;
|
|
845
|
-
if (options.debug) log("internal properties:", props);
|
|
846
|
-
const relative = cwd !== root && !options.absolute && buildRelative(cwd, props.root);
|
|
847
|
-
return [
|
|
848
|
-
new Builder(fdirOptions).crawl(root),
|
|
849
|
-
relative
|
|
850
|
-
];
|
|
851
|
-
}
|
|
852
|
-
async function glob(patternsOrOptions, options) {
|
|
853
|
-
if (patternsOrOptions && (null == options ? void 0 : options.patterns)) throw new Error("Cannot pass patterns as both an argument and an option");
|
|
854
|
-
const isModern = isReadonlyArray(patternsOrOptions) || "string" == typeof patternsOrOptions;
|
|
855
|
-
const opts = isModern ? options : patternsOrOptions;
|
|
856
|
-
const patterns = isModern ? patternsOrOptions : patternsOrOptions.patterns;
|
|
857
|
-
const [crawler, relative] = getCrawler(patterns, opts);
|
|
858
|
-
if (!relative) return crawler.withPromise();
|
|
859
|
-
return formatPaths(await crawler.withPromise(), relative);
|
|
860
|
-
}
|
|
861
|
-
const JS_CONFIG_FILES = [
|
|
862
|
-
'rslint.config.js',
|
|
863
|
-
'rslint.config.mjs',
|
|
864
|
-
'rslint.config.ts',
|
|
865
|
-
'rslint.config.mts'
|
|
866
|
-
];
|
|
867
|
-
function findJSConfig(cwd) {
|
|
868
|
-
for (const name of JS_CONFIG_FILES){
|
|
869
|
-
const p = node_path.join(cwd, name);
|
|
870
|
-
if (node_fs.existsSync(p)) return p;
|
|
871
|
-
}
|
|
872
|
-
return null;
|
|
873
|
-
}
|
|
874
|
-
function findJSConfigUp(startDir) {
|
|
875
|
-
let dir = node_path.resolve(startDir);
|
|
876
|
-
while(true){
|
|
877
|
-
const found = findJSConfig(dir);
|
|
878
|
-
if (found) return found;
|
|
879
|
-
const parent = node_path.dirname(dir);
|
|
880
|
-
if (parent === dir) return null;
|
|
881
|
-
dir = parent;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
async function findJSConfigsInDir(startDir) {
|
|
885
|
-
const resolved = node_path.resolve(startDir);
|
|
886
|
-
const matches = await glob([
|
|
887
|
-
'**/rslint.config.{js,mjs,ts,mts}'
|
|
888
|
-
], {
|
|
889
|
-
cwd: resolved,
|
|
890
|
-
absolute: true,
|
|
891
|
-
dot: true,
|
|
892
|
-
ignore: [
|
|
893
|
-
'**/node_modules/**',
|
|
894
|
-
'**/.git/**'
|
|
895
|
-
]
|
|
896
|
-
});
|
|
897
|
-
return matches.map((p)=>node_path.normalize(p));
|
|
898
|
-
}
|
|
899
|
-
async function discoverConfigs(files, dirs, cwd, explicitConfig) {
|
|
900
|
-
const configs = new Map();
|
|
901
|
-
const addConfig = (configPath)=>{
|
|
902
|
-
if (!configs.has(configPath)) configs.set(configPath, node_path.dirname(configPath));
|
|
903
|
-
};
|
|
904
|
-
if (explicitConfig) {
|
|
905
|
-
const resolved = node_path.resolve(cwd, explicitConfig);
|
|
906
|
-
addConfig(resolved);
|
|
907
|
-
return configs;
|
|
908
|
-
}
|
|
909
|
-
const startDirs = new Set();
|
|
910
|
-
const scanDirs = [];
|
|
911
|
-
if (0 === files.length && 0 === dirs.length) {
|
|
912
|
-
startDirs.add(cwd);
|
|
913
|
-
scanDirs.push(cwd);
|
|
914
|
-
}
|
|
915
|
-
for (const file of files)startDirs.add(node_path.dirname(file));
|
|
916
|
-
for (const dir of dirs){
|
|
917
|
-
startDirs.add(dir);
|
|
918
|
-
scanDirs.push(dir);
|
|
919
|
-
}
|
|
920
|
-
for (const startDir of startDirs){
|
|
921
|
-
const configPath = findJSConfigUp(startDir);
|
|
922
|
-
if (configPath) addConfig(configPath);
|
|
923
|
-
}
|
|
924
|
-
for (const dir of scanDirs)for (const configPath of (await findJSConfigsInDir(dir)))addConfig(configPath);
|
|
925
|
-
return configs;
|
|
926
|
-
}
|
|
927
|
-
function isGlobalIgnoreEntry(entry) {
|
|
928
|
-
const ignores = entry.ignores;
|
|
929
|
-
if (!Array.isArray(ignores) || 0 === ignores.length) return false;
|
|
930
|
-
return null == entry.files && null == entry.rules && (null == entry.plugins || (Array.isArray(entry.plugins) ? 0 === entry.plugins.length : 0 === Object.keys(entry.plugins).length)) && null == entry.languageOptions && null == entry.settings;
|
|
931
|
-
}
|
|
932
|
-
function getGlobalIgnores(entries) {
|
|
933
|
-
const patterns = [];
|
|
934
|
-
for (const entry of entries)if (isGlobalIgnoreEntry(entry)) for (const pattern of entry.ignores)patterns.push(pattern);
|
|
935
|
-
return patterns;
|
|
936
|
-
}
|
|
937
|
-
function isDirIgnoredByPatterns(dirPath, patterns, parentConfigDir) {
|
|
938
|
-
const relDir = node_path.relative(parentConfigDir, dirPath);
|
|
939
|
-
if (!relDir || relDir.startsWith('..')) return false;
|
|
940
|
-
const normalizedRelDir = relDir.split(node_path.sep).join('/');
|
|
941
|
-
for (const pattern of patterns){
|
|
942
|
-
if (!pattern || pattern.startsWith('!')) continue;
|
|
943
|
-
if (pattern.endsWith('/**/*') || pattern.endsWith('/*') && !pattern.endsWith('/**')) continue;
|
|
944
|
-
const isMatch = picomatch(pattern, {
|
|
945
|
-
dot: true
|
|
946
|
-
});
|
|
947
|
-
if (isMatch(normalizedRelDir) || isMatch(normalizedRelDir + '/') || isMatch(normalizedRelDir + '/x')) return true;
|
|
948
|
-
const segments = normalizedRelDir.split('/');
|
|
949
|
-
for(let i = 1; i < segments.length; i++){
|
|
950
|
-
const partial = segments.slice(0, i).join('/');
|
|
951
|
-
if (isMatch(partial) || isMatch(partial + '/') || isMatch(partial + '/x')) return true;
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
return false;
|
|
955
|
-
}
|
|
956
|
-
function filterConfigsByParentIgnores(configEntries) {
|
|
957
|
-
if (configEntries.length <= 1) return configEntries;
|
|
958
|
-
const resolvedDirs = new Map();
|
|
959
|
-
for (const entry of configEntries){
|
|
960
|
-
let dir = entry.configDirectory.replace(/[/\\]+$/, '');
|
|
961
|
-
try {
|
|
962
|
-
dir = node_fs.realpathSync(dir);
|
|
963
|
-
} catch {}
|
|
964
|
-
resolvedDirs.set(entry, dir);
|
|
965
|
-
}
|
|
966
|
-
const sorted = [
|
|
967
|
-
...configEntries
|
|
968
|
-
].sort((a, b)=>(resolvedDirs.get(a)?.length ?? 0) - (resolvedDirs.get(b)?.length ?? 0));
|
|
969
|
-
const result = [];
|
|
970
|
-
for (const config of sorted){
|
|
971
|
-
let ignored = false;
|
|
972
|
-
const configDir = resolvedDirs.get(config);
|
|
973
|
-
for (const parent of result){
|
|
974
|
-
const parentDir = resolvedDirs.get(parent);
|
|
975
|
-
if (!configDir.startsWith(parentDir + node_path.sep) && configDir !== parentDir) continue;
|
|
976
|
-
const globalIgnores = getGlobalIgnores(parent.entries);
|
|
977
|
-
if (0 !== globalIgnores.length) {
|
|
978
|
-
if (isDirIgnoredByPatterns(configDir, globalIgnores, parentDir)) {
|
|
979
|
-
ignored = true;
|
|
980
|
-
break;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
if (!ignored) result.push(config);
|
|
985
|
-
}
|
|
986
|
-
return result;
|
|
987
|
-
}
|
|
988
95
|
async function runWithJSConfigs(binPath, configs, goArgs, cwd, singleThreaded) {
|
|
989
96
|
const configEntries = [];
|
|
990
97
|
const dirToPath = new Map();
|