react-doctor 0.4.0-dev.6216430 → 0.4.0-dev.73dcb20

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.
Files changed (3) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +158 -21
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -66,6 +66,7 @@ permissions:
66
66
  contents: read
67
67
  pull-requests: write
68
68
  issues: write
69
+ statuses: write # lets the action publish the score as a commit status
69
70
 
70
71
  concurrency:
71
72
  group: react-doctor-${{ github.event.pull_request.number || github.ref }}
@@ -78,15 +79,15 @@ jobs:
78
79
  - uses: actions/checkout@v5
79
80
  with:
80
81
  fetch-depth: 0 # so React Doctor can diff against the merge-base for new-vs-existing
81
- - uses: millionco/react-doctor@v1
82
+ - uses: millionco/react-doctor@v2
82
83
  ```
83
84
 
84
85
  `fetch-depth: 0` is recommended so the baseline comparison can read the base commit; without enough history the Action falls back to reporting every finding in the changed files.
85
86
 
86
- `@v1` always resolves to the latest `v1.x` release of the Action. For hardened CI — recommended whenever the workflow is granted `pull-requests: write` — pin to a full commit SHA instead and let Dependabot or Renovate keep it current:
87
+ `@v2` always resolves to the latest `v2.x` release of the Action. For hardened CI — recommended whenever the workflow is granted `pull-requests: write` — pin to a full commit SHA instead and let Dependabot or Renovate keep it current:
87
88
 
88
89
  ```yaml
89
- - uses: millionco/react-doctor@b612664043a9be414166e3c6a69b355e39a8dcf4 # v1.1.1
90
+ - uses: millionco/react-doctor@75932719d11ef50e110eac01ce04acdc05fde074 # v2.0.1
90
91
  ```
91
92
 
92
93
  [Add GitHub Action →](https://github.com/marketplace/actions/react-doctor)
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]="f6c4adc9-3353-560f-a49f-c50a13c0b8a2")}catch(e){}}();
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]="301c4437-ca87-5afb-b69d-b7a7c3678175")}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";
@@ -12191,7 +12191,7 @@ const makeNoopConsole = () => ({
12191
12191
  });
12192
12192
  //#endregion
12193
12193
  //#region src/cli/utils/version.ts
12194
- const VERSION = "0.4.0-dev.6216430";
12194
+ const VERSION = "0.4.0-dev.73dcb20";
12195
12195
  //#endregion
12196
12196
  //#region src/cli/utils/json-mode.ts
12197
12197
  let context = null;
@@ -12549,13 +12549,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
12549
12549
  * uploads source-map artifacts under, so stack frames symbolicate. Honors the
12550
12550
  * standard `SENTRY_RELEASE` override.
12551
12551
  */
12552
- const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.0-dev.6216430`;
12552
+ const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.0-dev.73dcb20`;
12553
12553
  /**
12554
12554
  * Deployment environment shown in Sentry's environment filter. Defaults to
12555
12555
  * `production` for tagged releases and `development` for dev/unbuilt versions,
12556
12556
  * overridable via the standard `SENTRY_ENVIRONMENT` env var.
12557
12557
  */
12558
- const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.0-dev.6216430") ? "development" : "production");
12558
+ const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.0-dev.73dcb20") ? "development" : "production");
12559
12559
  /**
12560
12560
  * Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
12561
12561
  * (set to `0` to disable tracing) and falls back to
@@ -16752,10 +16752,10 @@ const canAnimateOnboarding = (stream = process.stdout) => {
16752
16752
  };
16753
16753
  //#endregion
16754
16754
  //#region src/cli/utils/onboarding-state.ts
16755
- const GLOBAL_CONFIG_PROJECT_NAME$1 = "react-doctor";
16755
+ const GLOBAL_CONFIG_PROJECT_NAME$2 = "react-doctor";
16756
16756
  const ONBOARDED_AT_KEY = "onboardedAt";
16757
16757
  const getOnboardingStore = (options = {}) => new Conf({
16758
- projectName: GLOBAL_CONFIG_PROJECT_NAME$1,
16758
+ projectName: GLOBAL_CONFIG_PROJECT_NAME$2,
16759
16759
  cwd: options.cwd
16760
16760
  });
16761
16761
  const hasCompletedOnboarding = (options = {}) => {
@@ -18143,6 +18143,11 @@ permissions:
18143
18143
  # comments (PRs are issues under the hood). Not exercised on \`push\`
18144
18144
  # events, so safe to drop if you only run on \`main\`.
18145
18145
  issues: write
18146
+ # Lets the action publish a commit status with the score + error/warning
18147
+ # counts (links to the run). This is how a \`push\` to \`main\` surfaces its
18148
+ # result, since the PR comment is skipped off pull requests. Drop it to
18149
+ # disable the status (or set \`commit-status: false\` below).
18150
+ statuses: write
18146
18151
 
18147
18152
  # Cancels any in-flight scan for the same PR (or branch, on push) the moment
18148
18153
  # a new commit arrives, so reviewers only ever see the latest run.
@@ -18156,20 +18161,42 @@ jobs:
18156
18161
  steps:
18157
18162
  - uses: actions/checkout@v5
18158
18163
 
18159
- - uses: millionco/react-doctor@v1
18164
+ - uses: millionco/react-doctor@v2
18160
18165
  # Common configuration knobs — uncomment any to override the default.
18161
18166
  # Full reference: https://www.react.doctor/ci
18162
18167
  # with:
18163
- # non-blocking: true # Report findings but always exit 0 (won't fail the PR check)
18164
- # fail-on: warning # Gate level: "error" (default) | "warning" | "none"
18168
+ # blocking: warning # Gate level: "error" (default) | "warning" | "none" (advisory)
18169
+ # scope: full # On PRs, scan the whole project instead of just changed files
18165
18170
  # comment: false # Disable the sticky PR summary comment
18166
- # annotations: false # Disable inline GitHub Actions annotations on changed files
18167
- # version: "0.2.18" # Pin to a specific react-doctor version instead of "latest"
18171
+ # review-comments: false # Disable inline review comments on changed lines
18172
+ # commit-status: false # Disable the commit status (score + counts, links to the run)
18173
+ # version: "0.4.0" # Pin to a specific react-doctor version instead of "latest"
18168
18174
  # directory: apps/web # Scan a sub-directory (default: ".")
18169
18175
  # project: "web,admin" # In a monorepo, scan specific workspace project(s)
18170
18176
  `;
18171
18177
  const getReactDoctorWorkflowPath = (projectRoot) => path$1.join(projectRoot, ".github", "workflows", "react-doctor.yml");
18172
18178
  const isReactDoctorWorkflowInstalled = (projectRoot) => fs$1.existsSync(getReactDoctorWorkflowPath(projectRoot));
18179
+ const V1_FLOATING_ACTION_REF = String.raw`millionco/react-doctor@v1(?![\w.])`;
18180
+ const V2_FLOATING_ACTION_REF = "millionco/react-doctor@v2";
18181
+ const readReactDoctorWorkflow = (projectRoot) => {
18182
+ const workflowPath = getReactDoctorWorkflowPath(projectRoot);
18183
+ try {
18184
+ return {
18185
+ workflowPath,
18186
+ content: fs$1.readFileSync(workflowPath, "utf8")
18187
+ };
18188
+ } catch {
18189
+ return null;
18190
+ }
18191
+ };
18192
+ const workflowUsesV1Action = (content) => new RegExp(V1_FLOATING_ACTION_REF).test(content);
18193
+ const upgradeWorkflowActionToV2 = (content) => {
18194
+ const upgraded = content.replace(new RegExp(V1_FLOATING_ACTION_REF, "g"), V2_FLOATING_ACTION_REF);
18195
+ return {
18196
+ content: upgraded,
18197
+ changed: upgraded !== content
18198
+ };
18199
+ };
18173
18200
  const installReactDoctorWorkflow = (projectRoot) => {
18174
18201
  const workflowPath = getReactDoctorWorkflowPath(projectRoot);
18175
18202
  if (fs$1.existsSync(workflowPath)) return {
@@ -18999,6 +19026,41 @@ const runInstallReactDoctor = async (options = {}) => {
18999
19026
  for (const agent of selectedAgents) recordCount(METRIC.installAgent, 1, { agent });
19000
19027
  };
19001
19028
  //#endregion
19029
+ //#region src/cli/utils/hash-project-root.ts
19030
+ const hashProjectRoot = (projectRoot) => createHash("sha256").update(path$1.resolve(projectRoot)).digest("hex");
19031
+ //#endregion
19032
+ //#region src/cli/utils/action-upgrade-prompt.ts
19033
+ const GLOBAL_CONFIG_PROJECT_NAME$1 = "react-doctor";
19034
+ const getActionUpgradeStore = (options = {}) => new Conf({
19035
+ projectName: GLOBAL_CONFIG_PROJECT_NAME$1,
19036
+ cwd: options.cwd
19037
+ });
19038
+ const hasHandledActionUpgrade = (projectRoot, storeOptions = {}) => {
19039
+ try {
19040
+ const upgrades = getActionUpgradeStore(storeOptions).get("actionUpgrades", {});
19041
+ return Boolean(upgrades[hashProjectRoot(projectRoot)]);
19042
+ } catch {
19043
+ return true;
19044
+ }
19045
+ };
19046
+ const recordActionUpgradeDecision = (projectRoot, outcome, storeOptions = {}) => {
19047
+ try {
19048
+ const store = getActionUpgradeStore(storeOptions);
19049
+ const upgrades = store.get("actionUpgrades", {});
19050
+ store.set("actionUpgrades", {
19051
+ ...upgrades,
19052
+ [hashProjectRoot(projectRoot)]: {
19053
+ rootDirectory: path$1.resolve(projectRoot),
19054
+ outcome,
19055
+ at: (/* @__PURE__ */ new Date()).toISOString()
19056
+ }
19057
+ });
19058
+ return true;
19059
+ } catch {
19060
+ return false;
19061
+ }
19062
+ };
19063
+ //#endregion
19002
19064
  //#region src/cli/utils/install-skill-for-agent.ts
19003
19065
  const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
19004
19066
  const source = getSkillSourceDirectory();
@@ -19049,9 +19111,9 @@ const openUrl = (url) => {
19049
19111
  //#endregion
19050
19112
  //#region src/cli/utils/open-workflow-pull-request.ts
19051
19113
  const NEW_BRANCH_PREFIX = "react-doctor/add-github-actions";
19052
- const COMMIT_MESSAGE = "ci: add React Doctor GitHub Actions workflow";
19053
- const PR_TITLE = "Add React Doctor to GitHub Actions";
19054
- const 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.
19114
+ const DEFAULT_COMMIT_MESSAGE = "ci: add React Doctor GitHub Actions workflow";
19115
+ const DEFAULT_PR_TITLE = "Add React Doctor to GitHub Actions";
19116
+ 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.
19055
19117
 
19056
19118
  Docs: https://www.react.doctor/ci`;
19057
19119
  const execFileAsync = promisify(execFile);
@@ -19103,6 +19165,9 @@ const findUniqueBranchName = async (cwd) => {
19103
19165
  };
19104
19166
  const openWorkflowPullRequest = async (params) => {
19105
19167
  const workflowPath = path$1.resolve(params.workflowPath);
19168
+ const commitMessage = params.commitMessage ?? DEFAULT_COMMIT_MESSAGE;
19169
+ const prTitle = params.prTitle ?? DEFAULT_PR_TITLE;
19170
+ const prBody = params.prBody ?? DEFAULT_PR_BODY;
19106
19171
  const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
19107
19172
  if (!repoRootProbe.success) return {
19108
19173
  status: "not-attempted",
@@ -19169,7 +19234,7 @@ const openWorkflowPullRequest = async (params) => {
19169
19234
  if (!(await run("git", [
19170
19235
  "commit",
19171
19236
  "-m",
19172
- COMMIT_MESSAGE
19237
+ commitMessage
19173
19238
  ], cwd)).success) {
19174
19239
  await restoreToPreviousBranch(true);
19175
19240
  return {
@@ -19193,9 +19258,9 @@ const openWorkflowPullRequest = async (params) => {
19193
19258
  "pr",
19194
19259
  "create",
19195
19260
  "--title",
19196
- PR_TITLE,
19261
+ prTitle,
19197
19262
  "--body",
19198
- PR_BODY,
19263
+ prBody,
19199
19264
  "--base",
19200
19265
  defaultBranch,
19201
19266
  "--head",
@@ -19347,6 +19412,77 @@ const setUpGitHubActions = async (rootDirectory) => {
19347
19412
  }
19348
19413
  cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
19349
19414
  };
19415
+ const UPGRADE_YES_CHOICE = "upgrade-yes";
19416
+ const UPGRADE_NO_CHOICE = "upgrade-no";
19417
+ const UPGRADE_COMMIT_MESSAGE = "ci: upgrade React Doctor GitHub Action to v2";
19418
+ const UPGRADE_PR_TITLE = "Upgrade React Doctor Action to v2";
19419
+ const UPGRADE_PR_BODY = `Bumps the React Doctor GitHub Actions workflow to the action's latest major, \`millionco/react-doctor@v2\`.
19420
+
19421
+ Docs: https://www.react.doctor/ci`;
19422
+ const askUpgradeActionVersion = async () => {
19423
+ const { upgradeChoice } = await prompts({
19424
+ type: "select",
19425
+ name: "upgradeChoice",
19426
+ message: "A new major of the React Doctor Action (v2) is out. Upgrade this repo's workflow?",
19427
+ hint: " ",
19428
+ choices: [{
19429
+ title: "Yes (recommended)",
19430
+ description: "Open a PR bumping the workflow to millionco/react-doctor@v2",
19431
+ value: UPGRADE_YES_CHOICE
19432
+ }, {
19433
+ title: "No, thanks",
19434
+ description: "Keep @v1 — won't ask again for this repo",
19435
+ value: UPGRADE_NO_CHOICE
19436
+ }],
19437
+ initial: 0
19438
+ }, { onCancel: () => true });
19439
+ if (upgradeChoice === void 0) return "cancel";
19440
+ return upgradeChoice === UPGRADE_YES_CHOICE ? "yes" : "no";
19441
+ };
19442
+ const upgradeGitHubActionsWorkflow = async (workflow) => {
19443
+ const { content, changed } = upgradeWorkflowActionToV2(workflow.content);
19444
+ if (!changed) return false;
19445
+ const upgradeSpinner = spinner("Opening a pull request to upgrade React Doctor to v2...").start();
19446
+ try {
19447
+ fs$1.writeFileSync(workflow.workflowPath, content);
19448
+ } catch {
19449
+ upgradeSpinner.fail("Couldn't update the workflow file.");
19450
+ return false;
19451
+ }
19452
+ const pullRequestResult = await openWorkflowPullRequest({
19453
+ workflowPath: workflow.workflowPath,
19454
+ commitMessage: UPGRADE_COMMIT_MESSAGE,
19455
+ prTitle: UPGRADE_PR_TITLE,
19456
+ prBody: UPGRADE_PR_BODY
19457
+ });
19458
+ if (pullRequestResult.status === "pr-opened") upgradeSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
19459
+ else if (pullRequestResult.status === "branch-pushed") upgradeSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
19460
+ else {
19461
+ upgradeSpinner.stop();
19462
+ try {
19463
+ fs$1.writeFileSync(workflow.workflowPath, content);
19464
+ } catch {
19465
+ cliLogger.log(" Couldn't finish the upgrade. Re-run React Doctor to try again.");
19466
+ return false;
19467
+ }
19468
+ const didStage = await stageWorkflowFile({ workflowPath: workflow.workflowPath });
19469
+ cliLogger.log(didStage ? " Updated the workflow to @v2 and staged it. Commit it to finish the upgrade." : " Updated the workflow to @v2. Commit the change to finish the upgrade.");
19470
+ }
19471
+ return true;
19472
+ };
19473
+ const maybeOfferActionUpgrade = async (projectRoot) => {
19474
+ const workflow = readReactDoctorWorkflow(projectRoot);
19475
+ if (!workflow || !workflowUsesV1Action(workflow.content)) return;
19476
+ if (hasHandledActionUpgrade(projectRoot)) return;
19477
+ const outcome = await askUpgradeActionVersion();
19478
+ if (outcome === "cancel") return;
19479
+ recordCount(METRIC.agentHandoff, 1, { outcome: outcome === "yes" ? "upgrade-accepted" : "upgrade-declined" });
19480
+ if (outcome === "no") {
19481
+ recordActionUpgradeDecision(projectRoot, "declined");
19482
+ return;
19483
+ }
19484
+ if (await upgradeGitHubActionsWorkflow(workflow)) recordActionUpgradeDecision(projectRoot, "accepted");
19485
+ };
19350
19486
  const SGR_BOLD_OFF = "\x1B[22m";
19351
19487
  const ciQuestionMessage = [
19352
19488
  "Add React Doctor to GitHub Actions?",
@@ -19394,7 +19530,8 @@ const detectLaunchableAgents = async () => {
19394
19530
  const handoffToAgent = async (input) => {
19395
19531
  if (!input.interactive || input.diagnostics.length === 0) return;
19396
19532
  cliLogger.break();
19397
- if (!isReactDoctorWorkflowInstalled(findNearestPackageDirectory(input.rootDirectory) ?? input.rootDirectory)) {
19533
+ const projectRootForCi = findNearestPackageDirectory(input.rootDirectory) ?? input.rootDirectory;
19534
+ if (!isReactDoctorWorkflowInstalled(projectRootForCi)) {
19398
19535
  const ciOutcome = await askAddToGitHubActions();
19399
19536
  recordCount(METRIC.agentHandoff, 1, {
19400
19537
  outcome: `ci-${ciOutcome}`,
@@ -19405,7 +19542,7 @@ const handoffToAgent = async (input) => {
19405
19542
  await setUpGitHubActions(input.rootDirectory);
19406
19543
  cliLogger.break();
19407
19544
  }
19408
- }
19545
+ } else await maybeOfferActionUpgrade(projectRootForCi);
19409
19546
  const { handoffTarget } = await prompts({
19410
19547
  type: "select",
19411
19548
  name: "handoffTarget",
@@ -19739,7 +19876,7 @@ const getSetupPromptStore = (options = {}) => new Conf({
19739
19876
  projectName: GLOBAL_CONFIG_PROJECT_NAME,
19740
19877
  cwd: options.cwd
19741
19878
  });
19742
- const getSetupPromptProjectKey = (projectRoot) => createHash("sha256").update(path$1.resolve(projectRoot)).digest("hex");
19879
+ const getSetupPromptProjectKey = (projectRoot) => hashProjectRoot(projectRoot);
19743
19880
  const hasDisabledSetupPrompt = (projectRoot, storeOptions = {}) => {
19744
19881
  try {
19745
19882
  return getSetupPromptStore(storeOptions).get("projects", {})[getSetupPromptProjectKey(projectRoot)]?.setupPrompt === false;
@@ -21311,4 +21448,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
21311
21448
  export {};
21312
21449
 
21313
21450
  //# sourceMappingURL=cli.js.map
21314
- //# debugId=f6c4adc9-3353-560f-a49f-c50a13c0b8a2
21451
+ //# debugId=301c4437-ca87-5afb-b69d-b7a7c3678175
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-doctor",
3
- "version": "0.4.0-dev.6216430",
3
+ "version": "0.4.0-dev.73dcb20",
4
4
  "description": "Diagnose and fix React codebases for security, performance, correctness, accessibility, bundle-size, and architecture issues",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -66,7 +66,7 @@
66
66
  "vscode-languageserver": "^9.0.1",
67
67
  "vscode-languageserver-textdocument": "^1.0.12",
68
68
  "vscode-uri": "^3.1.0",
69
- "oxlint-plugin-react-doctor": "0.4.0-dev.6216430"
69
+ "oxlint-plugin-react-doctor": "0.4.0-dev.73dcb20"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/babel__code-frame": "^7.27.0",