react-doctor 0.2.16-dev.ec5d58c → 0.2.17-dev.0c8b797
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 +109 -60
- package/dist/index.d.ts +16 -1
- package/dist/index.js +8 -26
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
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]="07713237-df07-5858-b7a4-7b12c0e7b293")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import * as Path from "node:path";
|
|
@@ -5054,33 +5054,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
5054
5054
|
value: mod,
|
|
5055
5055
|
enumerable: true
|
|
5056
5056
|
}) : target, mod));
|
|
5057
|
-
/**
|
|
5058
|
-
* Narrow errors raised by the project-discovery helpers
|
|
5059
|
-
* (`discoverProject` / `resolveDiagnoseTarget` / `readPackageJson`).
|
|
5060
|
-
*
|
|
5061
|
-
* These extend `Error` directly — they are NOT the tagged
|
|
5062
|
-
* `ReactDoctorError` from `../errors.js` (that one wraps every
|
|
5063
|
-
* runtime-pipeline failure as a `Schema.TaggedErrorClass` for
|
|
5064
|
-
* `Effect.catchReasons` dispatch). The split is intentional:
|
|
5065
|
-
*
|
|
5066
|
-
* - Discovery happens BEFORE the Effect runtime takes over — at the
|
|
5067
|
-
* `diagnose()` / CLI entry point — and throws plain JS exceptions
|
|
5068
|
-
* so callers can `try/catch` without an Effect-layer-aware
|
|
5069
|
-
* `instanceof` check.
|
|
5070
|
-
* - The Project service (`services/project.ts → translateProjectInfoError`)
|
|
5071
|
-
* translates each of these into the equivalent tagged-error
|
|
5072
|
-
* `reason` before re-raising inside the Effect pipeline, so the
|
|
5073
|
-
* runtime never sees a non-tagged failure.
|
|
5074
|
-
*
|
|
5075
|
-
* If you're inside the Effect runtime, use the tagged
|
|
5076
|
-
* `ReactDoctorError` from `../errors.js` instead.
|
|
5077
|
-
*/
|
|
5078
5057
|
var ProjectNotFoundError = class extends Error {
|
|
5079
5058
|
name = "ProjectNotFoundError";
|
|
5080
5059
|
directory;
|
|
5060
|
+
kind;
|
|
5081
5061
|
constructor(directory, options) {
|
|
5082
|
-
|
|
5062
|
+
const kind = options?.kind ?? "no-project";
|
|
5063
|
+
super(kind === "missing-path" ? `Scan target "${directory}" does not exist. Check the path and try again.` : `No React project found in ${directory}. Expected a package.json at the directory root or a nested package.json with a React dependency.`, options);
|
|
5083
5064
|
this.directory = directory;
|
|
5065
|
+
this.kind = kind;
|
|
5084
5066
|
}
|
|
5085
5067
|
};
|
|
5086
5068
|
var NoReactDependencyError = class extends Error {
|
|
@@ -5117,6 +5099,7 @@ var AmbiguousProjectError = class extends Error {
|
|
|
5117
5099
|
this.candidates = candidates;
|
|
5118
5100
|
}
|
|
5119
5101
|
};
|
|
5102
|
+
const isProjectDiscoveryError = (value) => value instanceof ProjectNotFoundError || value instanceof NoReactDependencyError || value instanceof PackageJsonNotFoundError || value instanceof NotADirectoryError || value instanceof AmbiguousProjectError;
|
|
5120
5103
|
const isFile = (filePath) => {
|
|
5121
5104
|
try {
|
|
5122
5105
|
return fs.statSync(filePath).isFile();
|
|
@@ -6299,7 +6282,7 @@ const MILLISECONDS_PER_SECOND = 1e3;
|
|
|
6299
6282
|
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
6300
6283
|
const ENTERPRISE_CONTACT_URL = "https://react.doctor/enterprise";
|
|
6301
6284
|
const SHARE_BASE_URL = "https://react.doctor/share";
|
|
6302
|
-
const DOCS_URL = "https://
|
|
6285
|
+
const DOCS_URL = "https://react.doctor/docs";
|
|
6303
6286
|
const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
|
|
6304
6287
|
const FETCH_TIMEOUT_MS = 1e4;
|
|
6305
6288
|
const GITHUB_VIEWER_PERMISSION_TIMEOUT_MS = 2e3;
|
|
@@ -7701,7 +7684,7 @@ const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
|
7701
7684
|
const redirectedDirectory = resolveConfigRootDir(userConfig, configSourceDirectory);
|
|
7702
7685
|
const directoryAfterRedirect = redirectedDirectory ?? absoluteRequested;
|
|
7703
7686
|
const resolvedDirectory = resolveDiagnoseTarget(directoryAfterRedirect, options) ?? directoryAfterRedirect;
|
|
7704
|
-
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory);
|
|
7687
|
+
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory, { kind: "missing-path" });
|
|
7705
7688
|
return {
|
|
7706
7689
|
resolvedDirectory,
|
|
7707
7690
|
requestedDirectory: absoluteRequested,
|
|
@@ -9203,7 +9186,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9203
9186
|
if (result.status !== 0) return null;
|
|
9204
9187
|
const branch = trimOrNull(result.stdout);
|
|
9205
9188
|
return branch === "HEAD" ? null : branch;
|
|
9206
|
-
}));
|
|
9189
|
+
}), Effect.orElseSucceed(() => null));
|
|
9207
9190
|
const defaultBranch = (directory) => Effect.gen(function* () {
|
|
9208
9191
|
const symref = yield* runGit(directory, ["symbolic-ref", "refs/remotes/origin/HEAD"]);
|
|
9209
9192
|
if (symref.status === 0) {
|
|
@@ -11759,7 +11742,7 @@ const filterSourceFiles = (filePaths) => filePaths.filter(isLintableSourceFile);
|
|
|
11759
11742
|
/**
|
|
11760
11743
|
* Canonical URL for a rule's documentation page — its reviewer-tested fix
|
|
11761
11744
|
* recipe rendered for humans — served at
|
|
11762
|
-
* `https://
|
|
11745
|
+
* `https://react.doctor/docs/rules/<plugin>/<rule>`. The CLI links here
|
|
11763
11746
|
* from its fix-recipe directive so each fix follows the canonical recipe
|
|
11764
11747
|
* instead of being improvised per diagnostic.
|
|
11765
11748
|
*/
|
|
@@ -11876,6 +11859,7 @@ const isNonInteractiveEnvironment = () => NON_INTERACTIVE_ENVIRONMENT_VARIABLES.
|
|
|
11876
11859
|
const STAGED_FILES_TEMP_DIR_PREFIX = "react-doctor-staged-";
|
|
11877
11860
|
const WELCOME_EXPLANATION_HOLD_MS = 2e3;
|
|
11878
11861
|
const WELCOME_HOLD_MS = 1e3;
|
|
11862
|
+
const CATEGORY_COUNTUP_SETTLE_HOLD_MS = 1e3;
|
|
11879
11863
|
const INTERNAL_ERROR_JSON_FALLBACK = "{\"schemaVersion\":1,\"ok\":false,\"error\":{\"message\":\"Internal error\",\"name\":\"Error\",\"chain\":[]}}\n";
|
|
11880
11864
|
const SENTRY_FLUSH_TIMEOUT_MS = 2e3;
|
|
11881
11865
|
const NANOSECONDS_PER_SECOND = 1000000000n;
|
|
@@ -11947,7 +11931,7 @@ const makeNoopConsole = () => ({
|
|
|
11947
11931
|
});
|
|
11948
11932
|
//#endregion
|
|
11949
11933
|
//#region src/cli/utils/version.ts
|
|
11950
|
-
const VERSION = "0.2.
|
|
11934
|
+
const VERSION = "0.2.17-dev.0c8b797";
|
|
11951
11935
|
//#endregion
|
|
11952
11936
|
//#region src/cli/utils/json-mode.ts
|
|
11953
11937
|
let context = null;
|
|
@@ -12293,13 +12277,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12293
12277
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12294
12278
|
* standard `SENTRY_RELEASE` override.
|
|
12295
12279
|
*/
|
|
12296
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.2.
|
|
12280
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.2.17-dev.0c8b797`;
|
|
12297
12281
|
/**
|
|
12298
12282
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12299
12283
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12300
12284
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12301
12285
|
*/
|
|
12302
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.2.
|
|
12286
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.2.17-dev.0c8b797") ? "development" : "production");
|
|
12303
12287
|
/**
|
|
12304
12288
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12305
12289
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -15882,9 +15866,6 @@ const buildCodeFrame = (input) => {
|
|
|
15882
15866
|
//#region src/cli/utils/build-section-divider.ts
|
|
15883
15867
|
const buildSectionDivider = () => highlighter.dim(` ${"─".repeat(60)}`);
|
|
15884
15868
|
//#endregion
|
|
15885
|
-
//#region src/cli/utils/ease-out-cubic.ts
|
|
15886
|
-
const easeOutCubic = (progress) => 1 - (1 - progress) ** 3;
|
|
15887
|
-
//#endregion
|
|
15888
15869
|
//#region src/cli/utils/indent-multiline-text.ts
|
|
15889
15870
|
const indentMultilineText = (text, linePrefix) => text.split("\n").map((lineText) => `${linePrefix}${lineText}`).join("\n");
|
|
15890
15871
|
//#endregion
|
|
@@ -15974,13 +15955,26 @@ const buildCategoryTally = (categoryGroup) => ({
|
|
|
15974
15955
|
warningCount: categoryGroup.diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length
|
|
15975
15956
|
});
|
|
15976
15957
|
const buildCategoryTallyLines = (tallies) => tallies.map((tally) => formatCategoryTallyLine(tally, tally.errorCount, tally.warningCount));
|
|
15958
|
+
const buildPartiallyRevealedTallyLines = (tallies, revealedUnitCount) => {
|
|
15959
|
+
let remainingToReveal = revealedUnitCount;
|
|
15960
|
+
return tallies.map((tally) => {
|
|
15961
|
+
const errorShown = Math.min(tally.errorCount, remainingToReveal);
|
|
15962
|
+
remainingToReveal -= errorShown;
|
|
15963
|
+
const warningShown = Math.min(tally.warningCount, remainingToReveal);
|
|
15964
|
+
remainingToReveal -= warningShown;
|
|
15965
|
+
return formatCategoryTallyLine(tally, errorShown, warningShown);
|
|
15966
|
+
});
|
|
15967
|
+
};
|
|
15977
15968
|
const printCategoryCountUp = (tallies) => Effect.gen(function* () {
|
|
15978
|
-
|
|
15979
|
-
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
|
|
15969
|
+
const totalUnitCount = tallies.reduce((sum, tally) => sum + tally.errorCount + tally.warningCount, 0);
|
|
15970
|
+
const unitsPerStep = Math.max(1, Math.ceil(totalUnitCount / 24));
|
|
15971
|
+
for (let revealedUnitCount = 0; revealedUnitCount < totalUnitCount; revealedUnitCount += unitsPerStep) {
|
|
15972
|
+
const lines = buildPartiallyRevealedTallyLines(tallies, revealedUnitCount);
|
|
15973
|
+
yield* writeStdout(`${revealedUnitCount === 0 ? "" : `\x1b[${tallies.length}A`}\r${lines.join("\n\r")}\n`);
|
|
15974
|
+
yield* Effect.sleep(70);
|
|
15975
|
+
}
|
|
15976
|
+
yield* writeStdout(`${totalUnitCount === 0 ? "" : `\x1b[${tallies.length}A`}\r${buildCategoryTallyLines(tallies).join("\n\r")}\n`);
|
|
15977
|
+
yield* Effect.sleep(CATEGORY_COUNTUP_SETTLE_HOLD_MS);
|
|
15984
15978
|
});
|
|
15985
15979
|
const TOP_ERROR_DETAIL_INDENT = " ";
|
|
15986
15980
|
const pickRepresentativeDiagnostic = (ruleDiagnostics) => ruleDiagnostics.find((diagnostic) => diagnostic.line > 0) ?? ruleDiagnostics[0];
|
|
@@ -16246,6 +16240,9 @@ const colorizeByScore = (text, score) => {
|
|
|
16246
16240
|
return highlighter.error(text);
|
|
16247
16241
|
};
|
|
16248
16242
|
//#endregion
|
|
16243
|
+
//#region src/cli/utils/ease-out-cubic.ts
|
|
16244
|
+
const easeOutCubic = (progress) => 1 - (1 - progress) ** 3;
|
|
16245
|
+
//#endregion
|
|
16249
16246
|
//#region src/cli/utils/render-score-header.ts
|
|
16250
16247
|
const RAINBOW_HUE_SHIFT_PER_FRAME = 9;
|
|
16251
16248
|
const RAINBOW_GRADIENT_WIDTH = 80;
|
|
@@ -17005,6 +17002,49 @@ const handleUserError = (error, options = {}) => {
|
|
|
17005
17002
|
process.exitCode = 1;
|
|
17006
17003
|
};
|
|
17007
17004
|
//#endregion
|
|
17005
|
+
//#region src/cli/utils/cli-input-error.ts
|
|
17006
|
+
/**
|
|
17007
|
+
* A mistake in *how the CLI was invoked* — a malformed `<file>:<line>`
|
|
17008
|
+
* argument, mutually exclusive flags, or an unknown `--project` name. This is
|
|
17009
|
+
* user input, not a react-doctor bug, so `isExpectedUserError` routes it
|
|
17010
|
+
* through `handleUserError`: a clean, single-line message with no Sentry
|
|
17011
|
+
* report and no "Something went wrong, open a prefilled issue" block.
|
|
17012
|
+
*
|
|
17013
|
+
* The `message` is rendered verbatim, so it must read as a complete,
|
|
17014
|
+
* human-readable sentence that tells the user how to fix their invocation.
|
|
17015
|
+
*/
|
|
17016
|
+
var CliInputError = class extends Error {
|
|
17017
|
+
name = "CliInputError";
|
|
17018
|
+
};
|
|
17019
|
+
//#endregion
|
|
17020
|
+
//#region src/cli/utils/is-expected-user-error.ts
|
|
17021
|
+
/**
|
|
17022
|
+
* Whether `error` is an expected, user-actionable failure — the user's project
|
|
17023
|
+
* or input, not a react-doctor bug. Such failures must be kept out of crash
|
|
17024
|
+
* reporting (Sentry + the alertable error-rate metric) and rendered via
|
|
17025
|
+
* `handleUserError` (a plain message — no "Something went wrong", prefilled
|
|
17026
|
+
* issue, Discord link, or Sentry reference), since there is no bug to report.
|
|
17027
|
+
*
|
|
17028
|
+
* Three distinct shapes reach the CLI's catch blocks:
|
|
17029
|
+
*
|
|
17030
|
+
* - **Project-discovery failures** (`NoReactDependencyError`,
|
|
17031
|
+
* `ProjectNotFoundError`, `PackageJsonNotFoundError`, `NotADirectoryError`,
|
|
17032
|
+
* `AmbiguousProjectError`) arrive as their plain legacy classes (so
|
|
17033
|
+
* `isReactDoctorError` is `false` for them) — narrow with
|
|
17034
|
+
* `isProjectDiscoveryError`. Running react-doctor against a directory that
|
|
17035
|
+
* has no React, or a path that doesn't exist, is the canonical example.
|
|
17036
|
+
* - **CLI invocation mistakes** (`CliInputError`): a malformed
|
|
17037
|
+
* `<file>:<line>` argument, mutually exclusive flags, or an unknown
|
|
17038
|
+
* `--project` name.
|
|
17039
|
+
* - **Bad `--diff` input** (`GitBaseBranchInvalid` / `GitBaseBranchMissing`)
|
|
17040
|
+
* stays the tagged `ReactDoctorError`, so dispatch on the reason `_tag`.
|
|
17041
|
+
*
|
|
17042
|
+
* This composes the existing core narrowers rather than introducing a new
|
|
17043
|
+
* error-shape helper (AGENTS.md): it encodes CLI-layer reporting policy, not
|
|
17044
|
+
* knowledge of the `ReactDoctorError` shape.
|
|
17045
|
+
*/
|
|
17046
|
+
const isExpectedUserError = (error) => error instanceof CliInputError || isProjectDiscoveryError(error) || isReactDoctorError(error) && (error.reason._tag === "GitBaseBranchInvalid" || error.reason._tag === "GitBaseBranchMissing");
|
|
17047
|
+
//#endregion
|
|
17008
17048
|
//#region src/cli/utils/build-handoff-payload.ts
|
|
17009
17049
|
const buildHandoffPayload = (input) => {
|
|
17010
17050
|
const topGroups = buildSortedRuleGroups(input.diagnostics).slice(0, 3);
|
|
@@ -18529,6 +18569,7 @@ const playWelcomeScene = () => Effect.gen(function* () {
|
|
|
18529
18569
|
*/
|
|
18530
18570
|
const reportErrorToSentry = async (error) => {
|
|
18531
18571
|
if (!Sentry.isInitialized()) return void 0;
|
|
18572
|
+
if (isExpectedUserError(error)) return void 0;
|
|
18532
18573
|
try {
|
|
18533
18574
|
const { tags, contexts } = buildSentryScope();
|
|
18534
18575
|
let reason = "unknown";
|
|
@@ -18608,6 +18649,7 @@ const findLowestScoredScan = (completedScans) => {
|
|
|
18608
18649
|
};
|
|
18609
18650
|
const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
18610
18651
|
const { completedScans, userConfig, verbose, isOffline, projectName } = input;
|
|
18652
|
+
const animateRender = !verbose && canAnimateOnboarding(process.stdout);
|
|
18611
18653
|
const surfaceDiagnostics = filterDiagnosticsForSurface(completedScans.flatMap((scan) => scan.result.diagnostics), "cli", userConfig);
|
|
18612
18654
|
const projectRootByDiagnostic = /* @__PURE__ */ new WeakMap();
|
|
18613
18655
|
for (const scan of completedScans) for (const diagnostic of scan.result.diagnostics) projectRootByDiagnostic.set(diagnostic, scan.result.project.rootDirectory);
|
|
@@ -18624,7 +18666,7 @@ const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
|
18624
18666
|
yield* Console.log(`${highlighter.success("✔")} Scanned ${totalScannedFileCount} ${totalScannedFileCount === 1 ? "file" : "files"} in ${formatElapsedTime(totalScanElapsedMilliseconds)}`);
|
|
18625
18667
|
if (surfaceDiagnostics.length > 0) {
|
|
18626
18668
|
yield* Console.log("");
|
|
18627
|
-
yield* printDiagnostics(surfaceDiagnostics, verbose, resolveDiagnosticSourceRoot, buildRulePriorityMap(completedScans.map((scan) => scan.result.score)), isCodingAgentEnvironment());
|
|
18669
|
+
yield* printDiagnostics(surfaceDiagnostics, verbose, resolveDiagnosticSourceRoot, buildRulePriorityMap(completedScans.map((scan) => scan.result.score)), isCodingAgentEnvironment(), { animateCountUp: animateRender });
|
|
18628
18670
|
}
|
|
18629
18671
|
const lowestScoredScan = findLowestScoredScan(completedScans);
|
|
18630
18672
|
const aggregateScore = lowestScoredScan?.result.score ?? null;
|
|
@@ -18636,7 +18678,8 @@ const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
|
18636
18678
|
potentialScore: lowestScoredScan ? yield* Effect.promise(() => computeProjectedScore(surfaceDiagnostics, lowestScoredScan.result.diagnostics, lowestScoredScan.result.score)) : null,
|
|
18637
18679
|
totalSourceFileCount,
|
|
18638
18680
|
noScoreMessage: "Score unavailable.",
|
|
18639
|
-
verbose
|
|
18681
|
+
verbose,
|
|
18682
|
+
animateProjection: animateRender
|
|
18640
18683
|
});
|
|
18641
18684
|
const entries = completedScans.map((scan) => {
|
|
18642
18685
|
const errorCount = scan.result.diagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
|
|
@@ -18666,7 +18709,11 @@ const getSetupPromptStore = (options = {}) => new Conf({
|
|
|
18666
18709
|
});
|
|
18667
18710
|
const getSetupPromptProjectKey = (projectRoot) => createHash("sha256").update(path.resolve(projectRoot)).digest("hex");
|
|
18668
18711
|
const hasDisabledSetupPrompt = (projectRoot, storeOptions = {}) => {
|
|
18669
|
-
|
|
18712
|
+
try {
|
|
18713
|
+
return getSetupPromptStore(storeOptions).get("projects", {})[getSetupPromptProjectKey(projectRoot)]?.setupPrompt === false;
|
|
18714
|
+
} catch {
|
|
18715
|
+
return false;
|
|
18716
|
+
}
|
|
18670
18717
|
};
|
|
18671
18718
|
const resolveInstallSetupProjectRoot = (options) => {
|
|
18672
18719
|
if (options.scanDirectories.length === 0) return findNearestPackageDirectory(options.scanRoot) ?? options.scanRoot;
|
|
@@ -18884,12 +18931,12 @@ const findOwningProjectDirectory = (rootDirectory, filePath) => {
|
|
|
18884
18931
|
//#region src/cli/utils/parse-file-line-argument.ts
|
|
18885
18932
|
const parseFileLineArgument = (rawArgument) => {
|
|
18886
18933
|
const lastColonIndex = rawArgument.lastIndexOf(":");
|
|
18887
|
-
if (lastColonIndex < 0) throw new
|
|
18934
|
+
if (lastColonIndex < 0) throw new CliInputError(`Expected "<file>:<line>" (e.g. "src/foo.tsx:42"), got "${rawArgument}".`);
|
|
18888
18935
|
const filePath = rawArgument.slice(0, lastColonIndex);
|
|
18889
18936
|
const lineText = rawArgument.slice(lastColonIndex + 1);
|
|
18890
|
-
if (filePath.length === 0) throw new
|
|
18937
|
+
if (filePath.length === 0) throw new CliInputError(`Missing file path in "${rawArgument}".`);
|
|
18891
18938
|
const line = Number.parseInt(lineText, 10);
|
|
18892
|
-
if (!Number.isFinite(line) || line <= 0 || String(line) !== lineText.trim()) throw new
|
|
18939
|
+
if (!Number.isFinite(line) || line <= 0 || String(line) !== lineText.trim()) throw new CliInputError(`Expected a positive line number in "${rawArgument}".`);
|
|
18893
18940
|
return {
|
|
18894
18941
|
filePath,
|
|
18895
18942
|
line
|
|
@@ -18918,10 +18965,7 @@ const resolveProjectFlag = (projectFlag, workspacePackages) => {
|
|
|
18918
18965
|
const resolvedDirectories = [];
|
|
18919
18966
|
for (const requestedName of requestedNames) {
|
|
18920
18967
|
const matched = workspacePackages.find((workspacePackage) => workspacePackage.name === requestedName || path.basename(workspacePackage.directory) === requestedName);
|
|
18921
|
-
if (!matched) {
|
|
18922
|
-
const availableNames = workspacePackages.map((workspacePackage) => workspacePackage.name).join(", ");
|
|
18923
|
-
throw new Error(`Project "${requestedName}" not found. Available: ${availableNames}`);
|
|
18924
|
-
}
|
|
18968
|
+
if (!matched) throw new CliInputError(`Project "${requestedName}" not found. Available: ${workspacePackages.map((workspacePackage) => workspacePackage.name).join(", ")}`);
|
|
18925
18969
|
resolvedDirectories.push(matched.directory);
|
|
18926
18970
|
}
|
|
18927
18971
|
return resolvedDirectories;
|
|
@@ -19001,14 +19045,14 @@ const shouldFailForDiagnostics = (diagnostics, failOnLevel) => {
|
|
|
19001
19045
|
const validateModeFlags = (flags) => {
|
|
19002
19046
|
const coercedDiff = coerceDiffValue(flags.diff);
|
|
19003
19047
|
const exclusiveModes = [flags.staged ? "--staged" : null, coercedDiff !== void 0 && coercedDiff !== false ? "--diff" : null].filter((modeName) => modeName !== null);
|
|
19004
|
-
if (exclusiveModes.length > 1) throw new
|
|
19005
|
-
if (flags.yes && flags.full) throw new
|
|
19006
|
-
if (flags.score && flags.json) throw new
|
|
19007
|
-
if (flags.score && flags.telemetry === false) throw new
|
|
19008
|
-
if (flags.prComment && (flags.json || flags.score)) throw new
|
|
19009
|
-
if (flags.annotations && flags.score) throw new
|
|
19010
|
-
if (flags.explain !== void 0 && flags.why !== void 0) throw new
|
|
19011
|
-
if ((flags.explain ?? flags.why) !== void 0 && (flags.json || flags.score || flags.annotations || flags.staged)) throw new
|
|
19048
|
+
if (exclusiveModes.length > 1) throw new CliInputError(`Cannot combine ${exclusiveModes.join(" and ")}; pick one mode.`);
|
|
19049
|
+
if (flags.yes && flags.full) throw new CliInputError("Cannot combine --yes and --full; pick one.");
|
|
19050
|
+
if (flags.score && flags.json) throw new CliInputError("Cannot combine --score and --json; pick one output mode.");
|
|
19051
|
+
if (flags.score && flags.telemetry === false) throw new CliInputError("Cannot combine --score with --no-telemetry; --score prints the score that --no-telemetry disables.");
|
|
19052
|
+
if (flags.prComment && (flags.json || flags.score)) throw new CliInputError("--pr-comment cannot be combined with --json or --score.");
|
|
19053
|
+
if (flags.annotations && flags.score) throw new CliInputError("--annotations cannot be combined with --score.");
|
|
19054
|
+
if (flags.explain !== void 0 && flags.why !== void 0) throw new CliInputError("Use --explain or --why, not both — they're aliases of the same flag.");
|
|
19055
|
+
if ((flags.explain ?? flags.why) !== void 0 && (flags.json || flags.score || flags.annotations || flags.staged)) throw new CliInputError("--explain cannot be combined with --json, --score, --annotations, or --staged.");
|
|
19012
19056
|
};
|
|
19013
19057
|
//#endregion
|
|
19014
19058
|
//#region src/cli/commands/inspect.ts
|
|
@@ -19256,7 +19300,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19256
19300
|
}
|
|
19257
19301
|
}
|
|
19258
19302
|
} catch (error) {
|
|
19259
|
-
const isUserError =
|
|
19303
|
+
const isUserError = isExpectedUserError(error);
|
|
19260
19304
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
19261
19305
|
if (isJsonMode) {
|
|
19262
19306
|
writeJsonErrorReport(error);
|
|
@@ -20150,15 +20194,20 @@ if (process.argv.includes("-V") && !strippedArgv.includes("-V")) {
|
|
|
20150
20194
|
applyColorPreference(strippedArgv);
|
|
20151
20195
|
const argv = normalizeHelpInvocation(strippedArgv, knownCommands);
|
|
20152
20196
|
program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
20153
|
-
const
|
|
20197
|
+
const isUserError = isExpectedUserError(error);
|
|
20198
|
+
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
20154
20199
|
if (isJsonModeActive()) {
|
|
20155
20200
|
writeJsonErrorReport(error);
|
|
20156
20201
|
process.exit(1);
|
|
20157
20202
|
}
|
|
20203
|
+
if (isUserError) {
|
|
20204
|
+
handleUserError(error);
|
|
20205
|
+
return;
|
|
20206
|
+
}
|
|
20158
20207
|
handleError(error, { sentryEventId });
|
|
20159
20208
|
});
|
|
20160
20209
|
//#endregion
|
|
20161
20210
|
export {};
|
|
20162
20211
|
|
|
20163
20212
|
//# sourceMappingURL=cli.js.map
|
|
20164
|
-
//# debugId=
|
|
20213
|
+
//# debugId=07713237-df07-5858-b7a4-7b12c0e7b293
|
package/dist/index.d.ts
CHANGED
|
@@ -610,10 +610,25 @@ interface JsonReport {
|
|
|
610
610
|
* If you're inside the Effect runtime, use the tagged
|
|
611
611
|
* `ReactDoctorError` from `../errors.js` instead.
|
|
612
612
|
*/
|
|
613
|
+
/**
|
|
614
|
+
* Distinguishes the two situations that both surface as "no project here", so
|
|
615
|
+
* the rendered message matches reality:
|
|
616
|
+
*
|
|
617
|
+
* - `no-project` (default): the path exists but has no React project — no
|
|
618
|
+
* `package.json` at the root and no discoverable nested React subproject.
|
|
619
|
+
* - `missing-path`: the resolved scan target does not exist on disk at all
|
|
620
|
+
* (a typo, a stale temp path, a monorepo subdir that isn't present). The
|
|
621
|
+
* generic "expected a package.json" guidance is misleading here, so point
|
|
622
|
+
* at the missing path instead.
|
|
623
|
+
*/
|
|
624
|
+
interface ProjectNotFoundOptions extends ErrorOptions {
|
|
625
|
+
readonly kind?: "no-project" | "missing-path";
|
|
626
|
+
}
|
|
613
627
|
declare class ProjectNotFoundError extends Error {
|
|
614
628
|
readonly name = "ProjectNotFoundError";
|
|
615
629
|
readonly directory: string;
|
|
616
|
-
|
|
630
|
+
readonly kind: "no-project" | "missing-path";
|
|
631
|
+
constructor(directory: string, options?: ProjectNotFoundOptions);
|
|
617
632
|
}
|
|
618
633
|
declare class NoReactDependencyError extends Error {
|
|
619
634
|
readonly name = "NoReactDependencyError";
|
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]="9b91fa51-6642-5351-a848-af91945dec6f")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
5
|
import * as fs$1 from "node:fs";
|
|
@@ -2027,33 +2027,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
2027
2027
|
value: mod,
|
|
2028
2028
|
enumerable: true
|
|
2029
2029
|
}) : target, mod));
|
|
2030
|
-
/**
|
|
2031
|
-
* Narrow errors raised by the project-discovery helpers
|
|
2032
|
-
* (`discoverProject` / `resolveDiagnoseTarget` / `readPackageJson`).
|
|
2033
|
-
*
|
|
2034
|
-
* These extend `Error` directly — they are NOT the tagged
|
|
2035
|
-
* `ReactDoctorError` from `../errors.js` (that one wraps every
|
|
2036
|
-
* runtime-pipeline failure as a `Schema.TaggedErrorClass` for
|
|
2037
|
-
* `Effect.catchReasons` dispatch). The split is intentional:
|
|
2038
|
-
*
|
|
2039
|
-
* - Discovery happens BEFORE the Effect runtime takes over — at the
|
|
2040
|
-
* `diagnose()` / CLI entry point — and throws plain JS exceptions
|
|
2041
|
-
* so callers can `try/catch` without an Effect-layer-aware
|
|
2042
|
-
* `instanceof` check.
|
|
2043
|
-
* - The Project service (`services/project.ts → translateProjectInfoError`)
|
|
2044
|
-
* translates each of these into the equivalent tagged-error
|
|
2045
|
-
* `reason` before re-raising inside the Effect pipeline, so the
|
|
2046
|
-
* runtime never sees a non-tagged failure.
|
|
2047
|
-
*
|
|
2048
|
-
* If you're inside the Effect runtime, use the tagged
|
|
2049
|
-
* `ReactDoctorError` from `../errors.js` instead.
|
|
2050
|
-
*/
|
|
2051
2030
|
var ProjectNotFoundError = class extends Error {
|
|
2052
2031
|
name = "ProjectNotFoundError";
|
|
2053
2032
|
directory;
|
|
2033
|
+
kind;
|
|
2054
2034
|
constructor(directory, options) {
|
|
2055
|
-
|
|
2035
|
+
const kind = options?.kind ?? "no-project";
|
|
2036
|
+
super(kind === "missing-path" ? `Scan target "${directory}" does not exist. Check the path and try again.` : `No React project found in ${directory}. Expected a package.json at the directory root or a nested package.json with a React dependency.`, options);
|
|
2056
2037
|
this.directory = directory;
|
|
2038
|
+
this.kind = kind;
|
|
2057
2039
|
}
|
|
2058
2040
|
};
|
|
2059
2041
|
var NoReactDependencyError = class extends Error {
|
|
@@ -4651,7 +4633,7 @@ const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
|
4651
4633
|
const redirectedDirectory = resolveConfigRootDir(userConfig, configSourceDirectory);
|
|
4652
4634
|
const directoryAfterRedirect = redirectedDirectory ?? absoluteRequested;
|
|
4653
4635
|
const resolvedDirectory = resolveDiagnoseTarget(directoryAfterRedirect, options) ?? directoryAfterRedirect;
|
|
4654
|
-
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory);
|
|
4636
|
+
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory, { kind: "missing-path" });
|
|
4655
4637
|
return {
|
|
4656
4638
|
resolvedDirectory,
|
|
4657
4639
|
requestedDirectory: absoluteRequested,
|
|
@@ -6137,7 +6119,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
6137
6119
|
if (result.status !== 0) return null;
|
|
6138
6120
|
const branch = trimOrNull(result.stdout);
|
|
6139
6121
|
return branch === "HEAD" ? null : branch;
|
|
6140
|
-
}));
|
|
6122
|
+
}), Effect.orElseSucceed(() => null));
|
|
6141
6123
|
const defaultBranch = (directory) => Effect.gen(function* () {
|
|
6142
6124
|
const symref = yield* runGit(directory, ["symbolic-ref", "refs/remotes/origin/HEAD"]);
|
|
6143
6125
|
if (symref.status === 0) {
|
|
@@ -8742,4 +8724,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
8742
8724
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
8743
8725
|
|
|
8744
8726
|
//# sourceMappingURL=index.js.map
|
|
8745
|
-
//# debugId=
|
|
8727
|
+
//# debugId=9b91fa51-6642-5351-a848-af91945dec6f
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-doctor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17-dev.0c8b797",
|
|
4
4
|
"description": "Diagnose and fix React codebases for security, performance, correctness, accessibility, bundle-size, and architecture issues",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"oxlint": "^1.66.0",
|
|
64
64
|
"prompts": "^2.4.2",
|
|
65
65
|
"typescript": ">=5.0.4 <7",
|
|
66
|
-
"oxlint-plugin-react-doctor": "0.2.
|
|
66
|
+
"oxlint-plugin-react-doctor": "0.2.17-dev.0c8b797"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/babel__code-frame": "^7.27.0",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
"@xterm/headless": "^6.0.0",
|
|
72
72
|
"commander": "^14.0.3",
|
|
73
73
|
"ora": "^9.4.0",
|
|
74
|
-
"@react-doctor/api": "0.2.
|
|
75
|
-
"@react-doctor/core": "0.2.
|
|
74
|
+
"@react-doctor/api": "0.2.17",
|
|
75
|
+
"@react-doctor/core": "0.2.17"
|
|
76
76
|
},
|
|
77
77
|
"engines": {
|
|
78
78
|
"node": "^20.19.0 || >=22.12.0"
|