react-doctor 0.5.1-dev.22268f7 → 0.5.1-dev.3de9106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +332 -126
- package/dist/index.d.ts +84 -39
- package/dist/index.js +225 -45
- package/dist/lsp.js +127 -40
- package/package.json +4 -4
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 `
|
|
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
|
-
|
|
10031
|
-
/**
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
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]="
|
|
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]="5c0d7930-333e-5d67-93cf-63eae9bd87f8")}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";
|
|
@@ -13,9 +13,10 @@ import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_
|
|
|
13
13
|
import * as OS from "node:os";
|
|
14
14
|
import os from "node:os";
|
|
15
15
|
import { parseJSON5 } from "confbox";
|
|
16
|
+
import * as NodeUrl from "node:url";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
16
18
|
import { createJiti } from "jiti";
|
|
17
19
|
import * as Crypto from "node:crypto";
|
|
18
|
-
import * as NodeUrl from "node:url";
|
|
19
20
|
import { gzipSync } from "node:zlib";
|
|
20
21
|
//#region ../../node_modules/.pnpm/effect@4.0.0-beta.70/node_modules/effect/dist/Pipeable.js
|
|
21
22
|
/**
|
|
@@ -19253,6 +19254,7 @@ var Diagnostic = class extends Class("Diagnostic")({
|
|
|
19253
19254
|
endLine: optional(Number$1),
|
|
19254
19255
|
endColumn: optional(Number$1),
|
|
19255
19256
|
category: String$1,
|
|
19257
|
+
fileContext: optional(Literals(["test", "story"])),
|
|
19256
19258
|
suppressionHint: optional(String$1),
|
|
19257
19259
|
relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
|
|
19258
19260
|
}) {};
|
|
@@ -34570,8 +34572,10 @@ const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
|
|
|
34570
34572
|
const relativePath = toRelativePath(filePath, rootDirectory);
|
|
34571
34573
|
return patterns.some((pattern) => pattern.test(relativePath));
|
|
34572
34574
|
};
|
|
34575
|
+
const SCRIPT_EXTENSION_FRAGMENT = "[cm]?[jt]sx?";
|
|
34576
|
+
const STORY_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:stories|story)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
|
|
34577
|
+
const TEST_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:test|spec|fixture|fixtures)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
|
|
34573
34578
|
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
34579
|
const FIXTURE_PROJECT_PATTERN = /\/(?:fixtures|__fixtures__)\//;
|
|
34576
34580
|
const SOURCE_ROOT_PATTERN = /\/(?:src|app|lib|components|pages|features|modules|packages|apps|frontend|client)\//g;
|
|
34577
34581
|
const stripAboveSourceRoot = (relativePath) => {
|
|
@@ -34582,12 +34586,23 @@ const stripAboveSourceRoot = (relativePath) => {
|
|
|
34582
34586
|
if (lastIdx >= 0) return relativePath.slice(lastIdx);
|
|
34583
34587
|
return relativePath.slice(fixtureMatch.index + fixtureMatch[0].length - 1);
|
|
34584
34588
|
};
|
|
34585
|
-
|
|
34586
|
-
|
|
34589
|
+
/**
|
|
34590
|
+
* Classifies where a file sits relative to shipped code. A finding in a
|
|
34591
|
+
* `.stories.tsx` or `.spec.ts` file never runs in front of users, so
|
|
34592
|
+
* renderers label those sites instead of framing them as production
|
|
34593
|
+
* impact (`rn-no-raw-text` in a spec doesn't say users crash).
|
|
34594
|
+
*
|
|
34595
|
+
* `"story"` is the `.stories.*` / `.story.*` suffix; `"test"` is the
|
|
34596
|
+
* test/spec/fixture suffixes and test directories; `"production"` is
|
|
34597
|
+
* the default.
|
|
34598
|
+
*/
|
|
34599
|
+
const classifyFileContext = (relativePath) => {
|
|
34600
|
+
if (relativePath.length === 0) return "production";
|
|
34587
34601
|
const forwardSlashed = relativePath.replaceAll("\\", "/");
|
|
34588
|
-
if (
|
|
34602
|
+
if (STORY_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "story";
|
|
34603
|
+
if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "test";
|
|
34589
34604
|
const scoped = stripAboveSourceRoot(forwardSlashed);
|
|
34590
|
-
return TEST_FILE_DIRECTORY_PATTERN.test(scoped);
|
|
34605
|
+
return TEST_FILE_DIRECTORY_PATTERN.test(scoped) ? "test" : "production";
|
|
34591
34606
|
};
|
|
34592
34607
|
/**
|
|
34593
34608
|
* Resolves the user-configured severity override for a rule.
|
|
@@ -34811,6 +34826,8 @@ const collectStringSet = (values) => {
|
|
|
34811
34826
|
* 5. `rn-no-raw-text` suppression via configured `textComponents` and
|
|
34812
34827
|
* `rawTextWrapperComponents` (config-driven JSX enclosure checks)
|
|
34813
34828
|
* 6. inline suppressions (`// react-doctor-disable-next-line ...`)
|
|
34829
|
+
* 7. file-context stamping (`fileContext: "test" | "story"` on
|
|
34830
|
+
* survivors in non-production files, so renderers can label them)
|
|
34814
34831
|
*
|
|
34815
34832
|
* Returns `null` when the diagnostic is dropped, the (possibly
|
|
34816
34833
|
* severity-restamped) diagnostic otherwise.
|
|
@@ -34830,7 +34847,7 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34830
34847
|
const hasTextComponents = textComponentNames.size > 0;
|
|
34831
34848
|
const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
|
|
34832
34849
|
const fileLinesCache = /* @__PURE__ */ new Map();
|
|
34833
|
-
const
|
|
34850
|
+
const fileContextCache = /* @__PURE__ */ new Map();
|
|
34834
34851
|
const libraryFileCache = /* @__PURE__ */ new Map();
|
|
34835
34852
|
const isLibraryFile = (filePath) => {
|
|
34836
34853
|
let cached = libraryFileCache.get(filePath);
|
|
@@ -34847,11 +34864,11 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34847
34864
|
fileLinesCache.set(filePath, lines);
|
|
34848
34865
|
return lines;
|
|
34849
34866
|
};
|
|
34850
|
-
const
|
|
34851
|
-
let cached =
|
|
34867
|
+
const getFileContext = (filePath) => {
|
|
34868
|
+
let cached = fileContextCache.get(filePath);
|
|
34852
34869
|
if (cached === void 0) {
|
|
34853
|
-
cached =
|
|
34854
|
-
|
|
34870
|
+
cached = classifyFileContext(filePath);
|
|
34871
|
+
fileContextCache.set(filePath, cached);
|
|
34855
34872
|
}
|
|
34856
34873
|
return cached;
|
|
34857
34874
|
};
|
|
@@ -34860,7 +34877,7 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34860
34877
|
const rule = reactDoctorPlugin.rules[diagnostic.rule];
|
|
34861
34878
|
if (!rule?.tags?.includes("test-noise")) return false;
|
|
34862
34879
|
if (rule.tags.includes("migration-hint")) return false;
|
|
34863
|
-
return
|
|
34880
|
+
return getFileContext(diagnostic.filePath) !== "production";
|
|
34864
34881
|
};
|
|
34865
34882
|
const isRuleIgnored = (ruleIdentifier) => {
|
|
34866
34883
|
for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
|
|
@@ -34917,6 +34934,11 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34917
34934
|
};
|
|
34918
34935
|
}
|
|
34919
34936
|
}
|
|
34937
|
+
const fileContext = getFileContext(current.filePath);
|
|
34938
|
+
if (fileContext !== "production") current = {
|
|
34939
|
+
...current,
|
|
34940
|
+
fileContext
|
|
34941
|
+
};
|
|
34920
34942
|
return current;
|
|
34921
34943
|
} };
|
|
34922
34944
|
};
|
|
@@ -35313,10 +35335,41 @@ const PACKAGE_JSON_CONFIG_KEY = "reactDoctor";
|
|
|
35313
35335
|
const LEGACY_CONFIG_FILENAME = "react-doctor.config.json";
|
|
35314
35336
|
const jiti = createJiti(import.meta.url);
|
|
35315
35337
|
const formatError = (error) => error instanceof Error ? error.message : String(error);
|
|
35316
|
-
const
|
|
35317
|
-
const imported = await
|
|
35338
|
+
const importDefaultExport = async (jitiInstance, filePath) => {
|
|
35339
|
+
const imported = await jitiInstance.import(filePath);
|
|
35318
35340
|
return imported?.default ?? imported;
|
|
35319
35341
|
};
|
|
35342
|
+
const SELF_PACKAGE_IMPORT_SPECIFIER = "react-doctor/api";
|
|
35343
|
+
const SELF_PACKAGE_RESOLVE_TARGETS = ["react-doctor/api", "@react-doctor/core"];
|
|
35344
|
+
const MODULE_NOT_FOUND_ERROR_CODES = new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
35345
|
+
let selfAliasJiti;
|
|
35346
|
+
const getSelfAliasJiti = () => {
|
|
35347
|
+
if (selfAliasJiti !== void 0) return selfAliasJiti;
|
|
35348
|
+
for (const resolveTarget of SELF_PACKAGE_RESOLVE_TARGETS) try {
|
|
35349
|
+
const aliasTargetPath = fileURLToPath(jiti.esmResolve(resolveTarget));
|
|
35350
|
+
selfAliasJiti = createJiti(import.meta.url, { alias: { [SELF_PACKAGE_IMPORT_SPECIFIER]: aliasTargetPath } });
|
|
35351
|
+
return selfAliasJiti;
|
|
35352
|
+
} catch {
|
|
35353
|
+
continue;
|
|
35354
|
+
}
|
|
35355
|
+
selfAliasJiti = null;
|
|
35356
|
+
return selfAliasJiti;
|
|
35357
|
+
};
|
|
35358
|
+
const isSelfPackageResolutionError = (error) => error instanceof Error && "code" in error && typeof error.code === "string" && MODULE_NOT_FOUND_ERROR_CODES.has(error.code) && error.message.includes(SELF_PACKAGE_IMPORT_SPECIFIER);
|
|
35359
|
+
const loadModuleConfig = async (filePath) => {
|
|
35360
|
+
try {
|
|
35361
|
+
return await importDefaultExport(jiti, filePath);
|
|
35362
|
+
} catch (error) {
|
|
35363
|
+
if (!isSelfPackageResolutionError(error)) throw error;
|
|
35364
|
+
const aliasJiti = getSelfAliasJiti();
|
|
35365
|
+
if (!aliasJiti) throw error;
|
|
35366
|
+
try {
|
|
35367
|
+
return await importDefaultExport(aliasJiti, filePath);
|
|
35368
|
+
} catch (retryError) {
|
|
35369
|
+
throw new Error(`${formatError(error)} (retry with ${SELF_PACKAGE_IMPORT_SPECIFIER} aliased to the running react-doctor package also failed: ${formatError(retryError)})`, { cause: retryError });
|
|
35370
|
+
}
|
|
35371
|
+
}
|
|
35372
|
+
};
|
|
35320
35373
|
const readDataConfig = (filePath) => parseJSON5(NFS.readFileSync(filePath, "utf-8"));
|
|
35321
35374
|
const readEmbeddedPackageJsonConfig = (directory) => {
|
|
35322
35375
|
const packageJsonPath = Path.join(directory, PACKAGE_JSON_FILENAME);
|
|
@@ -36024,6 +36077,17 @@ const checkPnpmHardening = (rootDirectory) => {
|
|
|
36024
36077
|
}));
|
|
36025
36078
|
return diagnostics;
|
|
36026
36079
|
};
|
|
36080
|
+
const buildReactNativeDiagnostic = (input) => ({
|
|
36081
|
+
filePath: input.filePath,
|
|
36082
|
+
plugin: "react-doctor",
|
|
36083
|
+
rule: input.rule,
|
|
36084
|
+
severity: input.severity ?? "warning",
|
|
36085
|
+
message: input.message,
|
|
36086
|
+
help: input.help,
|
|
36087
|
+
line: input.line ?? 0,
|
|
36088
|
+
column: input.column ?? 0,
|
|
36089
|
+
category: input.category ?? "Correctness"
|
|
36090
|
+
});
|
|
36027
36091
|
const BUILDER_BOB_PACKAGE = "react-native-builder-bob";
|
|
36028
36092
|
const isBuilderBobLibrary = (packageJson) => {
|
|
36029
36093
|
const bobConfig = packageJson[BUILDER_BOB_PACKAGE];
|
|
@@ -36035,17 +36099,12 @@ const checkReactNativeLibraryDependencies = (rootDirectory) => {
|
|
|
36035
36099
|
const misplaced = ["react", "react-native"].filter((name) => packageJson.dependencies?.[name] !== void 0);
|
|
36036
36100
|
if (misplaced.length === 0) return [];
|
|
36037
36101
|
const quoted = misplaced.map((name) => `"${name}"`).join(" and ");
|
|
36038
|
-
return [{
|
|
36102
|
+
return [buildReactNativeDiagnostic({
|
|
36039
36103
|
filePath: "package.json",
|
|
36040
|
-
plugin: "react-doctor",
|
|
36041
36104
|
rule: "rn-library-react-in-dependencies",
|
|
36042
|
-
severity: "warning",
|
|
36043
36105
|
message: `This react-native-builder-bob library lists ${quoted} in \`dependencies\` — that ships a second copy into consumer apps, causing "Invalid hook call" (duplicate React) and duplicate-native-module crashes.`,
|
|
36044
|
-
help: `Move ${quoted} to \`peerDependencies\` (keep ${misplaced.length === 1 ? "it" : "them"} in \`devDependencies\` for local development)
|
|
36045
|
-
|
|
36046
|
-
column: 0,
|
|
36047
|
-
category: "Correctness"
|
|
36048
|
-
}];
|
|
36106
|
+
help: `Move ${quoted} to \`peerDependencies\` (keep ${misplaced.length === 1 ? "it" : "them"} in \`devDependencies\` for local development).`
|
|
36107
|
+
})];
|
|
36049
36108
|
};
|
|
36050
36109
|
const BABEL_CONFIG_FILE_NAMES = [
|
|
36051
36110
|
"babel.config.js",
|
|
@@ -36057,6 +36116,8 @@ const BABEL_CONFIG_FILE_NAMES = [
|
|
|
36057
36116
|
".babelrc.json"
|
|
36058
36117
|
];
|
|
36059
36118
|
const LEGACY_PRESET_SPEC = "module:metro-react-native-babel-preset";
|
|
36119
|
+
const MODERN_PRESET_REFERENCE = new RegExp(`['"]module:@react-native/babel-preset['"]`);
|
|
36120
|
+
const ENABLE_BABEL_RUNTIME_VERSION = /enableBabelRuntime["']?\s*:\s*['"]/;
|
|
36060
36121
|
const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
36061
36122
|
for (const fileName of BABEL_CONFIG_FILE_NAMES) {
|
|
36062
36123
|
const filePath = Path.join(rootDirectory, fileName);
|
|
@@ -36067,18 +36128,20 @@ const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
|
36067
36128
|
} catch {
|
|
36068
36129
|
continue;
|
|
36069
36130
|
}
|
|
36070
|
-
if (
|
|
36071
|
-
return [{
|
|
36131
|
+
if (contents.includes(LEGACY_PRESET_SPEC)) return [buildReactNativeDiagnostic({
|
|
36072
36132
|
filePath: fileName,
|
|
36073
|
-
plugin: "react-doctor",
|
|
36074
36133
|
rule: "rn-no-metro-babel-preset",
|
|
36075
36134
|
severity: "error",
|
|
36076
36135
|
message: "`module:metro-react-native-babel-preset` was renamed to `@react-native/babel-preset` and is no longer installed by React Native 0.73+ — this preset reference fails to resolve and breaks the Metro/Babel transform.",
|
|
36077
|
-
help: "Replace the preset with `module:@react-native/babel-preset` (or `babel-preset-expo` on Expo) and remove the old `metro-react-native-babel-preset` dependency."
|
|
36078
|
-
|
|
36079
|
-
|
|
36080
|
-
|
|
36081
|
-
|
|
36136
|
+
help: "Replace the preset with `module:@react-native/babel-preset` (or `babel-preset-expo` on Expo) and remove the old `metro-react-native-babel-preset` dependency."
|
|
36137
|
+
})];
|
|
36138
|
+
if (MODERN_PRESET_REFERENCE.test(contents) && !ENABLE_BABEL_RUNTIME_VERSION.test(contents)) return [buildReactNativeDiagnostic({
|
|
36139
|
+
filePath: fileName,
|
|
36140
|
+
rule: "rn-no-metro-babel-runtime-version",
|
|
36141
|
+
severity: "warning",
|
|
36142
|
+
message: "`module:@react-native/babel-preset` has no `enableBabelRuntime` version, so Babel runtime helpers can be duplicated across files instead of imported once from @babel/runtime, increasing the JS bundle size.",
|
|
36143
|
+
help: "Set `enableBabelRuntime` to the @babel/runtime version from package.json, e.g. `['module:@react-native/babel-preset', { enableBabelRuntime: '^7.26.0' }]`."
|
|
36144
|
+
})];
|
|
36082
36145
|
}
|
|
36083
36146
|
return [];
|
|
36084
36147
|
};
|
|
@@ -38474,8 +38537,18 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
38474
38537
|
return bindingResolution !== null && !bindingResolution.isReactUseBinding;
|
|
38475
38538
|
};
|
|
38476
38539
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
38540
|
+
const LEADING_SEVERITY_LABEL_PATTERN = /^(?:Error|Warning):\s*/;
|
|
38541
|
+
const TRAILING_PERIOD_PATTERN = /\.$/;
|
|
38477
38542
|
const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
|
|
38478
|
-
const
|
|
38543
|
+
const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
|
|
38544
|
+
const REACT_COMPILER_IMPACT = "This component misses React Compiler's automatic memoization & re-renders more than it should";
|
|
38545
|
+
const REACT_COMPILER_ACTION = "Rewrite the flagged code so the compiler can optimize it.";
|
|
38546
|
+
const REACT_COMPILER_GENERIC_MESSAGE = `${REACT_COMPILER_IMPACT}. ${REACT_COMPILER_ACTION}`;
|
|
38547
|
+
const buildReactCompilerMessage = (reasonSummary) => {
|
|
38548
|
+
const normalizedSummary = reasonSummary.replace(TRAILING_PERIOD_PATTERN, "");
|
|
38549
|
+
if (!normalizedSummary) return REACT_COMPILER_GENERIC_MESSAGE;
|
|
38550
|
+
return `${REACT_COMPILER_IMPACT}: ${normalizedSummary}. ${REACT_COMPILER_ACTION}`;
|
|
38551
|
+
};
|
|
38479
38552
|
const PLUGIN_CATEGORY_MAP = {
|
|
38480
38553
|
react: "Bugs",
|
|
38481
38554
|
"react-hooks": "Bugs",
|
|
@@ -38502,7 +38575,10 @@ const getRuleRecommendation = (ruleName, project) => {
|
|
|
38502
38575
|
};
|
|
38503
38576
|
const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
|
|
38504
38577
|
const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
|
|
38505
|
-
const resolveDiagnosticTitle = (plugin, rule) =>
|
|
38578
|
+
const resolveDiagnosticTitle = (plugin, rule) => {
|
|
38579
|
+
if (plugin !== "react-hooks-js") return getRuleTitle(rule);
|
|
38580
|
+
return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
|
|
38581
|
+
};
|
|
38506
38582
|
const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
38507
38583
|
const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
|
|
38508
38584
|
return {
|
|
@@ -38511,10 +38587,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
|
38511
38587
|
};
|
|
38512
38588
|
};
|
|
38513
38589
|
const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
|
|
38514
|
-
if (plugin === "react-hooks-js")
|
|
38515
|
-
message
|
|
38516
|
-
|
|
38517
|
-
|
|
38590
|
+
if (plugin === "react-hooks-js") {
|
|
38591
|
+
const bailoutReason = message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim().replace(LEADING_SEVERITY_LABEL_PATTERN, "").trim();
|
|
38592
|
+
if (rule === "todo") return {
|
|
38593
|
+
message: REACT_COMPILER_GENERIC_MESSAGE,
|
|
38594
|
+
help: appendReanimatedSharedValueHint(bailoutReason || help, rule, project)
|
|
38595
|
+
};
|
|
38596
|
+
const [reasonSummary = "", ...reasonDetailLines] = bailoutReason.split("\n");
|
|
38597
|
+
const reasonDetail = reasonDetailLines.join("\n").trim();
|
|
38598
|
+
return {
|
|
38599
|
+
message: buildReactCompilerMessage(reasonSummary.trim()),
|
|
38600
|
+
help: appendReanimatedSharedValueHint(reasonDetail || help, rule, project)
|
|
38601
|
+
};
|
|
38602
|
+
}
|
|
38518
38603
|
return {
|
|
38519
38604
|
message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
|
|
38520
38605
|
help: help || getRuleRecommendation(rule, project) || ""
|
|
@@ -39181,7 +39266,7 @@ const ScoreApiResponseSchema = Struct({
|
|
|
39181
39266
|
})))
|
|
39182
39267
|
});
|
|
39183
39268
|
const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
|
|
39184
|
-
const
|
|
39269
|
+
const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
|
|
39185
39270
|
const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
39186
39271
|
const describeFailure = (error) => {
|
|
39187
39272
|
if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
|
|
@@ -39194,7 +39279,7 @@ const calculateScore = async (diagnostics, options = {}) => {
|
|
|
39194
39279
|
const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
|
|
39195
39280
|
try {
|
|
39196
39281
|
const compressedBody = gzipSync(JSON.stringify({
|
|
39197
|
-
diagnostics:
|
|
39282
|
+
diagnostics: stripLocalFileFields(diagnostics),
|
|
39198
39283
|
...options.metadata?.repo ? { repo: options.metadata.repo } : {},
|
|
39199
39284
|
...options.metadata?.sha ? { sha: options.metadata.sha } : {},
|
|
39200
39285
|
...options.metadata?.framework ? { framework: options.metadata.framework } : {},
|
|
@@ -40099,13 +40184,55 @@ const clearAutoSuppressionCaches = () => {};
|
|
|
40099
40184
|
* untouched so the loader sees the same plain object either way.
|
|
40100
40185
|
*/
|
|
40101
40186
|
const defineConfig = (config) => config;
|
|
40187
|
+
const unionValues = (baseValues, overrideValues) => [...new Set([...baseValues, ...overrideValues])];
|
|
40188
|
+
const mergeIgnores = (baseIgnore, overrideIgnore) => {
|
|
40189
|
+
const mergedIgnore = {
|
|
40190
|
+
...baseIgnore,
|
|
40191
|
+
...overrideIgnore
|
|
40192
|
+
};
|
|
40193
|
+
if (baseIgnore.rules && overrideIgnore.rules) mergedIgnore.rules = unionValues(baseIgnore.rules, overrideIgnore.rules);
|
|
40194
|
+
if (baseIgnore.files && overrideIgnore.files) mergedIgnore.files = unionValues(baseIgnore.files, overrideIgnore.files);
|
|
40195
|
+
if (baseIgnore.tags && overrideIgnore.tags) mergedIgnore.tags = unionValues(baseIgnore.tags, overrideIgnore.tags);
|
|
40196
|
+
if (baseIgnore.overrides && overrideIgnore.overrides) mergedIgnore.overrides = [...baseIgnore.overrides, ...overrideIgnore.overrides];
|
|
40197
|
+
return mergedIgnore;
|
|
40198
|
+
};
|
|
40199
|
+
/**
|
|
40200
|
+
* Layer one `ReactDoctorConfig` on top of another, additively: `rules` /
|
|
40201
|
+
* `categories` / `supplyChain` merge per key, `ignore` lists union
|
|
40202
|
+
* (`ignore.overrides` concatenate), and every other field is a scalar the
|
|
40203
|
+
* override simply wins on when set. Returns the base unchanged when there
|
|
40204
|
+
* is no override, and vice versa — so callers can thread `null` /
|
|
40205
|
+
* `undefined` through without special-casing.
|
|
40206
|
+
*/
|
|
40207
|
+
const mergeReactDoctorConfigs = (baseConfig, overrideConfig) => {
|
|
40208
|
+
if (overrideConfig === void 0) return baseConfig;
|
|
40209
|
+
if (baseConfig === null) return overrideConfig;
|
|
40210
|
+
const mergedConfig = {
|
|
40211
|
+
...baseConfig,
|
|
40212
|
+
...overrideConfig
|
|
40213
|
+
};
|
|
40214
|
+
if (baseConfig.rules && overrideConfig.rules) mergedConfig.rules = {
|
|
40215
|
+
...baseConfig.rules,
|
|
40216
|
+
...overrideConfig.rules
|
|
40217
|
+
};
|
|
40218
|
+
if (baseConfig.categories && overrideConfig.categories) mergedConfig.categories = {
|
|
40219
|
+
...baseConfig.categories,
|
|
40220
|
+
...overrideConfig.categories
|
|
40221
|
+
};
|
|
40222
|
+
if (baseConfig.supplyChain && overrideConfig.supplyChain) mergedConfig.supplyChain = {
|
|
40223
|
+
...baseConfig.supplyChain,
|
|
40224
|
+
...overrideConfig.supplyChain
|
|
40225
|
+
};
|
|
40226
|
+
if (baseConfig.ignore && overrideConfig.ignore) mergedConfig.ignore = mergeIgnores(baseConfig.ignore, overrideConfig.ignore);
|
|
40227
|
+
return mergedConfig;
|
|
40228
|
+
};
|
|
40102
40229
|
//#endregion
|
|
40103
40230
|
//#region ../api/dist/index.js
|
|
40104
|
-
const buildDiagnoseLayer = (config,
|
|
40105
|
-
const configLayer =
|
|
40231
|
+
const buildDiagnoseLayer = (config, configOverrideTarget) => {
|
|
40232
|
+
const configLayer = configOverrideTarget === void 0 ? Config.layerNode : Config.layerOf({
|
|
40106
40233
|
config,
|
|
40107
|
-
resolvedDirectory:
|
|
40108
|
-
configSourceDirectory:
|
|
40234
|
+
resolvedDirectory: configOverrideTarget.resolvedDirectory,
|
|
40235
|
+
configSourceDirectory: configOverrideTarget.configSourceDirectory
|
|
40109
40236
|
});
|
|
40110
40237
|
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
40238
|
};
|
|
@@ -40137,11 +40264,64 @@ const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
|
|
|
40137
40264
|
elapsedMilliseconds
|
|
40138
40265
|
};
|
|
40139
40266
|
};
|
|
40140
|
-
const
|
|
40267
|
+
const diagnoseDirectory = async (directory, options) => {
|
|
40141
40268
|
const startTime = globalThis.performance.now();
|
|
40142
40269
|
const scanTarget = await resolveScanTarget(directory);
|
|
40143
40270
|
return outputToDiagnoseResult(await runPromise(restoreLegacyThrow(buildInspectProgram(scanTarget, options).pipe(provide(buildDiagnoseLayer(scanTarget.userConfig)), provide(layerOtlp)))), globalThis.performance.now() - startTime);
|
|
40144
40271
|
};
|
|
40272
|
+
const findWorstScore = (projectResults) => {
|
|
40273
|
+
let worstResult = null;
|
|
40274
|
+
let worstScore = Number.POSITIVE_INFINITY;
|
|
40275
|
+
for (const projectResult of projectResults) {
|
|
40276
|
+
if (!projectResult.ok || projectResult.score === null) continue;
|
|
40277
|
+
if (projectResult.score.score < worstScore) {
|
|
40278
|
+
worstScore = projectResult.score.score;
|
|
40279
|
+
worstResult = projectResult.score;
|
|
40280
|
+
}
|
|
40281
|
+
}
|
|
40282
|
+
return worstResult;
|
|
40283
|
+
};
|
|
40284
|
+
const diagnoseProject = async (projectDefinition, baseOptions, batchConfig) => {
|
|
40285
|
+
const startTime = globalThis.performance.now();
|
|
40286
|
+
try {
|
|
40287
|
+
const scanTarget = await resolveScanTarget(projectDefinition.directory);
|
|
40288
|
+
const { directory: _, config: projectConfig, ...perProjectOptions } = projectDefinition;
|
|
40289
|
+
const didOverrideConfig = batchConfig !== void 0 || projectConfig !== void 0;
|
|
40290
|
+
const effectiveConfig = mergeReactDoctorConfigs(mergeReactDoctorConfigs(scanTarget.userConfig, batchConfig), projectConfig);
|
|
40291
|
+
const program = buildInspectProgram(scanTarget, {
|
|
40292
|
+
...baseOptions,
|
|
40293
|
+
...perProjectOptions
|
|
40294
|
+
}, effectiveConfig ?? void 0);
|
|
40295
|
+
const didOverridePlugins = batchConfig?.plugins !== void 0 || projectConfig?.plugins !== void 0;
|
|
40296
|
+
const layer = buildDiagnoseLayer(effectiveConfig, didOverrideConfig ? {
|
|
40297
|
+
resolvedDirectory: scanTarget.resolvedDirectory,
|
|
40298
|
+
configSourceDirectory: didOverridePlugins ? null : scanTarget.configSourceDirectory
|
|
40299
|
+
} : void 0);
|
|
40300
|
+
return {
|
|
40301
|
+
ok: true,
|
|
40302
|
+
...outputToDiagnoseResult(await runPromise(restoreLegacyThrow(program.pipe(provide(layer), provide(layerOtlp)))), globalThis.performance.now() - startTime),
|
|
40303
|
+
directory: scanTarget.resolvedDirectory
|
|
40304
|
+
};
|
|
40305
|
+
} catch (error) {
|
|
40306
|
+
return {
|
|
40307
|
+
ok: false,
|
|
40308
|
+
directory: projectDefinition.directory,
|
|
40309
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
40310
|
+
};
|
|
40311
|
+
}
|
|
40312
|
+
};
|
|
40313
|
+
const diagnoseProjectBatch = async (input) => {
|
|
40314
|
+
const startTime = globalThis.performance.now();
|
|
40315
|
+
const { projects, concurrency, config: batchConfig, ...baseOptions } = input;
|
|
40316
|
+
const projectResults = await mapWithConcurrency(projects, concurrency ?? 4, (projectDefinition) => diagnoseProject(projectDefinition, baseOptions, batchConfig));
|
|
40317
|
+
return {
|
|
40318
|
+
projects: projectResults,
|
|
40319
|
+
diagnostics: projectResults.flatMap((projectResult) => projectResult.ok ? projectResult.diagnostics : []),
|
|
40320
|
+
score: findWorstScore(projectResults),
|
|
40321
|
+
elapsedMilliseconds: globalThis.performance.now() - startTime
|
|
40322
|
+
};
|
|
40323
|
+
};
|
|
40324
|
+
const diagnose = (async (directoryOrInput, options = {}) => typeof directoryOrInput === "string" ? diagnoseDirectory(directoryOrInput, options) : diagnoseProjectBatch(directoryOrInput));
|
|
40145
40325
|
//#endregion
|
|
40146
40326
|
//#region src/index.ts
|
|
40147
40327
|
const clearCaches = () => {
|
|
@@ -40174,4 +40354,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
40174
40354
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
40175
40355
|
|
|
40176
40356
|
//# sourceMappingURL=index.js.map
|
|
40177
|
-
//# debugId=
|
|
40357
|
+
//# debugId=5c0d7930-333e-5d67-93cf-63eae9bd87f8
|