react-doctor 0.2.15-dev.520b0a9 → 0.2.15-dev.bd8298d

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.
Files changed (3) hide show
  1. package/dist/cli.js +113 -95
  2. package/dist/index.js +100 -65
  3. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c8bf2d99-8f0b-55f1-a894-63e600bf000b")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6e59d54f-a063-5355-9b76-f82556f70c89")}catch(e){}}();
3
3
  import { createRequire } from "node:module";
4
4
  import { execFileSync, spawn, spawnSync } from "node:child_process";
5
5
  import * as Path from "node:path";
@@ -7338,27 +7338,30 @@ var OxlintSpawnTimeoutMs = class extends Context.Reference("react-doctor/OxlintS
7338
7338
  var OxlintOutputMaxBytes = class extends Context.Reference("react-doctor/OxlintOutputMaxBytes", { defaultValue: () => OXLINT_OUTPUT_MAX_BYTES }) {};
7339
7339
  /**
7340
7340
  * Number of oxlint subprocesses the lint pass runs in parallel. Defaults
7341
- * to `1` (serial — the historical behavior) so resource usage is opt-in.
7342
- * The CLI's `--experimental-parallel` flag overrides this via `Layer.succeed`; the
7343
- * `REACT_DOCTOR_PARALLEL` env var seeds the default for programmatic /
7344
- * CI callers that never touch the flag:
7341
+ * to auto-detected CPU cores (parallel) so large repos scan fast out of
7342
+ * the box; `spawnLintBatches` transparently falls back to a single worker
7343
+ * if a parallel run exhausts system resources. The CLI's `--no-parallel`
7344
+ * flag forces serial via `Layer.succeed`; the `REACT_DOCTOR_PARALLEL` env
7345
+ * var seeds the default for programmatic / CI callers that never touch the
7346
+ * flag — parallelism is opt-OUT, so only the explicit serial values pin
7347
+ * one worker:
7345
7348
  *
7346
- * - unset / `0` / `false` / `off` → `1` (serial)
7347
- * - `auto` / `true` / `on` → available CPU cores (clamped)
7348
- * - a positive integer → that many workers (clamped)
7349
+ * - unset / `auto` / `true` / `on` → available CPU cores (clamped)
7350
+ * - `0` / `false` / `off` → `1` (serial)
7351
+ * - a positive integer → that many workers (clamped)
7352
+ * - any other value → available CPU cores (clamped)
7349
7353
  *
7350
7354
  * The resolved value is always within
7351
7355
  * `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`.
7352
7356
  */
7353
7357
  var OxlintConcurrency = class extends Context.Reference("react-doctor/OxlintConcurrency", { defaultValue: () => {
7354
7358
  const raw = process.env["REACT_DOCTOR_PARALLEL"];
7355
- if (raw === void 0) return 1;
7359
+ if (raw === void 0) return resolveScanConcurrency("auto");
7356
7360
  const normalized = raw.trim().toLowerCase();
7357
- if (normalized === "" || normalized === "0" || normalized === "false" || normalized === "off") return 1;
7358
- if (normalized === "auto" || normalized === "true" || normalized === "on") return resolveScanConcurrency("auto");
7361
+ if (normalized === "0" || normalized === "false" || normalized === "off") return 1;
7359
7362
  const parsed = Number.parseInt(normalized, 10);
7360
- if (!Number.isInteger(parsed) || parsed <= 0) return 1;
7361
- return resolveScanConcurrency(parsed);
7363
+ if (Number.isInteger(parsed) && parsed > 0) return resolveScanConcurrency(parsed);
7364
+ return resolveScanConcurrency("auto");
7362
7365
  } }) {};
7363
7366
  const DIAGNOSTIC_SURFACES = [
7364
7367
  "cli",
@@ -10532,6 +10535,21 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
10532
10535
  resolve(output);
10533
10536
  });
10534
10537
  });
10538
+ const PARALLELISM_EXHAUSTION_ERROR_CODES = new Set([
10539
+ "EAGAIN",
10540
+ "EMFILE",
10541
+ "ENFILE",
10542
+ "ENOMEM"
10543
+ ]);
10544
+ const isParallelismRelatedSpawnError = (error) => {
10545
+ if (!(error instanceof ReactDoctorError)) return false;
10546
+ const { reason } = error;
10547
+ if (reason._tag !== "OxlintSpawnFailed") return false;
10548
+ const { cause } = reason;
10549
+ if (typeof cause !== "object" || cause === null || !("code" in cause)) return false;
10550
+ const { code } = cause;
10551
+ return typeof code === "string" && PARALLELISM_EXHAUSTION_ERROR_CODES.has(code);
10552
+ };
10535
10553
  /**
10536
10554
  * Runs every prebuilt file batch through oxlint, with binary-split
10537
10555
  * retry on the splittable error classes (timeout / output-too-large /
@@ -10540,66 +10558,83 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
10540
10558
  * (surfaced via `onPartialFailure`) so JSON-mode consumers see WHICH
10541
10559
  * files were skipped instead of silently losing them.
10542
10560
  *
10543
- * Errors that aren't splittable (oxlint config crash, JS plugin
10544
- * resolution failure, etc.) propagate to the caller — the
10545
- * `runOxlint` retry-without-extends fallback re-spawns this loop
10546
- * with a slimmer config in that case.
10561
+ * Parallel runs (concurrency > 1) get one extra safety net: if the pass
10562
+ * fails with a resource-exhaustion error that's exclusive to running
10563
+ * many oxlint subprocesses at once (EAGAIN / EMFILE / ENFILE / ENOMEM —
10564
+ * see `isParallelismRelatedSpawnError`), the whole pass replays once
10565
+ * with a single worker. That's the only failure a serial replay can
10566
+ * clear, so every other error class is left to propagate.
10567
+ *
10568
+ * Errors that aren't splittable and aren't parallelism-related (oxlint
10569
+ * config crash, JS plugin resolution failure, etc.) propagate to the
10570
+ * caller — the `runOxlint` retry-without-extends fallback re-spawns this
10571
+ * loop with a slimmer config in that case.
10547
10572
  */
10548
10573
  const spawnLintBatches = async (input) => {
10549
10574
  const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes } = input;
10550
- const concurrency = resolveScanConcurrency(input.concurrency ?? 1);
10575
+ const requestedConcurrency = resolveScanConcurrency(input.concurrency ?? 1);
10551
10576
  const totalFileCount = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
10552
- const allDiagnostics = [];
10553
- const droppedFiles = [];
10554
- let firstDropReason = null;
10555
- const spawnLintBatch = async (batch) => {
10556
- const batchArgs = [...baseArgs, ...batch];
10557
- try {
10558
- return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes), project, rootDirectory);
10559
- } catch (error) {
10560
- if (!isSplittableReactDoctorError(error)) throw error;
10561
- if (batch.length <= 1) {
10562
- droppedFiles.push(...batch);
10563
- if (firstDropReason === null) firstDropReason = error.message;
10564
- return [];
10577
+ const runBatchPass = async (concurrency) => {
10578
+ const allDiagnostics = [];
10579
+ const droppedFiles = [];
10580
+ let firstDropReason = null;
10581
+ const spawnLintBatch = async (batch) => {
10582
+ const batchArgs = [...baseArgs, ...batch];
10583
+ try {
10584
+ return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes), project, rootDirectory);
10585
+ } catch (error) {
10586
+ if (!isSplittableReactDoctorError(error)) throw error;
10587
+ if (batch.length <= 1) {
10588
+ droppedFiles.push(...batch);
10589
+ if (firstDropReason === null) firstDropReason = error.message;
10590
+ return [];
10591
+ }
10592
+ const splitIndex = Math.ceil(batch.length / 2);
10593
+ return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
10565
10594
  }
10566
- const splitIndex = Math.ceil(batch.length / 2);
10567
- return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
10595
+ };
10596
+ let startedFileCount = 0;
10597
+ let scannedFileCount = 0;
10598
+ let displayedFileCount = 0;
10599
+ const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
10600
+ const ceiling = Math.min(startedFileCount, totalFileCount - 1);
10601
+ if (displayedFileCount < ceiling) {
10602
+ displayedFileCount += 1;
10603
+ onFileProgress(displayedFileCount, totalFileCount);
10604
+ }
10605
+ }, 50) : null;
10606
+ progressTimer?.unref?.();
10607
+ try {
10608
+ const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
10609
+ startedFileCount += batch.length;
10610
+ const batchDiagnostics = await spawnLintBatch(batch);
10611
+ scannedFileCount += batch.length;
10612
+ if (onFileProgress) {
10613
+ displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
10614
+ onFileProgress(displayedFileCount, totalFileCount);
10615
+ }
10616
+ return batchDiagnostics;
10617
+ });
10618
+ for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
10619
+ } finally {
10620
+ if (progressTimer !== null) clearInterval(progressTimer);
10568
10621
  }
10622
+ if (droppedFiles.length > 0 && onPartialFailure) {
10623
+ const previewFiles = droppedFiles.slice(0, 3).join(", ");
10624
+ const remainderHint = droppedFiles.length > 3 ? `, +${droppedFiles.length - 3} more` : "";
10625
+ const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
10626
+ onPartialFailure(`${droppedFiles.length} file(s) failed to lint and were skipped (${previewFiles}${remainderHint})${reasonHint}`);
10627
+ }
10628
+ return allDiagnostics;
10569
10629
  };
10570
- let startedFileCount = 0;
10571
- let scannedFileCount = 0;
10572
- let displayedFileCount = 0;
10573
- const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
10574
- const ceiling = Math.min(startedFileCount, totalFileCount - 1);
10575
- if (displayedFileCount < ceiling) {
10576
- displayedFileCount += 1;
10577
- onFileProgress(displayedFileCount, totalFileCount);
10578
- }
10579
- }, 50) : null;
10580
- progressTimer?.unref?.();
10630
+ let diagnostics;
10581
10631
  try {
10582
- const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
10583
- startedFileCount += batch.length;
10584
- const batchDiagnostics = await spawnLintBatch(batch);
10585
- scannedFileCount += batch.length;
10586
- if (onFileProgress) {
10587
- displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
10588
- onFileProgress(displayedFileCount, totalFileCount);
10589
- }
10590
- return batchDiagnostics;
10591
- });
10592
- for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
10593
- } finally {
10594
- if (progressTimer !== null) clearInterval(progressTimer);
10595
- }
10596
- if (droppedFiles.length > 0 && onPartialFailure) {
10597
- const previewFiles = droppedFiles.slice(0, 3).join(", ");
10598
- const remainderHint = droppedFiles.length > 3 ? `, +${droppedFiles.length - 3} more` : "";
10599
- const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
10600
- onPartialFailure(`${droppedFiles.length} file(s) failed to lint and were skipped (${previewFiles}${remainderHint})${reasonHint}`);
10632
+ diagnostics = await runBatchPass(requestedConcurrency);
10633
+ } catch (error) {
10634
+ if (requestedConcurrency <= 1 || !isParallelismRelatedSpawnError(error)) throw error;
10635
+ diagnostics = await runBatchPass(1);
10601
10636
  }
10602
- return dedupeDiagnostics(allDiagnostics);
10637
+ return dedupeDiagnostics(diagnostics);
10603
10638
  };
10604
10639
  let didValidate = false;
10605
10640
  /**
@@ -11907,7 +11942,7 @@ const makeNoopConsole = () => ({
11907
11942
  });
11908
11943
  //#endregion
11909
11944
  //#region src/cli/utils/version.ts
11910
- const VERSION = "0.2.15-dev.520b0a9";
11945
+ const VERSION = "0.2.15-dev.bd8298d";
11911
11946
  //#endregion
11912
11947
  //#region src/cli/utils/json-mode.ts
11913
11948
  let context = null;
@@ -12253,13 +12288,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
12253
12288
  * uploads source-map artifacts under, so stack frames symbolicate. Honors the
12254
12289
  * standard `SENTRY_RELEASE` override.
12255
12290
  */
12256
- const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.2.15-dev.520b0a9`;
12291
+ const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.2.15-dev.bd8298d`;
12257
12292
  /**
12258
12293
  * Deployment environment shown in Sentry's environment filter. Defaults to
12259
12294
  * `production` for tagged releases and `development` for dev/unbuilt versions,
12260
12295
  * overridable via the standard `SENTRY_ENVIRONMENT` env var.
12261
12296
  */
12262
- const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.2.15-dev.520b0a9") ? "development" : "production");
12297
+ const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.2.15-dev.bd8298d") ? "development" : "production");
12263
12298
  /**
12264
12299
  * Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
12265
12300
  * (set to `0` to disable tracing) and falls back to
@@ -18553,31 +18588,13 @@ const printAgentInstallHint = (writeLine = defaultWriteLine) => {
18553
18588
  //#endregion
18554
18589
  //#region src/cli/utils/resolve-parallel-flag.ts
18555
18590
  /**
18556
- * Translates the `--experimental-parallel [workers]` flag into a concrete
18557
- * worker count for `InspectOptions.concurrency`:
18558
- *
18559
- * - flag absent (`undefined`) → `undefined` (defer to the ambient
18560
- * default: serial unless `REACT_DOCTOR_PARALLEL` is set)
18561
- * - bare flag / `auto` → auto-detect CPU cores
18562
- * - `--experimental-parallel <n>` → `n` workers (clamped)
18563
- * - `false` / `off` / `0` → serial (an explicit opt-out, so
18564
- * it overrides an env-enabled default rather than deferring to it)
18565
- * - an unparseable value → auto-detect cores
18566
- *
18567
- * Commander yields `true` for a bare flag, the raw string for an explicit
18568
- * value, and `undefined` when the flag is omitted.
18591
+ * Maps the `--no-parallel` flag to an `InspectOptions.concurrency` value.
18592
+ * `--no-parallel` (`parallel === false`) pins serial, overriding any
18593
+ * env-enabled default; otherwise `undefined` defers to the ambient
18594
+ * `OxlintConcurrency` default (parallel, unless `REACT_DOCTOR_PARALLEL`
18595
+ * sets a worker count — the flag itself no longer takes one).
18569
18596
  */
18570
- const resolveParallelFlag = (parallel) => {
18571
- if (parallel === void 0) return void 0;
18572
- if (parallel === true) return resolveScanConcurrency("auto");
18573
- if (parallel === false) return 1;
18574
- const normalized = parallel.trim().toLowerCase();
18575
- if (normalized === "" || normalized === "auto" || normalized === "true") return resolveScanConcurrency("auto");
18576
- if (normalized === "false" || normalized === "off" || normalized === "0") return 1;
18577
- const parsed = Number.parseInt(normalized, 10);
18578
- if (!Number.isInteger(parsed) || parsed <= 0) return resolveScanConcurrency("auto");
18579
- return resolveScanConcurrency(parsed);
18580
- };
18597
+ const resolveParallelFlag = (parallel) => parallel === false ? 1 : void 0;
18581
18598
  //#endregion
18582
18599
  //#region src/cli/utils/resolve-cli-inspect-options.ts
18583
18600
  /**
@@ -18605,7 +18622,7 @@ const resolveCliInspectOptions = (flags, userConfig) => {
18605
18622
  isCi: isCiEnvironment(),
18606
18623
  silent: Boolean(flags.json),
18607
18624
  outputSurface: flags.prComment ? "prComment" : "cli",
18608
- concurrency: resolveParallelFlag(flags.experimentalParallel)
18625
+ concurrency: resolveParallelFlag(flags.parallel)
18609
18626
  };
18610
18627
  };
18611
18628
  //#endregion
@@ -19797,6 +19814,7 @@ const ROOT_FLAG_SPEC = {
19797
19814
  "--no-color",
19798
19815
  "--no-dead-code",
19799
19816
  "--no-lint",
19817
+ "--no-parallel",
19800
19818
  "--no-respect-inline-disables",
19801
19819
  "--no-score",
19802
19820
  "--no-telemetry",
@@ -19817,7 +19835,7 @@ const ROOT_FLAG_SPEC = {
19817
19835
  "--project",
19818
19836
  "--why"
19819
19837
  ]),
19820
- longOptionsWithOptionalValues: new Set(["--diff", "--experimental-parallel"]),
19838
+ longOptionsWithOptionalValues: new Set(["--diff"]),
19821
19839
  shortOptionsWithoutValues: new Set([
19822
19840
  "-h",
19823
19841
  "-v",
@@ -19984,7 +20002,7 @@ ${formatExampleLines([
19984
20002
  ${highlighter.dim("Learn more:")}
19985
20003
  ${highlighter.info(CANONICAL_GITHUB_URL)}
19986
20004
  `;
19987
- const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--full", "force a full scan (overrides any `diff` value in config or `--diff`)").option("--experimental-parallel [workers]", "experimental: lint with N parallel workers (default: auto-detect CPU cores) — speeds up large repos").option("--project <name>", "select workspace project (comma-separated for multiple)").option("--diff [base]", "scan only files changed vs base branch (pass `false` to disable; overridden by --full)").option("--changed-files-from <file>", "internal: scan source files listed in a newline-delimited changed-files file").option("--no-score", "skip the score API, the share URL, and crash reporting").option("--no-telemetry", "alias for --no-score (skip the score API, share URL, and crash reporting)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--fail-on <level>", "exit with error code on diagnostics: error, warning, none (default: none)").option("--annotations", "output diagnostics as GitHub Actions annotations").option("--pr-comment", "tune CLI output for sticky PR comments (drops weak-signal rule families like `design` from the printed list and the fail-on gate; configure via config.surfaces)").option("--explain <file:line>", "diagnose why a rule fired or why a suppression didn't apply at a specific location").option("--why <file:line>", "alias for --explain").option("--respect-inline-disables", "respect inline `// eslint-disable*` / `// oxlint-disable*` comments (default)").option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").option("--warnings", "show warning-severity diagnostics (default)").option("--no-warnings", "hide warning-severity diagnostics (errors only)").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderRootHelpEpilog);
20005
+ const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--full", "force a full scan (overrides any `diff` value in config or `--diff`)").option("--no-parallel", "lint serially with one worker (default: parallel across CPU cores; set the worker count with REACT_DOCTOR_PARALLEL)").option("--project <name>", "select workspace project (comma-separated for multiple)").option("--diff [base]", "scan only files changed vs base branch (pass `false` to disable; overridden by --full)").option("--changed-files-from <file>", "internal: scan source files listed in a newline-delimited changed-files file").option("--no-score", "skip the score API, the share URL, and crash reporting").option("--no-telemetry", "alias for --no-score (skip the score API, share URL, and crash reporting)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--fail-on <level>", "exit with error code on diagnostics: error, warning, none (default: none)").option("--annotations", "output diagnostics as GitHub Actions annotations").option("--pr-comment", "tune CLI output for sticky PR comments (drops weak-signal rule families like `design` from the printed list and the fail-on gate; configure via config.surfaces)").option("--explain <file:line>", "diagnose why a rule fired or why a suppression didn't apply at a specific location").option("--why <file:line>", "alias for --explain").option("--respect-inline-disables", "respect inline `// eslint-disable*` / `// oxlint-disable*` comments (default)").option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").option("--warnings", "show warning-severity diagnostics (default)").option("--no-warnings", "hide warning-severity diagnostics (errors only)").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderRootHelpEpilog);
19988
20006
  program.action(inspectAction);
19989
20007
  program.command("install").alias("setup").description("Install the react-doctor skill into your coding agents and optional git hook").option("-y, --yes", "skip prompts, install for all detected agents").option("--dry-run", "show what would be installed without writing files").option("--agent-hooks", "install native non-blocking agent hooks for Claude Code and Cursor").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderInstallHelpEpilog).action(installAction);
19990
20008
  program.command("version").description("show the version with Node and platform info").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").action(versionAction);
@@ -20020,4 +20038,4 @@ program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
20020
20038
  export {};
20021
20039
 
20022
20040
  //# sourceMappingURL=cli.js.map
20023
- //# debugId=c8bf2d99-8f0b-55f1-a894-63e600bf000b
20041
+ //# debugId=6e59d54f-a063-5355-9b76-f82556f70c89
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3967254f-df21-5398-99d5-ee0d17b33e7b")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="4bb0de05-d610-5389-a78b-f54547ccdc56")}catch(e){}}();
3
3
  import { createRequire } from "node:module";
4
4
  import * as Schema from "effect/Schema";
5
5
  import * as fs$1 from "node:fs";
@@ -4314,27 +4314,30 @@ var OxlintSpawnTimeoutMs = class extends Context.Reference("react-doctor/OxlintS
4314
4314
  var OxlintOutputMaxBytes = class extends Context.Reference("react-doctor/OxlintOutputMaxBytes", { defaultValue: () => OXLINT_OUTPUT_MAX_BYTES }) {};
4315
4315
  /**
4316
4316
  * Number of oxlint subprocesses the lint pass runs in parallel. Defaults
4317
- * to `1` (serial — the historical behavior) so resource usage is opt-in.
4318
- * The CLI's `--experimental-parallel` flag overrides this via `Layer.succeed`; the
4319
- * `REACT_DOCTOR_PARALLEL` env var seeds the default for programmatic /
4320
- * CI callers that never touch the flag:
4317
+ * to auto-detected CPU cores (parallel) so large repos scan fast out of
4318
+ * the box; `spawnLintBatches` transparently falls back to a single worker
4319
+ * if a parallel run exhausts system resources. The CLI's `--no-parallel`
4320
+ * flag forces serial via `Layer.succeed`; the `REACT_DOCTOR_PARALLEL` env
4321
+ * var seeds the default for programmatic / CI callers that never touch the
4322
+ * flag — parallelism is opt-OUT, so only the explicit serial values pin
4323
+ * one worker:
4321
4324
  *
4322
- * - unset / `0` / `false` / `off` → `1` (serial)
4323
- * - `auto` / `true` / `on` → available CPU cores (clamped)
4324
- * - a positive integer → that many workers (clamped)
4325
+ * - unset / `auto` / `true` / `on` → available CPU cores (clamped)
4326
+ * - `0` / `false` / `off` → `1` (serial)
4327
+ * - a positive integer → that many workers (clamped)
4328
+ * - any other value → available CPU cores (clamped)
4325
4329
  *
4326
4330
  * The resolved value is always within
4327
4331
  * `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`.
4328
4332
  */
4329
4333
  var OxlintConcurrency = class extends Context.Reference("react-doctor/OxlintConcurrency", { defaultValue: () => {
4330
4334
  const raw = process.env["REACT_DOCTOR_PARALLEL"];
4331
- if (raw === void 0) return 1;
4335
+ if (raw === void 0) return resolveScanConcurrency("auto");
4332
4336
  const normalized = raw.trim().toLowerCase();
4333
- if (normalized === "" || normalized === "0" || normalized === "false" || normalized === "off") return 1;
4334
- if (normalized === "auto" || normalized === "true" || normalized === "on") return resolveScanConcurrency("auto");
4337
+ if (normalized === "0" || normalized === "false" || normalized === "off") return 1;
4335
4338
  const parsed = Number.parseInt(normalized, 10);
4336
- if (!Number.isInteger(parsed) || parsed <= 0) return 1;
4337
- return resolveScanConcurrency(parsed);
4339
+ if (Number.isInteger(parsed) && parsed > 0) return resolveScanConcurrency(parsed);
4340
+ return resolveScanConcurrency("auto");
4338
4341
  } }) {};
4339
4342
  const DIAGNOSTIC_SURFACES = [
4340
4343
  "cli",
@@ -7485,6 +7488,21 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
7485
7488
  resolve(output);
7486
7489
  });
7487
7490
  });
7491
+ const PARALLELISM_EXHAUSTION_ERROR_CODES = new Set([
7492
+ "EAGAIN",
7493
+ "EMFILE",
7494
+ "ENFILE",
7495
+ "ENOMEM"
7496
+ ]);
7497
+ const isParallelismRelatedSpawnError = (error) => {
7498
+ if (!(error instanceof ReactDoctorError)) return false;
7499
+ const { reason } = error;
7500
+ if (reason._tag !== "OxlintSpawnFailed") return false;
7501
+ const { cause } = reason;
7502
+ if (typeof cause !== "object" || cause === null || !("code" in cause)) return false;
7503
+ const { code } = cause;
7504
+ return typeof code === "string" && PARALLELISM_EXHAUSTION_ERROR_CODES.has(code);
7505
+ };
7488
7506
  /**
7489
7507
  * Runs every prebuilt file batch through oxlint, with binary-split
7490
7508
  * retry on the splittable error classes (timeout / output-too-large /
@@ -7493,66 +7511,83 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
7493
7511
  * (surfaced via `onPartialFailure`) so JSON-mode consumers see WHICH
7494
7512
  * files were skipped instead of silently losing them.
7495
7513
  *
7496
- * Errors that aren't splittable (oxlint config crash, JS plugin
7497
- * resolution failure, etc.) propagate to the caller — the
7498
- * `runOxlint` retry-without-extends fallback re-spawns this loop
7499
- * with a slimmer config in that case.
7514
+ * Parallel runs (concurrency > 1) get one extra safety net: if the pass
7515
+ * fails with a resource-exhaustion error that's exclusive to running
7516
+ * many oxlint subprocesses at once (EAGAIN / EMFILE / ENFILE / ENOMEM —
7517
+ * see `isParallelismRelatedSpawnError`), the whole pass replays once
7518
+ * with a single worker. That's the only failure a serial replay can
7519
+ * clear, so every other error class is left to propagate.
7520
+ *
7521
+ * Errors that aren't splittable and aren't parallelism-related (oxlint
7522
+ * config crash, JS plugin resolution failure, etc.) propagate to the
7523
+ * caller — the `runOxlint` retry-without-extends fallback re-spawns this
7524
+ * loop with a slimmer config in that case.
7500
7525
  */
7501
7526
  const spawnLintBatches = async (input) => {
7502
7527
  const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes } = input;
7503
- const concurrency = resolveScanConcurrency(input.concurrency ?? 1);
7528
+ const requestedConcurrency = resolveScanConcurrency(input.concurrency ?? 1);
7504
7529
  const totalFileCount = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
7505
- const allDiagnostics = [];
7506
- const droppedFiles = [];
7507
- let firstDropReason = null;
7508
- const spawnLintBatch = async (batch) => {
7509
- const batchArgs = [...baseArgs, ...batch];
7510
- try {
7511
- return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes), project, rootDirectory);
7512
- } catch (error) {
7513
- if (!isSplittableReactDoctorError(error)) throw error;
7514
- if (batch.length <= 1) {
7515
- droppedFiles.push(...batch);
7516
- if (firstDropReason === null) firstDropReason = error.message;
7517
- return [];
7530
+ const runBatchPass = async (concurrency) => {
7531
+ const allDiagnostics = [];
7532
+ const droppedFiles = [];
7533
+ let firstDropReason = null;
7534
+ const spawnLintBatch = async (batch) => {
7535
+ const batchArgs = [...baseArgs, ...batch];
7536
+ try {
7537
+ return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes), project, rootDirectory);
7538
+ } catch (error) {
7539
+ if (!isSplittableReactDoctorError(error)) throw error;
7540
+ if (batch.length <= 1) {
7541
+ droppedFiles.push(...batch);
7542
+ if (firstDropReason === null) firstDropReason = error.message;
7543
+ return [];
7544
+ }
7545
+ const splitIndex = Math.ceil(batch.length / 2);
7546
+ return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
7547
+ }
7548
+ };
7549
+ let startedFileCount = 0;
7550
+ let scannedFileCount = 0;
7551
+ let displayedFileCount = 0;
7552
+ const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
7553
+ const ceiling = Math.min(startedFileCount, totalFileCount - 1);
7554
+ if (displayedFileCount < ceiling) {
7555
+ displayedFileCount += 1;
7556
+ onFileProgress(displayedFileCount, totalFileCount);
7518
7557
  }
7519
- const splitIndex = Math.ceil(batch.length / 2);
7520
- return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
7558
+ }, 50) : null;
7559
+ progressTimer?.unref?.();
7560
+ try {
7561
+ const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
7562
+ startedFileCount += batch.length;
7563
+ const batchDiagnostics = await spawnLintBatch(batch);
7564
+ scannedFileCount += batch.length;
7565
+ if (onFileProgress) {
7566
+ displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
7567
+ onFileProgress(displayedFileCount, totalFileCount);
7568
+ }
7569
+ return batchDiagnostics;
7570
+ });
7571
+ for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
7572
+ } finally {
7573
+ if (progressTimer !== null) clearInterval(progressTimer);
7521
7574
  }
7522
- };
7523
- let startedFileCount = 0;
7524
- let scannedFileCount = 0;
7525
- let displayedFileCount = 0;
7526
- const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
7527
- const ceiling = Math.min(startedFileCount, totalFileCount - 1);
7528
- if (displayedFileCount < ceiling) {
7529
- displayedFileCount += 1;
7530
- onFileProgress(displayedFileCount, totalFileCount);
7575
+ if (droppedFiles.length > 0 && onPartialFailure) {
7576
+ const previewFiles = droppedFiles.slice(0, 3).join(", ");
7577
+ const remainderHint = droppedFiles.length > 3 ? `, +${droppedFiles.length - 3} more` : "";
7578
+ const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
7579
+ onPartialFailure(`${droppedFiles.length} file(s) failed to lint and were skipped (${previewFiles}${remainderHint})${reasonHint}`);
7531
7580
  }
7532
- }, 50) : null;
7533
- progressTimer?.unref?.();
7581
+ return allDiagnostics;
7582
+ };
7583
+ let diagnostics;
7534
7584
  try {
7535
- const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
7536
- startedFileCount += batch.length;
7537
- const batchDiagnostics = await spawnLintBatch(batch);
7538
- scannedFileCount += batch.length;
7539
- if (onFileProgress) {
7540
- displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
7541
- onFileProgress(displayedFileCount, totalFileCount);
7542
- }
7543
- return batchDiagnostics;
7544
- });
7545
- for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
7546
- } finally {
7547
- if (progressTimer !== null) clearInterval(progressTimer);
7548
- }
7549
- if (droppedFiles.length > 0 && onPartialFailure) {
7550
- const previewFiles = droppedFiles.slice(0, 3).join(", ");
7551
- const remainderHint = droppedFiles.length > 3 ? `, +${droppedFiles.length - 3} more` : "";
7552
- const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
7553
- onPartialFailure(`${droppedFiles.length} file(s) failed to lint and were skipped (${previewFiles}${remainderHint})${reasonHint}`);
7585
+ diagnostics = await runBatchPass(requestedConcurrency);
7586
+ } catch (error) {
7587
+ if (requestedConcurrency <= 1 || !isParallelismRelatedSpawnError(error)) throw error;
7588
+ diagnostics = await runBatchPass(1);
7554
7589
  }
7555
- return dedupeDiagnostics(allDiagnostics);
7590
+ return dedupeDiagnostics(diagnostics);
7556
7591
  };
7557
7592
  let didValidate = false;
7558
7593
  /**
@@ -8699,4 +8734,4 @@ const toJsonReport = (result, options) => buildJsonReport({
8699
8734
  export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
8700
8735
 
8701
8736
  //# sourceMappingURL=index.js.map
8702
- //# debugId=3967254f-df21-5398-99d5-ee0d17b33e7b
8737
+ //# debugId=4bb0de05-d610-5389-a78b-f54547ccdc56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-doctor",
3
- "version": "0.2.15-dev.520b0a9",
3
+ "version": "0.2.15-dev.bd8298d",
4
4
  "description": "Diagnose and fix React codebases for security, performance, correctness, accessibility, bundle-size, and architecture issues",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -63,7 +63,7 @@
63
63
  "oxlint": "^1.66.0",
64
64
  "prompts": "^2.4.2",
65
65
  "typescript": ">=5.0.4 <7",
66
- "oxlint-plugin-react-doctor": "0.2.15-dev.520b0a9"
66
+ "oxlint-plugin-react-doctor": "0.2.15-dev.bd8298d"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/babel__code-frame": "^7.27.0",
@@ -71,8 +71,8 @@
71
71
  "@xterm/headless": "^6.0.0",
72
72
  "commander": "^14.0.3",
73
73
  "ora": "^9.4.0",
74
- "@react-doctor/core": "0.2.15",
75
- "@react-doctor/api": "0.2.15"
74
+ "@react-doctor/api": "0.2.15",
75
+ "@react-doctor/core": "0.2.15"
76
76
  },
77
77
  "engines": {
78
78
  "node": "^20.19.0 || >=22.12.0"