react-doctor 0.4.1-dev.e181ac1 → 0.4.2-dev.155cde2
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/LICENSE +1 -1
- package/README.md +4 -23
- package/dist/cli.js +1383 -1282
- package/dist/index.js +2 -2
- package/dist/lsp.js +3 -3
- package/package.json +7 -7
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]="92822f58-92ef-58d5-8850-2746c0b48fc0")}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,6 +6361,7 @@ 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";
|
|
6364
6365
|
const DOCS_URL = "https://react.doctor/docs";
|
|
6365
6366
|
const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
|
|
6366
6367
|
const FETCH_TIMEOUT_MS = 1e4;
|
|
@@ -12247,7 +12248,7 @@ const makeNoopConsole = () => ({
|
|
|
12247
12248
|
});
|
|
12248
12249
|
//#endregion
|
|
12249
12250
|
//#region src/cli/utils/version.ts
|
|
12250
|
-
const VERSION = "0.4.
|
|
12251
|
+
const VERSION = "0.4.2-dev.155cde2";
|
|
12251
12252
|
//#endregion
|
|
12252
12253
|
//#region src/cli/utils/json-mode.ts
|
|
12253
12254
|
let context = null;
|
|
@@ -12605,13 +12606,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12605
12606
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12606
12607
|
* standard `SENTRY_RELEASE` override.
|
|
12607
12608
|
*/
|
|
12608
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.
|
|
12609
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.2-dev.155cde2`;
|
|
12609
12610
|
/**
|
|
12610
12611
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12611
12612
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12612
12613
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12613
12614
|
*/
|
|
12614
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.
|
|
12615
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.2-dev.155cde2") ? "development" : "production");
|
|
12615
12616
|
/**
|
|
12616
12617
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12617
12618
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -16473,8 +16474,22 @@ const buildCodeFrame = (input) => {
|
|
|
16473
16474
|
});
|
|
16474
16475
|
};
|
|
16475
16476
|
//#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
|
|
16476
16490
|
//#region src/cli/utils/build-section-divider.ts
|
|
16477
|
-
const
|
|
16491
|
+
const DIVIDER_INDENT = " ";
|
|
16492
|
+
const buildSectionDivider = () => highlighter.dim(`${DIVIDER_INDENT}${"─".repeat(resolveMeasureWidth(2))}`);
|
|
16478
16493
|
//#endregion
|
|
16479
16494
|
//#region src/cli/utils/indent-multiline-text.ts
|
|
16480
16495
|
const indentMultilineText = (text, linePrefix) => text.split("\n").map((lineText) => `${linePrefix}${lineText}`).join("\n");
|
|
@@ -16634,7 +16649,10 @@ const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame
|
|
|
16634
16649
|
endLine: isMultiSite ? cluster.endLine : void 0,
|
|
16635
16650
|
rootDirectory: resolveSourceRoot(lead)
|
|
16636
16651
|
}) : null;
|
|
16637
|
-
if (codeFrame)
|
|
16652
|
+
if (codeFrame) {
|
|
16653
|
+
const boxInnerWidth = resolveMeasureWidth(8);
|
|
16654
|
+
lines.push(indentMultilineText(boxText(codeFrame, boxInnerWidth), TOP_ERROR_DETAIL_INDENT));
|
|
16655
|
+
}
|
|
16638
16656
|
const seenHints = /* @__PURE__ */ new Set();
|
|
16639
16657
|
for (const diagnostic of cluster.diagnostics) if (diagnostic.suppressionHint && !seenHints.has(diagnostic.suppressionHint)) {
|
|
16640
16658
|
seenHints.add(diagnostic.suppressionHint);
|
|
@@ -16652,8 +16670,8 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
|
|
|
16652
16670
|
const learnMoreLine = formatLearnMoreLine(representative);
|
|
16653
16671
|
if (learnMoreLine) lines.push(`${TOP_ERROR_DETAIL_INDENT}${highlighter.info(learnMoreLine)}`);
|
|
16654
16672
|
}
|
|
16655
|
-
if (!renderEverySite) for (const explanationLine of wrapTextToWidth(representative.message,
|
|
16656
|
-
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`,
|
|
16673
|
+
if (!renderEverySite) for (const explanationLine of wrapTextToWidth(representative.message, resolveMeasureWidth(4), { breakLongWords: false })) lines.push(`${TOP_ERROR_DETAIL_INDENT}${explanationLine}`);
|
|
16674
|
+
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`, resolveMeasureWidth(4), { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${fixLine}`));
|
|
16657
16675
|
if (renderEverySite && isAgentEnvironment) {
|
|
16658
16676
|
const fixRecipeLine = formatFixRecipeLine(representative);
|
|
16659
16677
|
if (fixRecipeLine) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${fixRecipeLine}`));
|
|
@@ -16847,14 +16865,21 @@ const RAINBOW_HUE_SHIFT_PER_FRAME = 9;
|
|
|
16847
16865
|
const RAINBOW_GRADIENT_WIDTH = 80;
|
|
16848
16866
|
const RAINBOW_OKLCH_LIGHTNESS = .638;
|
|
16849
16867
|
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
|
+
});
|
|
16850
16875
|
const buildScoreBarSegments = (filledCount) => {
|
|
16851
|
-
const emptyCount =
|
|
16876
|
+
const emptyCount = Math.max(0, getScoreBarWidth() - filledCount);
|
|
16852
16877
|
return {
|
|
16853
16878
|
filledSegment: "█".repeat(filledCount),
|
|
16854
16879
|
emptySegment: "░".repeat(emptyCount)
|
|
16855
16880
|
};
|
|
16856
16881
|
};
|
|
16857
|
-
const getFilledCount = (score) => Math.round(score / 100 *
|
|
16882
|
+
const getFilledCount = (score) => Math.round(score / 100 * getScoreBarWidth());
|
|
16858
16883
|
const joinScoreHeaderFrame = (lines) => `${lines[0]}\n\r${lines[1]}\n\r${lines[2]}\n\r${lines[3]}\n`;
|
|
16859
16884
|
const buildRawScoreBar = (displayScore) => {
|
|
16860
16885
|
const { filledSegment, emptySegment } = buildScoreBarSegments(getFilledCount(displayScore));
|
|
@@ -16890,10 +16915,11 @@ const buildScoreBar = (displayScore, colorScore = displayScore) => {
|
|
|
16890
16915
|
return colorizeByScore(filledSegment, colorScore) + highlighter.dim(emptySegment);
|
|
16891
16916
|
};
|
|
16892
16917
|
const buildProjectedScoreBar = (currentScore, potentialScore) => {
|
|
16918
|
+
const barWidth = getScoreBarWidth();
|
|
16893
16919
|
const currentFill = getFilledCount(currentScore);
|
|
16894
|
-
const potentialFill = Math.min(getFilledCount(potentialScore),
|
|
16920
|
+
const potentialFill = Math.min(getFilledCount(potentialScore), barWidth);
|
|
16895
16921
|
const gainCount = Math.max(0, potentialFill - currentFill);
|
|
16896
|
-
const emptyCount = Math.max(0,
|
|
16922
|
+
const emptyCount = Math.max(0, barWidth - currentFill - gainCount);
|
|
16897
16923
|
return colorizeByScore("█".repeat(currentFill), currentScore) + highlighter.dim(colorizeByScore("▓".repeat(gainCount), currentScore)) + highlighter.dim("░".repeat(emptyCount));
|
|
16898
16924
|
};
|
|
16899
16925
|
const getDoctorFace = (score) => {
|
|
@@ -16906,7 +16932,7 @@ const RAW_BRANDING_LINE = "React Doctor (https://react.doctor)";
|
|
|
16906
16932
|
const buildRawFaceLines = (score) => {
|
|
16907
16933
|
const [eyes, mouth] = getDoctorFace(score);
|
|
16908
16934
|
return [
|
|
16909
|
-
|
|
16935
|
+
FACE_BOX_TOP_BORDER,
|
|
16910
16936
|
`│ ${eyes} │`,
|
|
16911
16937
|
`│ ${mouth} │`,
|
|
16912
16938
|
"└─────┘"
|
|
@@ -17048,6 +17074,11 @@ const writeDiagnosticsDirectory = (diagnostics) => {
|
|
|
17048
17074
|
};
|
|
17049
17075
|
//#endregion
|
|
17050
17076
|
//#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
|
+
});
|
|
17051
17082
|
const buildShareUrl = (diagnostics, scoreResult, projectName) => {
|
|
17052
17083
|
const errorCount = diagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
|
|
17053
17084
|
const warningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
|
|
@@ -17067,14 +17098,14 @@ const printFooter = (input) => Effect.gen(function* () {
|
|
|
17067
17098
|
if (!input.isOffline) {
|
|
17068
17099
|
const shareUrl = buildShareUrl(input.diagnostics, input.scoreResult, input.projectName);
|
|
17069
17100
|
yield* Console.log(` ${highlighter.bold("Share:")} ${highlighter.info(shareUrl)}`);
|
|
17070
|
-
yield*
|
|
17101
|
+
yield* printFooterDescription("Tell others how you did on socials");
|
|
17071
17102
|
yield* Console.log("");
|
|
17072
17103
|
}
|
|
17073
17104
|
yield* Console.log(` ${highlighter.bold("Docs:")} ${highlighter.info(DOCS_URL)}`);
|
|
17074
|
-
yield*
|
|
17105
|
+
yield* printFooterDescription("Learn more about fixing issues, setting up CI/CD, and configuring rules with a config file");
|
|
17075
17106
|
yield* Console.log("");
|
|
17076
17107
|
yield* Console.log(` ${highlighter.bold("GitHub:")} ${highlighter.info(CANONICAL_GITHUB_URL)}`);
|
|
17077
|
-
yield*
|
|
17108
|
+
yield* printFooterDescription("Report issues and star the repository!");
|
|
17078
17109
|
});
|
|
17079
17110
|
const printSummary = (input) => Effect.gen(function* () {
|
|
17080
17111
|
if (input.scoreResult) {
|
|
@@ -17980,190 +18011,24 @@ const installDoctorScript = (options) => {
|
|
|
17980
18011
|
...scriptTarget.reason !== void 0 ? { scriptReason: scriptTarget.reason } : {}
|
|
17981
18012
|
};
|
|
17982
18013
|
};
|
|
17983
|
-
|
|
17984
|
-
|
|
17985
|
-
|
|
17986
|
-
|
|
17987
|
-
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
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);
|
|
18001
|
-
};
|
|
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];
|
|
18014
|
+
const formatDoctorScriptInstallMessage = (scriptResult) => {
|
|
18015
|
+
const scriptName = scriptResult.scriptName ?? "doctor";
|
|
18016
|
+
if (scriptResult.scriptStatus === "created") return `Added package script: ${scriptName}.`;
|
|
18017
|
+
if (scriptResult.scriptStatus === "existing") return `Package script already exists: ${scriptName}.`;
|
|
18018
|
+
if (scriptResult.scriptReason === "script-names-taken") return "Skipped package script: doctor and react-doctor are already taken.";
|
|
18019
|
+
if (scriptResult.scriptReason === "doctor-script-taken") return "Skipped package script: doctor and react-doctor scripts already exist.";
|
|
18020
|
+
if (scriptResult.scriptReason === "invalid-scripts") return "Skipped package script: scripts field is not an object.";
|
|
18021
|
+
return "Skipped package script: package.json missing or invalid.";
|
|
18050
18022
|
};
|
|
18051
|
-
const
|
|
18052
|
-
"
|
|
18053
|
-
|
|
18054
|
-
|
|
18055
|
-
|
|
18056
|
-
|
|
18057
|
-
|
|
18058
|
-
|
|
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
|
-
}
|
|
18023
|
+
const installReactDoctorScriptStep = (projectRoot) => {
|
|
18024
|
+
const scriptSpinner = spinner("Installing React Doctor package script...").start();
|
|
18025
|
+
try {
|
|
18026
|
+
const scriptResult = installDoctorScript({ projectRoot });
|
|
18027
|
+
scriptSpinner.succeed(formatDoctorScriptInstallMessage(scriptResult));
|
|
18028
|
+
} catch (error) {
|
|
18029
|
+
scriptSpinner.fail("Failed to install React Doctor package script.");
|
|
18030
|
+
throw error;
|
|
18162
18031
|
}
|
|
18163
|
-
return {
|
|
18164
|
-
installedAgents,
|
|
18165
|
-
files
|
|
18166
|
-
};
|
|
18167
18032
|
};
|
|
18168
18033
|
//#endregion
|
|
18169
18034
|
//#region src/cli/utils/install-github-workflow.ts
|
|
@@ -18273,1074 +18138,1389 @@ const installReactDoctorWorkflow = (projectRoot) => {
|
|
|
18273
18138
|
};
|
|
18274
18139
|
}
|
|
18275
18140
|
};
|
|
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
|
+
};
|
|
18276
18165
|
//#endregion
|
|
18277
|
-
//#region src/cli/utils/
|
|
18278
|
-
const
|
|
18279
|
-
|
|
18280
|
-
|
|
18281
|
-
|
|
18166
|
+
//#region src/cli/utils/hash-project-root.ts
|
|
18167
|
+
const hashProjectRoot = (projectRoot) => createHash("sha256").update(path$1.resolve(projectRoot)).digest("hex");
|
|
18168
|
+
//#endregion
|
|
18169
|
+
//#region src/cli/utils/action-upgrade-prompt.ts
|
|
18170
|
+
const GLOBAL_CONFIG_PROJECT_NAME$1 = "react-doctor";
|
|
18171
|
+
const getActionUpgradeStore = (options = {}) => new Conf({
|
|
18172
|
+
projectName: GLOBAL_CONFIG_PROJECT_NAME$1,
|
|
18173
|
+
cwd: options.cwd
|
|
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;
|
|
18282
18181
|
}
|
|
18283
|
-
|
|
18284
|
-
|
|
18182
|
+
};
|
|
18183
|
+
const recordActionUpgradeDecision = (projectRoot, outcome, storeOptions = {}) => {
|
|
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 {
|
|
18285
18197
|
return false;
|
|
18286
18198
|
}
|
|
18287
|
-
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18288
|
-
recordCount(METRIC.installWorkflow, 1);
|
|
18289
|
-
return true;
|
|
18290
18199
|
};
|
|
18291
18200
|
//#endregion
|
|
18292
|
-
//#region src/cli/utils/
|
|
18293
|
-
const
|
|
18294
|
-
|
|
18295
|
-
|
|
18296
|
-
|
|
18297
|
-
|
|
18298
|
-
|
|
18299
|
-
|
|
18300
|
-
|
|
18301
|
-
|
|
18302
|
-
|
|
18303
|
-
"react_doctor_scan_staged_files() {",
|
|
18304
|
-
` if [ -x "${LOCAL_REACT_DOCTOR_BIN}" ]; then`,
|
|
18305
|
-
` "${LOCAL_REACT_DOCTOR_BIN}" ${REACT_DOCTOR_COMMAND.replace("react-doctor ", "")}`,
|
|
18306
|
-
" return",
|
|
18307
|
-
" fi",
|
|
18308
|
-
"",
|
|
18309
|
-
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
18310
|
-
` ${REACT_DOCTOR_COMMAND}`,
|
|
18311
|
-
" return",
|
|
18312
|
-
" fi",
|
|
18313
|
-
"",
|
|
18314
|
-
" if command -v pnpm >/dev/null 2>&1; then",
|
|
18315
|
-
` ${PNPM_REACT_DOCTOR_COMMAND}`,
|
|
18316
|
-
" return",
|
|
18317
|
-
" fi",
|
|
18318
|
-
"",
|
|
18319
|
-
" if command -v npx >/dev/null 2>&1; then",
|
|
18320
|
-
` ${NPX_REACT_DOCTOR_COMMAND}`,
|
|
18321
|
-
" return",
|
|
18322
|
-
" fi",
|
|
18323
|
-
"",
|
|
18324
|
-
" printf '%s\\n' \"react-doctor: command not found; skipping staged scan.\"",
|
|
18325
|
-
"}",
|
|
18326
|
-
"",
|
|
18327
|
-
"react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\")",
|
|
18328
|
-
"if react_doctor_scan_staged_files > \"$react_doctor_output\" 2>&1; then",
|
|
18329
|
-
" rm -f \"$react_doctor_output\"",
|
|
18330
|
-
"else",
|
|
18331
|
-
" rm -f \"$react_doctor_output\"",
|
|
18332
|
-
` printf '%s\\n' "React Doctor found staged regressions." "Run ${REACT_DOCTOR_COMMAND} to inspect." "Want them fixed? Ask your agent to run that command and resolve the findings." >&2`,
|
|
18333
|
-
"fi",
|
|
18334
|
-
REACT_DOCTOR_BLOCK_END
|
|
18335
|
-
].join("\n");
|
|
18336
|
-
const mergeHookContent = (existingContent) => {
|
|
18337
|
-
const hookBlock = `${buildReactDoctorHookBlock()}\n`;
|
|
18338
|
-
if (REACT_DOCTOR_BLOCK_PATTERN.test(existingContent)) return ensureTrailingNewline(existingContent.replace(REACT_DOCTOR_BLOCK_PATTERN, hookBlock));
|
|
18339
|
-
if (existingContent.length === 0) return `${SHEBANG}\n\n${hookBlock}`;
|
|
18340
|
-
const normalizedExistingContent = ensureTrailingNewline(existingContent);
|
|
18341
|
-
if (normalizedExistingContent.startsWith(SHEBANG_PREFIX)) {
|
|
18342
|
-
const [shebangLine, ...remainingLines] = normalizedExistingContent.split("\n");
|
|
18343
|
-
return [
|
|
18344
|
-
shebangLine,
|
|
18201
|
+
//#region src/cli/utils/open-url.ts
|
|
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",
|
|
18345
18212
|
"",
|
|
18346
|
-
|
|
18347
|
-
|
|
18348
|
-
|
|
18349
|
-
}
|
|
18350
|
-
return `${SHEBANG}\n\n${hookBlock}${normalizedExistingContent}`;
|
|
18351
|
-
};
|
|
18352
|
-
const removeLegacyManagedRunner = (projectRoot) => {
|
|
18353
|
-
const runnerPath = path$1.join(projectRoot, LEGACY_HOOK_RUNNER_RELATIVE_PATH);
|
|
18354
|
-
fs$1.rmSync(runnerPath, { force: true });
|
|
18355
|
-
for (const directory of [path$1.dirname(runnerPath), path$1.join(projectRoot, ".react-doctor")]) try {
|
|
18356
|
-
fs$1.rmdirSync(directory);
|
|
18357
|
-
} catch {}
|
|
18358
|
-
};
|
|
18359
|
-
const installDirectGitHook = (options) => {
|
|
18360
|
-
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18361
|
-
const nextContent = mergeHookContent(didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "");
|
|
18362
|
-
if (options.hooksPathConfig !== void 0) runGit(options.projectRoot, [
|
|
18363
|
-
"config",
|
|
18364
|
-
"core.hooksPath",
|
|
18365
|
-
options.hooksPathConfig
|
|
18366
|
-
]);
|
|
18367
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18368
|
-
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18369
|
-
fs$1.chmodSync(options.hookPath, 493);
|
|
18370
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18213
|
+
url
|
|
18214
|
+
]
|
|
18215
|
+
};
|
|
18371
18216
|
return {
|
|
18372
|
-
|
|
18373
|
-
|
|
18374
|
-
status: didHookExist ? "updated" : "created"
|
|
18217
|
+
command: "xdg-open",
|
|
18218
|
+
args: [url]
|
|
18375
18219
|
};
|
|
18376
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
|
+
};
|
|
18377
18235
|
//#endregion
|
|
18378
|
-
//#region src/cli/utils/
|
|
18379
|
-
const
|
|
18380
|
-
|
|
18381
|
-
|
|
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
|
+
}
|
|
18382
18279
|
};
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
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";
|
|
18386
18303
|
};
|
|
18387
|
-
|
|
18388
|
-
|
|
18389
|
-
|
|
18390
|
-
|
|
18391
|
-
|
|
18392
|
-
|
|
18393
|
-
|
|
18394
|
-
|
|
18395
|
-
|
|
18396
|
-
|
|
18397
|
-
|
|
18398
|
-
|
|
18399
|
-
|
|
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
|
+
};
|
|
18400
18331
|
}
|
|
18401
|
-
parent[leafKey] = strategy.leafShape === "array" ? appendArrayCommand(parent[leafKey]) : appendStringCommand(parent[leafKey]);
|
|
18402
|
-
writeJsonFile$1(packageJsonPath, nextPackageJson);
|
|
18403
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18404
|
-
return {
|
|
18405
|
-
hookPath: packageJsonPath,
|
|
18406
|
-
kind: strategy.kind,
|
|
18407
|
-
status: didHookExist ? "updated" : "created"
|
|
18408
|
-
};
|
|
18409
18332
|
};
|
|
18410
|
-
const
|
|
18411
|
-
|
|
18412
|
-
|
|
18413
|
-
|
|
18414
|
-
|
|
18415
|
-
const installGhooks = (options) => installPackageJsonHook(options, {
|
|
18416
|
-
kind: "ghooks",
|
|
18417
|
-
path: [
|
|
18418
|
-
"config",
|
|
18419
|
-
"ghooks",
|
|
18420
|
-
"pre-commit"
|
|
18421
|
-
],
|
|
18422
|
-
leafShape: "string"
|
|
18423
|
-
});
|
|
18424
|
-
const installPreCommitNpm = (options) => installPackageJsonHook(options, {
|
|
18425
|
-
kind: "pre-commit-npm",
|
|
18426
|
-
path: ["pre-commit"],
|
|
18427
|
-
leafShape: "array"
|
|
18428
|
-
});
|
|
18429
|
-
const installPrettyQuick = (options) => installPackageJsonHook(options, {
|
|
18430
|
-
kind: "pretty-quick",
|
|
18431
|
-
path: ["gitHooks", "pre-commit"],
|
|
18432
|
-
leafShape: "string"
|
|
18433
|
-
});
|
|
18434
|
-
const installYorkie = (options) => installPackageJsonHook(options, {
|
|
18435
|
-
kind: "yorkie",
|
|
18436
|
-
path: ["gitHooks", "pre-commit"],
|
|
18437
|
-
leafShape: "string"
|
|
18438
|
-
});
|
|
18439
|
-
const installGitHooksJs = (options) => installPackageJsonHook(options, {
|
|
18440
|
-
kind: "git-hooks-js",
|
|
18441
|
-
path: ["git-hooks", "pre-commit"],
|
|
18442
|
-
leafShape: "string"
|
|
18443
|
-
});
|
|
18444
|
-
const appendIndentedBlockToTopLevelSection = (content, sectionName, block) => {
|
|
18445
|
-
const normalizedContent = ensureTrailingNewline(content);
|
|
18446
|
-
const match = new RegExp(`^${sectionName}:\\s*$`, "m").exec(normalizedContent);
|
|
18447
|
-
if (match === null) return ensureTrailingNewline([
|
|
18448
|
-
normalizedContent.trimEnd(),
|
|
18449
|
-
"",
|
|
18450
|
-
`${sectionName}:`,
|
|
18451
|
-
...block,
|
|
18452
|
-
""
|
|
18453
|
-
].filter((line, index) => index > 0 || line.length > 0).join("\n"));
|
|
18454
|
-
const sectionStartIndex = match.index;
|
|
18455
|
-
const nextSectionPattern = /^[A-Za-z0-9_-]+:\s*$/gm;
|
|
18456
|
-
nextSectionPattern.lastIndex = sectionStartIndex + match[0].length;
|
|
18457
|
-
let nextSectionMatch = nextSectionPattern.exec(normalizedContent);
|
|
18458
|
-
while (nextSectionMatch !== null && nextSectionMatch.index === sectionStartIndex) nextSectionMatch = nextSectionPattern.exec(normalizedContent);
|
|
18459
|
-
const insertIndex = nextSectionMatch?.index ?? normalizedContent.length;
|
|
18460
|
-
const prefix = normalizedContent.slice(0, insertIndex).trimEnd();
|
|
18461
|
-
const suffix = normalizedContent.slice(insertIndex);
|
|
18462
|
-
return ensureTrailingNewline([
|
|
18463
|
-
prefix,
|
|
18464
|
-
...block,
|
|
18465
|
-
suffix.trimStart()
|
|
18466
|
-
].join("\n"));
|
|
18467
|
-
};
|
|
18468
|
-
const findTopLevelSectionRange = (content, sectionName) => {
|
|
18469
|
-
const match = new RegExp(`^${sectionName}:\\s*$`, "m").exec(content);
|
|
18470
|
-
if (match === null) return null;
|
|
18471
|
-
const headerLineEndIndex = content.indexOf("\n", match.index);
|
|
18472
|
-
const headerEndIndex = headerLineEndIndex === -1 ? match.index + match[0].length : headerLineEndIndex + 1;
|
|
18473
|
-
const nextSectionPattern = /^[A-Za-z0-9_-]+:\s*$/gm;
|
|
18474
|
-
nextSectionPattern.lastIndex = headerEndIndex;
|
|
18475
|
-
return {
|
|
18476
|
-
headerEndIndex,
|
|
18477
|
-
contentEndIndex: nextSectionPattern.exec(content)?.index ?? content.length
|
|
18478
|
-
};
|
|
18479
|
-
};
|
|
18480
|
-
const appendLefthookCommand = (content) => {
|
|
18481
|
-
const normalizedContent = ensureTrailingNewline(content);
|
|
18482
|
-
const sectionRange = findTopLevelSectionRange(normalizedContent, "pre-commit");
|
|
18483
|
-
const reactDoctorCommandBlock = [
|
|
18484
|
-
" react-doctor:",
|
|
18485
|
-
` run: ${NON_BLOCKING_REACT_DOCTOR_COMMAND}`,
|
|
18486
|
-
""
|
|
18487
|
-
];
|
|
18488
|
-
if (sectionRange === null) return ensureTrailingNewline([
|
|
18489
|
-
normalizedContent.trimEnd(),
|
|
18490
|
-
"",
|
|
18491
|
-
"pre-commit:",
|
|
18492
|
-
" commands:",
|
|
18493
|
-
...reactDoctorCommandBlock
|
|
18494
|
-
].filter((line, index) => index > 0 || line.length > 0).join("\n"));
|
|
18495
|
-
const sectionContent = normalizedContent.slice(sectionRange.headerEndIndex, sectionRange.contentEndIndex);
|
|
18496
|
-
const commandsMatch = /^ commands:\s*$/m.exec(sectionContent);
|
|
18497
|
-
const insertIndex = commandsMatch === null ? sectionRange.headerEndIndex : sectionRange.headerEndIndex + sectionContent.indexOf(commandsMatch[0]) + commandsMatch[0].length + 1;
|
|
18498
|
-
const insertBlock = commandsMatch === null ? [" commands:", ...reactDoctorCommandBlock].join("\n") : reactDoctorCommandBlock.join("\n");
|
|
18499
|
-
return ensureTrailingNewline(`${normalizedContent.slice(0, insertIndex)}${insertBlock}${normalizedContent.slice(insertIndex)}`);
|
|
18500
|
-
};
|
|
18501
|
-
const installLefthook = (options) => {
|
|
18502
|
-
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18503
|
-
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18504
|
-
if (!existingContent.includes("react-doctor")) {
|
|
18505
|
-
const nextContent = appendLefthookCommand(existingContent);
|
|
18506
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18507
|
-
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18508
|
-
}
|
|
18509
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18510
|
-
return {
|
|
18511
|
-
hookPath: options.hookPath,
|
|
18512
|
-
kind: "lefthook",
|
|
18513
|
-
status: didHookExist ? "updated" : "created"
|
|
18514
|
-
};
|
|
18515
|
-
};
|
|
18516
|
-
const installPreCommit = (options) => {
|
|
18517
|
-
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18518
|
-
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18519
|
-
if (!existingContent.includes("id: react-doctor")) {
|
|
18520
|
-
const hasReposKey = /^repos:\s*$/m.test(existingContent);
|
|
18521
|
-
const localHookBlock = [
|
|
18522
|
-
" - repo: local",
|
|
18523
|
-
" hooks:",
|
|
18524
|
-
" - id: react-doctor",
|
|
18525
|
-
" name: react-doctor",
|
|
18526
|
-
` entry: sh -c '${NON_BLOCKING_REACT_DOCTOR_COMMAND}'`,
|
|
18527
|
-
" language: system",
|
|
18528
|
-
" pass_filenames: false",
|
|
18529
|
-
""
|
|
18530
|
-
].join("\n");
|
|
18531
|
-
const nextContent = hasReposKey ? `${ensureTrailingNewline(existingContent)}${localHookBlock}` : `repos:\n${localHookBlock}`;
|
|
18532
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18533
|
-
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18534
|
-
}
|
|
18535
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18536
|
-
return {
|
|
18537
|
-
hookPath: options.hookPath,
|
|
18538
|
-
kind: "pre-commit",
|
|
18539
|
-
status: didHookExist ? "updated" : "created"
|
|
18540
|
-
};
|
|
18541
|
-
};
|
|
18542
|
-
const installOvercommit = (options) => {
|
|
18543
|
-
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18544
|
-
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18545
|
-
if (!existingContent.includes("ReactDoctor")) {
|
|
18546
|
-
const nextContent = appendIndentedBlockToTopLevelSection(existingContent, "PreCommit", [
|
|
18547
|
-
" ReactDoctor:",
|
|
18548
|
-
" enabled: true",
|
|
18549
|
-
` command: ['sh', '-c', '${NON_BLOCKING_REACT_DOCTOR_COMMAND}']`,
|
|
18550
|
-
""
|
|
18551
|
-
]);
|
|
18552
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18553
|
-
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
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];
|
|
18554
18338
|
}
|
|
18555
|
-
|
|
18556
|
-
|
|
18557
|
-
|
|
18558
|
-
|
|
18559
|
-
|
|
18560
|
-
|
|
18561
|
-
|
|
18562
|
-
|
|
18563
|
-
|
|
18564
|
-
|
|
18565
|
-
|
|
18566
|
-
const isSimpleGitHooksProject = (projectRoot) => {
|
|
18567
|
-
const packageJson = readPackageJson(projectRoot);
|
|
18568
|
-
return isRecord(packageJson) && isRecord(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || fs$1.existsSync(path$1.join(projectRoot, ".simple-git-hooks.cjs"));
|
|
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;
|
|
18569
18350
|
};
|
|
18570
|
-
const
|
|
18571
|
-
|
|
18572
|
-
|
|
18573
|
-
|
|
18574
|
-
|
|
18575
|
-
|
|
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, "")}`;
|
|
18576
18358
|
};
|
|
18577
|
-
const
|
|
18578
|
-
const
|
|
18579
|
-
const
|
|
18580
|
-
const
|
|
18581
|
-
const
|
|
18582
|
-
const
|
|
18583
|
-
|
|
18584
|
-
|
|
18585
|
-
|
|
18586
|
-
const topLevel = runGit(projectRoot, ["rev-parse", "--show-toplevel"]) ?? projectRoot;
|
|
18587
|
-
const configuredHooksPath = runGit(projectRoot, [
|
|
18588
|
-
"config",
|
|
18589
|
-
"--path",
|
|
18590
|
-
"--get",
|
|
18591
|
-
"core.hooksPath"
|
|
18592
|
-
]);
|
|
18593
|
-
if (configuredHooksPath !== null && configuredHooksPath.length > 0) return {
|
|
18594
|
-
hookPath: path$1.join(resolveGitPath(topLevel, configuredHooksPath), HOOK_FILE_NAME),
|
|
18595
|
-
runnerRoot: topLevel,
|
|
18596
|
-
kind: "configured"
|
|
18597
|
-
};
|
|
18598
|
-
if (isHuskyProject(topLevel)) return {
|
|
18599
|
-
hookPath: path$1.join(topLevel, HUSKY_HOOKS_PATH, HOOK_FILE_NAME),
|
|
18600
|
-
runnerRoot: topLevel,
|
|
18601
|
-
kind: "husky",
|
|
18602
|
-
hooksPathConfig: HUSKY_HOOKS_PATH
|
|
18603
|
-
};
|
|
18604
|
-
if (isVitePlusProject(topLevel)) return {
|
|
18605
|
-
hookPath: path$1.join(topLevel, VITE_PLUS_HOOKS_PATH, HOOK_FILE_NAME),
|
|
18606
|
-
runnerRoot: topLevel,
|
|
18607
|
-
kind: "vite-plus",
|
|
18608
|
-
hooksPathConfig: VITE_PLUS_HOOKS_PATH
|
|
18609
|
-
};
|
|
18610
|
-
if (isSimpleGitHooksProject(topLevel)) return {
|
|
18611
|
-
hookPath: path$1.join(topLevel, "package.json"),
|
|
18612
|
-
runnerRoot: topLevel,
|
|
18613
|
-
kind: "simple-git-hooks"
|
|
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"
|
|
18614
18368
|
};
|
|
18615
|
-
const
|
|
18616
|
-
if (
|
|
18617
|
-
|
|
18618
|
-
|
|
18619
|
-
kind: "lefthook"
|
|
18369
|
+
const cwd = repoRootProbe.stdout;
|
|
18370
|
+
if (!isCommandAvailable("gh")) return {
|
|
18371
|
+
status: "not-attempted",
|
|
18372
|
+
reason: "gh-not-installed"
|
|
18620
18373
|
};
|
|
18621
|
-
if (
|
|
18622
|
-
|
|
18623
|
-
|
|
18624
|
-
kind: "pre-commit"
|
|
18374
|
+
if (!(await run("gh", ["auth", "status"], cwd)).success) return {
|
|
18375
|
+
status: "not-attempted",
|
|
18376
|
+
reason: "gh-not-authenticated"
|
|
18625
18377
|
};
|
|
18626
|
-
|
|
18627
|
-
|
|
18628
|
-
|
|
18629
|
-
|
|
18378
|
+
const defaultBranch = await detectDefaultBranch(cwd);
|
|
18379
|
+
if (!defaultBranch) return {
|
|
18380
|
+
status: "not-attempted",
|
|
18381
|
+
reason: "no-default-branch"
|
|
18630
18382
|
};
|
|
18631
|
-
|
|
18632
|
-
|
|
18633
|
-
|
|
18634
|
-
|
|
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"
|
|
18635
18391
|
};
|
|
18636
|
-
|
|
18637
|
-
|
|
18638
|
-
|
|
18639
|
-
|
|
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"
|
|
18640
18407
|
};
|
|
18641
|
-
|
|
18642
|
-
|
|
18643
|
-
|
|
18644
|
-
|
|
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);
|
|
18645
18415
|
};
|
|
18646
|
-
if (
|
|
18647
|
-
|
|
18648
|
-
|
|
18649
|
-
|
|
18650
|
-
|
|
18651
|
-
|
|
18652
|
-
|
|
18653
|
-
|
|
18654
|
-
|
|
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
|
|
18655
18466
|
};
|
|
18656
|
-
const hookPath = runGit(projectRoot, [
|
|
18657
|
-
"rev-parse",
|
|
18658
|
-
"--git-path",
|
|
18659
|
-
HOOK_RELATIVE_PATH
|
|
18660
|
-
]);
|
|
18661
|
-
if (hookPath === null || hookPath.length === 0) return null;
|
|
18662
18467
|
return {
|
|
18663
|
-
|
|
18664
|
-
|
|
18665
|
-
kind: "git"
|
|
18468
|
+
status: "pr-opened",
|
|
18469
|
+
url: prCreate.stdout.split(/\r?\n/).filter(Boolean).pop() ?? ""
|
|
18666
18470
|
};
|
|
18667
18471
|
};
|
|
18668
|
-
const
|
|
18669
|
-
|
|
18670
|
-
|
|
18671
|
-
if (
|
|
18672
|
-
|
|
18673
|
-
|
|
18674
|
-
|
|
18675
|
-
|
|
18676
|
-
|
|
18677
|
-
if (options.kind === "pretty-quick") return installPrettyQuick(options);
|
|
18678
|
-
return installDirectGitHook(options);
|
|
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;
|
|
18679
18481
|
};
|
|
18680
18482
|
//#endregion
|
|
18681
|
-
//#region src/cli/utils/
|
|
18682
|
-
const
|
|
18683
|
-
|
|
18684
|
-
|
|
18685
|
-
|
|
18686
|
-
const SETUP_OPTION_AGENT_HOOKS = "agent-hooks";
|
|
18687
|
-
const SETUP_OPTION_WORKFLOW = "workflow";
|
|
18688
|
-
const SETUP_OPTION_SKIP = "skip";
|
|
18689
|
-
const CONFIG_ONLY_GIT_HOOK_KINDS = new Set([
|
|
18690
|
-
"ghooks",
|
|
18691
|
-
"git-hooks-js",
|
|
18692
|
-
"lefthook",
|
|
18693
|
-
"overcommit",
|
|
18694
|
-
"pre-commit",
|
|
18695
|
-
"pre-commit-npm",
|
|
18696
|
-
"pretty-quick",
|
|
18697
|
-
"simple-git-hooks",
|
|
18698
|
-
"yorkie"
|
|
18699
|
-
]);
|
|
18700
|
-
const PACKAGE_MANAGER_LOCKFILES = [
|
|
18701
|
-
{
|
|
18702
|
-
packageManager: "pnpm",
|
|
18703
|
-
fileName: "pnpm-lock.yaml"
|
|
18704
|
-
},
|
|
18705
|
-
{
|
|
18706
|
-
packageManager: "yarn",
|
|
18707
|
-
fileName: "yarn.lock"
|
|
18708
|
-
},
|
|
18709
|
-
{
|
|
18710
|
-
packageManager: "bun",
|
|
18711
|
-
fileName: "bun.lockb"
|
|
18712
|
-
},
|
|
18713
|
-
{
|
|
18714
|
-
packageManager: "bun",
|
|
18715
|
-
fileName: "bun.lock"
|
|
18716
|
-
},
|
|
18717
|
-
{
|
|
18718
|
-
packageManager: "npm",
|
|
18719
|
-
fileName: "package-lock.json"
|
|
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;
|
|
18720
18488
|
}
|
|
18721
|
-
|
|
18722
|
-
|
|
18723
|
-
|
|
18724
|
-
while (true) {
|
|
18725
|
-
if (fileNames.some((fileName) => fs$1.existsSync(path$1.join(currentDirectory, fileName)))) return currentDirectory;
|
|
18726
|
-
const parentDirectory = path$1.dirname(currentDirectory);
|
|
18727
|
-
if (parentDirectory === currentDirectory) return null;
|
|
18728
|
-
currentDirectory = parentDirectory;
|
|
18489
|
+
if (result.status === "exists") {
|
|
18490
|
+
workflowSpinner.succeed("GitHub Actions workflow already configured.");
|
|
18491
|
+
return false;
|
|
18729
18492
|
}
|
|
18493
|
+
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18494
|
+
recordCount(METRIC.installWorkflow, 1);
|
|
18495
|
+
return true;
|
|
18730
18496
|
};
|
|
18731
|
-
|
|
18732
|
-
|
|
18733
|
-
|
|
18734
|
-
|
|
18735
|
-
|
|
18736
|
-
|
|
18737
|
-
|
|
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.");
|
|
18738
18521
|
}
|
|
18739
|
-
const parentDirectory = path$1.dirname(currentDirectory);
|
|
18740
|
-
if (parentDirectory === currentDirectory) break;
|
|
18741
|
-
currentDirectory = parentDirectory;
|
|
18742
18522
|
}
|
|
18743
|
-
|
|
18744
|
-
return
|
|
18523
|
+
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
18524
|
+
return didCreateWorkflow;
|
|
18745
18525
|
};
|
|
18746
|
-
|
|
18747
|
-
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
|
|
18764
|
-
packageSpecifier
|
|
18765
|
-
],
|
|
18766
|
-
cwd: projectRoot
|
|
18767
|
-
};
|
|
18768
|
-
if (packageManager === "bun") return {
|
|
18769
|
-
command: "bun",
|
|
18770
|
-
args: [
|
|
18771
|
-
"add",
|
|
18772
|
-
"--dev",
|
|
18773
|
-
packageSpecifier
|
|
18774
|
-
],
|
|
18775
|
-
cwd: projectRoot
|
|
18776
|
-
};
|
|
18777
|
-
return {
|
|
18778
|
-
command: "pnpm",
|
|
18779
|
-
args: [
|
|
18780
|
-
"add",
|
|
18781
|
-
"--save-dev",
|
|
18782
|
-
...packageManagerNeedsWorkspaceFlag(projectRoot) ? ["-w"] : [],
|
|
18783
|
-
packageSpecifier
|
|
18784
|
-
],
|
|
18785
|
-
cwd: projectRoot
|
|
18786
|
-
};
|
|
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);
|
|
18787
18544
|
};
|
|
18788
|
-
const
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
cwd: input.cwd,
|
|
18792
|
-
env: {
|
|
18793
|
-
...process.env,
|
|
18794
|
-
REACT_DOCTOR_INSTALL: "1"
|
|
18795
|
-
},
|
|
18796
|
-
shell: process.platform === "win32"
|
|
18797
|
-
});
|
|
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`);
|
|
18798
18548
|
};
|
|
18799
|
-
const
|
|
18800
|
-
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
candidate?.stdout,
|
|
18804
|
-
candidate?.message
|
|
18805
|
-
].map((part) => String(part ?? "")).join("\n");
|
|
18806
|
-
return /ERR_PNPM_TRUST_DOWNGRADE|trust downgrade/i.test(haystack);
|
|
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);
|
|
18807
18553
|
};
|
|
18808
|
-
const
|
|
18809
|
-
const
|
|
18810
|
-
const
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
if (
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
|
|
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
|
|
18819
18709
|
};
|
|
18820
|
-
|
|
18821
|
-
|
|
18822
|
-
|
|
18823
|
-
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
18827
|
-
|
|
18828
|
-
|
|
18710
|
+
};
|
|
18711
|
+
//#endregion
|
|
18712
|
+
//#region src/cli/utils/install-git-hook-file.ts
|
|
18713
|
+
const REACT_DOCTOR_BLOCK_START = "# react-doctor hook start";
|
|
18714
|
+
const REACT_DOCTOR_BLOCK_END = "# react-doctor hook end";
|
|
18715
|
+
const REACT_DOCTOR_BLOCK_PATTERN = new RegExp(`(?:${REACT_DOCTOR_BLOCK_START}[\\s\\S]*?${REACT_DOCTOR_BLOCK_END}\\n?|# react-doctor hook launcher start[\\s\\S]*?# react-doctor hook launcher end\\n?)`);
|
|
18716
|
+
const SHEBANG = "#!/bin/sh";
|
|
18717
|
+
const SHEBANG_PREFIX = "#!";
|
|
18718
|
+
const LOCAL_REACT_DOCTOR_BIN = "./node_modules/.bin/react-doctor";
|
|
18719
|
+
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --blocking warning";
|
|
18720
|
+
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --blocking warning";
|
|
18721
|
+
const buildReactDoctorHookBlock = () => [
|
|
18722
|
+
REACT_DOCTOR_BLOCK_START,
|
|
18723
|
+
"react_doctor_scan_staged_files() {",
|
|
18724
|
+
` if [ -x "${LOCAL_REACT_DOCTOR_BIN}" ]; then`,
|
|
18725
|
+
` "${LOCAL_REACT_DOCTOR_BIN}" ${REACT_DOCTOR_COMMAND.replace("react-doctor ", "")}`,
|
|
18726
|
+
" return",
|
|
18727
|
+
" fi",
|
|
18728
|
+
"",
|
|
18729
|
+
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
18730
|
+
` ${REACT_DOCTOR_COMMAND}`,
|
|
18731
|
+
" return",
|
|
18732
|
+
" fi",
|
|
18733
|
+
"",
|
|
18734
|
+
" if command -v pnpm >/dev/null 2>&1; then",
|
|
18735
|
+
` ${PNPM_REACT_DOCTOR_COMMAND}`,
|
|
18736
|
+
" return",
|
|
18737
|
+
" fi",
|
|
18738
|
+
"",
|
|
18739
|
+
" if command -v npx >/dev/null 2>&1; then",
|
|
18740
|
+
` ${NPX_REACT_DOCTOR_COMMAND}`,
|
|
18741
|
+
" return",
|
|
18742
|
+
" fi",
|
|
18743
|
+
"",
|
|
18744
|
+
" printf '%s\\n' \"react-doctor: command not found; skipping staged scan.\"",
|
|
18745
|
+
"}",
|
|
18746
|
+
"",
|
|
18747
|
+
"react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\")",
|
|
18748
|
+
"if react_doctor_scan_staged_files > \"$react_doctor_output\" 2>&1; then",
|
|
18749
|
+
" rm -f \"$react_doctor_output\"",
|
|
18750
|
+
"else",
|
|
18751
|
+
" rm -f \"$react_doctor_output\"",
|
|
18752
|
+
` printf '%s\\n' "React Doctor found staged regressions." "Run ${REACT_DOCTOR_COMMAND} to inspect." "Want them fixed? Ask your agent to run that command and resolve the findings." >&2`,
|
|
18753
|
+
"fi",
|
|
18754
|
+
REACT_DOCTOR_BLOCK_END
|
|
18755
|
+
].join("\n");
|
|
18756
|
+
const mergeHookContent = (existingContent) => {
|
|
18757
|
+
const hookBlock = `${buildReactDoctorHookBlock()}\n`;
|
|
18758
|
+
if (REACT_DOCTOR_BLOCK_PATTERN.test(existingContent)) return ensureTrailingNewline(existingContent.replace(REACT_DOCTOR_BLOCK_PATTERN, hookBlock));
|
|
18759
|
+
if (existingContent.length === 0) return `${SHEBANG}\n\n${hookBlock}`;
|
|
18760
|
+
const normalizedExistingContent = ensureTrailingNewline(existingContent);
|
|
18761
|
+
if (normalizedExistingContent.startsWith(SHEBANG_PREFIX)) {
|
|
18762
|
+
const [shebangLine, ...remainingLines] = normalizedExistingContent.split("\n");
|
|
18763
|
+
return [
|
|
18764
|
+
shebangLine,
|
|
18765
|
+
"",
|
|
18766
|
+
hookBlock.trimEnd(),
|
|
18767
|
+
...remainingLines
|
|
18768
|
+
].join("\n");
|
|
18829
18769
|
}
|
|
18830
|
-
return {
|
|
18770
|
+
return `${SHEBANG}\n\n${hookBlock}${normalizedExistingContent}`;
|
|
18831
18771
|
};
|
|
18832
|
-
const
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
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.`;
|
|
18839
|
-
return `React Doctor pre-commit hook ${hookResult.status} at ${hookResult.hookPath}.`;
|
|
18772
|
+
const removeLegacyManagedRunner = (projectRoot) => {
|
|
18773
|
+
const runnerPath = path$1.join(projectRoot, LEGACY_HOOK_RUNNER_RELATIVE_PATH);
|
|
18774
|
+
fs$1.rmSync(runnerPath, { force: true });
|
|
18775
|
+
for (const directory of [path$1.dirname(runnerPath), path$1.join(projectRoot, ".react-doctor")]) try {
|
|
18776
|
+
fs$1.rmdirSync(directory);
|
|
18777
|
+
} catch {}
|
|
18840
18778
|
};
|
|
18841
|
-
const
|
|
18842
|
-
const
|
|
18843
|
-
const
|
|
18844
|
-
if (
|
|
18845
|
-
|
|
18846
|
-
|
|
18847
|
-
|
|
18848
|
-
|
|
18849
|
-
|
|
18850
|
-
|
|
18779
|
+
const installDirectGitHook = (options) => {
|
|
18780
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18781
|
+
const nextContent = mergeHookContent(didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "");
|
|
18782
|
+
if (options.hooksPathConfig !== void 0) runGit(options.projectRoot, [
|
|
18783
|
+
"config",
|
|
18784
|
+
"core.hooksPath",
|
|
18785
|
+
options.hooksPathConfig
|
|
18786
|
+
]);
|
|
18787
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18788
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18789
|
+
fs$1.chmodSync(options.hookPath, 493);
|
|
18790
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18791
|
+
return {
|
|
18792
|
+
hookPath: options.hookPath,
|
|
18793
|
+
kind: options.kind ?? "git",
|
|
18794
|
+
status: didHookExist ? "updated" : "created"
|
|
18795
|
+
};
|
|
18851
18796
|
};
|
|
18852
|
-
|
|
18853
|
-
|
|
18854
|
-
|
|
18855
|
-
|
|
18856
|
-
|
|
18857
|
-
|
|
18858
|
-
|
|
18797
|
+
//#endregion
|
|
18798
|
+
//#region src/cli/utils/install-git-hook-config-managers.ts
|
|
18799
|
+
const appendStringCommand = (existingCommand) => {
|
|
18800
|
+
const existingCommandText = typeof existingCommand === "string" ? existingCommand : Array.isArray(existingCommand) ? existingCommand.filter((entry) => typeof entry === "string").join("\n") : "";
|
|
18801
|
+
return existingCommandText.includes("react-doctor --staged --blocking warning") ? existingCommandText : [existingCommandText, NON_BLOCKING_REACT_DOCTOR_COMMAND].filter(Boolean).join("\n");
|
|
18802
|
+
};
|
|
18803
|
+
const appendArrayCommand = (existingCommands) => {
|
|
18804
|
+
const commands = Array.isArray(existingCommands) ? existingCommands.filter((entry) => typeof entry === "string") : typeof existingCommands === "string" ? [existingCommands] : [];
|
|
18805
|
+
return commands.some((command) => command.includes("react-doctor --staged --blocking warning")) ? commands : [...commands, NON_BLOCKING_REACT_DOCTOR_COMMAND];
|
|
18806
|
+
};
|
|
18807
|
+
const installPackageJsonHook = (options, strategy) => {
|
|
18808
|
+
const packageJsonPath = getPackageJsonPath(options.projectRoot);
|
|
18809
|
+
const didHookExist = fs$1.existsSync(packageJsonPath);
|
|
18810
|
+
const packageJson = readPackageJson(options.projectRoot);
|
|
18811
|
+
const nextPackageJson = isRecord(packageJson) ? { ...packageJson } : {};
|
|
18812
|
+
const parentKeys = strategy.path.slice(0, -1);
|
|
18813
|
+
const leafKey = strategy.path[strategy.path.length - 1];
|
|
18814
|
+
let parent = nextPackageJson;
|
|
18815
|
+
for (const key of parentKeys) {
|
|
18816
|
+
const existing = parent[key];
|
|
18817
|
+
const cloned = isRecord(existing) ? { ...existing } : {};
|
|
18818
|
+
parent[key] = cloned;
|
|
18819
|
+
parent = cloned;
|
|
18820
|
+
}
|
|
18821
|
+
parent[leafKey] = strategy.leafShape === "array" ? appendArrayCommand(parent[leafKey]) : appendStringCommand(parent[leafKey]);
|
|
18822
|
+
writeJsonFile$1(packageJsonPath, nextPackageJson);
|
|
18823
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18824
|
+
return {
|
|
18825
|
+
hookPath: packageJsonPath,
|
|
18826
|
+
kind: strategy.kind,
|
|
18827
|
+
status: didHookExist ? "updated" : "created"
|
|
18828
|
+
};
|
|
18829
|
+
};
|
|
18830
|
+
const installSimpleGitHooks = (options) => installPackageJsonHook(options, {
|
|
18831
|
+
kind: "simple-git-hooks",
|
|
18832
|
+
path: ["simple-git-hooks", "pre-commit"],
|
|
18833
|
+
leafShape: "string"
|
|
18834
|
+
});
|
|
18835
|
+
const installGhooks = (options) => installPackageJsonHook(options, {
|
|
18836
|
+
kind: "ghooks",
|
|
18837
|
+
path: [
|
|
18838
|
+
"config",
|
|
18839
|
+
"ghooks",
|
|
18840
|
+
"pre-commit"
|
|
18841
|
+
],
|
|
18842
|
+
leafShape: "string"
|
|
18843
|
+
});
|
|
18844
|
+
const installPreCommitNpm = (options) => installPackageJsonHook(options, {
|
|
18845
|
+
kind: "pre-commit-npm",
|
|
18846
|
+
path: ["pre-commit"],
|
|
18847
|
+
leafShape: "array"
|
|
18848
|
+
});
|
|
18849
|
+
const installPrettyQuick = (options) => installPackageJsonHook(options, {
|
|
18850
|
+
kind: "pretty-quick",
|
|
18851
|
+
path: ["gitHooks", "pre-commit"],
|
|
18852
|
+
leafShape: "string"
|
|
18853
|
+
});
|
|
18854
|
+
const installYorkie = (options) => installPackageJsonHook(options, {
|
|
18855
|
+
kind: "yorkie",
|
|
18856
|
+
path: ["gitHooks", "pre-commit"],
|
|
18857
|
+
leafShape: "string"
|
|
18858
|
+
});
|
|
18859
|
+
const installGitHooksJs = (options) => installPackageJsonHook(options, {
|
|
18860
|
+
kind: "git-hooks-js",
|
|
18861
|
+
path: ["git-hooks", "pre-commit"],
|
|
18862
|
+
leafShape: "string"
|
|
18863
|
+
});
|
|
18864
|
+
const appendIndentedBlockToTopLevelSection = (content, sectionName, block) => {
|
|
18865
|
+
const normalizedContent = ensureTrailingNewline(content);
|
|
18866
|
+
const match = new RegExp(`^${sectionName}:\\s*$`, "m").exec(normalizedContent);
|
|
18867
|
+
if (match === null) return ensureTrailingNewline([
|
|
18868
|
+
normalizedContent.trimEnd(),
|
|
18869
|
+
"",
|
|
18870
|
+
`${sectionName}:`,
|
|
18871
|
+
...block,
|
|
18872
|
+
""
|
|
18873
|
+
].filter((line, index) => index > 0 || line.length > 0).join("\n"));
|
|
18874
|
+
const sectionStartIndex = match.index;
|
|
18875
|
+
const nextSectionPattern = /^[A-Za-z0-9_-]+:\s*$/gm;
|
|
18876
|
+
nextSectionPattern.lastIndex = sectionStartIndex + match[0].length;
|
|
18877
|
+
let nextSectionMatch = nextSectionPattern.exec(normalizedContent);
|
|
18878
|
+
while (nextSectionMatch !== null && nextSectionMatch.index === sectionStartIndex) nextSectionMatch = nextSectionPattern.exec(normalizedContent);
|
|
18879
|
+
const insertIndex = nextSectionMatch?.index ?? normalizedContent.length;
|
|
18880
|
+
const prefix = normalizedContent.slice(0, insertIndex).trimEnd();
|
|
18881
|
+
const suffix = normalizedContent.slice(insertIndex);
|
|
18882
|
+
return ensureTrailingNewline([
|
|
18883
|
+
prefix,
|
|
18884
|
+
...block,
|
|
18885
|
+
suffix.trimStart()
|
|
18886
|
+
].join("\n"));
|
|
18859
18887
|
};
|
|
18860
|
-
const
|
|
18861
|
-
|
|
18862
|
-
|
|
18888
|
+
const findTopLevelSectionRange = (content, sectionName) => {
|
|
18889
|
+
const match = new RegExp(`^${sectionName}:\\s*$`, "m").exec(content);
|
|
18890
|
+
if (match === null) return null;
|
|
18891
|
+
const headerLineEndIndex = content.indexOf("\n", match.index);
|
|
18892
|
+
const headerEndIndex = headerLineEndIndex === -1 ? match.index + match[0].length : headerLineEndIndex + 1;
|
|
18893
|
+
const nextSectionPattern = /^[A-Za-z0-9_-]+:\s*$/gm;
|
|
18894
|
+
nextSectionPattern.lastIndex = headerEndIndex;
|
|
18895
|
+
return {
|
|
18896
|
+
headerEndIndex,
|
|
18897
|
+
contentEndIndex: nextSectionPattern.exec(content)?.index ?? content.length
|
|
18898
|
+
};
|
|
18863
18899
|
};
|
|
18864
|
-
const
|
|
18865
|
-
const
|
|
18866
|
-
|
|
18867
|
-
|
|
18868
|
-
|
|
18869
|
-
|
|
18870
|
-
|
|
18871
|
-
|
|
18872
|
-
|
|
18900
|
+
const appendLefthookCommand = (content) => {
|
|
18901
|
+
const normalizedContent = ensureTrailingNewline(content);
|
|
18902
|
+
const sectionRange = findTopLevelSectionRange(normalizedContent, "pre-commit");
|
|
18903
|
+
const reactDoctorCommandBlock = [
|
|
18904
|
+
" react-doctor:",
|
|
18905
|
+
` run: ${NON_BLOCKING_REACT_DOCTOR_COMMAND}`,
|
|
18906
|
+
""
|
|
18907
|
+
];
|
|
18908
|
+
if (sectionRange === null) return ensureTrailingNewline([
|
|
18909
|
+
normalizedContent.trimEnd(),
|
|
18910
|
+
"",
|
|
18911
|
+
"pre-commit:",
|
|
18912
|
+
" commands:",
|
|
18913
|
+
...reactDoctorCommandBlock
|
|
18914
|
+
].filter((line, index) => index > 0 || line.length > 0).join("\n"));
|
|
18915
|
+
const sectionContent = normalizedContent.slice(sectionRange.headerEndIndex, sectionRange.contentEndIndex);
|
|
18916
|
+
const commandsMatch = /^ commands:\s*$/m.exec(sectionContent);
|
|
18917
|
+
const insertIndex = commandsMatch === null ? sectionRange.headerEndIndex : sectionRange.headerEndIndex + sectionContent.indexOf(commandsMatch[0]) + commandsMatch[0].length + 1;
|
|
18918
|
+
const insertBlock = commandsMatch === null ? [" commands:", ...reactDoctorCommandBlock].join("\n") : reactDoctorCommandBlock.join("\n");
|
|
18919
|
+
return ensureTrailingNewline(`${normalizedContent.slice(0, insertIndex)}${insertBlock}${normalizedContent.slice(insertIndex)}`);
|
|
18873
18920
|
};
|
|
18874
|
-
const
|
|
18875
|
-
|
|
18876
|
-
const
|
|
18877
|
-
|
|
18878
|
-
const
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
});
|
|
18882
|
-
recordCount(METRIC.installDependency, 1, {
|
|
18883
|
-
status: dependencyResult.dependencyStatus,
|
|
18884
|
-
reason: dependencyResult.dependencyReason ?? null,
|
|
18885
|
-
packageManager: detectPackageManager(projectRoot)
|
|
18886
|
-
});
|
|
18887
|
-
if (dependencyResult.dependencyStatus === "skipped") {
|
|
18888
|
-
const message = formatDependencyInstallMessage(dependencyResult);
|
|
18889
|
-
if (dependencyResult.dependencyReason === "trust-policy-blocked") dependencySpinner.warn(message);
|
|
18890
|
-
else dependencySpinner.fail(message);
|
|
18891
|
-
const followUp = buildDependencyFollowUp(dependencyResult);
|
|
18892
|
-
if (followUp !== void 0) cliLogger.dim(followUp);
|
|
18893
|
-
return dependencyResult;
|
|
18894
|
-
}
|
|
18895
|
-
dependencySpinner.succeed(formatDependencyInstallMessage(dependencyResult));
|
|
18896
|
-
return dependencyResult;
|
|
18897
|
-
} catch (error) {
|
|
18898
|
-
dependencySpinner.fail("Failed to install React Doctor package.");
|
|
18899
|
-
throw error;
|
|
18921
|
+
const installLefthook = (options) => {
|
|
18922
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18923
|
+
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18924
|
+
if (!existingContent.includes("react-doctor")) {
|
|
18925
|
+
const nextContent = appendLefthookCommand(existingContent);
|
|
18926
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18927
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18900
18928
|
}
|
|
18929
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18930
|
+
return {
|
|
18931
|
+
hookPath: options.hookPath,
|
|
18932
|
+
kind: "lefthook",
|
|
18933
|
+
status: didHookExist ? "updated" : "created"
|
|
18934
|
+
};
|
|
18901
18935
|
};
|
|
18902
|
-
const
|
|
18903
|
-
const
|
|
18904
|
-
|
|
18905
|
-
|
|
18906
|
-
const
|
|
18907
|
-
|
|
18908
|
-
|
|
18909
|
-
|
|
18910
|
-
|
|
18911
|
-
|
|
18912
|
-
|
|
18913
|
-
|
|
18914
|
-
|
|
18915
|
-
|
|
18916
|
-
|
|
18917
|
-
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
agents: [...agents],
|
|
18921
|
-
cwd: projectRoot,
|
|
18922
|
-
mode: "copy"
|
|
18923
|
-
});
|
|
18924
|
-
if (result.failed.length > 0) throw new Error(result.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
18925
|
-
if (result.skills.length > 0) installedSkillNames.push(sibling.name);
|
|
18936
|
+
const installPreCommit = (options) => {
|
|
18937
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18938
|
+
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18939
|
+
if (!existingContent.includes("id: react-doctor")) {
|
|
18940
|
+
const hasReposKey = /^repos:\s*$/m.test(existingContent);
|
|
18941
|
+
const localHookBlock = [
|
|
18942
|
+
" - repo: local",
|
|
18943
|
+
" hooks:",
|
|
18944
|
+
" - id: react-doctor",
|
|
18945
|
+
" name: react-doctor",
|
|
18946
|
+
` entry: sh -c '${NON_BLOCKING_REACT_DOCTOR_COMMAND}'`,
|
|
18947
|
+
" language: system",
|
|
18948
|
+
" pass_filenames: false",
|
|
18949
|
+
""
|
|
18950
|
+
].join("\n");
|
|
18951
|
+
const nextContent = hasReposKey ? `${ensureTrailingNewline(existingContent)}${localHookBlock}` : `repos:\n${localHookBlock}`;
|
|
18952
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18953
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18926
18954
|
}
|
|
18927
|
-
|
|
18955
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18956
|
+
return {
|
|
18957
|
+
hookPath: options.hookPath,
|
|
18958
|
+
kind: "pre-commit",
|
|
18959
|
+
status: didHookExist ? "updated" : "created"
|
|
18960
|
+
};
|
|
18928
18961
|
};
|
|
18929
|
-
const
|
|
18930
|
-
const
|
|
18931
|
-
const
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
cliLogger.error("No supported coding agents detected.");
|
|
18942
|
-
cliLogger.dim(" Looked for binaries on PATH (claude, codex, cursor, droid, gemini, copilot, opencode, pi)");
|
|
18943
|
-
cliLogger.dim(" and config dirs in $HOME (~/.claude, ~/.cursor, ~/.codex, ~/.gemini, ...).");
|
|
18944
|
-
process.exitCode = 1;
|
|
18945
|
-
return;
|
|
18946
|
-
}
|
|
18947
|
-
const skipPrompts = shouldSkipPrompts({ yes: options.yes });
|
|
18948
|
-
const gitHookTarget = options.gitHookPath === void 0 ? detectGitHookTarget(projectRoot) : options.gitHookPath === null ? null : buildManualGitHookTarget(options.gitHookPath, projectRoot);
|
|
18949
|
-
const gitHookPath = gitHookTarget?.hookPath;
|
|
18950
|
-
const promptOptions = options.onPromptCancel === void 0 ? {} : { onCancel: options.onPromptCancel };
|
|
18951
|
-
const prompt = options.prompt ?? prompts;
|
|
18952
|
-
const selectedAgents = skipPrompts ? detectedAgents : (await prompt({
|
|
18953
|
-
type: "multiselect",
|
|
18954
|
-
name: "agents",
|
|
18955
|
-
message: `Install the ${highlighter.info(`/react-doctor`)} skill for:`,
|
|
18956
|
-
choices: detectedAgents.map((agent) => ({
|
|
18957
|
-
title: getSkillAgentConfig(agent).displayName,
|
|
18958
|
-
value: agent,
|
|
18959
|
-
selected: true
|
|
18960
|
-
})),
|
|
18961
|
-
instructions: false,
|
|
18962
|
-
min: 1
|
|
18963
|
-
}, promptOptions)).agents ?? [];
|
|
18964
|
-
if (selectedAgents.length === 0) return;
|
|
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
|
-
}
|
|
18962
|
+
const installOvercommit = (options) => {
|
|
18963
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18964
|
+
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18965
|
+
if (!existingContent.includes("ReactDoctor")) {
|
|
18966
|
+
const nextContent = appendIndentedBlockToTopLevelSection(existingContent, "PreCommit", [
|
|
18967
|
+
" ReactDoctor:",
|
|
18968
|
+
" enabled: true",
|
|
18969
|
+
` command: ['sh', '-c', '${NON_BLOCKING_REACT_DOCTOR_COMMAND}']`,
|
|
18970
|
+
""
|
|
18971
|
+
]);
|
|
18972
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18973
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
19054
18974
|
}
|
|
19055
|
-
|
|
19056
|
-
|
|
19057
|
-
|
|
19058
|
-
|
|
19059
|
-
|
|
19060
|
-
|
|
19061
|
-
|
|
19062
|
-
|
|
19063
|
-
|
|
19064
|
-
|
|
19065
|
-
|
|
19066
|
-
|
|
19067
|
-
|
|
19068
|
-
|
|
19069
|
-
|
|
19070
|
-
|
|
18975
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18976
|
+
return {
|
|
18977
|
+
hookPath: options.hookPath,
|
|
18978
|
+
kind: "overcommit",
|
|
18979
|
+
status: didHookExist ? "updated" : "created"
|
|
18980
|
+
};
|
|
18981
|
+
};
|
|
18982
|
+
//#endregion
|
|
18983
|
+
//#region src/cli/utils/install-git-hook.ts
|
|
18984
|
+
const isHuskyProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, ".husky")) || packageHasDependency(projectRoot, "husky");
|
|
18985
|
+
const isVitePlusProject = (projectRoot) => packageHasDependency(projectRoot, "vite-plus");
|
|
18986
|
+
const isSimpleGitHooksProject = (projectRoot) => {
|
|
18987
|
+
const packageJson = readPackageJson(projectRoot);
|
|
18988
|
+
return isRecord(packageJson) && isRecord(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || fs$1.existsSync(path$1.join(projectRoot, ".simple-git-hooks.cjs"));
|
|
18989
|
+
};
|
|
18990
|
+
const getLefthookConfigPath = (projectRoot) => {
|
|
18991
|
+
for (const fileName of LEFTHOOK_CONFIG_FILES) {
|
|
18992
|
+
const filePath = path$1.join(projectRoot, fileName);
|
|
18993
|
+
if (fs$1.existsSync(filePath)) return filePath;
|
|
19071
18994
|
}
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
19076
|
-
|
|
19077
|
-
|
|
19078
|
-
|
|
19079
|
-
|
|
19080
|
-
|
|
19081
|
-
|
|
19082
|
-
|
|
18995
|
+
return packageHasDependency(projectRoot, "lefthook") ? path$1.join(projectRoot, LEFTHOOK_CONFIG_FILES[0] ?? "lefthook.yml") : null;
|
|
18996
|
+
};
|
|
18997
|
+
const isPreCommitProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, PRE_COMMIT_CONFIG_FILE));
|
|
18998
|
+
const isOvercommitProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, ".overcommit.yml")) || packageHasDependency(projectRoot, "overcommit");
|
|
18999
|
+
const isYorkieProject = (projectRoot) => packageHasRecordKey(projectRoot, "gitHooks") || packageHasDependency(projectRoot, "yorkie");
|
|
19000
|
+
const isGhooksProject = (projectRoot) => packageHasDependency(projectRoot, "ghooks") || packageHasNestedRecordKey(projectRoot, "config", "ghooks");
|
|
19001
|
+
const isGitHooksJsProject = (projectRoot) => packageHasRecordKey(projectRoot, "git-hooks") || packageHasDependency(projectRoot, "git-hooks-js");
|
|
19002
|
+
const isPreCommitNpmProject = (projectRoot) => packageHasDependency(projectRoot, "pre-commit");
|
|
19003
|
+
const isPrettyQuickProject = (projectRoot) => packageHasDependency(projectRoot, "pretty-quick");
|
|
19004
|
+
const detectGitHookTarget = (projectRoot) => {
|
|
19005
|
+
if (runGit(projectRoot, ["rev-parse", "--is-inside-work-tree"]) !== "true") return null;
|
|
19006
|
+
const topLevel = runGit(projectRoot, ["rev-parse", "--show-toplevel"]) ?? projectRoot;
|
|
19007
|
+
const configuredHooksPath = runGit(projectRoot, [
|
|
19008
|
+
"config",
|
|
19009
|
+
"--path",
|
|
19010
|
+
"--get",
|
|
19011
|
+
"core.hooksPath"
|
|
19012
|
+
]);
|
|
19013
|
+
if (configuredHooksPath !== null && configuredHooksPath.length > 0) return {
|
|
19014
|
+
hookPath: path$1.join(resolveGitPath(topLevel, configuredHooksPath), HOOK_FILE_NAME),
|
|
19015
|
+
runnerRoot: topLevel,
|
|
19016
|
+
kind: "configured"
|
|
19017
|
+
};
|
|
19018
|
+
if (isHuskyProject(topLevel)) return {
|
|
19019
|
+
hookPath: path$1.join(topLevel, HUSKY_HOOKS_PATH, HOOK_FILE_NAME),
|
|
19020
|
+
runnerRoot: topLevel,
|
|
19021
|
+
kind: "husky",
|
|
19022
|
+
hooksPathConfig: HUSKY_HOOKS_PATH
|
|
19023
|
+
};
|
|
19024
|
+
if (isVitePlusProject(topLevel)) return {
|
|
19025
|
+
hookPath: path$1.join(topLevel, VITE_PLUS_HOOKS_PATH, HOOK_FILE_NAME),
|
|
19026
|
+
runnerRoot: topLevel,
|
|
19027
|
+
kind: "vite-plus",
|
|
19028
|
+
hooksPathConfig: VITE_PLUS_HOOKS_PATH
|
|
19029
|
+
};
|
|
19030
|
+
if (isSimpleGitHooksProject(topLevel)) return {
|
|
19031
|
+
hookPath: path$1.join(topLevel, "package.json"),
|
|
19032
|
+
runnerRoot: topLevel,
|
|
19033
|
+
kind: "simple-git-hooks"
|
|
19034
|
+
};
|
|
19035
|
+
const lefthookConfigPath = getLefthookConfigPath(topLevel);
|
|
19036
|
+
if (lefthookConfigPath !== null) return {
|
|
19037
|
+
hookPath: lefthookConfigPath,
|
|
19038
|
+
runnerRoot: topLevel,
|
|
19039
|
+
kind: "lefthook"
|
|
19040
|
+
};
|
|
19041
|
+
if (isPreCommitProject(topLevel)) return {
|
|
19042
|
+
hookPath: path$1.join(topLevel, PRE_COMMIT_CONFIG_FILE),
|
|
19043
|
+
runnerRoot: topLevel,
|
|
19044
|
+
kind: "pre-commit"
|
|
19045
|
+
};
|
|
19046
|
+
if (isOvercommitProject(topLevel)) return {
|
|
19047
|
+
hookPath: path$1.join(topLevel, OVERCOMMIT_CONFIG_FILE),
|
|
19048
|
+
runnerRoot: topLevel,
|
|
19049
|
+
kind: "overcommit"
|
|
19050
|
+
};
|
|
19051
|
+
if (isYorkieProject(topLevel)) return {
|
|
19052
|
+
hookPath: getPackageJsonPath(topLevel),
|
|
19053
|
+
runnerRoot: topLevel,
|
|
19054
|
+
kind: "yorkie"
|
|
19055
|
+
};
|
|
19056
|
+
if (isGhooksProject(topLevel)) return {
|
|
19057
|
+
hookPath: getPackageJsonPath(topLevel),
|
|
19058
|
+
runnerRoot: topLevel,
|
|
19059
|
+
kind: "ghooks"
|
|
19060
|
+
};
|
|
19061
|
+
if (isGitHooksJsProject(topLevel)) return {
|
|
19062
|
+
hookPath: getPackageJsonPath(topLevel),
|
|
19063
|
+
runnerRoot: topLevel,
|
|
19064
|
+
kind: "git-hooks-js"
|
|
19065
|
+
};
|
|
19066
|
+
if (isPreCommitNpmProject(topLevel)) return {
|
|
19067
|
+
hookPath: getPackageJsonPath(topLevel),
|
|
19068
|
+
runnerRoot: topLevel,
|
|
19069
|
+
kind: "pre-commit-npm"
|
|
19070
|
+
};
|
|
19071
|
+
if (isPrettyQuickProject(topLevel)) return {
|
|
19072
|
+
hookPath: getPackageJsonPath(topLevel),
|
|
19073
|
+
runnerRoot: topLevel,
|
|
19074
|
+
kind: "pretty-quick"
|
|
19075
|
+
};
|
|
19076
|
+
const hookPath = runGit(projectRoot, [
|
|
19077
|
+
"rev-parse",
|
|
19078
|
+
"--git-path",
|
|
19079
|
+
HOOK_RELATIVE_PATH
|
|
19080
|
+
]);
|
|
19081
|
+
if (hookPath === null || hookPath.length === 0) return null;
|
|
19082
|
+
return {
|
|
19083
|
+
hookPath: resolveGitPath(projectRoot, hookPath),
|
|
19084
|
+
runnerRoot: topLevel,
|
|
19085
|
+
kind: "git"
|
|
19086
|
+
};
|
|
19087
|
+
};
|
|
19088
|
+
const installReactDoctorGitHook = (options) => {
|
|
19089
|
+
if (options.kind === "simple-git-hooks") return installSimpleGitHooks(options);
|
|
19090
|
+
if (options.kind === "lefthook") return installLefthook(options);
|
|
19091
|
+
if (options.kind === "pre-commit") return installPreCommit(options);
|
|
19092
|
+
if (options.kind === "overcommit") return installOvercommit(options);
|
|
19093
|
+
if (options.kind === "yorkie") return installYorkie(options);
|
|
19094
|
+
if (options.kind === "ghooks") return installGhooks(options);
|
|
19095
|
+
if (options.kind === "git-hooks-js") return installGitHooksJs(options);
|
|
19096
|
+
if (options.kind === "pre-commit-npm") return installPreCommitNpm(options);
|
|
19097
|
+
if (options.kind === "pretty-quick") return installPrettyQuick(options);
|
|
19098
|
+
return installDirectGitHook(options);
|
|
19083
19099
|
};
|
|
19084
19100
|
//#endregion
|
|
19085
|
-
//#region src/cli/utils/
|
|
19086
|
-
const
|
|
19101
|
+
//#region src/cli/utils/should-skip-prompts.ts
|
|
19102
|
+
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.json) || isNonInteractiveEnvironment() || !process.stdin.isTTY;
|
|
19087
19103
|
//#endregion
|
|
19088
|
-
//#region src/cli/utils/
|
|
19089
|
-
const
|
|
19090
|
-
const
|
|
19091
|
-
|
|
19092
|
-
|
|
19093
|
-
|
|
19094
|
-
|
|
19095
|
-
|
|
19096
|
-
|
|
19097
|
-
|
|
19098
|
-
|
|
19099
|
-
|
|
19104
|
+
//#region src/cli/utils/install-react-doctor.ts
|
|
19105
|
+
const SETUP_OPTION_GIT_HOOK = "git-hook";
|
|
19106
|
+
const SETUP_OPTION_AGENT_HOOKS = "agent-hooks";
|
|
19107
|
+
const SETUP_OPTION_SKIP = "skip";
|
|
19108
|
+
const CONFIG_ONLY_GIT_HOOK_KINDS = new Set([
|
|
19109
|
+
"ghooks",
|
|
19110
|
+
"git-hooks-js",
|
|
19111
|
+
"lefthook",
|
|
19112
|
+
"overcommit",
|
|
19113
|
+
"pre-commit",
|
|
19114
|
+
"pre-commit-npm",
|
|
19115
|
+
"pretty-quick",
|
|
19116
|
+
"simple-git-hooks",
|
|
19117
|
+
"yorkie"
|
|
19118
|
+
]);
|
|
19119
|
+
const PACKAGE_MANAGER_LOCKFILES = [
|
|
19120
|
+
{
|
|
19121
|
+
packageManager: "pnpm",
|
|
19122
|
+
fileName: "pnpm-lock.yaml"
|
|
19123
|
+
},
|
|
19124
|
+
{
|
|
19125
|
+
packageManager: "yarn",
|
|
19126
|
+
fileName: "yarn.lock"
|
|
19127
|
+
},
|
|
19128
|
+
{
|
|
19129
|
+
packageManager: "bun",
|
|
19130
|
+
fileName: "bun.lockb"
|
|
19131
|
+
},
|
|
19132
|
+
{
|
|
19133
|
+
packageManager: "bun",
|
|
19134
|
+
fileName: "bun.lock"
|
|
19135
|
+
},
|
|
19136
|
+
{
|
|
19137
|
+
packageManager: "npm",
|
|
19138
|
+
fileName: "package-lock.json"
|
|
19100
19139
|
}
|
|
19101
|
-
|
|
19102
|
-
const
|
|
19103
|
-
|
|
19104
|
-
|
|
19105
|
-
|
|
19106
|
-
|
|
19107
|
-
|
|
19108
|
-
|
|
19109
|
-
rootDirectory: path$1.resolve(projectRoot),
|
|
19110
|
-
outcome,
|
|
19111
|
-
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
19112
|
-
}
|
|
19113
|
-
});
|
|
19114
|
-
return true;
|
|
19115
|
-
} catch {
|
|
19116
|
-
return false;
|
|
19140
|
+
];
|
|
19141
|
+
const findNearestFileDirectory = (startDirectory, fileNames) => {
|
|
19142
|
+
let currentDirectory = path$1.resolve(startDirectory);
|
|
19143
|
+
while (true) {
|
|
19144
|
+
if (fileNames.some((fileName) => fs$1.existsSync(path$1.join(currentDirectory, fileName)))) return currentDirectory;
|
|
19145
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
19146
|
+
if (parentDirectory === currentDirectory) return null;
|
|
19147
|
+
currentDirectory = parentDirectory;
|
|
19117
19148
|
}
|
|
19118
19149
|
};
|
|
19119
|
-
|
|
19120
|
-
|
|
19121
|
-
|
|
19122
|
-
|
|
19123
|
-
|
|
19124
|
-
|
|
19125
|
-
|
|
19126
|
-
|
|
19127
|
-
|
|
19128
|
-
|
|
19129
|
-
|
|
19130
|
-
|
|
19150
|
+
const detectPackageManager = (projectRoot) => {
|
|
19151
|
+
let currentDirectory = path$1.resolve(projectRoot);
|
|
19152
|
+
while (true) {
|
|
19153
|
+
const packageJson = readPackageJson(currentDirectory);
|
|
19154
|
+
if (isRecord(packageJson) && typeof packageJson.packageManager === "string") {
|
|
19155
|
+
const packageManagerName = packageJson.packageManager.split("@")[0];
|
|
19156
|
+
if (packageManagerName === "pnpm" || packageManagerName === "yarn" || packageManagerName === "bun" || packageManagerName === "npm") return packageManagerName;
|
|
19157
|
+
}
|
|
19158
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
19159
|
+
if (parentDirectory === currentDirectory) break;
|
|
19160
|
+
currentDirectory = parentDirectory;
|
|
19161
|
+
}
|
|
19162
|
+
const lockfileDirectory = findNearestFileDirectory(projectRoot, PACKAGE_MANAGER_LOCKFILES.map((lockfile) => lockfile.fileName));
|
|
19163
|
+
return PACKAGE_MANAGER_LOCKFILES.find((lockfile) => lockfileDirectory !== null && fs$1.existsSync(path$1.join(lockfileDirectory, lockfile.fileName)))?.packageManager ?? "npm";
|
|
19131
19164
|
};
|
|
19132
|
-
|
|
19133
|
-
|
|
19134
|
-
const
|
|
19135
|
-
|
|
19136
|
-
|
|
19137
|
-
|
|
19165
|
+
const packageManagerNeedsWorkspaceFlag = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, "pnpm-workspace.yaml")) || findNearestFileDirectory(projectRoot, ["pnpm-workspace.yaml"]) !== null;
|
|
19166
|
+
const buildInstallCommand = (projectRoot) => {
|
|
19167
|
+
const packageManager = detectPackageManager(projectRoot);
|
|
19168
|
+
const packageSpecifier = `${DOCTOR_PACKAGE_NAME}@latest`;
|
|
19169
|
+
if (packageManager === "npm") return {
|
|
19170
|
+
command: "npm",
|
|
19171
|
+
args: [
|
|
19172
|
+
"install",
|
|
19173
|
+
"--save-dev",
|
|
19174
|
+
packageSpecifier
|
|
19175
|
+
],
|
|
19176
|
+
cwd: projectRoot
|
|
19138
19177
|
};
|
|
19139
|
-
if (
|
|
19140
|
-
command: "
|
|
19178
|
+
if (packageManager === "yarn") return {
|
|
19179
|
+
command: "yarn",
|
|
19180
|
+
args: [
|
|
19181
|
+
"add",
|
|
19182
|
+
"--dev",
|
|
19183
|
+
packageSpecifier
|
|
19184
|
+
],
|
|
19185
|
+
cwd: projectRoot
|
|
19186
|
+
};
|
|
19187
|
+
if (packageManager === "bun") return {
|
|
19188
|
+
command: "bun",
|
|
19141
19189
|
args: [
|
|
19142
|
-
"
|
|
19143
|
-
"
|
|
19144
|
-
|
|
19145
|
-
|
|
19146
|
-
|
|
19190
|
+
"add",
|
|
19191
|
+
"--dev",
|
|
19192
|
+
packageSpecifier
|
|
19193
|
+
],
|
|
19194
|
+
cwd: projectRoot
|
|
19147
19195
|
};
|
|
19148
19196
|
return {
|
|
19149
|
-
command: "
|
|
19150
|
-
args: [
|
|
19197
|
+
command: "pnpm",
|
|
19198
|
+
args: [
|
|
19199
|
+
"add",
|
|
19200
|
+
"--save-dev",
|
|
19201
|
+
...packageManagerNeedsWorkspaceFlag(projectRoot) ? ["-w"] : [],
|
|
19202
|
+
packageSpecifier
|
|
19203
|
+
],
|
|
19204
|
+
cwd: projectRoot
|
|
19151
19205
|
};
|
|
19152
19206
|
};
|
|
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
19207
|
const execFileAsync = promisify(execFile);
|
|
19176
|
-
const
|
|
19208
|
+
const defaultInstallDependencyRunner = async (input) => {
|
|
19209
|
+
await execFileAsync(input.command, [...input.args], {
|
|
19210
|
+
cwd: input.cwd,
|
|
19211
|
+
env: {
|
|
19212
|
+
...process.env,
|
|
19213
|
+
REACT_DOCTOR_INSTALL: "1"
|
|
19214
|
+
},
|
|
19215
|
+
shell: process.platform === "win32"
|
|
19216
|
+
});
|
|
19217
|
+
};
|
|
19218
|
+
const isSupplyChainTrustError = (error) => {
|
|
19219
|
+
const candidate = error;
|
|
19220
|
+
const haystack = [
|
|
19221
|
+
candidate?.stderr,
|
|
19222
|
+
candidate?.stdout,
|
|
19223
|
+
candidate?.message
|
|
19224
|
+
].map((part) => String(part ?? "")).join("\n");
|
|
19225
|
+
return /ERR_PNPM_TRUST_DOWNGRADE|trust downgrade/i.test(haystack);
|
|
19226
|
+
};
|
|
19227
|
+
const formatInstallCommand = (input) => [input.command, ...input.args].join(" ");
|
|
19228
|
+
const installReactDoctorDependency = async (options) => {
|
|
19229
|
+
const packageJson = readPackageJson(options.projectRoot);
|
|
19230
|
+
if (!isRecord(packageJson)) return {
|
|
19231
|
+
dependencyStatus: "skipped",
|
|
19232
|
+
dependencyReason: "missing-or-invalid-package-json"
|
|
19233
|
+
};
|
|
19234
|
+
if (hasDoctorDependency(packageJson)) return { dependencyStatus: "existing" };
|
|
19235
|
+
if (packageJson.devDependencies !== void 0 && !isRecord(packageJson.devDependencies)) return {
|
|
19236
|
+
dependencyStatus: "skipped",
|
|
19237
|
+
dependencyReason: "invalid-dev-dependencies"
|
|
19238
|
+
};
|
|
19239
|
+
const runnerInput = buildInstallCommand(options.projectRoot);
|
|
19177
19240
|
try {
|
|
19178
|
-
|
|
19179
|
-
cwd,
|
|
19180
|
-
encoding: "utf8"
|
|
19181
|
-
});
|
|
19182
|
-
return {
|
|
19183
|
-
success: true,
|
|
19184
|
-
stdout: stdout.trim(),
|
|
19185
|
-
stderr: stderr.trim()
|
|
19186
|
-
};
|
|
19241
|
+
await (options.runner ?? defaultInstallDependencyRunner)(runnerInput);
|
|
19187
19242
|
} catch (error) {
|
|
19188
|
-
const failure = error;
|
|
19189
19243
|
return {
|
|
19190
|
-
|
|
19191
|
-
|
|
19192
|
-
|
|
19244
|
+
dependencyStatus: "skipped",
|
|
19245
|
+
dependencyReason: isSupplyChainTrustError(error) ? "trust-policy-blocked" : "install-command-failed",
|
|
19246
|
+
installCommand: formatInstallCommand(runnerInput)
|
|
19193
19247
|
};
|
|
19194
19248
|
}
|
|
19249
|
+
return { dependencyStatus: "created" };
|
|
19195
19250
|
};
|
|
19196
|
-
const
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
|
|
19251
|
+
const buildManualGitHookTarget = (hookPath, projectRoot) => ({
|
|
19252
|
+
hookPath,
|
|
19253
|
+
runnerRoot: projectRoot,
|
|
19254
|
+
kind: "git"
|
|
19255
|
+
});
|
|
19256
|
+
const formatGitHookInstallMessage = (hookResult) => {
|
|
19257
|
+
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
|
+
return `React Doctor pre-commit hook ${hookResult.status} at ${hookResult.hookPath}.`;
|
|
19259
|
+
};
|
|
19260
|
+
const formatDependencyInstallMessage = (result) => {
|
|
19261
|
+
if (result.dependencyStatus === "created") return "Installed dev dependency: react-doctor.";
|
|
19262
|
+
if (result.dependencyStatus === "existing") return "React Doctor dependency already exists.";
|
|
19263
|
+
if (result.dependencyReason === "invalid-dev-dependencies") return "Skipped dev dependency install: devDependencies field is not an object.";
|
|
19264
|
+
if (result.dependencyReason === "trust-policy-blocked") return "Local install skipped by your package manager's supply-chain trust policy (safe to ignore for pre-release packages).";
|
|
19265
|
+
if (result.dependencyReason === "install-command-failed") return "Local install failed: your package manager rejected the command.";
|
|
19266
|
+
return "Skipped dev dependency install: package.json missing or invalid.";
|
|
19267
|
+
};
|
|
19268
|
+
const buildDependencyFollowUp = (result) => {
|
|
19269
|
+
if (result.dependencyReason !== "trust-policy-blocked" && result.dependencyReason !== "install-command-failed") return;
|
|
19270
|
+
return ` React Doctor still works via \`npx react-doctor\`. To install locally: ${result.installCommand ?? `npm install --save-dev react-doctor@latest`}`;
|
|
19271
|
+
};
|
|
19272
|
+
const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) => {
|
|
19273
|
+
installReactDoctorScriptStep(projectRoot);
|
|
19274
|
+
const dependencySpinner = spinner("Installing React Doctor package...").start();
|
|
19275
|
+
try {
|
|
19276
|
+
const dependencyResult = await installReactDoctorDependency({
|
|
19277
|
+
projectRoot,
|
|
19278
|
+
runner: dependencyRunner
|
|
19279
|
+
});
|
|
19280
|
+
recordCount(METRIC.installDependency, 1, {
|
|
19281
|
+
status: dependencyResult.dependencyStatus,
|
|
19282
|
+
reason: dependencyResult.dependencyReason ?? null,
|
|
19283
|
+
packageManager: detectPackageManager(projectRoot)
|
|
19284
|
+
});
|
|
19285
|
+
if (dependencyResult.dependencyStatus === "skipped") {
|
|
19286
|
+
const message = formatDependencyInstallMessage(dependencyResult);
|
|
19287
|
+
if (dependencyResult.dependencyReason === "trust-policy-blocked") dependencySpinner.warn(message);
|
|
19288
|
+
else dependencySpinner.fail(message);
|
|
19289
|
+
const followUp = buildDependencyFollowUp(dependencyResult);
|
|
19290
|
+
if (followUp !== void 0) cliLogger.dim(followUp);
|
|
19291
|
+
return dependencyResult;
|
|
19292
|
+
}
|
|
19293
|
+
dependencySpinner.succeed(formatDependencyInstallMessage(dependencyResult));
|
|
19294
|
+
return dependencyResult;
|
|
19295
|
+
} catch (error) {
|
|
19296
|
+
dependencySpinner.fail("Failed to install React Doctor package.");
|
|
19297
|
+
throw error;
|
|
19201
19298
|
}
|
|
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
19299
|
};
|
|
19214
|
-
const
|
|
19215
|
-
|
|
19216
|
-
|
|
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, "")}`;
|
|
19300
|
+
const getSkillSourceDirectory = () => {
|
|
19301
|
+
const distDirectory = path$1.dirname(fileURLToPath(import.meta.url));
|
|
19302
|
+
return path$1.join(distDirectory, "skills", SKILL_NAME);
|
|
19221
19303
|
};
|
|
19222
|
-
const
|
|
19223
|
-
const
|
|
19224
|
-
|
|
19225
|
-
const
|
|
19226
|
-
|
|
19227
|
-
|
|
19228
|
-
|
|
19229
|
-
|
|
19230
|
-
|
|
19231
|
-
|
|
19232
|
-
const
|
|
19233
|
-
|
|
19234
|
-
|
|
19235
|
-
|
|
19236
|
-
|
|
19237
|
-
|
|
19238
|
-
|
|
19239
|
-
|
|
19240
|
-
|
|
19241
|
-
|
|
19242
|
-
|
|
19243
|
-
|
|
19244
|
-
|
|
19245
|
-
|
|
19246
|
-
|
|
19247
|
-
|
|
19248
|
-
|
|
19249
|
-
|
|
19250
|
-
|
|
19251
|
-
|
|
19252
|
-
|
|
19253
|
-
|
|
19254
|
-
|
|
19255
|
-
|
|
19256
|
-
|
|
19257
|
-
"
|
|
19258
|
-
|
|
19259
|
-
|
|
19260
|
-
|
|
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
|
-
};
|
|
19304
|
+
const findBundledSiblingSkills = (primarySkillDir) => {
|
|
19305
|
+
const skillsParent = path$1.dirname(primarySkillDir);
|
|
19306
|
+
if (!fs$1.existsSync(skillsParent)) return [];
|
|
19307
|
+
const resolvedPrimary = path$1.resolve(primarySkillDir);
|
|
19308
|
+
return fs$1.readdirSync(skillsParent, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => ({
|
|
19309
|
+
name: entry.name,
|
|
19310
|
+
source: path$1.join(skillsParent, entry.name)
|
|
19311
|
+
})).filter((sibling) => path$1.resolve(sibling.source) !== resolvedPrimary && fs$1.existsSync(path$1.join(sibling.source, SKILL_MANIFEST_FILE)));
|
|
19312
|
+
};
|
|
19313
|
+
const installBundledSiblingSkills = async (primarySkillDir, agents, projectRoot) => {
|
|
19314
|
+
const installedSkillNames = [];
|
|
19315
|
+
for (const sibling of findBundledSiblingSkills(primarySkillDir)) {
|
|
19316
|
+
const result = await installSkillsFromSource({
|
|
19317
|
+
source: sibling.source,
|
|
19318
|
+
agents: [...agents],
|
|
19319
|
+
cwd: projectRoot,
|
|
19320
|
+
mode: "copy"
|
|
19321
|
+
});
|
|
19322
|
+
if (result.failed.length > 0) throw new Error(result.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
19323
|
+
if (result.skills.length > 0) installedSkillNames.push(sibling.name);
|
|
19324
|
+
}
|
|
19325
|
+
return installedSkillNames;
|
|
19326
|
+
};
|
|
19327
|
+
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;
|
|
19289
19343
|
}
|
|
19290
|
-
|
|
19291
|
-
|
|
19292
|
-
"
|
|
19293
|
-
|
|
19294
|
-
|
|
19295
|
-
await restoreToPreviousBranch(true);
|
|
19296
|
-
return {
|
|
19297
|
-
status: "not-attempted",
|
|
19298
|
-
reason: "git-commit-failed"
|
|
19299
|
-
};
|
|
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).");
|
|
19300
19349
|
}
|
|
19301
|
-
|
|
19302
|
-
|
|
19303
|
-
|
|
19304
|
-
|
|
19305
|
-
|
|
19306
|
-
|
|
19307
|
-
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
|
|
19311
|
-
|
|
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;
|
|
19312
19365
|
}
|
|
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
|
-
};
|
|
19334
19366
|
};
|
|
19335
|
-
const
|
|
19336
|
-
const
|
|
19337
|
-
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19341
|
-
|
|
19342
|
-
|
|
19343
|
-
|
|
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
|
+
const runInstallReactDoctor = async (options = {}) => {
|
|
19403
|
+
const requestedProjectRoot = options.projectRoot ?? process.cwd();
|
|
19404
|
+
const projectRoot = findNearestPackageDirectory(requestedProjectRoot) ?? requestedProjectRoot;
|
|
19405
|
+
const sourceDir = options.sourceDir ?? getSkillSourceDirectory();
|
|
19406
|
+
if (!fs$1.existsSync(path$1.join(sourceDir, SKILL_MANIFEST_FILE))) {
|
|
19407
|
+
cliLogger.error(`Could not locate the ${SKILL_NAME} skill bundled with this package.`);
|
|
19408
|
+
process.exitCode = 1;
|
|
19409
|
+
return;
|
|
19410
|
+
}
|
|
19411
|
+
const detectedAgents = options.detectedAgents ?? await detectAvailableAgents();
|
|
19412
|
+
if (detectedAgents.length === 0) {
|
|
19413
|
+
cliLogger.error("No supported coding agents detected.");
|
|
19414
|
+
cliLogger.dim(" Looked for binaries on PATH (claude, codex, cursor, droid, gemini, copilot, opencode, pi)");
|
|
19415
|
+
cliLogger.dim(" and config dirs in $HOME (~/.claude, ~/.cursor, ~/.codex, ~/.gemini, ...).");
|
|
19416
|
+
process.exitCode = 1;
|
|
19417
|
+
return;
|
|
19418
|
+
}
|
|
19419
|
+
const skipPrompts = shouldSkipPrompts({ yes: options.yes });
|
|
19420
|
+
const gitHookTarget = options.gitHookPath === void 0 ? detectGitHookTarget(projectRoot) : options.gitHookPath === null ? null : buildManualGitHookTarget(options.gitHookPath, projectRoot);
|
|
19421
|
+
const gitHookPath = gitHookTarget?.hookPath;
|
|
19422
|
+
const promptOptions = options.onPromptCancel === void 0 ? {} : { onCancel: options.onPromptCancel };
|
|
19423
|
+
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
|
+
const selectedAgents = skipPrompts ? detectedAgents : (await prompt({
|
|
19433
|
+
type: "multiselect",
|
|
19434
|
+
name: "agents",
|
|
19435
|
+
message: `Install the ${highlighter.info(`/react-doctor`)} skill for:`,
|
|
19436
|
+
choices: detectedAgents.map((agent) => ({
|
|
19437
|
+
title: getSkillAgentConfig(agent).displayName,
|
|
19438
|
+
value: agent,
|
|
19439
|
+
selected: true
|
|
19440
|
+
})),
|
|
19441
|
+
instructions: false,
|
|
19442
|
+
min: 1
|
|
19443
|
+
}, promptOptions)).agents ?? [];
|
|
19444
|
+
if (selectedAgents.length === 0) return;
|
|
19445
|
+
let dependencyResult;
|
|
19446
|
+
if (!options.dryRun) {
|
|
19447
|
+
await installReactDoctorSkillStep(sourceDir, selectedAgents, projectRoot);
|
|
19448
|
+
dependencyResult = await installReactDoctorPackageSetup(projectRoot, options.installDependencyRunner);
|
|
19449
|
+
}
|
|
19450
|
+
let didInstallWorkflow = false;
|
|
19451
|
+
if (!options.dryRun && (shouldInstallWorkflow || shouldUpgradeWorkflow)) {
|
|
19452
|
+
cliLogger.break();
|
|
19453
|
+
if (shouldInstallWorkflow) didInstallWorkflow = installReactDoctorWorkflowStep(projectRoot);
|
|
19454
|
+
else if (upgradeReactDoctorWorkflowStep(projectRoot)) recordActionUpgradeDecision(projectRoot, "accepted");
|
|
19455
|
+
}
|
|
19456
|
+
const setupActionChoices = [...gitHookPath === null || gitHookPath === void 0 ? [] : [{
|
|
19457
|
+
title: "Pre-commit hook",
|
|
19458
|
+
description: "Check staged changes before each commit",
|
|
19459
|
+
value: SETUP_OPTION_GIT_HOOK,
|
|
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);
|
|
19488
|
+
}
|
|
19489
|
+
if (options.dryRun) {
|
|
19490
|
+
cliLogger.log(`Dry run — would install ${SKILL_NAME} skill for:`);
|
|
19491
|
+
for (const agent of selectedAgents) cliLogger.dim(` - ${getSkillAgentConfig(agent).displayName}`);
|
|
19492
|
+
cliLogger.dim(` Source: ${sourceDir}`);
|
|
19493
|
+
for (const sibling of findBundledSiblingSkills(sourceDir)) cliLogger.dim(` Also installs skill: ${sibling.name}`);
|
|
19494
|
+
cliLogger.dim(" Package script: doctor (or react-doctor if doctor exists)");
|
|
19495
|
+
cliLogger.dim(" Dev dependency: react-doctor");
|
|
19496
|
+
if (shouldInstallGitHook) cliLogger.dim(` Git hook: ${gitHookPath}`);
|
|
19497
|
+
if (shouldInstallAgentHooks) cliLogger.dim(" Agent hooks: Claude Code / Cursor when selected");
|
|
19498
|
+
if (shouldInstallWorkflow) cliLogger.dim(` GitHub Actions workflow: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
19499
|
+
if (shouldUpgradeWorkflow) cliLogger.dim(` Upgrade GitHub Actions workflow to v2: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
19500
|
+
return;
|
|
19501
|
+
}
|
|
19502
|
+
recordCount(METRIC.installCompleted, 1, {
|
|
19503
|
+
agentsCount: selectedAgents.length,
|
|
19504
|
+
gitHook: shouldInstallGitHook,
|
|
19505
|
+
agentHooks: shouldInstallAgentHooks,
|
|
19506
|
+
workflow: didInstallWorkflow,
|
|
19507
|
+
dependencyStatus: dependencyResult?.dependencyStatus ?? "skipped",
|
|
19508
|
+
packageManager: detectPackageManager(projectRoot)
|
|
19509
|
+
});
|
|
19510
|
+
for (const agent of selectedAgents) recordCount(METRIC.installAgent, 1, { agent });
|
|
19511
|
+
};
|
|
19512
|
+
//#endregion
|
|
19513
|
+
//#region src/cli/utils/install-skill-for-agent.ts
|
|
19514
|
+
const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
|
|
19515
|
+
const source = getSkillSourceDirectory();
|
|
19516
|
+
if (!fs$1.existsSync(path$1.join(source, SKILL_MANIFEST_FILE))) return false;
|
|
19517
|
+
const result = await installSkillsFromSource({
|
|
19518
|
+
source,
|
|
19519
|
+
agents: [agent],
|
|
19520
|
+
cwd: projectRoot,
|
|
19521
|
+
mode: "copy"
|
|
19522
|
+
});
|
|
19523
|
+
return result.skills.length > 0 && result.failed.length === 0;
|
|
19344
19524
|
};
|
|
19345
19525
|
//#endregion
|
|
19346
19526
|
//#region src/cli/utils/launch-agent.ts
|
|
@@ -19431,9 +19611,6 @@ const copyToClipboard = (text) => {
|
|
|
19431
19611
|
};
|
|
19432
19612
|
//#endregion
|
|
19433
19613
|
//#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";
|
|
19437
19614
|
const CLIPBOARD_CHOICE = "clipboard";
|
|
19438
19615
|
const SKIP_CHOICE = "skip";
|
|
19439
19616
|
const printPayload = (payload) => {
|
|
@@ -19442,59 +19619,11 @@ const printPayload = (payload) => {
|
|
|
19442
19619
|
cliLogger.log(payload);
|
|
19443
19620
|
cliLogger.log(highlighter.dim("──────────────────────"));
|
|
19444
19621
|
};
|
|
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";
|
|
19473
19622
|
const UPGRADE_COMMIT_MESSAGE = "ci: upgrade React Doctor GitHub Action to v2";
|
|
19474
19623
|
const UPGRADE_PR_TITLE = "Upgrade React Doctor Action to v2";
|
|
19475
19624
|
const UPGRADE_PR_BODY = `Bumps the React Doctor GitHub Actions workflow to the action's latest major, \`millionco/react-doctor@v2\`.
|
|
19476
19625
|
|
|
19477
19626
|
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
|
-
};
|
|
19498
19627
|
const upgradeGitHubActionsWorkflow = async (workflow) => {
|
|
19499
19628
|
const { content, changed } = upgradeWorkflowActionToV2(workflow.content);
|
|
19500
19629
|
if (!changed) return false;
|
|
@@ -19539,46 +19668,6 @@ const maybeOfferActionUpgrade = async (projectRoot) => {
|
|
|
19539
19668
|
}
|
|
19540
19669
|
if (await upgradeGitHubActionsWorkflow(workflow)) recordActionUpgradeDecision(projectRoot, "accepted");
|
|
19541
19670
|
};
|
|
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
|
-
};
|
|
19582
19671
|
const detectLaunchableAgents = async () => {
|
|
19583
19672
|
const detected = new Set(await detectAvailableAgents());
|
|
19584
19673
|
return Object.keys(CLI_AGENT_BINARIES).filter((agentId) => detected.has(agentId) && isCommandAvailable(CLI_AGENT_BINARIES[agentId]));
|
|
@@ -19595,7 +19684,7 @@ const handoffToAgent = async (input) => {
|
|
|
19595
19684
|
});
|
|
19596
19685
|
if (ciOutcome === "cancel") return;
|
|
19597
19686
|
if (ciOutcome === "yes") {
|
|
19598
|
-
await setUpGitHubActions(input.rootDirectory);
|
|
19687
|
+
await setUpGitHubActions({ rootDirectory: input.rootDirectory });
|
|
19599
19688
|
cliLogger.break();
|
|
19600
19689
|
}
|
|
19601
19690
|
} else await maybeOfferActionUpgrade(projectRootForCi);
|
|
@@ -19746,6 +19835,14 @@ const HAPPY_FACE_LINES = [
|
|
|
19746
19835
|
"│ ▽ │",
|
|
19747
19836
|
"└─────┘"
|
|
19748
19837
|
];
|
|
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
|
+
};
|
|
19749
19846
|
const typeLine = (linePrefix, text, style, charDelayMs) => Effect.gen(function* () {
|
|
19750
19847
|
const characters = [...text];
|
|
19751
19848
|
for (let length = 1; length <= characters.length; length += 1) {
|
|
@@ -19759,13 +19856,17 @@ const playWelcomeScene = (options = {}) => Effect.gen(function* () {
|
|
|
19759
19856
|
const interLineDelayMs = 250 / speedMultiplier;
|
|
19760
19857
|
const explanationHoldMs = WELCOME_EXPLANATION_HOLD_MS / speedMultiplier;
|
|
19761
19858
|
const face = HAPPY_FACE_LINES.map((line) => highlighter.success(line));
|
|
19762
|
-
const mouthPrefix =
|
|
19763
|
-
|
|
19859
|
+
const mouthPrefix = `${FACE_INDENT}${face[2] ?? ""}${FACE_INDENT}`;
|
|
19860
|
+
const terminalColumns = process.stdout.columns;
|
|
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`);
|
|
19764
19865
|
yield* writeStdout("\x1B[3A");
|
|
19765
|
-
yield* typeLine(
|
|
19866
|
+
yield* typeLine(`${FACE_INDENT}${face[1] ?? ""}${FACE_INDENT}`, greeting, (fragment) => highlighter.bold(fragment), charDelayMs);
|
|
19766
19867
|
yield* Effect.sleep(interLineDelayMs);
|
|
19767
19868
|
yield* writeStdout("\x1B[1B");
|
|
19768
|
-
yield* typeLine(mouthPrefix,
|
|
19869
|
+
yield* typeLine(mouthPrefix, tagline, (fragment) => highlighter.dim(fragment), charDelayMs);
|
|
19769
19870
|
yield* Effect.sleep(explanationHoldMs);
|
|
19770
19871
|
yield* writeStdout("\x1B[3A\r\x1B[0J");
|
|
19771
19872
|
});
|
|
@@ -21521,4 +21622,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
|
|
|
21521
21622
|
export {};
|
|
21522
21623
|
|
|
21523
21624
|
//# sourceMappingURL=cli.js.map
|
|
21524
|
-
//# debugId=
|
|
21625
|
+
//# debugId=92822f58-92ef-58d5-8850-2746c0b48fc0
|