e2e-ai 1.4.3 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,7 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- loadAgent
4
- } from "./cli-98db6h2q.js";
3
+ banner,
4
+ error,
5
+ header,
6
+ info,
7
+ loadAgent,
8
+ require_picocolors,
9
+ runStage1,
10
+ setVerbose,
11
+ step,
12
+ success,
13
+ summary,
14
+ verbose,
15
+ warn
16
+ } from "./cli-h86f3dv5.js";
5
17
  import {
6
18
  getPackageRoot,
7
19
  getProjectRoot,
@@ -160,9 +172,9 @@ var require_main = __commonJS((exports, module) => {
160
172
  const attrs = _instructions(result, key);
161
173
  decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
162
174
  break;
163
- } catch (error) {
175
+ } catch (error2) {
164
176
  if (i + 1 >= length) {
165
- throw error;
177
+ throw error2;
166
178
  }
167
179
  }
168
180
  }
@@ -190,13 +202,13 @@ var require_main = __commonJS((exports, module) => {
190
202
  let uri;
191
203
  try {
192
204
  uri = new URL(dotenvKey);
193
- } catch (error) {
194
- if (error.code === "ERR_INVALID_URL") {
205
+ } catch (error2) {
206
+ if (error2.code === "ERR_INVALID_URL") {
195
207
  const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
196
208
  err.code = "INVALID_DOTENV_KEY";
197
209
  throw err;
198
210
  }
199
- throw error;
211
+ throw error2;
200
212
  }
201
213
  const key = uri.password;
202
214
  if (!key) {
@@ -342,10 +354,10 @@ var require_main = __commonJS((exports, module) => {
342
354
  const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
343
355
  aesgcm.setAuthTag(authTag);
344
356
  return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
345
- } catch (error) {
346
- const isRange = error instanceof RangeError;
347
- const invalidKeyLength = error.message === "Invalid key length";
348
- const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
357
+ } catch (error2) {
358
+ const isRange = error2 instanceof RangeError;
359
+ const invalidKeyLength = error2.message === "Invalid key length";
360
+ const decryptionFailed = error2.message === "Unsupported state or unable to authenticate data";
349
361
  if (isRange || invalidKeyLength) {
350
362
  const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
351
363
  err.code = "INVALID_DOTENV_KEY";
@@ -355,7 +367,7 @@ var require_main = __commonJS((exports, module) => {
355
367
  err.code = "DECRYPTION_FAILED";
356
368
  throw err;
357
369
  } else {
358
- throw error;
370
+ throw error2;
359
371
  }
360
372
  }
361
373
  }
@@ -2320,11 +2332,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2320
2332
  }
2321
2333
  _getOutputContext(contextOptions) {
2322
2334
  contextOptions = contextOptions || {};
2323
- const error = !!contextOptions.error;
2335
+ const error2 = !!contextOptions.error;
2324
2336
  let baseWrite;
2325
2337
  let hasColors;
2326
2338
  let helpWidth;
2327
- if (error) {
2339
+ if (error2) {
2328
2340
  baseWrite = (str) => this._outputConfiguration.writeErr(str);
2329
2341
  hasColors = this._outputConfiguration.getErrHasColors();
2330
2342
  helpWidth = this._outputConfiguration.getErrHelpWidth();
@@ -2338,7 +2350,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2338
2350
  str = this._outputConfiguration.stripColor(str);
2339
2351
  return baseWrite(str);
2340
2352
  };
2341
- return { error, write, hasColors, helpWidth };
2353
+ return { error: error2, write, hasColors, helpWidth };
2342
2354
  }
2343
2355
  outputHelp(contextOptions) {
2344
2356
  let deprecatedCallback;
@@ -2490,76 +2502,6 @@ var require_commander = __commonJS((exports) => {
2490
2502
  exports.InvalidOptionArgumentError = InvalidArgumentError;
2491
2503
  });
2492
2504
 
2493
- // node_modules/picocolors/picocolors.js
2494
- var require_picocolors = __commonJS((exports, module) => {
2495
- var p = process || {};
2496
- var argv = p.argv || [];
2497
- var env = p.env || {};
2498
- var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
2499
- var formatter = (open, close, replace = open) => (input) => {
2500
- let string = "" + input, index = string.indexOf(close, open.length);
2501
- return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
2502
- };
2503
- var replaceClose = (string, close, replace, index) => {
2504
- let result = "", cursor = 0;
2505
- do {
2506
- result += string.substring(cursor, index) + replace;
2507
- cursor = index + close.length;
2508
- index = string.indexOf(close, cursor);
2509
- } while (~index);
2510
- return result + string.substring(cursor);
2511
- };
2512
- var createColors = (enabled = isColorSupported) => {
2513
- let f = enabled ? formatter : () => String;
2514
- return {
2515
- isColorSupported: enabled,
2516
- reset: f("\x1B[0m", "\x1B[0m"),
2517
- bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
2518
- dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
2519
- italic: f("\x1B[3m", "\x1B[23m"),
2520
- underline: f("\x1B[4m", "\x1B[24m"),
2521
- inverse: f("\x1B[7m", "\x1B[27m"),
2522
- hidden: f("\x1B[8m", "\x1B[28m"),
2523
- strikethrough: f("\x1B[9m", "\x1B[29m"),
2524
- black: f("\x1B[30m", "\x1B[39m"),
2525
- red: f("\x1B[31m", "\x1B[39m"),
2526
- green: f("\x1B[32m", "\x1B[39m"),
2527
- yellow: f("\x1B[33m", "\x1B[39m"),
2528
- blue: f("\x1B[34m", "\x1B[39m"),
2529
- magenta: f("\x1B[35m", "\x1B[39m"),
2530
- cyan: f("\x1B[36m", "\x1B[39m"),
2531
- white: f("\x1B[37m", "\x1B[39m"),
2532
- gray: f("\x1B[90m", "\x1B[39m"),
2533
- bgBlack: f("\x1B[40m", "\x1B[49m"),
2534
- bgRed: f("\x1B[41m", "\x1B[49m"),
2535
- bgGreen: f("\x1B[42m", "\x1B[49m"),
2536
- bgYellow: f("\x1B[43m", "\x1B[49m"),
2537
- bgBlue: f("\x1B[44m", "\x1B[49m"),
2538
- bgMagenta: f("\x1B[45m", "\x1B[49m"),
2539
- bgCyan: f("\x1B[46m", "\x1B[49m"),
2540
- bgWhite: f("\x1B[47m", "\x1B[49m"),
2541
- blackBright: f("\x1B[90m", "\x1B[39m"),
2542
- redBright: f("\x1B[91m", "\x1B[39m"),
2543
- greenBright: f("\x1B[92m", "\x1B[39m"),
2544
- yellowBright: f("\x1B[93m", "\x1B[39m"),
2545
- blueBright: f("\x1B[94m", "\x1B[39m"),
2546
- magentaBright: f("\x1B[95m", "\x1B[39m"),
2547
- cyanBright: f("\x1B[96m", "\x1B[39m"),
2548
- whiteBright: f("\x1B[97m", "\x1B[39m"),
2549
- bgBlackBright: f("\x1B[100m", "\x1B[49m"),
2550
- bgRedBright: f("\x1B[101m", "\x1B[49m"),
2551
- bgGreenBright: f("\x1B[102m", "\x1B[49m"),
2552
- bgYellowBright: f("\x1B[103m", "\x1B[49m"),
2553
- bgBlueBright: f("\x1B[104m", "\x1B[49m"),
2554
- bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
2555
- bgCyanBright: f("\x1B[106m", "\x1B[49m"),
2556
- bgWhiteBright: f("\x1B[107m", "\x1B[49m")
2557
- };
2558
- };
2559
- module.exports = createColors();
2560
- module.exports.createColors = createColors;
2561
- });
2562
-
2563
2505
  // node_modules/cli-width/index.js
2564
2506
  var require_cli_width = __commonJS((exports, module) => {
2565
2507
  module.exports = cliWidth;
@@ -2739,65 +2681,6 @@ var {
2739
2681
  Help
2740
2682
  } = import__.default;
2741
2683
 
2742
- // src/utils/logger.ts
2743
- var import_picocolors = __toESM(require_picocolors(), 1);
2744
- var verboseEnabled = false;
2745
- function setVerbose(enabled) {
2746
- verboseEnabled = enabled;
2747
- }
2748
- function info(msg) {
2749
- console.log(import_picocolors.default.blue("i") + " " + msg);
2750
- }
2751
- function success(msg) {
2752
- console.log(import_picocolors.default.green("✓") + " " + msg);
2753
- }
2754
- function warn(msg) {
2755
- console.log(import_picocolors.default.yellow("!") + " " + msg);
2756
- }
2757
- function error(msg) {
2758
- console.error(import_picocolors.default.red("✗") + " " + msg);
2759
- }
2760
- function step(current, total, name, description) {
2761
- console.log(import_picocolors.default.cyan(`[${current}/${total}]`) + " " + import_picocolors.default.bold(name) + ": " + description);
2762
- }
2763
- function verbose(msg) {
2764
- if (verboseEnabled) {
2765
- console.log(import_picocolors.default.gray(" " + msg));
2766
- }
2767
- }
2768
- function header(title) {
2769
- console.log(`
2770
- ` + import_picocolors.default.bold(import_picocolors.default.magenta(title)));
2771
- console.log(import_picocolors.default.gray("─".repeat(title.length + 4)));
2772
- }
2773
- function banner(version) {
2774
- const title = ` e2e-ai v${version}`;
2775
- const subtitle = " AI-powered E2E test automation";
2776
- const width = Math.max(title.length, subtitle.length) + 2;
2777
- const top = import_picocolors.default.cyan("┌" + "─".repeat(width) + "┐");
2778
- const mid1 = import_picocolors.default.cyan("│") + import_picocolors.default.bold(title) + " ".repeat(width - title.length) + import_picocolors.default.cyan("│");
2779
- const mid2 = import_picocolors.default.cyan("│") + import_picocolors.default.gray(subtitle) + " ".repeat(width - subtitle.length) + import_picocolors.default.cyan("│");
2780
- const bottom = import_picocolors.default.cyan("└" + "─".repeat(width) + "┘");
2781
- console.log(top);
2782
- console.log(mid1);
2783
- console.log(mid2);
2784
- console.log(bottom);
2785
- }
2786
- function summary(steps) {
2787
- const nameCol = 16;
2788
- const statusCol = 10;
2789
- const headerLine = "Step".padEnd(nameCol) + "Status".padEnd(statusCol) + "Duration";
2790
- const separator = "─".repeat(nameCol + statusCol + 8);
2791
- console.log(import_picocolors.default.bold(headerLine));
2792
- console.log(import_picocolors.default.gray(separator));
2793
- for (const s of steps) {
2794
- const name = s.name.padEnd(nameCol);
2795
- const status = s.result.success ? import_picocolors.default.green("✓ pass".padEnd(statusCol)) : import_picocolors.default.red("✗ fail".padEnd(statusCol));
2796
- const duration = s.durationMs >= 1000 ? `${(s.durationMs / 1000).toFixed(1)}s` : `${Math.round(s.durationMs)}ms`;
2797
- console.log(name + status + duration);
2798
- }
2799
- }
2800
-
2801
2684
  // src/commands/record.ts
2802
2685
  import { join as join2 } from "node:path";
2803
2686
 
@@ -9052,38 +8935,40 @@ var dist_default6 = createPrompt((config, done) => {
9052
8935
  return `${lines}${cursorHide}`;
9053
8936
  });
9054
8937
  // src/commands/init.ts
9055
- var import_picocolors2 = __toESM(require_picocolors(), 1);
8938
+ var import_picocolors = __toESM(require_picocolors(), 1);
9056
8939
  function registerInit(program2) {
9057
8940
  program2.command("init").description("Initialize e2e-ai configuration for your project").option("--non-interactive", "Skip interactive prompts, use defaults").action(async (cmdOpts) => {
9058
8941
  const projectRoot = getProjectRoot();
9059
8942
  const e2eDir = join13(projectRoot, ".e2e-ai");
9060
- header("e2e-ai init");
9061
- const answers = cmdOpts?.nonInteractive ? getDefaultAnswers() : await askConfigQuestions();
9062
- const config = buildConfigFromAnswers(answers);
8943
+ const nonInteractive = !!cmdOpts?.nonInteractive;
9063
8944
  const configPath = join13(e2eDir, "config.ts");
9064
- if (fileExists(configPath)) {
9065
- warn(`Config already exists: ${configPath}`);
9066
- const overwrite = cmdOpts?.nonInteractive ? false : await dist_default4({ message: "Overwrite existing config?", default: false });
9067
- if (!overwrite) {
9068
- info("Skipping config generation");
9069
- } else {
9070
- writeFile(configPath, generateConfigFile(config));
9071
- success(`Config written: ${configPath}`);
9072
- }
8945
+ const isReInit = fileExists(configPath);
8946
+ header("e2e-ai init");
8947
+ if (isReInit) {
8948
+ info(`Existing .e2e-ai/ detected — preserving config and context.
8949
+ `);
8950
+ await copyAgentsToLocal(projectRoot, nonInteractive);
8951
+ await copyWorkflowGuide(projectRoot, nonInteractive);
9073
8952
  } else {
8953
+ const answers = nonInteractive ? getDefaultAnswers() : await askConfigQuestions();
8954
+ const config = buildConfigFromAnswers(answers);
9074
8955
  writeFile(configPath, generateConfigFile(config));
9075
8956
  success(`Config written: ${configPath}`);
8957
+ await copyAgentsToLocal(projectRoot, nonInteractive);
8958
+ await copyWorkflowGuide(projectRoot, nonInteractive);
9076
8959
  }
9077
- await copyAgentsToLocal(projectRoot, !!cmdOpts?.nonInteractive);
9078
- copyWorkflowGuide(projectRoot);
9079
8960
  console.log("");
9080
8961
  success(`Initialization complete!
9081
8962
  `);
9082
- console.log(import_picocolors2.default.bold("Next steps:"));
9083
- console.log(` 1. Use the ${import_picocolors2.default.cyan("init-agent")} in your AI tool to generate ${import_picocolors2.default.cyan(".e2e-ai/context.md")}`);
9084
- console.log(` (or use the MCP server: ${import_picocolors2.default.cyan("e2e_ai_scan_codebase")} + ${import_picocolors2.default.cyan("e2e_ai_read_agent")})`);
9085
- console.log(` 2. Review the generated ${import_picocolors2.default.cyan(".e2e-ai/context.md")}`);
9086
- console.log(` 3. Run: ${import_picocolors2.default.cyan("e2e-ai run --key PROJ-101")}`);
8963
+ if (!isReInit) {
8964
+ console.log(import_picocolors.default.bold("Next steps:"));
8965
+ console.log(` 1. Use the ${import_picocolors.default.cyan("init-agent")} in your AI tool to generate ${import_picocolors.default.cyan(".e2e-ai/context.md")}`);
8966
+ console.log(` (or use the MCP server: ${import_picocolors.default.cyan("e2e_ai_scan_codebase")} + ${import_picocolors.default.cyan("e2e_ai_read_agent")})`);
8967
+ console.log(` 2. Review the generated ${import_picocolors.default.cyan(".e2e-ai/context.md")}`);
8968
+ console.log(` 3. Run: ${import_picocolors.default.cyan("e2e-ai run --key PROJ-101")}`);
8969
+ } else {
8970
+ console.log(import_picocolors.default.dim("Config and context.md were preserved. Only agents and workflow were checked."));
8971
+ }
9087
8972
  });
9088
8973
  }
9089
8974
  function getDefaultAnswers() {
@@ -9199,8 +9084,8 @@ async function copyAgentsToLocal(projectRoot, nonInteractive) {
9199
9084
  return 0;
9200
9085
  }
9201
9086
  const overwrite = await dist_default4({
9202
- message: `Agent files already exist in .e2e-ai/agents/ (${existingFiles.length} files). Overwrite?`,
9203
- default: false
9087
+ message: `Update agents to latest version? (${agentFiles.length} files, currently ${existingFiles.length} in .e2e-ai/agents/)`,
9088
+ default: true
9204
9089
  });
9205
9090
  if (!overwrite) {
9206
9091
  info("Skipping agent copy");
@@ -9216,3845 +9101,134 @@ async function copyAgentsToLocal(projectRoot, nonInteractive) {
9216
9101
  success(`Agents copied to .e2e-ai/agents/ (${agentFiles.length} files)`);
9217
9102
  return agentFiles.length;
9218
9103
  }
9219
- function copyWorkflowGuide(projectRoot) {
9104
+ async function copyWorkflowGuide(projectRoot, nonInteractive) {
9220
9105
  const packageRoot = getPackageRoot();
9221
9106
  const source = join13(packageRoot, "templates", "workflow.md");
9222
9107
  const target = join13(projectRoot, ".e2e-ai", "workflow.md");
9223
9108
  if (!existsSync2(source))
9224
9109
  return;
9225
- if (existsSync2(target))
9226
- return;
9110
+ if (existsSync2(target)) {
9111
+ if (nonInteractive) {
9112
+ info("Workflow guide already exists, skipping");
9113
+ return;
9114
+ }
9115
+ const overwrite = await dist_default4({
9116
+ message: "Update workflow.md to latest version?",
9117
+ default: true
9118
+ });
9119
+ if (!overwrite) {
9120
+ info("Skipping workflow guide update");
9121
+ return;
9122
+ }
9123
+ }
9227
9124
  const content = readFileSync2(source, "utf-8");
9228
9125
  writeFile(target, content);
9229
9126
  success("Workflow guide written to .e2e-ai/workflow.md");
9230
9127
  }
9231
9128
 
9232
9129
  // src/commands/scan.ts
9233
- import { join as join15 } from "node:path";
9130
+ import { join as join14 } from "node:path";
9131
+ function registerScan(program2) {
9132
+ program2.command("scan").description("Scan codebase AST (routes, components, hooks, imports)").option("--output <file>", "Write output to specific file").option("--scan-dir <dir>", "Directory to scan (default: from config)").option("--no-cache", "Disable file-level caching").action(async (opts) => {
9133
+ const ctx = await resolveCommandContext(program2);
9134
+ const root = ctx.paths.projectRoot;
9135
+ const scanDir = opts.scanDir ?? ctx.config.scanner.scanDir;
9136
+ const cacheDir = join14(root, ctx.config.scanner.cacheDir);
9137
+ const scanConfig = {
9138
+ scanDir: join14(root, scanDir),
9139
+ include: ctx.config.scanner.include,
9140
+ exclude: ctx.config.scanner.exclude,
9141
+ cacheDir: opts.cache === false ? join14(cacheDir, `no-cache-${Date.now()}`) : cacheDir
9142
+ };
9143
+ const spinner = createSpinner();
9144
+ spinner.start("Scanning codebase...");
9145
+ const ast = await runStage1(scanConfig);
9146
+ spinner.stop();
9147
+ const outputPath = opts.output ?? (ctx.key ? join14(ctx.paths.workingDir, ctx.key, "ast-scan.json") : join14(root, ".e2e-ai", "ast-scan.json"));
9148
+ writeFile(outputPath, JSON.stringify(ast, null, 2));
9149
+ success(`AST written to ${outputPath}`);
9150
+ info(` Files: ${ast.stats.totalFiles} (${ast.stats.totalLines} lines)`);
9151
+ info(` Routes: ${ast.routes.length}`);
9152
+ info(` Components: ${ast.components.length}`);
9153
+ info(` Hooks: ${ast.hooks.length}`);
9154
+ });
9155
+ }
9234
9156
 
9235
- // src/scanner/scanner.ts
9236
- import { readFileSync as readFileSync4, existsSync as existsSync3, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "node:fs";
9237
- import { resolve, relative as relative2 } from "node:path";
9238
- import { createHash } from "node:crypto";
9157
+ // src/commands/push.ts
9158
+ import { join as join15 } from "node:path";
9239
9159
 
9240
- // node_modules/glob/dist/esm/index.min.js
9241
- import { fileURLToPath as Wi } from "node:url";
9242
- import { posix as mi, win32 as re } from "node:path";
9243
- import { fileURLToPath as gi } from "node:url";
9244
- import { lstatSync as wi, readdir as yi, readdirSync as bi, readlinkSync as Si, realpathSync as Ei } from "fs";
9245
- import * as xi from "node:fs";
9246
- import { lstat as Ci, readdir as Ti, readlink as Ai, realpath as ki } from "node:fs/promises";
9247
- import { EventEmitter as ee } from "node:events";
9248
- import Pe from "node:stream";
9249
- import { StringDecoder as ni } from "node:string_decoder";
9250
- var Gt = (n, t, e) => {
9251
- let s = n instanceof RegExp ? ce(n, e) : n, i = t instanceof RegExp ? ce(t, e) : t, r = s !== null && i != null && ss(s, i, e);
9252
- return r && { start: r[0], end: r[1], pre: e.slice(0, r[0]), body: e.slice(r[0] + s.length, r[1]), post: e.slice(r[1] + i.length) };
9253
- };
9254
- var ce = (n, t) => {
9255
- let e = t.match(n);
9256
- return e ? e[0] : null;
9257
- };
9258
- var ss = (n, t, e) => {
9259
- let s, i, r, o, h, a = e.indexOf(n), l = e.indexOf(t, a + 1), u = a;
9260
- if (a >= 0 && l > 0) {
9261
- if (n === t)
9262
- return [a, l];
9263
- for (s = [], r = e.length;u >= 0 && !h; ) {
9264
- if (u === a)
9265
- s.push(u), a = e.indexOf(n, u + 1);
9266
- else if (s.length === 1) {
9267
- let c = s.pop();
9268
- c !== undefined && (h = [c, l]);
9269
- } else
9270
- i = s.pop(), i !== undefined && i < r && (r = i, o = l), l = e.indexOf(t, u + 1);
9271
- u = a < l && a >= 0 ? a : l;
9272
- }
9273
- s.length && o !== undefined && (h = [r, o]);
9274
- }
9275
- return h;
9276
- };
9277
- var fe = "\x00SLASH" + Math.random() + "\x00";
9278
- var ue = "\x00OPEN" + Math.random() + "\x00";
9279
- var qt = "\x00CLOSE" + Math.random() + "\x00";
9280
- var de = "\x00COMMA" + Math.random() + "\x00";
9281
- var pe = "\x00PERIOD" + Math.random() + "\x00";
9282
- var is = new RegExp(fe, "g");
9283
- var rs = new RegExp(ue, "g");
9284
- var ns = new RegExp(qt, "g");
9285
- var os2 = new RegExp(de, "g");
9286
- var hs = new RegExp(pe, "g");
9287
- var as = /\\\\/g;
9288
- var ls = /\\{/g;
9289
- var cs = /\\}/g;
9290
- var fs = /\\,/g;
9291
- var us = /\\./g;
9292
- var ds = 1e5;
9293
- function Ht(n) {
9294
- return isNaN(n) ? n.charCodeAt(0) : parseInt(n, 10);
9295
- }
9296
- function ps(n) {
9297
- return n.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs, de).replace(us, pe);
9298
- }
9299
- function ms(n) {
9300
- return n.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os2, ",").replace(hs, ".");
9301
- }
9302
- function me(n) {
9303
- if (!n)
9304
- return [""];
9305
- let t = [], e = Gt("{", "}", n);
9306
- if (!e)
9307
- return n.split(",");
9308
- let { pre: s, body: i, post: r } = e, o = s.split(",");
9309
- o[o.length - 1] += "{" + i + "}";
9310
- let h = me(r);
9311
- return r.length && (o[o.length - 1] += h.shift(), o.push.apply(o, h)), t.push.apply(t, o), t;
9312
- }
9313
- function ge(n, t = {}) {
9314
- if (!n)
9315
- return [];
9316
- let { max: e = ds } = t;
9317
- return n.slice(0, 2) === "{}" && (n = "\\{\\}" + n.slice(2)), ht(ps(n), e, true).map(ms);
9318
- }
9319
- function gs(n) {
9320
- return "{" + n + "}";
9321
- }
9322
- function ws(n) {
9323
- return /^-?0\d/.test(n);
9324
- }
9325
- function ys(n, t) {
9326
- return n <= t;
9327
- }
9328
- function bs(n, t) {
9329
- return n >= t;
9330
- }
9331
- function ht(n, t, e) {
9332
- let s = [], i = Gt("{", "}", n);
9333
- if (!i)
9334
- return [n];
9335
- let r = i.pre, o = i.post.length ? ht(i.post, t, false) : [""];
9336
- if (/\$$/.test(i.pre))
9337
- for (let h = 0;h < o.length && h < t; h++) {
9338
- let a = r + "{" + i.body + "}" + o[h];
9339
- s.push(a);
9340
- }
9341
- else {
9342
- let h = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body), l = h || a, u = i.body.indexOf(",") >= 0;
9343
- if (!l && !u)
9344
- return i.post.match(/,(?!,).*\}/) ? (n = i.pre + "{" + i.body + qt + i.post, ht(n, t, true)) : [n];
9345
- let c;
9346
- if (l)
9347
- c = i.body.split(/\.\./);
9348
- else if (c = me(i.body), c.length === 1 && c[0] !== undefined && (c = ht(c[0], t, false).map(gs), c.length === 1))
9349
- return o.map((f) => i.pre + c[0] + f);
9350
- let d;
9351
- if (l && c[0] !== undefined && c[1] !== undefined) {
9352
- let f = Ht(c[0]), m = Ht(c[1]), p = Math.max(c[0].length, c[1].length), w = c.length === 3 && c[2] !== undefined ? Math.abs(Ht(c[2])) : 1, g = ys;
9353
- m < f && (w *= -1, g = bs);
9354
- let E = c.some(ws);
9355
- d = [];
9356
- for (let y = f;g(y, m); y += w) {
9357
- let b;
9358
- if (a)
9359
- b = String.fromCharCode(y), b === "\\" && (b = "");
9360
- else if (b = String(y), E) {
9361
- let z = p - b.length;
9362
- if (z > 0) {
9363
- let $ = new Array(z + 1).join("0");
9364
- y < 0 ? b = "-" + $ + b.slice(1) : b = $ + b;
9365
- }
9366
- }
9367
- d.push(b);
9368
- }
9369
- } else {
9370
- d = [];
9371
- for (let f = 0;f < c.length; f++)
9372
- d.push.apply(d, ht(c[f], t, false));
9373
- }
9374
- for (let f = 0;f < d.length; f++)
9375
- for (let m = 0;m < o.length && s.length < t; m++) {
9376
- let p = r + d[f] + o[m];
9377
- (!e || l || p) && s.push(p);
9378
- }
9160
+ // src/scanner/push.ts
9161
+ async function pushToApi(payload, apiUrl, apiKey) {
9162
+ const response = await fetch(apiUrl, {
9163
+ method: "POST",
9164
+ headers: {
9165
+ "Content-Type": "application/json",
9166
+ Authorization: `Bearer ${apiKey}`
9167
+ },
9168
+ body: JSON.stringify(payload)
9169
+ });
9170
+ if (!response.ok) {
9171
+ const body = await response.text();
9172
+ throw new Error(`Push failed (${response.status}): ${body}`);
9379
9173
  }
9380
- return s;
9174
+ return response.json();
9381
9175
  }
9382
- var at = (n) => {
9383
- if (typeof n != "string")
9384
- throw new TypeError("invalid pattern");
9385
- if (n.length > 65536)
9386
- throw new TypeError("pattern is too long");
9387
- };
9388
- var Ss = { "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true], "[:alpha:]": ["\\p{L}\\p{Nl}", true], "[:ascii:]": ["\\x00-\\x7f", false], "[:blank:]": ["\\p{Zs}\\t", true], "[:cntrl:]": ["\\p{Cc}", true], "[:digit:]": ["\\p{Nd}", true], "[:graph:]": ["\\p{Z}\\p{C}", true, true], "[:lower:]": ["\\p{Ll}", true], "[:print:]": ["\\p{C}", true], "[:punct:]": ["\\p{P}", true], "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true], "[:upper:]": ["\\p{Lu}", true], "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true], "[:xdigit:]": ["A-Fa-f0-9", false] };
9389
- var lt = (n) => n.replace(/[[\]\\-]/g, "\\$&");
9390
- var Es = (n) => n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
9391
- var we = (n) => n.join("");
9392
- var ye = (n, t) => {
9393
- let e = t;
9394
- if (n.charAt(e) !== "[")
9395
- throw new Error("not in a brace expression");
9396
- let s = [], i = [], r = e + 1, o = false, h = false, a = false, l = false, u = e, c = "";
9397
- t:
9398
- for (;r < n.length; ) {
9399
- let p = n.charAt(r);
9400
- if ((p === "!" || p === "^") && r === e + 1) {
9401
- l = true, r++;
9402
- continue;
9403
- }
9404
- if (p === "]" && o && !a) {
9405
- u = r + 1;
9406
- break;
9407
- }
9408
- if (o = true, p === "\\" && !a) {
9409
- a = true, r++;
9410
- continue;
9411
- }
9412
- if (p === "[" && !a) {
9413
- for (let [w, [g, S, E]] of Object.entries(Ss))
9414
- if (n.startsWith(w, r)) {
9415
- if (c)
9416
- return ["$.", false, n.length - e, true];
9417
- r += w.length, E ? i.push(g) : s.push(g), h = h || S;
9418
- continue t;
9419
- }
9420
- }
9421
- if (a = false, c) {
9422
- p > c ? s.push(lt(c) + "-" + lt(p)) : p === c && s.push(lt(p)), c = "", r++;
9423
- continue;
9424
- }
9425
- if (n.startsWith("-]", r + 1)) {
9426
- s.push(lt(p + "-")), r += 2;
9427
- continue;
9428
- }
9429
- if (n.startsWith("-", r + 1)) {
9430
- c = p, r += 2;
9431
- continue;
9432
- }
9433
- s.push(lt(p)), r++;
9434
- }
9435
- if (u < r)
9436
- return ["", false, 0, false];
9437
- if (!s.length && !i.length)
9438
- return ["$.", false, n.length - e, true];
9439
- if (i.length === 0 && s.length === 1 && /^\\?.$/.test(s[0]) && !l) {
9440
- let p = s[0].length === 2 ? s[0].slice(-1) : s[0];
9441
- return [Es(p), false, u - e, false];
9442
- }
9443
- let d = "[" + (l ? "^" : "") + we(s) + "]", f = "[" + (l ? "" : "^") + we(i) + "]";
9444
- return [s.length && i.length ? "(" + d + "|" + f + ")" : s.length ? d : f, h, u - e, true];
9445
- };
9446
- var W = (n, { windowsPathsNoEscape: t = false, magicalBraces: e = true } = {}) => e ? t ? n.replace(/\[([^\/\\])\]/g, "$1") : n.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1") : t ? n.replace(/\[([^\/\\{}])\]/g, "$1") : n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, "$1$2").replace(/\\([^\/{}])/g, "$1");
9447
- var xs = new Set(["!", "?", "+", "*", "@"]);
9448
- var be = (n) => xs.has(n);
9449
- var vs = "(?!(?:^|/)\\.\\.?(?:$|/))";
9450
- var Ct = "(?!\\.)";
9451
- var Cs = new Set(["[", "."]);
9452
- var Ts = new Set(["..", "."]);
9453
- var As = new Set("().*{}+?[]^$\\!");
9454
- var ks = (n) => n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
9455
- var Kt = "[^/]";
9456
- var Se = Kt + "*?";
9457
- var Ee = Kt + "+?";
9458
- var Q = class n {
9459
- type;
9460
- #t;
9461
- #s;
9462
- #n = false;
9463
- #r = [];
9464
- #o;
9465
- #S;
9466
- #w;
9467
- #c = false;
9468
- #h;
9469
- #u;
9470
- #f = false;
9471
- constructor(t, e, s = {}) {
9472
- this.type = t, t && (this.#s = true), this.#o = e, this.#t = this.#o ? this.#o.#t : this, this.#h = this.#t === this ? s : this.#t.#h, this.#w = this.#t === this ? [] : this.#t.#w, t === "!" && !this.#t.#c && this.#w.push(this), this.#S = this.#o ? this.#o.#r.length : 0;
9473
- }
9474
- get hasMagic() {
9475
- if (this.#s !== undefined)
9476
- return this.#s;
9477
- for (let t of this.#r)
9478
- if (typeof t != "string" && (t.type || t.hasMagic))
9479
- return this.#s = true;
9480
- return this.#s;
9481
- }
9482
- toString() {
9483
- return this.#u !== undefined ? this.#u : this.type ? this.#u = this.type + "(" + this.#r.map((t) => String(t)).join("|") + ")" : this.#u = this.#r.map((t) => String(t)).join("");
9484
- }
9485
- #a() {
9486
- if (this !== this.#t)
9487
- throw new Error("should only call on root");
9488
- if (this.#c)
9489
- return this;
9490
- this.toString(), this.#c = true;
9491
- let t;
9492
- for (;t = this.#w.pop(); ) {
9493
- if (t.type !== "!")
9494
- continue;
9495
- let e = t, s = e.#o;
9496
- for (;s; ) {
9497
- for (let i = e.#S + 1;!s.type && i < s.#r.length; i++)
9498
- for (let r of t.#r) {
9499
- if (typeof r == "string")
9500
- throw new Error("string part in extglob AST??");
9501
- r.copyIn(s.#r[i]);
9502
- }
9503
- e = s, s = e.#o;
9504
- }
9505
- }
9506
- return this;
9507
- }
9508
- push(...t) {
9509
- for (let e of t)
9510
- if (e !== "") {
9511
- if (typeof e != "string" && !(e instanceof n && e.#o === this))
9512
- throw new Error("invalid part: " + e);
9513
- this.#r.push(e);
9514
- }
9515
- }
9516
- toJSON() {
9517
- let t = this.type === null ? this.#r.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#r.map((e) => e.toJSON())];
9518
- return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#t || this.#t.#c && this.#o?.type === "!") && t.push({}), t;
9519
- }
9520
- isStart() {
9521
- if (this.#t === this)
9522
- return true;
9523
- if (!this.#o?.isStart())
9524
- return false;
9525
- if (this.#S === 0)
9526
- return true;
9527
- let t = this.#o;
9528
- for (let e = 0;e < this.#S; e++) {
9529
- let s = t.#r[e];
9530
- if (!(s instanceof n && s.type === "!"))
9531
- return false;
9532
- }
9533
- return true;
9534
- }
9535
- isEnd() {
9536
- if (this.#t === this || this.#o?.type === "!")
9537
- return true;
9538
- if (!this.#o?.isEnd())
9539
- return false;
9540
- if (!this.type)
9541
- return this.#o?.isEnd();
9542
- let t = this.#o ? this.#o.#r.length : 0;
9543
- return this.#S === t - 1;
9544
- }
9545
- copyIn(t) {
9546
- typeof t == "string" ? this.push(t) : this.push(t.clone(this));
9547
- }
9548
- clone(t) {
9549
- let e = new n(this.type, t);
9550
- for (let s of this.#r)
9551
- e.copyIn(s);
9552
- return e;
9553
- }
9554
- static #i(t, e, s, i) {
9555
- let r = false, o = false, h = -1, a = false;
9556
- if (e.type === null) {
9557
- let f = s, m = "";
9558
- for (;f < t.length; ) {
9559
- let p = t.charAt(f++);
9560
- if (r || p === "\\") {
9561
- r = !r, m += p;
9562
- continue;
9563
- }
9564
- if (o) {
9565
- f === h + 1 ? (p === "^" || p === "!") && (a = true) : p === "]" && !(f === h + 2 && a) && (o = false), m += p;
9566
- continue;
9567
- } else if (p === "[") {
9568
- o = true, h = f, a = false, m += p;
9569
- continue;
9570
- }
9571
- if (!i.noext && be(p) && t.charAt(f) === "(") {
9572
- e.push(m), m = "";
9573
- let w = new n(p, e);
9574
- f = n.#i(t, w, f, i), e.push(w);
9575
- continue;
9576
- }
9577
- m += p;
9578
- }
9579
- return e.push(m), f;
9580
- }
9581
- let l = s + 1, u = new n(null, e), c = [], d = "";
9582
- for (;l < t.length; ) {
9583
- let f = t.charAt(l++);
9584
- if (r || f === "\\") {
9585
- r = !r, d += f;
9586
- continue;
9587
- }
9588
- if (o) {
9589
- l === h + 1 ? (f === "^" || f === "!") && (a = true) : f === "]" && !(l === h + 2 && a) && (o = false), d += f;
9590
- continue;
9591
- } else if (f === "[") {
9592
- o = true, h = l, a = false, d += f;
9593
- continue;
9594
- }
9595
- if (be(f) && t.charAt(l) === "(") {
9596
- u.push(d), d = "";
9597
- let m = new n(f, u);
9598
- u.push(m), l = n.#i(t, m, l, i);
9599
- continue;
9600
- }
9601
- if (f === "|") {
9602
- u.push(d), d = "", c.push(u), u = new n(null, e);
9603
- continue;
9604
- }
9605
- if (f === ")")
9606
- return d === "" && e.#r.length === 0 && (e.#f = true), u.push(d), d = "", e.push(...c, u), l;
9607
- d += f;
9608
- }
9609
- return e.type = null, e.#s = undefined, e.#r = [t.substring(s - 1)], l;
9610
- }
9611
- static fromGlob(t, e = {}) {
9612
- let s = new n(null, undefined, e);
9613
- return n.#i(t, s, 0, e), s;
9614
- }
9615
- toMMPattern() {
9616
- if (this !== this.#t)
9617
- return this.#t.toMMPattern();
9618
- let t = this.toString(), [e, s, i, r] = this.toRegExpSource();
9619
- if (!(i || this.#s || this.#h.nocase && !this.#h.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
9620
- return s;
9621
- let h = (this.#h.nocase ? "i" : "") + (r ? "u" : "");
9622
- return Object.assign(new RegExp(`^${e}$`, h), { _src: e, _glob: t });
9623
- }
9624
- get options() {
9625
- return this.#h;
9626
- }
9627
- toRegExpSource(t) {
9628
- let e = t ?? !!this.#h.dot;
9629
- if (this.#t === this && this.#a(), !this.type) {
9630
- let a = this.isStart() && this.isEnd() && !this.#r.some((f) => typeof f != "string"), l = this.#r.map((f) => {
9631
- let [m, p, w, g] = typeof f == "string" ? n.#E(f, this.#s, a) : f.toRegExpSource(t);
9632
- return this.#s = this.#s || w, this.#n = this.#n || g, m;
9633
- }).join(""), u = "";
9634
- if (this.isStart() && typeof this.#r[0] == "string" && !(this.#r.length === 1 && Ts.has(this.#r[0]))) {
9635
- let m = Cs, p = e && m.has(l.charAt(0)) || l.startsWith("\\.") && m.has(l.charAt(2)) || l.startsWith("\\.\\.") && m.has(l.charAt(4)), w = !e && !t && m.has(l.charAt(0));
9636
- u = p ? vs : w ? Ct : "";
9637
- }
9638
- let c = "";
9639
- return this.isEnd() && this.#t.#c && this.#o?.type === "!" && (c = "(?:$|\\/)"), [u + l + c, W(l), this.#s = !!this.#s, this.#n];
9640
- }
9641
- let s = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:", r = this.#d(e);
9642
- if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
9643
- let a = this.toString();
9644
- return this.#r = [a], this.type = null, this.#s = undefined, [a, W(this.toString()), false, false];
9645
- }
9646
- let o = !s || t || e || !Ct ? "" : this.#d(true);
9647
- o === r && (o = ""), o && (r = `(?:${r})(?:${o})*?`);
9648
- let h = "";
9649
- if (this.type === "!" && this.#f)
9650
- h = (this.isStart() && !e ? Ct : "") + Ee;
9651
- else {
9652
- let a = this.type === "!" ? "))" + (this.isStart() && !e && !t ? Ct : "") + Se + ")" : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : `)${this.type}`;
9653
- h = i + r + a;
9654
- }
9655
- return [h, W(r), this.#s = !!this.#s, this.#n];
9656
- }
9657
- #d(t) {
9658
- return this.#r.map((e) => {
9659
- if (typeof e == "string")
9660
- throw new Error("string type in extglob ast??");
9661
- let [s, i, r, o] = e.toRegExpSource(t);
9662
- return this.#n = this.#n || o, s;
9663
- }).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
9664
- }
9665
- static #E(t, e, s = false) {
9666
- let i = false, r = "", o = false, h = false;
9667
- for (let a = 0;a < t.length; a++) {
9668
- let l = t.charAt(a);
9669
- if (i) {
9670
- i = false, r += (As.has(l) ? "\\" : "") + l;
9671
- continue;
9672
- }
9673
- if (l === "*") {
9674
- if (h)
9675
- continue;
9676
- h = true, r += s && /^[*]+$/.test(t) ? Ee : Se, e = true;
9677
- continue;
9678
- } else
9679
- h = false;
9680
- if (l === "\\") {
9681
- a === t.length - 1 ? r += "\\\\" : i = true;
9682
- continue;
9683
- }
9684
- if (l === "[") {
9685
- let [u, c, d, f] = ye(t, a);
9686
- if (d) {
9687
- r += u, o = o || c, a += d - 1, e = e || f;
9688
- continue;
9689
- }
9690
- }
9691
- if (l === "?") {
9692
- r += Kt, e = true;
9693
- continue;
9694
- }
9695
- r += ks(l);
9696
- }
9697
- return [r, W(t), !!e, o];
9698
- }
9699
- };
9700
- var tt = (n2, { windowsPathsNoEscape: t = false, magicalBraces: e = false } = {}) => e ? t ? n2.replace(/[?*()[\]{}]/g, "[$&]") : n2.replace(/[?*()[\]\\{}]/g, "\\$&") : t ? n2.replace(/[?*()[\]]/g, "[$&]") : n2.replace(/[?*()[\]\\]/g, "\\$&");
9701
- var O = (n2, t, e = {}) => (at(t), !e.nocomment && t.charAt(0) === "#" ? false : new D(t, e).match(n2));
9702
- var Rs = /^\*+([^+@!?\*\[\(]*)$/;
9703
- var Os = (n2) => (t) => !t.startsWith(".") && t.endsWith(n2);
9704
- var Fs = (n2) => (t) => t.endsWith(n2);
9705
- var Ds = (n2) => (n2 = n2.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(n2));
9706
- var Ms = (n2) => (n2 = n2.toLowerCase(), (t) => t.toLowerCase().endsWith(n2));
9707
- var Ns = /^\*+\.\*+$/;
9708
- var _s = (n2) => !n2.startsWith(".") && n2.includes(".");
9709
- var Ls = (n2) => n2 !== "." && n2 !== ".." && n2.includes(".");
9710
- var Ws = /^\.\*+$/;
9711
- var Ps = (n2) => n2 !== "." && n2 !== ".." && n2.startsWith(".");
9712
- var js = /^\*+$/;
9713
- var Is = (n2) => n2.length !== 0 && !n2.startsWith(".");
9714
- var zs = (n2) => n2.length !== 0 && n2 !== "." && n2 !== "..";
9715
- var Bs = /^\?+([^+@!?\*\[\(]*)?$/;
9716
- var Us = ([n2, t = ""]) => {
9717
- let e = Ce([n2]);
9718
- return t ? (t = t.toLowerCase(), (s) => e(s) && s.toLowerCase().endsWith(t)) : e;
9719
- };
9720
- var $s = ([n2, t = ""]) => {
9721
- let e = Te([n2]);
9722
- return t ? (t = t.toLowerCase(), (s) => e(s) && s.toLowerCase().endsWith(t)) : e;
9723
- };
9724
- var Gs = ([n2, t = ""]) => {
9725
- let e = Te([n2]);
9726
- return t ? (s) => e(s) && s.endsWith(t) : e;
9727
- };
9728
- var Hs = ([n2, t = ""]) => {
9729
- let e = Ce([n2]);
9730
- return t ? (s) => e(s) && s.endsWith(t) : e;
9731
- };
9732
- var Ce = ([n2]) => {
9733
- let t = n2.length;
9734
- return (e) => e.length === t && !e.startsWith(".");
9735
- };
9736
- var Te = ([n2]) => {
9737
- let t = n2.length;
9738
- return (e) => e.length === t && e !== "." && e !== "..";
9739
- };
9740
- var Ae = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
9741
- var xe = { win32: { sep: "\\" }, posix: { sep: "/" } };
9742
- var qs = Ae === "win32" ? xe.win32.sep : xe.posix.sep;
9743
- O.sep = qs;
9744
- var A = Symbol("globstar **");
9745
- O.GLOBSTAR = A;
9746
- var Ks = "[^/]";
9747
- var Vs = Ks + "*?";
9748
- var Ys = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
9749
- var Xs = "(?:(?!(?:\\/|^)\\.).)*?";
9750
- var Js = (n2, t = {}) => (e) => O(e, n2, t);
9751
- O.filter = Js;
9752
- var N = (n2, t = {}) => Object.assign({}, n2, t);
9753
- var Zs = (n2) => {
9754
- if (!n2 || typeof n2 != "object" || !Object.keys(n2).length)
9755
- return O;
9756
- let t = O;
9757
- return Object.assign((s, i, r = {}) => t(s, i, N(n2, r)), { Minimatch: class extends t.Minimatch {
9758
- constructor(i, r = {}) {
9759
- super(i, N(n2, r));
9760
- }
9761
- static defaults(i) {
9762
- return t.defaults(N(n2, i)).Minimatch;
9763
- }
9764
- }, AST: class extends t.AST {
9765
- constructor(i, r, o = {}) {
9766
- super(i, r, N(n2, o));
9767
- }
9768
- static fromGlob(i, r = {}) {
9769
- return t.AST.fromGlob(i, N(n2, r));
9770
- }
9771
- }, unescape: (s, i = {}) => t.unescape(s, N(n2, i)), escape: (s, i = {}) => t.escape(s, N(n2, i)), filter: (s, i = {}) => t.filter(s, N(n2, i)), defaults: (s) => t.defaults(N(n2, s)), makeRe: (s, i = {}) => t.makeRe(s, N(n2, i)), braceExpand: (s, i = {}) => t.braceExpand(s, N(n2, i)), match: (s, i, r = {}) => t.match(s, i, N(n2, r)), sep: t.sep, GLOBSTAR: A });
9772
- };
9773
- O.defaults = Zs;
9774
- var ke = (n2, t = {}) => (at(n2), t.nobrace || !/\{(?:(?!\{).)*\}/.test(n2) ? [n2] : ge(n2, { max: t.braceExpandMax }));
9775
- O.braceExpand = ke;
9776
- var Qs = (n2, t = {}) => new D(n2, t).makeRe();
9777
- O.makeRe = Qs;
9778
- var ti = (n2, t, e = {}) => {
9779
- let s = new D(t, e);
9780
- return n2 = n2.filter((i) => s.match(i)), s.options.nonull && !n2.length && n2.push(t), n2;
9781
- };
9782
- O.match = ti;
9783
- var ve = /[?*]|[+@!]\(.*?\)|\[|\]/;
9784
- var ei = (n2) => n2.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
9785
- var D = class {
9786
- options;
9787
- set;
9788
- pattern;
9789
- windowsPathsNoEscape;
9790
- nonegate;
9791
- negate;
9792
- comment;
9793
- empty;
9794
- preserveMultipleSlashes;
9795
- partial;
9796
- globSet;
9797
- globParts;
9798
- nocase;
9799
- isWindows;
9800
- platform;
9801
- windowsNoMagicRoot;
9802
- regexp;
9803
- constructor(t, e = {}) {
9804
- at(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ae, this.isWindows = this.platform === "win32";
9805
- let s = "allowWindowsEscape";
9806
- this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e[s] === false, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = false, this.nonegate = !!e.nonegate, this.comment = false, this.empty = false, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== undefined ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
9807
- }
9808
- hasMagic() {
9809
- if (this.options.magicalBraces && this.set.length > 1)
9810
- return true;
9811
- for (let t of this.set)
9812
- for (let e of t)
9813
- if (typeof e != "string")
9814
- return true;
9815
- return false;
9816
- }
9817
- debug(...t) {}
9818
- make() {
9819
- let t = this.pattern, e = this.options;
9820
- if (!e.nocomment && t.charAt(0) === "#") {
9821
- this.comment = true;
9822
- return;
9823
- }
9824
- if (!t) {
9825
- this.empty = true;
9826
- return;
9176
+
9177
+ // src/commands/push.ts
9178
+ function registerPush(program2) {
9179
+ program2.command("push [input]").description("Push QA map to remote API").option("--commit-sha <sha>", "Git commit SHA to associate").action(async (inputArg, opts) => {
9180
+ const ctx = await resolveCommandContext(program2);
9181
+ const apiUrl = ctx.config.push?.apiUrl ?? process.env.E2E_AI_API_URL;
9182
+ const apiKey = ctx.config.push?.apiKey ?? process.env.E2E_AI_API_KEY;
9183
+ if (!apiUrl) {
9184
+ error("No push.apiUrl configured. Set it in e2e-ai.config.ts or E2E_AI_API_URL env var.");
9185
+ process.exit(1);
9827
9186
  }
9828
- this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...r) => console.error(...r)), this.debug(this.pattern, this.globSet);
9829
- let s = this.globSet.map((r) => this.slashSplit(r));
9830
- this.globParts = this.preprocess(s), this.debug(this.pattern, this.globParts);
9831
- let i = this.globParts.map((r, o, h) => {
9832
- if (this.isWindows && this.windowsNoMagicRoot) {
9833
- let a = r[0] === "" && r[1] === "" && (r[2] === "?" || !ve.test(r[2])) && !ve.test(r[3]), l = /^[a-z]:/i.test(r[0]);
9834
- if (a)
9835
- return [...r.slice(0, 4), ...r.slice(4).map((u) => this.parse(u))];
9836
- if (l)
9837
- return [r[0], ...r.slice(1).map((u) => this.parse(u))];
9838
- }
9839
- return r.map((a) => this.parse(a));
9840
- });
9841
- if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(false) === -1), this.isWindows)
9842
- for (let r = 0;r < this.set.length; r++) {
9843
- let o = this.set[r];
9844
- o[0] === "" && o[1] === "" && this.globParts[r][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
9845
- }
9846
- this.debug(this.pattern, this.set);
9847
- }
9848
- preprocess(t) {
9849
- if (this.options.noglobstar)
9850
- for (let s = 0;s < t.length; s++)
9851
- for (let i = 0;i < t[s].length; i++)
9852
- t[s][i] === "**" && (t[s][i] = "*");
9853
- let { optimizationLevel: e = 1 } = this.options;
9854
- return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
9855
- }
9856
- adjascentGlobstarOptimize(t) {
9857
- return t.map((e) => {
9858
- let s = -1;
9859
- for (;(s = e.indexOf("**", s + 1)) !== -1; ) {
9860
- let i = s;
9861
- for (;e[i + 1] === "**"; )
9862
- i++;
9863
- i !== s && e.splice(s, i - s);
9864
- }
9865
- return e;
9866
- });
9867
- }
9868
- levelOneOptimize(t) {
9869
- return t.map((e) => (e = e.reduce((s, i) => {
9870
- let r = s[s.length - 1];
9871
- return i === "**" && r === "**" ? s : i === ".." && r && r !== ".." && r !== "." && r !== "**" ? (s.pop(), s) : (s.push(i), s);
9872
- }, []), e.length === 0 ? [""] : e));
9873
- }
9874
- levelTwoFileOptimize(t) {
9875
- Array.isArray(t) || (t = this.slashSplit(t));
9876
- let e = false;
9877
- do {
9878
- if (e = false, !this.preserveMultipleSlashes) {
9879
- for (let i = 1;i < t.length - 1; i++) {
9880
- let r = t[i];
9881
- i === 1 && r === "" && t[0] === "" || (r === "." || r === "") && (e = true, t.splice(i, 1), i--);
9882
- }
9883
- t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = true, t.pop());
9884
- }
9885
- let s = 0;
9886
- for (;(s = t.indexOf("..", s + 1)) !== -1; ) {
9887
- let i = t[s - 1];
9888
- i && i !== "." && i !== ".." && i !== "**" && (e = true, t.splice(s - 1, 2), s -= 2);
9889
- }
9890
- } while (e);
9891
- return t.length === 0 ? [""] : t;
9892
- }
9893
- firstPhasePreProcess(t) {
9894
- let e = false;
9895
- do {
9896
- e = false;
9897
- for (let s of t) {
9898
- let i = -1;
9899
- for (;(i = s.indexOf("**", i + 1)) !== -1; ) {
9900
- let o = i;
9901
- for (;s[o + 1] === "**"; )
9902
- o++;
9903
- o > i && s.splice(i + 1, o - i);
9904
- let h = s[i + 1], a = s[i + 2], l = s[i + 3];
9905
- if (h !== ".." || !a || a === "." || a === ".." || !l || l === "." || l === "..")
9906
- continue;
9907
- e = true, s.splice(i, 1);
9908
- let u = s.slice(0);
9909
- u[i] = "**", t.push(u), i--;
9910
- }
9911
- if (!this.preserveMultipleSlashes) {
9912
- for (let o = 1;o < s.length - 1; o++) {
9913
- let h = s[o];
9914
- o === 1 && h === "" && s[0] === "" || (h === "." || h === "") && (e = true, s.splice(o, 1), o--);
9915
- }
9916
- s[0] === "." && s.length === 2 && (s[1] === "." || s[1] === "") && (e = true, s.pop());
9917
- }
9918
- let r = 0;
9919
- for (;(r = s.indexOf("..", r + 1)) !== -1; ) {
9920
- let o = s[r - 1];
9921
- if (o && o !== "." && o !== ".." && o !== "**") {
9922
- e = true;
9923
- let a = r === 1 && s[r + 1] === "**" ? ["."] : [];
9924
- s.splice(r - 1, 2, ...a), s.length === 0 && s.push(""), r -= 2;
9925
- }
9926
- }
9927
- }
9928
- } while (e);
9929
- return t;
9930
- }
9931
- secondPhasePreProcess(t) {
9932
- for (let e = 0;e < t.length - 1; e++)
9933
- for (let s = e + 1;s < t.length; s++) {
9934
- let i = this.partsMatch(t[e], t[s], !this.preserveMultipleSlashes);
9935
- if (i) {
9936
- t[e] = [], t[s] = i;
9937
- break;
9938
- }
9939
- }
9940
- return t.filter((e) => e.length);
9941
- }
9942
- partsMatch(t, e, s = false) {
9943
- let i = 0, r = 0, o = [], h = "";
9944
- for (;i < t.length && r < e.length; )
9945
- if (t[i] === e[r])
9946
- o.push(h === "b" ? e[r] : t[i]), i++, r++;
9947
- else if (s && t[i] === "**" && e[r] === t[i + 1])
9948
- o.push(t[i]), i++;
9949
- else if (s && e[r] === "**" && t[i] === e[r + 1])
9950
- o.push(e[r]), r++;
9951
- else if (t[i] === "*" && e[r] && (this.options.dot || !e[r].startsWith(".")) && e[r] !== "**") {
9952
- if (h === "b")
9953
- return false;
9954
- h = "a", o.push(t[i]), i++, r++;
9955
- } else if (e[r] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") {
9956
- if (h === "a")
9957
- return false;
9958
- h = "b", o.push(e[r]), i++, r++;
9959
- } else
9960
- return false;
9961
- return t.length === e.length && o;
9962
- }
9963
- parseNegate() {
9964
- if (this.nonegate)
9965
- return;
9966
- let t = this.pattern, e = false, s = 0;
9967
- for (let i = 0;i < t.length && t.charAt(i) === "!"; i++)
9968
- e = !e, s++;
9969
- s && (this.pattern = t.slice(s)), this.negate = e;
9970
- }
9971
- matchOne(t, e, s = false) {
9972
- let i = this.options;
9973
- if (this.isWindows) {
9974
- let p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), w = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), g = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), S = !g && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), E = w ? 3 : p ? 0 : undefined, y = S ? 3 : g ? 0 : undefined;
9975
- if (typeof E == "number" && typeof y == "number") {
9976
- let [b, z] = [t[E], e[y]];
9977
- b.toLowerCase() === z.toLowerCase() && (e[y] = b, y > E ? e = e.slice(y) : E > y && (t = t.slice(E)));
9978
- }
9979
- }
9980
- let { optimizationLevel: r = 1 } = this.options;
9981
- r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
9982
- for (var o = 0, h = 0, a = t.length, l = e.length;o < a && h < l; o++, h++) {
9983
- this.debug("matchOne loop");
9984
- var u = e[h], c = t[o];
9985
- if (this.debug(e, u, c), u === false)
9986
- return false;
9987
- if (u === A) {
9988
- this.debug("GLOBSTAR", [e, u, c]);
9989
- var d = o, f = h + 1;
9990
- if (f === l) {
9991
- for (this.debug("** at the end");o < a; o++)
9992
- if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
9993
- return false;
9994
- return true;
9995
- }
9996
- for (;d < a; ) {
9997
- var m = t[d];
9998
- if (this.debug(`
9999
- globstar while`, t, d, e, f, m), this.matchOne(t.slice(d), e.slice(f), s))
10000
- return this.debug("globstar found match!", d, a, m), true;
10001
- if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
10002
- this.debug("dot detected!", t, d, e, f);
10003
- break;
10004
- }
10005
- this.debug("globstar swallow a segment, and continue"), d++;
10006
- }
10007
- return !!(s && (this.debug(`
10008
- >>> no match, partial?`, t, d, e, f), d === a));
10009
- }
10010
- let p;
10011
- if (typeof u == "string" ? (p = c === u, this.debug("string match", u, c, p)) : (p = u.test(c), this.debug("pattern match", u, c, p)), !p)
10012
- return false;
9187
+ if (!apiKey) {
9188
+ error("No push.apiKey configured. Set it in e2e-ai.config.ts or E2E_AI_API_KEY env var.");
9189
+ process.exit(1);
10013
9190
  }
10014
- if (o === a && h === l)
10015
- return true;
10016
- if (o === a)
10017
- return s;
10018
- if (h === l)
10019
- return o === a - 1 && t[o] === "";
10020
- throw new Error("wtf?");
10021
- }
10022
- braceExpand() {
10023
- return ke(this.pattern, this.options);
10024
- }
10025
- parse(t) {
10026
- at(t);
10027
- let e = this.options;
10028
- if (t === "**")
10029
- return A;
10030
- if (t === "")
10031
- return "";
10032
- let s, i = null;
10033
- (s = t.match(js)) ? i = e.dot ? zs : Is : (s = t.match(Rs)) ? i = (e.nocase ? e.dot ? Ms : Ds : e.dot ? Fs : Os)(s[1]) : (s = t.match(Bs)) ? i = (e.nocase ? e.dot ? $s : Us : e.dot ? Gs : Hs)(s) : (s = t.match(Ns)) ? i = e.dot ? Ls : _s : (s = t.match(Ws)) && (i = Ps);
10034
- let r = Q.fromGlob(t, this.options).toMMPattern();
10035
- return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
10036
- }
10037
- makeRe() {
10038
- if (this.regexp || this.regexp === false)
10039
- return this.regexp;
10040
- let t = this.set;
10041
- if (!t.length)
10042
- return this.regexp = false, this.regexp;
10043
- let e = this.options, s = e.noglobstar ? Vs : e.dot ? Ys : Xs, i = new Set(e.nocase ? ["i"] : []), r = t.map((a) => {
10044
- let l = a.map((c) => {
10045
- if (c instanceof RegExp)
10046
- for (let d of c.flags.split(""))
10047
- i.add(d);
10048
- return typeof c == "string" ? ei(c) : c === A ? A : c._src;
10049
- });
10050
- l.forEach((c, d) => {
10051
- let f = l[d + 1], m = l[d - 1];
10052
- c !== A || m === A || (m === undefined ? f !== undefined && f !== A ? l[d + 1] = "(?:\\/|" + s + "\\/)?" + f : l[d] = s : f === undefined ? l[d - 1] = m + "(?:\\/|\\/" + s + ")?" : f !== A && (l[d - 1] = m + "(?:\\/|\\/" + s + "\\/)" + f, l[d + 1] = A));
10053
- });
10054
- let u = l.filter((c) => c !== A);
10055
- if (this.partial && u.length >= 1) {
10056
- let c = [];
10057
- for (let d = 1;d <= u.length; d++)
10058
- c.push(u.slice(0, d).join("/"));
10059
- return "(?:" + c.join("|") + ")";
10060
- }
10061
- return u.join("/");
10062
- }).join("|"), [o, h] = t.length > 1 ? ["(?:", ")"] : ["", ""];
10063
- r = "^" + o + r + h + "$", this.partial && (r = "^(?:\\/|" + o + r.slice(1, -1) + h + ")$"), this.negate && (r = "^(?!" + r + ").+$");
10064
- try {
10065
- this.regexp = new RegExp(r, [...i].join(""));
10066
- } catch {
10067
- this.regexp = false;
9191
+ const root = ctx.paths.projectRoot;
9192
+ let inputPath;
9193
+ if (inputArg) {
9194
+ inputPath = join15(root, inputArg);
9195
+ } else if (ctx.key) {
9196
+ inputPath = join15(ctx.paths.workingDir, ctx.key, "qa-map.json");
9197
+ } else {
9198
+ inputPath = join15(root, ".e2e-ai", "qa-map.json");
10068
9199
  }
10069
- return this.regexp;
10070
- }
10071
- slashSplit(t) {
10072
- return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\/\/[^\/]+/.test(t) ? ["", ...t.split(/\/+/)] : t.split(/\/+/);
10073
- }
10074
- match(t, e = this.partial) {
10075
- if (this.debug("match", t, this.pattern), this.comment)
10076
- return false;
10077
- if (this.empty)
10078
- return t === "";
10079
- if (t === "/" && e)
10080
- return true;
10081
- let s = this.options;
10082
- this.isWindows && (t = t.split("\\").join("/"));
10083
- let i = this.slashSplit(t);
10084
- this.debug(this.pattern, "split", i);
10085
- let r = this.set;
10086
- this.debug(this.pattern, "set", r);
10087
- let o = i[i.length - 1];
10088
- if (!o)
10089
- for (let h = i.length - 2;!o && h >= 0; h--)
10090
- o = i[h];
10091
- for (let h = 0;h < r.length; h++) {
10092
- let a = r[h], l = i;
10093
- if (s.matchBase && a.length === 1 && (l = [o]), this.matchOne(l, a, e))
10094
- return s.flipNegate ? true : !this.negate;
10095
- }
10096
- return s.flipNegate ? false : this.negate;
10097
- }
10098
- static defaults(t) {
10099
- return O.defaults(t).Minimatch;
10100
- }
10101
- };
10102
- O.AST = Q;
10103
- O.Minimatch = D;
10104
- O.escape = tt;
10105
- O.unescape = W;
10106
- var si = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date;
10107
- var Oe = new Set;
10108
- var Vt = typeof process == "object" && process ? process : {};
10109
- var Fe = (n2, t, e, s) => {
10110
- typeof Vt.emitWarning == "function" ? Vt.emitWarning(n2, t, e, s) : console.error(`[${e}] ${t}: ${n2}`);
10111
- };
10112
- var At = globalThis.AbortController;
10113
- var Re = globalThis.AbortSignal;
10114
- if (typeof At > "u") {
10115
- Re = class {
10116
- onabort;
10117
- _onabort = [];
10118
- reason;
10119
- aborted = false;
10120
- addEventListener(e, s) {
10121
- this._onabort.push(s);
10122
- }
10123
- }, At = class {
10124
- constructor() {
10125
- t();
9200
+ if (!fileExists(inputPath)) {
9201
+ error(`QA map not found: ${inputPath}`);
9202
+ process.exit(1);
10126
9203
  }
10127
- signal = new Re;
10128
- abort(e) {
10129
- if (!this.signal.aborted) {
10130
- this.signal.reason = e, this.signal.aborted = true;
10131
- for (let s of this.signal._onabort)
10132
- s(e);
10133
- this.signal.onabort?.(e);
10134
- }
9204
+ const payload = JSON.parse(readFile(inputPath));
9205
+ if (opts?.commitSha) {
9206
+ payload.commitSha = opts.commitSha;
10135
9207
  }
10136
- };
10137
- let n2 = Vt.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1", t = () => {
10138
- n2 && (n2 = false, Fe("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", t));
10139
- };
10140
- }
10141
- var ii = (n2) => !Oe.has(n2);
10142
- var q = (n2) => n2 && n2 === Math.floor(n2) && n2 > 0 && isFinite(n2);
10143
- var De = (n2) => q(n2) ? n2 <= Math.pow(2, 8) ? Uint8Array : n2 <= Math.pow(2, 16) ? Uint16Array : n2 <= Math.pow(2, 32) ? Uint32Array : n2 <= Number.MAX_SAFE_INTEGER ? Tt : null : null;
10144
- var Tt = class extends Array {
10145
- constructor(n2) {
10146
- super(n2), this.fill(0);
10147
- }
10148
- };
10149
- var ri = class ct {
10150
- heap;
10151
- length;
10152
- static #t = false;
10153
- static create(t) {
10154
- let e = De(t);
10155
- if (!e)
10156
- return [];
10157
- ct.#t = true;
10158
- let s = new ct(t, e);
10159
- return ct.#t = false, s;
10160
- }
10161
- constructor(t, e) {
10162
- if (!ct.#t)
10163
- throw new TypeError("instantiate Stack using Stack.create(n)");
10164
- this.heap = new e(t), this.length = 0;
10165
- }
10166
- push(t) {
10167
- this.heap[this.length++] = t;
10168
- }
10169
- pop() {
10170
- return this.heap[--this.length];
10171
- }
10172
- };
10173
- var ft = class Me {
10174
- #t;
10175
- #s;
10176
- #n;
10177
- #r;
10178
- #o;
10179
- #S;
10180
- #w;
10181
- #c;
10182
- get perf() {
10183
- return this.#c;
10184
- }
10185
- ttl;
10186
- ttlResolution;
10187
- ttlAutopurge;
10188
- updateAgeOnGet;
10189
- updateAgeOnHas;
10190
- allowStale;
10191
- noDisposeOnSet;
10192
- noUpdateTTL;
10193
- maxEntrySize;
10194
- sizeCalculation;
10195
- noDeleteOnFetchRejection;
10196
- noDeleteOnStaleGet;
10197
- allowStaleOnFetchAbort;
10198
- allowStaleOnFetchRejection;
10199
- ignoreFetchAbort;
10200
- #h;
10201
- #u;
10202
- #f;
10203
- #a;
10204
- #i;
10205
- #d;
10206
- #E;
10207
- #b;
10208
- #p;
10209
- #R;
10210
- #m;
10211
- #C;
10212
- #T;
10213
- #g;
10214
- #y;
10215
- #x;
10216
- #A;
10217
- #e;
10218
- #_;
10219
- static unsafeExposeInternals(t) {
10220
- return { starts: t.#T, ttls: t.#g, autopurgeTimers: t.#y, sizes: t.#C, keyMap: t.#f, keyList: t.#a, valList: t.#i, next: t.#d, prev: t.#E, get head() {
10221
- return t.#b;
10222
- }, get tail() {
10223
- return t.#p;
10224
- }, free: t.#R, isBackgroundFetch: (e) => t.#l(e), backgroundFetch: (e, s, i, r) => t.#U(e, s, i, r), moveToTail: (e) => t.#W(e), indexes: (e) => t.#F(e), rindexes: (e) => t.#D(e), isStale: (e) => t.#v(e) };
10225
- }
10226
- get max() {
10227
- return this.#t;
10228
- }
10229
- get maxSize() {
10230
- return this.#s;
10231
- }
10232
- get calculatedSize() {
10233
- return this.#u;
10234
- }
10235
- get size() {
10236
- return this.#h;
10237
- }
10238
- get fetchMethod() {
10239
- return this.#S;
10240
- }
10241
- get memoMethod() {
10242
- return this.#w;
10243
- }
10244
- get dispose() {
10245
- return this.#n;
10246
- }
10247
- get onInsert() {
10248
- return this.#r;
10249
- }
10250
- get disposeAfter() {
10251
- return this.#o;
10252
- }
10253
- constructor(t) {
10254
- let { max: e = 0, ttl: s, ttlResolution: i = 1, ttlAutopurge: r, updateAgeOnGet: o, updateAgeOnHas: h, allowStale: a, dispose: l, onInsert: u, disposeAfter: c, noDisposeOnSet: d, noUpdateTTL: f, maxSize: m = 0, maxEntrySize: p = 0, sizeCalculation: w, fetchMethod: g, memoMethod: S, noDeleteOnFetchRejection: E, noDeleteOnStaleGet: y, allowStaleOnFetchRejection: b, allowStaleOnFetchAbort: z, ignoreFetchAbort: $, perf: J } = t;
10255
- if (J !== undefined && typeof J?.now != "function")
10256
- throw new TypeError("perf option must have a now() method if specified");
10257
- if (this.#c = J ?? si, e !== 0 && !q(e))
10258
- throw new TypeError("max option must be a nonnegative integer");
10259
- let Z = e ? De(e) : Array;
10260
- if (!Z)
10261
- throw new Error("invalid max value: " + e);
10262
- if (this.#t = e, this.#s = m, this.maxEntrySize = p || this.#s, this.sizeCalculation = w, this.sizeCalculation) {
10263
- if (!this.#s && !this.maxEntrySize)
10264
- throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
10265
- if (typeof this.sizeCalculation != "function")
10266
- throw new TypeError("sizeCalculation set to non-function");
10267
- }
10268
- if (S !== undefined && typeof S != "function")
10269
- throw new TypeError("memoMethod must be a function if defined");
10270
- if (this.#w = S, g !== undefined && typeof g != "function")
10271
- throw new TypeError("fetchMethod must be a function if specified");
10272
- if (this.#S = g, this.#A = !!g, this.#f = new Map, this.#a = new Array(e).fill(undefined), this.#i = new Array(e).fill(undefined), this.#d = new Z(e), this.#E = new Z(e), this.#b = 0, this.#p = 0, this.#R = ri.create(e), this.#h = 0, this.#u = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof c == "function" ? (this.#o = c, this.#m = []) : (this.#o = undefined, this.#m = undefined), this.#x = !!this.#n, this.#_ = !!this.#r, this.#e = !!this.#o, this.noDisposeOnSet = !!d, this.noUpdateTTL = !!f, this.noDeleteOnFetchRejection = !!E, this.allowStaleOnFetchRejection = !!b, this.allowStaleOnFetchAbort = !!z, this.ignoreFetchAbort = !!$, this.maxEntrySize !== 0) {
10273
- if (this.#s !== 0 && !q(this.#s))
10274
- throw new TypeError("maxSize must be a positive integer if specified");
10275
- if (!q(this.maxEntrySize))
10276
- throw new TypeError("maxEntrySize must be a positive integer if specified");
10277
- this.#G();
10278
- }
10279
- if (this.allowStale = !!a, this.noDeleteOnStaleGet = !!y, this.updateAgeOnGet = !!o, this.updateAgeOnHas = !!h, this.ttlResolution = q(i) || i === 0 ? i : 1, this.ttlAutopurge = !!r, this.ttl = s || 0, this.ttl) {
10280
- if (!q(this.ttl))
10281
- throw new TypeError("ttl must be a positive integer if specified");
10282
- this.#M();
10283
- }
10284
- if (this.#t === 0 && this.ttl === 0 && this.#s === 0)
10285
- throw new TypeError("At least one of max, maxSize, or ttl is required");
10286
- if (!this.ttlAutopurge && !this.#t && !this.#s) {
10287
- let $t = "LRU_CACHE_UNBOUNDED";
10288
- ii($t) && (Oe.add($t), Fe("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", $t, Me));
10289
- }
10290
- }
10291
- getRemainingTTL(t) {
10292
- return this.#f.has(t) ? 1 / 0 : 0;
10293
- }
10294
- #M() {
10295
- let t = new Tt(this.#t), e = new Tt(this.#t);
10296
- this.#g = t, this.#T = e;
10297
- let s = this.ttlAutopurge ? new Array(this.#t) : undefined;
10298
- this.#y = s, this.#j = (o, h, a = this.#c.now()) => {
10299
- if (e[o] = h !== 0 ? a : 0, t[o] = h, s?.[o] && (clearTimeout(s[o]), s[o] = undefined), h !== 0 && s) {
10300
- let l = setTimeout(() => {
10301
- this.#v(o) && this.#O(this.#a[o], "expire");
10302
- }, h + 1);
10303
- l.unref && l.unref(), s[o] = l;
10304
- }
10305
- }, this.#k = (o) => {
10306
- e[o] = t[o] !== 0 ? this.#c.now() : 0;
10307
- }, this.#N = (o, h) => {
10308
- if (t[h]) {
10309
- let a = t[h], l = e[h];
10310
- if (!a || !l)
10311
- return;
10312
- o.ttl = a, o.start = l, o.now = i || r();
10313
- let u = o.now - l;
10314
- o.remainingTTL = a - u;
10315
- }
10316
- };
10317
- let i = 0, r = () => {
10318
- let o = this.#c.now();
10319
- if (this.ttlResolution > 0) {
10320
- i = o;
10321
- let h = setTimeout(() => i = 0, this.ttlResolution);
10322
- h.unref && h.unref();
10323
- }
10324
- return o;
10325
- };
10326
- this.getRemainingTTL = (o) => {
10327
- let h = this.#f.get(o);
10328
- if (h === undefined)
10329
- return 0;
10330
- let a = t[h], l = e[h];
10331
- if (!a || !l)
10332
- return 1 / 0;
10333
- let u = (i || r()) - l;
10334
- return a - u;
10335
- }, this.#v = (o) => {
10336
- let h = e[o], a = t[o];
10337
- return !!a && !!h && (i || r()) - h > a;
10338
- };
10339
- }
10340
- #k = () => {};
10341
- #N = () => {};
10342
- #j = () => {};
10343
- #v = () => false;
10344
- #G() {
10345
- let t = new Tt(this.#t);
10346
- this.#u = 0, this.#C = t, this.#P = (e) => {
10347
- this.#u -= t[e], t[e] = 0;
10348
- }, this.#I = (e, s, i, r) => {
10349
- if (this.#l(s))
10350
- return 0;
10351
- if (!q(i))
10352
- if (r) {
10353
- if (typeof r != "function")
10354
- throw new TypeError("sizeCalculation must be a function");
10355
- if (i = r(s, e), !q(i))
10356
- throw new TypeError("sizeCalculation return invalid (expect positive integer)");
10357
- } else
10358
- throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
10359
- return i;
10360
- }, this.#L = (e, s, i) => {
10361
- if (t[e] = s, this.#s) {
10362
- let r = this.#s - t[e];
10363
- for (;this.#u > r; )
10364
- this.#B(true);
10365
- }
10366
- this.#u += t[e], i && (i.entrySize = s, i.totalCalculatedSize = this.#u);
10367
- };
10368
- }
10369
- #P = (t) => {};
10370
- #L = (t, e, s) => {};
10371
- #I = (t, e, s, i) => {
10372
- if (s || i)
10373
- throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
10374
- return 0;
10375
- };
10376
- *#F({ allowStale: t = this.allowStale } = {}) {
10377
- if (this.#h)
10378
- for (let e = this.#p;!(!this.#z(e) || ((t || !this.#v(e)) && (yield e), e === this.#b)); )
10379
- e = this.#E[e];
10380
- }
10381
- *#D({ allowStale: t = this.allowStale } = {}) {
10382
- if (this.#h)
10383
- for (let e = this.#b;!(!this.#z(e) || ((t || !this.#v(e)) && (yield e), e === this.#p)); )
10384
- e = this.#d[e];
10385
- }
10386
- #z(t) {
10387
- return t !== undefined && this.#f.get(this.#a[t]) === t;
10388
- }
10389
- *entries() {
10390
- for (let t of this.#F())
10391
- this.#i[t] !== undefined && this.#a[t] !== undefined && !this.#l(this.#i[t]) && (yield [this.#a[t], this.#i[t]]);
10392
- }
10393
- *rentries() {
10394
- for (let t of this.#D())
10395
- this.#i[t] !== undefined && this.#a[t] !== undefined && !this.#l(this.#i[t]) && (yield [this.#a[t], this.#i[t]]);
10396
- }
10397
- *keys() {
10398
- for (let t of this.#F()) {
10399
- let e = this.#a[t];
10400
- e !== undefined && !this.#l(this.#i[t]) && (yield e);
10401
- }
10402
- }
10403
- *rkeys() {
10404
- for (let t of this.#D()) {
10405
- let e = this.#a[t];
10406
- e !== undefined && !this.#l(this.#i[t]) && (yield e);
10407
- }
10408
- }
10409
- *values() {
10410
- for (let t of this.#F())
10411
- this.#i[t] !== undefined && !this.#l(this.#i[t]) && (yield this.#i[t]);
10412
- }
10413
- *rvalues() {
10414
- for (let t of this.#D())
10415
- this.#i[t] !== undefined && !this.#l(this.#i[t]) && (yield this.#i[t]);
10416
- }
10417
- [Symbol.iterator]() {
10418
- return this.entries();
10419
- }
10420
- [Symbol.toStringTag] = "LRUCache";
10421
- find(t, e = {}) {
10422
- for (let s of this.#F()) {
10423
- let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
10424
- if (r !== undefined && t(r, this.#a[s], this))
10425
- return this.get(this.#a[s], e);
10426
- }
10427
- }
10428
- forEach(t, e = this) {
10429
- for (let s of this.#F()) {
10430
- let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
10431
- r !== undefined && t.call(e, r, this.#a[s], this);
10432
- }
10433
- }
10434
- rforEach(t, e = this) {
10435
- for (let s of this.#D()) {
10436
- let i = this.#i[s], r = this.#l(i) ? i.__staleWhileFetching : i;
10437
- r !== undefined && t.call(e, r, this.#a[s], this);
10438
- }
10439
- }
10440
- purgeStale() {
10441
- let t = false;
10442
- for (let e of this.#D({ allowStale: true }))
10443
- this.#v(e) && (this.#O(this.#a[e], "expire"), t = true);
10444
- return t;
10445
- }
10446
- info(t) {
10447
- let e = this.#f.get(t);
10448
- if (e === undefined)
10449
- return;
10450
- let s = this.#i[e], i = this.#l(s) ? s.__staleWhileFetching : s;
10451
- if (i === undefined)
10452
- return;
10453
- let r = { value: i };
10454
- if (this.#g && this.#T) {
10455
- let o = this.#g[e], h = this.#T[e];
10456
- if (o && h) {
10457
- let a = o - (this.#c.now() - h);
10458
- r.ttl = a, r.start = Date.now();
10459
- }
10460
- }
10461
- return this.#C && (r.size = this.#C[e]), r;
10462
- }
10463
- dump() {
10464
- let t = [];
10465
- for (let e of this.#F({ allowStale: true })) {
10466
- let s = this.#a[e], i = this.#i[e], r = this.#l(i) ? i.__staleWhileFetching : i;
10467
- if (r === undefined || s === undefined)
10468
- continue;
10469
- let o = { value: r };
10470
- if (this.#g && this.#T) {
10471
- o.ttl = this.#g[e];
10472
- let h = this.#c.now() - this.#T[e];
10473
- o.start = Math.floor(Date.now() - h);
10474
- }
10475
- this.#C && (o.size = this.#C[e]), t.unshift([s, o]);
10476
- }
10477
- return t;
10478
- }
10479
- load(t) {
10480
- this.clear();
10481
- for (let [e, s] of t) {
10482
- if (s.start) {
10483
- let i = Date.now() - s.start;
10484
- s.start = this.#c.now() - i;
10485
- }
10486
- this.set(e, s.value, s);
10487
- }
10488
- }
10489
- set(t, e, s = {}) {
10490
- if (e === undefined)
10491
- return this.delete(t), this;
10492
- let { ttl: i = this.ttl, start: r, noDisposeOnSet: o = this.noDisposeOnSet, sizeCalculation: h = this.sizeCalculation, status: a } = s, { noUpdateTTL: l = this.noUpdateTTL } = s, u = this.#I(t, e, s.size || 0, h);
10493
- if (this.maxEntrySize && u > this.maxEntrySize)
10494
- return a && (a.set = "miss", a.maxEntrySizeExceeded = true), this.#O(t, "set"), this;
10495
- let c = this.#h === 0 ? undefined : this.#f.get(t);
10496
- if (c === undefined)
10497
- c = this.#h === 0 ? this.#p : this.#R.length !== 0 ? this.#R.pop() : this.#h === this.#t ? this.#B(false) : this.#h, this.#a[c] = t, this.#i[c] = e, this.#f.set(t, c), this.#d[this.#p] = c, this.#E[c] = this.#p, this.#p = c, this.#h++, this.#L(c, u, a), a && (a.set = "add"), l = false, this.#_ && this.#r?.(e, t, "add");
10498
- else {
10499
- this.#W(c);
10500
- let d = this.#i[c];
10501
- if (e !== d) {
10502
- if (this.#A && this.#l(d)) {
10503
- d.__abortController.abort(new Error("replaced"));
10504
- let { __staleWhileFetching: f } = d;
10505
- f !== undefined && !o && (this.#x && this.#n?.(f, t, "set"), this.#e && this.#m?.push([f, t, "set"]));
10506
- } else
10507
- o || (this.#x && this.#n?.(d, t, "set"), this.#e && this.#m?.push([d, t, "set"]));
10508
- if (this.#P(c), this.#L(c, u, a), this.#i[c] = e, a) {
10509
- a.set = "replace";
10510
- let f = d && this.#l(d) ? d.__staleWhileFetching : d;
10511
- f !== undefined && (a.oldValue = f);
10512
- }
10513
- } else
10514
- a && (a.set = "update");
10515
- this.#_ && this.onInsert?.(e, t, e === d ? "update" : "replace");
10516
- }
10517
- if (i !== 0 && !this.#g && this.#M(), this.#g && (l || this.#j(c, i, r), a && this.#N(a, c)), !o && this.#e && this.#m) {
10518
- let d = this.#m, f;
10519
- for (;f = d?.shift(); )
10520
- this.#o?.(...f);
10521
- }
10522
- return this;
10523
- }
10524
- pop() {
10525
- try {
10526
- for (;this.#h; ) {
10527
- let t = this.#i[this.#b];
10528
- if (this.#B(true), this.#l(t)) {
10529
- if (t.__staleWhileFetching)
10530
- return t.__staleWhileFetching;
10531
- } else if (t !== undefined)
10532
- return t;
10533
- }
10534
- } finally {
10535
- if (this.#e && this.#m) {
10536
- let t = this.#m, e;
10537
- for (;e = t?.shift(); )
10538
- this.#o?.(...e);
10539
- }
10540
- }
10541
- }
10542
- #B(t) {
10543
- let e = this.#b, s = this.#a[e], i = this.#i[e];
10544
- return this.#A && this.#l(i) ? i.__abortController.abort(new Error("evicted")) : (this.#x || this.#e) && (this.#x && this.#n?.(i, s, "evict"), this.#e && this.#m?.push([i, s, "evict"])), this.#P(e), this.#y?.[e] && (clearTimeout(this.#y[e]), this.#y[e] = undefined), t && (this.#a[e] = undefined, this.#i[e] = undefined, this.#R.push(e)), this.#h === 1 ? (this.#b = this.#p = 0, this.#R.length = 0) : this.#b = this.#d[e], this.#f.delete(s), this.#h--, e;
10545
- }
10546
- has(t, e = {}) {
10547
- let { updateAgeOnHas: s = this.updateAgeOnHas, status: i } = e, r = this.#f.get(t);
10548
- if (r !== undefined) {
10549
- let o = this.#i[r];
10550
- if (this.#l(o) && o.__staleWhileFetching === undefined)
10551
- return false;
10552
- if (this.#v(r))
10553
- i && (i.has = "stale", this.#N(i, r));
10554
- else
10555
- return s && this.#k(r), i && (i.has = "hit", this.#N(i, r)), true;
10556
- } else
10557
- i && (i.has = "miss");
10558
- return false;
10559
- }
10560
- peek(t, e = {}) {
10561
- let { allowStale: s = this.allowStale } = e, i = this.#f.get(t);
10562
- if (i === undefined || !s && this.#v(i))
10563
- return;
10564
- let r = this.#i[i];
10565
- return this.#l(r) ? r.__staleWhileFetching : r;
10566
- }
10567
- #U(t, e, s, i) {
10568
- let r = e === undefined ? undefined : this.#i[e];
10569
- if (this.#l(r))
10570
- return r;
10571
- let o = new At, { signal: h } = s;
10572
- h?.addEventListener("abort", () => o.abort(h.reason), { signal: o.signal });
10573
- let a = { signal: o.signal, options: s, context: i }, l = (p, w = false) => {
10574
- let { aborted: g } = o.signal, S = s.ignoreFetchAbort && p !== undefined, E = s.ignoreFetchAbort || !!(s.allowStaleOnFetchAbort && p !== undefined);
10575
- if (s.status && (g && !w ? (s.status.fetchAborted = true, s.status.fetchError = o.signal.reason, S && (s.status.fetchAbortIgnored = true)) : s.status.fetchResolved = true), g && !S && !w)
10576
- return c(o.signal.reason, E);
10577
- let y = f, b = this.#i[e];
10578
- return (b === f || S && w && b === undefined) && (p === undefined ? y.__staleWhileFetching !== undefined ? this.#i[e] = y.__staleWhileFetching : this.#O(t, "fetch") : (s.status && (s.status.fetchUpdated = true), this.set(t, p, a.options))), p;
10579
- }, u = (p) => (s.status && (s.status.fetchRejected = true, s.status.fetchError = p), c(p, false)), c = (p, w) => {
10580
- let { aborted: g } = o.signal, S = g && s.allowStaleOnFetchAbort, E = S || s.allowStaleOnFetchRejection, y = E || s.noDeleteOnFetchRejection, b = f;
10581
- if (this.#i[e] === f && (!y || !w && b.__staleWhileFetching === undefined ? this.#O(t, "fetch") : S || (this.#i[e] = b.__staleWhileFetching)), E)
10582
- return s.status && b.__staleWhileFetching !== undefined && (s.status.returnedStale = true), b.__staleWhileFetching;
10583
- if (b.__returned === b)
10584
- throw p;
10585
- }, d = (p, w) => {
10586
- let g = this.#S?.(t, r, a);
10587
- g && g instanceof Promise && g.then((S) => p(S === undefined ? undefined : S), w), o.signal.addEventListener("abort", () => {
10588
- (!s.ignoreFetchAbort || s.allowStaleOnFetchAbort) && (p(undefined), s.allowStaleOnFetchAbort && (p = (S) => l(S, true)));
10589
- });
10590
- };
10591
- s.status && (s.status.fetchDispatched = true);
10592
- let f = new Promise(d).then(l, u), m = Object.assign(f, { __abortController: o, __staleWhileFetching: r, __returned: undefined });
10593
- return e === undefined ? (this.set(t, m, { ...a.options, status: undefined }), e = this.#f.get(t)) : this.#i[e] = m, m;
10594
- }
10595
- #l(t) {
10596
- if (!this.#A)
10597
- return false;
10598
- let e = t;
10599
- return !!e && e instanceof Promise && e.hasOwnProperty("__staleWhileFetching") && e.__abortController instanceof At;
10600
- }
10601
- async fetch(t, e = {}) {
10602
- let { allowStale: s = this.allowStale, updateAgeOnGet: i = this.updateAgeOnGet, noDeleteOnStaleGet: r = this.noDeleteOnStaleGet, ttl: o = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: a = 0, sizeCalculation: l = this.sizeCalculation, noUpdateTTL: u = this.noUpdateTTL, noDeleteOnFetchRejection: c = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: d = this.allowStaleOnFetchRejection, ignoreFetchAbort: f = this.ignoreFetchAbort, allowStaleOnFetchAbort: m = this.allowStaleOnFetchAbort, context: p, forceRefresh: w = false, status: g, signal: S } = e;
10603
- if (!this.#A)
10604
- return g && (g.fetch = "get"), this.get(t, { allowStale: s, updateAgeOnGet: i, noDeleteOnStaleGet: r, status: g });
10605
- let E = { allowStale: s, updateAgeOnGet: i, noDeleteOnStaleGet: r, ttl: o, noDisposeOnSet: h, size: a, sizeCalculation: l, noUpdateTTL: u, noDeleteOnFetchRejection: c, allowStaleOnFetchRejection: d, allowStaleOnFetchAbort: m, ignoreFetchAbort: f, status: g, signal: S }, y = this.#f.get(t);
10606
- if (y === undefined) {
10607
- g && (g.fetch = "miss");
10608
- let b = this.#U(t, y, E, p);
10609
- return b.__returned = b;
10610
- } else {
10611
- let b = this.#i[y];
10612
- if (this.#l(b)) {
10613
- let Z = s && b.__staleWhileFetching !== undefined;
10614
- return g && (g.fetch = "inflight", Z && (g.returnedStale = true)), Z ? b.__staleWhileFetching : b.__returned = b;
10615
- }
10616
- let z = this.#v(y);
10617
- if (!w && !z)
10618
- return g && (g.fetch = "hit"), this.#W(y), i && this.#k(y), g && this.#N(g, y), b;
10619
- let $ = this.#U(t, y, E, p), J = $.__staleWhileFetching !== undefined && s;
10620
- return g && (g.fetch = z ? "stale" : "refresh", J && z && (g.returnedStale = true)), J ? $.__staleWhileFetching : $.__returned = $;
10621
- }
10622
- }
10623
- async forceFetch(t, e = {}) {
10624
- let s = await this.fetch(t, e);
10625
- if (s === undefined)
10626
- throw new Error("fetch() returned undefined");
10627
- return s;
10628
- }
10629
- memo(t, e = {}) {
10630
- let s = this.#w;
10631
- if (!s)
10632
- throw new Error("no memoMethod provided to constructor");
10633
- let { context: i, forceRefresh: r, ...o } = e, h = this.get(t, o);
10634
- if (!r && h !== undefined)
10635
- return h;
10636
- let a = s(t, h, { options: o, context: i });
10637
- return this.set(t, a, o), a;
10638
- }
10639
- get(t, e = {}) {
10640
- let { allowStale: s = this.allowStale, updateAgeOnGet: i = this.updateAgeOnGet, noDeleteOnStaleGet: r = this.noDeleteOnStaleGet, status: o } = e, h = this.#f.get(t);
10641
- if (h !== undefined) {
10642
- let a = this.#i[h], l = this.#l(a);
10643
- return o && this.#N(o, h), this.#v(h) ? (o && (o.get = "stale"), l ? (o && s && a.__staleWhileFetching !== undefined && (o.returnedStale = true), s ? a.__staleWhileFetching : undefined) : (r || this.#O(t, "expire"), o && s && (o.returnedStale = true), s ? a : undefined)) : (o && (o.get = "hit"), l ? a.__staleWhileFetching : (this.#W(h), i && this.#k(h), a));
10644
- } else
10645
- o && (o.get = "miss");
10646
- }
10647
- #$(t, e) {
10648
- this.#E[e] = t, this.#d[t] = e;
10649
- }
10650
- #W(t) {
10651
- t !== this.#p && (t === this.#b ? this.#b = this.#d[t] : this.#$(this.#E[t], this.#d[t]), this.#$(this.#p, t), this.#p = t);
10652
- }
10653
- delete(t) {
10654
- return this.#O(t, "delete");
10655
- }
10656
- #O(t, e) {
10657
- let s = false;
10658
- if (this.#h !== 0) {
10659
- let i = this.#f.get(t);
10660
- if (i !== undefined)
10661
- if (this.#y?.[i] && (clearTimeout(this.#y?.[i]), this.#y[i] = undefined), s = true, this.#h === 1)
10662
- this.#H(e);
10663
- else {
10664
- this.#P(i);
10665
- let r = this.#i[i];
10666
- if (this.#l(r) ? r.__abortController.abort(new Error("deleted")) : (this.#x || this.#e) && (this.#x && this.#n?.(r, t, e), this.#e && this.#m?.push([r, t, e])), this.#f.delete(t), this.#a[i] = undefined, this.#i[i] = undefined, i === this.#p)
10667
- this.#p = this.#E[i];
10668
- else if (i === this.#b)
10669
- this.#b = this.#d[i];
10670
- else {
10671
- let o = this.#E[i];
10672
- this.#d[o] = this.#d[i];
10673
- let h = this.#d[i];
10674
- this.#E[h] = this.#E[i];
10675
- }
10676
- this.#h--, this.#R.push(i);
10677
- }
10678
- }
10679
- if (this.#e && this.#m?.length) {
10680
- let i = this.#m, r;
10681
- for (;r = i?.shift(); )
10682
- this.#o?.(...r);
10683
- }
10684
- return s;
10685
- }
10686
- clear() {
10687
- return this.#H("delete");
10688
- }
10689
- #H(t) {
10690
- for (let e of this.#D({ allowStale: true })) {
10691
- let s = this.#i[e];
10692
- if (this.#l(s))
10693
- s.__abortController.abort(new Error("deleted"));
10694
- else {
10695
- let i = this.#a[e];
10696
- this.#x && this.#n?.(s, i, t), this.#e && this.#m?.push([s, i, t]);
10697
- }
10698
- }
10699
- if (this.#f.clear(), this.#i.fill(undefined), this.#a.fill(undefined), this.#g && this.#T) {
10700
- this.#g.fill(0), this.#T.fill(0);
10701
- for (let e of this.#y ?? [])
10702
- e !== undefined && clearTimeout(e);
10703
- this.#y?.fill(undefined);
10704
- }
10705
- if (this.#C && this.#C.fill(0), this.#b = 0, this.#p = 0, this.#R.length = 0, this.#u = 0, this.#h = 0, this.#e && this.#m) {
10706
- let e = this.#m, s;
10707
- for (;s = e?.shift(); )
10708
- this.#o?.(...s);
10709
- }
10710
- }
10711
- };
10712
- var Ne = typeof process == "object" && process ? process : { stdout: null, stderr: null };
10713
- var oi = (n2) => !!n2 && typeof n2 == "object" && (n2 instanceof V || n2 instanceof Pe || hi(n2) || ai(n2));
10714
- var hi = (n2) => !!n2 && typeof n2 == "object" && n2 instanceof ee && typeof n2.pipe == "function" && n2.pipe !== Pe.Writable.prototype.pipe;
10715
- var ai = (n2) => !!n2 && typeof n2 == "object" && n2 instanceof ee && typeof n2.write == "function" && typeof n2.end == "function";
10716
- var G = Symbol("EOF");
10717
- var H = Symbol("maybeEmitEnd");
10718
- var K = Symbol("emittedEnd");
10719
- var kt = Symbol("emittingEnd");
10720
- var ut = Symbol("emittedError");
10721
- var Rt = Symbol("closed");
10722
- var _e = Symbol("read");
10723
- var Ot = Symbol("flush");
10724
- var Le = Symbol("flushChunk");
10725
- var P = Symbol("encoding");
10726
- var et = Symbol("decoder");
10727
- var v = Symbol("flowing");
10728
- var dt = Symbol("paused");
10729
- var st = Symbol("resume");
10730
- var C = Symbol("buffer");
10731
- var F = Symbol("pipes");
10732
- var T = Symbol("bufferLength");
10733
- var Yt = Symbol("bufferPush");
10734
- var Ft = Symbol("bufferShift");
10735
- var k = Symbol("objectMode");
10736
- var x = Symbol("destroyed");
10737
- var Xt = Symbol("error");
10738
- var Jt = Symbol("emitData");
10739
- var We = Symbol("emitEnd");
10740
- var Zt = Symbol("emitEnd2");
10741
- var B = Symbol("async");
10742
- var Qt = Symbol("abort");
10743
- var Dt = Symbol("aborted");
10744
- var pt = Symbol("signal");
10745
- var Y = Symbol("dataListeners");
10746
- var M = Symbol("discarded");
10747
- var mt = (n2) => Promise.resolve().then(n2);
10748
- var li = (n2) => n2();
10749
- var ci = (n2) => n2 === "end" || n2 === "finish" || n2 === "prefinish";
10750
- var fi = (n2) => n2 instanceof ArrayBuffer || !!n2 && typeof n2 == "object" && n2.constructor && n2.constructor.name === "ArrayBuffer" && n2.byteLength >= 0;
10751
- var ui = (n2) => !Buffer.isBuffer(n2) && ArrayBuffer.isView(n2);
10752
- var Mt = class {
10753
- src;
10754
- dest;
10755
- opts;
10756
- ondrain;
10757
- constructor(t, e, s) {
10758
- this.src = t, this.dest = e, this.opts = s, this.ondrain = () => t[st](), this.dest.on("drain", this.ondrain);
10759
- }
10760
- unpipe() {
10761
- this.dest.removeListener("drain", this.ondrain);
10762
- }
10763
- proxyErrors(t) {}
10764
- end() {
10765
- this.unpipe(), this.opts.end && this.dest.end();
10766
- }
10767
- };
10768
- var te = class extends Mt {
10769
- unpipe() {
10770
- this.src.removeListener("error", this.proxyErrors), super.unpipe();
10771
- }
10772
- constructor(t, e, s) {
10773
- super(t, e, s), this.proxyErrors = (i) => this.dest.emit("error", i), t.on("error", this.proxyErrors);
10774
- }
10775
- };
10776
- var di = (n2) => !!n2.objectMode;
10777
- var pi = (n2) => !n2.objectMode && !!n2.encoding && n2.encoding !== "buffer";
10778
- var V = class extends ee {
10779
- [v] = false;
10780
- [dt] = false;
10781
- [F] = [];
10782
- [C] = [];
10783
- [k];
10784
- [P];
10785
- [B];
10786
- [et];
10787
- [G] = false;
10788
- [K] = false;
10789
- [kt] = false;
10790
- [Rt] = false;
10791
- [ut] = null;
10792
- [T] = 0;
10793
- [x] = false;
10794
- [pt];
10795
- [Dt] = false;
10796
- [Y] = 0;
10797
- [M] = false;
10798
- writable = true;
10799
- readable = true;
10800
- constructor(...t) {
10801
- let e = t[0] || {};
10802
- if (super(), e.objectMode && typeof e.encoding == "string")
10803
- throw new TypeError("Encoding and objectMode may not be used together");
10804
- di(e) ? (this[k] = true, this[P] = null) : pi(e) ? (this[P] = e.encoding, this[k] = false) : (this[k] = false, this[P] = null), this[B] = !!e.async, this[et] = this[P] ? new ni(this[P]) : null, e && e.debugExposeBuffer === true && Object.defineProperty(this, "buffer", { get: () => this[C] }), e && e.debugExposePipes === true && Object.defineProperty(this, "pipes", { get: () => this[F] });
10805
- let { signal: s } = e;
10806
- s && (this[pt] = s, s.aborted ? this[Qt]() : s.addEventListener("abort", () => this[Qt]()));
10807
- }
10808
- get bufferLength() {
10809
- return this[T];
10810
- }
10811
- get encoding() {
10812
- return this[P];
10813
- }
10814
- set encoding(t) {
10815
- throw new Error("Encoding must be set at instantiation time");
10816
- }
10817
- setEncoding(t) {
10818
- throw new Error("Encoding must be set at instantiation time");
10819
- }
10820
- get objectMode() {
10821
- return this[k];
10822
- }
10823
- set objectMode(t) {
10824
- throw new Error("objectMode must be set at instantiation time");
10825
- }
10826
- get async() {
10827
- return this[B];
10828
- }
10829
- set async(t) {
10830
- this[B] = this[B] || !!t;
10831
- }
10832
- [Qt]() {
10833
- this[Dt] = true, this.emit("abort", this[pt]?.reason), this.destroy(this[pt]?.reason);
10834
- }
10835
- get aborted() {
10836
- return this[Dt];
10837
- }
10838
- set aborted(t) {}
10839
- write(t, e, s) {
10840
- if (this[Dt])
10841
- return false;
10842
- if (this[G])
10843
- throw new Error("write after end");
10844
- if (this[x])
10845
- return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true;
10846
- typeof e == "function" && (s = e, e = "utf8"), e || (e = "utf8");
10847
- let i = this[B] ? mt : li;
10848
- if (!this[k] && !Buffer.isBuffer(t)) {
10849
- if (ui(t))
10850
- t = Buffer.from(t.buffer, t.byteOffset, t.byteLength);
10851
- else if (fi(t))
10852
- t = Buffer.from(t);
10853
- else if (typeof t != "string")
10854
- throw new Error("Non-contiguous data written to non-objectMode stream");
10855
- }
10856
- return this[k] ? (this[v] && this[T] !== 0 && this[Ot](true), this[v] ? this.emit("data", t) : this[Yt](t), this[T] !== 0 && this.emit("readable"), s && i(s), this[v]) : t.length ? (typeof t == "string" && !(e === this[P] && !this[et]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[P] && (t = this[et].write(t)), this[v] && this[T] !== 0 && this[Ot](true), this[v] ? this.emit("data", t) : this[Yt](t), this[T] !== 0 && this.emit("readable"), s && i(s), this[v]) : (this[T] !== 0 && this.emit("readable"), s && i(s), this[v]);
10857
- }
10858
- read(t) {
10859
- if (this[x])
10860
- return null;
10861
- if (this[M] = false, this[T] === 0 || t === 0 || t && t > this[T])
10862
- return this[H](), null;
10863
- this[k] && (t = null), this[C].length > 1 && !this[k] && (this[C] = [this[P] ? this[C].join("") : Buffer.concat(this[C], this[T])]);
10864
- let e = this[_e](t || null, this[C][0]);
10865
- return this[H](), e;
10866
- }
10867
- [_e](t, e) {
10868
- if (this[k])
10869
- this[Ft]();
10870
- else {
10871
- let s = e;
10872
- t === s.length || t === null ? this[Ft]() : typeof s == "string" ? (this[C][0] = s.slice(t), e = s.slice(0, t), this[T] -= t) : (this[C][0] = s.subarray(t), e = s.subarray(0, t), this[T] -= t);
10873
- }
10874
- return this.emit("data", e), !this[C].length && !this[G] && this.emit("drain"), e;
10875
- }
10876
- end(t, e, s) {
10877
- return typeof t == "function" && (s = t, t = undefined), typeof e == "function" && (s = e, e = "utf8"), t !== undefined && this.write(t, e), s && this.once("end", s), this[G] = true, this.writable = false, (this[v] || !this[dt]) && this[H](), this;
10878
- }
10879
- [st]() {
10880
- this[x] || (!this[Y] && !this[F].length && (this[M] = true), this[dt] = false, this[v] = true, this.emit("resume"), this[C].length ? this[Ot]() : this[G] ? this[H]() : this.emit("drain"));
10881
- }
10882
- resume() {
10883
- return this[st]();
10884
- }
10885
- pause() {
10886
- this[v] = false, this[dt] = true, this[M] = false;
10887
- }
10888
- get destroyed() {
10889
- return this[x];
10890
- }
10891
- get flowing() {
10892
- return this[v];
10893
- }
10894
- get paused() {
10895
- return this[dt];
10896
- }
10897
- [Yt](t) {
10898
- this[k] ? this[T] += 1 : this[T] += t.length, this[C].push(t);
10899
- }
10900
- [Ft]() {
10901
- return this[k] ? this[T] -= 1 : this[T] -= this[C][0].length, this[C].shift();
10902
- }
10903
- [Ot](t = false) {
10904
- do
10905
- ;
10906
- while (this[Le](this[Ft]()) && this[C].length);
10907
- !t && !this[C].length && !this[G] && this.emit("drain");
10908
- }
10909
- [Le](t) {
10910
- return this.emit("data", t), this[v];
10911
- }
10912
- pipe(t, e) {
10913
- if (this[x])
10914
- return t;
10915
- this[M] = false;
10916
- let s = this[K];
10917
- return e = e || {}, t === Ne.stdout || t === Ne.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, s ? e.end && t.end() : (this[F].push(e.proxyErrors ? new te(this, t, e) : new Mt(this, t, e)), this[B] ? mt(() => this[st]()) : this[st]()), t;
10918
- }
10919
- unpipe(t) {
10920
- let e = this[F].find((s) => s.dest === t);
10921
- e && (this[F].length === 1 ? (this[v] && this[Y] === 0 && (this[v] = false), this[F] = []) : this[F].splice(this[F].indexOf(e), 1), e.unpipe());
10922
- }
10923
- addListener(t, e) {
10924
- return this.on(t, e);
10925
- }
10926
- on(t, e) {
10927
- let s = super.on(t, e);
10928
- if (t === "data")
10929
- this[M] = false, this[Y]++, !this[F].length && !this[v] && this[st]();
10930
- else if (t === "readable" && this[T] !== 0)
10931
- super.emit("readable");
10932
- else if (ci(t) && this[K])
10933
- super.emit(t), this.removeAllListeners(t);
10934
- else if (t === "error" && this[ut]) {
10935
- let i = e;
10936
- this[B] ? mt(() => i.call(this, this[ut])) : i.call(this, this[ut]);
10937
- }
10938
- return s;
10939
- }
10940
- removeListener(t, e) {
10941
- return this.off(t, e);
10942
- }
10943
- off(t, e) {
10944
- let s = super.off(t, e);
10945
- return t === "data" && (this[Y] = this.listeners("data").length, this[Y] === 0 && !this[M] && !this[F].length && (this[v] = false)), s;
10946
- }
10947
- removeAllListeners(t) {
10948
- let e = super.removeAllListeners(t);
10949
- return (t === "data" || t === undefined) && (this[Y] = 0, !this[M] && !this[F].length && (this[v] = false)), e;
10950
- }
10951
- get emittedEnd() {
10952
- return this[K];
10953
- }
10954
- [H]() {
10955
- !this[kt] && !this[K] && !this[x] && this[C].length === 0 && this[G] && (this[kt] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Rt] && this.emit("close"), this[kt] = false);
10956
- }
10957
- emit(t, ...e) {
10958
- let s = e[0];
10959
- if (t !== "error" && t !== "close" && t !== x && this[x])
10960
- return false;
10961
- if (t === "data")
10962
- return !this[k] && !s ? false : this[B] ? (mt(() => this[Jt](s)), true) : this[Jt](s);
10963
- if (t === "end")
10964
- return this[We]();
10965
- if (t === "close") {
10966
- if (this[Rt] = true, !this[K] && !this[x])
10967
- return false;
10968
- let r = super.emit("close");
10969
- return this.removeAllListeners("close"), r;
10970
- } else if (t === "error") {
10971
- this[ut] = s, super.emit(Xt, s);
10972
- let r = !this[pt] || this.listeners("error").length ? super.emit("error", s) : false;
10973
- return this[H](), r;
10974
- } else if (t === "resume") {
10975
- let r = super.emit("resume");
10976
- return this[H](), r;
10977
- } else if (t === "finish" || t === "prefinish") {
10978
- let r = super.emit(t);
10979
- return this.removeAllListeners(t), r;
10980
- }
10981
- let i = super.emit(t, ...e);
10982
- return this[H](), i;
10983
- }
10984
- [Jt](t) {
10985
- for (let s of this[F])
10986
- s.dest.write(t) === false && this.pause();
10987
- let e = this[M] ? false : super.emit("data", t);
10988
- return this[H](), e;
10989
- }
10990
- [We]() {
10991
- return this[K] ? false : (this[K] = true, this.readable = false, this[B] ? (mt(() => this[Zt]()), true) : this[Zt]());
10992
- }
10993
- [Zt]() {
10994
- if (this[et]) {
10995
- let e = this[et].end();
10996
- if (e) {
10997
- for (let s of this[F])
10998
- s.dest.write(e);
10999
- this[M] || super.emit("data", e);
11000
- }
11001
- }
11002
- for (let e of this[F])
11003
- e.end();
11004
- let t = super.emit("end");
11005
- return this.removeAllListeners("end"), t;
11006
- }
11007
- async collect() {
11008
- let t = Object.assign([], { dataLength: 0 });
11009
- this[k] || (t.dataLength = 0);
11010
- let e = this.promise();
11011
- return this.on("data", (s) => {
11012
- t.push(s), this[k] || (t.dataLength += s.length);
11013
- }), await e, t;
11014
- }
11015
- async concat() {
11016
- if (this[k])
11017
- throw new Error("cannot concat in objectMode");
11018
- let t = await this.collect();
11019
- return this[P] ? t.join("") : Buffer.concat(t, t.dataLength);
11020
- }
11021
- async promise() {
11022
- return new Promise((t, e) => {
11023
- this.on(x, () => e(new Error("stream destroyed"))), this.on("error", (s) => e(s)), this.on("end", () => t());
11024
- });
11025
- }
11026
- [Symbol.asyncIterator]() {
11027
- this[M] = false;
11028
- let t = false, e = async () => (this.pause(), t = true, { value: undefined, done: true });
11029
- return { next: () => {
11030
- if (t)
11031
- return e();
11032
- let i = this.read();
11033
- if (i !== null)
11034
- return Promise.resolve({ done: false, value: i });
11035
- if (this[G])
11036
- return e();
11037
- let r, o, h = (c) => {
11038
- this.off("data", a), this.off("end", l), this.off(x, u), e(), o(c);
11039
- }, a = (c) => {
11040
- this.off("error", h), this.off("end", l), this.off(x, u), this.pause(), r({ value: c, done: !!this[G] });
11041
- }, l = () => {
11042
- this.off("error", h), this.off("data", a), this.off(x, u), e(), r({ done: true, value: undefined });
11043
- }, u = () => h(new Error("stream destroyed"));
11044
- return new Promise((c, d) => {
11045
- o = d, r = c, this.once(x, u), this.once("error", h), this.once("end", l), this.once("data", a);
11046
- });
11047
- }, throw: e, return: e, [Symbol.asyncIterator]() {
11048
- return this;
11049
- }, [Symbol.asyncDispose]: async () => {} };
11050
- }
11051
- [Symbol.iterator]() {
11052
- this[M] = false;
11053
- let t = false, e = () => (this.pause(), this.off(Xt, e), this.off(x, e), this.off("end", e), t = true, { done: true, value: undefined }), s = () => {
11054
- if (t)
11055
- return e();
11056
- let i = this.read();
11057
- return i === null ? e() : { done: false, value: i };
11058
- };
11059
- return this.once("end", e), this.once(Xt, e), this.once(x, e), { next: s, throw: e, return: e, [Symbol.iterator]() {
11060
- return this;
11061
- }, [Symbol.dispose]: () => {} };
11062
- }
11063
- destroy(t) {
11064
- if (this[x])
11065
- return t ? this.emit("error", t) : this.emit(x), this;
11066
- this[x] = true, this[M] = true, this[C].length = 0, this[T] = 0;
11067
- let e = this;
11068
- return typeof e.close == "function" && !this[Rt] && e.close(), t ? this.emit("error", t) : this.emit(x), this;
11069
- }
11070
- static get isStream() {
11071
- return oi;
11072
- }
11073
- };
11074
- var vi = Ei.native;
11075
- var wt = { lstatSync: wi, readdir: yi, readdirSync: bi, readlinkSync: Si, realpathSync: vi, promises: { lstat: Ci, readdir: Ti, readlink: Ai, realpath: ki } };
11076
- var Ue = (n2) => !n2 || n2 === wt || n2 === xi ? wt : { ...wt, ...n2, promises: { ...wt.promises, ...n2.promises || {} } };
11077
- var $e = /^\\\\\?\\([a-z]:)\\?$/i;
11078
- var Ri = (n2) => n2.replace(/\//g, "\\").replace($e, "$1\\");
11079
- var Oi = /[\\\/]/;
11080
- var L = 0;
11081
- var Ge = 1;
11082
- var He = 2;
11083
- var U = 4;
11084
- var qe = 6;
11085
- var Ke = 8;
11086
- var X = 10;
11087
- var Ve = 12;
11088
- var _ = 15;
11089
- var gt = ~_;
11090
- var se = 16;
11091
- var je = 32;
11092
- var yt = 64;
11093
- var j = 128;
11094
- var Nt = 256;
11095
- var Lt = 512;
11096
- var Ie = yt | j | Lt;
11097
- var Fi = 1023;
11098
- var ie = (n2) => n2.isFile() ? Ke : n2.isDirectory() ? U : n2.isSymbolicLink() ? X : n2.isCharacterDevice() ? He : n2.isBlockDevice() ? qe : n2.isSocket() ? Ve : n2.isFIFO() ? Ge : L;
11099
- var ze = new ft({ max: 2 ** 12 });
11100
- var bt = (n2) => {
11101
- let t = ze.get(n2);
11102
- if (t)
11103
- return t;
11104
- let e = n2.normalize("NFKD");
11105
- return ze.set(n2, e), e;
11106
- };
11107
- var Be = new ft({ max: 2 ** 12 });
11108
- var _t = (n2) => {
11109
- let t = Be.get(n2);
11110
- if (t)
11111
- return t;
11112
- let e = bt(n2.toLowerCase());
11113
- return Be.set(n2, e), e;
11114
- };
11115
- var Wt = class extends ft {
11116
- constructor() {
11117
- super({ max: 256 });
11118
- }
11119
- };
11120
- var ne = class extends ft {
11121
- constructor(t = 16 * 1024) {
11122
- super({ maxSize: t, sizeCalculation: (e) => e.length + 1 });
11123
- }
11124
- };
11125
- var Ye = Symbol("PathScurry setAsCwd");
11126
- var R = class {
11127
- name;
11128
- root;
11129
- roots;
11130
- parent;
11131
- nocase;
11132
- isCWD = false;
11133
- #t;
11134
- #s;
11135
- get dev() {
11136
- return this.#s;
11137
- }
11138
- #n;
11139
- get mode() {
11140
- return this.#n;
11141
- }
11142
- #r;
11143
- get nlink() {
11144
- return this.#r;
11145
- }
11146
- #o;
11147
- get uid() {
11148
- return this.#o;
11149
- }
11150
- #S;
11151
- get gid() {
11152
- return this.#S;
11153
- }
11154
- #w;
11155
- get rdev() {
11156
- return this.#w;
11157
- }
11158
- #c;
11159
- get blksize() {
11160
- return this.#c;
11161
- }
11162
- #h;
11163
- get ino() {
11164
- return this.#h;
11165
- }
11166
- #u;
11167
- get size() {
11168
- return this.#u;
11169
- }
11170
- #f;
11171
- get blocks() {
11172
- return this.#f;
11173
- }
11174
- #a;
11175
- get atimeMs() {
11176
- return this.#a;
11177
- }
11178
- #i;
11179
- get mtimeMs() {
11180
- return this.#i;
11181
- }
11182
- #d;
11183
- get ctimeMs() {
11184
- return this.#d;
11185
- }
11186
- #E;
11187
- get birthtimeMs() {
11188
- return this.#E;
11189
- }
11190
- #b;
11191
- get atime() {
11192
- return this.#b;
11193
- }
11194
- #p;
11195
- get mtime() {
11196
- return this.#p;
11197
- }
11198
- #R;
11199
- get ctime() {
11200
- return this.#R;
11201
- }
11202
- #m;
11203
- get birthtime() {
11204
- return this.#m;
11205
- }
11206
- #C;
11207
- #T;
11208
- #g;
11209
- #y;
11210
- #x;
11211
- #A;
11212
- #e;
11213
- #_;
11214
- #M;
11215
- #k;
11216
- get parentPath() {
11217
- return (this.parent || this).fullpath();
11218
- }
11219
- get path() {
11220
- return this.parentPath;
11221
- }
11222
- constructor(t, e = L, s, i, r, o, h) {
11223
- this.name = t, this.#C = r ? _t(t) : bt(t), this.#e = e & Fi, this.nocase = r, this.roots = i, this.root = s || this, this.#_ = o, this.#g = h.fullpath, this.#x = h.relative, this.#A = h.relativePosix, this.parent = h.parent, this.parent ? this.#t = this.parent.#t : this.#t = Ue(h.fs);
11224
- }
11225
- depth() {
11226
- return this.#T !== undefined ? this.#T : this.parent ? this.#T = this.parent.depth() + 1 : this.#T = 0;
11227
- }
11228
- childrenCache() {
11229
- return this.#_;
11230
- }
11231
- resolve(t) {
11232
- if (!t)
11233
- return this;
11234
- let e = this.getRootString(t), i = t.substring(e.length).split(this.splitSep);
11235
- return e ? this.getRoot(e).#N(i) : this.#N(i);
11236
- }
11237
- #N(t) {
11238
- let e = this;
11239
- for (let s of t)
11240
- e = e.child(s);
11241
- return e;
11242
- }
11243
- children() {
11244
- let t = this.#_.get(this);
11245
- if (t)
11246
- return t;
11247
- let e = Object.assign([], { provisional: 0 });
11248
- return this.#_.set(this, e), this.#e &= ~se, e;
11249
- }
11250
- child(t, e) {
11251
- if (t === "" || t === ".")
11252
- return this;
11253
- if (t === "..")
11254
- return this.parent || this;
11255
- let s = this.children(), i = this.nocase ? _t(t) : bt(t);
11256
- for (let a of s)
11257
- if (a.#C === i)
11258
- return a;
11259
- let r = this.parent ? this.sep : "", o = this.#g ? this.#g + r + t : undefined, h = this.newChild(t, L, { ...e, parent: this, fullpath: o });
11260
- return this.canReaddir() || (h.#e |= j), s.push(h), h;
11261
- }
11262
- relative() {
11263
- if (this.isCWD)
11264
- return "";
11265
- if (this.#x !== undefined)
11266
- return this.#x;
11267
- let t = this.name, e = this.parent;
11268
- if (!e)
11269
- return this.#x = this.name;
11270
- let s = e.relative();
11271
- return s + (!s || !e.parent ? "" : this.sep) + t;
11272
- }
11273
- relativePosix() {
11274
- if (this.sep === "/")
11275
- return this.relative();
11276
- if (this.isCWD)
11277
- return "";
11278
- if (this.#A !== undefined)
11279
- return this.#A;
11280
- let t = this.name, e = this.parent;
11281
- if (!e)
11282
- return this.#A = this.fullpathPosix();
11283
- let s = e.relativePosix();
11284
- return s + (!s || !e.parent ? "" : "/") + t;
11285
- }
11286
- fullpath() {
11287
- if (this.#g !== undefined)
11288
- return this.#g;
11289
- let t = this.name, e = this.parent;
11290
- if (!e)
11291
- return this.#g = this.name;
11292
- let i = e.fullpath() + (e.parent ? this.sep : "") + t;
11293
- return this.#g = i;
11294
- }
11295
- fullpathPosix() {
11296
- if (this.#y !== undefined)
11297
- return this.#y;
11298
- if (this.sep === "/")
11299
- return this.#y = this.fullpath();
11300
- if (!this.parent) {
11301
- let i = this.fullpath().replace(/\\/g, "/");
11302
- return /^[a-z]:\//i.test(i) ? this.#y = `//?/${i}` : this.#y = i;
11303
- }
11304
- let t = this.parent, e = t.fullpathPosix(), s = e + (!e || !t.parent ? "" : "/") + this.name;
11305
- return this.#y = s;
11306
- }
11307
- isUnknown() {
11308
- return (this.#e & _) === L;
11309
- }
11310
- isType(t) {
11311
- return this[`is${t}`]();
11312
- }
11313
- getType() {
11314
- return this.isUnknown() ? "Unknown" : this.isDirectory() ? "Directory" : this.isFile() ? "File" : this.isSymbolicLink() ? "SymbolicLink" : this.isFIFO() ? "FIFO" : this.isCharacterDevice() ? "CharacterDevice" : this.isBlockDevice() ? "BlockDevice" : this.isSocket() ? "Socket" : "Unknown";
11315
- }
11316
- isFile() {
11317
- return (this.#e & _) === Ke;
11318
- }
11319
- isDirectory() {
11320
- return (this.#e & _) === U;
11321
- }
11322
- isCharacterDevice() {
11323
- return (this.#e & _) === He;
11324
- }
11325
- isBlockDevice() {
11326
- return (this.#e & _) === qe;
11327
- }
11328
- isFIFO() {
11329
- return (this.#e & _) === Ge;
11330
- }
11331
- isSocket() {
11332
- return (this.#e & _) === Ve;
11333
- }
11334
- isSymbolicLink() {
11335
- return (this.#e & X) === X;
11336
- }
11337
- lstatCached() {
11338
- return this.#e & je ? this : undefined;
11339
- }
11340
- readlinkCached() {
11341
- return this.#M;
11342
- }
11343
- realpathCached() {
11344
- return this.#k;
11345
- }
11346
- readdirCached() {
11347
- let t = this.children();
11348
- return t.slice(0, t.provisional);
11349
- }
11350
- canReadlink() {
11351
- if (this.#M)
11352
- return true;
11353
- if (!this.parent)
11354
- return false;
11355
- let t = this.#e & _;
11356
- return !(t !== L && t !== X || this.#e & Nt || this.#e & j);
11357
- }
11358
- calledReaddir() {
11359
- return !!(this.#e & se);
11360
- }
11361
- isENOENT() {
11362
- return !!(this.#e & j);
11363
- }
11364
- isNamed(t) {
11365
- return this.nocase ? this.#C === _t(t) : this.#C === bt(t);
11366
- }
11367
- async readlink() {
11368
- let t = this.#M;
11369
- if (t)
11370
- return t;
11371
- if (this.canReadlink() && this.parent)
11372
- try {
11373
- let e = await this.#t.promises.readlink(this.fullpath()), s = (await this.parent.realpath())?.resolve(e);
11374
- if (s)
11375
- return this.#M = s;
11376
- } catch (e) {
11377
- this.#D(e.code);
11378
- return;
11379
- }
11380
- }
11381
- readlinkSync() {
11382
- let t = this.#M;
11383
- if (t)
11384
- return t;
11385
- if (this.canReadlink() && this.parent)
11386
- try {
11387
- let e = this.#t.readlinkSync(this.fullpath()), s = this.parent.realpathSync()?.resolve(e);
11388
- if (s)
11389
- return this.#M = s;
11390
- } catch (e) {
11391
- this.#D(e.code);
11392
- return;
11393
- }
11394
- }
11395
- #j(t) {
11396
- this.#e |= se;
11397
- for (let e = t.provisional;e < t.length; e++) {
11398
- let s = t[e];
11399
- s && s.#v();
11400
- }
11401
- }
11402
- #v() {
11403
- this.#e & j || (this.#e = (this.#e | j) & gt, this.#G());
11404
- }
11405
- #G() {
11406
- let t = this.children();
11407
- t.provisional = 0;
11408
- for (let e of t)
11409
- e.#v();
11410
- }
11411
- #P() {
11412
- this.#e |= Lt, this.#L();
11413
- }
11414
- #L() {
11415
- if (this.#e & yt)
11416
- return;
11417
- let t = this.#e;
11418
- (t & _) === U && (t &= gt), this.#e = t | yt, this.#G();
11419
- }
11420
- #I(t = "") {
11421
- t === "ENOTDIR" || t === "EPERM" ? this.#L() : t === "ENOENT" ? this.#v() : this.children().provisional = 0;
11422
- }
11423
- #F(t = "") {
11424
- t === "ENOTDIR" ? this.parent.#L() : t === "ENOENT" && this.#v();
11425
- }
11426
- #D(t = "") {
11427
- let e = this.#e;
11428
- e |= Nt, t === "ENOENT" && (e |= j), (t === "EINVAL" || t === "UNKNOWN") && (e &= gt), this.#e = e, t === "ENOTDIR" && this.parent && this.parent.#L();
11429
- }
11430
- #z(t, e) {
11431
- return this.#U(t, e) || this.#B(t, e);
11432
- }
11433
- #B(t, e) {
11434
- let s = ie(t), i = this.newChild(t.name, s, { parent: this }), r = i.#e & _;
11435
- return r !== U && r !== X && r !== L && (i.#e |= yt), e.unshift(i), e.provisional++, i;
11436
- }
11437
- #U(t, e) {
11438
- for (let s = e.provisional;s < e.length; s++) {
11439
- let i = e[s];
11440
- if ((this.nocase ? _t(t.name) : bt(t.name)) === i.#C)
11441
- return this.#l(t, i, s, e);
11442
- }
11443
- }
11444
- #l(t, e, s, i) {
11445
- let r = e.name;
11446
- return e.#e = e.#e & gt | ie(t), r !== t.name && (e.name = t.name), s !== i.provisional && (s === i.length - 1 ? i.pop() : i.splice(s, 1), i.unshift(e)), i.provisional++, e;
11447
- }
11448
- async lstat() {
11449
- if ((this.#e & j) === 0)
11450
- try {
11451
- return this.#$(await this.#t.promises.lstat(this.fullpath())), this;
11452
- } catch (t) {
11453
- this.#F(t.code);
11454
- }
11455
- }
11456
- lstatSync() {
11457
- if ((this.#e & j) === 0)
11458
- try {
11459
- return this.#$(this.#t.lstatSync(this.fullpath())), this;
11460
- } catch (t) {
11461
- this.#F(t.code);
11462
- }
11463
- }
11464
- #$(t) {
11465
- let { atime: e, atimeMs: s, birthtime: i, birthtimeMs: r, blksize: o, blocks: h, ctime: a, ctimeMs: l, dev: u, gid: c, ino: d, mode: f, mtime: m, mtimeMs: p, nlink: w, rdev: g, size: S, uid: E } = t;
11466
- this.#b = e, this.#a = s, this.#m = i, this.#E = r, this.#c = o, this.#f = h, this.#R = a, this.#d = l, this.#s = u, this.#S = c, this.#h = d, this.#n = f, this.#p = m, this.#i = p, this.#r = w, this.#w = g, this.#u = S, this.#o = E;
11467
- let y = ie(t);
11468
- this.#e = this.#e & gt | y | je, y !== L && y !== U && y !== X && (this.#e |= yt);
11469
- }
11470
- #W = [];
11471
- #O = false;
11472
- #H(t) {
11473
- this.#O = false;
11474
- let e = this.#W.slice();
11475
- this.#W.length = 0, e.forEach((s) => s(null, t));
11476
- }
11477
- readdirCB(t, e = false) {
11478
- if (!this.canReaddir()) {
11479
- e ? t(null, []) : queueMicrotask(() => t(null, []));
11480
- return;
11481
- }
11482
- let s = this.children();
11483
- if (this.calledReaddir()) {
11484
- let r = s.slice(0, s.provisional);
11485
- e ? t(null, r) : queueMicrotask(() => t(null, r));
11486
- return;
11487
- }
11488
- if (this.#W.push(t), this.#O)
11489
- return;
11490
- this.#O = true;
11491
- let i = this.fullpath();
11492
- this.#t.readdir(i, { withFileTypes: true }, (r, o) => {
11493
- if (r)
11494
- this.#I(r.code), s.provisional = 0;
11495
- else {
11496
- for (let h of o)
11497
- this.#z(h, s);
11498
- this.#j(s);
11499
- }
11500
- this.#H(s.slice(0, s.provisional));
11501
- });
11502
- }
11503
- #q;
11504
- async readdir() {
11505
- if (!this.canReaddir())
11506
- return [];
11507
- let t = this.children();
11508
- if (this.calledReaddir())
11509
- return t.slice(0, t.provisional);
11510
- let e = this.fullpath();
11511
- if (this.#q)
11512
- await this.#q;
11513
- else {
11514
- let s = () => {};
11515
- this.#q = new Promise((i) => s = i);
11516
- try {
11517
- for (let i of await this.#t.promises.readdir(e, { withFileTypes: true }))
11518
- this.#z(i, t);
11519
- this.#j(t);
11520
- } catch (i) {
11521
- this.#I(i.code), t.provisional = 0;
11522
- }
11523
- this.#q = undefined, s();
11524
- }
11525
- return t.slice(0, t.provisional);
11526
- }
11527
- readdirSync() {
11528
- if (!this.canReaddir())
11529
- return [];
11530
- let t = this.children();
11531
- if (this.calledReaddir())
11532
- return t.slice(0, t.provisional);
11533
- let e = this.fullpath();
11534
- try {
11535
- for (let s of this.#t.readdirSync(e, { withFileTypes: true }))
11536
- this.#z(s, t);
11537
- this.#j(t);
11538
- } catch (s) {
11539
- this.#I(s.code), t.provisional = 0;
11540
- }
11541
- return t.slice(0, t.provisional);
11542
- }
11543
- canReaddir() {
11544
- if (this.#e & Ie)
11545
- return false;
11546
- let t = _ & this.#e;
11547
- return t === L || t === U || t === X;
11548
- }
11549
- shouldWalk(t, e) {
11550
- return (this.#e & U) === U && !(this.#e & Ie) && !t.has(this) && (!e || e(this));
11551
- }
11552
- async realpath() {
11553
- if (this.#k)
11554
- return this.#k;
11555
- if (!((Lt | Nt | j) & this.#e))
11556
- try {
11557
- let t = await this.#t.promises.realpath(this.fullpath());
11558
- return this.#k = this.resolve(t);
11559
- } catch {
11560
- this.#P();
11561
- }
11562
- }
11563
- realpathSync() {
11564
- if (this.#k)
11565
- return this.#k;
11566
- if (!((Lt | Nt | j) & this.#e))
11567
- try {
11568
- let t = this.#t.realpathSync(this.fullpath());
11569
- return this.#k = this.resolve(t);
11570
- } catch {
11571
- this.#P();
11572
- }
11573
- }
11574
- [Ye](t) {
11575
- if (t === this)
11576
- return;
11577
- t.isCWD = false, this.isCWD = true;
11578
- let e = new Set([]), s = [], i = this;
11579
- for (;i && i.parent; )
11580
- e.add(i), i.#x = s.join(this.sep), i.#A = s.join("/"), i = i.parent, s.push("..");
11581
- for (i = t;i && i.parent && !e.has(i); )
11582
- i.#x = undefined, i.#A = undefined, i = i.parent;
11583
- }
11584
- };
11585
- var Pt = class n2 extends R {
11586
- sep = "\\";
11587
- splitSep = Oi;
11588
- constructor(t, e = L, s, i, r, o, h) {
11589
- super(t, e, s, i, r, o, h);
11590
- }
11591
- newChild(t, e = L, s = {}) {
11592
- return new n2(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
11593
- }
11594
- getRootString(t) {
11595
- return re.parse(t).root;
11596
- }
11597
- getRoot(t) {
11598
- if (t = Ri(t.toUpperCase()), t === this.root.name)
11599
- return this.root;
11600
- for (let [e, s] of Object.entries(this.roots))
11601
- if (this.sameRoot(t, e))
11602
- return this.roots[t] = s;
11603
- return this.roots[t] = new it(t, this).root;
11604
- }
11605
- sameRoot(t, e = this.root.name) {
11606
- return t = t.toUpperCase().replace(/\//g, "\\").replace($e, "$1\\"), t === e;
11607
- }
11608
- };
11609
- var jt = class n3 extends R {
11610
- splitSep = "/";
11611
- sep = "/";
11612
- constructor(t, e = L, s, i, r, o, h) {
11613
- super(t, e, s, i, r, o, h);
11614
- }
11615
- getRootString(t) {
11616
- return t.startsWith("/") ? "/" : "";
11617
- }
11618
- getRoot(t) {
11619
- return this.root;
11620
- }
11621
- newChild(t, e = L, s = {}) {
11622
- return new n3(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
11623
- }
11624
- };
11625
- var It = class {
11626
- root;
11627
- rootPath;
11628
- roots;
11629
- cwd;
11630
- #t;
11631
- #s;
11632
- #n;
11633
- nocase;
11634
- #r;
11635
- constructor(t = process.cwd(), e, s, { nocase: i, childrenCacheSize: r = 16 * 1024, fs: o = wt } = {}) {
11636
- this.#r = Ue(o), (t instanceof URL || t.startsWith("file://")) && (t = gi(t));
11637
- let h = e.resolve(t);
11638
- this.roots = Object.create(null), this.rootPath = this.parseRootPath(h), this.#t = new Wt, this.#s = new Wt, this.#n = new ne(r);
11639
- let a = h.substring(this.rootPath.length).split(s);
11640
- if (a.length === 1 && !a[0] && a.pop(), i === undefined)
11641
- throw new TypeError("must provide nocase setting to PathScurryBase ctor");
11642
- this.nocase = i, this.root = this.newRoot(this.#r), this.roots[this.rootPath] = this.root;
11643
- let l = this.root, u = a.length - 1, c = e.sep, d = this.rootPath, f = false;
11644
- for (let m of a) {
11645
- let p = u--;
11646
- l = l.child(m, { relative: new Array(p).fill("..").join(c), relativePosix: new Array(p).fill("..").join("/"), fullpath: d += (f ? "" : c) + m }), f = true;
11647
- }
11648
- this.cwd = l;
11649
- }
11650
- depth(t = this.cwd) {
11651
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.depth();
11652
- }
11653
- childrenCache() {
11654
- return this.#n;
11655
- }
11656
- resolve(...t) {
11657
- let e = "";
11658
- for (let r = t.length - 1;r >= 0; r--) {
11659
- let o = t[r];
11660
- if (!(!o || o === ".") && (e = e ? `${o}/${e}` : o, this.isAbsolute(o)))
11661
- break;
11662
- }
11663
- let s = this.#t.get(e);
11664
- if (s !== undefined)
11665
- return s;
11666
- let i = this.cwd.resolve(e).fullpath();
11667
- return this.#t.set(e, i), i;
11668
- }
11669
- resolvePosix(...t) {
11670
- let e = "";
11671
- for (let r = t.length - 1;r >= 0; r--) {
11672
- let o = t[r];
11673
- if (!(!o || o === ".") && (e = e ? `${o}/${e}` : o, this.isAbsolute(o)))
11674
- break;
11675
- }
11676
- let s = this.#s.get(e);
11677
- if (s !== undefined)
11678
- return s;
11679
- let i = this.cwd.resolve(e).fullpathPosix();
11680
- return this.#s.set(e, i), i;
11681
- }
11682
- relative(t = this.cwd) {
11683
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.relative();
11684
- }
11685
- relativePosix(t = this.cwd) {
11686
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.relativePosix();
11687
- }
11688
- basename(t = this.cwd) {
11689
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.name;
11690
- }
11691
- dirname(t = this.cwd) {
11692
- return typeof t == "string" && (t = this.cwd.resolve(t)), (t.parent || t).fullpath();
11693
- }
11694
- async readdir(t = this.cwd, e = { withFileTypes: true }) {
11695
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11696
- let { withFileTypes: s } = e;
11697
- if (t.canReaddir()) {
11698
- let i = await t.readdir();
11699
- return s ? i : i.map((r) => r.name);
11700
- } else
11701
- return [];
11702
- }
11703
- readdirSync(t = this.cwd, e = { withFileTypes: true }) {
11704
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11705
- let { withFileTypes: s = true } = e;
11706
- return t.canReaddir() ? s ? t.readdirSync() : t.readdirSync().map((i) => i.name) : [];
11707
- }
11708
- async lstat(t = this.cwd) {
11709
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.lstat();
11710
- }
11711
- lstatSync(t = this.cwd) {
11712
- return typeof t == "string" && (t = this.cwd.resolve(t)), t.lstatSync();
11713
- }
11714
- async readlink(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
11715
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
11716
- let s = await t.readlink();
11717
- return e ? s : s?.fullpath();
11718
- }
11719
- readlinkSync(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
11720
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
11721
- let s = t.readlinkSync();
11722
- return e ? s : s?.fullpath();
11723
- }
11724
- async realpath(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
11725
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
11726
- let s = await t.realpath();
11727
- return e ? s : s?.fullpath();
11728
- }
11729
- realpathSync(t = this.cwd, { withFileTypes: e } = { withFileTypes: false }) {
11730
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t.withFileTypes, t = this.cwd);
11731
- let s = t.realpathSync();
11732
- return e ? s : s?.fullpath();
11733
- }
11734
- async walk(t = this.cwd, e = {}) {
11735
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11736
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = [];
11737
- (!r || r(t)) && h.push(s ? t : t.fullpath());
11738
- let a = new Set, l = (c, d) => {
11739
- a.add(c), c.readdirCB((f, m) => {
11740
- if (f)
11741
- return d(f);
11742
- let p = m.length;
11743
- if (!p)
11744
- return d();
11745
- let w = () => {
11746
- --p === 0 && d();
11747
- };
11748
- for (let g of m)
11749
- (!r || r(g)) && h.push(s ? g : g.fullpath()), i && g.isSymbolicLink() ? g.realpath().then((S) => S?.isUnknown() ? S.lstat() : S).then((S) => S?.shouldWalk(a, o) ? l(S, w) : w()) : g.shouldWalk(a, o) ? l(g, w) : w();
11750
- }, true);
11751
- }, u = t;
11752
- return new Promise((c, d) => {
11753
- l(u, (f) => {
11754
- if (f)
11755
- return d(f);
11756
- c(h);
11757
- });
11758
- });
11759
- }
11760
- walkSync(t = this.cwd, e = {}) {
11761
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11762
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = [];
11763
- (!r || r(t)) && h.push(s ? t : t.fullpath());
11764
- let a = new Set([t]);
11765
- for (let l of a) {
11766
- let u = l.readdirSync();
11767
- for (let c of u) {
11768
- (!r || r(c)) && h.push(s ? c : c.fullpath());
11769
- let d = c;
11770
- if (c.isSymbolicLink()) {
11771
- if (!(i && (d = c.realpathSync())))
11772
- continue;
11773
- d.isUnknown() && d.lstatSync();
11774
- }
11775
- d.shouldWalk(a, o) && a.add(d);
11776
- }
11777
- }
11778
- return h;
11779
- }
11780
- [Symbol.asyncIterator]() {
11781
- return this.iterate();
11782
- }
11783
- iterate(t = this.cwd, e = {}) {
11784
- return typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd), this.stream(t, e)[Symbol.asyncIterator]();
11785
- }
11786
- [Symbol.iterator]() {
11787
- return this.iterateSync();
11788
- }
11789
- *iterateSync(t = this.cwd, e = {}) {
11790
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11791
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e;
11792
- (!r || r(t)) && (yield s ? t : t.fullpath());
11793
- let h = new Set([t]);
11794
- for (let a of h) {
11795
- let l = a.readdirSync();
11796
- for (let u of l) {
11797
- (!r || r(u)) && (yield s ? u : u.fullpath());
11798
- let c = u;
11799
- if (u.isSymbolicLink()) {
11800
- if (!(i && (c = u.realpathSync())))
11801
- continue;
11802
- c.isUnknown() && c.lstatSync();
11803
- }
11804
- c.shouldWalk(h, o) && h.add(c);
11805
- }
11806
- }
11807
- }
11808
- stream(t = this.cwd, e = {}) {
11809
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11810
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = new V({ objectMode: true });
11811
- (!r || r(t)) && h.write(s ? t : t.fullpath());
11812
- let a = new Set, l = [t], u = 0, c = () => {
11813
- let d = false;
11814
- for (;!d; ) {
11815
- let f = l.shift();
11816
- if (!f) {
11817
- u === 0 && h.end();
11818
- return;
11819
- }
11820
- u++, a.add(f);
11821
- let m = (w, g, S = false) => {
11822
- if (w)
11823
- return h.emit("error", w);
11824
- if (i && !S) {
11825
- let E = [];
11826
- for (let y of g)
11827
- y.isSymbolicLink() && E.push(y.realpath().then((b) => b?.isUnknown() ? b.lstat() : b));
11828
- if (E.length) {
11829
- Promise.all(E).then(() => m(null, g, true));
11830
- return;
11831
- }
11832
- }
11833
- for (let E of g)
11834
- E && (!r || r(E)) && (h.write(s ? E : E.fullpath()) || (d = true));
11835
- u--;
11836
- for (let E of g) {
11837
- let y = E.realpathCached() || E;
11838
- y.shouldWalk(a, o) && l.push(y);
11839
- }
11840
- d && !h.flowing ? h.once("drain", c) : p || c();
11841
- }, p = true;
11842
- f.readdirCB(m, true), p = false;
11843
- }
11844
- };
11845
- return c(), h;
11846
- }
11847
- streamSync(t = this.cwd, e = {}) {
11848
- typeof t == "string" ? t = this.cwd.resolve(t) : t instanceof R || (e = t, t = this.cwd);
11849
- let { withFileTypes: s = true, follow: i = false, filter: r, walkFilter: o } = e, h = new V({ objectMode: true }), a = new Set;
11850
- (!r || r(t)) && h.write(s ? t : t.fullpath());
11851
- let l = [t], u = 0, c = () => {
11852
- let d = false;
11853
- for (;!d; ) {
11854
- let f = l.shift();
11855
- if (!f) {
11856
- u === 0 && h.end();
11857
- return;
11858
- }
11859
- u++, a.add(f);
11860
- let m = f.readdirSync();
11861
- for (let p of m)
11862
- (!r || r(p)) && (h.write(s ? p : p.fullpath()) || (d = true));
11863
- u--;
11864
- for (let p of m) {
11865
- let w = p;
11866
- if (p.isSymbolicLink()) {
11867
- if (!(i && (w = p.realpathSync())))
11868
- continue;
11869
- w.isUnknown() && w.lstatSync();
11870
- }
11871
- w.shouldWalk(a, o) && l.push(w);
11872
- }
11873
- }
11874
- d && !h.flowing && h.once("drain", c);
11875
- };
11876
- return c(), h;
11877
- }
11878
- chdir(t = this.cwd) {
11879
- let e = this.cwd;
11880
- this.cwd = typeof t == "string" ? this.cwd.resolve(t) : t, this.cwd[Ye](e);
11881
- }
11882
- };
11883
- var it = class extends It {
11884
- sep = "\\";
11885
- constructor(t = process.cwd(), e = {}) {
11886
- let { nocase: s = true } = e;
11887
- super(t, re, "\\", { ...e, nocase: s }), this.nocase = s;
11888
- for (let i = this.cwd;i; i = i.parent)
11889
- i.nocase = this.nocase;
11890
- }
11891
- parseRootPath(t) {
11892
- return re.parse(t).root.toUpperCase();
11893
- }
11894
- newRoot(t) {
11895
- return new Pt(this.rootPath, U, undefined, this.roots, this.nocase, this.childrenCache(), { fs: t });
11896
- }
11897
- isAbsolute(t) {
11898
- return t.startsWith("/") || t.startsWith("\\") || /^[a-z]:(\/|\\)/i.test(t);
11899
- }
11900
- };
11901
- var rt = class extends It {
11902
- sep = "/";
11903
- constructor(t = process.cwd(), e = {}) {
11904
- let { nocase: s = false } = e;
11905
- super(t, mi, "/", { ...e, nocase: s }), this.nocase = s;
11906
- }
11907
- parseRootPath(t) {
11908
- return "/";
11909
- }
11910
- newRoot(t) {
11911
- return new jt(this.rootPath, U, undefined, this.roots, this.nocase, this.childrenCache(), { fs: t });
11912
- }
11913
- isAbsolute(t) {
11914
- return t.startsWith("/");
11915
- }
11916
- };
11917
- var St = class extends rt {
11918
- constructor(t = process.cwd(), e = {}) {
11919
- let { nocase: s = true } = e;
11920
- super(t, { ...e, nocase: s });
11921
- }
11922
- };
11923
- var Cr = process.platform === "win32" ? Pt : jt;
11924
- var Xe = process.platform === "win32" ? it : process.platform === "darwin" ? St : rt;
11925
- var Di = (n4) => n4.length >= 1;
11926
- var Mi = (n4) => n4.length >= 1;
11927
- var Ni = Symbol.for("nodejs.util.inspect.custom");
11928
- var nt = class n4 {
11929
- #t;
11930
- #s;
11931
- #n;
11932
- length;
11933
- #r;
11934
- #o;
11935
- #S;
11936
- #w;
11937
- #c;
11938
- #h;
11939
- #u = true;
11940
- constructor(t, e, s, i) {
11941
- if (!Di(t))
11942
- throw new TypeError("empty pattern list");
11943
- if (!Mi(e))
11944
- throw new TypeError("empty glob list");
11945
- if (e.length !== t.length)
11946
- throw new TypeError("mismatched pattern list and glob list lengths");
11947
- if (this.length = t.length, s < 0 || s >= this.length)
11948
- throw new TypeError("index out of range");
11949
- if (this.#t = t, this.#s = e, this.#n = s, this.#r = i, this.#n === 0) {
11950
- if (this.isUNC()) {
11951
- let [r, o, h, a, ...l] = this.#t, [u, c, d, f, ...m] = this.#s;
11952
- l[0] === "" && (l.shift(), m.shift());
11953
- let p = [r, o, h, a, ""].join("/"), w = [u, c, d, f, ""].join("/");
11954
- this.#t = [p, ...l], this.#s = [w, ...m], this.length = this.#t.length;
11955
- } else if (this.isDrive() || this.isAbsolute()) {
11956
- let [r, ...o] = this.#t, [h, ...a] = this.#s;
11957
- o[0] === "" && (o.shift(), a.shift());
11958
- let l = r + "/", u = h + "/";
11959
- this.#t = [l, ...o], this.#s = [u, ...a], this.length = this.#t.length;
11960
- }
11961
- }
11962
- }
11963
- [Ni]() {
11964
- return "Pattern <" + this.#s.slice(this.#n).join("/") + ">";
11965
- }
11966
- pattern() {
11967
- return this.#t[this.#n];
11968
- }
11969
- isString() {
11970
- return typeof this.#t[this.#n] == "string";
11971
- }
11972
- isGlobstar() {
11973
- return this.#t[this.#n] === A;
11974
- }
11975
- isRegExp() {
11976
- return this.#t[this.#n] instanceof RegExp;
11977
- }
11978
- globString() {
11979
- return this.#S = this.#S || (this.#n === 0 ? this.isAbsolute() ? this.#s[0] + this.#s.slice(1).join("/") : this.#s.join("/") : this.#s.slice(this.#n).join("/"));
11980
- }
11981
- hasMore() {
11982
- return this.length > this.#n + 1;
11983
- }
11984
- rest() {
11985
- return this.#o !== undefined ? this.#o : this.hasMore() ? (this.#o = new n4(this.#t, this.#s, this.#n + 1, this.#r), this.#o.#h = this.#h, this.#o.#c = this.#c, this.#o.#w = this.#w, this.#o) : this.#o = null;
11986
- }
11987
- isUNC() {
11988
- let t = this.#t;
11989
- return this.#c !== undefined ? this.#c : this.#c = this.#r === "win32" && this.#n === 0 && t[0] === "" && t[1] === "" && typeof t[2] == "string" && !!t[2] && typeof t[3] == "string" && !!t[3];
11990
- }
11991
- isDrive() {
11992
- let t = this.#t;
11993
- return this.#w !== undefined ? this.#w : this.#w = this.#r === "win32" && this.#n === 0 && this.length > 1 && typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]);
11994
- }
11995
- isAbsolute() {
11996
- let t = this.#t;
11997
- return this.#h !== undefined ? this.#h : this.#h = t[0] === "" && t.length > 1 || this.isDrive() || this.isUNC();
11998
- }
11999
- root() {
12000
- let t = this.#t[0];
12001
- return typeof t == "string" && this.isAbsolute() && this.#n === 0 ? t : "";
12002
- }
12003
- checkFollowGlobstar() {
12004
- return !(this.#n === 0 || !this.isGlobstar() || !this.#u);
12005
- }
12006
- markFollowGlobstar() {
12007
- return this.#n === 0 || !this.isGlobstar() || !this.#u ? false : (this.#u = false, true);
12008
- }
12009
- };
12010
- var _i = typeof process == "object" && process && typeof process.platform == "string" ? process.platform : "linux";
12011
- var ot = class {
12012
- relative;
12013
- relativeChildren;
12014
- absolute;
12015
- absoluteChildren;
12016
- platform;
12017
- mmopts;
12018
- constructor(t, { nobrace: e, nocase: s, noext: i, noglobstar: r, platform: o = _i }) {
12019
- this.relative = [], this.absolute = [], this.relativeChildren = [], this.absoluteChildren = [], this.platform = o, this.mmopts = { dot: true, nobrace: e, nocase: s, noext: i, noglobstar: r, optimizationLevel: 2, platform: o, nocomment: true, nonegate: true };
12020
- for (let h of t)
12021
- this.add(h);
12022
- }
12023
- add(t) {
12024
- let e = new D(t, this.mmopts);
12025
- for (let s = 0;s < e.set.length; s++) {
12026
- let i = e.set[s], r = e.globParts[s];
12027
- if (!i || !r)
12028
- throw new Error("invalid pattern object");
12029
- for (;i[0] === "." && r[0] === "."; )
12030
- i.shift(), r.shift();
12031
- let o = new nt(i, r, 0, this.platform), h = new D(o.globString(), this.mmopts), a = r[r.length - 1] === "**", l = o.isAbsolute();
12032
- l ? this.absolute.push(h) : this.relative.push(h), a && (l ? this.absoluteChildren.push(h) : this.relativeChildren.push(h));
12033
- }
12034
- }
12035
- ignored(t) {
12036
- let e = t.fullpath(), s = `${e}/`, i = t.relative() || ".", r = `${i}/`;
12037
- for (let o of this.relative)
12038
- if (o.match(i) || o.match(r))
12039
- return true;
12040
- for (let o of this.absolute)
12041
- if (o.match(e) || o.match(s))
12042
- return true;
12043
- return false;
12044
- }
12045
- childrenIgnored(t) {
12046
- let e = t.fullpath() + "/", s = (t.relative() || ".") + "/";
12047
- for (let i of this.relativeChildren)
12048
- if (i.match(s))
12049
- return true;
12050
- for (let i of this.absoluteChildren)
12051
- if (i.match(e))
12052
- return true;
12053
- return false;
12054
- }
12055
- };
12056
- var oe = class n5 {
12057
- store;
12058
- constructor(t = new Map) {
12059
- this.store = t;
12060
- }
12061
- copy() {
12062
- return new n5(new Map(this.store));
12063
- }
12064
- hasWalked(t, e) {
12065
- return this.store.get(t.fullpath())?.has(e.globString());
12066
- }
12067
- storeWalked(t, e) {
12068
- let s = t.fullpath(), i = this.store.get(s);
12069
- i ? i.add(e.globString()) : this.store.set(s, new Set([e.globString()]));
12070
- }
12071
- };
12072
- var he = class {
12073
- store = new Map;
12074
- add(t, e, s) {
12075
- let i = (e ? 2 : 0) | (s ? 1 : 0), r = this.store.get(t);
12076
- this.store.set(t, r === undefined ? i : i & r);
12077
- }
12078
- entries() {
12079
- return [...this.store.entries()].map(([t, e]) => [t, !!(e & 2), !!(e & 1)]);
12080
- }
12081
- };
12082
- var ae = class {
12083
- store = new Map;
12084
- add(t, e) {
12085
- if (!t.canReaddir())
12086
- return;
12087
- let s = this.store.get(t);
12088
- s ? s.find((i) => i.globString() === e.globString()) || s.push(e) : this.store.set(t, [e]);
12089
- }
12090
- get(t) {
12091
- let e = this.store.get(t);
12092
- if (!e)
12093
- throw new Error("attempting to walk unknown path");
12094
- return e;
12095
- }
12096
- entries() {
12097
- return this.keys().map((t) => [t, this.store.get(t)]);
12098
- }
12099
- keys() {
12100
- return [...this.store.keys()].filter((t) => t.canReaddir());
12101
- }
12102
- };
12103
- var Et = class n6 {
12104
- hasWalkedCache;
12105
- matches = new he;
12106
- subwalks = new ae;
12107
- patterns;
12108
- follow;
12109
- dot;
12110
- opts;
12111
- constructor(t, e) {
12112
- this.opts = t, this.follow = !!t.follow, this.dot = !!t.dot, this.hasWalkedCache = e ? e.copy() : new oe;
12113
- }
12114
- processPatterns(t, e) {
12115
- this.patterns = e;
12116
- let s = e.map((i) => [t, i]);
12117
- for (let [i, r] of s) {
12118
- this.hasWalkedCache.storeWalked(i, r);
12119
- let o = r.root(), h = r.isAbsolute() && this.opts.absolute !== false;
12120
- if (o) {
12121
- i = i.resolve(o === "/" && this.opts.root !== undefined ? this.opts.root : o);
12122
- let c = r.rest();
12123
- if (c)
12124
- r = c;
12125
- else {
12126
- this.matches.add(i, true, false);
12127
- continue;
12128
- }
12129
- }
12130
- if (i.isENOENT())
12131
- continue;
12132
- let a, l, u = false;
12133
- for (;typeof (a = r.pattern()) == "string" && (l = r.rest()); )
12134
- i = i.resolve(a), r = l, u = true;
12135
- if (a = r.pattern(), l = r.rest(), u) {
12136
- if (this.hasWalkedCache.hasWalked(i, r))
12137
- continue;
12138
- this.hasWalkedCache.storeWalked(i, r);
12139
- }
12140
- if (typeof a == "string") {
12141
- let c = a === ".." || a === "" || a === ".";
12142
- this.matches.add(i.resolve(a), h, c);
12143
- continue;
12144
- } else if (a === A) {
12145
- (!i.isSymbolicLink() || this.follow || r.checkFollowGlobstar()) && this.subwalks.add(i, r);
12146
- let c = l?.pattern(), d = l?.rest();
12147
- if (!l || (c === "" || c === ".") && !d)
12148
- this.matches.add(i, h, c === "" || c === ".");
12149
- else if (c === "..") {
12150
- let f = i.parent || i;
12151
- d ? this.hasWalkedCache.hasWalked(f, d) || this.subwalks.add(f, d) : this.matches.add(f, h, true);
12152
- }
12153
- } else
12154
- a instanceof RegExp && this.subwalks.add(i, r);
12155
- }
12156
- return this;
12157
- }
12158
- subwalkTargets() {
12159
- return this.subwalks.keys();
12160
- }
12161
- child() {
12162
- return new n6(this.opts, this.hasWalkedCache);
12163
- }
12164
- filterEntries(t, e) {
12165
- let s = this.subwalks.get(t), i = this.child();
12166
- for (let r of e)
12167
- for (let o of s) {
12168
- let h = o.isAbsolute(), a = o.pattern(), l = o.rest();
12169
- a === A ? i.testGlobstar(r, o, l, h) : a instanceof RegExp ? i.testRegExp(r, a, l, h) : i.testString(r, a, l, h);
12170
- }
12171
- return i;
12172
- }
12173
- testGlobstar(t, e, s, i) {
12174
- if ((this.dot || !t.name.startsWith(".")) && (e.hasMore() || this.matches.add(t, i, false), t.canReaddir() && (this.follow || !t.isSymbolicLink() ? this.subwalks.add(t, e) : t.isSymbolicLink() && (s && e.checkFollowGlobstar() ? this.subwalks.add(t, s) : e.markFollowGlobstar() && this.subwalks.add(t, e)))), s) {
12175
- let r = s.pattern();
12176
- if (typeof r == "string" && r !== ".." && r !== "" && r !== ".")
12177
- this.testString(t, r, s.rest(), i);
12178
- else if (r === "..") {
12179
- let o = t.parent || t;
12180
- this.subwalks.add(o, s);
12181
- } else
12182
- r instanceof RegExp && this.testRegExp(t, r, s.rest(), i);
12183
- }
12184
- }
12185
- testRegExp(t, e, s, i) {
12186
- e.test(t.name) && (s ? this.subwalks.add(t, s) : this.matches.add(t, i, false));
12187
- }
12188
- testString(t, e, s, i) {
12189
- t.isNamed(e) && (s ? this.subwalks.add(t, s) : this.matches.add(t, i, false));
12190
- }
12191
- };
12192
- var Li = (n7, t) => typeof n7 == "string" ? new ot([n7], t) : Array.isArray(n7) ? new ot(n7, t) : n7;
12193
- var zt = class {
12194
- path;
12195
- patterns;
12196
- opts;
12197
- seen = new Set;
12198
- paused = false;
12199
- aborted = false;
12200
- #t = [];
12201
- #s;
12202
- #n;
12203
- signal;
12204
- maxDepth;
12205
- includeChildMatches;
12206
- constructor(t, e, s) {
12207
- if (this.patterns = t, this.path = e, this.opts = s, this.#n = !s.posix && s.platform === "win32" ? "\\" : "/", this.includeChildMatches = s.includeChildMatches !== false, (s.ignore || !this.includeChildMatches) && (this.#s = Li(s.ignore ?? [], s), !this.includeChildMatches && typeof this.#s.add != "function")) {
12208
- let i = "cannot ignore child matches, ignore lacks add() method.";
12209
- throw new Error(i);
12210
- }
12211
- this.maxDepth = s.maxDepth || 1 / 0, s.signal && (this.signal = s.signal, this.signal.addEventListener("abort", () => {
12212
- this.#t.length = 0;
12213
- }));
12214
- }
12215
- #r(t) {
12216
- return this.seen.has(t) || !!this.#s?.ignored?.(t);
12217
- }
12218
- #o(t) {
12219
- return !!this.#s?.childrenIgnored?.(t);
12220
- }
12221
- pause() {
12222
- this.paused = true;
12223
- }
12224
- resume() {
12225
- if (this.signal?.aborted)
12226
- return;
12227
- this.paused = false;
12228
- let t;
12229
- for (;!this.paused && (t = this.#t.shift()); )
12230
- t();
12231
- }
12232
- onResume(t) {
12233
- this.signal?.aborted || (this.paused ? this.#t.push(t) : t());
12234
- }
12235
- async matchCheck(t, e) {
12236
- if (e && this.opts.nodir)
12237
- return;
12238
- let s;
12239
- if (this.opts.realpath) {
12240
- if (s = t.realpathCached() || await t.realpath(), !s)
12241
- return;
12242
- t = s;
12243
- }
12244
- let r = t.isUnknown() || this.opts.stat ? await t.lstat() : t;
12245
- if (this.opts.follow && this.opts.nodir && r?.isSymbolicLink()) {
12246
- let o = await r.realpath();
12247
- o && (o.isUnknown() || this.opts.stat) && await o.lstat();
12248
- }
12249
- return this.matchCheckTest(r, e);
12250
- }
12251
- matchCheckTest(t, e) {
12252
- return t && (this.maxDepth === 1 / 0 || t.depth() <= this.maxDepth) && (!e || t.canReaddir()) && (!this.opts.nodir || !t.isDirectory()) && (!this.opts.nodir || !this.opts.follow || !t.isSymbolicLink() || !t.realpathCached()?.isDirectory()) && !this.#r(t) ? t : undefined;
12253
- }
12254
- matchCheckSync(t, e) {
12255
- if (e && this.opts.nodir)
12256
- return;
12257
- let s;
12258
- if (this.opts.realpath) {
12259
- if (s = t.realpathCached() || t.realpathSync(), !s)
12260
- return;
12261
- t = s;
12262
- }
12263
- let r = t.isUnknown() || this.opts.stat ? t.lstatSync() : t;
12264
- if (this.opts.follow && this.opts.nodir && r?.isSymbolicLink()) {
12265
- let o = r.realpathSync();
12266
- o && (o?.isUnknown() || this.opts.stat) && o.lstatSync();
12267
- }
12268
- return this.matchCheckTest(r, e);
12269
- }
12270
- matchFinish(t, e) {
12271
- if (this.#r(t))
12272
- return;
12273
- if (!this.includeChildMatches && this.#s?.add) {
12274
- let r = `${t.relativePosix()}/**`;
12275
- this.#s.add(r);
12276
- }
12277
- let s = this.opts.absolute === undefined ? e : this.opts.absolute;
12278
- this.seen.add(t);
12279
- let i = this.opts.mark && t.isDirectory() ? this.#n : "";
12280
- if (this.opts.withFileTypes)
12281
- this.matchEmit(t);
12282
- else if (s) {
12283
- let r = this.opts.posix ? t.fullpathPosix() : t.fullpath();
12284
- this.matchEmit(r + i);
12285
- } else {
12286
- let r = this.opts.posix ? t.relativePosix() : t.relative(), o = this.opts.dotRelative && !r.startsWith(".." + this.#n) ? "." + this.#n : "";
12287
- this.matchEmit(r ? o + r + i : "." + i);
12288
- }
12289
- }
12290
- async match(t, e, s) {
12291
- let i = await this.matchCheck(t, s);
12292
- i && this.matchFinish(i, e);
12293
- }
12294
- matchSync(t, e, s) {
12295
- let i = this.matchCheckSync(t, s);
12296
- i && this.matchFinish(i, e);
12297
- }
12298
- walkCB(t, e, s) {
12299
- this.signal?.aborted && s(), this.walkCB2(t, e, new Et(this.opts), s);
12300
- }
12301
- walkCB2(t, e, s, i) {
12302
- if (this.#o(t))
12303
- return i();
12304
- if (this.signal?.aborted && i(), this.paused) {
12305
- this.onResume(() => this.walkCB2(t, e, s, i));
12306
- return;
12307
- }
12308
- s.processPatterns(t, e);
12309
- let r = 1, o = () => {
12310
- --r === 0 && i();
12311
- };
12312
- for (let [h, a, l] of s.matches.entries())
12313
- this.#r(h) || (r++, this.match(h, a, l).then(() => o()));
12314
- for (let h of s.subwalkTargets()) {
12315
- if (this.maxDepth !== 1 / 0 && h.depth() >= this.maxDepth)
12316
- continue;
12317
- r++;
12318
- let a = h.readdirCached();
12319
- h.calledReaddir() ? this.walkCB3(h, a, s, o) : h.readdirCB((l, u) => this.walkCB3(h, u, s, o), true);
12320
- }
12321
- o();
12322
- }
12323
- walkCB3(t, e, s, i) {
12324
- s = s.filterEntries(t, e);
12325
- let r = 1, o = () => {
12326
- --r === 0 && i();
12327
- };
12328
- for (let [h, a, l] of s.matches.entries())
12329
- this.#r(h) || (r++, this.match(h, a, l).then(() => o()));
12330
- for (let [h, a] of s.subwalks.entries())
12331
- r++, this.walkCB2(h, a, s.child(), o);
12332
- o();
12333
- }
12334
- walkCBSync(t, e, s) {
12335
- this.signal?.aborted && s(), this.walkCB2Sync(t, e, new Et(this.opts), s);
12336
- }
12337
- walkCB2Sync(t, e, s, i) {
12338
- if (this.#o(t))
12339
- return i();
12340
- if (this.signal?.aborted && i(), this.paused) {
12341
- this.onResume(() => this.walkCB2Sync(t, e, s, i));
12342
- return;
12343
- }
12344
- s.processPatterns(t, e);
12345
- let r = 1, o = () => {
12346
- --r === 0 && i();
12347
- };
12348
- for (let [h, a, l] of s.matches.entries())
12349
- this.#r(h) || this.matchSync(h, a, l);
12350
- for (let h of s.subwalkTargets()) {
12351
- if (this.maxDepth !== 1 / 0 && h.depth() >= this.maxDepth)
12352
- continue;
12353
- r++;
12354
- let a = h.readdirSync();
12355
- this.walkCB3Sync(h, a, s, o);
12356
- }
12357
- o();
12358
- }
12359
- walkCB3Sync(t, e, s, i) {
12360
- s = s.filterEntries(t, e);
12361
- let r = 1, o = () => {
12362
- --r === 0 && i();
12363
- };
12364
- for (let [h, a, l] of s.matches.entries())
12365
- this.#r(h) || this.matchSync(h, a, l);
12366
- for (let [h, a] of s.subwalks.entries())
12367
- r++, this.walkCB2Sync(h, a, s.child(), o);
12368
- o();
12369
- }
12370
- };
12371
- var xt = class extends zt {
12372
- matches = new Set;
12373
- constructor(t, e, s) {
12374
- super(t, e, s);
12375
- }
12376
- matchEmit(t) {
12377
- this.matches.add(t);
12378
- }
12379
- async walk() {
12380
- if (this.signal?.aborted)
12381
- throw this.signal.reason;
12382
- return this.path.isUnknown() && await this.path.lstat(), await new Promise((t, e) => {
12383
- this.walkCB(this.path, this.patterns, () => {
12384
- this.signal?.aborted ? e(this.signal.reason) : t(this.matches);
12385
- });
12386
- }), this.matches;
12387
- }
12388
- walkSync() {
12389
- if (this.signal?.aborted)
12390
- throw this.signal.reason;
12391
- return this.path.isUnknown() && this.path.lstatSync(), this.walkCBSync(this.path, this.patterns, () => {
12392
- if (this.signal?.aborted)
12393
- throw this.signal.reason;
12394
- }), this.matches;
12395
- }
12396
- };
12397
- var vt = class extends zt {
12398
- results;
12399
- constructor(t, e, s) {
12400
- super(t, e, s), this.results = new V({ signal: this.signal, objectMode: true }), this.results.on("drain", () => this.resume()), this.results.on("resume", () => this.resume());
12401
- }
12402
- matchEmit(t) {
12403
- this.results.write(t), this.results.flowing || this.pause();
12404
- }
12405
- stream() {
12406
- let t = this.path;
12407
- return t.isUnknown() ? t.lstat().then(() => {
12408
- this.walkCB(t, this.patterns, () => this.results.end());
12409
- }) : this.walkCB(t, this.patterns, () => this.results.end()), this.results;
12410
- }
12411
- streamSync() {
12412
- return this.path.isUnknown() && this.path.lstatSync(), this.walkCBSync(this.path, this.patterns, () => this.results.end()), this.results;
12413
- }
12414
- };
12415
- var Pi = typeof process == "object" && process && typeof process.platform == "string" ? process.platform : "linux";
12416
- var I = class {
12417
- absolute;
12418
- cwd;
12419
- root;
12420
- dot;
12421
- dotRelative;
12422
- follow;
12423
- ignore;
12424
- magicalBraces;
12425
- mark;
12426
- matchBase;
12427
- maxDepth;
12428
- nobrace;
12429
- nocase;
12430
- nodir;
12431
- noext;
12432
- noglobstar;
12433
- pattern;
12434
- platform;
12435
- realpath;
12436
- scurry;
12437
- stat;
12438
- signal;
12439
- windowsPathsNoEscape;
12440
- withFileTypes;
12441
- includeChildMatches;
12442
- opts;
12443
- patterns;
12444
- constructor(t, e) {
12445
- if (!e)
12446
- throw new TypeError("glob options required");
12447
- if (this.withFileTypes = !!e.withFileTypes, this.signal = e.signal, this.follow = !!e.follow, this.dot = !!e.dot, this.dotRelative = !!e.dotRelative, this.nodir = !!e.nodir, this.mark = !!e.mark, e.cwd ? (e.cwd instanceof URL || e.cwd.startsWith("file://")) && (e.cwd = Wi(e.cwd)) : this.cwd = "", this.cwd = e.cwd || "", this.root = e.root, this.magicalBraces = !!e.magicalBraces, this.nobrace = !!e.nobrace, this.noext = !!e.noext, this.realpath = !!e.realpath, this.absolute = e.absolute, this.includeChildMatches = e.includeChildMatches !== false, this.noglobstar = !!e.noglobstar, this.matchBase = !!e.matchBase, this.maxDepth = typeof e.maxDepth == "number" ? e.maxDepth : 1 / 0, this.stat = !!e.stat, this.ignore = e.ignore, this.withFileTypes && this.absolute !== undefined)
12448
- throw new Error("cannot set absolute and withFileTypes:true");
12449
- if (typeof t == "string" && (t = [t]), this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === false, this.windowsPathsNoEscape && (t = t.map((a) => a.replace(/\\/g, "/"))), this.matchBase) {
12450
- if (e.noglobstar)
12451
- throw new TypeError("base matching requires globstar");
12452
- t = t.map((a) => a.includes("/") ? a : `./**/${a}`);
12453
- }
12454
- if (this.pattern = t, this.platform = e.platform || Pi, this.opts = { ...e, platform: this.platform }, e.scurry) {
12455
- if (this.scurry = e.scurry, e.nocase !== undefined && e.nocase !== e.scurry.nocase)
12456
- throw new Error("nocase option contradicts provided scurry option");
12457
- } else {
12458
- let a = e.platform === "win32" ? it : e.platform === "darwin" ? St : e.platform ? rt : Xe;
12459
- this.scurry = new a(this.cwd, { nocase: e.nocase, fs: e.fs });
12460
- }
12461
- this.nocase = this.scurry.nocase;
12462
- let s = this.platform === "darwin" || this.platform === "win32", i = { braceExpandMax: 1e4, ...e, dot: this.dot, matchBase: this.matchBase, nobrace: this.nobrace, nocase: this.nocase, nocaseMagicOnly: s, nocomment: true, noext: this.noext, nonegate: true, optimizationLevel: 2, platform: this.platform, windowsPathsNoEscape: this.windowsPathsNoEscape, debug: !!this.opts.debug }, r = this.pattern.map((a) => new D(a, i)), [o, h] = r.reduce((a, l) => (a[0].push(...l.set), a[1].push(...l.globParts), a), [[], []]);
12463
- this.patterns = o.map((a, l) => {
12464
- let u = h[l];
12465
- if (!u)
12466
- throw new Error("invalid pattern object");
12467
- return new nt(a, u, 0, this.platform);
12468
- });
12469
- }
12470
- async walk() {
12471
- return [...await new xt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).walk()];
12472
- }
12473
- walkSync() {
12474
- return [...new xt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).walkSync()];
12475
- }
12476
- stream() {
12477
- return new vt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).stream();
12478
- }
12479
- streamSync() {
12480
- return new vt(this.patterns, this.scurry.cwd, { ...this.opts, maxDepth: this.maxDepth !== 1 / 0 ? this.maxDepth + this.scurry.cwd.depth() : 1 / 0, platform: this.platform, nocase: this.nocase, includeChildMatches: this.includeChildMatches }).streamSync();
12481
- }
12482
- iterateSync() {
12483
- return this.streamSync()[Symbol.iterator]();
12484
- }
12485
- [Symbol.iterator]() {
12486
- return this.iterateSync();
12487
- }
12488
- iterate() {
12489
- return this.stream()[Symbol.asyncIterator]();
12490
- }
12491
- [Symbol.asyncIterator]() {
12492
- return this.iterate();
12493
- }
12494
- };
12495
- var le = (n7, t = {}) => {
12496
- Array.isArray(n7) || (n7 = [n7]);
12497
- for (let e of n7)
12498
- if (new D(e, t).hasMagic())
12499
- return true;
12500
- return false;
12501
- };
12502
- function Bt(n7, t = {}) {
12503
- return new I(n7, t).streamSync();
12504
- }
12505
- function Qe(n7, t = {}) {
12506
- return new I(n7, t).stream();
12507
- }
12508
- function ts(n7, t = {}) {
12509
- return new I(n7, t).walkSync();
12510
- }
12511
- async function Je(n7, t = {}) {
12512
- return new I(n7, t).walk();
12513
- }
12514
- function Ut(n7, t = {}) {
12515
- return new I(n7, t).iterateSync();
12516
- }
12517
- function es(n7, t = {}) {
12518
- return new I(n7, t).iterate();
12519
- }
12520
- var ji = Bt;
12521
- var Ii = Object.assign(Qe, { sync: Bt });
12522
- var zi = Ut;
12523
- var Bi = Object.assign(es, { sync: Ut });
12524
- var Ui = Object.assign(ts, { stream: Bt, iterate: Ut });
12525
- var Ze = Object.assign(Je, { glob: Je, globSync: ts, sync: Ui, globStream: Qe, stream: Ii, globStreamSync: Bt, streamSync: ji, globIterate: es, iterate: Bi, globIterateSync: Ut, iterateSync: zi, Glob: I, hasMagic: le, escape: tt, unescape: W });
12526
- Ze.glob = Ze;
12527
-
12528
- // src/scanner/parsers/typescript.ts
12529
- class TypeScriptParser {
12530
- extensions = [".ts", ".tsx", ".js", ".jsx"];
12531
- async parse(filePath, content) {
12532
- const lines = content.split(`
12533
- `);
12534
- const imports = this.extractImports(content);
12535
- const exports = this.extractExports(content);
12536
- const components = this.extractComponents(filePath, content);
12537
- const hooks = this.extractHooks(filePath, content);
12538
- const file = {
12539
- path: filePath,
12540
- language: filePath.endsWith(".tsx") || filePath.endsWith(".jsx") ? "tsx" : "typescript",
12541
- lines: lines.length,
12542
- exports,
12543
- imports
12544
- };
12545
- const dependencies = imports.map((imp) => ({
12546
- from: filePath,
12547
- to: imp.source,
12548
- specifiers: imp.specifiers
12549
- }));
12550
- return {
12551
- file,
12552
- routes: [],
12553
- components,
12554
- hooks,
12555
- dependencies
12556
- };
12557
- }
12558
- extractImports(content) {
12559
- const imports = [];
12560
- const importRegex = /^import\s+(?:(?:(\w+)|(\{[^}]+\})|\*\s+as\s+(\w+))\s+from\s+)?["']([^"']+)["']/gm;
12561
- let match;
12562
- while ((match = importRegex.exec(content)) !== null) {
12563
- const defaultImport = match[1];
12564
- const namedImports = match[2];
12565
- const namespaceImport = match[3];
12566
- const source = match[4];
12567
- const specifiers = [];
12568
- let isDefault = false;
12569
- if (defaultImport) {
12570
- specifiers.push(defaultImport);
12571
- isDefault = true;
12572
- }
12573
- if (namedImports) {
12574
- const names = namedImports.replace(/[{}]/g, "").split(",").map((s) => s.trim().split(/\s+as\s+/)[0].trim()).filter(Boolean);
12575
- specifiers.push(...names);
12576
- }
12577
- if (namespaceImport) {
12578
- specifiers.push(`* as ${namespaceImport}`);
12579
- }
12580
- imports.push({ source, specifiers, isDefault });
12581
- }
12582
- return imports;
12583
- }
12584
- extractExports(content) {
12585
- const exports = [];
12586
- const namedExportRegex = /^export\s+(?:default\s+)?(?:async\s+)?(?:function|const|let|var|class|type|interface|enum)\s+(\w+)/gm;
12587
- let match;
12588
- while ((match = namedExportRegex.exec(content)) !== null) {
12589
- exports.push(match[1]);
12590
- }
12591
- if (/^export\s+default\s+/m.test(content)) {
12592
- if (!exports.includes("default")) {
12593
- exports.push("default");
12594
- }
12595
- }
12596
- const reExportRegex = /^export\s+\{([^}]+)\}/gm;
12597
- while ((match = reExportRegex.exec(content)) !== null) {
12598
- const names = match[1].split(",").map((s) => s.trim().split(/\s+as\s+/).pop()?.trim()).filter((s) => !!s);
12599
- exports.push(...names);
12600
- }
12601
- return [...new Set(exports)];
12602
- }
12603
- extractComponents(filePath, content) {
12604
- const components = [];
12605
- const isTSX = filePath.endsWith(".tsx") || filePath.endsWith(".jsx");
12606
- if (!isTSX && !content.includes("React.createElement"))
12607
- return components;
12608
- const funcComponentRegex = /(?:export\s+(?:default\s+)?)?(?:async\s+)?function\s+([A-Z]\w+)\s*\(([^)]*)\)/g;
12609
- const arrowComponentRegex = /(?:export\s+(?:default\s+)?)?(?:const|let)\s+([A-Z]\w+)\s*(?::\s*\w+(?:<[^>]+>)?\s*)?=\s*(?:\([^)]*\)|(\w+))\s*(?::\s*\w+(?:<[^>]+>)?\s*)?=>/g;
12610
- let match;
12611
- while ((match = funcComponentRegex.exec(content)) !== null) {
12612
- const name = match[1];
12613
- const paramsStr = match[2];
12614
- components.push({
12615
- name,
12616
- filePath,
12617
- props: this.extractPropsFromParams(paramsStr, content),
12618
- isExported: content.includes("export") && content.substring(Math.max(0, match.index - 30), match.index + match[0].length).includes("export"),
12619
- hasJSX: true,
12620
- hookCalls: this.extractHookCalls(content, match.index)
12621
- });
12622
- }
12623
- while ((match = arrowComponentRegex.exec(content)) !== null) {
12624
- const name = match[1];
12625
- components.push({
12626
- name,
12627
- filePath,
12628
- props: this.extractPropsFromContext(name, content),
12629
- isExported: content.substring(Math.max(0, match.index - 20), match.index + match[0].length).includes("export"),
12630
- hasJSX: true,
12631
- hookCalls: this.extractHookCalls(content, match.index)
12632
- });
12633
- }
12634
- return components;
12635
- }
12636
- extractPropsFromParams(paramsStr, _content) {
12637
- if (!paramsStr.trim())
12638
- return [];
12639
- const destructured = paramsStr.match(/\{\s*([^}]+)\s*\}/);
12640
- if (destructured) {
12641
- return destructured[1].split(",").map((p) => p.trim().split(/[=:]/)[0].trim()).filter(Boolean);
12642
- }
12643
- const typed = paramsStr.match(/(\w+)\s*:\s*(\w+)/);
12644
- if (typed) {
12645
- return [typed[1]];
12646
- }
12647
- return [];
12648
- }
12649
- extractPropsFromContext(componentName, content) {
12650
- const propsTypeRegex = new RegExp(`(?:interface|type)\\s+${componentName}Props\\s*(?:=\\s*)?\\{([^}]+)\\}`);
12651
- const match = content.match(propsTypeRegex);
12652
- if (match) {
12653
- return match[1].split(/[;\n]/).map((line) => line.trim().split(/[?:]/)[0].trim()).filter(Boolean);
12654
- }
12655
- return [];
12656
- }
12657
- extractHookCalls(content, startIndex) {
12658
- const hookCalls = [];
12659
- const bodyStart = content.indexOf("{", startIndex);
12660
- if (bodyStart === -1)
12661
- return hookCalls;
12662
- let depth = 0;
12663
- let bodyEnd = bodyStart;
12664
- for (let i = bodyStart;i < content.length; i++) {
12665
- if (content[i] === "{")
12666
- depth++;
12667
- if (content[i] === "}")
12668
- depth--;
12669
- if (depth === 0) {
12670
- bodyEnd = i;
12671
- break;
12672
- }
12673
- }
12674
- const body = content.substring(bodyStart, bodyEnd);
12675
- const hookRegex = /\b(use\w+)\s*\(/g;
12676
- let match;
12677
- while ((match = hookRegex.exec(body)) !== null) {
12678
- if (!hookCalls.includes(match[1])) {
12679
- hookCalls.push(match[1]);
12680
- }
12681
- }
12682
- return hookCalls;
12683
- }
12684
- extractHooks(filePath, content) {
12685
- const hooks = [];
12686
- const hookDefRegex = /(?:export\s+)?(?:function|const)\s+(use[A-Z]\w+)/g;
12687
- let match;
12688
- while ((match = hookDefRegex.exec(content)) !== null) {
12689
- const name = match[1];
12690
- const bodyStart = content.indexOf("{", match.index);
12691
- if (bodyStart === -1)
12692
- continue;
12693
- const deps = [];
12694
- let depth = 0;
12695
- let bodyEnd = bodyStart;
12696
- for (let i = bodyStart;i < content.length; i++) {
12697
- if (content[i] === "{")
12698
- depth++;
12699
- if (content[i] === "}")
12700
- depth--;
12701
- if (depth === 0) {
12702
- bodyEnd = i;
12703
- break;
12704
- }
12705
- }
12706
- const body = content.substring(bodyStart, bodyEnd);
12707
- const depRegex = /\b(use\w+)\s*\(/g;
12708
- let depMatch;
12709
- while ((depMatch = depRegex.exec(body)) !== null) {
12710
- if (depMatch[1] !== name && !deps.includes(depMatch[1])) {
12711
- deps.push(depMatch[1]);
12712
- }
12713
- }
12714
- hooks.push({
12715
- name,
12716
- filePath,
12717
- isCustom: true,
12718
- dependencies: deps
12719
- });
12720
- }
12721
- return hooks;
12722
- }
12723
- }
12724
-
12725
- // src/scanner/extractors/routes.ts
12726
- import { readdirSync as readdirSync3, statSync, readFileSync as readFileSync3 } from "node:fs";
12727
- import { join as join14, relative, basename as basename3, dirname as dirname4 } from "node:path";
12728
- function extractRoutes(scanDir) {
12729
- const routes = [];
12730
- const appDirs = ["app", "src/app"].map((d) => join14(scanDir, d));
12731
- for (const appDir of appDirs) {
12732
- try {
12733
- if (statSync(appDir).isDirectory()) {
12734
- extractAppRouterRoutes(appDir, appDir, routes);
12735
- }
12736
- } catch {}
12737
- }
12738
- const pagesDirs = ["pages", "src/pages"].map((d) => join14(scanDir, d));
12739
- for (const pagesDir of pagesDirs) {
12740
- try {
12741
- if (statSync(pagesDir).isDirectory()) {
12742
- extractPagesRouterRoutes(pagesDir, pagesDir, routes);
12743
- }
12744
- } catch {}
12745
- }
12746
- return routes;
12747
- }
12748
- function extractAppRouterRoutes(dir, baseDir, routes) {
12749
- const entries = readdirSync3(dir, { withFileTypes: true });
12750
- for (const entry of entries) {
12751
- const fullPath = join14(dir, entry.name);
12752
- if (entry.isDirectory()) {
12753
- extractAppRouterRoutes(fullPath, baseDir, routes);
12754
- continue;
12755
- }
12756
- const name = basename3(entry.name, entry.name.substring(entry.name.indexOf(".")));
12757
- const ext = entry.name.substring(entry.name.indexOf("."));
12758
- if (![".ts", ".tsx", ".js", ".jsx"].some((e) => entry.name.endsWith(e)))
12759
- continue;
12760
- if (name === "page") {
12761
- const routePath = dirToRoutePath(relative(baseDir, dir));
12762
- const layoutFile = findLayoutFile(dir, baseDir);
12763
- routes.push({
12764
- path: routePath,
12765
- filePath: relative(process.cwd(), fullPath),
12766
- isDynamic: routePath.includes("["),
12767
- layoutFile: layoutFile ? relative(process.cwd(), layoutFile) : undefined
12768
- });
12769
- }
12770
- if (name === "route") {
12771
- const routePath = dirToRoutePath(relative(baseDir, dir));
12772
- const methods = extractApiMethods(fullPath);
12773
- for (const method of methods) {
12774
- routes.push({
12775
- path: routePath,
12776
- filePath: relative(process.cwd(), fullPath),
12777
- method,
12778
- isDynamic: routePath.includes("[")
12779
- });
12780
- }
12781
- }
12782
- }
12783
- }
12784
- function extractPagesRouterRoutes(dir, baseDir, routes) {
12785
- const entries = readdirSync3(dir, { withFileTypes: true });
12786
- for (const entry of entries) {
12787
- const fullPath = join14(dir, entry.name);
12788
- if (entry.isDirectory()) {
12789
- if (entry.name === "api") {
12790
- extractPagesApiRoutes(fullPath, baseDir, routes);
12791
- } else {
12792
- extractPagesRouterRoutes(fullPath, baseDir, routes);
12793
- }
12794
- continue;
12795
- }
12796
- if (![".ts", ".tsx", ".js", ".jsx"].some((e) => entry.name.endsWith(e)))
12797
- continue;
12798
- if (entry.name.startsWith("_"))
12799
- continue;
12800
- const name = basename3(entry.name).replace(/\.(ts|tsx|js|jsx)$/, "");
12801
- const relDir = relative(baseDir, dir);
12802
- const routePath = `/${relDir ? relDir + "/" : ""}${name === "index" ? "" : name}`.replace(/\/+/g, "/") || "/";
12803
- routes.push({
12804
- path: routePath,
12805
- filePath: relative(process.cwd(), fullPath),
12806
- isDynamic: routePath.includes("[")
12807
- });
12808
- }
12809
- }
12810
- function extractPagesApiRoutes(dir, baseDir, routes) {
12811
- const entries = readdirSync3(dir, { withFileTypes: true });
12812
- for (const entry of entries) {
12813
- const fullPath = join14(dir, entry.name);
12814
- if (entry.isDirectory()) {
12815
- extractPagesApiRoutes(fullPath, baseDir, routes);
12816
- continue;
12817
- }
12818
- if (![".ts", ".tsx", ".js", ".jsx"].some((e) => entry.name.endsWith(e)))
12819
- continue;
12820
- const name = basename3(entry.name).replace(/\.(ts|tsx|js|jsx)$/, "");
12821
- const relDir = relative(baseDir, dir);
12822
- const routePath = `/${relDir ? relDir + "/" : ""}${name === "index" ? "" : name}`.replace(/\/+/g, "/");
12823
- routes.push({
12824
- path: routePath,
12825
- filePath: relative(process.cwd(), fullPath),
12826
- method: "handler",
12827
- isDynamic: routePath.includes("[")
12828
- });
12829
- }
12830
- }
12831
- function dirToRoutePath(relPath) {
12832
- if (!relPath)
12833
- return "/";
12834
- const cleaned = relPath.split("/").filter((segment) => !segment.startsWith("(")).join("/");
12835
- return `/${cleaned}` || "/";
12836
- }
12837
- function findLayoutFile(dir, baseDir) {
12838
- let current = dir;
12839
- while (current.startsWith(baseDir)) {
12840
- for (const ext of [".tsx", ".ts", ".jsx", ".js"]) {
12841
- const layoutPath = join14(current, `layout${ext}`);
12842
- try {
12843
- statSync(layoutPath);
12844
- return layoutPath;
12845
- } catch {}
12846
- }
12847
- current = dirname4(current);
12848
- }
12849
- return;
12850
- }
12851
- function extractApiMethods(filePath) {
12852
- try {
12853
- const content = readFileSync3(filePath, "utf-8");
12854
- const methods = [];
12855
- const methodRegex = /export\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g;
12856
- let match;
12857
- while ((match = methodRegex.exec(content)) !== null) {
12858
- methods.push(match[1]);
12859
- }
12860
- return methods.length > 0 ? methods : ["handler"];
12861
- } catch {
12862
- return ["handler"];
12863
- }
12864
- }
12865
- // src/scanner/scanner.ts
12866
- async function runStage1(config) {
12867
- const scanDir = resolve(config.scanDir);
12868
- const cacheDir = resolve(config.cacheDir, "ast");
12869
- mkdirSync2(cacheDir, { recursive: true });
12870
- const manifestPath = resolve(cacheDir, "manifest.json");
12871
- let manifest = { files: {} };
12872
- if (existsSync3(manifestPath)) {
12873
- try {
12874
- manifest = JSON.parse(readFileSync4(manifestPath, "utf-8"));
12875
- } catch {
12876
- manifest = { files: {} };
12877
- }
12878
- }
12879
- const files = collectFiles(scanDir, config.include, config.exclude);
12880
- verbose(`Found ${files.length} files to scan`);
12881
- const parser = new TypeScriptParser;
12882
- const allFiles = [];
12883
- const allComponents = [];
12884
- const allHooks = [];
12885
- const allDependencies = [];
12886
- let totalLines = 0;
12887
- let cachedCount = 0;
12888
- for (const filePath of files) {
12889
- const content = readFileSync4(filePath, "utf-8");
12890
- const hash = createHash("md5").update(content).digest("hex");
12891
- const relPath = relative2(process.cwd(), filePath);
12892
- const cached = manifest.files[relPath];
12893
- if (cached && cached.hash === hash) {
12894
- const cacheFile = resolve(cacheDir, cached.resultFile);
12895
- if (existsSync3(cacheFile)) {
12896
- try {
12897
- const cachedResult = JSON.parse(readFileSync4(cacheFile, "utf-8"));
12898
- allFiles.push(cachedResult.file);
12899
- allComponents.push(...cachedResult.components);
12900
- allHooks.push(...cachedResult.hooks);
12901
- allDependencies.push(...cachedResult.dependencies);
12902
- totalLines += cachedResult.file.lines;
12903
- cachedCount++;
12904
- continue;
12905
- } catch {}
12906
- }
12907
- }
12908
- const result = await parser.parse(relPath, content);
12909
- allFiles.push(result.file);
12910
- allComponents.push(...result.components);
12911
- allHooks.push(...result.hooks);
12912
- allDependencies.push(...result.dependencies);
12913
- totalLines += result.file.lines;
12914
- const resultFile = `${hash}.json`;
12915
- writeFileSync2(resolve(cacheDir, resultFile), JSON.stringify({
12916
- file: result.file,
12917
- components: result.components,
12918
- hooks: result.hooks,
12919
- dependencies: result.dependencies
12920
- }));
12921
- manifest.files[relPath] = { hash, resultFile };
12922
- }
12923
- writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2));
12924
- if (cachedCount > 0) {
12925
- verbose(`${cachedCount} files from cache, ${files.length - cachedCount} re-parsed`);
12926
- }
12927
- const routes = extractRoutes(scanDir);
12928
- verbose(`Found ${routes.length} routes`);
12929
- verbose(`Found ${allComponents.length} components`);
12930
- verbose(`Found ${allHooks.length} custom hooks`);
12931
- return {
12932
- version: "1.0",
12933
- scannedAt: new Date().toISOString(),
12934
- language: "typescript",
12935
- stats: { totalFiles: files.length, totalLines },
12936
- files: allFiles,
12937
- routes,
12938
- components: allComponents,
12939
- hooks: allHooks,
12940
- dependencies: allDependencies
12941
- };
12942
- }
12943
- function collectFiles(dir, includePatterns, excludePatterns) {
12944
- const files = [];
12945
- for (const pattern of includePatterns) {
12946
- const matches = ts(pattern, {
12947
- cwd: dir,
12948
- absolute: true,
12949
- ignore: excludePatterns
12950
- });
12951
- files.push(...matches);
12952
- }
12953
- return [...new Set(files)].sort();
12954
- }
12955
-
12956
- // src/commands/scan.ts
12957
- function registerScan(program2) {
12958
- program2.command("scan").description("Scan codebase AST (routes, components, hooks, imports)").option("--output <file>", "Write output to specific file").option("--scan-dir <dir>", "Directory to scan (default: from config)").option("--no-cache", "Disable file-level caching").action(async (opts) => {
12959
- const ctx = await resolveCommandContext(program2);
12960
- const root = ctx.paths.projectRoot;
12961
- const scanDir = opts.scanDir ?? ctx.config.scanner.scanDir;
12962
- const cacheDir = join15(root, ctx.config.scanner.cacheDir);
12963
- const scanConfig = {
12964
- scanDir: join15(root, scanDir),
12965
- include: ctx.config.scanner.include,
12966
- exclude: ctx.config.scanner.exclude,
12967
- cacheDir: opts.cache === false ? join15(cacheDir, `no-cache-${Date.now()}`) : cacheDir
12968
- };
12969
- const spinner = createSpinner();
12970
- spinner.start("Scanning codebase...");
12971
- const ast = await runStage1(scanConfig);
12972
- spinner.stop();
12973
- const outputPath = opts.output ?? (ctx.key ? join15(ctx.paths.workingDir, ctx.key, "ast-scan.json") : join15(root, ".e2e-ai", "ast-scan.json"));
12974
- writeFile(outputPath, JSON.stringify(ast, null, 2));
12975
- success(`AST written to ${outputPath}`);
12976
- info(` Files: ${ast.stats.totalFiles} (${ast.stats.totalLines} lines)`);
12977
- info(` Routes: ${ast.routes.length}`);
12978
- info(` Components: ${ast.components.length}`);
12979
- info(` Hooks: ${ast.hooks.length}`);
12980
- });
12981
- }
12982
-
12983
- // src/commands/push.ts
12984
- import { join as join16 } from "node:path";
12985
-
12986
- // src/scanner/push.ts
12987
- async function pushToApi(payload, apiUrl, apiKey) {
12988
- const response = await fetch(apiUrl, {
12989
- method: "POST",
12990
- headers: {
12991
- "Content-Type": "application/json",
12992
- Authorization: `Bearer ${apiKey}`
12993
- },
12994
- body: JSON.stringify(payload)
12995
- });
12996
- if (!response.ok) {
12997
- const body = await response.text();
12998
- throw new Error(`Push failed (${response.status}): ${body}`);
12999
- }
13000
- return response.json();
13001
- }
13002
-
13003
- // src/commands/push.ts
13004
- function registerPush(program2) {
13005
- program2.command("push [input]").description("Push QA map to remote API").option("--commit-sha <sha>", "Git commit SHA to associate").action(async (inputArg, opts) => {
13006
- const ctx = await resolveCommandContext(program2);
13007
- const apiUrl = ctx.config.push?.apiUrl ?? process.env.E2E_AI_API_URL;
13008
- const apiKey = ctx.config.push?.apiKey ?? process.env.E2E_AI_API_KEY;
13009
- if (!apiUrl) {
13010
- error("No push.apiUrl configured. Set it in e2e-ai.config.ts or E2E_AI_API_URL env var.");
13011
- process.exit(1);
13012
- }
13013
- if (!apiKey) {
13014
- error("No push.apiKey configured. Set it in e2e-ai.config.ts or E2E_AI_API_KEY env var.");
13015
- process.exit(1);
13016
- }
13017
- const root = ctx.paths.projectRoot;
13018
- let inputPath;
13019
- if (inputArg) {
13020
- inputPath = join16(root, inputArg);
13021
- } else if (ctx.key) {
13022
- inputPath = join16(ctx.paths.workingDir, ctx.key, "qa-map.json");
13023
- } else {
13024
- inputPath = join16(root, ".e2e-ai", "qa-map.json");
13025
- }
13026
- if (!fileExists(inputPath)) {
13027
- error(`QA map not found: ${inputPath}`);
13028
- process.exit(1);
13029
- }
13030
- const payload = JSON.parse(readFile(inputPath));
13031
- if (opts?.commitSha) {
13032
- payload.commitSha = opts.commitSha;
13033
- }
13034
- info(`Pushing: ${payload.features.length} features, ${payload.workflows.length} workflows, ${payload.scenarios.length} scenarios`);
13035
- const spinner = createSpinner();
13036
- spinner.start("Pushing to API...");
13037
- const result = await pushToApi(payload, apiUrl, apiKey);
13038
- spinner.stop();
13039
- success("Push successful!");
13040
- info(` Version: ${result.version} (schema v${result.schemaVersion})`);
13041
- info(` Auto-linked scenarios: ${result.stats.autoLinkedScenarios}`);
13042
- });
9208
+ info(`Pushing: ${payload.features.length} features, ${payload.workflows.length} workflows, ${payload.scenarios.length} scenarios`);
9209
+ const spinner = createSpinner();
9210
+ spinner.start("Pushing to API...");
9211
+ const result = await pushToApi(payload, apiUrl, apiKey);
9212
+ spinner.stop();
9213
+ success("Push successful!");
9214
+ info(` Version: ${result.version} (schema v${result.schemaVersion})`);
9215
+ info(` Auto-linked scenarios: ${result.stats.autoLinkedScenarios}`);
9216
+ });
13043
9217
  }
13044
9218
 
13045
9219
  // src/commands/analyze.ts
13046
- import { join as join17 } from "node:path";
9220
+ import { join as join16 } from "node:path";
13047
9221
  function registerAnalyze(program2) {
13048
9222
  program2.command("analyze [input]").description("Analyze AST scan with AI to generate QA map (features, workflows, scenarios)").option("--output <file>", "Write QA map to specific file").option("--skip-scenarios", "Only run feature analysis (skip scenario generation)").action(async (inputArg, opts) => {
13049
9223
  const ctx = await resolveCommandContext(program2);
13050
9224
  const root = ctx.paths.projectRoot;
13051
9225
  let inputPath;
13052
9226
  if (inputArg) {
13053
- inputPath = join17(root, inputArg);
9227
+ inputPath = join16(root, inputArg);
13054
9228
  } else if (ctx.key) {
13055
- inputPath = join17(ctx.paths.workingDir, ctx.key, "ast-scan.json");
9229
+ inputPath = join16(ctx.paths.workingDir, ctx.key, "ast-scan.json");
13056
9230
  } else {
13057
- inputPath = join17(root, ".e2e-ai", "ast-scan.json");
9231
+ inputPath = join16(root, ".e2e-ai", "ast-scan.json");
13058
9232
  }
13059
9233
  if (!fileExists(inputPath)) {
13060
9234
  error(`AST scan not found: ${inputPath}. Run "e2e-ai scan" first.`);
@@ -13109,7 +9283,7 @@ function registerAnalyze(program2) {
13109
9283
  } else {
13110
9284
  finalPayload = { ...qaMap, scenarios: [] };
13111
9285
  }
13112
- const outputPath = opts?.output ?? (ctx.key ? join17(ctx.paths.workingDir, ctx.key, "qa-map.json") : join17(root, ".e2e-ai", "qa-map.json"));
9286
+ const outputPath = opts?.output ?? (ctx.key ? join16(ctx.paths.workingDir, ctx.key, "qa-map.json") : join16(root, ".e2e-ai", "qa-map.json"));
13113
9287
  writeFile(outputPath, JSON.stringify(finalPayload, null, 2));
13114
9288
  success(`QA map written to ${outputPath}`);
13115
9289
  });