react-doctor 0.4.1 → 0.4.2-dev.25cc69b
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 +6 -74
- package/dist/cli.js +1414 -1294
- package/dist/index.d.ts +11 -1
- package/dist/index.js +41 -4
- package/dist/lsp.js +34 -4
- package/dist/skills/react-doctor/SKILL.md +2 -2
- package/dist/skills/{doctor-explain/SKILL.md → react-doctor/references/explain.md} +6 -9
- 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]="afa1d140-a4ff-5bff-bb67-c4959b977495")}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;
|
|
@@ -7629,6 +7630,35 @@ const loadPackageJsonConfig = (directory) => {
|
|
|
7629
7630
|
format: "package-json"
|
|
7630
7631
|
};
|
|
7631
7632
|
};
|
|
7633
|
+
const loadLegacyConfig = (directory) => {
|
|
7634
|
+
const legacyFilePath = path$1.join(directory, LEGACY_CONFIG_FILENAME);
|
|
7635
|
+
if (!isFile(legacyFilePath)) return {
|
|
7636
|
+
status: "absent",
|
|
7637
|
+
loaded: null
|
|
7638
|
+
};
|
|
7639
|
+
try {
|
|
7640
|
+
const parsed = readDataConfig(legacyFilePath);
|
|
7641
|
+
if (isPlainObject(parsed)) {
|
|
7642
|
+
warn(`${LEGACY_CONFIG_FILENAME} is deprecated — rename it to ${CONFIG_BASENAME}.json (or author a ${CONFIG_BASENAME}.ts). It is still read for now.`);
|
|
7643
|
+
return {
|
|
7644
|
+
status: "found",
|
|
7645
|
+
loaded: {
|
|
7646
|
+
config: validateConfigTypes(parsed),
|
|
7647
|
+
sourceDirectory: directory,
|
|
7648
|
+
configFilePath: legacyFilePath,
|
|
7649
|
+
format: "json"
|
|
7650
|
+
}
|
|
7651
|
+
};
|
|
7652
|
+
}
|
|
7653
|
+
warn(`${LEGACY_CONFIG_FILENAME} must contain an object, ignoring.`);
|
|
7654
|
+
} catch (error) {
|
|
7655
|
+
warn(`Failed to load ${LEGACY_CONFIG_FILENAME}: ${formatError(error)}`);
|
|
7656
|
+
}
|
|
7657
|
+
return {
|
|
7658
|
+
status: "invalid",
|
|
7659
|
+
loaded: null
|
|
7660
|
+
};
|
|
7661
|
+
};
|
|
7632
7662
|
const loadConfigFromDirectory = async (directory) => {
|
|
7633
7663
|
let sawBrokenConfigFile = false;
|
|
7634
7664
|
for (const extension of CONFIG_EXTENSIONS) {
|
|
@@ -7658,7 +7688,8 @@ const loadConfigFromDirectory = async (directory) => {
|
|
|
7658
7688
|
status: "found",
|
|
7659
7689
|
loaded: packageJsonConfig
|
|
7660
7690
|
};
|
|
7661
|
-
|
|
7691
|
+
const legacyResult = loadLegacyConfig(directory);
|
|
7692
|
+
if (legacyResult.status !== "absent") return legacyResult;
|
|
7662
7693
|
return {
|
|
7663
7694
|
status: sawBrokenConfigFile ? "invalid" : "absent",
|
|
7664
7695
|
loaded: null
|
|
@@ -7695,7 +7726,9 @@ const directoryHasCurrentConfig = (directory) => {
|
|
|
7695
7726
|
/**
|
|
7696
7727
|
* Walks up from `rootDirectory` (same boundary semantics as
|
|
7697
7728
|
* `loadConfigWithSource`) looking for a pre-migration
|
|
7698
|
-
* `react-doctor.config.json
|
|
7729
|
+
* `react-doctor.config.json`. The loader still reads this file as a deprecated
|
|
7730
|
+
* fallback (see `loadLegacyConfig`); this detector is what lets the interactive
|
|
7731
|
+
* CLI offer to rename it to a current-format config. Returns the first one
|
|
7699
7732
|
* found, or `null` when a current-format config supersedes it or none exists
|
|
7700
7733
|
* before a project boundary. Detection only — the CLI performs the rename.
|
|
7701
7734
|
*/
|
|
@@ -12215,7 +12248,7 @@ const makeNoopConsole = () => ({
|
|
|
12215
12248
|
});
|
|
12216
12249
|
//#endregion
|
|
12217
12250
|
//#region src/cli/utils/version.ts
|
|
12218
|
-
const VERSION = "0.4.
|
|
12251
|
+
const VERSION = "0.4.2-dev.25cc69b";
|
|
12219
12252
|
//#endregion
|
|
12220
12253
|
//#region src/cli/utils/json-mode.ts
|
|
12221
12254
|
let context = null;
|
|
@@ -12573,13 +12606,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12573
12606
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12574
12607
|
* standard `SENTRY_RELEASE` override.
|
|
12575
12608
|
*/
|
|
12576
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.
|
|
12609
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.2-dev.25cc69b`;
|
|
12577
12610
|
/**
|
|
12578
12611
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12579
12612
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12580
12613
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12581
12614
|
*/
|
|
12582
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.
|
|
12615
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.2-dev.25cc69b") ? "development" : "production");
|
|
12583
12616
|
/**
|
|
12584
12617
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12585
12618
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -16441,8 +16474,22 @@ const buildCodeFrame = (input) => {
|
|
|
16441
16474
|
});
|
|
16442
16475
|
};
|
|
16443
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
|
|
16444
16490
|
//#region src/cli/utils/build-section-divider.ts
|
|
16445
|
-
const
|
|
16491
|
+
const DIVIDER_INDENT = " ";
|
|
16492
|
+
const buildSectionDivider = () => highlighter.dim(`${DIVIDER_INDENT}${"─".repeat(resolveMeasureWidth(2))}`);
|
|
16446
16493
|
//#endregion
|
|
16447
16494
|
//#region src/cli/utils/indent-multiline-text.ts
|
|
16448
16495
|
const indentMultilineText = (text, linePrefix) => text.split("\n").map((lineText) => `${linePrefix}${lineText}`).join("\n");
|
|
@@ -16602,7 +16649,10 @@ const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame
|
|
|
16602
16649
|
endLine: isMultiSite ? cluster.endLine : void 0,
|
|
16603
16650
|
rootDirectory: resolveSourceRoot(lead)
|
|
16604
16651
|
}) : null;
|
|
16605
|
-
if (codeFrame)
|
|
16652
|
+
if (codeFrame) {
|
|
16653
|
+
const boxInnerWidth = resolveMeasureWidth(8);
|
|
16654
|
+
lines.push(indentMultilineText(boxText(codeFrame, boxInnerWidth), TOP_ERROR_DETAIL_INDENT));
|
|
16655
|
+
}
|
|
16606
16656
|
const seenHints = /* @__PURE__ */ new Set();
|
|
16607
16657
|
for (const diagnostic of cluster.diagnostics) if (diagnostic.suppressionHint && !seenHints.has(diagnostic.suppressionHint)) {
|
|
16608
16658
|
seenHints.add(diagnostic.suppressionHint);
|
|
@@ -16620,8 +16670,8 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
|
|
|
16620
16670
|
const learnMoreLine = formatLearnMoreLine(representative);
|
|
16621
16671
|
if (learnMoreLine) lines.push(`${TOP_ERROR_DETAIL_INDENT}${highlighter.info(learnMoreLine)}`);
|
|
16622
16672
|
}
|
|
16623
|
-
if (!renderEverySite) for (const explanationLine of wrapTextToWidth(representative.message,
|
|
16624
|
-
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}`));
|
|
16625
16675
|
if (renderEverySite && isAgentEnvironment) {
|
|
16626
16676
|
const fixRecipeLine = formatFixRecipeLine(representative);
|
|
16627
16677
|
if (fixRecipeLine) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${fixRecipeLine}`));
|
|
@@ -16815,14 +16865,21 @@ const RAINBOW_HUE_SHIFT_PER_FRAME = 9;
|
|
|
16815
16865
|
const RAINBOW_GRADIENT_WIDTH = 80;
|
|
16816
16866
|
const RAINBOW_OKLCH_LIGHTNESS = .638;
|
|
16817
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
|
+
});
|
|
16818
16875
|
const buildScoreBarSegments = (filledCount) => {
|
|
16819
|
-
const emptyCount =
|
|
16876
|
+
const emptyCount = Math.max(0, getScoreBarWidth() - filledCount);
|
|
16820
16877
|
return {
|
|
16821
16878
|
filledSegment: "█".repeat(filledCount),
|
|
16822
16879
|
emptySegment: "░".repeat(emptyCount)
|
|
16823
16880
|
};
|
|
16824
16881
|
};
|
|
16825
|
-
const getFilledCount = (score) => Math.round(score / 100 *
|
|
16882
|
+
const getFilledCount = (score) => Math.round(score / 100 * getScoreBarWidth());
|
|
16826
16883
|
const joinScoreHeaderFrame = (lines) => `${lines[0]}\n\r${lines[1]}\n\r${lines[2]}\n\r${lines[3]}\n`;
|
|
16827
16884
|
const buildRawScoreBar = (displayScore) => {
|
|
16828
16885
|
const { filledSegment, emptySegment } = buildScoreBarSegments(getFilledCount(displayScore));
|
|
@@ -16858,10 +16915,11 @@ const buildScoreBar = (displayScore, colorScore = displayScore) => {
|
|
|
16858
16915
|
return colorizeByScore(filledSegment, colorScore) + highlighter.dim(emptySegment);
|
|
16859
16916
|
};
|
|
16860
16917
|
const buildProjectedScoreBar = (currentScore, potentialScore) => {
|
|
16918
|
+
const barWidth = getScoreBarWidth();
|
|
16861
16919
|
const currentFill = getFilledCount(currentScore);
|
|
16862
|
-
const potentialFill = Math.min(getFilledCount(potentialScore),
|
|
16920
|
+
const potentialFill = Math.min(getFilledCount(potentialScore), barWidth);
|
|
16863
16921
|
const gainCount = Math.max(0, potentialFill - currentFill);
|
|
16864
|
-
const emptyCount = Math.max(0,
|
|
16922
|
+
const emptyCount = Math.max(0, barWidth - currentFill - gainCount);
|
|
16865
16923
|
return colorizeByScore("█".repeat(currentFill), currentScore) + highlighter.dim(colorizeByScore("▓".repeat(gainCount), currentScore)) + highlighter.dim("░".repeat(emptyCount));
|
|
16866
16924
|
};
|
|
16867
16925
|
const getDoctorFace = (score) => {
|
|
@@ -16874,7 +16932,7 @@ const RAW_BRANDING_LINE = "React Doctor (https://react.doctor)";
|
|
|
16874
16932
|
const buildRawFaceLines = (score) => {
|
|
16875
16933
|
const [eyes, mouth] = getDoctorFace(score);
|
|
16876
16934
|
return [
|
|
16877
|
-
|
|
16935
|
+
FACE_BOX_TOP_BORDER,
|
|
16878
16936
|
`│ ${eyes} │`,
|
|
16879
16937
|
`│ ${mouth} │`,
|
|
16880
16938
|
"└─────┘"
|
|
@@ -17016,6 +17074,11 @@ const writeDiagnosticsDirectory = (diagnostics) => {
|
|
|
17016
17074
|
};
|
|
17017
17075
|
//#endregion
|
|
17018
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
|
+
});
|
|
17019
17082
|
const buildShareUrl = (diagnostics, scoreResult, projectName) => {
|
|
17020
17083
|
const errorCount = diagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
|
|
17021
17084
|
const warningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
|
|
@@ -17035,14 +17098,14 @@ const printFooter = (input) => Effect.gen(function* () {
|
|
|
17035
17098
|
if (!input.isOffline) {
|
|
17036
17099
|
const shareUrl = buildShareUrl(input.diagnostics, input.scoreResult, input.projectName);
|
|
17037
17100
|
yield* Console.log(` ${highlighter.bold("Share:")} ${highlighter.info(shareUrl)}`);
|
|
17038
|
-
yield*
|
|
17101
|
+
yield* printFooterDescription("Tell others how you did on socials");
|
|
17039
17102
|
yield* Console.log("");
|
|
17040
17103
|
}
|
|
17041
17104
|
yield* Console.log(` ${highlighter.bold("Docs:")} ${highlighter.info(DOCS_URL)}`);
|
|
17042
|
-
yield*
|
|
17105
|
+
yield* printFooterDescription("Learn more about fixing issues, setting up CI/CD, and configuring rules with a config file");
|
|
17043
17106
|
yield* Console.log("");
|
|
17044
17107
|
yield* Console.log(` ${highlighter.bold("GitHub:")} ${highlighter.info(CANONICAL_GITHUB_URL)}`);
|
|
17045
|
-
yield*
|
|
17108
|
+
yield* printFooterDescription("Report issues and star the repository!");
|
|
17046
17109
|
});
|
|
17047
17110
|
const printSummary = (input) => Effect.gen(function* () {
|
|
17048
17111
|
if (input.scoreResult) {
|
|
@@ -17948,190 +18011,24 @@ const installDoctorScript = (options) => {
|
|
|
17948
18011
|
...scriptTarget.reason !== void 0 ? { scriptReason: scriptTarget.reason } : {}
|
|
17949
18012
|
};
|
|
17950
18013
|
};
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
const CURSOR_HOOK_RELATIVE_PATH = ".cursor/hooks/react-doctor.sh";
|
|
17960
|
-
const CURSOR_HOOK_MATCHER = "Write|Edit|MultiEdit|ApplyPatch";
|
|
17961
|
-
const CURSOR_HOOKS_SCHEMA_VERSION = 1;
|
|
17962
|
-
const JSON_INDENT_SPACES$1 = 2;
|
|
17963
|
-
const isSupportedAgent = (agent) => agent === CLAUDE_AGENT || agent === CURSOR_AGENT;
|
|
17964
|
-
const readJsonFile = (filePath, fallback) => {
|
|
17965
|
-
if (!fs$1.existsSync(filePath)) return fallback;
|
|
17966
|
-
const content = fs$1.readFileSync(filePath, "utf8").trim();
|
|
17967
|
-
if (content.length === 0) return fallback;
|
|
17968
|
-
return JSON.parse(content);
|
|
17969
|
-
};
|
|
17970
|
-
const writeJsonFile = (filePath, value) => {
|
|
17971
|
-
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
17972
|
-
fs$1.writeFileSync(filePath, `${JSON.stringify(value, null, JSON_INDENT_SPACES$1)}\n`);
|
|
17973
|
-
};
|
|
17974
|
-
const writeHookScript = (filePath) => {
|
|
17975
|
-
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
17976
|
-
fs$1.writeFileSync(filePath, buildAgentHookScript());
|
|
17977
|
-
fs$1.chmodSync(filePath, 493);
|
|
17978
|
-
};
|
|
17979
|
-
const hasClaudeHookCommand = (groups) => groups.some((group) => (group.hooks ?? []).some((hook) => hook.command === CLAUDE_HOOK_COMMAND));
|
|
17980
|
-
const installClaudeHook = (projectRoot) => {
|
|
17981
|
-
const settingsPath = path$1.join(projectRoot, CLAUDE_SETTINGS_RELATIVE_PATH);
|
|
17982
|
-
const hookPath = path$1.join(projectRoot, CLAUDE_HOOK_RELATIVE_PATH);
|
|
17983
|
-
const settings = readJsonFile(settingsPath, {});
|
|
17984
|
-
const hooks = { ...settings.hooks ?? {} };
|
|
17985
|
-
const postToolBatchHooks = [...hooks.PostToolBatch ?? []];
|
|
17986
|
-
if (!hasClaudeHookCommand(postToolBatchHooks)) postToolBatchHooks.push({ hooks: [{
|
|
17987
|
-
type: "command",
|
|
17988
|
-
command: CLAUDE_HOOK_COMMAND
|
|
17989
|
-
}] });
|
|
17990
|
-
hooks.PostToolBatch = postToolBatchHooks;
|
|
17991
|
-
writeJsonFile(settingsPath, {
|
|
17992
|
-
...settings,
|
|
17993
|
-
hooks
|
|
17994
|
-
});
|
|
17995
|
-
writeHookScript(hookPath);
|
|
17996
|
-
return [settingsPath, hookPath];
|
|
17997
|
-
};
|
|
17998
|
-
const hasCursorHookCommand = (handlers) => handlers.some((handler) => handler.command === CURSOR_HOOK_RELATIVE_PATH);
|
|
17999
|
-
const installCursorHook = (projectRoot) => {
|
|
18000
|
-
const configPath = path$1.join(projectRoot, CURSOR_HOOKS_RELATIVE_PATH);
|
|
18001
|
-
const hookPath = path$1.join(projectRoot, CURSOR_HOOK_RELATIVE_PATH);
|
|
18002
|
-
const config = readJsonFile(configPath, {});
|
|
18003
|
-
const hooks = { ...config.hooks ?? {} };
|
|
18004
|
-
const postToolUseHooks = [...hooks.postToolUse ?? []];
|
|
18005
|
-
if (!hasCursorHookCommand(postToolUseHooks)) postToolUseHooks.push({
|
|
18006
|
-
command: CURSOR_HOOK_RELATIVE_PATH,
|
|
18007
|
-
matcher: CURSOR_HOOK_MATCHER,
|
|
18008
|
-
timeout: 120
|
|
18009
|
-
});
|
|
18010
|
-
hooks.postToolUse = postToolUseHooks;
|
|
18011
|
-
writeJsonFile(configPath, {
|
|
18012
|
-
...config,
|
|
18013
|
-
version: config.version ?? CURSOR_HOOKS_SCHEMA_VERSION,
|
|
18014
|
-
hooks
|
|
18015
|
-
});
|
|
18016
|
-
writeHookScript(hookPath);
|
|
18017
|
-
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.";
|
|
18018
18022
|
};
|
|
18019
|
-
const
|
|
18020
|
-
"
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
"",
|
|
18028
|
-
"script_dir=$(CDPATH= cd \"$(dirname \"$0\")\" && pwd)",
|
|
18029
|
-
"project_root=${CLAUDE_PROJECT_DIR:-}",
|
|
18030
|
-
"if [ -z \"$project_root\" ]; then",
|
|
18031
|
-
" project_root=$(CDPATH= cd \"$script_dir/../..\" && pwd)",
|
|
18032
|
-
"fi",
|
|
18033
|
-
"if ! cd \"$project_root\"; then",
|
|
18034
|
-
" exit 0",
|
|
18035
|
-
"fi",
|
|
18036
|
-
"",
|
|
18037
|
-
"should_scan() {",
|
|
18038
|
-
" if ! command -v node >/dev/null 2>&1; then",
|
|
18039
|
-
" return 0",
|
|
18040
|
-
" fi",
|
|
18041
|
-
"",
|
|
18042
|
-
" node - \"$input_file\" <<'NODE'",
|
|
18043
|
-
"const fs = require('node:fs');",
|
|
18044
|
-
"const inputPath = process.argv[2];",
|
|
18045
|
-
"const editToolNames = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'ApplyPatch']);",
|
|
18046
|
-
"try {",
|
|
18047
|
-
" const input = JSON.parse(fs.readFileSync(inputPath, 'utf8') || '{}');",
|
|
18048
|
-
" const eventName = input.hook_event_name || input.eventName || input.event_name;",
|
|
18049
|
-
" if (eventName === 'PostToolBatch') {",
|
|
18050
|
-
" const toolCalls = Array.isArray(input.tool_calls) ? input.tool_calls : [];",
|
|
18051
|
-
" process.exit(toolCalls.some((toolCall) => editToolNames.has(toolCall.tool_name)) ? 0 : 10);",
|
|
18052
|
-
" }",
|
|
18053
|
-
" const toolName = input.tool_name || input.toolName || input.tool;",
|
|
18054
|
-
" process.exit(!toolName || editToolNames.has(toolName) ? 0 : 10);",
|
|
18055
|
-
"} catch {",
|
|
18056
|
-
" process.exit(0);",
|
|
18057
|
-
"}",
|
|
18058
|
-
"NODE",
|
|
18059
|
-
"}",
|
|
18060
|
-
"",
|
|
18061
|
-
"run_react_doctor() {",
|
|
18062
|
-
" if [ -x ./node_modules/.bin/react-doctor ]; then",
|
|
18063
|
-
" ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
|
|
18064
|
-
" return",
|
|
18065
|
-
" fi",
|
|
18066
|
-
"",
|
|
18067
|
-
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
18068
|
-
" react-doctor --verbose --diff --blocking warning --no-score",
|
|
18069
|
-
" return",
|
|
18070
|
-
" fi",
|
|
18071
|
-
"",
|
|
18072
|
-
" if command -v pnpm >/dev/null 2>&1; then",
|
|
18073
|
-
" pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
18074
|
-
" return",
|
|
18075
|
-
" fi",
|
|
18076
|
-
"",
|
|
18077
|
-
" if command -v npx >/dev/null 2>&1; then",
|
|
18078
|
-
" npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
18079
|
-
" return",
|
|
18080
|
-
" fi",
|
|
18081
|
-
"",
|
|
18082
|
-
" printf '%s\\n' 'react-doctor: command not found; skipping agent hook scan.'",
|
|
18083
|
-
" return 0",
|
|
18084
|
-
"}",
|
|
18085
|
-
"",
|
|
18086
|
-
"if ! should_scan; then",
|
|
18087
|
-
" exit 0",
|
|
18088
|
-
"fi",
|
|
18089
|
-
"",
|
|
18090
|
-
"if run_react_doctor > \"$output_file\" 2>&1; then",
|
|
18091
|
-
" exit 0",
|
|
18092
|
-
"fi",
|
|
18093
|
-
"",
|
|
18094
|
-
"node - \"$input_file\" \"$output_file\" <<'NODE'",
|
|
18095
|
-
"const fs = require('node:fs');",
|
|
18096
|
-
"const inputPath = process.argv[2];",
|
|
18097
|
-
"const outputPath = process.argv[3];",
|
|
18098
|
-
"const readInput = () => {",
|
|
18099
|
-
" try {",
|
|
18100
|
-
" return JSON.parse(fs.readFileSync(inputPath, 'utf8') || '{}');",
|
|
18101
|
-
" } catch {",
|
|
18102
|
-
" return {};",
|
|
18103
|
-
" }",
|
|
18104
|
-
"};",
|
|
18105
|
-
"const input = readInput();",
|
|
18106
|
-
"const scanOutput = fs.readFileSync(outputPath, 'utf8').trim();",
|
|
18107
|
-
"if (!scanOutput) process.exit(0);",
|
|
18108
|
-
"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}`;",
|
|
18109
|
-
"if (input.hook_event_name === 'PostToolBatch') {",
|
|
18110
|
-
" console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolBatch', additionalContext: message } }));",
|
|
18111
|
-
"} else {",
|
|
18112
|
-
" console.log(JSON.stringify({ additional_context: message }));",
|
|
18113
|
-
"}",
|
|
18114
|
-
"NODE",
|
|
18115
|
-
""
|
|
18116
|
-
].join("\n");
|
|
18117
|
-
const installReactDoctorAgentHooks = (options) => {
|
|
18118
|
-
const installedAgents = [];
|
|
18119
|
-
const files = [];
|
|
18120
|
-
const requestedAgents = options.agents.filter(isSupportedAgent);
|
|
18121
|
-
for (const agent of requestedAgents) {
|
|
18122
|
-
if (agent === CLAUDE_AGENT) {
|
|
18123
|
-
files.push(...installClaudeHook(options.projectRoot));
|
|
18124
|
-
installedAgents.push(agent);
|
|
18125
|
-
}
|
|
18126
|
-
if (agent === CURSOR_AGENT) {
|
|
18127
|
-
files.push(...installCursorHook(options.projectRoot));
|
|
18128
|
-
installedAgents.push(agent);
|
|
18129
|
-
}
|
|
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;
|
|
18130
18031
|
}
|
|
18131
|
-
return {
|
|
18132
|
-
installedAgents,
|
|
18133
|
-
files
|
|
18134
|
-
};
|
|
18135
18032
|
};
|
|
18136
18033
|
//#endregion
|
|
18137
18034
|
//#region src/cli/utils/install-github-workflow.ts
|
|
@@ -18241,1074 +18138,1359 @@ const installReactDoctorWorkflow = (projectRoot) => {
|
|
|
18241
18138
|
};
|
|
18242
18139
|
}
|
|
18243
18140
|
};
|
|
18244
|
-
|
|
18245
|
-
|
|
18246
|
-
|
|
18247
|
-
|
|
18248
|
-
|
|
18249
|
-
|
|
18250
|
-
}
|
|
18251
|
-
if (
|
|
18252
|
-
|
|
18253
|
-
|
|
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
|
+
};
|
|
18254
18163
|
}
|
|
18255
|
-
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18256
|
-
recordCount(METRIC.installWorkflow, 1);
|
|
18257
|
-
return true;
|
|
18258
18164
|
};
|
|
18259
18165
|
//#endregion
|
|
18260
|
-
//#region src/cli/utils/
|
|
18261
|
-
const
|
|
18262
|
-
|
|
18263
|
-
|
|
18264
|
-
const
|
|
18265
|
-
const
|
|
18266
|
-
|
|
18267
|
-
|
|
18268
|
-
|
|
18269
|
-
const
|
|
18270
|
-
|
|
18271
|
-
|
|
18272
|
-
|
|
18273
|
-
|
|
18274
|
-
|
|
18275
|
-
" fi",
|
|
18276
|
-
"",
|
|
18277
|
-
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
18278
|
-
` ${REACT_DOCTOR_COMMAND}`,
|
|
18279
|
-
" return",
|
|
18280
|
-
" fi",
|
|
18281
|
-
"",
|
|
18282
|
-
" if command -v pnpm >/dev/null 2>&1; then",
|
|
18283
|
-
` ${PNPM_REACT_DOCTOR_COMMAND}`,
|
|
18284
|
-
" return",
|
|
18285
|
-
" fi",
|
|
18286
|
-
"",
|
|
18287
|
-
" if command -v npx >/dev/null 2>&1; then",
|
|
18288
|
-
` ${NPX_REACT_DOCTOR_COMMAND}`,
|
|
18289
|
-
" return",
|
|
18290
|
-
" fi",
|
|
18291
|
-
"",
|
|
18292
|
-
" printf '%s\\n' \"react-doctor: command not found; skipping staged scan.\"",
|
|
18293
|
-
"}",
|
|
18294
|
-
"",
|
|
18295
|
-
"react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\")",
|
|
18296
|
-
"if react_doctor_scan_staged_files > \"$react_doctor_output\" 2>&1; then",
|
|
18297
|
-
" rm -f \"$react_doctor_output\"",
|
|
18298
|
-
"else",
|
|
18299
|
-
" rm -f \"$react_doctor_output\"",
|
|
18300
|
-
` 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`,
|
|
18301
|
-
"fi",
|
|
18302
|
-
REACT_DOCTOR_BLOCK_END
|
|
18303
|
-
].join("\n");
|
|
18304
|
-
const mergeHookContent = (existingContent) => {
|
|
18305
|
-
const hookBlock = `${buildReactDoctorHookBlock()}\n`;
|
|
18306
|
-
if (REACT_DOCTOR_BLOCK_PATTERN.test(existingContent)) return ensureTrailingNewline(existingContent.replace(REACT_DOCTOR_BLOCK_PATTERN, hookBlock));
|
|
18307
|
-
if (existingContent.length === 0) return `${SHEBANG}\n\n${hookBlock}`;
|
|
18308
|
-
const normalizedExistingContent = ensureTrailingNewline(existingContent);
|
|
18309
|
-
if (normalizedExistingContent.startsWith(SHEBANG_PREFIX)) {
|
|
18310
|
-
const [shebangLine, ...remainingLines] = normalizedExistingContent.split("\n");
|
|
18311
|
-
return [
|
|
18312
|
-
shebangLine,
|
|
18313
|
-
"",
|
|
18314
|
-
hookBlock.trimEnd(),
|
|
18315
|
-
...remainingLines
|
|
18316
|
-
].join("\n");
|
|
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;
|
|
18317
18181
|
}
|
|
18318
|
-
return `${SHEBANG}\n\n${hookBlock}${normalizedExistingContent}`;
|
|
18319
18182
|
};
|
|
18320
|
-
const
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
|
|
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 {
|
|
18197
|
+
return false;
|
|
18198
|
+
}
|
|
18326
18199
|
};
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
if (
|
|
18331
|
-
"
|
|
18332
|
-
|
|
18333
|
-
|
|
18334
|
-
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18200
|
+
//#endregion
|
|
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",
|
|
18212
|
+
"",
|
|
18213
|
+
url
|
|
18214
|
+
]
|
|
18215
|
+
};
|
|
18339
18216
|
return {
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
status: didHookExist ? "updated" : "created"
|
|
18217
|
+
command: "xdg-open",
|
|
18218
|
+
args: [url]
|
|
18343
18219
|
};
|
|
18344
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
|
+
};
|
|
18345
18235
|
//#endregion
|
|
18346
|
-
//#region src/cli/utils/
|
|
18347
|
-
const
|
|
18348
|
-
|
|
18349
|
-
|
|
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
|
+
}
|
|
18350
18279
|
};
|
|
18351
|
-
|
|
18352
|
-
|
|
18353
|
-
|
|
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";
|
|
18354
18303
|
};
|
|
18355
|
-
|
|
18356
|
-
|
|
18357
|
-
|
|
18358
|
-
|
|
18359
|
-
|
|
18360
|
-
|
|
18361
|
-
|
|
18362
|
-
|
|
18363
|
-
|
|
18364
|
-
|
|
18365
|
-
|
|
18366
|
-
|
|
18367
|
-
|
|
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
|
+
};
|
|
18368
18331
|
}
|
|
18369
|
-
parent[leafKey] = strategy.leafShape === "array" ? appendArrayCommand(parent[leafKey]) : appendStringCommand(parent[leafKey]);
|
|
18370
|
-
writeJsonFile$1(packageJsonPath, nextPackageJson);
|
|
18371
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18372
|
-
return {
|
|
18373
|
-
hookPath: packageJsonPath,
|
|
18374
|
-
kind: strategy.kind,
|
|
18375
|
-
status: didHookExist ? "updated" : "created"
|
|
18376
|
-
};
|
|
18377
18332
|
};
|
|
18378
|
-
const
|
|
18379
|
-
|
|
18380
|
-
|
|
18381
|
-
|
|
18382
|
-
|
|
18383
|
-
const installGhooks = (options) => installPackageJsonHook(options, {
|
|
18384
|
-
kind: "ghooks",
|
|
18385
|
-
path: [
|
|
18386
|
-
"config",
|
|
18387
|
-
"ghooks",
|
|
18388
|
-
"pre-commit"
|
|
18389
|
-
],
|
|
18390
|
-
leafShape: "string"
|
|
18391
|
-
});
|
|
18392
|
-
const installPreCommitNpm = (options) => installPackageJsonHook(options, {
|
|
18393
|
-
kind: "pre-commit-npm",
|
|
18394
|
-
path: ["pre-commit"],
|
|
18395
|
-
leafShape: "array"
|
|
18396
|
-
});
|
|
18397
|
-
const installPrettyQuick = (options) => installPackageJsonHook(options, {
|
|
18398
|
-
kind: "pretty-quick",
|
|
18399
|
-
path: ["gitHooks", "pre-commit"],
|
|
18400
|
-
leafShape: "string"
|
|
18401
|
-
});
|
|
18402
|
-
const installYorkie = (options) => installPackageJsonHook(options, {
|
|
18403
|
-
kind: "yorkie",
|
|
18404
|
-
path: ["gitHooks", "pre-commit"],
|
|
18405
|
-
leafShape: "string"
|
|
18406
|
-
});
|
|
18407
|
-
const installGitHooksJs = (options) => installPackageJsonHook(options, {
|
|
18408
|
-
kind: "git-hooks-js",
|
|
18409
|
-
path: ["git-hooks", "pre-commit"],
|
|
18410
|
-
leafShape: "string"
|
|
18411
|
-
});
|
|
18412
|
-
const appendIndentedBlockToTopLevelSection = (content, sectionName, block) => {
|
|
18413
|
-
const normalizedContent = ensureTrailingNewline(content);
|
|
18414
|
-
const match = new RegExp(`^${sectionName}:\\s*$`, "m").exec(normalizedContent);
|
|
18415
|
-
if (match === null) return ensureTrailingNewline([
|
|
18416
|
-
normalizedContent.trimEnd(),
|
|
18417
|
-
"",
|
|
18418
|
-
`${sectionName}:`,
|
|
18419
|
-
...block,
|
|
18420
|
-
""
|
|
18421
|
-
].filter((line, index) => index > 0 || line.length > 0).join("\n"));
|
|
18422
|
-
const sectionStartIndex = match.index;
|
|
18423
|
-
const nextSectionPattern = /^[A-Za-z0-9_-]+:\s*$/gm;
|
|
18424
|
-
nextSectionPattern.lastIndex = sectionStartIndex + match[0].length;
|
|
18425
|
-
let nextSectionMatch = nextSectionPattern.exec(normalizedContent);
|
|
18426
|
-
while (nextSectionMatch !== null && nextSectionMatch.index === sectionStartIndex) nextSectionMatch = nextSectionPattern.exec(normalizedContent);
|
|
18427
|
-
const insertIndex = nextSectionMatch?.index ?? normalizedContent.length;
|
|
18428
|
-
const prefix = normalizedContent.slice(0, insertIndex).trimEnd();
|
|
18429
|
-
const suffix = normalizedContent.slice(insertIndex);
|
|
18430
|
-
return ensureTrailingNewline([
|
|
18431
|
-
prefix,
|
|
18432
|
-
...block,
|
|
18433
|
-
suffix.trimStart()
|
|
18434
|
-
].join("\n"));
|
|
18435
|
-
};
|
|
18436
|
-
const findTopLevelSectionRange = (content, sectionName) => {
|
|
18437
|
-
const match = new RegExp(`^${sectionName}:\\s*$`, "m").exec(content);
|
|
18438
|
-
if (match === null) return null;
|
|
18439
|
-
const headerLineEndIndex = content.indexOf("\n", match.index);
|
|
18440
|
-
const headerEndIndex = headerLineEndIndex === -1 ? match.index + match[0].length : headerLineEndIndex + 1;
|
|
18441
|
-
const nextSectionPattern = /^[A-Za-z0-9_-]+:\s*$/gm;
|
|
18442
|
-
nextSectionPattern.lastIndex = headerEndIndex;
|
|
18443
|
-
return {
|
|
18444
|
-
headerEndIndex,
|
|
18445
|
-
contentEndIndex: nextSectionPattern.exec(content)?.index ?? content.length
|
|
18446
|
-
};
|
|
18447
|
-
};
|
|
18448
|
-
const appendLefthookCommand = (content) => {
|
|
18449
|
-
const normalizedContent = ensureTrailingNewline(content);
|
|
18450
|
-
const sectionRange = findTopLevelSectionRange(normalizedContent, "pre-commit");
|
|
18451
|
-
const reactDoctorCommandBlock = [
|
|
18452
|
-
" react-doctor:",
|
|
18453
|
-
` run: ${NON_BLOCKING_REACT_DOCTOR_COMMAND}`,
|
|
18454
|
-
""
|
|
18455
|
-
];
|
|
18456
|
-
if (sectionRange === null) return ensureTrailingNewline([
|
|
18457
|
-
normalizedContent.trimEnd(),
|
|
18458
|
-
"",
|
|
18459
|
-
"pre-commit:",
|
|
18460
|
-
" commands:",
|
|
18461
|
-
...reactDoctorCommandBlock
|
|
18462
|
-
].filter((line, index) => index > 0 || line.length > 0).join("\n"));
|
|
18463
|
-
const sectionContent = normalizedContent.slice(sectionRange.headerEndIndex, sectionRange.contentEndIndex);
|
|
18464
|
-
const commandsMatch = /^ commands:\s*$/m.exec(sectionContent);
|
|
18465
|
-
const insertIndex = commandsMatch === null ? sectionRange.headerEndIndex : sectionRange.headerEndIndex + sectionContent.indexOf(commandsMatch[0]) + commandsMatch[0].length + 1;
|
|
18466
|
-
const insertBlock = commandsMatch === null ? [" commands:", ...reactDoctorCommandBlock].join("\n") : reactDoctorCommandBlock.join("\n");
|
|
18467
|
-
return ensureTrailingNewline(`${normalizedContent.slice(0, insertIndex)}${insertBlock}${normalizedContent.slice(insertIndex)}`);
|
|
18468
|
-
};
|
|
18469
|
-
const installLefthook = (options) => {
|
|
18470
|
-
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18471
|
-
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
18472
|
-
if (!existingContent.includes("react-doctor")) {
|
|
18473
|
-
const nextContent = appendLefthookCommand(existingContent);
|
|
18474
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18475
|
-
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];
|
|
18476
18338
|
}
|
|
18477
|
-
|
|
18478
|
-
|
|
18479
|
-
|
|
18480
|
-
|
|
18481
|
-
|
|
18482
|
-
|
|
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;
|
|
18483
18350
|
};
|
|
18484
|
-
const
|
|
18485
|
-
|
|
18486
|
-
|
|
18487
|
-
|
|
18488
|
-
|
|
18489
|
-
|
|
18490
|
-
|
|
18491
|
-
" hooks:",
|
|
18492
|
-
" - id: react-doctor",
|
|
18493
|
-
" name: react-doctor",
|
|
18494
|
-
` entry: sh -c '${NON_BLOCKING_REACT_DOCTOR_COMMAND}'`,
|
|
18495
|
-
" language: system",
|
|
18496
|
-
" pass_filenames: false",
|
|
18497
|
-
""
|
|
18498
|
-
].join("\n");
|
|
18499
|
-
const nextContent = hasReposKey ? `${ensureTrailingNewline(existingContent)}${localHookBlock}` : `repos:\n${localHookBlock}`;
|
|
18500
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18501
|
-
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18502
|
-
}
|
|
18503
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18504
|
-
return {
|
|
18505
|
-
hookPath: options.hookPath,
|
|
18506
|
-
kind: "pre-commit",
|
|
18507
|
-
status: didHookExist ? "updated" : "created"
|
|
18508
|
-
};
|
|
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, "")}`;
|
|
18509
18358
|
};
|
|
18510
|
-
const
|
|
18511
|
-
const
|
|
18512
|
-
const
|
|
18513
|
-
|
|
18514
|
-
|
|
18515
|
-
|
|
18516
|
-
|
|
18517
|
-
|
|
18518
|
-
|
|
18519
|
-
]);
|
|
18520
|
-
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18521
|
-
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18522
|
-
}
|
|
18523
|
-
removeLegacyManagedRunner(options.projectRoot);
|
|
18524
|
-
return {
|
|
18525
|
-
hookPath: options.hookPath,
|
|
18526
|
-
kind: "overcommit",
|
|
18527
|
-
status: didHookExist ? "updated" : "created"
|
|
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"
|
|
18528
18368
|
};
|
|
18529
|
-
|
|
18530
|
-
|
|
18531
|
-
|
|
18532
|
-
|
|
18533
|
-
const isVitePlusProject = (projectRoot) => packageHasDependency(projectRoot, "vite-plus");
|
|
18534
|
-
const isSimpleGitHooksProject = (projectRoot) => {
|
|
18535
|
-
const packageJson = readPackageJson(projectRoot);
|
|
18536
|
-
return isRecord(packageJson) && isRecord(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || fs$1.existsSync(path$1.join(projectRoot, ".simple-git-hooks.cjs"));
|
|
18537
|
-
};
|
|
18538
|
-
const getLefthookConfigPath = (projectRoot) => {
|
|
18539
|
-
for (const fileName of LEFTHOOK_CONFIG_FILES) {
|
|
18540
|
-
const filePath = path$1.join(projectRoot, fileName);
|
|
18541
|
-
if (fs$1.existsSync(filePath)) return filePath;
|
|
18542
|
-
}
|
|
18543
|
-
return packageHasDependency(projectRoot, "lefthook") ? path$1.join(projectRoot, LEFTHOOK_CONFIG_FILES[0] ?? "lefthook.yml") : null;
|
|
18544
|
-
};
|
|
18545
|
-
const isPreCommitProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, PRE_COMMIT_CONFIG_FILE));
|
|
18546
|
-
const isOvercommitProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, ".overcommit.yml")) || packageHasDependency(projectRoot, "overcommit");
|
|
18547
|
-
const isYorkieProject = (projectRoot) => packageHasRecordKey(projectRoot, "gitHooks") || packageHasDependency(projectRoot, "yorkie");
|
|
18548
|
-
const isGhooksProject = (projectRoot) => packageHasDependency(projectRoot, "ghooks") || packageHasNestedRecordKey(projectRoot, "config", "ghooks");
|
|
18549
|
-
const isGitHooksJsProject = (projectRoot) => packageHasRecordKey(projectRoot, "git-hooks") || packageHasDependency(projectRoot, "git-hooks-js");
|
|
18550
|
-
const isPreCommitNpmProject = (projectRoot) => packageHasDependency(projectRoot, "pre-commit");
|
|
18551
|
-
const isPrettyQuickProject = (projectRoot) => packageHasDependency(projectRoot, "pretty-quick");
|
|
18552
|
-
const detectGitHookTarget = (projectRoot) => {
|
|
18553
|
-
if (runGit(projectRoot, ["rev-parse", "--is-inside-work-tree"]) !== "true") return null;
|
|
18554
|
-
const topLevel = runGit(projectRoot, ["rev-parse", "--show-toplevel"]) ?? projectRoot;
|
|
18555
|
-
const configuredHooksPath = runGit(projectRoot, [
|
|
18556
|
-
"config",
|
|
18557
|
-
"--path",
|
|
18558
|
-
"--get",
|
|
18559
|
-
"core.hooksPath"
|
|
18560
|
-
]);
|
|
18561
|
-
if (configuredHooksPath !== null && configuredHooksPath.length > 0) return {
|
|
18562
|
-
hookPath: path$1.join(resolveGitPath(topLevel, configuredHooksPath), HOOK_FILE_NAME),
|
|
18563
|
-
runnerRoot: topLevel,
|
|
18564
|
-
kind: "configured"
|
|
18369
|
+
const cwd = repoRootProbe.stdout;
|
|
18370
|
+
if (!isCommandAvailable("gh")) return {
|
|
18371
|
+
status: "not-attempted",
|
|
18372
|
+
reason: "gh-not-installed"
|
|
18565
18373
|
};
|
|
18566
|
-
if (
|
|
18567
|
-
|
|
18568
|
-
|
|
18569
|
-
kind: "husky",
|
|
18570
|
-
hooksPathConfig: HUSKY_HOOKS_PATH
|
|
18374
|
+
if (!(await run("gh", ["auth", "status"], cwd)).success) return {
|
|
18375
|
+
status: "not-attempted",
|
|
18376
|
+
reason: "gh-not-authenticated"
|
|
18571
18377
|
};
|
|
18572
|
-
|
|
18573
|
-
|
|
18574
|
-
|
|
18575
|
-
|
|
18576
|
-
hooksPathConfig: VITE_PLUS_HOOKS_PATH
|
|
18378
|
+
const defaultBranch = await detectDefaultBranch(cwd);
|
|
18379
|
+
if (!defaultBranch) return {
|
|
18380
|
+
status: "not-attempted",
|
|
18381
|
+
reason: "no-default-branch"
|
|
18577
18382
|
};
|
|
18578
|
-
|
|
18579
|
-
|
|
18580
|
-
|
|
18581
|
-
|
|
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"
|
|
18582
18391
|
};
|
|
18583
|
-
const
|
|
18584
|
-
|
|
18585
|
-
|
|
18586
|
-
|
|
18587
|
-
|
|
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"
|
|
18588
18407
|
};
|
|
18589
|
-
|
|
18590
|
-
|
|
18591
|
-
|
|
18592
|
-
|
|
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);
|
|
18593
18415
|
};
|
|
18594
|
-
if (
|
|
18595
|
-
|
|
18596
|
-
|
|
18597
|
-
|
|
18598
|
-
|
|
18599
|
-
|
|
18600
|
-
|
|
18601
|
-
|
|
18602
|
-
|
|
18603
|
-
|
|
18604
|
-
|
|
18605
|
-
|
|
18606
|
-
|
|
18607
|
-
|
|
18608
|
-
|
|
18609
|
-
|
|
18610
|
-
|
|
18611
|
-
|
|
18612
|
-
|
|
18613
|
-
|
|
18614
|
-
|
|
18615
|
-
|
|
18616
|
-
|
|
18617
|
-
|
|
18618
|
-
|
|
18619
|
-
|
|
18620
|
-
|
|
18621
|
-
|
|
18622
|
-
|
|
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
|
|
18623
18466
|
};
|
|
18624
|
-
const hookPath = runGit(projectRoot, [
|
|
18625
|
-
"rev-parse",
|
|
18626
|
-
"--git-path",
|
|
18627
|
-
HOOK_RELATIVE_PATH
|
|
18628
|
-
]);
|
|
18629
|
-
if (hookPath === null || hookPath.length === 0) return null;
|
|
18630
18467
|
return {
|
|
18631
|
-
|
|
18632
|
-
|
|
18633
|
-
kind: "git"
|
|
18468
|
+
status: "pr-opened",
|
|
18469
|
+
url: prCreate.stdout.split(/\r?\n/).filter(Boolean).pop() ?? ""
|
|
18634
18470
|
};
|
|
18635
18471
|
};
|
|
18636
|
-
const
|
|
18637
|
-
|
|
18638
|
-
|
|
18639
|
-
if (
|
|
18640
|
-
|
|
18641
|
-
|
|
18642
|
-
|
|
18643
|
-
|
|
18644
|
-
|
|
18645
|
-
if (options.kind === "pretty-quick") return installPrettyQuick(options);
|
|
18646
|
-
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;
|
|
18647
18481
|
};
|
|
18648
18482
|
//#endregion
|
|
18649
|
-
//#region src/cli/utils/
|
|
18650
|
-
const
|
|
18651
|
-
|
|
18652
|
-
|
|
18653
|
-
|
|
18654
|
-
const SETUP_OPTION_AGENT_HOOKS = "agent-hooks";
|
|
18655
|
-
const SETUP_OPTION_WORKFLOW = "workflow";
|
|
18656
|
-
const SETUP_OPTION_SKIP = "skip";
|
|
18657
|
-
const CONFIG_ONLY_GIT_HOOK_KINDS = new Set([
|
|
18658
|
-
"ghooks",
|
|
18659
|
-
"git-hooks-js",
|
|
18660
|
-
"lefthook",
|
|
18661
|
-
"overcommit",
|
|
18662
|
-
"pre-commit",
|
|
18663
|
-
"pre-commit-npm",
|
|
18664
|
-
"pretty-quick",
|
|
18665
|
-
"simple-git-hooks",
|
|
18666
|
-
"yorkie"
|
|
18667
|
-
]);
|
|
18668
|
-
const PACKAGE_MANAGER_LOCKFILES = [
|
|
18669
|
-
{
|
|
18670
|
-
packageManager: "pnpm",
|
|
18671
|
-
fileName: "pnpm-lock.yaml"
|
|
18672
|
-
},
|
|
18673
|
-
{
|
|
18674
|
-
packageManager: "yarn",
|
|
18675
|
-
fileName: "yarn.lock"
|
|
18676
|
-
},
|
|
18677
|
-
{
|
|
18678
|
-
packageManager: "bun",
|
|
18679
|
-
fileName: "bun.lockb"
|
|
18680
|
-
},
|
|
18681
|
-
{
|
|
18682
|
-
packageManager: "bun",
|
|
18683
|
-
fileName: "bun.lock"
|
|
18684
|
-
},
|
|
18685
|
-
{
|
|
18686
|
-
packageManager: "npm",
|
|
18687
|
-
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;
|
|
18688
18488
|
}
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18692
|
-
while (true) {
|
|
18693
|
-
if (fileNames.some((fileName) => fs$1.existsSync(path$1.join(currentDirectory, fileName)))) return currentDirectory;
|
|
18694
|
-
const parentDirectory = path$1.dirname(currentDirectory);
|
|
18695
|
-
if (parentDirectory === currentDirectory) return null;
|
|
18696
|
-
currentDirectory = parentDirectory;
|
|
18489
|
+
if (result.status === "exists") {
|
|
18490
|
+
workflowSpinner.succeed("GitHub Actions workflow already configured.");
|
|
18491
|
+
return false;
|
|
18697
18492
|
}
|
|
18493
|
+
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18494
|
+
recordCount(METRIC.installWorkflow, 1);
|
|
18495
|
+
return true;
|
|
18698
18496
|
};
|
|
18699
|
-
|
|
18700
|
-
|
|
18701
|
-
|
|
18702
|
-
|
|
18703
|
-
|
|
18704
|
-
|
|
18705
|
-
|
|
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.");
|
|
18706
18521
|
}
|
|
18707
|
-
const parentDirectory = path$1.dirname(currentDirectory);
|
|
18708
|
-
if (parentDirectory === currentDirectory) break;
|
|
18709
|
-
currentDirectory = parentDirectory;
|
|
18710
18522
|
}
|
|
18711
|
-
|
|
18712
|
-
return
|
|
18523
|
+
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
18524
|
+
return didCreateWorkflow;
|
|
18713
18525
|
};
|
|
18714
|
-
|
|
18715
|
-
|
|
18716
|
-
|
|
18717
|
-
|
|
18718
|
-
|
|
18719
|
-
|
|
18720
|
-
|
|
18721
|
-
|
|
18722
|
-
|
|
18723
|
-
|
|
18724
|
-
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
|
|
18729
|
-
|
|
18730
|
-
|
|
18731
|
-
|
|
18732
|
-
packageSpecifier
|
|
18733
|
-
],
|
|
18734
|
-
cwd: projectRoot
|
|
18735
|
-
};
|
|
18736
|
-
if (packageManager === "bun") return {
|
|
18737
|
-
command: "bun",
|
|
18738
|
-
args: [
|
|
18739
|
-
"add",
|
|
18740
|
-
"--dev",
|
|
18741
|
-
packageSpecifier
|
|
18742
|
-
],
|
|
18743
|
-
cwd: projectRoot
|
|
18744
|
-
};
|
|
18745
|
-
return {
|
|
18746
|
-
command: "pnpm",
|
|
18747
|
-
args: [
|
|
18748
|
-
"add",
|
|
18749
|
-
"--save-dev",
|
|
18750
|
-
...packageManagerNeedsWorkspaceFlag(projectRoot) ? ["-w"] : [],
|
|
18751
|
-
packageSpecifier
|
|
18752
|
-
],
|
|
18753
|
-
cwd: projectRoot
|
|
18754
|
-
};
|
|
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);
|
|
18755
18544
|
};
|
|
18756
|
-
const
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
|
|
18764
|
-
|
|
18545
|
+
const writeJsonFile = (filePath, value) => {
|
|
18546
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
18547
|
+
fs$1.writeFileSync(filePath, `${JSON.stringify(value, null, JSON_INDENT_SPACES$1)}\n`);
|
|
18548
|
+
};
|
|
18549
|
+
const writeHookScript = (filePath) => {
|
|
18550
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
18551
|
+
fs$1.writeFileSync(filePath, buildAgentHookScript());
|
|
18552
|
+
fs$1.chmodSync(filePath, 493);
|
|
18553
|
+
};
|
|
18554
|
+
const hasClaudeHookCommand = (groups) => groups.some((group) => (group.hooks ?? []).some((hook) => hook.command === CLAUDE_HOOK_COMMAND));
|
|
18555
|
+
const installClaudeHook = (projectRoot) => {
|
|
18556
|
+
const settingsPath = path$1.join(projectRoot, CLAUDE_SETTINGS_RELATIVE_PATH);
|
|
18557
|
+
const hookPath = path$1.join(projectRoot, CLAUDE_HOOK_RELATIVE_PATH);
|
|
18558
|
+
const settings = readJsonFile(settingsPath, {});
|
|
18559
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
18560
|
+
const postToolBatchHooks = [...hooks.PostToolBatch ?? []];
|
|
18561
|
+
if (!hasClaudeHookCommand(postToolBatchHooks)) postToolBatchHooks.push({ hooks: [{
|
|
18562
|
+
type: "command",
|
|
18563
|
+
command: CLAUDE_HOOK_COMMAND
|
|
18564
|
+
}] });
|
|
18565
|
+
hooks.PostToolBatch = postToolBatchHooks;
|
|
18566
|
+
writeJsonFile(settingsPath, {
|
|
18567
|
+
...settings,
|
|
18568
|
+
hooks
|
|
18765
18569
|
});
|
|
18570
|
+
writeHookScript(hookPath);
|
|
18571
|
+
return [settingsPath, hookPath];
|
|
18766
18572
|
};
|
|
18767
|
-
const
|
|
18768
|
-
|
|
18769
|
-
const
|
|
18770
|
-
|
|
18771
|
-
|
|
18772
|
-
|
|
18773
|
-
|
|
18774
|
-
|
|
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];
|
|
18775
18593
|
};
|
|
18776
|
-
const
|
|
18777
|
-
|
|
18778
|
-
|
|
18779
|
-
|
|
18780
|
-
|
|
18781
|
-
|
|
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
|
|
18782
18709
|
};
|
|
18783
|
-
|
|
18784
|
-
|
|
18785
|
-
|
|
18786
|
-
|
|
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");
|
|
18769
|
+
}
|
|
18770
|
+
return `${SHEBANG}\n\n${hookBlock}${normalizedExistingContent}`;
|
|
18771
|
+
};
|
|
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 {}
|
|
18778
|
+
};
|
|
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"
|
|
18787
18795
|
};
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18796
|
+
};
|
|
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;
|
|
18797
18820
|
}
|
|
18798
|
-
|
|
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
|
+
};
|
|
18799
18829
|
};
|
|
18800
|
-
const
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
|
|
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"
|
|
18804
18863
|
});
|
|
18805
|
-
const
|
|
18806
|
-
|
|
18807
|
-
|
|
18808
|
-
|
|
18809
|
-
|
|
18810
|
-
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
const
|
|
18821
|
-
|
|
18822
|
-
|
|
18823
|
-
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
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"));
|
|
18827
18887
|
};
|
|
18828
|
-
const
|
|
18829
|
-
|
|
18830
|
-
|
|
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
|
+
};
|
|
18831
18899
|
};
|
|
18832
|
-
const
|
|
18833
|
-
const
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
18838
|
-
|
|
18839
|
-
|
|
18840
|
-
|
|
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)}`);
|
|
18841
18920
|
};
|
|
18842
|
-
const
|
|
18843
|
-
|
|
18844
|
-
const
|
|
18845
|
-
|
|
18846
|
-
const
|
|
18847
|
-
|
|
18848
|
-
|
|
18849
|
-
});
|
|
18850
|
-
recordCount(METRIC.installDependency, 1, {
|
|
18851
|
-
status: dependencyResult.dependencyStatus,
|
|
18852
|
-
reason: dependencyResult.dependencyReason ?? null,
|
|
18853
|
-
packageManager: detectPackageManager(projectRoot)
|
|
18854
|
-
});
|
|
18855
|
-
if (dependencyResult.dependencyStatus === "skipped") {
|
|
18856
|
-
const message = formatDependencyInstallMessage(dependencyResult);
|
|
18857
|
-
if (dependencyResult.dependencyReason === "trust-policy-blocked") dependencySpinner.warn(message);
|
|
18858
|
-
else dependencySpinner.fail(message);
|
|
18859
|
-
const followUp = buildDependencyFollowUp(dependencyResult);
|
|
18860
|
-
if (followUp !== void 0) cliLogger.dim(followUp);
|
|
18861
|
-
return dependencyResult;
|
|
18862
|
-
}
|
|
18863
|
-
dependencySpinner.succeed(formatDependencyInstallMessage(dependencyResult));
|
|
18864
|
-
return dependencyResult;
|
|
18865
|
-
} catch (error) {
|
|
18866
|
-
dependencySpinner.fail("Failed to install React Doctor package.");
|
|
18867
|
-
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);
|
|
18868
18928
|
}
|
|
18929
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18930
|
+
return {
|
|
18931
|
+
hookPath: options.hookPath,
|
|
18932
|
+
kind: "lefthook",
|
|
18933
|
+
status: didHookExist ? "updated" : "created"
|
|
18934
|
+
};
|
|
18869
18935
|
};
|
|
18870
|
-
const
|
|
18871
|
-
const
|
|
18872
|
-
|
|
18873
|
-
|
|
18874
|
-
const
|
|
18875
|
-
|
|
18876
|
-
|
|
18877
|
-
|
|
18878
|
-
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18884
|
-
|
|
18885
|
-
|
|
18886
|
-
|
|
18887
|
-
|
|
18888
|
-
agents: [...agents],
|
|
18889
|
-
cwd: projectRoot,
|
|
18890
|
-
mode: "copy"
|
|
18891
|
-
});
|
|
18892
|
-
if (result.failed.length > 0) throw new Error(result.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
18893
|
-
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);
|
|
18894
18954
|
}
|
|
18895
|
-
|
|
18955
|
+
removeLegacyManagedRunner(options.projectRoot);
|
|
18956
|
+
return {
|
|
18957
|
+
hookPath: options.hookPath,
|
|
18958
|
+
kind: "pre-commit",
|
|
18959
|
+
status: didHookExist ? "updated" : "created"
|
|
18960
|
+
};
|
|
18896
18961
|
};
|
|
18897
|
-
const
|
|
18898
|
-
const
|
|
18899
|
-
const
|
|
18900
|
-
|
|
18901
|
-
|
|
18902
|
-
|
|
18903
|
-
|
|
18904
|
-
|
|
18905
|
-
|
|
18906
|
-
|
|
18907
|
-
|
|
18908
|
-
|
|
18909
|
-
cliLogger.error("No supported coding agents detected.");
|
|
18910
|
-
cliLogger.dim(" Looked for binaries on PATH (claude, codex, cursor, droid, gemini, copilot, opencode, pi)");
|
|
18911
|
-
cliLogger.dim(" and config dirs in $HOME (~/.claude, ~/.cursor, ~/.codex, ~/.gemini, ...).");
|
|
18912
|
-
process.exitCode = 1;
|
|
18913
|
-
return;
|
|
18914
|
-
}
|
|
18915
|
-
const skipPrompts = shouldSkipPrompts({ yes: options.yes });
|
|
18916
|
-
const gitHookTarget = options.gitHookPath === void 0 ? detectGitHookTarget(projectRoot) : options.gitHookPath === null ? null : buildManualGitHookTarget(options.gitHookPath, projectRoot);
|
|
18917
|
-
const gitHookPath = gitHookTarget?.hookPath;
|
|
18918
|
-
const promptOptions = options.onPromptCancel === void 0 ? {} : { onCancel: options.onPromptCancel };
|
|
18919
|
-
const prompt = options.prompt ?? prompts;
|
|
18920
|
-
const selectedAgents = skipPrompts ? detectedAgents : (await prompt({
|
|
18921
|
-
type: "multiselect",
|
|
18922
|
-
name: "agents",
|
|
18923
|
-
message: `Install the ${highlighter.info(`/react-doctor`)} skill for:`,
|
|
18924
|
-
choices: detectedAgents.map((agent) => ({
|
|
18925
|
-
title: getSkillAgentConfig(agent).displayName,
|
|
18926
|
-
value: agent,
|
|
18927
|
-
selected: true
|
|
18928
|
-
})),
|
|
18929
|
-
instructions: false,
|
|
18930
|
-
min: 1
|
|
18931
|
-
}, promptOptions)).agents ?? [];
|
|
18932
|
-
if (selectedAgents.length === 0) return;
|
|
18933
|
-
const workflowTargetPath = getReactDoctorWorkflowPath(projectRoot);
|
|
18934
|
-
const canInstallWorkflow = !isReactDoctorWorkflowInstalled(projectRoot);
|
|
18935
|
-
const setupActionChoices = [
|
|
18936
|
-
...gitHookPath === null || gitHookPath === void 0 ? [] : [{
|
|
18937
|
-
title: "Pre-commit hook",
|
|
18938
|
-
description: "Check staged changes before each commit",
|
|
18939
|
-
value: SETUP_OPTION_GIT_HOOK,
|
|
18940
|
-
selected: true
|
|
18941
|
-
}],
|
|
18942
|
-
...canInstallNativeAgentHooks(selectedAgents) ? [{
|
|
18943
|
-
title: "Agent hooks",
|
|
18944
|
-
description: "Ask Claude Code or Cursor to scan after code edits",
|
|
18945
|
-
value: SETUP_OPTION_AGENT_HOOKS,
|
|
18946
|
-
selected: Boolean(options.agentHooks)
|
|
18947
|
-
}] : [],
|
|
18948
|
-
...canInstallWorkflow ? [{
|
|
18949
|
-
title: "GitHub Actions workflow",
|
|
18950
|
-
description: "Scan pull requests in CI",
|
|
18951
|
-
value: SETUP_OPTION_WORKFLOW,
|
|
18952
|
-
selected: true
|
|
18953
|
-
}] : []
|
|
18954
|
-
];
|
|
18955
|
-
const setupChoices = setupActionChoices.length === 0 ? [] : [{
|
|
18956
|
-
title: "Skip optional setup",
|
|
18957
|
-
description: "Install only the agent skill and package setup",
|
|
18958
|
-
value: SETUP_OPTION_SKIP,
|
|
18959
|
-
selected: false
|
|
18960
|
-
}, ...setupActionChoices];
|
|
18961
|
-
const selectedSetupOptions = skipPrompts || setupChoices.length === 0 ? [] : (await prompt({
|
|
18962
|
-
type: "multiselect",
|
|
18963
|
-
name: "setupOptions",
|
|
18964
|
-
message: "Select additional React Doctor setup:",
|
|
18965
|
-
choices: setupChoices,
|
|
18966
|
-
instructions: false
|
|
18967
|
-
}, promptOptions)).setupOptions ?? [];
|
|
18968
|
-
const selectedSetupActions = selectedSetupOptions.filter((setupOption) => setupOption !== SETUP_OPTION_SKIP);
|
|
18969
|
-
const didSkipOptionalSetup = selectedSetupActions.length === 0 && selectedSetupOptions.includes(SETUP_OPTION_SKIP);
|
|
18970
|
-
const shouldInstallGitHook = gitHookPath != null && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_GIT_HOOK));
|
|
18971
|
-
const shouldInstallAgentHooks = Boolean(options.agentHooks) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_AGENT_HOOKS);
|
|
18972
|
-
const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_WORKFLOW));
|
|
18973
|
-
if (options.dryRun) {
|
|
18974
|
-
cliLogger.log(`Dry run — would install ${SKILL_NAME} skill for:`);
|
|
18975
|
-
for (const agent of selectedAgents) cliLogger.dim(` - ${getSkillAgentConfig(agent).displayName}`);
|
|
18976
|
-
cliLogger.dim(` Source: ${sourceDir}`);
|
|
18977
|
-
for (const sibling of findBundledSiblingSkills(sourceDir)) cliLogger.dim(` Also installs skill: ${sibling.name}`);
|
|
18978
|
-
cliLogger.dim(" Package script: doctor (or react-doctor if doctor exists)");
|
|
18979
|
-
cliLogger.dim(" Dev dependency: react-doctor");
|
|
18980
|
-
if (shouldInstallGitHook) cliLogger.dim(` Git hook: ${gitHookPath}`);
|
|
18981
|
-
if (shouldInstallAgentHooks) cliLogger.dim(" Agent hooks: Claude Code / Cursor when selected");
|
|
18982
|
-
if (shouldInstallWorkflow) cliLogger.dim(` GitHub Actions workflow: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
18983
|
-
return;
|
|
18984
|
-
}
|
|
18985
|
-
const installSpinner = spinner(`Installing ${SKILL_NAME} skill...`).start();
|
|
18986
|
-
try {
|
|
18987
|
-
const installResult = await installSkillsFromSource({
|
|
18988
|
-
source: sourceDir,
|
|
18989
|
-
agents: selectedAgents,
|
|
18990
|
-
cwd: projectRoot,
|
|
18991
|
-
mode: "copy"
|
|
18992
|
-
});
|
|
18993
|
-
if (installResult.skills.length === 0) throw new Error(`Could not parse ${SKILL_MANIFEST_FILE} for ${SKILL_NAME} (missing or invalid frontmatter).`);
|
|
18994
|
-
if (installResult.failed.length > 0) throw new Error(installResult.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
18995
|
-
installSpinner.succeed(`${SKILL_NAME} skill installed for ${selectedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
18996
|
-
} catch (error) {
|
|
18997
|
-
installSpinner.fail(`Failed to install ${SKILL_NAME} skill.`);
|
|
18998
|
-
throw error;
|
|
18999
|
-
}
|
|
19000
|
-
try {
|
|
19001
|
-
const installedSiblingSkills = await installBundledSiblingSkills(sourceDir, selectedAgents, projectRoot);
|
|
19002
|
-
if (installedSiblingSkills.length > 0) cliLogger.dim(` Also installed the ${installedSiblingSkills.join(", ")} skill.`);
|
|
19003
|
-
} catch {
|
|
19004
|
-
cliLogger.dim(" Skipped bundled sibling skills (install error).");
|
|
19005
|
-
}
|
|
19006
|
-
const dependencyResult = await installReactDoctorPackageSetup(projectRoot, options.installDependencyRunner);
|
|
19007
|
-
if (shouldInstallGitHook && gitHookTarget !== null && gitHookTarget !== void 0) {
|
|
19008
|
-
const hookSpinner = spinner("Installing React Doctor pre-commit hook...").start();
|
|
19009
|
-
try {
|
|
19010
|
-
const hookResult = installReactDoctorGitHook({
|
|
19011
|
-
hookPath: gitHookTarget.hookPath,
|
|
19012
|
-
projectRoot: gitHookTarget.runnerRoot,
|
|
19013
|
-
kind: gitHookTarget.kind,
|
|
19014
|
-
hooksPathConfig: gitHookTarget.hooksPathConfig
|
|
19015
|
-
});
|
|
19016
|
-
hookSpinner.succeed(formatGitHookInstallMessage(hookResult));
|
|
19017
|
-
recordCount(METRIC.installGitHook, 1, { kind: hookResult.kind });
|
|
19018
|
-
} catch (error) {
|
|
19019
|
-
hookSpinner.fail("Failed to install React Doctor pre-commit hook.");
|
|
19020
|
-
throw error;
|
|
19021
|
-
}
|
|
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);
|
|
19022
18974
|
}
|
|
19023
|
-
|
|
19024
|
-
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
|
|
19031
|
-
|
|
19032
|
-
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19036
|
-
|
|
19037
|
-
|
|
19038
|
-
|
|
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;
|
|
19039
18994
|
}
|
|
19040
|
-
|
|
19041
|
-
|
|
19042
|
-
|
|
19043
|
-
|
|
19044
|
-
|
|
19045
|
-
|
|
19046
|
-
|
|
19047
|
-
|
|
19048
|
-
|
|
19049
|
-
|
|
19050
|
-
|
|
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);
|
|
19051
19099
|
};
|
|
19052
19100
|
//#endregion
|
|
19053
|
-
//#region src/cli/utils/
|
|
19054
|
-
const
|
|
19101
|
+
//#region src/cli/utils/should-skip-prompts.ts
|
|
19102
|
+
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.json) || isNonInteractiveEnvironment() || !process.stdin.isTTY;
|
|
19055
19103
|
//#endregion
|
|
19056
|
-
//#region src/cli/utils/
|
|
19057
|
-
const
|
|
19058
|
-
const
|
|
19059
|
-
|
|
19060
|
-
|
|
19061
|
-
|
|
19062
|
-
|
|
19063
|
-
|
|
19064
|
-
|
|
19065
|
-
|
|
19066
|
-
|
|
19067
|
-
|
|
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"
|
|
19068
19139
|
}
|
|
19069
|
-
|
|
19070
|
-
const
|
|
19071
|
-
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
19076
|
-
|
|
19077
|
-
rootDirectory: path$1.resolve(projectRoot),
|
|
19078
|
-
outcome,
|
|
19079
|
-
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
19080
|
-
}
|
|
19081
|
-
});
|
|
19082
|
-
return true;
|
|
19083
|
-
} catch {
|
|
19084
|
-
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;
|
|
19085
19148
|
}
|
|
19086
19149
|
};
|
|
19087
|
-
|
|
19088
|
-
|
|
19089
|
-
|
|
19090
|
-
|
|
19091
|
-
|
|
19092
|
-
|
|
19093
|
-
|
|
19094
|
-
|
|
19095
|
-
|
|
19096
|
-
|
|
19097
|
-
|
|
19098
|
-
|
|
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";
|
|
19099
19164
|
};
|
|
19100
|
-
|
|
19101
|
-
|
|
19102
|
-
const
|
|
19103
|
-
|
|
19104
|
-
|
|
19105
|
-
|
|
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
|
|
19106
19177
|
};
|
|
19107
|
-
if (
|
|
19108
|
-
command: "
|
|
19178
|
+
if (packageManager === "yarn") return {
|
|
19179
|
+
command: "yarn",
|
|
19109
19180
|
args: [
|
|
19110
|
-
"
|
|
19111
|
-
"
|
|
19112
|
-
|
|
19113
|
-
|
|
19114
|
-
|
|
19181
|
+
"add",
|
|
19182
|
+
"--dev",
|
|
19183
|
+
packageSpecifier
|
|
19184
|
+
],
|
|
19185
|
+
cwd: projectRoot
|
|
19186
|
+
};
|
|
19187
|
+
if (packageManager === "bun") return {
|
|
19188
|
+
command: "bun",
|
|
19189
|
+
args: [
|
|
19190
|
+
"add",
|
|
19191
|
+
"--dev",
|
|
19192
|
+
packageSpecifier
|
|
19193
|
+
],
|
|
19194
|
+
cwd: projectRoot
|
|
19115
19195
|
};
|
|
19116
19196
|
return {
|
|
19117
|
-
command: "
|
|
19118
|
-
args: [
|
|
19197
|
+
command: "pnpm",
|
|
19198
|
+
args: [
|
|
19199
|
+
"add",
|
|
19200
|
+
"--save-dev",
|
|
19201
|
+
...packageManagerNeedsWorkspaceFlag(projectRoot) ? ["-w"] : [],
|
|
19202
|
+
packageSpecifier
|
|
19203
|
+
],
|
|
19204
|
+
cwd: projectRoot
|
|
19119
19205
|
};
|
|
19120
19206
|
};
|
|
19121
|
-
const openUrl = (url) => {
|
|
19122
|
-
try {
|
|
19123
|
-
const { command, args } = resolveOpenCommand(url);
|
|
19124
|
-
const child = spawn(command, args, {
|
|
19125
|
-
detached: true,
|
|
19126
|
-
stdio: "ignore"
|
|
19127
|
-
});
|
|
19128
|
-
child.on("error", () => {});
|
|
19129
|
-
child.unref();
|
|
19130
|
-
return true;
|
|
19131
|
-
} catch {
|
|
19132
|
-
return false;
|
|
19133
|
-
}
|
|
19134
|
-
};
|
|
19135
|
-
//#endregion
|
|
19136
|
-
//#region src/cli/utils/open-workflow-pull-request.ts
|
|
19137
|
-
const NEW_BRANCH_PREFIX = "react-doctor/add-github-actions";
|
|
19138
|
-
const DEFAULT_COMMIT_MESSAGE = "ci: add React Doctor GitHub Actions workflow";
|
|
19139
|
-
const DEFAULT_PR_TITLE = "Add React Doctor to GitHub Actions";
|
|
19140
|
-
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.
|
|
19141
|
-
|
|
19142
|
-
Docs: https://www.react.doctor/ci`;
|
|
19143
19207
|
const execFileAsync = promisify(execFile);
|
|
19144
|
-
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);
|
|
19145
19240
|
try {
|
|
19146
|
-
|
|
19147
|
-
cwd,
|
|
19148
|
-
encoding: "utf8"
|
|
19149
|
-
});
|
|
19150
|
-
return {
|
|
19151
|
-
success: true,
|
|
19152
|
-
stdout: stdout.trim(),
|
|
19153
|
-
stderr: stderr.trim()
|
|
19154
|
-
};
|
|
19241
|
+
await (options.runner ?? defaultInstallDependencyRunner)(runnerInput);
|
|
19155
19242
|
} catch (error) {
|
|
19156
|
-
const failure = error;
|
|
19157
19243
|
return {
|
|
19158
|
-
|
|
19159
|
-
|
|
19160
|
-
|
|
19244
|
+
dependencyStatus: "skipped",
|
|
19245
|
+
dependencyReason: isSupplyChainTrustError(error) ? "trust-policy-blocked" : "install-command-failed",
|
|
19246
|
+
installCommand: formatInstallCommand(runnerInput)
|
|
19161
19247
|
};
|
|
19162
19248
|
}
|
|
19249
|
+
return { dependencyStatus: "created" };
|
|
19163
19250
|
};
|
|
19164
|
-
const
|
|
19165
|
-
|
|
19166
|
-
|
|
19167
|
-
|
|
19168
|
-
|
|
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;
|
|
19169
19298
|
}
|
|
19170
|
-
if ((await run("git", [
|
|
19171
|
-
"rev-parse",
|
|
19172
|
-
"--verify",
|
|
19173
|
-
"origin/main"
|
|
19174
|
-
], cwd)).success) return "main";
|
|
19175
|
-
if ((await run("git", [
|
|
19176
|
-
"rev-parse",
|
|
19177
|
-
"--verify",
|
|
19178
|
-
"origin/master"
|
|
19179
|
-
], cwd)).success) return "master";
|
|
19180
|
-
return null;
|
|
19181
19299
|
};
|
|
19182
|
-
const
|
|
19183
|
-
|
|
19184
|
-
|
|
19185
|
-
"--verify",
|
|
19186
|
-
NEW_BRANCH_PREFIX
|
|
19187
|
-
], cwd)).success) return NEW_BRANCH_PREFIX;
|
|
19188
|
-
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);
|
|
19189
19303
|
};
|
|
19190
|
-
const
|
|
19191
|
-
|
|
19192
|
-
const
|
|
19193
|
-
|
|
19194
|
-
|
|
19195
|
-
|
|
19196
|
-
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
|
|
19201
|
-
|
|
19202
|
-
|
|
19203
|
-
|
|
19204
|
-
|
|
19205
|
-
|
|
19206
|
-
status: "not-attempted",
|
|
19207
|
-
reason: "gh-not-authenticated"
|
|
19208
|
-
};
|
|
19209
|
-
const defaultBranch = await detectDefaultBranch(cwd);
|
|
19210
|
-
if (!defaultBranch) return {
|
|
19211
|
-
status: "not-attempted",
|
|
19212
|
-
reason: "no-default-branch"
|
|
19213
|
-
};
|
|
19214
|
-
const previousBranchProbe = await run("git", [
|
|
19215
|
-
"rev-parse",
|
|
19216
|
-
"--abbrev-ref",
|
|
19217
|
-
"HEAD"
|
|
19218
|
-
], cwd);
|
|
19219
|
-
if (!previousBranchProbe.success || previousBranchProbe.stdout === "HEAD") return {
|
|
19220
|
-
status: "not-attempted",
|
|
19221
|
-
reason: "detached-head"
|
|
19222
|
-
};
|
|
19223
|
-
const previousBranch = previousBranchProbe.stdout;
|
|
19224
|
-
await run("git", [
|
|
19225
|
-
"fetch",
|
|
19226
|
-
"origin",
|
|
19227
|
-
defaultBranch
|
|
19228
|
-
], cwd);
|
|
19229
|
-
const newBranch = await findUniqueBranchName(cwd);
|
|
19230
|
-
if (!(await run("git", [
|
|
19231
|
-
"checkout",
|
|
19232
|
-
"-b",
|
|
19233
|
-
newBranch,
|
|
19234
|
-
`origin/${defaultBranch}`
|
|
19235
|
-
], cwd)).success) return {
|
|
19236
|
-
status: "not-attempted",
|
|
19237
|
-
reason: "checkout-failed"
|
|
19238
|
-
};
|
|
19239
|
-
const restoreToPreviousBranch = async (deleteNewBranch) => {
|
|
19240
|
-
await run("git", ["checkout", previousBranch], cwd);
|
|
19241
|
-
if (deleteNewBranch) await run("git", [
|
|
19242
|
-
"branch",
|
|
19243
|
-
"-D",
|
|
19244
|
-
newBranch
|
|
19245
|
-
], cwd);
|
|
19246
|
-
};
|
|
19247
|
-
if (!(await run("git", [
|
|
19248
|
-
"add",
|
|
19249
|
-
"--",
|
|
19250
|
-
path$1.relative(cwd, workflowPath)
|
|
19251
|
-
], cwd)).success) {
|
|
19252
|
-
await restoreToPreviousBranch(true);
|
|
19253
|
-
return {
|
|
19254
|
-
status: "not-attempted",
|
|
19255
|
-
reason: "git-add-failed"
|
|
19256
|
-
};
|
|
19304
|
+
const canInstallNativeAgentHooks = (agents) => agents.some((agent) => agent === "claude-code" || agent === "cursor");
|
|
19305
|
+
const installReactDoctorSkillStep = async (sourceDir, selectedAgents, projectRoot) => {
|
|
19306
|
+
const installSpinner = spinner(`Installing ${SKILL_NAME} skill...`).start();
|
|
19307
|
+
try {
|
|
19308
|
+
const installResult = await installSkillsFromSource({
|
|
19309
|
+
source: sourceDir,
|
|
19310
|
+
agents: selectedAgents,
|
|
19311
|
+
cwd: projectRoot,
|
|
19312
|
+
mode: "copy"
|
|
19313
|
+
});
|
|
19314
|
+
if (installResult.skills.length === 0) throw new Error(`Could not parse ${SKILL_MANIFEST_FILE} for ${SKILL_NAME} (missing or invalid frontmatter).`);
|
|
19315
|
+
if (installResult.failed.length > 0) throw new Error(installResult.failed.map((failure) => `${getSkillAgentConfig(failure.agent).displayName}: ${failure.error}`).join("\n"));
|
|
19316
|
+
installSpinner.succeed(`${SKILL_NAME} skill installed for ${selectedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
19317
|
+
} catch (error) {
|
|
19318
|
+
installSpinner.fail(`Failed to install ${SKILL_NAME} skill.`);
|
|
19319
|
+
throw error;
|
|
19257
19320
|
}
|
|
19258
|
-
|
|
19259
|
-
|
|
19260
|
-
|
|
19261
|
-
|
|
19262
|
-
|
|
19263
|
-
|
|
19264
|
-
|
|
19265
|
-
|
|
19266
|
-
|
|
19267
|
-
};
|
|
19321
|
+
};
|
|
19322
|
+
const installReactDoctorGitHookStep = (gitHookTarget) => {
|
|
19323
|
+
const hookSpinner = spinner("Installing React Doctor pre-commit hook...").start();
|
|
19324
|
+
try {
|
|
19325
|
+
const hookResult = installReactDoctorGitHook({
|
|
19326
|
+
hookPath: gitHookTarget.hookPath,
|
|
19327
|
+
projectRoot: gitHookTarget.runnerRoot,
|
|
19328
|
+
kind: gitHookTarget.kind,
|
|
19329
|
+
hooksPathConfig: gitHookTarget.hooksPathConfig
|
|
19330
|
+
});
|
|
19331
|
+
hookSpinner.succeed(formatGitHookInstallMessage(hookResult));
|
|
19332
|
+
recordCount(METRIC.installGitHook, 1, { kind: hookResult.kind });
|
|
19333
|
+
} catch (error) {
|
|
19334
|
+
hookSpinner.fail("Failed to install React Doctor pre-commit hook.");
|
|
19335
|
+
throw error;
|
|
19268
19336
|
}
|
|
19269
|
-
|
|
19270
|
-
|
|
19271
|
-
|
|
19272
|
-
|
|
19273
|
-
|
|
19274
|
-
|
|
19275
|
-
|
|
19276
|
-
|
|
19277
|
-
|
|
19278
|
-
|
|
19279
|
-
|
|
19337
|
+
};
|
|
19338
|
+
const installReactDoctorAgentHooksStep = (projectRoot, selectedAgents) => {
|
|
19339
|
+
const hookSpinner = spinner("Installing React Doctor agent hooks...").start();
|
|
19340
|
+
try {
|
|
19341
|
+
const hookResult = installReactDoctorAgentHooks({
|
|
19342
|
+
projectRoot,
|
|
19343
|
+
agents: selectedAgents
|
|
19344
|
+
});
|
|
19345
|
+
if (hookResult.installedAgents.length === 0) hookSpinner.succeed("No supported native agent hook targets selected.");
|
|
19346
|
+
else {
|
|
19347
|
+
hookSpinner.succeed(`React Doctor agent hooks installed for ${hookResult.installedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
19348
|
+
recordCount(METRIC.installAgentHooks, 1, { agentsCount: hookResult.installedAgents.length });
|
|
19349
|
+
}
|
|
19350
|
+
} catch (error) {
|
|
19351
|
+
hookSpinner.fail("Failed to install React Doctor agent hooks.");
|
|
19352
|
+
throw error;
|
|
19280
19353
|
}
|
|
19281
|
-
const prCreate = await run("gh", [
|
|
19282
|
-
"pr",
|
|
19283
|
-
"create",
|
|
19284
|
-
"--title",
|
|
19285
|
-
prTitle,
|
|
19286
|
-
"--body",
|
|
19287
|
-
prBody,
|
|
19288
|
-
"--base",
|
|
19289
|
-
defaultBranch,
|
|
19290
|
-
"--head",
|
|
19291
|
-
newBranch
|
|
19292
|
-
], cwd);
|
|
19293
|
-
await restoreToPreviousBranch(false);
|
|
19294
|
-
if (!prCreate.success) return {
|
|
19295
|
-
status: "branch-pushed",
|
|
19296
|
-
branch: newBranch
|
|
19297
|
-
};
|
|
19298
|
-
return {
|
|
19299
|
-
status: "pr-opened",
|
|
19300
|
-
url: prCreate.stdout.split(/\r?\n/).filter(Boolean).pop() ?? ""
|
|
19301
|
-
};
|
|
19302
19354
|
};
|
|
19303
|
-
const
|
|
19304
|
-
|
|
19305
|
-
|
|
19306
|
-
|
|
19307
|
-
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
|
|
19311
|
-
|
|
19355
|
+
const installReactDoctorWorkflowStep = (projectRoot) => {
|
|
19356
|
+
return reportWorkflowResult(spinner("Adding GitHub Actions workflow...").start(), installReactDoctorWorkflow(projectRoot), projectRoot);
|
|
19357
|
+
};
|
|
19358
|
+
const upgradeReactDoctorWorkflowStep = (projectRoot) => {
|
|
19359
|
+
const workflowSpinner = spinner("Upgrading GitHub Actions workflow to v2...").start();
|
|
19360
|
+
const upgradeResult = upgradeReactDoctorWorkflowInPlace(projectRoot);
|
|
19361
|
+
if (upgradeResult.status === "failed") {
|
|
19362
|
+
workflowSpinner.fail("Couldn't update the GitHub Actions workflow.");
|
|
19363
|
+
return false;
|
|
19364
|
+
}
|
|
19365
|
+
if (upgradeResult.status === "not-needed") {
|
|
19366
|
+
workflowSpinner.succeed("GitHub Actions workflow already up to date.");
|
|
19367
|
+
return false;
|
|
19368
|
+
}
|
|
19369
|
+
workflowSpinner.succeed(`Upgraded the GitHub Actions workflow to v2 at ${path$1.relative(projectRoot, upgradeResult.workflowPath)}.`);
|
|
19370
|
+
recordCount(METRIC.installWorkflow, 1, { kind: "upgrade" });
|
|
19371
|
+
return true;
|
|
19372
|
+
};
|
|
19373
|
+
const runInstallReactDoctor = async (options = {}) => {
|
|
19374
|
+
const requestedProjectRoot = options.projectRoot ?? process.cwd();
|
|
19375
|
+
const projectRoot = findNearestPackageDirectory(requestedProjectRoot) ?? requestedProjectRoot;
|
|
19376
|
+
const sourceDir = options.sourceDir ?? getSkillSourceDirectory();
|
|
19377
|
+
if (!fs$1.existsSync(path$1.join(sourceDir, SKILL_MANIFEST_FILE))) {
|
|
19378
|
+
cliLogger.error(`Could not locate the ${SKILL_NAME} skill bundled with this package.`);
|
|
19379
|
+
process.exitCode = 1;
|
|
19380
|
+
return;
|
|
19381
|
+
}
|
|
19382
|
+
const detectedAgents = options.detectedAgents ?? await detectAvailableAgents();
|
|
19383
|
+
if (detectedAgents.length === 0) {
|
|
19384
|
+
cliLogger.error("No supported coding agents detected.");
|
|
19385
|
+
cliLogger.dim(" Looked for binaries on PATH (claude, codex, cursor, droid, gemini, copilot, opencode, pi)");
|
|
19386
|
+
cliLogger.dim(" and config dirs in $HOME (~/.claude, ~/.cursor, ~/.codex, ~/.gemini, ...).");
|
|
19387
|
+
process.exitCode = 1;
|
|
19388
|
+
return;
|
|
19389
|
+
}
|
|
19390
|
+
const skipPrompts = shouldSkipPrompts({ yes: options.yes });
|
|
19391
|
+
const gitHookTarget = options.gitHookPath === void 0 ? detectGitHookTarget(projectRoot) : options.gitHookPath === null ? null : buildManualGitHookTarget(options.gitHookPath, projectRoot);
|
|
19392
|
+
const gitHookPath = gitHookTarget?.hookPath;
|
|
19393
|
+
const promptOptions = options.onPromptCancel === void 0 ? {} : { onCancel: options.onPromptCancel };
|
|
19394
|
+
const prompt = options.prompt ?? prompts;
|
|
19395
|
+
const workflowTargetPath = getReactDoctorWorkflowPath(projectRoot);
|
|
19396
|
+
const existingWorkflow = readReactDoctorWorkflow(projectRoot);
|
|
19397
|
+
const canInstallWorkflow = !fs$1.existsSync(workflowTargetPath);
|
|
19398
|
+
const canUpgradeWorkflow = existingWorkflow !== null && workflowUsesV1Action(existingWorkflow.content) && !hasHandledActionUpgrade(projectRoot);
|
|
19399
|
+
const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || !skipPrompts && await askAddToGitHubActions(prompt) === "yes");
|
|
19400
|
+
const upgradePromptOutcome = canUpgradeWorkflow && !options.yes && !skipPrompts ? await askUpgradeActionVersion(prompt) : null;
|
|
19401
|
+
const shouldUpgradeWorkflow = canUpgradeWorkflow && (Boolean(options.yes) || upgradePromptOutcome === "yes");
|
|
19402
|
+
if (upgradePromptOutcome === "no" && !options.dryRun) recordActionUpgradeDecision(projectRoot, "declined");
|
|
19403
|
+
const selectedAgents = skipPrompts ? detectedAgents : (await prompt({
|
|
19404
|
+
type: "multiselect",
|
|
19405
|
+
name: "agents",
|
|
19406
|
+
message: `Install the ${highlighter.info(`/react-doctor`)} skill for:`,
|
|
19407
|
+
choices: detectedAgents.map((agent) => ({
|
|
19408
|
+
title: getSkillAgentConfig(agent).displayName,
|
|
19409
|
+
value: agent,
|
|
19410
|
+
selected: true
|
|
19411
|
+
})),
|
|
19412
|
+
instructions: false,
|
|
19413
|
+
min: 1
|
|
19414
|
+
}, promptOptions)).agents ?? [];
|
|
19415
|
+
if (selectedAgents.length === 0) return;
|
|
19416
|
+
let dependencyResult;
|
|
19417
|
+
if (!options.dryRun) {
|
|
19418
|
+
await installReactDoctorSkillStep(sourceDir, selectedAgents, projectRoot);
|
|
19419
|
+
dependencyResult = await installReactDoctorPackageSetup(projectRoot, options.installDependencyRunner);
|
|
19420
|
+
}
|
|
19421
|
+
let didInstallWorkflow = false;
|
|
19422
|
+
if (!options.dryRun && (shouldInstallWorkflow || shouldUpgradeWorkflow)) {
|
|
19423
|
+
cliLogger.break();
|
|
19424
|
+
if (shouldInstallWorkflow) didInstallWorkflow = installReactDoctorWorkflowStep(projectRoot);
|
|
19425
|
+
else if (upgradeReactDoctorWorkflowStep(projectRoot)) recordActionUpgradeDecision(projectRoot, "accepted");
|
|
19426
|
+
}
|
|
19427
|
+
const setupActionChoices = [...gitHookPath === null || gitHookPath === void 0 ? [] : [{
|
|
19428
|
+
title: "Pre-commit hook",
|
|
19429
|
+
description: "Check staged changes before each commit",
|
|
19430
|
+
value: SETUP_OPTION_GIT_HOOK,
|
|
19431
|
+
selected: true
|
|
19432
|
+
}], ...canInstallNativeAgentHooks(selectedAgents) ? [{
|
|
19433
|
+
title: "Agent hooks",
|
|
19434
|
+
description: "Ask Claude Code or Cursor to scan after code edits",
|
|
19435
|
+
value: SETUP_OPTION_AGENT_HOOKS,
|
|
19436
|
+
selected: Boolean(options.agentHooks)
|
|
19437
|
+
}] : []];
|
|
19438
|
+
const setupChoices = setupActionChoices.length === 0 ? [] : [{
|
|
19439
|
+
title: "Skip optional setup",
|
|
19440
|
+
description: "Install only the agent skill and package setup",
|
|
19441
|
+
value: SETUP_OPTION_SKIP,
|
|
19442
|
+
selected: false
|
|
19443
|
+
}, ...setupActionChoices];
|
|
19444
|
+
if (setupChoices.length > 0 && !options.dryRun) cliLogger.break();
|
|
19445
|
+
const selectedSetupOptions = skipPrompts || setupChoices.length === 0 ? [] : (await prompt({
|
|
19446
|
+
type: "multiselect",
|
|
19447
|
+
name: "setupOptions",
|
|
19448
|
+
message: "Select additional React Doctor setup:",
|
|
19449
|
+
choices: setupChoices,
|
|
19450
|
+
instructions: false
|
|
19451
|
+
}, promptOptions)).setupOptions ?? [];
|
|
19452
|
+
const selectedSetupActions = selectedSetupOptions.filter((setupOption) => setupOption !== SETUP_OPTION_SKIP);
|
|
19453
|
+
const didSkipOptionalSetup = selectedSetupActions.length === 0 && selectedSetupOptions.includes(SETUP_OPTION_SKIP);
|
|
19454
|
+
const shouldInstallGitHook = gitHookPath != null && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_GIT_HOOK));
|
|
19455
|
+
const shouldInstallAgentHooks = Boolean(options.agentHooks) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_AGENT_HOOKS);
|
|
19456
|
+
if (!options.dryRun) {
|
|
19457
|
+
if (shouldInstallGitHook && gitHookTarget !== null && gitHookTarget !== void 0) installReactDoctorGitHookStep(gitHookTarget);
|
|
19458
|
+
if (shouldInstallAgentHooks) installReactDoctorAgentHooksStep(projectRoot, selectedAgents);
|
|
19459
|
+
}
|
|
19460
|
+
if (options.dryRun) {
|
|
19461
|
+
cliLogger.log(`Dry run — would install ${SKILL_NAME} skill for:`);
|
|
19462
|
+
for (const agent of selectedAgents) cliLogger.dim(` - ${getSkillAgentConfig(agent).displayName}`);
|
|
19463
|
+
cliLogger.dim(` Source: ${sourceDir}`);
|
|
19464
|
+
cliLogger.dim(" Package script: doctor (or react-doctor if doctor exists)");
|
|
19465
|
+
cliLogger.dim(" Dev dependency: react-doctor");
|
|
19466
|
+
if (shouldInstallGitHook) cliLogger.dim(` Git hook: ${gitHookPath}`);
|
|
19467
|
+
if (shouldInstallAgentHooks) cliLogger.dim(" Agent hooks: Claude Code / Cursor when selected");
|
|
19468
|
+
if (shouldInstallWorkflow) cliLogger.dim(` GitHub Actions workflow: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
19469
|
+
if (shouldUpgradeWorkflow) cliLogger.dim(` Upgrade GitHub Actions workflow to v2: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
19470
|
+
return;
|
|
19471
|
+
}
|
|
19472
|
+
recordCount(METRIC.installCompleted, 1, {
|
|
19473
|
+
agentsCount: selectedAgents.length,
|
|
19474
|
+
gitHook: shouldInstallGitHook,
|
|
19475
|
+
agentHooks: shouldInstallAgentHooks,
|
|
19476
|
+
workflow: didInstallWorkflow,
|
|
19477
|
+
dependencyStatus: dependencyResult?.dependencyStatus ?? "skipped",
|
|
19478
|
+
packageManager: detectPackageManager(projectRoot)
|
|
19479
|
+
});
|
|
19480
|
+
for (const agent of selectedAgents) recordCount(METRIC.installAgent, 1, { agent });
|
|
19481
|
+
};
|
|
19482
|
+
//#endregion
|
|
19483
|
+
//#region src/cli/utils/install-skill-for-agent.ts
|
|
19484
|
+
const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
|
|
19485
|
+
const source = getSkillSourceDirectory();
|
|
19486
|
+
if (!fs$1.existsSync(path$1.join(source, SKILL_MANIFEST_FILE))) return false;
|
|
19487
|
+
const result = await installSkillsFromSource({
|
|
19488
|
+
source,
|
|
19489
|
+
agents: [agent],
|
|
19490
|
+
cwd: projectRoot,
|
|
19491
|
+
mode: "copy"
|
|
19492
|
+
});
|
|
19493
|
+
return result.skills.length > 0 && result.failed.length === 0;
|
|
19312
19494
|
};
|
|
19313
19495
|
//#endregion
|
|
19314
19496
|
//#region src/cli/utils/launch-agent.ts
|
|
@@ -19399,9 +19581,6 @@ const copyToClipboard = (text) => {
|
|
|
19399
19581
|
};
|
|
19400
19582
|
//#endregion
|
|
19401
19583
|
//#region src/cli/utils/handoff-to-agent.ts
|
|
19402
|
-
const CI_YES_CHOICE = "ci-yes";
|
|
19403
|
-
const CI_LEARN_MORE_CHOICE = "ci-learn-more";
|
|
19404
|
-
const CI_NO_CHOICE = "ci-no";
|
|
19405
19584
|
const CLIPBOARD_CHOICE = "clipboard";
|
|
19406
19585
|
const SKIP_CHOICE = "skip";
|
|
19407
19586
|
const printPayload = (payload) => {
|
|
@@ -19410,59 +19589,11 @@ const printPayload = (payload) => {
|
|
|
19410
19589
|
cliLogger.log(payload);
|
|
19411
19590
|
cliLogger.log(highlighter.dim("──────────────────────"));
|
|
19412
19591
|
};
|
|
19413
|
-
const setUpGitHubActions = async (rootDirectory) => {
|
|
19414
|
-
const projectRoot = findNearestPackageDirectory(rootDirectory) ?? rootDirectory;
|
|
19415
|
-
try {
|
|
19416
|
-
installReactDoctorScriptStep(projectRoot);
|
|
19417
|
-
} catch {}
|
|
19418
|
-
const workflowSpinner = spinner("Adding GitHub Actions workflow...").start();
|
|
19419
|
-
const workflowResult = installReactDoctorWorkflow(projectRoot);
|
|
19420
|
-
reportWorkflowResult(workflowSpinner, workflowResult, projectRoot);
|
|
19421
|
-
cliLogger.break();
|
|
19422
|
-
if (workflowResult.status === "failed") {
|
|
19423
|
-
cliLogger.log(` Couldn't set up GitHub Actions automatically. Follow the guide at ${highlighter.info(CI_URL)}`);
|
|
19424
|
-
return;
|
|
19425
|
-
}
|
|
19426
|
-
if (workflowResult.status === "created") {
|
|
19427
|
-
const pullRequestSpinner = spinner("Opening a pull request for review...").start();
|
|
19428
|
-
const pullRequestResult = await openWorkflowPullRequest({ workflowPath: workflowResult.workflowPath });
|
|
19429
|
-
if (pullRequestResult.status === "pr-opened") pullRequestSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
|
|
19430
|
-
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}`);
|
|
19431
|
-
else {
|
|
19432
|
-
pullRequestSpinner.stop();
|
|
19433
|
-
if (await stageWorkflowFile({ workflowPath: workflowResult.workflowPath })) cliLogger.log(` Staged the workflow file. Commit it to start scanning every pull request.`);
|
|
19434
|
-
else cliLogger.log(" React Doctor will now scan every new pull request automatically.");
|
|
19435
|
-
}
|
|
19436
|
-
}
|
|
19437
|
-
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
19438
|
-
};
|
|
19439
|
-
const UPGRADE_YES_CHOICE = "upgrade-yes";
|
|
19440
|
-
const UPGRADE_NO_CHOICE = "upgrade-no";
|
|
19441
19592
|
const UPGRADE_COMMIT_MESSAGE = "ci: upgrade React Doctor GitHub Action to v2";
|
|
19442
19593
|
const UPGRADE_PR_TITLE = "Upgrade React Doctor Action to v2";
|
|
19443
19594
|
const UPGRADE_PR_BODY = `Bumps the React Doctor GitHub Actions workflow to the action's latest major, \`millionco/react-doctor@v2\`.
|
|
19444
19595
|
|
|
19445
19596
|
Docs: https://www.react.doctor/ci`;
|
|
19446
|
-
const askUpgradeActionVersion = async () => {
|
|
19447
|
-
const { upgradeChoice } = await prompts({
|
|
19448
|
-
type: "select",
|
|
19449
|
-
name: "upgradeChoice",
|
|
19450
|
-
message: "A new major of the React Doctor Action (v2) is out. Upgrade this repo's workflow?",
|
|
19451
|
-
hint: " ",
|
|
19452
|
-
choices: [{
|
|
19453
|
-
title: "Yes (recommended)",
|
|
19454
|
-
description: "Open a PR bumping the workflow to millionco/react-doctor@v2",
|
|
19455
|
-
value: UPGRADE_YES_CHOICE
|
|
19456
|
-
}, {
|
|
19457
|
-
title: "No, thanks",
|
|
19458
|
-
description: "Keep @v1 — won't ask again for this repo",
|
|
19459
|
-
value: UPGRADE_NO_CHOICE
|
|
19460
|
-
}],
|
|
19461
|
-
initial: 0
|
|
19462
|
-
}, { onCancel: () => true });
|
|
19463
|
-
if (upgradeChoice === void 0) return "cancel";
|
|
19464
|
-
return upgradeChoice === UPGRADE_YES_CHOICE ? "yes" : "no";
|
|
19465
|
-
};
|
|
19466
19597
|
const upgradeGitHubActionsWorkflow = async (workflow) => {
|
|
19467
19598
|
const { content, changed } = upgradeWorkflowActionToV2(workflow.content);
|
|
19468
19599
|
if (!changed) return false;
|
|
@@ -19507,46 +19638,6 @@ const maybeOfferActionUpgrade = async (projectRoot) => {
|
|
|
19507
19638
|
}
|
|
19508
19639
|
if (await upgradeGitHubActionsWorkflow(workflow)) recordActionUpgradeDecision(projectRoot, "accepted");
|
|
19509
19640
|
};
|
|
19510
|
-
const SGR_BOLD_OFF = "\x1B[22m";
|
|
19511
|
-
const ciQuestionMessage = [
|
|
19512
|
-
"Add React Doctor to GitHub Actions?",
|
|
19513
|
-
`${SGR_BOLD_OFF} ${highlighter.dim("Scan every pull request to prevent new React issues while you fix the backlog.")}`,
|
|
19514
|
-
`${SGR_BOLD_OFF} ${highlighter.dim(`Used by teams at ${CI_TRUST_COMPANIES}.`)}`
|
|
19515
|
-
].join("\n");
|
|
19516
|
-
const askAddToGitHubActions = async () => {
|
|
19517
|
-
while (true) {
|
|
19518
|
-
const { ciChoice } = await prompts({
|
|
19519
|
-
type: "select",
|
|
19520
|
-
name: "ciChoice",
|
|
19521
|
-
message: ciQuestionMessage,
|
|
19522
|
-
hint: " ",
|
|
19523
|
-
choices: [
|
|
19524
|
-
{
|
|
19525
|
-
title: "Yes (recommended)",
|
|
19526
|
-
description: "Adds the workflow file and a doctor package script",
|
|
19527
|
-
value: CI_YES_CHOICE
|
|
19528
|
-
},
|
|
19529
|
-
{
|
|
19530
|
-
title: "Learn more",
|
|
19531
|
-
description: highlighter.info(CI_URL),
|
|
19532
|
-
value: CI_LEARN_MORE_CHOICE
|
|
19533
|
-
},
|
|
19534
|
-
{
|
|
19535
|
-
title: "No, thanks",
|
|
19536
|
-
description: "Continue to the agent handoff",
|
|
19537
|
-
value: CI_NO_CHOICE
|
|
19538
|
-
}
|
|
19539
|
-
],
|
|
19540
|
-
initial: 0
|
|
19541
|
-
}, { onCancel: () => true });
|
|
19542
|
-
if (ciChoice === void 0) return "cancel";
|
|
19543
|
-
if (ciChoice === CI_YES_CHOICE) return "yes";
|
|
19544
|
-
if (ciChoice === CI_NO_CHOICE) return "no";
|
|
19545
|
-
const opened = openUrl(CI_URL);
|
|
19546
|
-
cliLogger.log(opened ? `Opened ${highlighter.info(CI_URL)} in your browser.` : `Visit ${highlighter.info(CI_URL)} to learn more.`);
|
|
19547
|
-
cliLogger.break();
|
|
19548
|
-
}
|
|
19549
|
-
};
|
|
19550
19641
|
const detectLaunchableAgents = async () => {
|
|
19551
19642
|
const detected = new Set(await detectAvailableAgents());
|
|
19552
19643
|
return Object.keys(CLI_AGENT_BINARIES).filter((agentId) => detected.has(agentId) && isCommandAvailable(CLI_AGENT_BINARIES[agentId]));
|
|
@@ -19563,7 +19654,7 @@ const handoffToAgent = async (input) => {
|
|
|
19563
19654
|
});
|
|
19564
19655
|
if (ciOutcome === "cancel") return;
|
|
19565
19656
|
if (ciOutcome === "yes") {
|
|
19566
|
-
await setUpGitHubActions(input.rootDirectory);
|
|
19657
|
+
await setUpGitHubActions({ rootDirectory: input.rootDirectory });
|
|
19567
19658
|
cliLogger.break();
|
|
19568
19659
|
}
|
|
19569
19660
|
} else await maybeOfferActionUpgrade(projectRootForCi);
|
|
@@ -19714,6 +19805,14 @@ const HAPPY_FACE_LINES = [
|
|
|
19714
19805
|
"│ ▽ │",
|
|
19715
19806
|
"└─────┘"
|
|
19716
19807
|
];
|
|
19808
|
+
const FACE_INDENT = " ";
|
|
19809
|
+
const FACE_PREFIX_WIDTH = 2 + (HAPPY_FACE_LINES[0]?.length ?? 0) + 2;
|
|
19810
|
+
const clampToColumns = (text, maxColumns) => {
|
|
19811
|
+
if (maxColumns <= 0) return "";
|
|
19812
|
+
if (text.length <= maxColumns) return text;
|
|
19813
|
+
if (maxColumns === 1) return "…";
|
|
19814
|
+
return `${text.slice(0, maxColumns - 1).trimEnd()}…`;
|
|
19815
|
+
};
|
|
19717
19816
|
const typeLine = (linePrefix, text, style, charDelayMs) => Effect.gen(function* () {
|
|
19718
19817
|
const characters = [...text];
|
|
19719
19818
|
for (let length = 1; length <= characters.length; length += 1) {
|
|
@@ -19727,13 +19826,17 @@ const playWelcomeScene = (options = {}) => Effect.gen(function* () {
|
|
|
19727
19826
|
const interLineDelayMs = 250 / speedMultiplier;
|
|
19728
19827
|
const explanationHoldMs = WELCOME_EXPLANATION_HOLD_MS / speedMultiplier;
|
|
19729
19828
|
const face = HAPPY_FACE_LINES.map((line) => highlighter.success(line));
|
|
19730
|
-
const mouthPrefix =
|
|
19731
|
-
|
|
19829
|
+
const mouthPrefix = `${FACE_INDENT}${face[2] ?? ""}${FACE_INDENT}`;
|
|
19830
|
+
const terminalColumns = process.stdout.columns;
|
|
19831
|
+
const availableTextColumns = terminalColumns && terminalColumns > 0 ? Math.max(0, terminalColumns - FACE_PREFIX_WIDTH - 1) : Number.POSITIVE_INFINITY;
|
|
19832
|
+
const greeting = clampToColumns("Welcome to React Doctor", availableTextColumns);
|
|
19833
|
+
const tagline = clampToColumns("I diagnose your React code for bugs, security & performance.", availableTextColumns);
|
|
19834
|
+
yield* writeStdout(`\n${face.map((line) => `${FACE_INDENT}${line}`).join("\n")}\n`);
|
|
19732
19835
|
yield* writeStdout("\x1B[3A");
|
|
19733
|
-
yield* typeLine(
|
|
19836
|
+
yield* typeLine(`${FACE_INDENT}${face[1] ?? ""}${FACE_INDENT}`, greeting, (fragment) => highlighter.bold(fragment), charDelayMs);
|
|
19734
19837
|
yield* Effect.sleep(interLineDelayMs);
|
|
19735
19838
|
yield* writeStdout("\x1B[1B");
|
|
19736
|
-
yield* typeLine(mouthPrefix,
|
|
19839
|
+
yield* typeLine(mouthPrefix, tagline, (fragment) => highlighter.dim(fragment), charDelayMs);
|
|
19737
19840
|
yield* Effect.sleep(explanationHoldMs);
|
|
19738
19841
|
yield* writeStdout("\x1B[3A\r\x1B[0J");
|
|
19739
19842
|
});
|
|
@@ -20273,8 +20376,8 @@ const buildChangedFilesDiffInfo = (changedFiles) => ({
|
|
|
20273
20376
|
* `react-doctor.config.json` to `doctor.config.ts` before config is loaded,
|
|
20274
20377
|
* so the scan reads the renamed file and the user is told once. CI, coding
|
|
20275
20378
|
* agents, JSON/score output, pre-commit (`--staged`) hooks, and non-TTY runs
|
|
20276
|
-
* are left untouched — the loader
|
|
20277
|
-
* never mutates the repo unattended.
|
|
20379
|
+
* are left untouched — the loader still reads the legacy file as a deprecated
|
|
20380
|
+
* fallback and warns — so a scan never mutates the repo unattended.
|
|
20278
20381
|
*/
|
|
20279
20382
|
const maybeMigrateLegacyConfig = (requestedDirectory, { isQuiet, isStaged }) => {
|
|
20280
20383
|
if (!(!isQuiet && !isStaged && process.stdout.isTTY === true && !isCiOrCodingAgentEnvironment())) return;
|
|
@@ -20636,13 +20739,27 @@ const resolveRuleConfigTarget = async (projectRoot) => {
|
|
|
20636
20739
|
config: isPlainObject(embedded) ? embedded : {}
|
|
20637
20740
|
};
|
|
20638
20741
|
}
|
|
20639
|
-
if (loaded.format === "json")
|
|
20640
|
-
|
|
20641
|
-
|
|
20642
|
-
|
|
20643
|
-
|
|
20644
|
-
|
|
20645
|
-
|
|
20742
|
+
if (loaded.format === "json") {
|
|
20743
|
+
if (path$1.basename(loaded.configFilePath) === "react-doctor.config.json") {
|
|
20744
|
+
const legacyConfig = readObjectFile(loaded.configFilePath) ?? {};
|
|
20745
|
+
delete legacyConfig.$schema;
|
|
20746
|
+
return {
|
|
20747
|
+
format: "json",
|
|
20748
|
+
filePath: path$1.join(loaded.sourceDirectory, NEW_CONFIG_FILENAME),
|
|
20749
|
+
directory: loaded.sourceDirectory,
|
|
20750
|
+
exists: false,
|
|
20751
|
+
config: legacyConfig,
|
|
20752
|
+
migratedFromFilePath: loaded.configFilePath
|
|
20753
|
+
};
|
|
20754
|
+
}
|
|
20755
|
+
return {
|
|
20756
|
+
format: "json",
|
|
20757
|
+
filePath: loaded.configFilePath,
|
|
20758
|
+
directory: loaded.sourceDirectory,
|
|
20759
|
+
exists: true,
|
|
20760
|
+
config: readObjectFile(loaded.configFilePath) ?? {}
|
|
20761
|
+
};
|
|
20762
|
+
}
|
|
20646
20763
|
return {
|
|
20647
20764
|
format: "module",
|
|
20648
20765
|
filePath: loaded.configFilePath,
|
|
@@ -20721,7 +20838,10 @@ const writeRuleConfig = async (target, nextConfig) => {
|
|
|
20721
20838
|
return { written };
|
|
20722
20839
|
}
|
|
20723
20840
|
if (target.format === "package-json") writePackageJsonConfig(target.filePath, nextConfig);
|
|
20724
|
-
else
|
|
20841
|
+
else {
|
|
20842
|
+
writeJsonConfig(target.filePath, nextConfig);
|
|
20843
|
+
if (target.migratedFromFilePath) fs$1.rmSync(target.migratedFromFilePath, { force: true });
|
|
20844
|
+
}
|
|
20725
20845
|
clearConfigCache();
|
|
20726
20846
|
return { written: true };
|
|
20727
20847
|
};
|
|
@@ -21472,4 +21592,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
|
|
|
21472
21592
|
export {};
|
|
21473
21593
|
|
|
21474
21594
|
//# sourceMappingURL=cli.js.map
|
|
21475
|
-
//# debugId=
|
|
21595
|
+
//# debugId=afa1d140-a4ff-5bff-bb67-c4959b977495
|