react-doctor 0.5.1-dev.94f9f4f → 0.5.1-dev.9cc6555

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/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]="a4054417-b813-5ebe-8feb-dce2d3571fbc")}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]="c8ddec5f-75dd-56a9-93b8-c34b1f202f7c")}catch(e){}}();
3
3
  import { r as __toESM$1, t as __commonJSMin$1 } from "./chunk-N93fKeF6.js";
4
4
  import { createRequire } from "node:module";
5
5
  import * as NFS from "node:fs";
@@ -19253,6 +19253,7 @@ var Diagnostic = class extends Class("Diagnostic")({
19253
19253
  endLine: optional(Number$1),
19254
19254
  endColumn: optional(Number$1),
19255
19255
  category: String$1,
19256
+ fileContext: optional(Literals(["test", "story"])),
19256
19257
  suppressionHint: optional(String$1),
19257
19258
  relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
19258
19259
  }) {};
@@ -34570,8 +34571,10 @@ const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
34570
34571
  const relativePath = toRelativePath(filePath, rootDirectory);
34571
34572
  return patterns.some((pattern) => pattern.test(relativePath));
34572
34573
  };
34574
+ const SCRIPT_EXTENSION_FRAGMENT = "[cm]?[jt]sx?";
34575
+ const STORY_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:stories|story)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
34576
+ const TEST_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:test|spec|fixture|fixtures)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
34573
34577
  const TEST_FILE_DIRECTORY_PATTERN = /(?:^|\/)(?:__tests__|__test__|tests|test|__mocks__|cypress|e2e|playwright)\//;
34574
- const TEST_FILE_SUFFIX_PATTERN = /\.(?:test|spec|stories|story|fixture|fixtures)\.(?:[cm]?[jt]sx?)$/;
34575
34578
  const FIXTURE_PROJECT_PATTERN = /\/(?:fixtures|__fixtures__)\//;
34576
34579
  const SOURCE_ROOT_PATTERN = /\/(?:src|app|lib|components|pages|features|modules|packages|apps|frontend|client)\//g;
34577
34580
  const stripAboveSourceRoot = (relativePath) => {
@@ -34582,12 +34585,23 @@ const stripAboveSourceRoot = (relativePath) => {
34582
34585
  if (lastIdx >= 0) return relativePath.slice(lastIdx);
34583
34586
  return relativePath.slice(fixtureMatch.index + fixtureMatch[0].length - 1);
34584
34587
  };
34585
- const isTestFilePath = (relativePath) => {
34586
- if (relativePath.length === 0) return false;
34588
+ /**
34589
+ * Classifies where a file sits relative to shipped code. A finding in a
34590
+ * `.stories.tsx` or `.spec.ts` file never runs in front of users, so
34591
+ * renderers label those sites instead of framing them as production
34592
+ * impact (`rn-no-raw-text` in a spec doesn't say users crash).
34593
+ *
34594
+ * `"story"` is the `.stories.*` / `.story.*` suffix; `"test"` is the
34595
+ * test/spec/fixture suffixes and test directories; `"production"` is
34596
+ * the default.
34597
+ */
34598
+ const classifyFileContext = (relativePath) => {
34599
+ if (relativePath.length === 0) return "production";
34587
34600
  const forwardSlashed = relativePath.replaceAll("\\", "/");
34588
- if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return true;
34601
+ if (STORY_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "story";
34602
+ if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "test";
34589
34603
  const scoped = stripAboveSourceRoot(forwardSlashed);
34590
- return TEST_FILE_DIRECTORY_PATTERN.test(scoped);
34604
+ return TEST_FILE_DIRECTORY_PATTERN.test(scoped) ? "test" : "production";
34591
34605
  };
34592
34606
  /**
34593
34607
  * Resolves the user-configured severity override for a rule.
@@ -34811,6 +34825,8 @@ const collectStringSet = (values) => {
34811
34825
  * 5. `rn-no-raw-text` suppression via configured `textComponents` and
34812
34826
  * `rawTextWrapperComponents` (config-driven JSX enclosure checks)
34813
34827
  * 6. inline suppressions (`// react-doctor-disable-next-line ...`)
34828
+ * 7. file-context stamping (`fileContext: "test" | "story"` on
34829
+ * survivors in non-production files, so renderers can label them)
34814
34830
  *
34815
34831
  * Returns `null` when the diagnostic is dropped, the (possibly
34816
34832
  * severity-restamped) diagnostic otherwise.
@@ -34830,7 +34846,7 @@ const buildDiagnosticPipeline = (input) => {
34830
34846
  const hasTextComponents = textComponentNames.size > 0;
34831
34847
  const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
34832
34848
  const fileLinesCache = /* @__PURE__ */ new Map();
34833
- const testFileCache = /* @__PURE__ */ new Map();
34849
+ const fileContextCache = /* @__PURE__ */ new Map();
34834
34850
  const libraryFileCache = /* @__PURE__ */ new Map();
34835
34851
  const isLibraryFile = (filePath) => {
34836
34852
  let cached = libraryFileCache.get(filePath);
@@ -34847,11 +34863,11 @@ const buildDiagnosticPipeline = (input) => {
34847
34863
  fileLinesCache.set(filePath, lines);
34848
34864
  return lines;
34849
34865
  };
34850
- const isTest = (filePath) => {
34851
- let cached = testFileCache.get(filePath);
34866
+ const getFileContext = (filePath) => {
34867
+ let cached = fileContextCache.get(filePath);
34852
34868
  if (cached === void 0) {
34853
- cached = isTestFilePath(filePath);
34854
- testFileCache.set(filePath, cached);
34869
+ cached = classifyFileContext(filePath);
34870
+ fileContextCache.set(filePath, cached);
34855
34871
  }
34856
34872
  return cached;
34857
34873
  };
@@ -34860,7 +34876,7 @@ const buildDiagnosticPipeline = (input) => {
34860
34876
  const rule = reactDoctorPlugin.rules[diagnostic.rule];
34861
34877
  if (!rule?.tags?.includes("test-noise")) return false;
34862
34878
  if (rule.tags.includes("migration-hint")) return false;
34863
- return isTest(diagnostic.filePath);
34879
+ return getFileContext(diagnostic.filePath) !== "production";
34864
34880
  };
34865
34881
  const isRuleIgnored = (ruleIdentifier) => {
34866
34882
  for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
@@ -34917,6 +34933,11 @@ const buildDiagnosticPipeline = (input) => {
34917
34933
  };
34918
34934
  }
34919
34935
  }
34936
+ const fileContext = getFileContext(current.filePath);
34937
+ if (fileContext !== "production") current = {
34938
+ ...current,
34939
+ fileContext
34940
+ };
34920
34941
  return current;
34921
34942
  } };
34922
34943
  };
@@ -37034,6 +37055,42 @@ var Files = class Files extends Service()("react-doctor/Files") {
37034
37055
  }));
37035
37056
  };
37036
37057
  };
37058
+ const HUNK_HEADER_PATTERN = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
37059
+ /**
37060
+ * Parses a `git diff --unified=0` patch into the inclusive 1-based line ranges
37061
+ * each file added or modified on the new side. Files are keyed by the path in
37062
+ * the `+++ b/<path>` header (with `--relative`, relative to the diff's cwd).
37063
+ * Added/renamed/modified files appear; pure deletions (`+++ /dev/null`) are
37064
+ * skipped because they have no new-side line to report on.
37065
+ */
37066
+ const parseChangedLineRanges = (patch) => {
37067
+ const rangesByFile = /* @__PURE__ */ new Map();
37068
+ let currentRanges = null;
37069
+ for (const line of patch.split("\n")) {
37070
+ if (line.startsWith("+++ ")) {
37071
+ const target = line.slice(4).trim();
37072
+ if (target === "/dev/null") {
37073
+ currentRanges = null;
37074
+ continue;
37075
+ }
37076
+ const file = target.startsWith("b/") ? target.slice(2) : target;
37077
+ currentRanges = rangesByFile.get(file) ?? [];
37078
+ rangesByFile.set(file, currentRanges);
37079
+ continue;
37080
+ }
37081
+ if (currentRanges === null) continue;
37082
+ const hunk = HUNK_HEADER_PATTERN.exec(line);
37083
+ if (hunk === null) continue;
37084
+ const start = Number(hunk[1]);
37085
+ const lineCount = hunk[2] === void 0 ? 1 : Number(hunk[2]);
37086
+ if (lineCount <= 0) continue;
37087
+ currentRanges.push([start, start + lineCount - 1]);
37088
+ }
37089
+ return [...rangesByFile].filter(([, ranges]) => ranges.length > 0).map(([file, ranges]) => ({
37090
+ file,
37091
+ ranges
37092
+ }));
37093
+ };
37037
37094
  const trimOrNull = (value) => {
37038
37095
  const trimmed = value.trim();
37039
37096
  return trimmed.length === 0 ? null : trimmed;
@@ -37399,6 +37456,22 @@ var Git = class Git extends Service()("react-doctor/Git") {
37399
37456
  status: result.status,
37400
37457
  stdout: result.stdout
37401
37458
  };
37459
+ }),
37460
+ changedLineRanges: ({ directory, baseRef, cached, files }) => gen(function* () {
37461
+ if (files.length === 0) return [];
37462
+ if (baseRef !== void 0 && !isSafeGitRevision(baseRef)) return null;
37463
+ const result = yield* runGit(directory, [
37464
+ "diff",
37465
+ "--unified=0",
37466
+ "--diff-filter=ACMR",
37467
+ "--relative",
37468
+ ...cached ? ["--cached"] : [],
37469
+ ...baseRef !== void 0 ? [baseRef] : [],
37470
+ "--",
37471
+ ...files
37472
+ ]);
37473
+ if (result.status !== 0) return null;
37474
+ return parseChangedLineRanges(result.stdout);
37402
37475
  })
37403
37476
  });
37404
37477
  })).pipe(provide$2(layer$2.pipe(provide$2(mergeAll$1(layer$1, layer)))));
@@ -37429,7 +37502,8 @@ var Git = class Git extends Service()("react-doctor/Git") {
37429
37502
  status: matches.length === 0 ? 1 : 0,
37430
37503
  stdout
37431
37504
  };
37432
- })
37505
+ }),
37506
+ changedLineRanges: () => succeed$2(snapshot.changedLineRanges ?? [])
37433
37507
  }));
37434
37508
  };
37435
37509
  const estimateArgsLength = (args) => args.reduce((total, argument) => total + argument.length + 1, 0);
@@ -38421,8 +38495,18 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
38421
38495
  return bindingResolution !== null && !bindingResolution.isReactUseBinding;
38422
38496
  };
38423
38497
  const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
38498
+ const LEADING_SEVERITY_LABEL_PATTERN = /^(?:Error|Warning):\s*/;
38499
+ const TRAILING_PERIOD_PATTERN = /\.$/;
38424
38500
  const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
38425
- const REACT_COMPILER_MESSAGE = "This component misses React Compiler's automatic memoization & re-renders more than it should. Rewrite the flagged code so the compiler can optimize it.";
38501
+ const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
38502
+ const REACT_COMPILER_IMPACT = "This component misses React Compiler's automatic memoization & re-renders more than it should";
38503
+ const REACT_COMPILER_ACTION = "Rewrite the flagged code so the compiler can optimize it.";
38504
+ const REACT_COMPILER_GENERIC_MESSAGE = `${REACT_COMPILER_IMPACT}. ${REACT_COMPILER_ACTION}`;
38505
+ const buildReactCompilerMessage = (reasonSummary) => {
38506
+ const normalizedSummary = reasonSummary.replace(TRAILING_PERIOD_PATTERN, "");
38507
+ if (!normalizedSummary) return REACT_COMPILER_GENERIC_MESSAGE;
38508
+ return `${REACT_COMPILER_IMPACT}: ${normalizedSummary}. ${REACT_COMPILER_ACTION}`;
38509
+ };
38426
38510
  const PLUGIN_CATEGORY_MAP = {
38427
38511
  react: "Bugs",
38428
38512
  "react-hooks": "Bugs",
@@ -38449,7 +38533,10 @@ const getRuleRecommendation = (ruleName, project) => {
38449
38533
  };
38450
38534
  const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
38451
38535
  const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
38452
- const resolveDiagnosticTitle = (plugin, rule) => plugin === "react-hooks-js" ? REACT_COMPILER_TITLE : getRuleTitle(rule);
38536
+ const resolveDiagnosticTitle = (plugin, rule) => {
38537
+ if (plugin !== "react-hooks-js") return getRuleTitle(rule);
38538
+ return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
38539
+ };
38453
38540
  const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38454
38541
  const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
38455
38542
  return {
@@ -38458,10 +38545,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38458
38545
  };
38459
38546
  };
38460
38547
  const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
38461
- if (plugin === "react-hooks-js") return {
38462
- message: REACT_COMPILER_MESSAGE,
38463
- help: appendReanimatedSharedValueHint(message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || help, rule, project)
38464
- };
38548
+ if (plugin === "react-hooks-js") {
38549
+ const bailoutReason = message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim().replace(LEADING_SEVERITY_LABEL_PATTERN, "").trim();
38550
+ if (rule === "todo") return {
38551
+ message: REACT_COMPILER_GENERIC_MESSAGE,
38552
+ help: appendReanimatedSharedValueHint(bailoutReason || help, rule, project)
38553
+ };
38554
+ const [reasonSummary = "", ...reasonDetailLines] = bailoutReason.split("\n");
38555
+ const reasonDetail = reasonDetailLines.join("\n").trim();
38556
+ return {
38557
+ message: buildReactCompilerMessage(reasonSummary.trim()),
38558
+ help: appendReanimatedSharedValueHint(reasonDetail || help, rule, project)
38559
+ };
38560
+ }
38465
38561
  return {
38466
38562
  message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
38467
38563
  help: help || getRuleRecommendation(rule, project) || ""
@@ -39128,7 +39224,7 @@ const ScoreApiResponseSchema = Struct({
39128
39224
  })))
39129
39225
  });
39130
39226
  const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
39131
- const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
39227
+ const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
39132
39228
  const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
39133
39229
  const describeFailure = (error) => {
39134
39230
  if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
@@ -39141,7 +39237,7 @@ const calculateScore = async (diagnostics, options = {}) => {
39141
39237
  const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
39142
39238
  try {
39143
39239
  const compressedBody = gzipSync(JSON.stringify({
39144
- diagnostics: stripFilePaths(diagnostics),
39240
+ diagnostics: stripLocalFileFields(diagnostics),
39145
39241
  ...options.metadata?.repo ? { repo: options.metadata.repo } : {},
39146
39242
  ...options.metadata?.sha ? { sha: options.metadata.sha } : {},
39147
39243
  ...options.metadata?.framework ? { framework: options.metadata.framework } : {},
@@ -39208,25 +39304,36 @@ const decodeArtifact = decodeUnknownOption(Struct({ score: optional(Struct({
39208
39304
  const SCORE_AXES = [
39209
39305
  {
39210
39306
  key: "supplyChain",
39211
- label: "supply chain"
39307
+ label: "supply chain",
39308
+ gates: true
39212
39309
  },
39213
39310
  {
39214
39311
  key: "vulnerability",
39215
- label: "vulnerability"
39312
+ label: "vulnerability",
39313
+ gates: true
39216
39314
  },
39217
39315
  {
39218
39316
  key: "maintenance",
39219
- label: "maintenance"
39317
+ label: "maintenance",
39318
+ gates: false
39220
39319
  },
39221
39320
  {
39222
39321
  key: "quality",
39223
- label: "quality"
39322
+ label: "quality",
39323
+ gates: false
39224
39324
  },
39225
39325
  {
39226
39326
  key: "license",
39227
- label: "license"
39327
+ label: "license",
39328
+ gates: false
39228
39329
  }
39229
39330
  ];
39331
+ const GATED_AXES = SCORE_AXES.filter((axis) => axis.gates);
39332
+ const worstGatedAxis = (score) => {
39333
+ let worst = GATED_AXES[0];
39334
+ for (const axis of GATED_AXES) if (score[axis.key] < score[worst.key]) worst = axis;
39335
+ return worst;
39336
+ };
39230
39337
  const clampScore = (value) => {
39231
39338
  if (!Number.isFinite(value)) return 50;
39232
39339
  return Math.min(Math.max(value, 0), 100);
@@ -39342,15 +39449,14 @@ const fetchSocketScore = (dependency) => tryPromise(async (signal) => {
39342
39449
  "socket.purl": toPurl(dependency)
39343
39450
  } }));
39344
39451
  const formatAxisScores = (score) => SCORE_AXES.map((axis) => `${axis.label} ${toHundred(score[axis.key])}`).join(", ");
39345
- const buildLowScoreDiagnostic = (dependency, score, options) => {
39346
- const overall = toHundred(score.overall);
39452
+ const buildLowScoreDiagnostic = (dependency, score, failingAxis, options) => {
39347
39453
  const packagePageUrl = `${SOCKET_PACKAGE_PAGE_BASE}/${dependency.name}/overview/${dependency.version}`;
39348
39454
  return {
39349
39455
  filePath: "package.json",
39350
39456
  plugin: SUPPLY_CHAIN_PLUGIN,
39351
39457
  rule: SUPPLY_CHAIN_RULE,
39352
39458
  severity: options.severity,
39353
- message: `\`${dependency.name}\` (declared in package.json as "${dependency.spec}", scored at ${dependency.version}) has a Socket supply-chain score of ${overall}/100 (below the minimum of ${options.minScore}). Axis scores — ${formatAxisScores(score)}.`,
39459
+ message: `\`${dependency.name}\` (declared in package.json as "${dependency.spec}", scored at ${dependency.version}) has a Socket ${failingAxis.label} score of ${toHundred(score[failingAxis.key])}/100 (below the minimum of ${options.minScore}). Axis scores — ${formatAxisScores(score)}.`,
39354
39460
  help: `Update or replace the \`"${dependency.name}": "${dependency.spec}"\` entry in package.json. Review ${dependency.name} on Socket: ${packagePageUrl}. Or raise \`supplyChain.minScore\` if you have vetted and accepted this package.`,
39355
39461
  url: packagePageUrl,
39356
39462
  line: dependency.line,
@@ -39362,7 +39468,9 @@ const buildLowScoreDiagnostic = (dependency, score, options) => {
39362
39468
  * Scores every direct dependency in the project's `package.json` against
39363
39469
  * Socket.dev's free PURL endpoint (the same one Socket Firewall's free tier
39364
39470
  * uses — no API key) and returns a diagnostic for each dependency whose
39365
- * Socket `overall` score is below the configured `minScore`.
39471
+ * worst Socket *security* axis — supply chain or vulnerability — is below
39472
+ * the configured `minScore`. The quality / maintenance / license axes are
39473
+ * reported as context but never gate (see GATED_AXES).
39366
39474
  *
39367
39475
  * Lookups run with bounded concurrency via `Effect.forEach`. The check is
39368
39476
  * total/fail-open: each per-package lookup already recovers to `null`
@@ -39380,8 +39488,9 @@ const checkSupplyChain = (input) => gen(function* () {
39380
39488
  for (let index = 0; index < dependencies.length; index += 1) {
39381
39489
  const score = scores[index];
39382
39490
  if (!score) continue;
39383
- if (toHundred(score.overall) >= options.minScore) continue;
39384
- diagnostics.push(buildLowScoreDiagnostic(dependencies[index], score, options));
39491
+ const worstAxis = worstGatedAxis(score);
39492
+ if (toHundred(score[worstAxis.key]) >= options.minScore) continue;
39493
+ diagnostics.push(buildLowScoreDiagnostic(dependencies[index], score, worstAxis, options));
39385
39494
  }
39386
39495
  return diagnostics;
39387
39496
  });
@@ -39389,7 +39498,8 @@ const checkSupplyChain = (input) => gen(function* () {
39389
39498
  * `SupplyChain` scores the project's direct dependencies against Socket.dev's
39390
39499
  * free, keyless PURL endpoint — the same lookup Socket Firewall's free tier
39391
39500
  * (`sfw`) performs — and streams a diagnostic for each dependency whose
39392
- * Socket score falls below the configured `supplyChain.minScore`.
39501
+ * worst Socket security axis (supply chain or vulnerability) falls below
39502
+ * the configured `supplyChain.minScore`.
39393
39503
  *
39394
39504
  * Runs by default (one network request per dependency); the orchestrator
39395
39505
  * provides `layerOf([])` only when the user opts out via
@@ -40032,13 +40142,55 @@ const clearAutoSuppressionCaches = () => {};
40032
40142
  * untouched so the loader sees the same plain object either way.
40033
40143
  */
40034
40144
  const defineConfig = (config) => config;
40145
+ const unionValues = (baseValues, overrideValues) => [...new Set([...baseValues, ...overrideValues])];
40146
+ const mergeIgnores = (baseIgnore, overrideIgnore) => {
40147
+ const mergedIgnore = {
40148
+ ...baseIgnore,
40149
+ ...overrideIgnore
40150
+ };
40151
+ if (baseIgnore.rules && overrideIgnore.rules) mergedIgnore.rules = unionValues(baseIgnore.rules, overrideIgnore.rules);
40152
+ if (baseIgnore.files && overrideIgnore.files) mergedIgnore.files = unionValues(baseIgnore.files, overrideIgnore.files);
40153
+ if (baseIgnore.tags && overrideIgnore.tags) mergedIgnore.tags = unionValues(baseIgnore.tags, overrideIgnore.tags);
40154
+ if (baseIgnore.overrides && overrideIgnore.overrides) mergedIgnore.overrides = [...baseIgnore.overrides, ...overrideIgnore.overrides];
40155
+ return mergedIgnore;
40156
+ };
40157
+ /**
40158
+ * Layer one `ReactDoctorConfig` on top of another, additively: `rules` /
40159
+ * `categories` / `supplyChain` merge per key, `ignore` lists union
40160
+ * (`ignore.overrides` concatenate), and every other field is a scalar the
40161
+ * override simply wins on when set. Returns the base unchanged when there
40162
+ * is no override, and vice versa — so callers can thread `null` /
40163
+ * `undefined` through without special-casing.
40164
+ */
40165
+ const mergeReactDoctorConfigs = (baseConfig, overrideConfig) => {
40166
+ if (overrideConfig === void 0) return baseConfig;
40167
+ if (baseConfig === null) return overrideConfig;
40168
+ const mergedConfig = {
40169
+ ...baseConfig,
40170
+ ...overrideConfig
40171
+ };
40172
+ if (baseConfig.rules && overrideConfig.rules) mergedConfig.rules = {
40173
+ ...baseConfig.rules,
40174
+ ...overrideConfig.rules
40175
+ };
40176
+ if (baseConfig.categories && overrideConfig.categories) mergedConfig.categories = {
40177
+ ...baseConfig.categories,
40178
+ ...overrideConfig.categories
40179
+ };
40180
+ if (baseConfig.supplyChain && overrideConfig.supplyChain) mergedConfig.supplyChain = {
40181
+ ...baseConfig.supplyChain,
40182
+ ...overrideConfig.supplyChain
40183
+ };
40184
+ if (baseConfig.ignore && overrideConfig.ignore) mergedConfig.ignore = mergeIgnores(baseConfig.ignore, overrideConfig.ignore);
40185
+ return mergedConfig;
40186
+ };
40035
40187
  //#endregion
40036
40188
  //#region ../api/dist/index.js
40037
- const buildDiagnoseLayer = (config, configOverride) => {
40038
- const configLayer = configOverride === void 0 ? Config.layerNode : Config.layerOf({
40189
+ const buildDiagnoseLayer = (config, configOverrideTarget) => {
40190
+ const configLayer = configOverrideTarget === void 0 ? Config.layerNode : Config.layerOf({
40039
40191
  config,
40040
- resolvedDirectory: configOverride.resolvedDirectory,
40041
- configSourceDirectory: null
40192
+ resolvedDirectory: configOverrideTarget.resolvedDirectory,
40193
+ configSourceDirectory: configOverrideTarget.configSourceDirectory
40042
40194
  });
40043
40195
  return mergeAll$1(Project.layerNode, configLayer, DeadCode.layerNode, Files.layerNode, Git.layerNode, Linter.layerOxlint, LintPartialFailures.layerLive, Progress.layerNoop, Reporter.layerNoop, Score.layerHttp, config?.supplyChain?.enabled !== false ? SupplyChain.layerNode : SupplyChain.layerOf([]));
40044
40196
  };
@@ -40070,11 +40222,64 @@ const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
40070
40222
  elapsedMilliseconds
40071
40223
  };
40072
40224
  };
40073
- const diagnose = async (directory, options = {}) => {
40225
+ const diagnoseDirectory = async (directory, options) => {
40074
40226
  const startTime = globalThis.performance.now();
40075
40227
  const scanTarget = await resolveScanTarget(directory);
40076
40228
  return outputToDiagnoseResult(await runPromise(restoreLegacyThrow(buildInspectProgram(scanTarget, options).pipe(provide(buildDiagnoseLayer(scanTarget.userConfig)), provide(layerOtlp)))), globalThis.performance.now() - startTime);
40077
40229
  };
40230
+ const findWorstScore = (projectResults) => {
40231
+ let worstResult = null;
40232
+ let worstScore = Number.POSITIVE_INFINITY;
40233
+ for (const projectResult of projectResults) {
40234
+ if (!projectResult.ok || projectResult.score === null) continue;
40235
+ if (projectResult.score.score < worstScore) {
40236
+ worstScore = projectResult.score.score;
40237
+ worstResult = projectResult.score;
40238
+ }
40239
+ }
40240
+ return worstResult;
40241
+ };
40242
+ const diagnoseProject = async (projectDefinition, baseOptions, batchConfig) => {
40243
+ const startTime = globalThis.performance.now();
40244
+ try {
40245
+ const scanTarget = await resolveScanTarget(projectDefinition.directory);
40246
+ const { directory: _, config: projectConfig, ...perProjectOptions } = projectDefinition;
40247
+ const didOverrideConfig = batchConfig !== void 0 || projectConfig !== void 0;
40248
+ const effectiveConfig = mergeReactDoctorConfigs(mergeReactDoctorConfigs(scanTarget.userConfig, batchConfig), projectConfig);
40249
+ const program = buildInspectProgram(scanTarget, {
40250
+ ...baseOptions,
40251
+ ...perProjectOptions
40252
+ }, effectiveConfig ?? void 0);
40253
+ const didOverridePlugins = batchConfig?.plugins !== void 0 || projectConfig?.plugins !== void 0;
40254
+ const layer = buildDiagnoseLayer(effectiveConfig, didOverrideConfig ? {
40255
+ resolvedDirectory: scanTarget.resolvedDirectory,
40256
+ configSourceDirectory: didOverridePlugins ? null : scanTarget.configSourceDirectory
40257
+ } : void 0);
40258
+ return {
40259
+ ok: true,
40260
+ ...outputToDiagnoseResult(await runPromise(restoreLegacyThrow(program.pipe(provide(layer), provide(layerOtlp)))), globalThis.performance.now() - startTime),
40261
+ directory: scanTarget.resolvedDirectory
40262
+ };
40263
+ } catch (error) {
40264
+ return {
40265
+ ok: false,
40266
+ directory: projectDefinition.directory,
40267
+ error: error instanceof Error ? error : new Error(String(error))
40268
+ };
40269
+ }
40270
+ };
40271
+ const diagnoseProjectBatch = async (input) => {
40272
+ const startTime = globalThis.performance.now();
40273
+ const { projects, concurrency, config: batchConfig, ...baseOptions } = input;
40274
+ const projectResults = await mapWithConcurrency(projects, concurrency ?? 4, (projectDefinition) => diagnoseProject(projectDefinition, baseOptions, batchConfig));
40275
+ return {
40276
+ projects: projectResults,
40277
+ diagnostics: projectResults.flatMap((projectResult) => projectResult.ok ? projectResult.diagnostics : []),
40278
+ score: findWorstScore(projectResults),
40279
+ elapsedMilliseconds: globalThis.performance.now() - startTime
40280
+ };
40281
+ };
40282
+ const diagnose = (async (directoryOrInput, options = {}) => typeof directoryOrInput === "string" ? diagnoseDirectory(directoryOrInput, options) : diagnoseProjectBatch(directoryOrInput));
40078
40283
  //#endregion
40079
40284
  //#region src/index.ts
40080
40285
  const clearCaches = () => {
@@ -40107,4 +40312,4 @@ const toJsonReport = (result, options) => buildJsonReport({
40107
40312
  export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
40108
40313
 
40109
40314
  //# sourceMappingURL=index.js.map
40110
- //# debugId=a4054417-b813-5ebe-8feb-dce2d3571fbc
40315
+ //# debugId=c8ddec5f-75dd-56a9-93b8-c34b1f202f7c