react-doctor 0.4.2-dev.42c339f → 0.4.2-dev.7cf52d8
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 +704 -805
- package/dist/index.js +2 -2
- package/package.json +6 -6
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]="1486eaee-ed07-5eef-a9d7-51293140e237")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import * as path$1 from "node:path";
|
|
@@ -6361,7 +6361,6 @@ const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
|
6361
6361
|
const ENTERPRISE_CONTACT_URL = "https://react.doctor/enterprise";
|
|
6362
6362
|
const SHARE_BASE_URL = "https://react.doctor/share";
|
|
6363
6363
|
const CI_URL = "https://react.doctor/ci";
|
|
6364
|
-
const GITHUB_ACTIONS_SETUP_URL = "https://www.react.doctor/docs/ci-and-prs/github-actions-setup";
|
|
6365
6364
|
const DOCS_URL = "https://react.doctor/docs";
|
|
6366
6365
|
const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
|
|
6367
6366
|
const FETCH_TIMEOUT_MS = 1e4;
|
|
@@ -12248,7 +12247,7 @@ const makeNoopConsole = () => ({
|
|
|
12248
12247
|
});
|
|
12249
12248
|
//#endregion
|
|
12250
12249
|
//#region src/cli/utils/version.ts
|
|
12251
|
-
const VERSION = "0.4.2-dev.
|
|
12250
|
+
const VERSION = "0.4.2-dev.7cf52d8";
|
|
12252
12251
|
//#endregion
|
|
12253
12252
|
//#region src/cli/utils/json-mode.ts
|
|
12254
12253
|
let context = null;
|
|
@@ -12606,13 +12605,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12606
12605
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12607
12606
|
* standard `SENTRY_RELEASE` override.
|
|
12608
12607
|
*/
|
|
12609
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.2-dev.
|
|
12608
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.2-dev.7cf52d8`;
|
|
12610
12609
|
/**
|
|
12611
12610
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12612
12611
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12613
12612
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12614
12613
|
*/
|
|
12615
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.2-dev.
|
|
12614
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.2-dev.7cf52d8") ? "development" : "production");
|
|
12616
12615
|
/**
|
|
12617
12616
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12618
12617
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -16474,22 +16473,8 @@ const buildCodeFrame = (input) => {
|
|
|
16474
16473
|
});
|
|
16475
16474
|
};
|
|
16476
16475
|
//#endregion
|
|
16477
|
-
//#region src/cli/utils/resolve-measure-width.ts
|
|
16478
|
-
const resolveClampedWidth = (input) => {
|
|
16479
|
-
const terminalColumns = process.stdout.columns;
|
|
16480
|
-
if (!terminalColumns || terminalColumns <= 0) return input.fullWidth;
|
|
16481
|
-
const availableColumns = terminalColumns - input.reservedColumns;
|
|
16482
|
-
return Math.max(input.minWidth, Math.min(input.fullWidth, availableColumns));
|
|
16483
|
-
};
|
|
16484
|
-
const resolveMeasureWidth = (reservedColumns = 0) => resolveClampedWidth({
|
|
16485
|
-
reservedColumns,
|
|
16486
|
-
fullWidth: 60,
|
|
16487
|
-
minWidth: 24
|
|
16488
|
-
});
|
|
16489
|
-
//#endregion
|
|
16490
16476
|
//#region src/cli/utils/build-section-divider.ts
|
|
16491
|
-
const
|
|
16492
|
-
const buildSectionDivider = () => highlighter.dim(`${DIVIDER_INDENT}${"─".repeat(resolveMeasureWidth(2))}`);
|
|
16477
|
+
const buildSectionDivider = () => highlighter.dim(` ${"─".repeat(60)}`);
|
|
16493
16478
|
//#endregion
|
|
16494
16479
|
//#region src/cli/utils/indent-multiline-text.ts
|
|
16495
16480
|
const indentMultilineText = (text, linePrefix) => text.split("\n").map((lineText) => `${linePrefix}${lineText}`).join("\n");
|
|
@@ -16649,10 +16634,7 @@ const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame
|
|
|
16649
16634
|
endLine: isMultiSite ? cluster.endLine : void 0,
|
|
16650
16635
|
rootDirectory: resolveSourceRoot(lead)
|
|
16651
16636
|
}) : null;
|
|
16652
|
-
if (codeFrame)
|
|
16653
|
-
const boxInnerWidth = resolveMeasureWidth(8);
|
|
16654
|
-
lines.push(indentMultilineText(boxText(codeFrame, boxInnerWidth), TOP_ERROR_DETAIL_INDENT));
|
|
16655
|
-
}
|
|
16637
|
+
if (codeFrame) lines.push(indentMultilineText(boxText(codeFrame, 60), TOP_ERROR_DETAIL_INDENT));
|
|
16656
16638
|
const seenHints = /* @__PURE__ */ new Set();
|
|
16657
16639
|
for (const diagnostic of cluster.diagnostics) if (diagnostic.suppressionHint && !seenHints.has(diagnostic.suppressionHint)) {
|
|
16658
16640
|
seenHints.add(diagnostic.suppressionHint);
|
|
@@ -16670,8 +16652,8 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
|
|
|
16670
16652
|
const learnMoreLine = formatLearnMoreLine(representative);
|
|
16671
16653
|
if (learnMoreLine) lines.push(`${TOP_ERROR_DETAIL_INDENT}${highlighter.info(learnMoreLine)}`);
|
|
16672
16654
|
}
|
|
16673
|
-
if (!renderEverySite) for (const explanationLine of wrapTextToWidth(representative.message,
|
|
16674
|
-
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`,
|
|
16655
|
+
if (!renderEverySite) for (const explanationLine of wrapTextToWidth(representative.message, 60, { breakLongWords: false })) lines.push(`${TOP_ERROR_DETAIL_INDENT}${explanationLine}`);
|
|
16656
|
+
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`, 60, { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${fixLine}`));
|
|
16675
16657
|
if (renderEverySite && isAgentEnvironment) {
|
|
16676
16658
|
const fixRecipeLine = formatFixRecipeLine(representative);
|
|
16677
16659
|
if (fixRecipeLine) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${fixRecipeLine}`));
|
|
@@ -16865,21 +16847,14 @@ const RAINBOW_HUE_SHIFT_PER_FRAME = 9;
|
|
|
16865
16847
|
const RAINBOW_GRADIENT_WIDTH = 80;
|
|
16866
16848
|
const RAINBOW_OKLCH_LIGHTNESS = .638;
|
|
16867
16849
|
const RAINBOW_OKLCH_CHROMA = .129;
|
|
16868
|
-
const FACE_BOX_TOP_BORDER = "┌─────┐";
|
|
16869
|
-
const SCORE_RIGHT_COLUMN_OFFSET = 11;
|
|
16870
|
-
const getScoreBarWidth = () => resolveClampedWidth({
|
|
16871
|
-
reservedColumns: SCORE_RIGHT_COLUMN_OFFSET + 1,
|
|
16872
|
-
fullWidth: 50,
|
|
16873
|
-
minWidth: 10
|
|
16874
|
-
});
|
|
16875
16850
|
const buildScoreBarSegments = (filledCount) => {
|
|
16876
|
-
const emptyCount =
|
|
16851
|
+
const emptyCount = 50 - filledCount;
|
|
16877
16852
|
return {
|
|
16878
16853
|
filledSegment: "█".repeat(filledCount),
|
|
16879
16854
|
emptySegment: "░".repeat(emptyCount)
|
|
16880
16855
|
};
|
|
16881
16856
|
};
|
|
16882
|
-
const getFilledCount = (score) => Math.round(score / 100 *
|
|
16857
|
+
const getFilledCount = (score) => Math.round(score / 100 * 50);
|
|
16883
16858
|
const joinScoreHeaderFrame = (lines) => `${lines[0]}\n\r${lines[1]}\n\r${lines[2]}\n\r${lines[3]}\n`;
|
|
16884
16859
|
const buildRawScoreBar = (displayScore) => {
|
|
16885
16860
|
const { filledSegment, emptySegment } = buildScoreBarSegments(getFilledCount(displayScore));
|
|
@@ -16915,11 +16890,10 @@ const buildScoreBar = (displayScore, colorScore = displayScore) => {
|
|
|
16915
16890
|
return colorizeByScore(filledSegment, colorScore) + highlighter.dim(emptySegment);
|
|
16916
16891
|
};
|
|
16917
16892
|
const buildProjectedScoreBar = (currentScore, potentialScore) => {
|
|
16918
|
-
const barWidth = getScoreBarWidth();
|
|
16919
16893
|
const currentFill = getFilledCount(currentScore);
|
|
16920
|
-
const potentialFill = Math.min(getFilledCount(potentialScore),
|
|
16894
|
+
const potentialFill = Math.min(getFilledCount(potentialScore), 50);
|
|
16921
16895
|
const gainCount = Math.max(0, potentialFill - currentFill);
|
|
16922
|
-
const emptyCount = Math.max(0,
|
|
16896
|
+
const emptyCount = Math.max(0, 50 - currentFill - gainCount);
|
|
16923
16897
|
return colorizeByScore("█".repeat(currentFill), currentScore) + highlighter.dim(colorizeByScore("▓".repeat(gainCount), currentScore)) + highlighter.dim("░".repeat(emptyCount));
|
|
16924
16898
|
};
|
|
16925
16899
|
const getDoctorFace = (score) => {
|
|
@@ -16932,7 +16906,7 @@ const RAW_BRANDING_LINE = "React Doctor (https://react.doctor)";
|
|
|
16932
16906
|
const buildRawFaceLines = (score) => {
|
|
16933
16907
|
const [eyes, mouth] = getDoctorFace(score);
|
|
16934
16908
|
return [
|
|
16935
|
-
|
|
16909
|
+
"┌─────┐",
|
|
16936
16910
|
`│ ${eyes} │`,
|
|
16937
16911
|
`│ ${mouth} │`,
|
|
16938
16912
|
"└─────┘"
|
|
@@ -17074,11 +17048,6 @@ const writeDiagnosticsDirectory = (diagnostics) => {
|
|
|
17074
17048
|
};
|
|
17075
17049
|
//#endregion
|
|
17076
17050
|
//#region src/cli/utils/render-summary.ts
|
|
17077
|
-
const FOOTER_DESCRIPTION_INDENT = " ";
|
|
17078
|
-
const printFooterDescription = (description) => Effect.gen(function* () {
|
|
17079
|
-
const wrapWidth = resolveMeasureWidth(2);
|
|
17080
|
-
for (const line of wrapTextToWidth(description, wrapWidth)) yield* Console.log(highlighter.dim(`${FOOTER_DESCRIPTION_INDENT}${line}`));
|
|
17081
|
-
});
|
|
17082
17051
|
const buildShareUrl = (diagnostics, scoreResult, projectName) => {
|
|
17083
17052
|
const errorCount = diagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
|
|
17084
17053
|
const warningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
|
|
@@ -17098,14 +17067,14 @@ const printFooter = (input) => Effect.gen(function* () {
|
|
|
17098
17067
|
if (!input.isOffline) {
|
|
17099
17068
|
const shareUrl = buildShareUrl(input.diagnostics, input.scoreResult, input.projectName);
|
|
17100
17069
|
yield* Console.log(` ${highlighter.bold("Share:")} ${highlighter.info(shareUrl)}`);
|
|
17101
|
-
yield*
|
|
17070
|
+
yield* Console.log(highlighter.dim(" Tell others how you did on socials"));
|
|
17102
17071
|
yield* Console.log("");
|
|
17103
17072
|
}
|
|
17104
17073
|
yield* Console.log(` ${highlighter.bold("Docs:")} ${highlighter.info(DOCS_URL)}`);
|
|
17105
|
-
yield*
|
|
17074
|
+
yield* Console.log(highlighter.dim(" Learn more about fixing issues, setting up CI/CD, and configuring rules with a config file"));
|
|
17106
17075
|
yield* Console.log("");
|
|
17107
17076
|
yield* Console.log(` ${highlighter.bold("GitHub:")} ${highlighter.info(CANONICAL_GITHUB_URL)}`);
|
|
17108
|
-
yield*
|
|
17077
|
+
yield* Console.log(highlighter.dim(" Report issues and star the repository!"));
|
|
17109
17078
|
});
|
|
17110
17079
|
const printSummary = (input) => Effect.gen(function* () {
|
|
17111
17080
|
if (input.scoreResult) {
|
|
@@ -18011,24 +17980,190 @@ const installDoctorScript = (options) => {
|
|
|
18011
17980
|
...scriptTarget.reason !== void 0 ? { scriptReason: scriptTarget.reason } : {}
|
|
18012
17981
|
};
|
|
18013
17982
|
};
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
17983
|
+
//#endregion
|
|
17984
|
+
//#region src/cli/utils/install-agent-hooks.ts
|
|
17985
|
+
const CLAUDE_AGENT = "claude-code";
|
|
17986
|
+
const CURSOR_AGENT = "cursor";
|
|
17987
|
+
const CLAUDE_SETTINGS_RELATIVE_PATH = ".claude/settings.json";
|
|
17988
|
+
const CLAUDE_HOOK_RELATIVE_PATH = ".claude/hooks/react-doctor.sh";
|
|
17989
|
+
const CLAUDE_HOOK_COMMAND = "sh \"$CLAUDE_PROJECT_DIR/.claude/hooks/react-doctor.sh\"";
|
|
17990
|
+
const CURSOR_HOOKS_RELATIVE_PATH = ".cursor/hooks.json";
|
|
17991
|
+
const CURSOR_HOOK_RELATIVE_PATH = ".cursor/hooks/react-doctor.sh";
|
|
17992
|
+
const CURSOR_HOOK_MATCHER = "Write|Edit|MultiEdit|ApplyPatch";
|
|
17993
|
+
const CURSOR_HOOKS_SCHEMA_VERSION = 1;
|
|
17994
|
+
const JSON_INDENT_SPACES$1 = 2;
|
|
17995
|
+
const isSupportedAgent = (agent) => agent === CLAUDE_AGENT || agent === CURSOR_AGENT;
|
|
17996
|
+
const readJsonFile = (filePath, fallback) => {
|
|
17997
|
+
if (!fs$1.existsSync(filePath)) return fallback;
|
|
17998
|
+
const content = fs$1.readFileSync(filePath, "utf8").trim();
|
|
17999
|
+
if (content.length === 0) return fallback;
|
|
18000
|
+
return JSON.parse(content);
|
|
18022
18001
|
};
|
|
18023
|
-
const
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18002
|
+
const writeJsonFile = (filePath, value) => {
|
|
18003
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
18004
|
+
fs$1.writeFileSync(filePath, `${JSON.stringify(value, null, JSON_INDENT_SPACES$1)}\n`);
|
|
18005
|
+
};
|
|
18006
|
+
const writeHookScript = (filePath) => {
|
|
18007
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
18008
|
+
fs$1.writeFileSync(filePath, buildAgentHookScript());
|
|
18009
|
+
fs$1.chmodSync(filePath, 493);
|
|
18010
|
+
};
|
|
18011
|
+
const hasClaudeHookCommand = (groups) => groups.some((group) => (group.hooks ?? []).some((hook) => hook.command === CLAUDE_HOOK_COMMAND));
|
|
18012
|
+
const installClaudeHook = (projectRoot) => {
|
|
18013
|
+
const settingsPath = path$1.join(projectRoot, CLAUDE_SETTINGS_RELATIVE_PATH);
|
|
18014
|
+
const hookPath = path$1.join(projectRoot, CLAUDE_HOOK_RELATIVE_PATH);
|
|
18015
|
+
const settings = readJsonFile(settingsPath, {});
|
|
18016
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
18017
|
+
const postToolBatchHooks = [...hooks.PostToolBatch ?? []];
|
|
18018
|
+
if (!hasClaudeHookCommand(postToolBatchHooks)) postToolBatchHooks.push({ hooks: [{
|
|
18019
|
+
type: "command",
|
|
18020
|
+
command: CLAUDE_HOOK_COMMAND
|
|
18021
|
+
}] });
|
|
18022
|
+
hooks.PostToolBatch = postToolBatchHooks;
|
|
18023
|
+
writeJsonFile(settingsPath, {
|
|
18024
|
+
...settings,
|
|
18025
|
+
hooks
|
|
18026
|
+
});
|
|
18027
|
+
writeHookScript(hookPath);
|
|
18028
|
+
return [settingsPath, hookPath];
|
|
18029
|
+
};
|
|
18030
|
+
const hasCursorHookCommand = (handlers) => handlers.some((handler) => handler.command === CURSOR_HOOK_RELATIVE_PATH);
|
|
18031
|
+
const installCursorHook = (projectRoot) => {
|
|
18032
|
+
const configPath = path$1.join(projectRoot, CURSOR_HOOKS_RELATIVE_PATH);
|
|
18033
|
+
const hookPath = path$1.join(projectRoot, CURSOR_HOOK_RELATIVE_PATH);
|
|
18034
|
+
const config = readJsonFile(configPath, {});
|
|
18035
|
+
const hooks = { ...config.hooks ?? {} };
|
|
18036
|
+
const postToolUseHooks = [...hooks.postToolUse ?? []];
|
|
18037
|
+
if (!hasCursorHookCommand(postToolUseHooks)) postToolUseHooks.push({
|
|
18038
|
+
command: CURSOR_HOOK_RELATIVE_PATH,
|
|
18039
|
+
matcher: CURSOR_HOOK_MATCHER,
|
|
18040
|
+
timeout: 120
|
|
18041
|
+
});
|
|
18042
|
+
hooks.postToolUse = postToolUseHooks;
|
|
18043
|
+
writeJsonFile(configPath, {
|
|
18044
|
+
...config,
|
|
18045
|
+
version: config.version ?? CURSOR_HOOKS_SCHEMA_VERSION,
|
|
18046
|
+
hooks
|
|
18047
|
+
});
|
|
18048
|
+
writeHookScript(hookPath);
|
|
18049
|
+
return [configPath, hookPath];
|
|
18050
|
+
};
|
|
18051
|
+
const buildAgentHookScript = () => [
|
|
18052
|
+
"#!/bin/sh",
|
|
18053
|
+
"set -u",
|
|
18054
|
+
"",
|
|
18055
|
+
"input_file=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-agent-hook.XXXXXX\")",
|
|
18056
|
+
"output_file=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-agent-hook-output.XXXXXX\")",
|
|
18057
|
+
"trap 'rm -f \"$input_file\" \"$output_file\"' EXIT",
|
|
18058
|
+
"cat > \"$input_file\"",
|
|
18059
|
+
"",
|
|
18060
|
+
"script_dir=$(CDPATH= cd \"$(dirname \"$0\")\" && pwd)",
|
|
18061
|
+
"project_root=${CLAUDE_PROJECT_DIR:-}",
|
|
18062
|
+
"if [ -z \"$project_root\" ]; then",
|
|
18063
|
+
" project_root=$(CDPATH= cd \"$script_dir/../..\" && pwd)",
|
|
18064
|
+
"fi",
|
|
18065
|
+
"if ! cd \"$project_root\"; then",
|
|
18066
|
+
" exit 0",
|
|
18067
|
+
"fi",
|
|
18068
|
+
"",
|
|
18069
|
+
"should_scan() {",
|
|
18070
|
+
" if ! command -v node >/dev/null 2>&1; then",
|
|
18071
|
+
" return 0",
|
|
18072
|
+
" fi",
|
|
18073
|
+
"",
|
|
18074
|
+
" node - \"$input_file\" <<'NODE'",
|
|
18075
|
+
"const fs = require('node:fs');",
|
|
18076
|
+
"const inputPath = process.argv[2];",
|
|
18077
|
+
"const editToolNames = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'ApplyPatch']);",
|
|
18078
|
+
"try {",
|
|
18079
|
+
" const input = JSON.parse(fs.readFileSync(inputPath, 'utf8') || '{}');",
|
|
18080
|
+
" const eventName = input.hook_event_name || input.eventName || input.event_name;",
|
|
18081
|
+
" if (eventName === 'PostToolBatch') {",
|
|
18082
|
+
" const toolCalls = Array.isArray(input.tool_calls) ? input.tool_calls : [];",
|
|
18083
|
+
" process.exit(toolCalls.some((toolCall) => editToolNames.has(toolCall.tool_name)) ? 0 : 10);",
|
|
18084
|
+
" }",
|
|
18085
|
+
" const toolName = input.tool_name || input.toolName || input.tool;",
|
|
18086
|
+
" process.exit(!toolName || editToolNames.has(toolName) ? 0 : 10);",
|
|
18087
|
+
"} catch {",
|
|
18088
|
+
" process.exit(0);",
|
|
18089
|
+
"}",
|
|
18090
|
+
"NODE",
|
|
18091
|
+
"}",
|
|
18092
|
+
"",
|
|
18093
|
+
"run_react_doctor() {",
|
|
18094
|
+
" if [ -x ./node_modules/.bin/react-doctor ]; then",
|
|
18095
|
+
" ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
|
|
18096
|
+
" return",
|
|
18097
|
+
" fi",
|
|
18098
|
+
"",
|
|
18099
|
+
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
18100
|
+
" react-doctor --verbose --diff --blocking warning --no-score",
|
|
18101
|
+
" return",
|
|
18102
|
+
" fi",
|
|
18103
|
+
"",
|
|
18104
|
+
" if command -v pnpm >/dev/null 2>&1; then",
|
|
18105
|
+
" pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
18106
|
+
" return",
|
|
18107
|
+
" fi",
|
|
18108
|
+
"",
|
|
18109
|
+
" if command -v npx >/dev/null 2>&1; then",
|
|
18110
|
+
" npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
18111
|
+
" return",
|
|
18112
|
+
" fi",
|
|
18113
|
+
"",
|
|
18114
|
+
" printf '%s\\n' 'react-doctor: command not found; skipping agent hook scan.'",
|
|
18115
|
+
" return 0",
|
|
18116
|
+
"}",
|
|
18117
|
+
"",
|
|
18118
|
+
"if ! should_scan; then",
|
|
18119
|
+
" exit 0",
|
|
18120
|
+
"fi",
|
|
18121
|
+
"",
|
|
18122
|
+
"if run_react_doctor > \"$output_file\" 2>&1; then",
|
|
18123
|
+
" exit 0",
|
|
18124
|
+
"fi",
|
|
18125
|
+
"",
|
|
18126
|
+
"node - \"$input_file\" \"$output_file\" <<'NODE'",
|
|
18127
|
+
"const fs = require('node:fs');",
|
|
18128
|
+
"const inputPath = process.argv[2];",
|
|
18129
|
+
"const outputPath = process.argv[3];",
|
|
18130
|
+
"const readInput = () => {",
|
|
18131
|
+
" try {",
|
|
18132
|
+
" return JSON.parse(fs.readFileSync(inputPath, 'utf8') || '{}');",
|
|
18133
|
+
" } catch {",
|
|
18134
|
+
" return {};",
|
|
18135
|
+
" }",
|
|
18136
|
+
"};",
|
|
18137
|
+
"const input = readInput();",
|
|
18138
|
+
"const scanOutput = fs.readFileSync(outputPath, 'utf8').trim();",
|
|
18139
|
+
"if (!scanOutput) process.exit(0);",
|
|
18140
|
+
"const message = `React Doctor found issues in the changed files. Review this output and fix the regressions before finishing. For confirmed issues that cannot be fixed now, create GitHub issues with the rule, file/line, confidence, impact, and proposed fix.\\n\\n${scanOutput}`;",
|
|
18141
|
+
"if (input.hook_event_name === 'PostToolBatch') {",
|
|
18142
|
+
" console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolBatch', additionalContext: message } }));",
|
|
18143
|
+
"} else {",
|
|
18144
|
+
" console.log(JSON.stringify({ additional_context: message }));",
|
|
18145
|
+
"}",
|
|
18146
|
+
"NODE",
|
|
18147
|
+
""
|
|
18148
|
+
].join("\n");
|
|
18149
|
+
const installReactDoctorAgentHooks = (options) => {
|
|
18150
|
+
const installedAgents = [];
|
|
18151
|
+
const files = [];
|
|
18152
|
+
const requestedAgents = options.agents.filter(isSupportedAgent);
|
|
18153
|
+
for (const agent of requestedAgents) {
|
|
18154
|
+
if (agent === CLAUDE_AGENT) {
|
|
18155
|
+
files.push(...installClaudeHook(options.projectRoot));
|
|
18156
|
+
installedAgents.push(agent);
|
|
18157
|
+
}
|
|
18158
|
+
if (agent === CURSOR_AGENT) {
|
|
18159
|
+
files.push(...installCursorHook(options.projectRoot));
|
|
18160
|
+
installedAgents.push(agent);
|
|
18161
|
+
}
|
|
18031
18162
|
}
|
|
18163
|
+
return {
|
|
18164
|
+
installedAgents,
|
|
18165
|
+
files
|
|
18166
|
+
};
|
|
18032
18167
|
};
|
|
18033
18168
|
//#endregion
|
|
18034
18169
|
//#region src/cli/utils/install-github-workflow.ts
|
|
@@ -18138,575 +18273,20 @@ const installReactDoctorWorkflow = (projectRoot) => {
|
|
|
18138
18273
|
};
|
|
18139
18274
|
}
|
|
18140
18275
|
};
|
|
18141
|
-
const upgradeReactDoctorWorkflowInPlace = (projectRoot) => {
|
|
18142
|
-
const workflow = readReactDoctorWorkflow(projectRoot);
|
|
18143
|
-
if (!workflow) return {
|
|
18144
|
-
status: "not-needed",
|
|
18145
|
-
workflowPath: getReactDoctorWorkflowPath(projectRoot)
|
|
18146
|
-
};
|
|
18147
|
-
const { content, changed } = upgradeWorkflowActionToV2(workflow.content);
|
|
18148
|
-
if (!changed) return {
|
|
18149
|
-
status: "not-needed",
|
|
18150
|
-
workflowPath: workflow.workflowPath
|
|
18151
|
-
};
|
|
18152
|
-
try {
|
|
18153
|
-
fs$1.writeFileSync(workflow.workflowPath, content);
|
|
18154
|
-
return {
|
|
18155
|
-
status: "upgraded",
|
|
18156
|
-
workflowPath: workflow.workflowPath
|
|
18157
|
-
};
|
|
18158
|
-
} catch {
|
|
18159
|
-
return {
|
|
18160
|
-
status: "failed",
|
|
18161
|
-
workflowPath: workflow.workflowPath
|
|
18162
|
-
};
|
|
18163
|
-
}
|
|
18164
|
-
};
|
|
18165
|
-
//#endregion
|
|
18166
|
-
//#region src/cli/utils/hash-project-root.ts
|
|
18167
|
-
const hashProjectRoot = (projectRoot) => createHash("sha256").update(path$1.resolve(projectRoot)).digest("hex");
|
|
18168
18276
|
//#endregion
|
|
18169
|
-
//#region src/cli/utils/
|
|
18170
|
-
const
|
|
18171
|
-
|
|
18172
|
-
|
|
18173
|
-
|
|
18174
|
-
});
|
|
18175
|
-
const hasHandledActionUpgrade = (projectRoot, storeOptions = {}) => {
|
|
18176
|
-
try {
|
|
18177
|
-
const upgrades = getActionUpgradeStore(storeOptions).get("actionUpgrades", {});
|
|
18178
|
-
return Boolean(upgrades[hashProjectRoot(projectRoot)]);
|
|
18179
|
-
} catch {
|
|
18180
|
-
return true;
|
|
18277
|
+
//#region src/cli/utils/report-workflow-result.ts
|
|
18278
|
+
const reportWorkflowResult = (workflowSpinner, result, projectRoot) => {
|
|
18279
|
+
if (result.status === "failed") {
|
|
18280
|
+
workflowSpinner.fail("Couldn't write the GitHub Actions workflow.");
|
|
18281
|
+
return false;
|
|
18181
18282
|
}
|
|
18182
|
-
|
|
18183
|
-
|
|
18184
|
-
try {
|
|
18185
|
-
const store = getActionUpgradeStore(storeOptions);
|
|
18186
|
-
const upgrades = store.get("actionUpgrades", {});
|
|
18187
|
-
store.set("actionUpgrades", {
|
|
18188
|
-
...upgrades,
|
|
18189
|
-
[hashProjectRoot(projectRoot)]: {
|
|
18190
|
-
rootDirectory: path$1.resolve(projectRoot),
|
|
18191
|
-
outcome,
|
|
18192
|
-
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
18193
|
-
}
|
|
18194
|
-
});
|
|
18195
|
-
return true;
|
|
18196
|
-
} catch {
|
|
18283
|
+
if (result.status === "exists") {
|
|
18284
|
+
workflowSpinner.succeed("GitHub Actions workflow already configured.");
|
|
18197
18285
|
return false;
|
|
18198
18286
|
}
|
|
18199
|
-
};
|
|
18200
|
-
|
|
18201
|
-
|
|
18202
|
-
const resolveOpenCommand = (url) => {
|
|
18203
|
-
if (process$1.platform === "darwin") return {
|
|
18204
|
-
command: "open",
|
|
18205
|
-
args: [url]
|
|
18206
|
-
};
|
|
18207
|
-
if (process$1.platform === "win32") return {
|
|
18208
|
-
command: "cmd",
|
|
18209
|
-
args: [
|
|
18210
|
-
"/c",
|
|
18211
|
-
"start",
|
|
18212
|
-
"",
|
|
18213
|
-
url
|
|
18214
|
-
]
|
|
18215
|
-
};
|
|
18216
|
-
return {
|
|
18217
|
-
command: "xdg-open",
|
|
18218
|
-
args: [url]
|
|
18219
|
-
};
|
|
18220
|
-
};
|
|
18221
|
-
const openUrl = (url) => {
|
|
18222
|
-
try {
|
|
18223
|
-
const { command, args } = resolveOpenCommand(url);
|
|
18224
|
-
const child = spawn(command, args, {
|
|
18225
|
-
detached: true,
|
|
18226
|
-
stdio: "ignore"
|
|
18227
|
-
});
|
|
18228
|
-
child.on("error", () => {});
|
|
18229
|
-
child.unref();
|
|
18230
|
-
return true;
|
|
18231
|
-
} catch {
|
|
18232
|
-
return false;
|
|
18233
|
-
}
|
|
18234
|
-
};
|
|
18235
|
-
//#endregion
|
|
18236
|
-
//#region src/cli/utils/ask-add-to-github-actions.ts
|
|
18237
|
-
const CI_YES_CHOICE = "ci-yes";
|
|
18238
|
-
const CI_LEARN_MORE_CHOICE = "ci-learn-more";
|
|
18239
|
-
const CI_NO_CHOICE = "ci-no";
|
|
18240
|
-
const SGR_BOLD_OFF = "\x1B[22m";
|
|
18241
|
-
const ciQuestionMessage = [
|
|
18242
|
-
"Add React Doctor to GitHub Actions?",
|
|
18243
|
-
`${SGR_BOLD_OFF} ${highlighter.dim("Scan every pull request to prevent new React issues while you fix the backlog.")}`,
|
|
18244
|
-
`${SGR_BOLD_OFF} ${highlighter.dim(`Used by teams at ${CI_TRUST_COMPANIES}.`)}`
|
|
18245
|
-
].join("\n");
|
|
18246
|
-
const askAddToGitHubActions = async (prompt = prompts) => {
|
|
18247
|
-
while (true) {
|
|
18248
|
-
const { ciChoice } = await prompt({
|
|
18249
|
-
type: "select",
|
|
18250
|
-
name: "ciChoice",
|
|
18251
|
-
message: ciQuestionMessage,
|
|
18252
|
-
hint: " ",
|
|
18253
|
-
choices: [
|
|
18254
|
-
{
|
|
18255
|
-
title: "Yes",
|
|
18256
|
-
description: "Adds the workflow file and a doctor package script",
|
|
18257
|
-
value: CI_YES_CHOICE
|
|
18258
|
-
},
|
|
18259
|
-
{
|
|
18260
|
-
title: "Learn more",
|
|
18261
|
-
description: "Opens the docs page in your browser",
|
|
18262
|
-
value: CI_LEARN_MORE_CHOICE
|
|
18263
|
-
},
|
|
18264
|
-
{
|
|
18265
|
-
title: "No",
|
|
18266
|
-
description: "Skip for now",
|
|
18267
|
-
value: CI_NO_CHOICE
|
|
18268
|
-
}
|
|
18269
|
-
],
|
|
18270
|
-
initial: 0
|
|
18271
|
-
}, { onCancel: () => true });
|
|
18272
|
-
if (ciChoice === void 0) return "cancel";
|
|
18273
|
-
if (ciChoice === CI_YES_CHOICE) return "yes";
|
|
18274
|
-
if (ciChoice === CI_NO_CHOICE) return "no";
|
|
18275
|
-
const opened = openUrl(GITHUB_ACTIONS_SETUP_URL);
|
|
18276
|
-
cliLogger.log(opened ? `Opened ${highlighter.info(GITHUB_ACTIONS_SETUP_URL)} in your browser.` : `Visit ${highlighter.info(GITHUB_ACTIONS_SETUP_URL)} to learn more.`);
|
|
18277
|
-
cliLogger.break();
|
|
18278
|
-
}
|
|
18279
|
-
};
|
|
18280
|
-
//#endregion
|
|
18281
|
-
//#region src/cli/utils/ask-upgrade-action-version.ts
|
|
18282
|
-
const UPGRADE_YES_CHOICE = "upgrade-yes";
|
|
18283
|
-
const UPGRADE_NO_CHOICE = "upgrade-no";
|
|
18284
|
-
const askUpgradeActionVersion = async (prompt = prompts) => {
|
|
18285
|
-
const { upgradeChoice } = await prompt({
|
|
18286
|
-
type: "select",
|
|
18287
|
-
name: "upgradeChoice",
|
|
18288
|
-
message: "A new major of the React Doctor Action (v2) is out. Upgrade this repo's workflow?",
|
|
18289
|
-
hint: " ",
|
|
18290
|
-
choices: [{
|
|
18291
|
-
title: "Yes (recommended)",
|
|
18292
|
-
description: "Bump the workflow to millionco/react-doctor@v2",
|
|
18293
|
-
value: UPGRADE_YES_CHOICE
|
|
18294
|
-
}, {
|
|
18295
|
-
title: "No, thanks",
|
|
18296
|
-
description: "Keep @v1 — won't ask again for this repo",
|
|
18297
|
-
value: UPGRADE_NO_CHOICE
|
|
18298
|
-
}],
|
|
18299
|
-
initial: 0
|
|
18300
|
-
}, { onCancel: () => true });
|
|
18301
|
-
if (upgradeChoice === void 0) return "cancel";
|
|
18302
|
-
return upgradeChoice === UPGRADE_YES_CHOICE ? "yes" : "no";
|
|
18303
|
-
};
|
|
18304
|
-
//#endregion
|
|
18305
|
-
//#region src/cli/utils/open-workflow-pull-request.ts
|
|
18306
|
-
const NEW_BRANCH_PREFIX = "react-doctor/add-github-actions";
|
|
18307
|
-
const DEFAULT_COMMIT_MESSAGE = "ci: add React Doctor GitHub Actions workflow";
|
|
18308
|
-
const DEFAULT_PR_TITLE = "Add React Doctor to GitHub Actions";
|
|
18309
|
-
const DEFAULT_PR_BODY = `Adds a [React Doctor](https://www.react.doctor) scan to every pull request and every push to the default branch. The workflow file is documented inline.
|
|
18310
|
-
|
|
18311
|
-
Docs: https://www.react.doctor/ci`;
|
|
18312
|
-
const execFileAsync$1 = promisify(execFile);
|
|
18313
|
-
const run = async (command, args, cwd) => {
|
|
18314
|
-
try {
|
|
18315
|
-
const { stdout, stderr } = await execFileAsync$1(command, [...args], {
|
|
18316
|
-
cwd,
|
|
18317
|
-
encoding: "utf8"
|
|
18318
|
-
});
|
|
18319
|
-
return {
|
|
18320
|
-
success: true,
|
|
18321
|
-
stdout: stdout.trim(),
|
|
18322
|
-
stderr: stderr.trim()
|
|
18323
|
-
};
|
|
18324
|
-
} catch (error) {
|
|
18325
|
-
const failure = error;
|
|
18326
|
-
return {
|
|
18327
|
-
success: false,
|
|
18328
|
-
stdout: (failure.stdout ?? "").trim(),
|
|
18329
|
-
stderr: (failure.stderr ?? "").trim()
|
|
18330
|
-
};
|
|
18331
|
-
}
|
|
18332
|
-
};
|
|
18333
|
-
const detectDefaultBranch = async (cwd) => {
|
|
18334
|
-
const symRef = await run("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], cwd);
|
|
18335
|
-
if (symRef.success) {
|
|
18336
|
-
const branchMatch = symRef.stdout.match(/refs\/remotes\/origin\/(.+)$/);
|
|
18337
|
-
if (branchMatch) return branchMatch[1];
|
|
18338
|
-
}
|
|
18339
|
-
if ((await run("git", [
|
|
18340
|
-
"rev-parse",
|
|
18341
|
-
"--verify",
|
|
18342
|
-
"origin/main"
|
|
18343
|
-
], cwd)).success) return "main";
|
|
18344
|
-
if ((await run("git", [
|
|
18345
|
-
"rev-parse",
|
|
18346
|
-
"--verify",
|
|
18347
|
-
"origin/master"
|
|
18348
|
-
], cwd)).success) return "master";
|
|
18349
|
-
return null;
|
|
18350
|
-
};
|
|
18351
|
-
const findUniqueBranchName = async (cwd) => {
|
|
18352
|
-
if (!(await run("git", [
|
|
18353
|
-
"rev-parse",
|
|
18354
|
-
"--verify",
|
|
18355
|
-
NEW_BRANCH_PREFIX
|
|
18356
|
-
], cwd)).success) return NEW_BRANCH_PREFIX;
|
|
18357
|
-
return `${NEW_BRANCH_PREFIX}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 16).replace(/[-:T]/g, "")}`;
|
|
18358
|
-
};
|
|
18359
|
-
const openWorkflowPullRequest = async (params) => {
|
|
18360
|
-
const workflowPath = path$1.resolve(params.workflowPath);
|
|
18361
|
-
const commitMessage = params.commitMessage ?? DEFAULT_COMMIT_MESSAGE;
|
|
18362
|
-
const prTitle = params.prTitle ?? DEFAULT_PR_TITLE;
|
|
18363
|
-
const prBody = params.prBody ?? DEFAULT_PR_BODY;
|
|
18364
|
-
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
18365
|
-
if (!repoRootProbe.success) return {
|
|
18366
|
-
status: "not-attempted",
|
|
18367
|
-
reason: "not-a-git-repo"
|
|
18368
|
-
};
|
|
18369
|
-
const cwd = repoRootProbe.stdout;
|
|
18370
|
-
if (!isCommandAvailable("gh")) return {
|
|
18371
|
-
status: "not-attempted",
|
|
18372
|
-
reason: "gh-not-installed"
|
|
18373
|
-
};
|
|
18374
|
-
if (!(await run("gh", ["auth", "status"], cwd)).success) return {
|
|
18375
|
-
status: "not-attempted",
|
|
18376
|
-
reason: "gh-not-authenticated"
|
|
18377
|
-
};
|
|
18378
|
-
const defaultBranch = await detectDefaultBranch(cwd);
|
|
18379
|
-
if (!defaultBranch) return {
|
|
18380
|
-
status: "not-attempted",
|
|
18381
|
-
reason: "no-default-branch"
|
|
18382
|
-
};
|
|
18383
|
-
const previousBranchProbe = await run("git", [
|
|
18384
|
-
"rev-parse",
|
|
18385
|
-
"--abbrev-ref",
|
|
18386
|
-
"HEAD"
|
|
18387
|
-
], cwd);
|
|
18388
|
-
if (!previousBranchProbe.success || previousBranchProbe.stdout === "HEAD") return {
|
|
18389
|
-
status: "not-attempted",
|
|
18390
|
-
reason: "detached-head"
|
|
18391
|
-
};
|
|
18392
|
-
const previousBranch = previousBranchProbe.stdout;
|
|
18393
|
-
await run("git", [
|
|
18394
|
-
"fetch",
|
|
18395
|
-
"origin",
|
|
18396
|
-
defaultBranch
|
|
18397
|
-
], cwd);
|
|
18398
|
-
const newBranch = await findUniqueBranchName(cwd);
|
|
18399
|
-
if (!(await run("git", [
|
|
18400
|
-
"checkout",
|
|
18401
|
-
"-b",
|
|
18402
|
-
newBranch,
|
|
18403
|
-
`origin/${defaultBranch}`
|
|
18404
|
-
], cwd)).success) return {
|
|
18405
|
-
status: "not-attempted",
|
|
18406
|
-
reason: "checkout-failed"
|
|
18407
|
-
};
|
|
18408
|
-
const restoreToPreviousBranch = async (deleteNewBranch) => {
|
|
18409
|
-
await run("git", ["checkout", previousBranch], cwd);
|
|
18410
|
-
if (deleteNewBranch) await run("git", [
|
|
18411
|
-
"branch",
|
|
18412
|
-
"-D",
|
|
18413
|
-
newBranch
|
|
18414
|
-
], cwd);
|
|
18415
|
-
};
|
|
18416
|
-
if (!(await run("git", [
|
|
18417
|
-
"add",
|
|
18418
|
-
"--",
|
|
18419
|
-
path$1.relative(cwd, workflowPath)
|
|
18420
|
-
], cwd)).success) {
|
|
18421
|
-
await restoreToPreviousBranch(true);
|
|
18422
|
-
return {
|
|
18423
|
-
status: "not-attempted",
|
|
18424
|
-
reason: "git-add-failed"
|
|
18425
|
-
};
|
|
18426
|
-
}
|
|
18427
|
-
if (!(await run("git", [
|
|
18428
|
-
"commit",
|
|
18429
|
-
"-m",
|
|
18430
|
-
commitMessage
|
|
18431
|
-
], cwd)).success) {
|
|
18432
|
-
await restoreToPreviousBranch(true);
|
|
18433
|
-
return {
|
|
18434
|
-
status: "not-attempted",
|
|
18435
|
-
reason: "git-commit-failed"
|
|
18436
|
-
};
|
|
18437
|
-
}
|
|
18438
|
-
if (!(await run("git", [
|
|
18439
|
-
"push",
|
|
18440
|
-
"-u",
|
|
18441
|
-
"origin",
|
|
18442
|
-
newBranch
|
|
18443
|
-
], cwd)).success) {
|
|
18444
|
-
await restoreToPreviousBranch(true);
|
|
18445
|
-
return {
|
|
18446
|
-
status: "not-attempted",
|
|
18447
|
-
reason: "git-push-failed"
|
|
18448
|
-
};
|
|
18449
|
-
}
|
|
18450
|
-
const prCreate = await run("gh", [
|
|
18451
|
-
"pr",
|
|
18452
|
-
"create",
|
|
18453
|
-
"--title",
|
|
18454
|
-
prTitle,
|
|
18455
|
-
"--body",
|
|
18456
|
-
prBody,
|
|
18457
|
-
"--base",
|
|
18458
|
-
defaultBranch,
|
|
18459
|
-
"--head",
|
|
18460
|
-
newBranch
|
|
18461
|
-
], cwd);
|
|
18462
|
-
await restoreToPreviousBranch(false);
|
|
18463
|
-
if (!prCreate.success) return {
|
|
18464
|
-
status: "branch-pushed",
|
|
18465
|
-
branch: newBranch
|
|
18466
|
-
};
|
|
18467
|
-
return {
|
|
18468
|
-
status: "pr-opened",
|
|
18469
|
-
url: prCreate.stdout.split(/\r?\n/).filter(Boolean).pop() ?? ""
|
|
18470
|
-
};
|
|
18471
|
-
};
|
|
18472
|
-
const stageWorkflowFile = async (params) => {
|
|
18473
|
-
const workflowPath = path$1.resolve(params.workflowPath);
|
|
18474
|
-
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
18475
|
-
if (!repoRootProbe.success) return false;
|
|
18476
|
-
return (await run("git", [
|
|
18477
|
-
"add",
|
|
18478
|
-
"--",
|
|
18479
|
-
path$1.relative(repoRootProbe.stdout, workflowPath)
|
|
18480
|
-
], repoRootProbe.stdout)).success;
|
|
18481
|
-
};
|
|
18482
|
-
//#endregion
|
|
18483
|
-
//#region src/cli/utils/report-workflow-result.ts
|
|
18484
|
-
const reportWorkflowResult = (workflowSpinner, result, projectRoot) => {
|
|
18485
|
-
if (result.status === "failed") {
|
|
18486
|
-
workflowSpinner.fail("Couldn't write the GitHub Actions workflow.");
|
|
18487
|
-
return false;
|
|
18488
|
-
}
|
|
18489
|
-
if (result.status === "exists") {
|
|
18490
|
-
workflowSpinner.succeed("GitHub Actions workflow already configured.");
|
|
18491
|
-
return false;
|
|
18492
|
-
}
|
|
18493
|
-
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18494
|
-
recordCount(METRIC.installWorkflow, 1);
|
|
18495
|
-
return true;
|
|
18496
|
-
};
|
|
18497
|
-
//#endregion
|
|
18498
|
-
//#region src/cli/utils/set-up-github-actions.ts
|
|
18499
|
-
const setUpGitHubActions = async (options) => {
|
|
18500
|
-
const projectRoot = findNearestPackageDirectory(options.rootDirectory) ?? options.rootDirectory;
|
|
18501
|
-
try {
|
|
18502
|
-
installReactDoctorScriptStep(projectRoot);
|
|
18503
|
-
} catch {}
|
|
18504
|
-
const workflowSpinner = spinner("Adding GitHub Actions workflow...").start();
|
|
18505
|
-
const workflowResult = installReactDoctorWorkflow(projectRoot);
|
|
18506
|
-
const didCreateWorkflow = reportWorkflowResult(workflowSpinner, workflowResult, projectRoot);
|
|
18507
|
-
cliLogger.break();
|
|
18508
|
-
if (workflowResult.status === "failed") {
|
|
18509
|
-
cliLogger.log(` Couldn't set up GitHub Actions automatically. Follow the guide at ${highlighter.info(CI_URL)}`);
|
|
18510
|
-
return false;
|
|
18511
|
-
}
|
|
18512
|
-
if (workflowResult.status === "created") {
|
|
18513
|
-
const pullRequestSpinner = spinner("Opening a pull request for review...").start();
|
|
18514
|
-
const pullRequestResult = await openWorkflowPullRequest({ workflowPath: workflowResult.workflowPath });
|
|
18515
|
-
if (pullRequestResult.status === "pr-opened") pullRequestSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
|
|
18516
|
-
else if (pullRequestResult.status === "branch-pushed") pullRequestSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
|
|
18517
|
-
else {
|
|
18518
|
-
pullRequestSpinner.stop();
|
|
18519
|
-
const didStage = await stageWorkflowFile({ workflowPath: workflowResult.workflowPath });
|
|
18520
|
-
cliLogger.log(didStage ? ` Staged the workflow file. Commit it to start scanning every pull request.` : " React Doctor will now scan every new pull request automatically.");
|
|
18521
|
-
}
|
|
18522
|
-
}
|
|
18523
|
-
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
18524
|
-
return didCreateWorkflow;
|
|
18525
|
-
};
|
|
18526
|
-
//#endregion
|
|
18527
|
-
//#region src/cli/utils/install-agent-hooks.ts
|
|
18528
|
-
const CLAUDE_AGENT = "claude-code";
|
|
18529
|
-
const CURSOR_AGENT = "cursor";
|
|
18530
|
-
const CLAUDE_SETTINGS_RELATIVE_PATH = ".claude/settings.json";
|
|
18531
|
-
const CLAUDE_HOOK_RELATIVE_PATH = ".claude/hooks/react-doctor.sh";
|
|
18532
|
-
const CLAUDE_HOOK_COMMAND = "sh \"$CLAUDE_PROJECT_DIR/.claude/hooks/react-doctor.sh\"";
|
|
18533
|
-
const CURSOR_HOOKS_RELATIVE_PATH = ".cursor/hooks.json";
|
|
18534
|
-
const CURSOR_HOOK_RELATIVE_PATH = ".cursor/hooks/react-doctor.sh";
|
|
18535
|
-
const CURSOR_HOOK_MATCHER = "Write|Edit|MultiEdit|ApplyPatch";
|
|
18536
|
-
const CURSOR_HOOKS_SCHEMA_VERSION = 1;
|
|
18537
|
-
const JSON_INDENT_SPACES$1 = 2;
|
|
18538
|
-
const isSupportedAgent = (agent) => agent === CLAUDE_AGENT || agent === CURSOR_AGENT;
|
|
18539
|
-
const readJsonFile = (filePath, fallback) => {
|
|
18540
|
-
if (!fs$1.existsSync(filePath)) return fallback;
|
|
18541
|
-
const content = fs$1.readFileSync(filePath, "utf8").trim();
|
|
18542
|
-
if (content.length === 0) return fallback;
|
|
18543
|
-
return JSON.parse(content);
|
|
18544
|
-
};
|
|
18545
|
-
const writeJsonFile = (filePath, value) => {
|
|
18546
|
-
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
18547
|
-
fs$1.writeFileSync(filePath, `${JSON.stringify(value, null, JSON_INDENT_SPACES$1)}\n`);
|
|
18548
|
-
};
|
|
18549
|
-
const writeHookScript = (filePath) => {
|
|
18550
|
-
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
18551
|
-
fs$1.writeFileSync(filePath, buildAgentHookScript());
|
|
18552
|
-
fs$1.chmodSync(filePath, 493);
|
|
18553
|
-
};
|
|
18554
|
-
const hasClaudeHookCommand = (groups) => groups.some((group) => (group.hooks ?? []).some((hook) => hook.command === CLAUDE_HOOK_COMMAND));
|
|
18555
|
-
const installClaudeHook = (projectRoot) => {
|
|
18556
|
-
const settingsPath = path$1.join(projectRoot, CLAUDE_SETTINGS_RELATIVE_PATH);
|
|
18557
|
-
const hookPath = path$1.join(projectRoot, CLAUDE_HOOK_RELATIVE_PATH);
|
|
18558
|
-
const settings = readJsonFile(settingsPath, {});
|
|
18559
|
-
const hooks = { ...settings.hooks ?? {} };
|
|
18560
|
-
const postToolBatchHooks = [...hooks.PostToolBatch ?? []];
|
|
18561
|
-
if (!hasClaudeHookCommand(postToolBatchHooks)) postToolBatchHooks.push({ hooks: [{
|
|
18562
|
-
type: "command",
|
|
18563
|
-
command: CLAUDE_HOOK_COMMAND
|
|
18564
|
-
}] });
|
|
18565
|
-
hooks.PostToolBatch = postToolBatchHooks;
|
|
18566
|
-
writeJsonFile(settingsPath, {
|
|
18567
|
-
...settings,
|
|
18568
|
-
hooks
|
|
18569
|
-
});
|
|
18570
|
-
writeHookScript(hookPath);
|
|
18571
|
-
return [settingsPath, hookPath];
|
|
18572
|
-
};
|
|
18573
|
-
const hasCursorHookCommand = (handlers) => handlers.some((handler) => handler.command === CURSOR_HOOK_RELATIVE_PATH);
|
|
18574
|
-
const installCursorHook = (projectRoot) => {
|
|
18575
|
-
const configPath = path$1.join(projectRoot, CURSOR_HOOKS_RELATIVE_PATH);
|
|
18576
|
-
const hookPath = path$1.join(projectRoot, CURSOR_HOOK_RELATIVE_PATH);
|
|
18577
|
-
const config = readJsonFile(configPath, {});
|
|
18578
|
-
const hooks = { ...config.hooks ?? {} };
|
|
18579
|
-
const postToolUseHooks = [...hooks.postToolUse ?? []];
|
|
18580
|
-
if (!hasCursorHookCommand(postToolUseHooks)) postToolUseHooks.push({
|
|
18581
|
-
command: CURSOR_HOOK_RELATIVE_PATH,
|
|
18582
|
-
matcher: CURSOR_HOOK_MATCHER,
|
|
18583
|
-
timeout: 120
|
|
18584
|
-
});
|
|
18585
|
-
hooks.postToolUse = postToolUseHooks;
|
|
18586
|
-
writeJsonFile(configPath, {
|
|
18587
|
-
...config,
|
|
18588
|
-
version: config.version ?? CURSOR_HOOKS_SCHEMA_VERSION,
|
|
18589
|
-
hooks
|
|
18590
|
-
});
|
|
18591
|
-
writeHookScript(hookPath);
|
|
18592
|
-
return [configPath, hookPath];
|
|
18593
|
-
};
|
|
18594
|
-
const buildAgentHookScript = () => [
|
|
18595
|
-
"#!/bin/sh",
|
|
18596
|
-
"set -u",
|
|
18597
|
-
"",
|
|
18598
|
-
"input_file=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-agent-hook.XXXXXX\")",
|
|
18599
|
-
"output_file=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-agent-hook-output.XXXXXX\")",
|
|
18600
|
-
"trap 'rm -f \"$input_file\" \"$output_file\"' EXIT",
|
|
18601
|
-
"cat > \"$input_file\"",
|
|
18602
|
-
"",
|
|
18603
|
-
"script_dir=$(CDPATH= cd \"$(dirname \"$0\")\" && pwd)",
|
|
18604
|
-
"project_root=${CLAUDE_PROJECT_DIR:-}",
|
|
18605
|
-
"if [ -z \"$project_root\" ]; then",
|
|
18606
|
-
" project_root=$(CDPATH= cd \"$script_dir/../..\" && pwd)",
|
|
18607
|
-
"fi",
|
|
18608
|
-
"if ! cd \"$project_root\"; then",
|
|
18609
|
-
" exit 0",
|
|
18610
|
-
"fi",
|
|
18611
|
-
"",
|
|
18612
|
-
"should_scan() {",
|
|
18613
|
-
" if ! command -v node >/dev/null 2>&1; then",
|
|
18614
|
-
" return 0",
|
|
18615
|
-
" fi",
|
|
18616
|
-
"",
|
|
18617
|
-
" node - \"$input_file\" <<'NODE'",
|
|
18618
|
-
"const fs = require('node:fs');",
|
|
18619
|
-
"const inputPath = process.argv[2];",
|
|
18620
|
-
"const editToolNames = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'ApplyPatch']);",
|
|
18621
|
-
"try {",
|
|
18622
|
-
" const input = JSON.parse(fs.readFileSync(inputPath, 'utf8') || '{}');",
|
|
18623
|
-
" const eventName = input.hook_event_name || input.eventName || input.event_name;",
|
|
18624
|
-
" if (eventName === 'PostToolBatch') {",
|
|
18625
|
-
" const toolCalls = Array.isArray(input.tool_calls) ? input.tool_calls : [];",
|
|
18626
|
-
" process.exit(toolCalls.some((toolCall) => editToolNames.has(toolCall.tool_name)) ? 0 : 10);",
|
|
18627
|
-
" }",
|
|
18628
|
-
" const toolName = input.tool_name || input.toolName || input.tool;",
|
|
18629
|
-
" process.exit(!toolName || editToolNames.has(toolName) ? 0 : 10);",
|
|
18630
|
-
"} catch {",
|
|
18631
|
-
" process.exit(0);",
|
|
18632
|
-
"}",
|
|
18633
|
-
"NODE",
|
|
18634
|
-
"}",
|
|
18635
|
-
"",
|
|
18636
|
-
"run_react_doctor() {",
|
|
18637
|
-
" if [ -x ./node_modules/.bin/react-doctor ]; then",
|
|
18638
|
-
" ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
|
|
18639
|
-
" return",
|
|
18640
|
-
" fi",
|
|
18641
|
-
"",
|
|
18642
|
-
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
18643
|
-
" react-doctor --verbose --diff --blocking warning --no-score",
|
|
18644
|
-
" return",
|
|
18645
|
-
" fi",
|
|
18646
|
-
"",
|
|
18647
|
-
" if command -v pnpm >/dev/null 2>&1; then",
|
|
18648
|
-
" pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
18649
|
-
" return",
|
|
18650
|
-
" fi",
|
|
18651
|
-
"",
|
|
18652
|
-
" if command -v npx >/dev/null 2>&1; then",
|
|
18653
|
-
" npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
18654
|
-
" return",
|
|
18655
|
-
" fi",
|
|
18656
|
-
"",
|
|
18657
|
-
" printf '%s\\n' 'react-doctor: command not found; skipping agent hook scan.'",
|
|
18658
|
-
" return 0",
|
|
18659
|
-
"}",
|
|
18660
|
-
"",
|
|
18661
|
-
"if ! should_scan; then",
|
|
18662
|
-
" exit 0",
|
|
18663
|
-
"fi",
|
|
18664
|
-
"",
|
|
18665
|
-
"if run_react_doctor > \"$output_file\" 2>&1; then",
|
|
18666
|
-
" exit 0",
|
|
18667
|
-
"fi",
|
|
18668
|
-
"",
|
|
18669
|
-
"node - \"$input_file\" \"$output_file\" <<'NODE'",
|
|
18670
|
-
"const fs = require('node:fs');",
|
|
18671
|
-
"const inputPath = process.argv[2];",
|
|
18672
|
-
"const outputPath = process.argv[3];",
|
|
18673
|
-
"const readInput = () => {",
|
|
18674
|
-
" try {",
|
|
18675
|
-
" return JSON.parse(fs.readFileSync(inputPath, 'utf8') || '{}');",
|
|
18676
|
-
" } catch {",
|
|
18677
|
-
" return {};",
|
|
18678
|
-
" }",
|
|
18679
|
-
"};",
|
|
18680
|
-
"const input = readInput();",
|
|
18681
|
-
"const scanOutput = fs.readFileSync(outputPath, 'utf8').trim();",
|
|
18682
|
-
"if (!scanOutput) process.exit(0);",
|
|
18683
|
-
"const message = `React Doctor found issues in the changed files. Review this output and fix the regressions before finishing. For confirmed issues that cannot be fixed now, create GitHub issues with the rule, file/line, confidence, impact, and proposed fix.\\n\\n${scanOutput}`;",
|
|
18684
|
-
"if (input.hook_event_name === 'PostToolBatch') {",
|
|
18685
|
-
" console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolBatch', additionalContext: message } }));",
|
|
18686
|
-
"} else {",
|
|
18687
|
-
" console.log(JSON.stringify({ additional_context: message }));",
|
|
18688
|
-
"}",
|
|
18689
|
-
"NODE",
|
|
18690
|
-
""
|
|
18691
|
-
].join("\n");
|
|
18692
|
-
const installReactDoctorAgentHooks = (options) => {
|
|
18693
|
-
const installedAgents = [];
|
|
18694
|
-
const files = [];
|
|
18695
|
-
const requestedAgents = options.agents.filter(isSupportedAgent);
|
|
18696
|
-
for (const agent of requestedAgents) {
|
|
18697
|
-
if (agent === CLAUDE_AGENT) {
|
|
18698
|
-
files.push(...installClaudeHook(options.projectRoot));
|
|
18699
|
-
installedAgents.push(agent);
|
|
18700
|
-
}
|
|
18701
|
-
if (agent === CURSOR_AGENT) {
|
|
18702
|
-
files.push(...installCursorHook(options.projectRoot));
|
|
18703
|
-
installedAgents.push(agent);
|
|
18704
|
-
}
|
|
18705
|
-
}
|
|
18706
|
-
return {
|
|
18707
|
-
installedAgents,
|
|
18708
|
-
files
|
|
18709
|
-
};
|
|
18287
|
+
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18288
|
+
recordCount(METRIC.installWorkflow, 1);
|
|
18289
|
+
return true;
|
|
18710
18290
|
};
|
|
18711
18291
|
//#endregion
|
|
18712
18292
|
//#region src/cli/utils/install-git-hook-file.ts
|
|
@@ -19104,6 +18684,7 @@ const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.js
|
|
|
19104
18684
|
//#region src/cli/utils/install-react-doctor.ts
|
|
19105
18685
|
const SETUP_OPTION_GIT_HOOK = "git-hook";
|
|
19106
18686
|
const SETUP_OPTION_AGENT_HOOKS = "agent-hooks";
|
|
18687
|
+
const SETUP_OPTION_WORKFLOW = "workflow";
|
|
19107
18688
|
const SETUP_OPTION_SKIP = "skip";
|
|
19108
18689
|
const CONFIG_ONLY_GIT_HOOK_KINDS = new Set([
|
|
19109
18690
|
"ghooks",
|
|
@@ -19204,9 +18785,9 @@ const buildInstallCommand = (projectRoot) => {
|
|
|
19204
18785
|
cwd: projectRoot
|
|
19205
18786
|
};
|
|
19206
18787
|
};
|
|
19207
|
-
const execFileAsync = promisify(execFile);
|
|
18788
|
+
const execFileAsync$1 = promisify(execFile);
|
|
19208
18789
|
const defaultInstallDependencyRunner = async (input) => {
|
|
19209
|
-
await execFileAsync(input.command, [...input.args], {
|
|
18790
|
+
await execFileAsync$1(input.command, [...input.args], {
|
|
19210
18791
|
cwd: input.cwd,
|
|
19211
18792
|
env: {
|
|
19212
18793
|
...process.env,
|
|
@@ -19257,6 +18838,17 @@ const formatGitHookInstallMessage = (hookResult) => {
|
|
|
19257
18838
|
if (CONFIG_ONLY_GIT_HOOK_KINDS.has(hookResult.kind)) return `React Doctor pre-commit config ${hookResult.status} at ${hookResult.hookPath}. Run your hook manager's install command if hooks are not already installed.`;
|
|
19258
18839
|
return `React Doctor pre-commit hook ${hookResult.status} at ${hookResult.hookPath}.`;
|
|
19259
18840
|
};
|
|
18841
|
+
const formatDoctorScriptInstallMessage = (scriptResult) => {
|
|
18842
|
+
const messages = [];
|
|
18843
|
+
const scriptName = scriptResult.scriptName ?? "doctor";
|
|
18844
|
+
if (scriptResult.scriptStatus === "created") messages.push(`Added package script: ${scriptName}.`);
|
|
18845
|
+
else if (scriptResult.scriptStatus === "existing") messages.push(`Package script already exists: ${scriptName}.`);
|
|
18846
|
+
else if (scriptResult.scriptReason === "script-names-taken") messages.push("Skipped package script: doctor and react-doctor are already taken.");
|
|
18847
|
+
else if (scriptResult.scriptReason === "doctor-script-taken") messages.push("Skipped package script: doctor and react-doctor scripts already exist.");
|
|
18848
|
+
else if (scriptResult.scriptReason === "invalid-scripts") messages.push(`Skipped package script: scripts field is not an object.`);
|
|
18849
|
+
else messages.push("Skipped package script: package.json missing or invalid.");
|
|
18850
|
+
return messages.join(" ");
|
|
18851
|
+
};
|
|
19260
18852
|
const formatDependencyInstallMessage = (result) => {
|
|
19261
18853
|
if (result.dependencyStatus === "created") return "Installed dev dependency: react-doctor.";
|
|
19262
18854
|
if (result.dependencyStatus === "existing") return "React Doctor dependency already exists.";
|
|
@@ -19269,6 +18861,16 @@ const buildDependencyFollowUp = (result) => {
|
|
|
19269
18861
|
if (result.dependencyReason !== "trust-policy-blocked" && result.dependencyReason !== "install-command-failed") return;
|
|
19270
18862
|
return ` React Doctor still works via \`npx react-doctor\`. To install locally: ${result.installCommand ?? `npm install --save-dev react-doctor@latest`}`;
|
|
19271
18863
|
};
|
|
18864
|
+
const installReactDoctorScriptStep = (projectRoot) => {
|
|
18865
|
+
const scriptSpinner = spinner("Installing React Doctor package script...").start();
|
|
18866
|
+
try {
|
|
18867
|
+
const scriptResult = installDoctorScript({ projectRoot });
|
|
18868
|
+
scriptSpinner.succeed(formatDoctorScriptInstallMessage(scriptResult));
|
|
18869
|
+
} catch (error) {
|
|
18870
|
+
scriptSpinner.fail("Failed to install React Doctor package script.");
|
|
18871
|
+
throw error;
|
|
18872
|
+
}
|
|
18873
|
+
};
|
|
19272
18874
|
const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) => {
|
|
19273
18875
|
installReactDoctorScriptStep(projectRoot);
|
|
19274
18876
|
const dependencySpinner = spinner("Installing React Doctor package...").start();
|
|
@@ -19325,80 +18927,6 @@ const installBundledSiblingSkills = async (primarySkillDir, agents, projectRoot)
|
|
|
19325
18927
|
return installedSkillNames;
|
|
19326
18928
|
};
|
|
19327
18929
|
const canInstallNativeAgentHooks = (agents) => agents.some((agent) => agent === "claude-code" || agent === "cursor");
|
|
19328
|
-
const installReactDoctorSkillStep = async (sourceDir, selectedAgents, projectRoot) => {
|
|
19329
|
-
const installSpinner = spinner(`Installing ${SKILL_NAME} skill...`).start();
|
|
19330
|
-
try {
|
|
19331
|
-
const installResult = await installSkillsFromSource({
|
|
19332
|
-
source: sourceDir,
|
|
19333
|
-
agents: selectedAgents,
|
|
19334
|
-
cwd: projectRoot,
|
|
19335
|
-
mode: "copy"
|
|
19336
|
-
});
|
|
19337
|
-
if (installResult.skills.length === 0) throw new Error(`Could not parse ${SKILL_MANIFEST_FILE} for ${SKILL_NAME} (missing or invalid frontmatter).`);
|
|
19338
|
-
if (installResult.failed.length > 0) throw new Error(installResult.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
19339
|
-
installSpinner.succeed(`${SKILL_NAME} skill installed for ${selectedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
19340
|
-
} catch (error) {
|
|
19341
|
-
installSpinner.fail(`Failed to install ${SKILL_NAME} skill.`);
|
|
19342
|
-
throw error;
|
|
19343
|
-
}
|
|
19344
|
-
try {
|
|
19345
|
-
const installedSiblingSkills = await installBundledSiblingSkills(sourceDir, selectedAgents, projectRoot);
|
|
19346
|
-
if (installedSiblingSkills.length > 0) cliLogger.dim(` Also installed the ${installedSiblingSkills.join(", ")} skill.`);
|
|
19347
|
-
} catch {
|
|
19348
|
-
cliLogger.dim(" Skipped bundled sibling skills (install error).");
|
|
19349
|
-
}
|
|
19350
|
-
};
|
|
19351
|
-
const installReactDoctorGitHookStep = (gitHookTarget) => {
|
|
19352
|
-
const hookSpinner = spinner("Installing React Doctor pre-commit hook...").start();
|
|
19353
|
-
try {
|
|
19354
|
-
const hookResult = installReactDoctorGitHook({
|
|
19355
|
-
hookPath: gitHookTarget.hookPath,
|
|
19356
|
-
projectRoot: gitHookTarget.runnerRoot,
|
|
19357
|
-
kind: gitHookTarget.kind,
|
|
19358
|
-
hooksPathConfig: gitHookTarget.hooksPathConfig
|
|
19359
|
-
});
|
|
19360
|
-
hookSpinner.succeed(formatGitHookInstallMessage(hookResult));
|
|
19361
|
-
recordCount(METRIC.installGitHook, 1, { kind: hookResult.kind });
|
|
19362
|
-
} catch (error) {
|
|
19363
|
-
hookSpinner.fail("Failed to install React Doctor pre-commit hook.");
|
|
19364
|
-
throw error;
|
|
19365
|
-
}
|
|
19366
|
-
};
|
|
19367
|
-
const installReactDoctorAgentHooksStep = (projectRoot, selectedAgents) => {
|
|
19368
|
-
const hookSpinner = spinner("Installing React Doctor agent hooks...").start();
|
|
19369
|
-
try {
|
|
19370
|
-
const hookResult = installReactDoctorAgentHooks({
|
|
19371
|
-
projectRoot,
|
|
19372
|
-
agents: selectedAgents
|
|
19373
|
-
});
|
|
19374
|
-
if (hookResult.installedAgents.length === 0) hookSpinner.succeed("No supported native agent hook targets selected.");
|
|
19375
|
-
else {
|
|
19376
|
-
hookSpinner.succeed(`React Doctor agent hooks installed for ${hookResult.installedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
19377
|
-
recordCount(METRIC.installAgentHooks, 1, { agentsCount: hookResult.installedAgents.length });
|
|
19378
|
-
}
|
|
19379
|
-
} catch (error) {
|
|
19380
|
-
hookSpinner.fail("Failed to install React Doctor agent hooks.");
|
|
19381
|
-
throw error;
|
|
19382
|
-
}
|
|
19383
|
-
};
|
|
19384
|
-
const installReactDoctorWorkflowStep = (projectRoot) => {
|
|
19385
|
-
return reportWorkflowResult(spinner("Adding GitHub Actions workflow...").start(), installReactDoctorWorkflow(projectRoot), projectRoot);
|
|
19386
|
-
};
|
|
19387
|
-
const upgradeReactDoctorWorkflowStep = (projectRoot) => {
|
|
19388
|
-
const workflowSpinner = spinner("Upgrading GitHub Actions workflow to v2...").start();
|
|
19389
|
-
const upgradeResult = upgradeReactDoctorWorkflowInPlace(projectRoot);
|
|
19390
|
-
if (upgradeResult.status === "failed") {
|
|
19391
|
-
workflowSpinner.fail("Couldn't update the GitHub Actions workflow.");
|
|
19392
|
-
return false;
|
|
19393
|
-
}
|
|
19394
|
-
if (upgradeResult.status === "not-needed") {
|
|
19395
|
-
workflowSpinner.succeed("GitHub Actions workflow already up to date.");
|
|
19396
|
-
return false;
|
|
19397
|
-
}
|
|
19398
|
-
workflowSpinner.succeed(`Upgraded the GitHub Actions workflow to v2 at ${path$1.relative(projectRoot, upgradeResult.workflowPath)}.`);
|
|
19399
|
-
recordCount(METRIC.installWorkflow, 1, { kind: "upgrade" });
|
|
19400
|
-
return true;
|
|
19401
|
-
};
|
|
19402
18930
|
const runInstallReactDoctor = async (options = {}) => {
|
|
19403
18931
|
const requestedProjectRoot = options.projectRoot ?? process.cwd();
|
|
19404
18932
|
const projectRoot = findNearestPackageDirectory(requestedProjectRoot) ?? requestedProjectRoot;
|
|
@@ -19421,14 +18949,6 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
19421
18949
|
const gitHookPath = gitHookTarget?.hookPath;
|
|
19422
18950
|
const promptOptions = options.onPromptCancel === void 0 ? {} : { onCancel: options.onPromptCancel };
|
|
19423
18951
|
const prompt = options.prompt ?? prompts;
|
|
19424
|
-
const workflowTargetPath = getReactDoctorWorkflowPath(projectRoot);
|
|
19425
|
-
const existingWorkflow = readReactDoctorWorkflow(projectRoot);
|
|
19426
|
-
const canInstallWorkflow = !fs$1.existsSync(workflowTargetPath);
|
|
19427
|
-
const canUpgradeWorkflow = existingWorkflow !== null && workflowUsesV1Action(existingWorkflow.content) && !hasHandledActionUpgrade(projectRoot);
|
|
19428
|
-
const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || !skipPrompts && await askAddToGitHubActions(prompt) === "yes");
|
|
19429
|
-
const upgradePromptOutcome = canUpgradeWorkflow && !options.yes && !skipPrompts ? await askUpgradeActionVersion(prompt) : null;
|
|
19430
|
-
const shouldUpgradeWorkflow = canUpgradeWorkflow && (Boolean(options.yes) || upgradePromptOutcome === "yes");
|
|
19431
|
-
if (upgradePromptOutcome === "no" && !options.dryRun) recordActionUpgradeDecision(projectRoot, "declined");
|
|
19432
18952
|
const selectedAgents = skipPrompts ? detectedAgents : (await prompt({
|
|
19433
18953
|
type: "multiselect",
|
|
19434
18954
|
name: "agents",
|
|
@@ -19442,85 +18962,385 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
19442
18962
|
min: 1
|
|
19443
18963
|
}, promptOptions)).agents ?? [];
|
|
19444
18964
|
if (selectedAgents.length === 0) return;
|
|
19445
|
-
|
|
19446
|
-
|
|
19447
|
-
|
|
19448
|
-
|
|
18965
|
+
const workflowTargetPath = getReactDoctorWorkflowPath(projectRoot);
|
|
18966
|
+
const canInstallWorkflow = !isReactDoctorWorkflowInstalled(projectRoot);
|
|
18967
|
+
const setupActionChoices = [
|
|
18968
|
+
...gitHookPath === null || gitHookPath === void 0 ? [] : [{
|
|
18969
|
+
title: "Pre-commit hook",
|
|
18970
|
+
description: "Check staged changes before each commit",
|
|
18971
|
+
value: SETUP_OPTION_GIT_HOOK,
|
|
18972
|
+
selected: true
|
|
18973
|
+
}],
|
|
18974
|
+
...canInstallNativeAgentHooks(selectedAgents) ? [{
|
|
18975
|
+
title: "Agent hooks",
|
|
18976
|
+
description: "Ask Claude Code or Cursor to scan after code edits",
|
|
18977
|
+
value: SETUP_OPTION_AGENT_HOOKS,
|
|
18978
|
+
selected: Boolean(options.agentHooks)
|
|
18979
|
+
}] : [],
|
|
18980
|
+
...canInstallWorkflow ? [{
|
|
18981
|
+
title: "GitHub Actions workflow",
|
|
18982
|
+
description: "Scan pull requests in CI",
|
|
18983
|
+
value: SETUP_OPTION_WORKFLOW,
|
|
18984
|
+
selected: true
|
|
18985
|
+
}] : []
|
|
18986
|
+
];
|
|
18987
|
+
const setupChoices = setupActionChoices.length === 0 ? [] : [{
|
|
18988
|
+
title: "Skip optional setup",
|
|
18989
|
+
description: "Install only the agent skill and package setup",
|
|
18990
|
+
value: SETUP_OPTION_SKIP,
|
|
18991
|
+
selected: false
|
|
18992
|
+
}, ...setupActionChoices];
|
|
18993
|
+
const selectedSetupOptions = skipPrompts || setupChoices.length === 0 ? [] : (await prompt({
|
|
18994
|
+
type: "multiselect",
|
|
18995
|
+
name: "setupOptions",
|
|
18996
|
+
message: "Select additional React Doctor setup:",
|
|
18997
|
+
choices: setupChoices,
|
|
18998
|
+
instructions: false
|
|
18999
|
+
}, promptOptions)).setupOptions ?? [];
|
|
19000
|
+
const selectedSetupActions = selectedSetupOptions.filter((setupOption) => setupOption !== SETUP_OPTION_SKIP);
|
|
19001
|
+
const didSkipOptionalSetup = selectedSetupActions.length === 0 && selectedSetupOptions.includes(SETUP_OPTION_SKIP);
|
|
19002
|
+
const shouldInstallGitHook = gitHookPath != null && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_GIT_HOOK));
|
|
19003
|
+
const shouldInstallAgentHooks = Boolean(options.agentHooks) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_AGENT_HOOKS);
|
|
19004
|
+
const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_WORKFLOW));
|
|
19005
|
+
if (options.dryRun) {
|
|
19006
|
+
cliLogger.log(`Dry run — would install ${SKILL_NAME} skill for:`);
|
|
19007
|
+
for (const agent of selectedAgents) cliLogger.dim(` - ${getSkillAgentConfig(agent).displayName}`);
|
|
19008
|
+
cliLogger.dim(` Source: ${sourceDir}`);
|
|
19009
|
+
for (const sibling of findBundledSiblingSkills(sourceDir)) cliLogger.dim(` Also installs skill: ${sibling.name}`);
|
|
19010
|
+
cliLogger.dim(" Package script: doctor (or react-doctor if doctor exists)");
|
|
19011
|
+
cliLogger.dim(" Dev dependency: react-doctor");
|
|
19012
|
+
if (shouldInstallGitHook) cliLogger.dim(` Git hook: ${gitHookPath}`);
|
|
19013
|
+
if (shouldInstallAgentHooks) cliLogger.dim(" Agent hooks: Claude Code / Cursor when selected");
|
|
19014
|
+
if (shouldInstallWorkflow) cliLogger.dim(` GitHub Actions workflow: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
19015
|
+
return;
|
|
19016
|
+
}
|
|
19017
|
+
const installSpinner = spinner(`Installing ${SKILL_NAME} skill...`).start();
|
|
19018
|
+
try {
|
|
19019
|
+
const installResult = await installSkillsFromSource({
|
|
19020
|
+
source: sourceDir,
|
|
19021
|
+
agents: selectedAgents,
|
|
19022
|
+
cwd: projectRoot,
|
|
19023
|
+
mode: "copy"
|
|
19024
|
+
});
|
|
19025
|
+
if (installResult.skills.length === 0) throw new Error(`Could not parse ${SKILL_MANIFEST_FILE} for ${SKILL_NAME} (missing or invalid frontmatter).`);
|
|
19026
|
+
if (installResult.failed.length > 0) throw new Error(installResult.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
19027
|
+
installSpinner.succeed(`${SKILL_NAME} skill installed for ${selectedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
19028
|
+
} catch (error) {
|
|
19029
|
+
installSpinner.fail(`Failed to install ${SKILL_NAME} skill.`);
|
|
19030
|
+
throw error;
|
|
19031
|
+
}
|
|
19032
|
+
try {
|
|
19033
|
+
const installedSiblingSkills = await installBundledSiblingSkills(sourceDir, selectedAgents, projectRoot);
|
|
19034
|
+
if (installedSiblingSkills.length > 0) cliLogger.dim(` Also installed the ${installedSiblingSkills.join(", ")} skill.`);
|
|
19035
|
+
} catch {
|
|
19036
|
+
cliLogger.dim(" Skipped bundled sibling skills (install error).");
|
|
19037
|
+
}
|
|
19038
|
+
const dependencyResult = await installReactDoctorPackageSetup(projectRoot, options.installDependencyRunner);
|
|
19039
|
+
if (shouldInstallGitHook && gitHookTarget !== null && gitHookTarget !== void 0) {
|
|
19040
|
+
const hookSpinner = spinner("Installing React Doctor pre-commit hook...").start();
|
|
19041
|
+
try {
|
|
19042
|
+
const hookResult = installReactDoctorGitHook({
|
|
19043
|
+
hookPath: gitHookTarget.hookPath,
|
|
19044
|
+
projectRoot: gitHookTarget.runnerRoot,
|
|
19045
|
+
kind: gitHookTarget.kind,
|
|
19046
|
+
hooksPathConfig: gitHookTarget.hooksPathConfig
|
|
19047
|
+
});
|
|
19048
|
+
hookSpinner.succeed(formatGitHookInstallMessage(hookResult));
|
|
19049
|
+
recordCount(METRIC.installGitHook, 1, { kind: hookResult.kind });
|
|
19050
|
+
} catch (error) {
|
|
19051
|
+
hookSpinner.fail("Failed to install React Doctor pre-commit hook.");
|
|
19052
|
+
throw error;
|
|
19053
|
+
}
|
|
19054
|
+
}
|
|
19055
|
+
if (shouldInstallAgentHooks) {
|
|
19056
|
+
const hookSpinner = spinner("Installing React Doctor agent hooks...").start();
|
|
19057
|
+
try {
|
|
19058
|
+
const hookResult = installReactDoctorAgentHooks({
|
|
19059
|
+
projectRoot,
|
|
19060
|
+
agents: selectedAgents
|
|
19061
|
+
});
|
|
19062
|
+
if (hookResult.installedAgents.length === 0) hookSpinner.succeed("No supported native agent hook targets selected.");
|
|
19063
|
+
else {
|
|
19064
|
+
hookSpinner.succeed(`React Doctor agent hooks installed for ${hookResult.installedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
19065
|
+
recordCount(METRIC.installAgentHooks, 1, { agentsCount: hookResult.installedAgents.length });
|
|
19066
|
+
}
|
|
19067
|
+
} catch (error) {
|
|
19068
|
+
hookSpinner.fail("Failed to install React Doctor agent hooks.");
|
|
19069
|
+
throw error;
|
|
19070
|
+
}
|
|
19071
|
+
}
|
|
19072
|
+
let didInstallWorkflow = false;
|
|
19073
|
+
if (shouldInstallWorkflow) didInstallWorkflow = reportWorkflowResult(spinner("Adding GitHub Actions workflow...").start(), installReactDoctorWorkflow(projectRoot), projectRoot);
|
|
19074
|
+
recordCount(METRIC.installCompleted, 1, {
|
|
19075
|
+
agentsCount: selectedAgents.length,
|
|
19076
|
+
gitHook: shouldInstallGitHook,
|
|
19077
|
+
agentHooks: shouldInstallAgentHooks,
|
|
19078
|
+
workflow: didInstallWorkflow,
|
|
19079
|
+
dependencyStatus: dependencyResult.dependencyStatus,
|
|
19080
|
+
packageManager: detectPackageManager(projectRoot)
|
|
19081
|
+
});
|
|
19082
|
+
for (const agent of selectedAgents) recordCount(METRIC.installAgent, 1, { agent });
|
|
19083
|
+
};
|
|
19084
|
+
//#endregion
|
|
19085
|
+
//#region src/cli/utils/hash-project-root.ts
|
|
19086
|
+
const hashProjectRoot = (projectRoot) => createHash("sha256").update(path$1.resolve(projectRoot)).digest("hex");
|
|
19087
|
+
//#endregion
|
|
19088
|
+
//#region src/cli/utils/action-upgrade-prompt.ts
|
|
19089
|
+
const GLOBAL_CONFIG_PROJECT_NAME$1 = "react-doctor";
|
|
19090
|
+
const getActionUpgradeStore = (options = {}) => new Conf({
|
|
19091
|
+
projectName: GLOBAL_CONFIG_PROJECT_NAME$1,
|
|
19092
|
+
cwd: options.cwd
|
|
19093
|
+
});
|
|
19094
|
+
const hasHandledActionUpgrade = (projectRoot, storeOptions = {}) => {
|
|
19095
|
+
try {
|
|
19096
|
+
const upgrades = getActionUpgradeStore(storeOptions).get("actionUpgrades", {});
|
|
19097
|
+
return Boolean(upgrades[hashProjectRoot(projectRoot)]);
|
|
19098
|
+
} catch {
|
|
19099
|
+
return true;
|
|
19100
|
+
}
|
|
19101
|
+
};
|
|
19102
|
+
const recordActionUpgradeDecision = (projectRoot, outcome, storeOptions = {}) => {
|
|
19103
|
+
try {
|
|
19104
|
+
const store = getActionUpgradeStore(storeOptions);
|
|
19105
|
+
const upgrades = store.get("actionUpgrades", {});
|
|
19106
|
+
store.set("actionUpgrades", {
|
|
19107
|
+
...upgrades,
|
|
19108
|
+
[hashProjectRoot(projectRoot)]: {
|
|
19109
|
+
rootDirectory: path$1.resolve(projectRoot),
|
|
19110
|
+
outcome,
|
|
19111
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
19112
|
+
}
|
|
19113
|
+
});
|
|
19114
|
+
return true;
|
|
19115
|
+
} catch {
|
|
19116
|
+
return false;
|
|
19117
|
+
}
|
|
19118
|
+
};
|
|
19119
|
+
//#endregion
|
|
19120
|
+
//#region src/cli/utils/install-skill-for-agent.ts
|
|
19121
|
+
const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
|
|
19122
|
+
const source = getSkillSourceDirectory();
|
|
19123
|
+
if (!fs$1.existsSync(path$1.join(source, SKILL_MANIFEST_FILE))) return false;
|
|
19124
|
+
const result = await installSkillsFromSource({
|
|
19125
|
+
source,
|
|
19126
|
+
agents: [agent],
|
|
19127
|
+
cwd: projectRoot,
|
|
19128
|
+
mode: "copy"
|
|
19129
|
+
});
|
|
19130
|
+
return result.skills.length > 0 && result.failed.length === 0;
|
|
19131
|
+
};
|
|
19132
|
+
//#endregion
|
|
19133
|
+
//#region src/cli/utils/open-url.ts
|
|
19134
|
+
const resolveOpenCommand = (url) => {
|
|
19135
|
+
if (process$1.platform === "darwin") return {
|
|
19136
|
+
command: "open",
|
|
19137
|
+
args: [url]
|
|
19138
|
+
};
|
|
19139
|
+
if (process$1.platform === "win32") return {
|
|
19140
|
+
command: "cmd",
|
|
19141
|
+
args: [
|
|
19142
|
+
"/c",
|
|
19143
|
+
"start",
|
|
19144
|
+
"",
|
|
19145
|
+
url
|
|
19146
|
+
]
|
|
19147
|
+
};
|
|
19148
|
+
return {
|
|
19149
|
+
command: "xdg-open",
|
|
19150
|
+
args: [url]
|
|
19151
|
+
};
|
|
19152
|
+
};
|
|
19153
|
+
const openUrl = (url) => {
|
|
19154
|
+
try {
|
|
19155
|
+
const { command, args } = resolveOpenCommand(url);
|
|
19156
|
+
const child = spawn(command, args, {
|
|
19157
|
+
detached: true,
|
|
19158
|
+
stdio: "ignore"
|
|
19159
|
+
});
|
|
19160
|
+
child.on("error", () => {});
|
|
19161
|
+
child.unref();
|
|
19162
|
+
return true;
|
|
19163
|
+
} catch {
|
|
19164
|
+
return false;
|
|
19165
|
+
}
|
|
19166
|
+
};
|
|
19167
|
+
//#endregion
|
|
19168
|
+
//#region src/cli/utils/open-workflow-pull-request.ts
|
|
19169
|
+
const NEW_BRANCH_PREFIX = "react-doctor/add-github-actions";
|
|
19170
|
+
const DEFAULT_COMMIT_MESSAGE = "ci: add React Doctor GitHub Actions workflow";
|
|
19171
|
+
const DEFAULT_PR_TITLE = "Add React Doctor to GitHub Actions";
|
|
19172
|
+
const DEFAULT_PR_BODY = `Adds a [React Doctor](https://www.react.doctor) scan to every pull request and every push to the default branch. The workflow file is documented inline.
|
|
19173
|
+
|
|
19174
|
+
Docs: https://www.react.doctor/ci`;
|
|
19175
|
+
const execFileAsync = promisify(execFile);
|
|
19176
|
+
const run = async (command, args, cwd) => {
|
|
19177
|
+
try {
|
|
19178
|
+
const { stdout, stderr } = await execFileAsync(command, [...args], {
|
|
19179
|
+
cwd,
|
|
19180
|
+
encoding: "utf8"
|
|
19181
|
+
});
|
|
19182
|
+
return {
|
|
19183
|
+
success: true,
|
|
19184
|
+
stdout: stdout.trim(),
|
|
19185
|
+
stderr: stderr.trim()
|
|
19186
|
+
};
|
|
19187
|
+
} catch (error) {
|
|
19188
|
+
const failure = error;
|
|
19189
|
+
return {
|
|
19190
|
+
success: false,
|
|
19191
|
+
stdout: (failure.stdout ?? "").trim(),
|
|
19192
|
+
stderr: (failure.stderr ?? "").trim()
|
|
19193
|
+
};
|
|
19194
|
+
}
|
|
19195
|
+
};
|
|
19196
|
+
const detectDefaultBranch = async (cwd) => {
|
|
19197
|
+
const symRef = await run("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], cwd);
|
|
19198
|
+
if (symRef.success) {
|
|
19199
|
+
const branchMatch = symRef.stdout.match(/refs\/remotes\/origin\/(.+)$/);
|
|
19200
|
+
if (branchMatch) return branchMatch[1];
|
|
19201
|
+
}
|
|
19202
|
+
if ((await run("git", [
|
|
19203
|
+
"rev-parse",
|
|
19204
|
+
"--verify",
|
|
19205
|
+
"origin/main"
|
|
19206
|
+
], cwd)).success) return "main";
|
|
19207
|
+
if ((await run("git", [
|
|
19208
|
+
"rev-parse",
|
|
19209
|
+
"--verify",
|
|
19210
|
+
"origin/master"
|
|
19211
|
+
], cwd)).success) return "master";
|
|
19212
|
+
return null;
|
|
19213
|
+
};
|
|
19214
|
+
const findUniqueBranchName = async (cwd) => {
|
|
19215
|
+
if (!(await run("git", [
|
|
19216
|
+
"rev-parse",
|
|
19217
|
+
"--verify",
|
|
19218
|
+
NEW_BRANCH_PREFIX
|
|
19219
|
+
], cwd)).success) return NEW_BRANCH_PREFIX;
|
|
19220
|
+
return `${NEW_BRANCH_PREFIX}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 16).replace(/[-:T]/g, "")}`;
|
|
19221
|
+
};
|
|
19222
|
+
const openWorkflowPullRequest = async (params) => {
|
|
19223
|
+
const workflowPath = path$1.resolve(params.workflowPath);
|
|
19224
|
+
const commitMessage = params.commitMessage ?? DEFAULT_COMMIT_MESSAGE;
|
|
19225
|
+
const prTitle = params.prTitle ?? DEFAULT_PR_TITLE;
|
|
19226
|
+
const prBody = params.prBody ?? DEFAULT_PR_BODY;
|
|
19227
|
+
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
19228
|
+
if (!repoRootProbe.success) return {
|
|
19229
|
+
status: "not-attempted",
|
|
19230
|
+
reason: "not-a-git-repo"
|
|
19231
|
+
};
|
|
19232
|
+
const cwd = repoRootProbe.stdout;
|
|
19233
|
+
if (!isCommandAvailable("gh")) return {
|
|
19234
|
+
status: "not-attempted",
|
|
19235
|
+
reason: "gh-not-installed"
|
|
19236
|
+
};
|
|
19237
|
+
if (!(await run("gh", ["auth", "status"], cwd)).success) return {
|
|
19238
|
+
status: "not-attempted",
|
|
19239
|
+
reason: "gh-not-authenticated"
|
|
19240
|
+
};
|
|
19241
|
+
const defaultBranch = await detectDefaultBranch(cwd);
|
|
19242
|
+
if (!defaultBranch) return {
|
|
19243
|
+
status: "not-attempted",
|
|
19244
|
+
reason: "no-default-branch"
|
|
19245
|
+
};
|
|
19246
|
+
const previousBranchProbe = await run("git", [
|
|
19247
|
+
"rev-parse",
|
|
19248
|
+
"--abbrev-ref",
|
|
19249
|
+
"HEAD"
|
|
19250
|
+
], cwd);
|
|
19251
|
+
if (!previousBranchProbe.success || previousBranchProbe.stdout === "HEAD") return {
|
|
19252
|
+
status: "not-attempted",
|
|
19253
|
+
reason: "detached-head"
|
|
19254
|
+
};
|
|
19255
|
+
const previousBranch = previousBranchProbe.stdout;
|
|
19256
|
+
await run("git", [
|
|
19257
|
+
"fetch",
|
|
19258
|
+
"origin",
|
|
19259
|
+
defaultBranch
|
|
19260
|
+
], cwd);
|
|
19261
|
+
const newBranch = await findUniqueBranchName(cwd);
|
|
19262
|
+
if (!(await run("git", [
|
|
19263
|
+
"checkout",
|
|
19264
|
+
"-b",
|
|
19265
|
+
newBranch,
|
|
19266
|
+
`origin/${defaultBranch}`
|
|
19267
|
+
], cwd)).success) return {
|
|
19268
|
+
status: "not-attempted",
|
|
19269
|
+
reason: "checkout-failed"
|
|
19270
|
+
};
|
|
19271
|
+
const restoreToPreviousBranch = async (deleteNewBranch) => {
|
|
19272
|
+
await run("git", ["checkout", previousBranch], cwd);
|
|
19273
|
+
if (deleteNewBranch) await run("git", [
|
|
19274
|
+
"branch",
|
|
19275
|
+
"-D",
|
|
19276
|
+
newBranch
|
|
19277
|
+
], cwd);
|
|
19278
|
+
};
|
|
19279
|
+
if (!(await run("git", [
|
|
19280
|
+
"add",
|
|
19281
|
+
"--",
|
|
19282
|
+
path$1.relative(cwd, workflowPath)
|
|
19283
|
+
], cwd)).success) {
|
|
19284
|
+
await restoreToPreviousBranch(true);
|
|
19285
|
+
return {
|
|
19286
|
+
status: "not-attempted",
|
|
19287
|
+
reason: "git-add-failed"
|
|
19288
|
+
};
|
|
19449
19289
|
}
|
|
19450
|
-
|
|
19451
|
-
|
|
19452
|
-
|
|
19453
|
-
|
|
19454
|
-
|
|
19455
|
-
|
|
19456
|
-
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
selected: true
|
|
19461
|
-
}], ...canInstallNativeAgentHooks(selectedAgents) ? [{
|
|
19462
|
-
title: "Agent hooks",
|
|
19463
|
-
description: "Ask Claude Code or Cursor to scan after code edits",
|
|
19464
|
-
value: SETUP_OPTION_AGENT_HOOKS,
|
|
19465
|
-
selected: Boolean(options.agentHooks)
|
|
19466
|
-
}] : []];
|
|
19467
|
-
const setupChoices = setupActionChoices.length === 0 ? [] : [{
|
|
19468
|
-
title: "Skip optional setup",
|
|
19469
|
-
description: "Install only the agent skill and package setup",
|
|
19470
|
-
value: SETUP_OPTION_SKIP,
|
|
19471
|
-
selected: false
|
|
19472
|
-
}, ...setupActionChoices];
|
|
19473
|
-
if (setupChoices.length > 0 && !options.dryRun) cliLogger.break();
|
|
19474
|
-
const selectedSetupOptions = skipPrompts || setupChoices.length === 0 ? [] : (await prompt({
|
|
19475
|
-
type: "multiselect",
|
|
19476
|
-
name: "setupOptions",
|
|
19477
|
-
message: "Select additional React Doctor setup:",
|
|
19478
|
-
choices: setupChoices,
|
|
19479
|
-
instructions: false
|
|
19480
|
-
}, promptOptions)).setupOptions ?? [];
|
|
19481
|
-
const selectedSetupActions = selectedSetupOptions.filter((setupOption) => setupOption !== SETUP_OPTION_SKIP);
|
|
19482
|
-
const didSkipOptionalSetup = selectedSetupActions.length === 0 && selectedSetupOptions.includes(SETUP_OPTION_SKIP);
|
|
19483
|
-
const shouldInstallGitHook = gitHookPath != null && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_GIT_HOOK));
|
|
19484
|
-
const shouldInstallAgentHooks = Boolean(options.agentHooks) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_AGENT_HOOKS);
|
|
19485
|
-
if (!options.dryRun) {
|
|
19486
|
-
if (shouldInstallGitHook && gitHookTarget !== null && gitHookTarget !== void 0) installReactDoctorGitHookStep(gitHookTarget);
|
|
19487
|
-
if (shouldInstallAgentHooks) installReactDoctorAgentHooksStep(projectRoot, selectedAgents);
|
|
19290
|
+
if (!(await run("git", [
|
|
19291
|
+
"commit",
|
|
19292
|
+
"-m",
|
|
19293
|
+
commitMessage
|
|
19294
|
+
], cwd)).success) {
|
|
19295
|
+
await restoreToPreviousBranch(true);
|
|
19296
|
+
return {
|
|
19297
|
+
status: "not-attempted",
|
|
19298
|
+
reason: "git-commit-failed"
|
|
19299
|
+
};
|
|
19488
19300
|
}
|
|
19489
|
-
if (
|
|
19490
|
-
|
|
19491
|
-
|
|
19492
|
-
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
|
|
19500
|
-
return;
|
|
19301
|
+
if (!(await run("git", [
|
|
19302
|
+
"push",
|
|
19303
|
+
"-u",
|
|
19304
|
+
"origin",
|
|
19305
|
+
newBranch
|
|
19306
|
+
], cwd)).success) {
|
|
19307
|
+
await restoreToPreviousBranch(true);
|
|
19308
|
+
return {
|
|
19309
|
+
status: "not-attempted",
|
|
19310
|
+
reason: "git-push-failed"
|
|
19311
|
+
};
|
|
19501
19312
|
}
|
|
19502
|
-
|
|
19503
|
-
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19313
|
+
const prCreate = await run("gh", [
|
|
19314
|
+
"pr",
|
|
19315
|
+
"create",
|
|
19316
|
+
"--title",
|
|
19317
|
+
prTitle,
|
|
19318
|
+
"--body",
|
|
19319
|
+
prBody,
|
|
19320
|
+
"--base",
|
|
19321
|
+
defaultBranch,
|
|
19322
|
+
"--head",
|
|
19323
|
+
newBranch
|
|
19324
|
+
], cwd);
|
|
19325
|
+
await restoreToPreviousBranch(false);
|
|
19326
|
+
if (!prCreate.success) return {
|
|
19327
|
+
status: "branch-pushed",
|
|
19328
|
+
branch: newBranch
|
|
19329
|
+
};
|
|
19330
|
+
return {
|
|
19331
|
+
status: "pr-opened",
|
|
19332
|
+
url: prCreate.stdout.split(/\r?\n/).filter(Boolean).pop() ?? ""
|
|
19333
|
+
};
|
|
19511
19334
|
};
|
|
19512
|
-
|
|
19513
|
-
|
|
19514
|
-
const
|
|
19515
|
-
|
|
19516
|
-
|
|
19517
|
-
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
19521
|
-
mode: "copy"
|
|
19522
|
-
});
|
|
19523
|
-
return result.skills.length > 0 && result.failed.length === 0;
|
|
19335
|
+
const stageWorkflowFile = async (params) => {
|
|
19336
|
+
const workflowPath = path$1.resolve(params.workflowPath);
|
|
19337
|
+
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
19338
|
+
if (!repoRootProbe.success) return false;
|
|
19339
|
+
return (await run("git", [
|
|
19340
|
+
"add",
|
|
19341
|
+
"--",
|
|
19342
|
+
path$1.relative(repoRootProbe.stdout, workflowPath)
|
|
19343
|
+
], repoRootProbe.stdout)).success;
|
|
19524
19344
|
};
|
|
19525
19345
|
//#endregion
|
|
19526
19346
|
//#region src/cli/utils/launch-agent.ts
|
|
@@ -19611,6 +19431,9 @@ const copyToClipboard = (text) => {
|
|
|
19611
19431
|
};
|
|
19612
19432
|
//#endregion
|
|
19613
19433
|
//#region src/cli/utils/handoff-to-agent.ts
|
|
19434
|
+
const CI_YES_CHOICE = "ci-yes";
|
|
19435
|
+
const CI_LEARN_MORE_CHOICE = "ci-learn-more";
|
|
19436
|
+
const CI_NO_CHOICE = "ci-no";
|
|
19614
19437
|
const CLIPBOARD_CHOICE = "clipboard";
|
|
19615
19438
|
const SKIP_CHOICE = "skip";
|
|
19616
19439
|
const printPayload = (payload) => {
|
|
@@ -19619,11 +19442,59 @@ const printPayload = (payload) => {
|
|
|
19619
19442
|
cliLogger.log(payload);
|
|
19620
19443
|
cliLogger.log(highlighter.dim("──────────────────────"));
|
|
19621
19444
|
};
|
|
19445
|
+
const setUpGitHubActions = async (rootDirectory) => {
|
|
19446
|
+
const projectRoot = findNearestPackageDirectory(rootDirectory) ?? rootDirectory;
|
|
19447
|
+
try {
|
|
19448
|
+
installReactDoctorScriptStep(projectRoot);
|
|
19449
|
+
} catch {}
|
|
19450
|
+
const workflowSpinner = spinner("Adding GitHub Actions workflow...").start();
|
|
19451
|
+
const workflowResult = installReactDoctorWorkflow(projectRoot);
|
|
19452
|
+
reportWorkflowResult(workflowSpinner, workflowResult, projectRoot);
|
|
19453
|
+
cliLogger.break();
|
|
19454
|
+
if (workflowResult.status === "failed") {
|
|
19455
|
+
cliLogger.log(` Couldn't set up GitHub Actions automatically. Follow the guide at ${highlighter.info(CI_URL)}`);
|
|
19456
|
+
return;
|
|
19457
|
+
}
|
|
19458
|
+
if (workflowResult.status === "created") {
|
|
19459
|
+
const pullRequestSpinner = spinner("Opening a pull request for review...").start();
|
|
19460
|
+
const pullRequestResult = await openWorkflowPullRequest({ workflowPath: workflowResult.workflowPath });
|
|
19461
|
+
if (pullRequestResult.status === "pr-opened") pullRequestSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
|
|
19462
|
+
else if (pullRequestResult.status === "branch-pushed") pullRequestSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
|
|
19463
|
+
else {
|
|
19464
|
+
pullRequestSpinner.stop();
|
|
19465
|
+
if (await stageWorkflowFile({ workflowPath: workflowResult.workflowPath })) cliLogger.log(` Staged the workflow file. Commit it to start scanning every pull request.`);
|
|
19466
|
+
else cliLogger.log(" React Doctor will now scan every new pull request automatically.");
|
|
19467
|
+
}
|
|
19468
|
+
}
|
|
19469
|
+
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
19470
|
+
};
|
|
19471
|
+
const UPGRADE_YES_CHOICE = "upgrade-yes";
|
|
19472
|
+
const UPGRADE_NO_CHOICE = "upgrade-no";
|
|
19622
19473
|
const UPGRADE_COMMIT_MESSAGE = "ci: upgrade React Doctor GitHub Action to v2";
|
|
19623
19474
|
const UPGRADE_PR_TITLE = "Upgrade React Doctor Action to v2";
|
|
19624
19475
|
const UPGRADE_PR_BODY = `Bumps the React Doctor GitHub Actions workflow to the action's latest major, \`millionco/react-doctor@v2\`.
|
|
19625
19476
|
|
|
19626
19477
|
Docs: https://www.react.doctor/ci`;
|
|
19478
|
+
const askUpgradeActionVersion = async () => {
|
|
19479
|
+
const { upgradeChoice } = await prompts({
|
|
19480
|
+
type: "select",
|
|
19481
|
+
name: "upgradeChoice",
|
|
19482
|
+
message: "A new major of the React Doctor Action (v2) is out. Upgrade this repo's workflow?",
|
|
19483
|
+
hint: " ",
|
|
19484
|
+
choices: [{
|
|
19485
|
+
title: "Yes (recommended)",
|
|
19486
|
+
description: "Open a PR bumping the workflow to millionco/react-doctor@v2",
|
|
19487
|
+
value: UPGRADE_YES_CHOICE
|
|
19488
|
+
}, {
|
|
19489
|
+
title: "No, thanks",
|
|
19490
|
+
description: "Keep @v1 — won't ask again for this repo",
|
|
19491
|
+
value: UPGRADE_NO_CHOICE
|
|
19492
|
+
}],
|
|
19493
|
+
initial: 0
|
|
19494
|
+
}, { onCancel: () => true });
|
|
19495
|
+
if (upgradeChoice === void 0) return "cancel";
|
|
19496
|
+
return upgradeChoice === UPGRADE_YES_CHOICE ? "yes" : "no";
|
|
19497
|
+
};
|
|
19627
19498
|
const upgradeGitHubActionsWorkflow = async (workflow) => {
|
|
19628
19499
|
const { content, changed } = upgradeWorkflowActionToV2(workflow.content);
|
|
19629
19500
|
if (!changed) return false;
|
|
@@ -19668,6 +19539,46 @@ const maybeOfferActionUpgrade = async (projectRoot) => {
|
|
|
19668
19539
|
}
|
|
19669
19540
|
if (await upgradeGitHubActionsWorkflow(workflow)) recordActionUpgradeDecision(projectRoot, "accepted");
|
|
19670
19541
|
};
|
|
19542
|
+
const SGR_BOLD_OFF = "\x1B[22m";
|
|
19543
|
+
const ciQuestionMessage = [
|
|
19544
|
+
"Add React Doctor to GitHub Actions?",
|
|
19545
|
+
`${SGR_BOLD_OFF} ${highlighter.dim("Scan every pull request to prevent new React issues while you fix the backlog.")}`,
|
|
19546
|
+
`${SGR_BOLD_OFF} ${highlighter.dim(`Used by teams at ${CI_TRUST_COMPANIES}.`)}`
|
|
19547
|
+
].join("\n");
|
|
19548
|
+
const askAddToGitHubActions = async () => {
|
|
19549
|
+
while (true) {
|
|
19550
|
+
const { ciChoice } = await prompts({
|
|
19551
|
+
type: "select",
|
|
19552
|
+
name: "ciChoice",
|
|
19553
|
+
message: ciQuestionMessage,
|
|
19554
|
+
hint: " ",
|
|
19555
|
+
choices: [
|
|
19556
|
+
{
|
|
19557
|
+
title: "Yes (recommended)",
|
|
19558
|
+
description: "Adds the workflow file and a doctor package script",
|
|
19559
|
+
value: CI_YES_CHOICE
|
|
19560
|
+
},
|
|
19561
|
+
{
|
|
19562
|
+
title: "Learn more",
|
|
19563
|
+
description: highlighter.info(CI_URL),
|
|
19564
|
+
value: CI_LEARN_MORE_CHOICE
|
|
19565
|
+
},
|
|
19566
|
+
{
|
|
19567
|
+
title: "No, thanks",
|
|
19568
|
+
description: "Continue to the agent handoff",
|
|
19569
|
+
value: CI_NO_CHOICE
|
|
19570
|
+
}
|
|
19571
|
+
],
|
|
19572
|
+
initial: 0
|
|
19573
|
+
}, { onCancel: () => true });
|
|
19574
|
+
if (ciChoice === void 0) return "cancel";
|
|
19575
|
+
if (ciChoice === CI_YES_CHOICE) return "yes";
|
|
19576
|
+
if (ciChoice === CI_NO_CHOICE) return "no";
|
|
19577
|
+
const opened = openUrl(CI_URL);
|
|
19578
|
+
cliLogger.log(opened ? `Opened ${highlighter.info(CI_URL)} in your browser.` : `Visit ${highlighter.info(CI_URL)} to learn more.`);
|
|
19579
|
+
cliLogger.break();
|
|
19580
|
+
}
|
|
19581
|
+
};
|
|
19671
19582
|
const detectLaunchableAgents = async () => {
|
|
19672
19583
|
const detected = new Set(await detectAvailableAgents());
|
|
19673
19584
|
return Object.keys(CLI_AGENT_BINARIES).filter((agentId) => detected.has(agentId) && isCommandAvailable(CLI_AGENT_BINARIES[agentId]));
|
|
@@ -19684,7 +19595,7 @@ const handoffToAgent = async (input) => {
|
|
|
19684
19595
|
});
|
|
19685
19596
|
if (ciOutcome === "cancel") return;
|
|
19686
19597
|
if (ciOutcome === "yes") {
|
|
19687
|
-
await setUpGitHubActions(
|
|
19598
|
+
await setUpGitHubActions(input.rootDirectory);
|
|
19688
19599
|
cliLogger.break();
|
|
19689
19600
|
}
|
|
19690
19601
|
} else await maybeOfferActionUpgrade(projectRootForCi);
|
|
@@ -19835,14 +19746,6 @@ const HAPPY_FACE_LINES = [
|
|
|
19835
19746
|
"│ ▽ │",
|
|
19836
19747
|
"└─────┘"
|
|
19837
19748
|
];
|
|
19838
|
-
const FACE_INDENT = " ";
|
|
19839
|
-
const FACE_PREFIX_WIDTH = 2 + (HAPPY_FACE_LINES[0]?.length ?? 0) + 2;
|
|
19840
|
-
const clampToColumns = (text, maxColumns) => {
|
|
19841
|
-
if (maxColumns <= 0) return "";
|
|
19842
|
-
if (text.length <= maxColumns) return text;
|
|
19843
|
-
if (maxColumns === 1) return "…";
|
|
19844
|
-
return `${text.slice(0, maxColumns - 1).trimEnd()}…`;
|
|
19845
|
-
};
|
|
19846
19749
|
const typeLine = (linePrefix, text, style, charDelayMs) => Effect.gen(function* () {
|
|
19847
19750
|
const characters = [...text];
|
|
19848
19751
|
for (let length = 1; length <= characters.length; length += 1) {
|
|
@@ -19856,17 +19759,13 @@ const playWelcomeScene = (options = {}) => Effect.gen(function* () {
|
|
|
19856
19759
|
const interLineDelayMs = 250 / speedMultiplier;
|
|
19857
19760
|
const explanationHoldMs = WELCOME_EXPLANATION_HOLD_MS / speedMultiplier;
|
|
19858
19761
|
const face = HAPPY_FACE_LINES.map((line) => highlighter.success(line));
|
|
19859
|
-
const mouthPrefix =
|
|
19860
|
-
|
|
19861
|
-
const availableTextColumns = terminalColumns && terminalColumns > 0 ? Math.max(0, terminalColumns - FACE_PREFIX_WIDTH - 1) : Number.POSITIVE_INFINITY;
|
|
19862
|
-
const greeting = clampToColumns("Welcome to React Doctor", availableTextColumns);
|
|
19863
|
-
const tagline = clampToColumns("I diagnose your React code for bugs, security & performance.", availableTextColumns);
|
|
19864
|
-
yield* writeStdout(`\n${face.map((line) => `${FACE_INDENT}${line}`).join("\n")}\n`);
|
|
19762
|
+
const mouthPrefix = ` ${face[2] ?? ""} `;
|
|
19763
|
+
yield* writeStdout(`\n${face.map((line) => ` ${line}`).join("\n")}\n`);
|
|
19865
19764
|
yield* writeStdout("\x1B[3A");
|
|
19866
|
-
yield* typeLine(
|
|
19765
|
+
yield* typeLine(` ${face[1] ?? ""} `, "Welcome to React Doctor", (fragment) => highlighter.bold(fragment), charDelayMs);
|
|
19867
19766
|
yield* Effect.sleep(interLineDelayMs);
|
|
19868
19767
|
yield* writeStdout("\x1B[1B");
|
|
19869
|
-
yield* typeLine(mouthPrefix,
|
|
19768
|
+
yield* typeLine(mouthPrefix, "I diagnose your React code for bugs, security & performance.", (fragment) => highlighter.dim(fragment), charDelayMs);
|
|
19870
19769
|
yield* Effect.sleep(explanationHoldMs);
|
|
19871
19770
|
yield* writeStdout("\x1B[3A\r\x1B[0J");
|
|
19872
19771
|
});
|
|
@@ -21622,4 +21521,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
|
|
|
21622
21521
|
export {};
|
|
21623
21522
|
|
|
21624
21523
|
//# sourceMappingURL=cli.js.map
|
|
21625
|
-
//# debugId=
|
|
21524
|
+
//# debugId=1486eaee-ed07-5eef-a9d7-51293140e237
|