react-doctor 0.5.1-dev.038aaf7 → 0.5.1-dev.0a9d583

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.d.ts CHANGED
@@ -9237,6 +9237,22 @@ interface ReactDoctorConfig {
9237
9237
  * requested directory).
9238
9238
  */
9239
9239
  rootDir?: string;
9240
+ /**
9241
+ * Projects to scan and score separately — the config-file equivalent of
9242
+ * the CLI `--project` flag, for repos that always want per-module scoring
9243
+ * (e.g. a monorepo dashboard tracking each module's score daily) without
9244
+ * passing the flag on every run.
9245
+ *
9246
+ * Entries resolve exactly like `--project` values: workspace package
9247
+ * names (or directory basenames) first, then directory paths relative to
9248
+ * the scanned root. `"*"` selects every discovered workspace project.
9249
+ * Invalid entries fail the run with the same error as the flag.
9250
+ *
9251
+ * Precedence: an explicit `--project` flag overrides this list. Only the
9252
+ * config at the invocation root is consulted — `projects` inside a
9253
+ * module's own config is ignored (modules can't redirect the scan).
9254
+ */
9255
+ projects?: string[];
9240
9256
  textComponents?: string[];
9241
9257
  /**
9242
9258
  * Names of components that safely route string-only children through a
@@ -9436,6 +9452,7 @@ interface DiagnosticRelatedLocation {
9436
9452
  endColumn?: number;
9437
9453
  message: string;
9438
9454
  }
9455
+ type DiagnosticFileContext = "test" | "story" | "production";
9439
9456
  interface Diagnostic {
9440
9457
  filePath: string;
9441
9458
  plugin: string;
@@ -9462,6 +9479,12 @@ interface Diagnostic {
9462
9479
  /** 1-indexed end column of the primary span, when derivable. */
9463
9480
  endColumn?: number;
9464
9481
  category: string;
9482
+ /**
9483
+ * Set when the file never ships to users (`"test"` / `"story"`), so
9484
+ * renderers can label the site instead of implying production impact.
9485
+ * Omitted for production files (the default).
9486
+ */
9487
+ fileContext?: Exclude<DiagnosticFileContext, "production">;
9465
9488
  suppressionHint?: string;
9466
9489
  /** Secondary source locations (oxlint's non-primary labels). */
9467
9490
  relatedLocations?: DiagnosticRelatedLocation[];
@@ -9601,12 +9624,55 @@ interface DiagnoseResult {
9601
9624
  elapsedMilliseconds: number;
9602
9625
  }
9603
9626
  /**
9604
- * A single project to scan as part of a `diagnoseProjects()` batch.
9627
+ * A single project to scan as part of a `diagnose({ projects })` batch.
9605
9628
  * Scan options (`deadCode`, `lint`, etc.) are flat on the entry and
9606
9629
  * layer on top of the global defaults — omitted fields fall through.
9607
- * `config` is a full `ReactDoctorConfig` override that replaces the
9608
- * on-disk `doctor.config.*` for this project's scan.
9609
9630
  */
9631
+ interface ProjectDefinition extends DiagnoseOptions {
9632
+ directory: string;
9633
+ /**
9634
+ * Per-project config overrides, layered additively (see
9635
+ * `mergeReactDoctorConfigs`) on top of the project's on-disk
9636
+ * `doctor.config.*` and the batch-level `DiagnoseProjectsInput.config`
9637
+ * — so disabling one rule here keeps every base rule intact.
9638
+ */
9639
+ config?: ReactDoctorConfig;
9640
+ }
9641
+ interface ProjectResultOk extends DiagnoseResult {
9642
+ ok: true;
9643
+ directory: string;
9644
+ }
9645
+ interface ProjectResultError {
9646
+ ok: false;
9647
+ directory: string;
9648
+ error: Error;
9649
+ }
9650
+ type ProjectResult = ProjectResultOk | ProjectResultError;
9651
+ interface DiagnoseProjectsInput extends DiagnoseOptions {
9652
+ projects: ProjectDefinition[];
9653
+ /**
9654
+ * Config overrides applied to every project in the batch, layered
9655
+ * additively (see `mergeReactDoctorConfigs`) between each project's
9656
+ * on-disk `doctor.config.*` and its `ProjectDefinition.config` — one
9657
+ * base rule set for the batch, overridden per project only where needed.
9658
+ */
9659
+ config?: ReactDoctorConfig;
9660
+ /**
9661
+ * Maximum number of projects to scan concurrently. Defaults to
9662
+ * `DEFAULT_PROJECT_SCAN_CONCURRENCY` (4) — each project scan fans out
9663
+ * its own lint workers, so the batch is bounded rather than fully
9664
+ * parallel. Set to `1` for sequential execution. Values below 1 are
9665
+ * clamped to 1.
9666
+ */
9667
+ concurrency?: number;
9668
+ }
9669
+ interface DiagnoseProjectsResult {
9670
+ projects: ProjectResult[];
9671
+ diagnostics: Diagnostic[];
9672
+ score: ScoreResult | null;
9673
+ elapsedMilliseconds: number;
9674
+ } //#endregion
9675
+ //#region src/types/handle-error.d.ts
9610
9676
  //#endregion
9611
9677
  //#region src/types/inspect.d.ts
9612
9678
  interface InspectResult {
@@ -10027,41 +10093,20 @@ declare const defineConfig: (config: ReactDoctorConfig) => ReactDoctorConfig; //
10027
10093
  //#endregion
10028
10094
  //#region ../api/dist/index.d.ts
10029
10095
  //#region src/diagnose.d.ts
10030
- declare const diagnose: (directory: string, options?: DiagnoseOptions) => Promise<DiagnoseResult>;
10031
- /**
10032
- * Scan multiple projects in parallel and return per-project scores,
10033
- * diagnostics, and an aggregate score (worst-of across all projects).
10034
- *
10035
- * Each project runs its own independent `runInspect` pipeline — the
10036
- * same pipeline `diagnose()` uses — so per-project config overrides,
10037
- * dead-code analysis, and scoring all work identically to a single
10038
- * `diagnose()` call.
10039
- *
10040
- * Projects that fail (e.g. missing `package.json`, no React dependency)
10041
- * are included in the result with `ok: false` rather than aborting the
10042
- * entire batch, so callers always receive partial results.
10043
- *
10044
- * ```ts
10045
- * const result = await diagnoseProjects({
10046
- * projects: [
10047
- * { directory: "packages/app" },
10048
- * { directory: "packages/shared", deadCode: false },
10049
- * { directory: "packages/admin", config: {
10050
- * rules: { "react-doctor/no-array-index-as-key": "off" },
10051
- * }},
10052
- * ],
10053
- * concurrency: 4,
10054
- * });
10055
- *
10056
- * for (const project of result.projects) {
10057
- * if (project.ok) {
10058
- * console.log(project.directory, project.score);
10059
- * } else {
10060
- * console.error(project.directory, project.error);
10061
- * }
10062
- * }
10063
- * ```
10064
- */
10096
+ interface Diagnose {
10097
+ /** Scan a single project directory and return diagnostics + score. */
10098
+ (directory: string, options?: DiagnoseOptions): Promise<DiagnoseResult>;
10099
+ /**
10100
+ * Scan multiple projects in parallel — each through the same pipeline as
10101
+ * the single-directory form — and return per-project results plus an
10102
+ * aggregate worst-of score. A failing project (e.g. no `package.json`)
10103
+ * comes back with `ok: false` instead of aborting the batch. Per-project
10104
+ * `config` layers on the batch `config`, which layers on each project's
10105
+ * on-disk config (see `mergeReactDoctorConfigs`).
10106
+ */
10107
+ (input: DiagnoseProjectsInput): Promise<DiagnoseProjectsResult>;
10108
+ }
10109
+ declare const diagnose: Diagnose; //#endregion
10065
10110
  //#endregion
10066
10111
  //#region src/index.d.ts
10067
10112
  declare const clearCaches: () => void;
@@ -10072,5 +10117,5 @@ interface ToJsonReportOptions {
10072
10117
  }
10073
10118
  declare const toJsonReport: (result: DiagnoseResult, options: ToJsonReportOptions) => JsonReport;
10074
10119
  //#endregion
10075
- export { AmbiguousProjectError, type DiagnoseOptions, type DiagnoseResult, type Diagnostic, type DiffInfo, type JsonReport, type JsonReportDiffInfo, type JsonReportError, type JsonReportMode, type JsonReportProjectEntry, type JsonReportSummary, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, type ProjectInfo, ProjectNotFoundError, type ReactDoctorConfig, ReactDoctorError, type ScoreResult, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
10120
+ export { AmbiguousProjectError, type DiagnoseOptions, type DiagnoseProjectsInput, type DiagnoseProjectsResult, type DiagnoseResult, type Diagnostic, type DiffInfo, type JsonReport, type JsonReportDiffInfo, type JsonReportError, type JsonReportMode, type JsonReportProjectEntry, type JsonReportSummary, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, type ProjectDefinition, type ProjectInfo, ProjectNotFoundError, type ProjectResult, type ProjectResultError, type ProjectResultOk, type ReactDoctorConfig, ReactDoctorError, type ScoreResult, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
10076
10121
  //# sourceMappingURL=index.d.ts.map
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]="0090e471-3c19-51d5-8774-cc4c6a98e591")}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
  };
@@ -38474,8 +38495,18 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
38474
38495
  return bindingResolution !== null && !bindingResolution.isReactUseBinding;
38475
38496
  };
38476
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 = /\.$/;
38477
38500
  const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
38478
- 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
+ };
38479
38510
  const PLUGIN_CATEGORY_MAP = {
38480
38511
  react: "Bugs",
38481
38512
  "react-hooks": "Bugs",
@@ -38502,7 +38533,10 @@ const getRuleRecommendation = (ruleName, project) => {
38502
38533
  };
38503
38534
  const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
38504
38535
  const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
38505
- 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
+ };
38506
38540
  const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38507
38541
  const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
38508
38542
  return {
@@ -38511,10 +38545,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
38511
38545
  };
38512
38546
  };
38513
38547
  const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
38514
- if (plugin === "react-hooks-js") return {
38515
- message: REACT_COMPILER_MESSAGE,
38516
- help: appendReanimatedSharedValueHint(message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || help, rule, project)
38517
- };
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
+ }
38518
38561
  return {
38519
38562
  message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
38520
38563
  help: help || getRuleRecommendation(rule, project) || ""
@@ -39181,7 +39224,7 @@ const ScoreApiResponseSchema = Struct({
39181
39224
  })))
39182
39225
  });
39183
39226
  const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
39184
- const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
39227
+ const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
39185
39228
  const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
39186
39229
  const describeFailure = (error) => {
39187
39230
  if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
@@ -39194,7 +39237,7 @@ const calculateScore = async (diagnostics, options = {}) => {
39194
39237
  const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
39195
39238
  try {
39196
39239
  const compressedBody = gzipSync(JSON.stringify({
39197
- diagnostics: stripFilePaths(diagnostics),
39240
+ diagnostics: stripLocalFileFields(diagnostics),
39198
39241
  ...options.metadata?.repo ? { repo: options.metadata.repo } : {},
39199
39242
  ...options.metadata?.sha ? { sha: options.metadata.sha } : {},
39200
39243
  ...options.metadata?.framework ? { framework: options.metadata.framework } : {},
@@ -40099,13 +40142,55 @@ const clearAutoSuppressionCaches = () => {};
40099
40142
  * untouched so the loader sees the same plain object either way.
40100
40143
  */
40101
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
+ };
40102
40187
  //#endregion
40103
40188
  //#region ../api/dist/index.js
40104
- const buildDiagnoseLayer = (config, configOverride) => {
40105
- const configLayer = configOverride === void 0 ? Config.layerNode : Config.layerOf({
40189
+ const buildDiagnoseLayer = (config, configOverrideTarget) => {
40190
+ const configLayer = configOverrideTarget === void 0 ? Config.layerNode : Config.layerOf({
40106
40191
  config,
40107
- resolvedDirectory: configOverride.resolvedDirectory,
40108
- configSourceDirectory: null
40192
+ resolvedDirectory: configOverrideTarget.resolvedDirectory,
40193
+ configSourceDirectory: configOverrideTarget.configSourceDirectory
40109
40194
  });
40110
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([]));
40111
40196
  };
@@ -40137,11 +40222,64 @@ const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
40137
40222
  elapsedMilliseconds
40138
40223
  };
40139
40224
  };
40140
- const diagnose = async (directory, options = {}) => {
40225
+ const diagnoseDirectory = async (directory, options) => {
40141
40226
  const startTime = globalThis.performance.now();
40142
40227
  const scanTarget = await resolveScanTarget(directory);
40143
40228
  return outputToDiagnoseResult(await runPromise(restoreLegacyThrow(buildInspectProgram(scanTarget, options).pipe(provide(buildDiagnoseLayer(scanTarget.userConfig)), provide(layerOtlp)))), globalThis.performance.now() - startTime);
40144
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));
40145
40283
  //#endregion
40146
40284
  //#region src/index.ts
40147
40285
  const clearCaches = () => {
@@ -40174,4 +40312,4 @@ const toJsonReport = (result, options) => buildJsonReport({
40174
40312
  export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
40175
40313
 
40176
40314
  //# sourceMappingURL=index.js.map
40177
- //# debugId=0090e471-3c19-51d5-8774-cc4c6a98e591
40315
+ //# debugId=c8ddec5f-75dd-56a9-93b8-c34b1f202f7c