@lage-run/globby 13.0.1 → 13.0.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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  CommonJS wrapper of [`globby`](https://www.npmjs.com/package/globby) with caching support and all dependencies bundled.
2
2
 
3
- This should follow the newest version of `globby` compatible with Lage's minimum Node version. As of writing, that's Node 14 and `globby` 13.
3
+ This should follow the newest version of `globby` compatible with Lage's minimum Node version. As of writing, that's Node 16 and `globby` 13.
package/dist/index.d.ts CHANGED
@@ -240,5 +240,11 @@ export interface Options extends FastGlobOptionsWithoutCwd {
240
240
  }
241
241
  export declare function globAsync(patterns: string[], options?: Options): Promise<string[]>;
242
242
  export declare function glob(patterns: string[], options?: Options): string[];
243
+ /**
244
+ * Uncached variants — use these when the file system may change between calls
245
+ * (e.g. cache storage collecting build outputs after a task runs).
246
+ */
247
+ export declare function globAsyncUncached(patterns: string[], options?: Options): Promise<string[]>;
248
+ export declare function globUncached(patterns: string[], options?: Options): string[];
243
249
 
244
250
  export {};
package/dist/index.js CHANGED
@@ -1533,6 +1533,7 @@ var require_constants2 = __commonJS({
1533
1533
  var path2 = require("path");
1534
1534
  var WIN_SLASH = "\\\\/";
1535
1535
  var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
1536
+ var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
1536
1537
  var DOT_LITERAL = "\\.";
1537
1538
  var PLUS_LITERAL = "\\+";
1538
1539
  var QMARK_LITERAL = "\\?";
@@ -1580,6 +1581,7 @@ var require_constants2 = __commonJS({
1580
1581
  END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
1581
1582
  };
1582
1583
  var POSIX_REGEX_SOURCE = {
1584
+ __proto__: null,
1583
1585
  alnum: "a-zA-Z0-9",
1584
1586
  alpha: "a-zA-Z",
1585
1587
  ascii: "\\x00-\\x7F",
@@ -1596,6 +1598,7 @@ var require_constants2 = __commonJS({
1596
1598
  xdigit: "A-Fa-f0-9"
1597
1599
  };
1598
1600
  module2.exports = {
1601
+ DEFAULT_MAX_EXTGLOB_RECURSION,
1599
1602
  MAX_LENGTH: 1024 * 64,
1600
1603
  POSIX_REGEX_SOURCE,
1601
1604
  // regular expressions
@@ -1607,6 +1610,7 @@ var require_constants2 = __commonJS({
1607
1610
  REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
1608
1611
  // Replace globs with equivalent patterns to reduce parsing time.
1609
1612
  REPLACEMENTS: {
1613
+ __proto__: null,
1610
1614
  "***": "*",
1611
1615
  "**/**": "**",
1612
1616
  "**/**/**": "**"
@@ -2143,6 +2147,213 @@ var require_parse2 = __commonJS({
2143
2147
  var syntaxError = (type, char) => {
2144
2148
  return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
2145
2149
  };
2150
+ var splitTopLevel = (input) => {
2151
+ const parts = [];
2152
+ let bracket = 0;
2153
+ let paren = 0;
2154
+ let quote = 0;
2155
+ let value = "";
2156
+ let escaped = false;
2157
+ for (const ch of input) {
2158
+ if (escaped === true) {
2159
+ value += ch;
2160
+ escaped = false;
2161
+ continue;
2162
+ }
2163
+ if (ch === "\\") {
2164
+ value += ch;
2165
+ escaped = true;
2166
+ continue;
2167
+ }
2168
+ if (ch === '"') {
2169
+ quote = quote === 1 ? 0 : 1;
2170
+ value += ch;
2171
+ continue;
2172
+ }
2173
+ if (quote === 0) {
2174
+ if (ch === "[") {
2175
+ bracket++;
2176
+ } else if (ch === "]" && bracket > 0) {
2177
+ bracket--;
2178
+ } else if (bracket === 0) {
2179
+ if (ch === "(") {
2180
+ paren++;
2181
+ } else if (ch === ")" && paren > 0) {
2182
+ paren--;
2183
+ } else if (ch === "|" && paren === 0) {
2184
+ parts.push(value);
2185
+ value = "";
2186
+ continue;
2187
+ }
2188
+ }
2189
+ }
2190
+ value += ch;
2191
+ }
2192
+ parts.push(value);
2193
+ return parts;
2194
+ };
2195
+ var isPlainBranch = (branch) => {
2196
+ let escaped = false;
2197
+ for (const ch of branch) {
2198
+ if (escaped === true) {
2199
+ escaped = false;
2200
+ continue;
2201
+ }
2202
+ if (ch === "\\") {
2203
+ escaped = true;
2204
+ continue;
2205
+ }
2206
+ if (/[?*+@!()[\]{}]/.test(ch)) {
2207
+ return false;
2208
+ }
2209
+ }
2210
+ return true;
2211
+ };
2212
+ var normalizeSimpleBranch = (branch) => {
2213
+ let value = branch.trim();
2214
+ let changed = true;
2215
+ while (changed === true) {
2216
+ changed = false;
2217
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
2218
+ value = value.slice(2, -1);
2219
+ changed = true;
2220
+ }
2221
+ }
2222
+ if (!isPlainBranch(value)) {
2223
+ return;
2224
+ }
2225
+ return value.replace(/\\(.)/g, "$1");
2226
+ };
2227
+ var hasRepeatedCharPrefixOverlap = (branches) => {
2228
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
2229
+ for (let i = 0; i < values.length; i++) {
2230
+ for (let j = i + 1; j < values.length; j++) {
2231
+ const a = values[i];
2232
+ const b = values[j];
2233
+ const char = a[0];
2234
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
2235
+ continue;
2236
+ }
2237
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
2238
+ return true;
2239
+ }
2240
+ }
2241
+ }
2242
+ return false;
2243
+ };
2244
+ var parseRepeatedExtglob = (pattern, requireEnd = true) => {
2245
+ if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
2246
+ return;
2247
+ }
2248
+ let bracket = 0;
2249
+ let paren = 0;
2250
+ let quote = 0;
2251
+ let escaped = false;
2252
+ for (let i = 1; i < pattern.length; i++) {
2253
+ const ch = pattern[i];
2254
+ if (escaped === true) {
2255
+ escaped = false;
2256
+ continue;
2257
+ }
2258
+ if (ch === "\\") {
2259
+ escaped = true;
2260
+ continue;
2261
+ }
2262
+ if (ch === '"') {
2263
+ quote = quote === 1 ? 0 : 1;
2264
+ continue;
2265
+ }
2266
+ if (quote === 1) {
2267
+ continue;
2268
+ }
2269
+ if (ch === "[") {
2270
+ bracket++;
2271
+ continue;
2272
+ }
2273
+ if (ch === "]" && bracket > 0) {
2274
+ bracket--;
2275
+ continue;
2276
+ }
2277
+ if (bracket > 0) {
2278
+ continue;
2279
+ }
2280
+ if (ch === "(") {
2281
+ paren++;
2282
+ continue;
2283
+ }
2284
+ if (ch === ")") {
2285
+ paren--;
2286
+ if (paren === 0) {
2287
+ if (requireEnd === true && i !== pattern.length - 1) {
2288
+ return;
2289
+ }
2290
+ return {
2291
+ type: pattern[0],
2292
+ body: pattern.slice(2, i),
2293
+ end: i
2294
+ };
2295
+ }
2296
+ }
2297
+ }
2298
+ };
2299
+ var getStarExtglobSequenceOutput = (pattern) => {
2300
+ let index = 0;
2301
+ const chars = [];
2302
+ while (index < pattern.length) {
2303
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
2304
+ if (!match || match.type !== "*") {
2305
+ return;
2306
+ }
2307
+ const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
2308
+ if (branches.length !== 1) {
2309
+ return;
2310
+ }
2311
+ const branch = normalizeSimpleBranch(branches[0]);
2312
+ if (!branch || branch.length !== 1) {
2313
+ return;
2314
+ }
2315
+ chars.push(branch);
2316
+ index += match.end + 1;
2317
+ }
2318
+ if (chars.length < 1) {
2319
+ return;
2320
+ }
2321
+ const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
2322
+ return `${source}*`;
2323
+ };
2324
+ var repeatedExtglobRecursion = (pattern) => {
2325
+ let depth = 0;
2326
+ let value = pattern.trim();
2327
+ let match = parseRepeatedExtglob(value);
2328
+ while (match) {
2329
+ depth++;
2330
+ value = match.body.trim();
2331
+ match = parseRepeatedExtglob(value);
2332
+ }
2333
+ return depth;
2334
+ };
2335
+ var analyzeRepeatedExtglob = (body, options) => {
2336
+ if (options.maxExtglobRecursion === false) {
2337
+ return { risky: false };
2338
+ }
2339
+ const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
2340
+ const branches = splitTopLevel(body).map((branch) => branch.trim());
2341
+ if (branches.length > 1) {
2342
+ if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
2343
+ return { risky: true };
2344
+ }
2345
+ }
2346
+ for (const branch of branches) {
2347
+ const safeOutput = getStarExtglobSequenceOutput(branch);
2348
+ if (safeOutput) {
2349
+ return { risky: true, safeOutput };
2350
+ }
2351
+ if (repeatedExtglobRecursion(branch) > max) {
2352
+ return { risky: true };
2353
+ }
2354
+ }
2355
+ return { risky: false };
2356
+ };
2146
2357
  var parse = (input, options) => {
2147
2358
  if (typeof input !== "string") {
2148
2359
  throw new TypeError("Expected a string");
@@ -2274,6 +2485,8 @@ var require_parse2 = __commonJS({
2274
2485
  token.prev = prev;
2275
2486
  token.parens = state.parens;
2276
2487
  token.output = state.output;
2488
+ token.startIndex = state.index;
2489
+ token.tokensIndex = tokens.length;
2277
2490
  const output = (opts.capture ? "(" : "") + token.open;
2278
2491
  increment("parens");
2279
2492
  push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
@@ -2281,6 +2494,26 @@ var require_parse2 = __commonJS({
2281
2494
  extglobs.push(token);
2282
2495
  };
2283
2496
  const extglobClose = (token) => {
2497
+ const literal = input.slice(token.startIndex, state.index + 1);
2498
+ const body = input.slice(token.startIndex + 2, state.index);
2499
+ const analysis = analyzeRepeatedExtglob(body, opts);
2500
+ if ((token.type === "plus" || token.type === "star") && analysis.risky) {
2501
+ const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
2502
+ const open = tokens[token.tokensIndex];
2503
+ open.type = "text";
2504
+ open.value = literal;
2505
+ open.output = safeOutput || utils.escapeRegex(literal);
2506
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
2507
+ tokens[i].value = "";
2508
+ tokens[i].output = "";
2509
+ delete tokens[i].suffix;
2510
+ }
2511
+ state.output = token.output + open.output;
2512
+ state.backtrack = true;
2513
+ push({ type: "paren", extglob: true, value, output: "" });
2514
+ decrement("parens");
2515
+ return;
2516
+ }
2284
2517
  let output = token.close + (opts.capture ? ")" : "");
2285
2518
  let rest;
2286
2519
  if (token.type === "negate") {
@@ -6038,7 +6271,9 @@ var require_ignore = __commonJS({
6038
6271
  var index_exports = {};
6039
6272
  __export(index_exports, {
6040
6273
  glob: () => glob,
6041
- globAsync: () => globAsync
6274
+ globAsync: () => globAsync,
6275
+ globAsyncUncached: () => globAsyncUncached,
6276
+ globUncached: () => globUncached
6042
6277
  });
6043
6278
  module.exports = __toCommonJS(index_exports);
6044
6279
 
@@ -6330,10 +6565,18 @@ function glob(patterns, options) {
6330
6565
  }
6331
6566
  return cache.get(key) || [];
6332
6567
  }
6568
+ async function globAsyncUncached(patterns, options) {
6569
+ return globby(patterns, options);
6570
+ }
6571
+ function globUncached(patterns, options) {
6572
+ return globbySync(patterns, options);
6573
+ }
6333
6574
  // Annotate the CommonJS export names for ESM import in node:
6334
6575
  0 && (module.exports = {
6335
6576
  glob,
6336
- globAsync
6577
+ globAsync,
6578
+ globAsyncUncached,
6579
+ globUncached
6337
6580
  });
6338
6581
  /*! Bundled license information:
6339
6582
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lage-run/globby",
3
- "version": "13.0.1",
3
+ "version": "13.0.2",
4
4
  "license": "MIT",
5
5
  "description": "Bundled CJS wrapper of globby with caching support",
6
6
  "main": "dist/index.js",