@rslint/core 0.5.3 → 0.6.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/bin/rslint.cjs +21 -4
- package/dist/0~engine.js +406 -0
- package/dist/34.js +33 -0
- package/dist/browser.d.ts +52 -39
- package/dist/browser.js +42 -74
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +1051 -93
- package/dist/config-loader.d.ts +45 -14
- package/dist/config-loader.js +95 -59
- package/dist/eslint-plugin/612.js +43 -0
- package/dist/eslint-plugin/index.d.ts +892 -0
- package/dist/eslint-plugin/index.js +26692 -0
- package/dist/eslint-plugin/lint-worker.js +26225 -0
- package/dist/eslint-plugin/types.d.ts +23 -0
- package/dist/eslint-plugin/types.js +1 -0
- package/dist/index.d.ts +626 -19
- package/dist/index.js +598 -15
- package/dist/service.d.ts +360 -30
- package/dist/service.js +19 -34
- package/package.json +27 -11
- package/dist/browser.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/configs/import.d.ts +0 -6
- package/dist/configs/import.d.ts.map +0 -1
- package/dist/configs/import.js +0 -7
- package/dist/configs/index.d.ts +0 -47
- package/dist/configs/index.d.ts.map +0 -1
- package/dist/configs/index.js +0 -36
- package/dist/configs/javascript.d.ts +0 -6
- package/dist/configs/javascript.d.ts.map +0 -1
- package/dist/configs/javascript.js +0 -72
- package/dist/configs/jest.d.ts +0 -7
- package/dist/configs/jest.d.ts.map +0 -1
- package/dist/configs/jest.js +0 -35
- package/dist/configs/jsx-a11y.d.ts +0 -6
- package/dist/configs/jsx-a11y.d.ts.map +0 -1
- package/dist/configs/jsx-a11y.js +0 -135
- package/dist/configs/promise.d.ts +0 -6
- package/dist/configs/promise.d.ts.map +0 -1
- package/dist/configs/promise.js +0 -20
- package/dist/configs/react-hooks.d.ts +0 -6
- package/dist/configs/react-hooks.d.ts.map +0 -1
- package/dist/configs/react-hooks.js +0 -24
- package/dist/configs/react.d.ts +0 -6
- package/dist/configs/react.d.ts.map +0 -1
- package/dist/configs/react.js +0 -31
- package/dist/configs/typescript.d.ts +0 -9
- package/dist/configs/typescript.d.ts.map +0 -1
- package/dist/configs/typescript.js +0 -122
- package/dist/configs/unicorn.d.ts +0 -8
- package/dist/configs/unicorn.d.ts.map +0 -1
- package/dist/configs/unicorn.js +0 -161
- package/dist/define-config.d.ts +0 -110
- package/dist/define-config.d.ts.map +0 -1
- package/dist/define-config.js +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/node.d.ts +0 -31
- package/dist/node.d.ts.map +0 -1
- package/dist/node.js +0 -116
- package/dist/service.d.ts.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -342
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
- package/dist/utils/args.d.ts +0 -19
- package/dist/utils/args.d.ts.map +0 -1
- package/dist/utils/args.js +0 -101
- package/dist/utils/config-discovery.d.ts +0 -47
- package/dist/utils/config-discovery.d.ts.map +0 -1
- package/dist/utils/config-discovery.js +0 -238
- package/dist/worker.d.ts +0 -2
- package/dist/worker.d.ts.map +0 -1
- package/dist/worker.js +0 -114
package/dist/cli.js
CHANGED
|
@@ -1,44 +1,998 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import node_fs from "node:fs";
|
|
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
|
+
import { loadConfigFile, collectPluginMeta, normalizeConfig } from "./config-loader.js";
|
|
10
|
+
function isJSConfigFile(filePath) {
|
|
11
|
+
return /\.(ts|mts|js|mjs)$/.test(filePath);
|
|
12
|
+
}
|
|
13
|
+
function args_parseArgs(argv) {
|
|
14
|
+
const { values, tokens } = parseArgs({
|
|
15
|
+
args: argv,
|
|
16
|
+
strict: false,
|
|
17
|
+
tokens: true,
|
|
18
|
+
options: {
|
|
19
|
+
config: {
|
|
20
|
+
type: 'string'
|
|
21
|
+
},
|
|
22
|
+
init: {
|
|
23
|
+
type: 'boolean'
|
|
24
|
+
},
|
|
25
|
+
singleThreaded: {
|
|
26
|
+
type: 'boolean'
|
|
27
|
+
},
|
|
28
|
+
format: {
|
|
29
|
+
type: 'string'
|
|
30
|
+
},
|
|
31
|
+
'max-warnings': {
|
|
32
|
+
type: 'string'
|
|
33
|
+
},
|
|
34
|
+
rule: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
multiple: true
|
|
37
|
+
},
|
|
38
|
+
trace: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
},
|
|
41
|
+
cpuprof: {
|
|
42
|
+
type: 'string'
|
|
43
|
+
},
|
|
44
|
+
'start-time': {
|
|
45
|
+
type: 'string'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const flags = [];
|
|
50
|
+
const positionalsBefore = [];
|
|
51
|
+
const positionalsAfter = [];
|
|
52
|
+
let seenTerminator = false;
|
|
53
|
+
for (const token of tokens)if ('option' === token.kind) {
|
|
54
|
+
if ('config' === token.name || 'init' === token.name || 'start-time' === token.name) continue;
|
|
55
|
+
flags.push(token.rawName);
|
|
56
|
+
if (null != token.value) flags.push(token.value);
|
|
57
|
+
} else if ('option-terminator' === token.kind) seenTerminator = true;
|
|
58
|
+
else if ('positional' === token.kind) if (seenTerminator) positionalsAfter.push(token.value);
|
|
59
|
+
else positionalsBefore.push(token.value);
|
|
60
|
+
const positionals = [
|
|
61
|
+
...positionalsBefore,
|
|
62
|
+
...positionalsAfter
|
|
63
|
+
];
|
|
64
|
+
const rest = seenTerminator ? [
|
|
65
|
+
...flags,
|
|
66
|
+
...positionalsBefore,
|
|
67
|
+
'--',
|
|
68
|
+
...positionalsAfter
|
|
69
|
+
] : [
|
|
70
|
+
...flags,
|
|
71
|
+
...positionalsBefore
|
|
72
|
+
];
|
|
73
|
+
return {
|
|
74
|
+
config: values.config ?? null,
|
|
75
|
+
init: values.init ?? false,
|
|
76
|
+
singleThreaded: values.singleThreaded ?? false,
|
|
77
|
+
rest,
|
|
78
|
+
positionals
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function classifyArgs(positionals, cwd) {
|
|
82
|
+
const files = [];
|
|
83
|
+
const dirs = [];
|
|
84
|
+
for (const arg of positionals){
|
|
85
|
+
const resolved = node_path.resolve(cwd, arg);
|
|
86
|
+
try {
|
|
87
|
+
const real = node_fs.realpathSync(resolved);
|
|
88
|
+
if (node_fs.statSync(real).isDirectory()) dirs.push(real);
|
|
89
|
+
else files.push(real);
|
|
90
|
+
} catch {
|
|
91
|
+
files.push(resolved);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
files,
|
|
96
|
+
dirs
|
|
97
|
+
};
|
|
98
|
+
}
|
|
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 = [];
|
|
11
300
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
function globSync(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.sync();
|
|
859
|
+
return formatPaths(crawler.sync(), 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
|
+
function findJSConfigsInDir(startDir) {
|
|
885
|
+
const resolved = node_path.resolve(startDir);
|
|
886
|
+
return globSync([
|
|
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
|
+
}).map((p)=>node_path.normalize(p));
|
|
897
|
+
}
|
|
898
|
+
function discoverConfigs(files, dirs, cwd, explicitConfig) {
|
|
899
|
+
const configs = new Map();
|
|
900
|
+
const addConfig = (configPath)=>{
|
|
901
|
+
if (!configs.has(configPath)) configs.set(configPath, node_path.dirname(configPath));
|
|
902
|
+
};
|
|
903
|
+
if (explicitConfig) {
|
|
904
|
+
const resolved = node_path.resolve(cwd, explicitConfig);
|
|
905
|
+
addConfig(resolved);
|
|
906
|
+
return configs;
|
|
907
|
+
}
|
|
908
|
+
const startDirs = new Set();
|
|
909
|
+
const scanDirs = [];
|
|
910
|
+
if (0 === files.length && 0 === dirs.length) {
|
|
911
|
+
startDirs.add(cwd);
|
|
912
|
+
scanDirs.push(cwd);
|
|
913
|
+
}
|
|
914
|
+
for (const file of files)startDirs.add(node_path.dirname(file));
|
|
915
|
+
for (const dir of dirs){
|
|
916
|
+
startDirs.add(dir);
|
|
917
|
+
scanDirs.push(dir);
|
|
918
|
+
}
|
|
919
|
+
for (const startDir of startDirs){
|
|
920
|
+
const configPath = findJSConfigUp(startDir);
|
|
921
|
+
if (configPath) addConfig(configPath);
|
|
922
|
+
}
|
|
923
|
+
for (const dir of scanDirs)for (const configPath of findJSConfigsInDir(dir))addConfig(configPath);
|
|
924
|
+
return configs;
|
|
925
|
+
}
|
|
926
|
+
function isGlobalIgnoreEntry(entry) {
|
|
927
|
+
const ignores = entry.ignores;
|
|
928
|
+
if (!Array.isArray(ignores) || 0 === ignores.length) return false;
|
|
929
|
+
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;
|
|
930
|
+
}
|
|
931
|
+
function getGlobalIgnores(entries) {
|
|
932
|
+
const patterns = [];
|
|
933
|
+
for (const entry of entries)if (isGlobalIgnoreEntry(entry)) for (const pattern of entry.ignores)patterns.push(pattern);
|
|
934
|
+
return patterns;
|
|
935
|
+
}
|
|
936
|
+
function isDirIgnoredByPatterns(dirPath, patterns, parentConfigDir) {
|
|
937
|
+
const relDir = node_path.relative(parentConfigDir, dirPath);
|
|
938
|
+
if (!relDir || relDir.startsWith('..')) return false;
|
|
939
|
+
const normalizedRelDir = relDir.split(node_path.sep).join('/');
|
|
940
|
+
for (const pattern of patterns){
|
|
941
|
+
if (!pattern || pattern.startsWith('!')) continue;
|
|
942
|
+
if (pattern.endsWith('/**/*') || pattern.endsWith('/*') && !pattern.endsWith('/**')) continue;
|
|
943
|
+
const isMatch = picomatch(pattern, {
|
|
944
|
+
dot: true
|
|
945
|
+
});
|
|
946
|
+
if (isMatch(normalizedRelDir) || isMatch(normalizedRelDir + '/') || isMatch(normalizedRelDir + '/x')) return true;
|
|
947
|
+
const segments = normalizedRelDir.split('/');
|
|
948
|
+
for(let i = 1; i < segments.length; i++){
|
|
949
|
+
const partial = segments.slice(0, i).join('/');
|
|
950
|
+
if (isMatch(partial) || isMatch(partial + '/') || isMatch(partial + '/x')) return true;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
function filterConfigsByParentIgnores(configEntries) {
|
|
956
|
+
if (configEntries.length <= 1) return configEntries;
|
|
957
|
+
const resolvedDirs = new Map();
|
|
958
|
+
for (const entry of configEntries){
|
|
959
|
+
let dir = entry.configDirectory.replace(/[/\\]+$/, '');
|
|
960
|
+
try {
|
|
961
|
+
dir = node_fs.realpathSync(dir);
|
|
962
|
+
} catch {}
|
|
963
|
+
resolvedDirs.set(entry, dir);
|
|
964
|
+
}
|
|
965
|
+
const sorted = [
|
|
966
|
+
...configEntries
|
|
967
|
+
].sort((a, b)=>(resolvedDirs.get(a)?.length ?? 0) - (resolvedDirs.get(b)?.length ?? 0));
|
|
968
|
+
const result = [];
|
|
969
|
+
for (const config of sorted){
|
|
970
|
+
let ignored = false;
|
|
971
|
+
const configDir = resolvedDirs.get(config);
|
|
972
|
+
for (const parent of result){
|
|
973
|
+
const parentDir = resolvedDirs.get(parent);
|
|
974
|
+
if (!configDir.startsWith(parentDir + node_path.sep) && configDir !== parentDir) continue;
|
|
975
|
+
const globalIgnores = getGlobalIgnores(parent.entries);
|
|
976
|
+
if (0 !== globalIgnores.length) {
|
|
977
|
+
if (isDirIgnoredByPatterns(configDir, globalIgnores, parentDir)) {
|
|
978
|
+
ignored = true;
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
if (!ignored) result.push(config);
|
|
984
|
+
}
|
|
985
|
+
return result;
|
|
986
|
+
}
|
|
987
|
+
async function runWithJSConfigs(binPath, configs, goArgs, cwd, singleThreaded) {
|
|
34
988
|
const configEntries = [];
|
|
35
|
-
const
|
|
36
|
-
|
|
989
|
+
const dirToPath = new Map();
|
|
990
|
+
const isSingleConfig = 1 === configs.size;
|
|
991
|
+
for (const [configPath, configDir] of configs){
|
|
37
992
|
let rawConfig;
|
|
38
993
|
try {
|
|
39
994
|
rawConfig = await loadConfigFile(configPath);
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
995
|
+
} catch (err) {
|
|
42
996
|
const msg = err instanceof Error ? err.message : String(err);
|
|
43
997
|
if (isSingleConfig) {
|
|
44
998
|
process.stderr.write(`Error: failed to load config ${configPath}: ${msg}\n`);
|
|
@@ -50,8 +1004,7 @@ async function runWithJSConfigs(binPath, configs, goArgs, cwd) {
|
|
|
50
1004
|
let entries;
|
|
51
1005
|
try {
|
|
52
1006
|
entries = normalizeConfig(rawConfig);
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
1007
|
+
} catch (err) {
|
|
55
1008
|
const msg = err instanceof Error ? err.message : String(err);
|
|
56
1009
|
if (isSingleConfig) {
|
|
57
1010
|
process.stderr.write(`Error: invalid config in ${configPath}: ${msg}\n`);
|
|
@@ -60,73 +1013,78 @@ async function runWithJSConfigs(binPath, configs, goArgs, cwd) {
|
|
|
60
1013
|
process.stderr.write(`Warning: skipping config ${configPath}: ${msg}\n`);
|
|
61
1014
|
continue;
|
|
62
1015
|
}
|
|
63
|
-
configEntries.push({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (configEntries.length === 0) {
|
|
67
|
-
return execBinary(binPath, goArgs);
|
|
68
|
-
}
|
|
69
|
-
// Filter out nested configs whose directory is covered by a parent config's
|
|
70
|
-
// global ignores. This aligns with ESLint v10 behavior: when walking the
|
|
71
|
-
// directory tree, global ignores prevent entering directories, so nested
|
|
72
|
-
// configs in ignored directories are never discovered.
|
|
73
|
-
const filteredEntries = filterConfigsByParentIgnores(configEntries);
|
|
74
|
-
const payload = JSON.stringify({ configs: filteredEntries });
|
|
75
|
-
try {
|
|
76
|
-
execFileSync(binPath, ['--config-stdin', ...goArgs], {
|
|
77
|
-
input: payload,
|
|
78
|
-
stdio: ['pipe', 'inherit', 'inherit'],
|
|
79
|
-
cwd,
|
|
1016
|
+
configEntries.push({
|
|
1017
|
+
configDirectory: configDir,
|
|
1018
|
+
entries
|
|
80
1019
|
});
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
if (isExecError(error))
|
|
85
|
-
return error.status;
|
|
86
|
-
process.stderr.write(`Failed to execute ${binPath}: ${String(error)}\n`);
|
|
87
|
-
return 1;
|
|
1020
|
+
dirToPath.set(configDir, configPath);
|
|
88
1021
|
}
|
|
1022
|
+
const { runEngine } = await import("./0~engine.js");
|
|
1023
|
+
if (0 === configEntries.length) return runEngine({
|
|
1024
|
+
binPath,
|
|
1025
|
+
goArgs,
|
|
1026
|
+
configs: [],
|
|
1027
|
+
cwd
|
|
1028
|
+
});
|
|
1029
|
+
const filteredEntries = filterConfigsByParentIgnores(configEntries);
|
|
1030
|
+
const { eslintPluginEntries, pluginConfigs } = collectPluginMeta(filteredEntries.map((ce)=>({
|
|
1031
|
+
configPath: dirToPath.get(ce.configDirectory) ?? '',
|
|
1032
|
+
configDirectory: ce.configDirectory,
|
|
1033
|
+
entries: ce.entries
|
|
1034
|
+
})));
|
|
1035
|
+
return runEngine({
|
|
1036
|
+
binPath,
|
|
1037
|
+
goArgs,
|
|
1038
|
+
configs: filteredEntries,
|
|
1039
|
+
cwd,
|
|
1040
|
+
eslintPluginEntries,
|
|
1041
|
+
pluginConfigs,
|
|
1042
|
+
runtime: {
|
|
1043
|
+
singleThreaded
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
89
1046
|
}
|
|
90
|
-
|
|
1047
|
+
async function run(binPath, argv, startTime) {
|
|
91
1048
|
const cwd = process.cwd();
|
|
92
|
-
const args =
|
|
93
|
-
// --init: pass through to Go
|
|
1049
|
+
const args = args_parseArgs(argv);
|
|
94
1050
|
if (args.init) {
|
|
95
|
-
|
|
1051
|
+
const { runEngine } = await import("./0~engine.js");
|
|
1052
|
+
return runEngine({
|
|
1053
|
+
binPath,
|
|
1054
|
+
goArgs: [
|
|
1055
|
+
'--init'
|
|
1056
|
+
],
|
|
1057
|
+
configs: [],
|
|
1058
|
+
cwd
|
|
1059
|
+
});
|
|
96
1060
|
}
|
|
97
|
-
// Validate explicit --config flag
|
|
98
1061
|
if (args.config) {
|
|
99
|
-
const configPath =
|
|
100
|
-
if (!
|
|
1062
|
+
const configPath = node_path.resolve(cwd, args.config);
|
|
1063
|
+
if (!node_fs.existsSync(configPath)) {
|
|
101
1064
|
process.stderr.write(`Error: config file not found: ${configPath}\n`);
|
|
102
1065
|
return 1;
|
|
103
1066
|
}
|
|
104
1067
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// Classify positional arguments into files and directories
|
|
1068
|
+
const goArgs = [
|
|
1069
|
+
`--start-time=${startTime}`,
|
|
1070
|
+
...args.rest
|
|
1071
|
+
];
|
|
110
1072
|
const { files, dirs } = classifyArgs(args.positionals, cwd);
|
|
111
|
-
// Discover JS/TS configs
|
|
112
1073
|
const configs = discoverConfigs(files, dirs, cwd, args.config);
|
|
113
|
-
// Check if any discovered config is a JS/TS config.
|
|
114
|
-
// NOTE: If any JS config is found (even in subdirectories), the entire flow
|
|
115
|
-
// switches to the JS config path. A root JSON config (rslint.json) will be
|
|
116
|
-
// bypassed in this case. This is a known limitation of mixing JSON and JS
|
|
117
|
-
// config formats. JSON config is deprecated — projects should migrate to JS.
|
|
118
1074
|
const jsConfigs = new Map();
|
|
119
|
-
for (const [configPath, configDir] of configs)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
:
|
|
131
|
-
|
|
1075
|
+
for (const [configPath, configDir] of configs)if (isJSConfigFile(configPath)) jsConfigs.set(configPath, configDir);
|
|
1076
|
+
if (jsConfigs.size > 0) return runWithJSConfigs(binPath, jsConfigs, goArgs, cwd, args.singleThreaded);
|
|
1077
|
+
const jsonGoArgs = args.config ? [
|
|
1078
|
+
'--config',
|
|
1079
|
+
args.config,
|
|
1080
|
+
...goArgs
|
|
1081
|
+
] : goArgs;
|
|
1082
|
+
const { runEngine } = await import("./0~engine.js");
|
|
1083
|
+
return runEngine({
|
|
1084
|
+
binPath,
|
|
1085
|
+
goArgs: jsonGoArgs,
|
|
1086
|
+
configs: [],
|
|
1087
|
+
cwd
|
|
1088
|
+
});
|
|
132
1089
|
}
|
|
1090
|
+
export { run };
|