@cjser/globby 16.2.0-cjser.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1349 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/globby.tmp-26-1778145952693/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ convertPathToPattern: () => convertPathToPattern,
33
+ generateGlobTasks: () => generateGlobTasks,
34
+ generateGlobTasksSync: () => generateGlobTasksSync,
35
+ globby: () => globby,
36
+ globbyStream: () => globbyStream,
37
+ globbySync: () => globbySync,
38
+ isDynamicPattern: () => isDynamicPattern,
39
+ isGitIgnored: () => isGitIgnored,
40
+ isGitIgnoredSync: () => isGitIgnoredSync,
41
+ isIgnoredByIgnoreFiles: () => isIgnoredByIgnoreFiles,
42
+ isIgnoredByIgnoreFilesSync: () => isIgnoredByIgnoreFilesSync
43
+ });
44
+ module.exports = __toCommonJS(index_exports);
45
+ var import_node_process2 = __toESM(require("node:process"), 1);
46
+ var import_node_fs3 = __toESM(require("node:fs"), 1);
47
+ var import_node_path3 = __toESM(require("node:path"), 1);
48
+ var import_node_stream = require("node:stream");
49
+ var import_sindresorhus_merge_streams = __toESM(require("@cjser/sindresorhus__merge-streams"), 1);
50
+ var import_fast_glob3 = __toESM(require("fast-glob"), 1);
51
+ var import_node2 = require("@cjser/unicorn-magic/node");
52
+
53
+ // packages/@cjser/globby.tmp-26-1778145952693/ignore.js
54
+ var import_node_process = __toESM(require("node:process"), 1);
55
+ var import_node_fs2 = __toESM(require("node:fs"), 1);
56
+ var import_promises = __toESM(require("node:fs/promises"), 1);
57
+ var import_node_path2 = __toESM(require("node:path"), 1);
58
+ var import_node_os = __toESM(require("node:os"), 1);
59
+ var import_fast_glob2 = __toESM(require("fast-glob"), 1);
60
+ var import_ignore = __toESM(require("ignore"), 1);
61
+ var import_is_path_inside2 = __toESM(require("@cjser/is-path-inside"), 1);
62
+ var import_slash = __toESM(require("@cjser/slash"), 1);
63
+ var import_node = require("@cjser/unicorn-magic/node");
64
+
65
+ // packages/@cjser/globby.tmp-26-1778145952693/utilities.js
66
+ var import_node_fs = __toESM(require("node:fs"), 1);
67
+ var import_node_path = __toESM(require("node:path"), 1);
68
+ var import_node_util = require("node:util");
69
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
70
+ var import_is_path_inside = __toESM(require("@cjser/is-path-inside"), 1);
71
+ var isNegativePattern = (pattern) => pattern[0] === "!";
72
+ var normalizeAbsolutePatternToRelative = (pattern) => {
73
+ if (!pattern.startsWith("/")) {
74
+ return pattern;
75
+ }
76
+ const inner = pattern.slice(1);
77
+ const firstSlashIndex = inner.indexOf("/");
78
+ const firstSegment = firstSlashIndex > 0 ? inner.slice(0, firstSlashIndex) : inner;
79
+ if (firstSlashIndex > 0 && !import_fast_glob.default.isDynamicPattern(firstSegment)) {
80
+ return pattern;
81
+ }
82
+ return inner;
83
+ };
84
+ var absolutePrefixesMatch = (positivePrefix, negativePrefix) => negativePrefix === positivePrefix;
85
+ var getStaticAbsolutePathPrefix = (pattern) => {
86
+ if (!import_node_path.default.isAbsolute(pattern)) {
87
+ return void 0;
88
+ }
89
+ const staticSegments = [];
90
+ for (const segment of pattern.split("/")) {
91
+ if (!segment) {
92
+ continue;
93
+ }
94
+ if (import_fast_glob.default.isDynamicPattern(segment)) {
95
+ break;
96
+ }
97
+ staticSegments.push(segment);
98
+ }
99
+ return staticSegments.length === 0 ? void 0 : `/${staticSegments.join("/")}`;
100
+ };
101
+ var normalizeNegativePattern = (pattern, positiveAbsolutePathPrefixes = [], hasRelativePositivePattern = false) => {
102
+ if (!pattern.startsWith("/")) {
103
+ return pattern;
104
+ }
105
+ const normalizedPattern = normalizeAbsolutePatternToRelative(pattern);
106
+ if (normalizedPattern !== pattern) {
107
+ return normalizedPattern;
108
+ }
109
+ if (hasRelativePositivePattern) {
110
+ return pattern.slice(1);
111
+ }
112
+ const negativeAbsolutePathPrefix = getStaticAbsolutePathPrefix(pattern);
113
+ const preserveAsAbsolutePattern = negativeAbsolutePathPrefix !== void 0 && positiveAbsolutePathPrefixes.some((positiveAbsolutePathPrefix) => absolutePrefixesMatch(positiveAbsolutePathPrefix, negativeAbsolutePathPrefix));
114
+ return preserveAsAbsolutePattern ? pattern : pattern.slice(1);
115
+ };
116
+ var bindFsMethod = (object, methodName) => {
117
+ const method = object == null ? void 0 : object[methodName];
118
+ return typeof method === "function" ? method.bind(object) : void 0;
119
+ };
120
+ var promisifyFsMethod = (object, methodName) => {
121
+ const method = object == null ? void 0 : object[methodName];
122
+ if (typeof method !== "function") {
123
+ return void 0;
124
+ }
125
+ return (0, import_node_util.promisify)(method.bind(object));
126
+ };
127
+ var normalizeDirectoryPatternForFastGlob = (pattern) => {
128
+ if (!pattern.endsWith("/")) {
129
+ return pattern;
130
+ }
131
+ const trimmedPattern = pattern.replace(/\/+$/u, "");
132
+ if (!trimmedPattern) {
133
+ return "/**";
134
+ }
135
+ if (trimmedPattern === "**") {
136
+ return "**/**";
137
+ }
138
+ const hasLeadingSlash = trimmedPattern.startsWith("/");
139
+ const patternBody = hasLeadingSlash ? trimmedPattern.slice(1) : trimmedPattern;
140
+ const hasInnerSlash = patternBody.includes("/");
141
+ const needsRecursivePrefix = !hasLeadingSlash && !hasInnerSlash && !trimmedPattern.startsWith("**/");
142
+ const recursivePrefix = needsRecursivePrefix ? "**/" : "";
143
+ return `${recursivePrefix}${trimmedPattern}/**`;
144
+ };
145
+ var getParentDirectoryPrefix = (pattern) => {
146
+ const normalizedPattern = isNegativePattern(pattern) ? pattern.slice(1) : pattern;
147
+ const match = normalizedPattern.match(/^(\.\.\/)+/);
148
+ return match ? match[0] : "";
149
+ };
150
+ var adjustIgnorePatternsForParentDirectories = (patterns, ignorePatterns) => {
151
+ if (patterns.length === 0 || ignorePatterns.length === 0) {
152
+ return ignorePatterns;
153
+ }
154
+ const parentPrefixes = patterns.map((pattern) => getParentDirectoryPrefix(pattern));
155
+ const firstPrefix = parentPrefixes[0];
156
+ if (!firstPrefix) {
157
+ return ignorePatterns;
158
+ }
159
+ const allSamePrefix = parentPrefixes.every((prefix) => prefix === firstPrefix);
160
+ if (!allSamePrefix) {
161
+ return ignorePatterns;
162
+ }
163
+ return ignorePatterns.map((pattern) => {
164
+ if (pattern.startsWith("**/") && !pattern.startsWith("../")) {
165
+ return firstPrefix + pattern;
166
+ }
167
+ return pattern;
168
+ });
169
+ };
170
+ var getAsyncStatMethod = (fsImplementation) => bindFsMethod(fsImplementation == null ? void 0 : fsImplementation.promises, "stat") ?? bindFsMethod(import_node_fs.default.promises, "stat");
171
+ var getStatSyncMethod = (fsImplementation) => {
172
+ if (fsImplementation) {
173
+ return bindFsMethod(fsImplementation, "statSync");
174
+ }
175
+ return bindFsMethod(import_node_fs.default, "statSync");
176
+ };
177
+ var pathHasGitDirectory = (stats) => {
178
+ var _a, _b;
179
+ return Boolean(((_a = stats == null ? void 0 : stats.isDirectory) == null ? void 0 : _a.call(stats)) || ((_b = stats == null ? void 0 : stats.isFile) == null ? void 0 : _b.call(stats)));
180
+ };
181
+ var buildPathChain = (startPath, rootPath) => {
182
+ const chain = [];
183
+ let currentPath = startPath;
184
+ chain.push(currentPath);
185
+ while (currentPath !== rootPath) {
186
+ const parentPath = import_node_path.default.dirname(currentPath);
187
+ if (parentPath === currentPath) {
188
+ break;
189
+ }
190
+ currentPath = parentPath;
191
+ chain.push(currentPath);
192
+ }
193
+ return chain;
194
+ };
195
+ var findGitRootInChain = async (paths, statMethod) => {
196
+ for (const directory of paths) {
197
+ const gitPath = import_node_path.default.join(directory, ".git");
198
+ try {
199
+ const stats = await statMethod(gitPath);
200
+ if (pathHasGitDirectory(stats)) {
201
+ return directory;
202
+ }
203
+ } catch {
204
+ }
205
+ }
206
+ return void 0;
207
+ };
208
+ var findGitRootSyncUncached = (cwd, fsImplementation) => {
209
+ const statSyncMethod = getStatSyncMethod(fsImplementation);
210
+ if (!statSyncMethod) {
211
+ return void 0;
212
+ }
213
+ const currentPath = import_node_path.default.resolve(cwd);
214
+ const { root } = import_node_path.default.parse(currentPath);
215
+ const chain = buildPathChain(currentPath, root);
216
+ for (const directory of chain) {
217
+ const gitPath = import_node_path.default.join(directory, ".git");
218
+ try {
219
+ const stats = statSyncMethod(gitPath);
220
+ if (pathHasGitDirectory(stats)) {
221
+ return directory;
222
+ }
223
+ } catch {
224
+ }
225
+ }
226
+ return void 0;
227
+ };
228
+ var findGitRootSync = (cwd, fsImplementation) => {
229
+ if (typeof cwd !== "string") {
230
+ throw new TypeError("cwd must be a string");
231
+ }
232
+ return findGitRootSyncUncached(cwd, fsImplementation);
233
+ };
234
+ var findGitRootAsyncUncached = async (cwd, fsImplementation) => {
235
+ const statMethod = getAsyncStatMethod(fsImplementation);
236
+ if (!statMethod) {
237
+ return findGitRootSync(cwd, fsImplementation);
238
+ }
239
+ const currentPath = import_node_path.default.resolve(cwd);
240
+ const { root } = import_node_path.default.parse(currentPath);
241
+ const chain = buildPathChain(currentPath, root);
242
+ return findGitRootInChain(chain, statMethod);
243
+ };
244
+ var findGitRoot = async (cwd, fsImplementation) => {
245
+ if (typeof cwd !== "string") {
246
+ throw new TypeError("cwd must be a string");
247
+ }
248
+ return findGitRootAsyncUncached(cwd, fsImplementation);
249
+ };
250
+ var isWithinGitRoot = (gitRoot, cwd) => {
251
+ const resolvedGitRoot = import_node_path.default.resolve(gitRoot);
252
+ const resolvedCwd = import_node_path.default.resolve(cwd);
253
+ return resolvedCwd === resolvedGitRoot || (0, import_is_path_inside.default)(resolvedCwd, resolvedGitRoot);
254
+ };
255
+ var getParentGitignorePaths = (gitRoot, cwd) => {
256
+ if (gitRoot && typeof gitRoot !== "string") {
257
+ throw new TypeError("gitRoot must be a string or undefined");
258
+ }
259
+ if (typeof cwd !== "string") {
260
+ throw new TypeError("cwd must be a string");
261
+ }
262
+ if (!gitRoot) {
263
+ return [];
264
+ }
265
+ if (!isWithinGitRoot(gitRoot, cwd)) {
266
+ return [];
267
+ }
268
+ const chain = buildPathChain(import_node_path.default.resolve(cwd), import_node_path.default.resolve(gitRoot));
269
+ return [...chain].reverse().map((directory) => import_node_path.default.join(directory, ".gitignore"));
270
+ };
271
+ var convertPatternsForFastGlob = (patterns, usingGitRoot, normalizeDirectoryPatternForFastGlob2) => {
272
+ if (usingGitRoot) {
273
+ return [];
274
+ }
275
+ const result = [];
276
+ let hasNegations = false;
277
+ for (const pattern of patterns) {
278
+ if (isNegativePattern(pattern)) {
279
+ hasNegations = true;
280
+ break;
281
+ }
282
+ result.push(normalizeDirectoryPatternForFastGlob2(pattern));
283
+ }
284
+ return hasNegations ? [] : result;
285
+ };
286
+
287
+ // packages/@cjser/globby.tmp-26-1778145952693/ignore.js
288
+ var defaultIgnoredDirectories = [
289
+ "**/node_modules",
290
+ "**/flow-typed",
291
+ "**/coverage",
292
+ "**/.git"
293
+ ];
294
+ var ignoreFilesGlobOptions = {
295
+ absolute: true,
296
+ dot: true
297
+ };
298
+ var GITIGNORE_FILES_PATTERN = "**/.gitignore";
299
+ var MAX_INCLUDE_DEPTH = 10;
300
+ var getReadFileMethod = (fsImplementation) => bindFsMethod(fsImplementation == null ? void 0 : fsImplementation.promises, "readFile") ?? bindFsMethod(import_promises.default, "readFile") ?? promisifyFsMethod(fsImplementation, "readFile");
301
+ var getReadFileSyncMethod = (fsImplementation) => bindFsMethod(fsImplementation, "readFileSync") ?? bindFsMethod(import_node_fs2.default, "readFileSync");
302
+ var shouldSkipIgnoreFileError = (error, suppressErrors) => {
303
+ if (!error) {
304
+ return Boolean(suppressErrors);
305
+ }
306
+ if (error.code === "ENOENT" || error.code === "ENOTDIR") {
307
+ return true;
308
+ }
309
+ return Boolean(suppressErrors);
310
+ };
311
+ var createReadError = (kind, filePath, error) => {
312
+ const prefix = `Failed to read ${kind} at ${filePath}`;
313
+ if (error instanceof Error) {
314
+ return new Error(`${prefix}: ${error.message}`, { cause: error });
315
+ }
316
+ return new Error(`${prefix}: ${String(error)}`);
317
+ };
318
+ var createIgnoreFileReadError = (filePath, error) => createReadError("ignore file", filePath, error);
319
+ var createGitConfigReadError = (filePath, error) => createReadError("git config", filePath, error);
320
+ var processIgnoreFileCore = (filePath, readMethod, suppressErrors) => {
321
+ try {
322
+ const content = readMethod(filePath, "utf8");
323
+ return { filePath, content };
324
+ } catch (error) {
325
+ if (shouldSkipIgnoreFileError(error, suppressErrors)) {
326
+ return void 0;
327
+ }
328
+ throw createIgnoreFileReadError(filePath, error);
329
+ }
330
+ };
331
+ var readIgnoreFilesSafely = async (paths, readFileMethod, suppressErrors) => {
332
+ const fileResults = await Promise.all(paths.map(async (filePath) => {
333
+ try {
334
+ const content = await readFileMethod(filePath, "utf8");
335
+ return { filePath, content };
336
+ } catch (error) {
337
+ if (shouldSkipIgnoreFileError(error, suppressErrors)) {
338
+ return void 0;
339
+ }
340
+ throw createIgnoreFileReadError(filePath, error);
341
+ }
342
+ }));
343
+ return fileResults.filter(Boolean);
344
+ };
345
+ var readIgnoreFilesSafelySync = (paths, readFileSyncMethod, suppressErrors) => paths.map((filePath) => processIgnoreFileCore(filePath, readFileSyncMethod, suppressErrors)).filter(Boolean);
346
+ var dedupePaths = (paths) => {
347
+ const seen = /* @__PURE__ */ new Set();
348
+ return paths.filter((filePath) => {
349
+ if (seen.has(filePath)) {
350
+ return false;
351
+ }
352
+ seen.add(filePath);
353
+ return true;
354
+ });
355
+ };
356
+ var globIgnoreFiles = (globFunction, patterns, normalizedOptions) => globFunction(patterns, {
357
+ ...normalizedOptions,
358
+ ...ignoreFilesGlobOptions
359
+ // Must be last to ensure absolute/dot flags stick
360
+ });
361
+ var getParentIgnorePaths = (gitRoot, normalizedOptions) => gitRoot ? getParentGitignorePaths(gitRoot, normalizedOptions.cwd) : [];
362
+ var combineIgnoreFilePaths = (gitRoot, normalizedOptions, childPaths) => dedupePaths([
363
+ ...getParentIgnorePaths(gitRoot, normalizedOptions),
364
+ ...childPaths
365
+ ]);
366
+ var buildIgnoreResult = (files, normalizedOptions, gitRoot) => {
367
+ const baseDir = gitRoot || normalizedOptions.cwd;
368
+ const patterns = getPatternsFromIgnoreFiles(files, baseDir);
369
+ const matcher = createIgnoreMatcher(patterns, normalizedOptions.cwd, baseDir);
370
+ return {
371
+ patterns,
372
+ matcher,
373
+ predicate: (fileOrDirectory) => matcher(fileOrDirectory).ignored,
374
+ usingGitRoot: Boolean(gitRoot && gitRoot !== normalizedOptions.cwd)
375
+ };
376
+ };
377
+ var applyBaseToPattern = (pattern, base) => {
378
+ if (!base) {
379
+ return pattern;
380
+ }
381
+ const isNegative = isNegativePattern(pattern);
382
+ const cleanPattern = isNegative ? pattern.slice(1) : pattern;
383
+ const slashIndex = cleanPattern.indexOf("/");
384
+ const hasNonTrailingSlash = slashIndex !== -1 && slashIndex !== cleanPattern.length - 1;
385
+ let result;
386
+ if (!hasNonTrailingSlash) {
387
+ result = import_node_path2.default.posix.join(base, "**", cleanPattern);
388
+ } else if (cleanPattern.startsWith("/")) {
389
+ result = import_node_path2.default.posix.join(base, cleanPattern.slice(1));
390
+ } else {
391
+ result = import_node_path2.default.posix.join(base, cleanPattern);
392
+ }
393
+ return isNegative ? "!" + result : result;
394
+ };
395
+ var parseIgnoreFile = (file, cwd) => {
396
+ const base = (0, import_slash.default)(import_node_path2.default.relative(cwd, import_node_path2.default.dirname(file.filePath)));
397
+ return file.content.split(/\r?\n/).filter((line) => line && !line.startsWith("#")).map((pattern) => applyBaseToPattern(pattern, base));
398
+ };
399
+ var toRelativePath = (fileOrDirectory, cwd) => {
400
+ if (import_node_path2.default.isAbsolute(fileOrDirectory)) {
401
+ const relativePath = import_node_path2.default.relative(cwd, fileOrDirectory);
402
+ if (relativePath && !(0, import_is_path_inside2.default)(fileOrDirectory, cwd)) {
403
+ return void 0;
404
+ }
405
+ return relativePath;
406
+ }
407
+ if (fileOrDirectory.startsWith("./")) {
408
+ return fileOrDirectory.slice(2);
409
+ }
410
+ if (fileOrDirectory.startsWith("../")) {
411
+ return void 0;
412
+ }
413
+ return fileOrDirectory;
414
+ };
415
+ var notIgnored = { ignored: false, unignored: false };
416
+ var createIgnoreMatcher = (patterns, cwd, baseDir) => {
417
+ const ignores = (0, import_ignore.default)().add(patterns);
418
+ const resolvedCwd = import_node_path2.default.normalize(import_node_path2.default.resolve(cwd));
419
+ const resolvedBaseDir = import_node_path2.default.normalize(import_node_path2.default.resolve(baseDir));
420
+ return (fileOrDirectory) => {
421
+ fileOrDirectory = (0, import_node.toPath)(fileOrDirectory);
422
+ const hasTrailingSeparator = /[/\\]$/.test(fileOrDirectory);
423
+ const normalizedPath = import_node_path2.default.normalize(import_node_path2.default.resolve(fileOrDirectory));
424
+ if (normalizedPath === resolvedCwd) {
425
+ return notIgnored;
426
+ }
427
+ let relativePath = toRelativePath(fileOrDirectory, resolvedBaseDir);
428
+ if (relativePath === void 0) {
429
+ return notIgnored;
430
+ }
431
+ if (!relativePath) {
432
+ return notIgnored;
433
+ }
434
+ if (hasTrailingSeparator && !relativePath.endsWith(import_node_path2.default.sep)) {
435
+ relativePath += import_node_path2.default.sep;
436
+ }
437
+ return ignores.test((0, import_slash.default)(relativePath));
438
+ };
439
+ };
440
+ var normalizeOptions = (options = {}) => {
441
+ const ignoreOption = options.ignore ? Array.isArray(options.ignore) ? options.ignore : [options.ignore] : [];
442
+ const cwd = (0, import_node.toPath)(options.cwd) ?? import_node_process.default.cwd();
443
+ const deep = typeof options.deep === "number" ? Math.max(0, options.deep) + 1 : Number.POSITIVE_INFINITY;
444
+ return {
445
+ cwd,
446
+ suppressErrors: options.suppressErrors ?? false,
447
+ deep,
448
+ ignore: [...ignoreOption, ...defaultIgnoredDirectories],
449
+ followSymbolicLinks: options.followSymbolicLinks ?? true,
450
+ concurrency: options.concurrency,
451
+ throwErrorOnBrokenSymbolicLink: options.throwErrorOnBrokenSymbolicLink ?? false,
452
+ fs: options.fs
453
+ };
454
+ };
455
+ var unescapeGitQuotedValue = (value) => value.replaceAll(/\\(["\\abfnrtv])/g, (_match, escapedCharacter) => {
456
+ switch (escapedCharacter) {
457
+ case "a": {
458
+ return "\x07";
459
+ }
460
+ case "b": {
461
+ return "\b";
462
+ }
463
+ case "f": {
464
+ return "\f";
465
+ }
466
+ case "n": {
467
+ return "\n";
468
+ }
469
+ case "r": {
470
+ return "\r";
471
+ }
472
+ case "t": {
473
+ return " ";
474
+ }
475
+ case "v": {
476
+ return "\v";
477
+ }
478
+ default: {
479
+ return escapedCharacter;
480
+ }
481
+ }
482
+ });
483
+ var parseGitConfigValue = (value) => {
484
+ const trimmedValue = value.trim();
485
+ const quotedMatch = trimmedValue.match(/^"((?:[^"\\]|\\.)*)"\s*(?:[#;].*)?$/);
486
+ if (quotedMatch) {
487
+ return unescapeGitQuotedValue(quotedMatch[1]);
488
+ }
489
+ return trimmedValue.replace(/\s[#;].*$/, "").trim();
490
+ };
491
+ var resolveConfigPath = (filePath, configPath) => {
492
+ if (configPath.startsWith("~/")) {
493
+ const homeDirectory = import_node_os.default.homedir();
494
+ const resolved = import_node_path2.default.join(homeDirectory, configPath.slice(2));
495
+ if (!(0, import_is_path_inside2.default)(resolved, homeDirectory)) {
496
+ return import_node_path2.default.join(homeDirectory, ".globby-invalid-path-traversal");
497
+ }
498
+ return resolved;
499
+ }
500
+ if (import_node_path2.default.isAbsolute(configPath)) {
501
+ return configPath;
502
+ }
503
+ return import_node_path2.default.resolve(import_node_path2.default.dirname(filePath), configPath);
504
+ };
505
+ var parseGitConfigSection = (line) => {
506
+ if (!line.startsWith("[")) {
507
+ return void 0;
508
+ }
509
+ let inQuotes = false;
510
+ let isEscaped = false;
511
+ for (let index = 1; index < line.length; index++) {
512
+ const character = line[index];
513
+ if (isEscaped) {
514
+ isEscaped = false;
515
+ continue;
516
+ }
517
+ if (character === "\\") {
518
+ isEscaped = true;
519
+ continue;
520
+ }
521
+ if (character === '"') {
522
+ inQuotes = !inQuotes;
523
+ continue;
524
+ }
525
+ if (character === "]" && !inQuotes) {
526
+ const remainder = line.slice(index + 1).trimStart();
527
+ if (remainder && !remainder.startsWith("#") && !remainder.startsWith(";")) {
528
+ return void 0;
529
+ }
530
+ return line.slice(1, index).trim();
531
+ }
532
+ }
533
+ return void 0;
534
+ };
535
+ var parseGitConfigEntry = (line) => {
536
+ const match = line.match(/^([A-Za-z\d-.]+)\s*=\s*(.*)$/);
537
+ if (!match) {
538
+ return void 0;
539
+ }
540
+ return {
541
+ key: match[1].toLowerCase(),
542
+ value: parseGitConfigValue(match[2])
543
+ };
544
+ };
545
+ var parseIncludeIfCondition = (section) => {
546
+ if (!section) {
547
+ return void 0;
548
+ }
549
+ const match = section.match(/^includeif\s+"([^"]+)"$/i);
550
+ return match ? match[1] : void 0;
551
+ };
552
+ var normalizeGitConfigConditionPattern = (pattern, configFilePath) => {
553
+ if (pattern.startsWith("~/")) {
554
+ pattern = import_node_path2.default.join(import_node_os.default.homedir(), pattern.slice(2));
555
+ } else if (pattern.startsWith("./")) {
556
+ pattern = import_node_path2.default.resolve(import_node_path2.default.dirname(configFilePath), pattern.slice(2));
557
+ } else if (!import_node_path2.default.isAbsolute(pattern)) {
558
+ pattern = `**/${pattern}`;
559
+ }
560
+ if (pattern.endsWith("/")) {
561
+ pattern += "**";
562
+ }
563
+ return (0, import_slash.default)(pattern);
564
+ };
565
+ var gitConfigGlobToRegex = (pattern, flags) => {
566
+ let regex = "";
567
+ for (let index = 0; index < pattern.length; index++) {
568
+ const character = pattern[index];
569
+ const nextCharacter = pattern[index + 1];
570
+ const nextNextCharacter = pattern[index + 2];
571
+ if (character === "*" && nextCharacter === "*" && nextNextCharacter === "/") {
572
+ regex += "(?:.*/)?";
573
+ index += 2;
574
+ continue;
575
+ }
576
+ if (character === "*" && nextCharacter === "*") {
577
+ regex += ".*";
578
+ index += 1;
579
+ continue;
580
+ }
581
+ if (character === "*") {
582
+ regex += "[^/]*";
583
+ continue;
584
+ }
585
+ if (character === "?") {
586
+ regex += "[^/]";
587
+ continue;
588
+ }
589
+ if (character === "[") {
590
+ const closingBracketIndex = pattern.indexOf("]", index + 1);
591
+ if (closingBracketIndex !== -1) {
592
+ const bracketContent = pattern.slice(index + 1, closingBracketIndex);
593
+ if (bracketContent) {
594
+ const negatedBracketContent = bracketContent[0] === "!" ? `^${bracketContent.slice(1)}` : bracketContent;
595
+ regex += `[${negatedBracketContent}]`;
596
+ index = closingBracketIndex;
597
+ continue;
598
+ }
599
+ }
600
+ }
601
+ regex += /[|\\{}()[\]^$+?.]/.test(character) ? `\\${character}` : character;
602
+ }
603
+ try {
604
+ return new RegExp(`^${regex}$`, flags);
605
+ } catch {
606
+ return /(?!)/;
607
+ }
608
+ };
609
+ var matchesIncludeIfCondition = (condition, gitDirectory, configFilePath) => {
610
+ if (!gitDirectory) {
611
+ return false;
612
+ }
613
+ const match = condition.match(/^(gitdir|gitdir\/i):(.*)$/i);
614
+ if (!match) {
615
+ return false;
616
+ }
617
+ const [, keyword, rawPattern] = match;
618
+ const pattern = normalizeGitConfigConditionPattern(rawPattern.trim(), configFilePath);
619
+ const isCaseInsensitive = keyword.toLowerCase() === "gitdir/i";
620
+ const regularExpression = gitConfigGlobToRegex(pattern, isCaseInsensitive ? "i" : void 0);
621
+ const normalizedGitDirectory = (0, import_slash.default)(import_node_path2.default.resolve(gitDirectory));
622
+ return regularExpression.test(normalizedGitDirectory);
623
+ };
624
+ var shouldIncludeConfigSection = (section, gitDirectory, configFilePath) => {
625
+ if ((section == null ? void 0 : section.toLowerCase()) === "include") {
626
+ return true;
627
+ }
628
+ const condition = parseIncludeIfCondition(section);
629
+ return condition ? matchesIncludeIfCondition(condition, gitDirectory, configFilePath) : false;
630
+ };
631
+ var createExcludesFileValue = (value, declaringFilePath) => ({
632
+ value,
633
+ declaringFilePath
634
+ });
635
+ var parseGitConfigForExcludesFile = (content, normalizedPath, gitDirectory) => {
636
+ let currentSection;
637
+ let excludesFile;
638
+ const includePaths = [];
639
+ for (const line of content.split(/\r?\n/)) {
640
+ const trimmed = line.trim();
641
+ if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith(";")) {
642
+ continue;
643
+ }
644
+ if (trimmed.startsWith("[")) {
645
+ currentSection = parseGitConfigSection(trimmed);
646
+ continue;
647
+ }
648
+ const entry = parseGitConfigEntry(trimmed);
649
+ if (!entry) {
650
+ continue;
651
+ }
652
+ if ((currentSection == null ? void 0 : currentSection.toLowerCase()) === "core" && entry.key === "excludesfile") {
653
+ excludesFile = createExcludesFileValue(entry.value, normalizedPath);
654
+ continue;
655
+ }
656
+ if (shouldIncludeConfigSection(currentSection, gitDirectory, normalizedPath) && entry.key === "path" && entry.value) {
657
+ includePaths.push(resolveConfigPath(normalizedPath, entry.value));
658
+ }
659
+ }
660
+ return { excludesFile, includePaths };
661
+ };
662
+ var readGitConfigFile = (normalizedPath, readMethod, suppressErrors) => {
663
+ try {
664
+ return readMethod(normalizedPath, "utf8");
665
+ } catch (error) {
666
+ if (shouldSkipIgnoreFileError(error, suppressErrors)) {
667
+ return void 0;
668
+ }
669
+ throw createGitConfigReadError(normalizedPath, error);
670
+ }
671
+ };
672
+ var getExcludesFileFromGitConfigSync = (filePath, readFileSync, gitDirectory, options = {}) => {
673
+ const { suppressErrors, includeStack = /* @__PURE__ */ new Set(), depth = 0 } = options;
674
+ const normalizedPath = import_node_path2.default.resolve(filePath);
675
+ if (includeStack.has(normalizedPath)) {
676
+ return void 0;
677
+ }
678
+ if (depth >= MAX_INCLUDE_DEPTH) {
679
+ return void 0;
680
+ }
681
+ includeStack.add(normalizedPath);
682
+ const content = readGitConfigFile(normalizedPath, readFileSync, suppressErrors);
683
+ if (content === void 0) {
684
+ includeStack.delete(normalizedPath);
685
+ return void 0;
686
+ }
687
+ let { excludesFile, includePaths } = parseGitConfigForExcludesFile(content, normalizedPath, gitDirectory);
688
+ for (const includePath of includePaths) {
689
+ const includedExcludesFile = getExcludesFileFromGitConfigSync(includePath, readFileSync, gitDirectory, { suppressErrors, includeStack, depth: depth + 1 });
690
+ if (includedExcludesFile !== void 0) {
691
+ excludesFile = includedExcludesFile;
692
+ }
693
+ }
694
+ includeStack.delete(normalizedPath);
695
+ return excludesFile;
696
+ };
697
+ var getExcludesFileFromGitConfigAsync = async (filePath, readFile, gitDirectory, options = {}) => {
698
+ const { suppressErrors, includeStack = /* @__PURE__ */ new Set(), depth = 0 } = options;
699
+ const normalizedPath = import_node_path2.default.resolve(filePath);
700
+ if (includeStack.has(normalizedPath)) {
701
+ return void 0;
702
+ }
703
+ if (depth >= MAX_INCLUDE_DEPTH) {
704
+ return void 0;
705
+ }
706
+ includeStack.add(normalizedPath);
707
+ let content;
708
+ try {
709
+ content = await readFile(normalizedPath, "utf8");
710
+ } catch (error) {
711
+ includeStack.delete(normalizedPath);
712
+ if (shouldSkipIgnoreFileError(error, suppressErrors)) {
713
+ return void 0;
714
+ }
715
+ throw createGitConfigReadError(normalizedPath, error);
716
+ }
717
+ let { excludesFile, includePaths } = parseGitConfigForExcludesFile(content, normalizedPath, gitDirectory);
718
+ for (const includePath of includePaths) {
719
+ const includedExcludesFile = await getExcludesFileFromGitConfigAsync(includePath, readFile, gitDirectory, { suppressErrors, includeStack, depth: depth + 1 });
720
+ if (includedExcludesFile !== void 0) {
721
+ excludesFile = includedExcludesFile;
722
+ }
723
+ }
724
+ includeStack.delete(normalizedPath);
725
+ return excludesFile;
726
+ };
727
+ var resolveGitDirectoryFromFile = (gitFilePath, content) => {
728
+ const match = content.match(/^gitdir:\s*(.+?)\s*$/i);
729
+ if (!match) {
730
+ return gitFilePath;
731
+ }
732
+ return import_node_path2.default.resolve(import_node_path2.default.dirname(gitFilePath), match[1]);
733
+ };
734
+ var getGitDirectorySync = (gitRoot, readFileSync) => {
735
+ if (!gitRoot) {
736
+ return void 0;
737
+ }
738
+ const gitFilePath = import_node_path2.default.join(gitRoot, ".git");
739
+ try {
740
+ return resolveGitDirectoryFromFile(gitFilePath, readFileSync(gitFilePath, "utf8"));
741
+ } catch {
742
+ return gitFilePath;
743
+ }
744
+ };
745
+ var getGitDirectoryAsync = async (gitRoot, readFile) => {
746
+ if (!gitRoot) {
747
+ return void 0;
748
+ }
749
+ const gitFilePath = import_node_path2.default.join(gitRoot, ".git");
750
+ try {
751
+ return resolveGitDirectoryFromFile(gitFilePath, await readFile(gitFilePath, "utf8"));
752
+ } catch {
753
+ return gitFilePath;
754
+ }
755
+ };
756
+ var getXdgConfigHome = () => import_node_process.default.env.XDG_CONFIG_HOME || import_node_path2.default.join(import_node_os.default.homedir(), ".config");
757
+ var getGitConfigPaths = () => {
758
+ if ("GIT_CONFIG_GLOBAL" in import_node_process.default.env) {
759
+ const value = import_node_process.default.env.GIT_CONFIG_GLOBAL;
760
+ return value ? [value] : [];
761
+ }
762
+ return [
763
+ import_node_path2.default.join(getXdgConfigHome(), "git", "config"),
764
+ import_node_path2.default.join(import_node_os.default.homedir(), ".gitconfig")
765
+ ];
766
+ };
767
+ var getDefaultGlobalGitignorePath = () => import_node_path2.default.join(getXdgConfigHome(), "git", "ignore");
768
+ var resolveExcludesFilePath = (excludesFileConfig) => {
769
+ if ((excludesFileConfig == null ? void 0 : excludesFileConfig.value) === "") {
770
+ return void 0;
771
+ }
772
+ if (excludesFileConfig === void 0) {
773
+ return getDefaultGlobalGitignorePath();
774
+ }
775
+ return resolveConfigPath(excludesFileConfig.declaringFilePath, excludesFileConfig.value);
776
+ };
777
+ var readGlobalGitignoreContent = (filePath, readMethod, suppressErrors) => {
778
+ try {
779
+ const content = readMethod(filePath, "utf8");
780
+ return { filePath, content };
781
+ } catch (error) {
782
+ if (shouldSkipIgnoreFileError(error, suppressErrors)) {
783
+ return void 0;
784
+ }
785
+ throw createIgnoreFileReadError(filePath, error);
786
+ }
787
+ };
788
+ var getGlobalGitignoreFile = (options = {}) => {
789
+ const cwd = (0, import_node.toPath)(options.cwd) ?? import_node_process.default.cwd();
790
+ const readFileSync = getReadFileSyncMethod(options.fs);
791
+ const gitRoot = findGitRootSync(cwd, options.fs);
792
+ const gitDirectory = getGitDirectorySync(gitRoot, readFileSync);
793
+ let excludesFileConfig;
794
+ for (const gitConfigPath of getGitConfigPaths()) {
795
+ const value = getExcludesFileFromGitConfigSync(gitConfigPath, readFileSync, gitDirectory, { suppressErrors: options.suppressErrors });
796
+ if (value !== void 0) {
797
+ excludesFileConfig = value;
798
+ }
799
+ }
800
+ const filePath = resolveExcludesFilePath(excludesFileConfig);
801
+ return filePath === void 0 ? void 0 : readGlobalGitignoreContent(filePath, readFileSync, options.suppressErrors);
802
+ };
803
+ var getGlobalGitignoreFileAsync = async (options = {}) => {
804
+ const cwd = (0, import_node.toPath)(options.cwd) ?? import_node_process.default.cwd();
805
+ const readFile = getReadFileMethod(options.fs);
806
+ const gitRoot = await findGitRoot(cwd, options.fs);
807
+ const gitDirectory = await getGitDirectoryAsync(gitRoot, readFile);
808
+ const excludesFileValues = await Promise.all(getGitConfigPaths().map((gitConfigPath) => getExcludesFileFromGitConfigAsync(
809
+ gitConfigPath,
810
+ readFile,
811
+ gitDirectory,
812
+ { suppressErrors: options.suppressErrors }
813
+ )));
814
+ const excludesFileConfig = excludesFileValues.findLast((value) => value !== void 0);
815
+ const filePath = resolveExcludesFilePath(excludesFileConfig);
816
+ if (filePath === void 0) {
817
+ return void 0;
818
+ }
819
+ try {
820
+ const content = await readFile(filePath, "utf8");
821
+ return { filePath, content };
822
+ } catch (error) {
823
+ if (shouldSkipIgnoreFileError(error, options.suppressErrors)) {
824
+ return void 0;
825
+ }
826
+ throw createIgnoreFileReadError(filePath, error);
827
+ }
828
+ };
829
+ var buildGlobalMatcher = (globalIgnoreFile, cwd, rootDirectory = cwd) => {
830
+ const patterns = parseIgnoreFile(globalIgnoreFile, import_node_path2.default.dirname(globalIgnoreFile.filePath));
831
+ return createIgnoreMatcher(patterns, cwd, rootDirectory);
832
+ };
833
+ var collectIgnoreFileArtifactsAsync = async (patterns, options, includeParentIgnoreFiles) => {
834
+ const normalizedOptions = normalizeOptions(options);
835
+ const childPaths = await globIgnoreFiles(import_fast_glob2.default, patterns, normalizedOptions);
836
+ const gitRoot = includeParentIgnoreFiles ? await findGitRoot(normalizedOptions.cwd, normalizedOptions.fs) : void 0;
837
+ const allPaths = combineIgnoreFilePaths(gitRoot, normalizedOptions, childPaths);
838
+ const readFileMethod = getReadFileMethod(normalizedOptions.fs);
839
+ const files = await readIgnoreFilesSafely(allPaths, readFileMethod, normalizedOptions.suppressErrors);
840
+ return { files, normalizedOptions, gitRoot };
841
+ };
842
+ var collectIgnoreFileArtifactsSync = (patterns, options, includeParentIgnoreFiles) => {
843
+ const normalizedOptions = normalizeOptions(options);
844
+ const childPaths = globIgnoreFiles(import_fast_glob2.default.sync, patterns, normalizedOptions);
845
+ const gitRoot = includeParentIgnoreFiles ? findGitRootSync(normalizedOptions.cwd, normalizedOptions.fs) : void 0;
846
+ const allPaths = combineIgnoreFilePaths(gitRoot, normalizedOptions, childPaths);
847
+ const readFileSyncMethod = getReadFileSyncMethod(normalizedOptions.fs);
848
+ const files = readIgnoreFilesSafelySync(allPaths, readFileSyncMethod, normalizedOptions.suppressErrors);
849
+ return { files, normalizedOptions, gitRoot };
850
+ };
851
+ var isIgnoredByIgnoreFiles = async (patterns, options) => {
852
+ const { files, normalizedOptions, gitRoot } = await collectIgnoreFileArtifactsAsync(patterns, options, false);
853
+ return buildIgnoreResult(files, normalizedOptions, gitRoot).predicate;
854
+ };
855
+ var isIgnoredByIgnoreFilesSync = (patterns, options) => {
856
+ const { files, normalizedOptions, gitRoot } = collectIgnoreFileArtifactsSync(patterns, options, false);
857
+ return buildIgnoreResult(files, normalizedOptions, gitRoot).predicate;
858
+ };
859
+ var getPatternsFromIgnoreFiles = (files, baseDir) => files.flatMap((file) => parseIgnoreFile(file, baseDir));
860
+ var getIgnorePatternsAndPredicate = async (patterns, options, includeParentIgnoreFiles = false) => {
861
+ const { files, normalizedOptions, gitRoot } = await collectIgnoreFileArtifactsAsync(
862
+ patterns,
863
+ options,
864
+ includeParentIgnoreFiles
865
+ );
866
+ return buildIgnoreResult(files, normalizedOptions, gitRoot);
867
+ };
868
+ var getIgnorePatternsAndPredicateSync = (patterns, options, includeParentIgnoreFiles = false) => {
869
+ const { files, normalizedOptions, gitRoot } = collectIgnoreFileArtifactsSync(
870
+ patterns,
871
+ options,
872
+ includeParentIgnoreFiles
873
+ );
874
+ return buildIgnoreResult(files, normalizedOptions, gitRoot);
875
+ };
876
+ var isGitIgnored = (options) => isIgnoredByIgnoreFiles(GITIGNORE_FILES_PATTERN, options);
877
+ var isGitIgnoredSync = (options) => isIgnoredByIgnoreFilesSync(GITIGNORE_FILES_PATTERN, options);
878
+
879
+ // packages/@cjser/globby.tmp-26-1778145952693/index.js
880
+ var assertPatternsInput = (patterns) => {
881
+ if (patterns.some((pattern) => typeof pattern !== "string")) {
882
+ throw new TypeError("Patterns must be a string or an array of strings");
883
+ }
884
+ };
885
+ var getStatMethod = (fsImplementation) => {
886
+ if (fsImplementation) {
887
+ return bindFsMethod(fsImplementation.promises, "stat") ?? promisifyFsMethod(fsImplementation, "stat");
888
+ }
889
+ return bindFsMethod(import_node_fs3.default.promises, "stat");
890
+ };
891
+ var getStatSyncMethod2 = (fsImplementation) => bindFsMethod(fsImplementation, "statSync") ?? bindFsMethod(import_node_fs3.default, "statSync");
892
+ var isDirectory = async (path3, fsImplementation) => {
893
+ try {
894
+ const stats = await getStatMethod(fsImplementation)(path3);
895
+ return stats.isDirectory();
896
+ } catch {
897
+ return false;
898
+ }
899
+ };
900
+ var isDirectorySync = (path3, fsImplementation) => {
901
+ try {
902
+ const stats = getStatSyncMethod2(fsImplementation)(path3);
903
+ return stats.isDirectory();
904
+ } catch {
905
+ return false;
906
+ }
907
+ };
908
+ var normalizePathForDirectoryGlob = (filePath, cwd) => {
909
+ const path3 = isNegativePattern(filePath) ? filePath.slice(1) : filePath;
910
+ return import_node_path3.default.isAbsolute(path3) ? path3 : import_node_path3.default.join(cwd, path3);
911
+ };
912
+ var shouldExpandGlobstarDirectory = (pattern) => {
913
+ const match = pattern == null ? void 0 : pattern.match(/\*\*\/([^/]+)$/);
914
+ if (!match) {
915
+ return false;
916
+ }
917
+ const dirname = match[1];
918
+ const hasWildcards = /[*?[\]{}]/.test(dirname);
919
+ const hasExtension = import_node_path3.default.extname(dirname) && !dirname.startsWith(".");
920
+ return !hasWildcards && !hasExtension;
921
+ };
922
+ var getDirectoryGlob = ({ directoryPath, files, extensions }) => {
923
+ const extensionGlob = (extensions == null ? void 0 : extensions.length) > 0 ? `.${extensions.length > 1 ? `{${extensions.join(",")}}` : extensions[0]}` : "";
924
+ return files ? files.map((file) => import_node_path3.default.posix.join(directoryPath, `**/${import_node_path3.default.extname(file) ? file : `${file}${extensionGlob}`}`)) : [import_node_path3.default.posix.join(directoryPath, `**${extensionGlob ? `/*${extensionGlob}` : ""}`)];
925
+ };
926
+ var directoryToGlob = async (directoryPaths, {
927
+ cwd = import_node_process2.default.cwd(),
928
+ files,
929
+ extensions,
930
+ fs: fsImplementation
931
+ } = {}) => {
932
+ const globs = await Promise.all(directoryPaths.map(async (directoryPath) => {
933
+ const checkPattern = isNegativePattern(directoryPath) ? directoryPath.slice(1) : directoryPath;
934
+ if (shouldExpandGlobstarDirectory(checkPattern)) {
935
+ return getDirectoryGlob({ directoryPath, files, extensions });
936
+ }
937
+ const pathToCheck = normalizePathForDirectoryGlob(directoryPath, cwd);
938
+ return await isDirectory(pathToCheck, fsImplementation) ? getDirectoryGlob({ directoryPath, files, extensions }) : directoryPath;
939
+ }));
940
+ return globs.flat();
941
+ };
942
+ var directoryToGlobSync = (directoryPaths, {
943
+ cwd = import_node_process2.default.cwd(),
944
+ files,
945
+ extensions,
946
+ fs: fsImplementation
947
+ } = {}) => directoryPaths.flatMap((directoryPath) => {
948
+ const checkPattern = isNegativePattern(directoryPath) ? directoryPath.slice(1) : directoryPath;
949
+ if (shouldExpandGlobstarDirectory(checkPattern)) {
950
+ return getDirectoryGlob({ directoryPath, files, extensions });
951
+ }
952
+ const pathToCheck = normalizePathForDirectoryGlob(directoryPath, cwd);
953
+ return isDirectorySync(pathToCheck, fsImplementation) ? getDirectoryGlob({ directoryPath, files, extensions }) : directoryPath;
954
+ });
955
+ var toPatternsArray = (patterns) => {
956
+ patterns = [...new Set([patterns].flat())];
957
+ assertPatternsInput(patterns);
958
+ return patterns;
959
+ };
960
+ var checkCwdOption = (cwd, fsImplementation = import_node_fs3.default) => {
961
+ if (!cwd || !fsImplementation.statSync) {
962
+ return;
963
+ }
964
+ let stats;
965
+ try {
966
+ stats = fsImplementation.statSync(cwd);
967
+ } catch {
968
+ return;
969
+ }
970
+ if (!stats.isDirectory()) {
971
+ throw new Error(`The \`cwd\` option must be a path to a directory, got: ${cwd}`);
972
+ }
973
+ };
974
+ var normalizeOptions2 = (options = {}) => {
975
+ const ignore = options.ignore ? Array.isArray(options.ignore) ? options.ignore : [options.ignore] : [];
976
+ options = {
977
+ ...options,
978
+ ignore,
979
+ expandDirectories: options.expandDirectories ?? true,
980
+ cwd: (0, import_node2.toPath)(options.cwd)
981
+ };
982
+ checkCwdOption(options.cwd, options.fs);
983
+ return options;
984
+ };
985
+ var normalizeArguments = (function_) => async (patterns, options) => function_(toPatternsArray(patterns), normalizeOptions2(options));
986
+ var normalizeArgumentsSync = (function_) => (patterns, options) => function_(toPatternsArray(patterns), normalizeOptions2(options));
987
+ var getIgnoreFilesPatterns = (options) => {
988
+ const { ignoreFiles, gitignore } = options;
989
+ const patterns = ignoreFiles ? toPatternsArray(ignoreFiles) : [];
990
+ if (gitignore) {
991
+ patterns.push(GITIGNORE_FILES_PATTERN);
992
+ }
993
+ return patterns;
994
+ };
995
+ var isPathIgnored = (matcher, globalMatcher, path3) => {
996
+ const globalResult = globalMatcher ? globalMatcher(path3) : void 0;
997
+ const result = matcher ? matcher(path3) : void 0;
998
+ if (result == null ? void 0 : result.unignored) {
999
+ return false;
1000
+ }
1001
+ return Boolean((result == null ? void 0 : result.ignored) || (globalResult == null ? void 0 : globalResult.ignored));
1002
+ };
1003
+ var hasIgnoredAncestorDirectory = (matcher, globalMatcher, file) => {
1004
+ let currentPath = file;
1005
+ while (true) {
1006
+ const parentDirectory = import_node_path3.default.dirname(currentPath);
1007
+ if (parentDirectory === currentPath) {
1008
+ return false;
1009
+ }
1010
+ if (isPathIgnored(matcher, globalMatcher, `${parentDirectory}${import_node_path3.default.sep}`)) {
1011
+ return true;
1012
+ }
1013
+ currentPath = parentDirectory;
1014
+ }
1015
+ };
1016
+ var combinePredicate = (matcher, globalMatcher) => {
1017
+ if (!matcher && !globalMatcher) {
1018
+ return false;
1019
+ }
1020
+ return (file) => {
1021
+ const result = matcher ? matcher(file) : void 0;
1022
+ if (result == null ? void 0 : result.unignored) {
1023
+ const globalResult = globalMatcher ? globalMatcher(file) : void 0;
1024
+ return (globalResult == null ? void 0 : globalResult.ignored) && hasIgnoredAncestorDirectory(matcher, globalMatcher, file);
1025
+ }
1026
+ return isPathIgnored(matcher, globalMatcher, file);
1027
+ };
1028
+ };
1029
+ var buildIgnoreFilterResult = (options, cwd, { patterns, matcher, usingGitRoot }, globalMatcher, createFilter) => {
1030
+ const finalPredicate = combinePredicate(matcher, globalMatcher);
1031
+ const patternsForFastGlob = convertPatternsForFastGlob(patterns, usingGitRoot, normalizeDirectoryPatternForFastGlob);
1032
+ return {
1033
+ options: {
1034
+ ...options,
1035
+ ignore: [...options.ignore, ...patternsForFastGlob]
1036
+ },
1037
+ filter: createFilter(finalPredicate, cwd, options.fs)
1038
+ };
1039
+ };
1040
+ var applyIgnoreFilesAndGetFilter = async (options) => {
1041
+ const cwd = options.cwd ?? import_node_process2.default.cwd();
1042
+ const ignoreFilesPatterns = getIgnoreFilesPatterns(options);
1043
+ const globalIgnoreFile = options.globalGitignore ? await getGlobalGitignoreFileAsync(options) : void 0;
1044
+ if (ignoreFilesPatterns.length === 0 && !globalIgnoreFile) {
1045
+ return {
1046
+ options,
1047
+ filter: createFilterFunctionAsync(false, cwd, options.fs)
1048
+ };
1049
+ }
1050
+ const includeParentIgnoreFiles = options.gitignore === true;
1051
+ const ignoreResult = ignoreFilesPatterns.length > 0 ? await getIgnorePatternsAndPredicate(ignoreFilesPatterns, options, includeParentIgnoreFiles) : { patterns: [], matcher: false, usingGitRoot: false };
1052
+ const globalGitRoot = globalIgnoreFile ? await findGitRoot(cwd, options.fs) : void 0;
1053
+ const globalMatcher = globalIgnoreFile ? buildGlobalMatcher(globalIgnoreFile, cwd, globalGitRoot ?? cwd) : void 0;
1054
+ return buildIgnoreFilterResult(options, cwd, ignoreResult, globalMatcher, createFilterFunctionAsync);
1055
+ };
1056
+ var applyIgnoreFilesAndGetFilterSync = (options) => {
1057
+ const cwd = options.cwd ?? import_node_process2.default.cwd();
1058
+ const ignoreFilesPatterns = getIgnoreFilesPatterns(options);
1059
+ const globalIgnoreFile = options.globalGitignore ? getGlobalGitignoreFile(options) : void 0;
1060
+ if (ignoreFilesPatterns.length === 0 && !globalIgnoreFile) {
1061
+ return {
1062
+ options,
1063
+ filter: createFilterFunction(false, cwd, options.fs)
1064
+ };
1065
+ }
1066
+ const includeParentIgnoreFiles = options.gitignore === true;
1067
+ const ignoreResult = ignoreFilesPatterns.length > 0 ? getIgnorePatternsAndPredicateSync(ignoreFilesPatterns, options, includeParentIgnoreFiles) : { patterns: [], matcher: false, usingGitRoot: false };
1068
+ const globalGitRoot = globalIgnoreFile ? findGitRootSync(cwd, options.fs) : void 0;
1069
+ const globalMatcher = globalIgnoreFile ? buildGlobalMatcher(globalIgnoreFile, cwd, globalGitRoot ?? cwd) : void 0;
1070
+ return buildIgnoreFilterResult(options, cwd, ignoreResult, globalMatcher, createFilterFunction);
1071
+ };
1072
+ var assertGlobalGitignoreSyncSupport = (options) => {
1073
+ if (options.globalGitignore && options.fs && !options.fs.statSync) {
1074
+ throw new Error("The `globalGitignore` option in `globbySync()` requires `fs.statSync` when a custom `fs` is provided.");
1075
+ }
1076
+ };
1077
+ var globalGitignoreAsyncStatErrorMessage = "The `globalGitignore` option in `globby()` and `globbyStream()` requires `fs.promises.stat` or `fs.stat` when a custom `fs` is provided.";
1078
+ var assertGlobalGitignoreAsyncSupport = (options) => {
1079
+ var _a;
1080
+ if (!options.globalGitignore || !options.fs) {
1081
+ return;
1082
+ }
1083
+ if (!((_a = options.fs.promises) == null ? void 0 : _a.stat) && !options.fs.stat) {
1084
+ throw new Error(globalGitignoreAsyncStatErrorMessage);
1085
+ }
1086
+ };
1087
+ var createPathResolver = (cwd) => {
1088
+ const basePath = cwd || import_node_process2.default.cwd();
1089
+ const pathCache = /* @__PURE__ */ new Map();
1090
+ return (pathKey) => {
1091
+ let absolutePath = pathCache.get(pathKey);
1092
+ if (absolutePath === void 0) {
1093
+ if (pathCache.size > 1e4) {
1094
+ pathCache.clear();
1095
+ }
1096
+ absolutePath = import_node_path3.default.isAbsolute(pathKey) ? pathKey : import_node_path3.default.resolve(basePath, pathKey);
1097
+ pathCache.set(pathKey, absolutePath);
1098
+ }
1099
+ return absolutePath;
1100
+ };
1101
+ };
1102
+ var createAsyncDirectoryCheck = (fsMethod) => {
1103
+ const directoryCache = /* @__PURE__ */ new Map();
1104
+ return async (absolutePath) => {
1105
+ let isDirectory2 = directoryCache.get(absolutePath);
1106
+ if (isDirectory2 !== void 0) {
1107
+ return isDirectory2;
1108
+ }
1109
+ try {
1110
+ const stats = await (fsMethod == null ? void 0 : fsMethod(absolutePath));
1111
+ isDirectory2 = Boolean(stats == null ? void 0 : stats.isDirectory());
1112
+ } catch {
1113
+ isDirectory2 = false;
1114
+ }
1115
+ if (directoryCache.size > 1e4) {
1116
+ directoryCache.clear();
1117
+ }
1118
+ directoryCache.set(absolutePath, isDirectory2);
1119
+ return isDirectory2;
1120
+ };
1121
+ };
1122
+ var createDirectoryCheck = (fsMethod) => {
1123
+ const directoryCache = /* @__PURE__ */ new Map();
1124
+ return (absolutePath) => {
1125
+ var _a;
1126
+ let isDirectory2 = directoryCache.get(absolutePath);
1127
+ if (isDirectory2 !== void 0) {
1128
+ return isDirectory2;
1129
+ }
1130
+ try {
1131
+ isDirectory2 = Boolean((_a = fsMethod == null ? void 0 : fsMethod(absolutePath)) == null ? void 0 : _a.isDirectory());
1132
+ } catch {
1133
+ isDirectory2 = false;
1134
+ }
1135
+ if (directoryCache.size > 1e4) {
1136
+ directoryCache.clear();
1137
+ }
1138
+ directoryCache.set(absolutePath, isDirectory2);
1139
+ return isDirectory2;
1140
+ };
1141
+ };
1142
+ var createFilterFunctionAsync = (isIgnored, cwd, fsImplementation) => {
1143
+ const resolveAbsolutePath = createPathResolver(cwd);
1144
+ const isDirectoryEntry = createAsyncDirectoryCheck(getStatMethod(fsImplementation));
1145
+ return async (fastGlobResult) => {
1146
+ if (!isIgnored) {
1147
+ return true;
1148
+ }
1149
+ const absolutePath = resolveAbsolutePath(import_node_path3.default.normalize(fastGlobResult.path ?? fastGlobResult));
1150
+ if (isIgnored(absolutePath)) {
1151
+ return false;
1152
+ }
1153
+ return !(await isDirectoryEntry(absolutePath) && isIgnored(`${absolutePath}${import_node_path3.default.sep}`));
1154
+ };
1155
+ };
1156
+ var createFilterFunction = (isIgnored, cwd, fsImplementation) => {
1157
+ const seen = /* @__PURE__ */ new Set();
1158
+ const resolveAbsolutePath = createPathResolver(cwd);
1159
+ const isDirectoryEntry = createDirectoryCheck(getStatSyncMethod2(fsImplementation));
1160
+ return (fastGlobResult) => {
1161
+ const pathKey = import_node_path3.default.normalize(fastGlobResult.path ?? fastGlobResult);
1162
+ if (seen.has(pathKey)) {
1163
+ return false;
1164
+ }
1165
+ if (isIgnored) {
1166
+ const absolutePath = resolveAbsolutePath(pathKey);
1167
+ if (isIgnored(absolutePath)) {
1168
+ return false;
1169
+ }
1170
+ if (isDirectoryEntry(absolutePath) && isIgnored(`${absolutePath}${import_node_path3.default.sep}`)) {
1171
+ return false;
1172
+ }
1173
+ }
1174
+ seen.add(pathKey);
1175
+ return true;
1176
+ };
1177
+ };
1178
+ var unionFastGlobResults = (results, filter) => results.flat().filter((fastGlobResult) => filter(fastGlobResult));
1179
+ var unionFastGlobResultsAsync = async (results, filter) => {
1180
+ results = results.flat();
1181
+ const matches = await Promise.all(results.map((fastGlobResult) => filter(fastGlobResult)));
1182
+ const seen = /* @__PURE__ */ new Set();
1183
+ return results.filter((fastGlobResult, index) => {
1184
+ if (!matches[index]) {
1185
+ return false;
1186
+ }
1187
+ const pathKey = import_node_path3.default.normalize(fastGlobResult.path ?? fastGlobResult);
1188
+ if (seen.has(pathKey)) {
1189
+ return false;
1190
+ }
1191
+ seen.add(pathKey);
1192
+ return true;
1193
+ });
1194
+ };
1195
+ var convertNegativePatterns = (patterns, options) => {
1196
+ if (patterns.length > 0 && patterns.every((pattern) => isNegativePattern(pattern))) {
1197
+ if (options.expandNegationOnlyPatterns === false) {
1198
+ return [];
1199
+ }
1200
+ patterns = ["**/*", ...patterns];
1201
+ }
1202
+ const positiveAbsolutePathPrefixes = [];
1203
+ let hasRelativePositivePattern = false;
1204
+ const normalizedPatterns = [];
1205
+ for (const pattern of patterns) {
1206
+ if (isNegativePattern(pattern)) {
1207
+ normalizedPatterns.push(`!${normalizeNegativePattern(pattern.slice(1), positiveAbsolutePathPrefixes, hasRelativePositivePattern)}`);
1208
+ continue;
1209
+ }
1210
+ normalizedPatterns.push(pattern);
1211
+ const staticAbsolutePathPrefix = getStaticAbsolutePathPrefix(pattern);
1212
+ if (staticAbsolutePathPrefix === void 0) {
1213
+ hasRelativePositivePattern = true;
1214
+ continue;
1215
+ }
1216
+ positiveAbsolutePathPrefixes.push(staticAbsolutePathPrefix);
1217
+ }
1218
+ patterns = normalizedPatterns;
1219
+ const tasks = [];
1220
+ while (patterns.length > 0) {
1221
+ const index = patterns.findIndex((pattern) => isNegativePattern(pattern));
1222
+ if (index === -1) {
1223
+ tasks.push({ patterns, options });
1224
+ break;
1225
+ }
1226
+ const ignorePattern = patterns[index].slice(1);
1227
+ for (const task of tasks) {
1228
+ task.options.ignore.push(ignorePattern);
1229
+ }
1230
+ if (index !== 0) {
1231
+ tasks.push({
1232
+ patterns: patterns.slice(0, index),
1233
+ options: {
1234
+ ...options,
1235
+ ignore: [
1236
+ ...options.ignore,
1237
+ ignorePattern
1238
+ ]
1239
+ }
1240
+ });
1241
+ }
1242
+ patterns = patterns.slice(index + 1);
1243
+ }
1244
+ return tasks;
1245
+ };
1246
+ var applyParentDirectoryIgnoreAdjustments = (tasks) => tasks.map((task) => ({
1247
+ patterns: task.patterns,
1248
+ options: {
1249
+ ...task.options,
1250
+ ignore: adjustIgnorePatternsForParentDirectories(task.patterns, task.options.ignore)
1251
+ }
1252
+ }));
1253
+ var normalizeExpandDirectoriesOption = (options, cwd) => ({
1254
+ ...cwd ? { cwd } : {},
1255
+ ...Array.isArray(options) ? { files: options } : options
1256
+ });
1257
+ var generateTasks = async (patterns, options) => {
1258
+ const globTasks = convertNegativePatterns(patterns, options);
1259
+ const { cwd, expandDirectories, fs: fsImplementation } = options;
1260
+ if (!expandDirectories) {
1261
+ return applyParentDirectoryIgnoreAdjustments(globTasks);
1262
+ }
1263
+ const directoryToGlobOptions = {
1264
+ ...normalizeExpandDirectoriesOption(expandDirectories, cwd),
1265
+ fs: fsImplementation
1266
+ };
1267
+ return Promise.all(globTasks.map(async (task) => {
1268
+ let { patterns: patterns2, options: options2 } = task;
1269
+ [
1270
+ patterns2,
1271
+ options2.ignore
1272
+ ] = await Promise.all([
1273
+ directoryToGlob(patterns2, directoryToGlobOptions),
1274
+ directoryToGlob(options2.ignore, { cwd, fs: fsImplementation })
1275
+ ]);
1276
+ options2.ignore = adjustIgnorePatternsForParentDirectories(patterns2, options2.ignore);
1277
+ return { patterns: patterns2, options: options2 };
1278
+ }));
1279
+ };
1280
+ var generateTasksSync = (patterns, options) => {
1281
+ const globTasks = convertNegativePatterns(patterns, options);
1282
+ const { cwd, expandDirectories, fs: fsImplementation } = options;
1283
+ if (!expandDirectories) {
1284
+ return applyParentDirectoryIgnoreAdjustments(globTasks);
1285
+ }
1286
+ const directoryToGlobSyncOptions = {
1287
+ ...normalizeExpandDirectoriesOption(expandDirectories, cwd),
1288
+ fs: fsImplementation
1289
+ };
1290
+ return globTasks.map((task) => {
1291
+ let { patterns: patterns2, options: options2 } = task;
1292
+ patterns2 = directoryToGlobSync(patterns2, directoryToGlobSyncOptions);
1293
+ options2.ignore = directoryToGlobSync(options2.ignore, { cwd, fs: fsImplementation });
1294
+ options2.ignore = adjustIgnorePatternsForParentDirectories(patterns2, options2.ignore);
1295
+ return { patterns: patterns2, options: options2 };
1296
+ });
1297
+ };
1298
+ var globby = normalizeArguments(async (patterns, options) => {
1299
+ assertGlobalGitignoreAsyncSupport(options);
1300
+ const { options: modifiedOptions, filter } = await applyIgnoreFilesAndGetFilter(options);
1301
+ const tasks = await generateTasks(patterns, modifiedOptions);
1302
+ const results = await Promise.all(tasks.map((task) => (0, import_fast_glob3.default)(task.patterns, task.options)));
1303
+ return unionFastGlobResultsAsync(results, filter);
1304
+ });
1305
+ var globbySync = normalizeArgumentsSync((patterns, options) => {
1306
+ assertGlobalGitignoreSyncSupport(options);
1307
+ const { options: modifiedOptions, filter } = applyIgnoreFilesAndGetFilterSync(options);
1308
+ const tasks = generateTasksSync(patterns, modifiedOptions);
1309
+ const results = tasks.map((task) => import_fast_glob3.default.sync(task.patterns, task.options));
1310
+ return unionFastGlobResults(results, filter);
1311
+ });
1312
+ var globbyStream = normalizeArgumentsSync((patterns, options) => {
1313
+ assertGlobalGitignoreAsyncSupport(options);
1314
+ const seen = /* @__PURE__ */ new Set();
1315
+ const stream = import_node_stream.Readable.from((async function* () {
1316
+ const { options: modifiedOptions, filter } = await applyIgnoreFilesAndGetFilter(options);
1317
+ const tasks = await generateTasks(patterns, modifiedOptions);
1318
+ if (tasks.length === 0) {
1319
+ return;
1320
+ }
1321
+ const streams = tasks.map((task) => import_fast_glob3.default.stream(task.patterns, task.options));
1322
+ for await (const fastGlobResult of (0, import_sindresorhus_merge_streams.default)(streams)) {
1323
+ const pathKey = import_node_path3.default.normalize(fastGlobResult.path ?? fastGlobResult);
1324
+ if (!seen.has(pathKey) && await filter(fastGlobResult)) {
1325
+ seen.add(pathKey);
1326
+ yield fastGlobResult;
1327
+ }
1328
+ }
1329
+ })());
1330
+ return stream;
1331
+ });
1332
+ var isDynamicPattern = normalizeArgumentsSync((patterns, options) => patterns.some((pattern) => import_fast_glob3.default.isDynamicPattern(pattern, options)));
1333
+ var generateGlobTasks = normalizeArguments(generateTasks);
1334
+ var generateGlobTasksSync = normalizeArgumentsSync(generateTasksSync);
1335
+ var { convertPathToPattern } = import_fast_glob3.default;
1336
+ // Annotate the CommonJS export names for ESM import in node:
1337
+ 0 && (module.exports = {
1338
+ convertPathToPattern,
1339
+ generateGlobTasks,
1340
+ generateGlobTasksSync,
1341
+ globby,
1342
+ globbyStream,
1343
+ globbySync,
1344
+ isDynamicPattern,
1345
+ isGitIgnored,
1346
+ isGitIgnoredSync,
1347
+ isIgnoredByIgnoreFiles,
1348
+ isIgnoredByIgnoreFilesSync
1349
+ });