react-doctor 0.3.0 → 0.4.0-dev.15bd9d8
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/README.md +22 -5
- package/bin/react-doctor.js +9 -1
- package/dist/cli.js +818 -255
- package/dist/index.d.ts +141 -12
- package/dist/index.js +189 -60
- package/dist/lsp.js +10804 -0
- package/package.json +8 -4
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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]="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";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import * as fs$1 from "node:fs";
|
|
8
|
-
import fs from "node:fs";
|
|
8
|
+
import fs, { mkdtempSync, rmSync } from "node:fs";
|
|
9
9
|
import process$1 from "node:process";
|
|
10
10
|
import * as Schema from "effect/Schema";
|
|
11
11
|
import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES, REACT_COMPILER_RULES, REACT_DOCTOR_RULES } from "oxlint-plugin-react-doctor";
|
|
@@ -34,11 +34,11 @@ import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
|
34
34
|
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
35
35
|
import * as ts from "typescript";
|
|
36
36
|
import { gzipSync } from "node:zlib";
|
|
37
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
38
|
+
import * as Exit from "effect/Exit";
|
|
37
39
|
import * as Sentry from "@sentry/node";
|
|
38
40
|
import { performance } from "node:perf_hooks";
|
|
39
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
40
41
|
import * as Tracer from "effect/Tracer";
|
|
41
|
-
import * as Exit from "effect/Exit";
|
|
42
42
|
import { promisify, stripVTControlCharacters } from "node:util";
|
|
43
43
|
import tty from "node:tty";
|
|
44
44
|
import { codeFrameColumns } from "@babel/code-frame";
|
|
@@ -3085,6 +3085,16 @@ const { program: program$1, createCommand, createArgument, createOption, Command
|
|
|
3085
3085
|
//#endregion
|
|
3086
3086
|
//#region ../core/dist/schemas.js
|
|
3087
3087
|
const Severity = Schema.Literals(["error", "warning"]);
|
|
3088
|
+
var DiagnosticRelatedLocation = class extends Schema.Class("DiagnosticRelatedLocation")({
|
|
3089
|
+
filePath: Schema.String,
|
|
3090
|
+
line: Schema.Number,
|
|
3091
|
+
column: Schema.Number,
|
|
3092
|
+
offset: Schema.optional(Schema.Number),
|
|
3093
|
+
length: Schema.optional(Schema.Number),
|
|
3094
|
+
endLine: Schema.optional(Schema.Number),
|
|
3095
|
+
endColumn: Schema.optional(Schema.Number),
|
|
3096
|
+
message: Schema.String
|
|
3097
|
+
}) {};
|
|
3088
3098
|
var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
3089
3099
|
filePath: Schema.String,
|
|
3090
3100
|
plugin: Schema.String,
|
|
@@ -3096,13 +3106,19 @@ var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
|
3096
3106
|
url: Schema.optional(Schema.String),
|
|
3097
3107
|
line: Schema.Number,
|
|
3098
3108
|
column: Schema.Number,
|
|
3109
|
+
offset: Schema.optional(Schema.Number),
|
|
3110
|
+
length: Schema.optional(Schema.Number),
|
|
3111
|
+
endLine: Schema.optional(Schema.Number),
|
|
3112
|
+
endColumn: Schema.optional(Schema.Number),
|
|
3099
3113
|
category: Schema.String,
|
|
3100
|
-
suppressionHint: Schema.optional(Schema.String)
|
|
3114
|
+
suppressionHint: Schema.optional(Schema.String),
|
|
3115
|
+
relatedLocations: Schema.optional(Schema.Array(DiagnosticRelatedLocation))
|
|
3101
3116
|
}) {};
|
|
3102
3117
|
const JsonReportMode = Schema.Literals([
|
|
3103
3118
|
"full",
|
|
3104
3119
|
"diff",
|
|
3105
|
-
"staged"
|
|
3120
|
+
"staged",
|
|
3121
|
+
"baseline"
|
|
3106
3122
|
]);
|
|
3107
3123
|
var JsonReportSummary = class extends Schema.Class("JsonReportSummary")({
|
|
3108
3124
|
errorCount: Schema.Number,
|
|
@@ -3121,7 +3137,9 @@ var JsonReportDiffInfo = class extends Schema.Class("JsonReportDiffInfo")({
|
|
|
3121
3137
|
var JsonReportError = class extends Schema.Class("JsonReportError")({
|
|
3122
3138
|
message: Schema.String,
|
|
3123
3139
|
name: Schema.String,
|
|
3124
|
-
chain: Schema.Array(Schema.String)
|
|
3140
|
+
chain: Schema.Array(Schema.String),
|
|
3141
|
+
/** Sentry event id for the crash, when one was reported. */
|
|
3142
|
+
sentryEventId: Schema.optional(Schema.NullOr(Schema.String))
|
|
3125
3143
|
}) {};
|
|
3126
3144
|
/**
|
|
3127
3145
|
* Schema for a single project entry within a JsonReport. `project` is
|
|
@@ -3158,7 +3176,33 @@ var JsonReportV1 = class extends Schema.Class("JsonReportV1")({
|
|
|
3158
3176
|
elapsedMilliseconds: Schema.Number,
|
|
3159
3177
|
error: Schema.NullOr(JsonReportError)
|
|
3160
3178
|
}) {};
|
|
3161
|
-
Schema.
|
|
3179
|
+
var JsonReportBaseline = class extends Schema.Class("JsonReportBaseline")({
|
|
3180
|
+
baseRef: Schema.String,
|
|
3181
|
+
newCount: Schema.Number,
|
|
3182
|
+
fixedCount: Schema.Number,
|
|
3183
|
+
baseTotalCount: Schema.Number
|
|
3184
|
+
}) {};
|
|
3185
|
+
/**
|
|
3186
|
+
* Baseline (PR-introduced-issues-only) report — `schemaVersion: 2`. A
|
|
3187
|
+
* superset of v1: same fields, plus a `baseline` block. `diagnostics` /
|
|
3188
|
+
* `summary` counts are the introduced findings only; `summary.score` stays
|
|
3189
|
+
* the head project-health score. Consumers branch on `schemaVersion`.
|
|
3190
|
+
*/
|
|
3191
|
+
var JsonReportV2 = class extends Schema.Class("JsonReportV2")({
|
|
3192
|
+
schemaVersion: Schema.Literal(2),
|
|
3193
|
+
version: Schema.String,
|
|
3194
|
+
ok: Schema.Boolean,
|
|
3195
|
+
directory: Schema.String,
|
|
3196
|
+
mode: JsonReportMode,
|
|
3197
|
+
diff: Schema.NullOr(JsonReportDiffInfo),
|
|
3198
|
+
baseline: JsonReportBaseline,
|
|
3199
|
+
projects: Schema.Array(JsonReportProjectEntry),
|
|
3200
|
+
diagnostics: Schema.Array(Diagnostic),
|
|
3201
|
+
summary: JsonReportSummary,
|
|
3202
|
+
elapsedMilliseconds: Schema.Number,
|
|
3203
|
+
error: Schema.NullOr(JsonReportError)
|
|
3204
|
+
}) {};
|
|
3205
|
+
Schema.Union([JsonReportV1, JsonReportV2]);
|
|
3162
3206
|
//#endregion
|
|
3163
3207
|
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/constants.js
|
|
3164
3208
|
var require_constants = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
@@ -9281,6 +9325,11 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9281
9325
|
branch
|
|
9282
9326
|
]).pipe(Effect.map((result) => result.status === 0));
|
|
9283
9327
|
const headSha = (directory) => runGit(directory, ["rev-parse", "HEAD"]).pipe(Effect.map((result) => result.status === 0 ? trimOrNull(result.stdout) : null));
|
|
9328
|
+
const mergeBase = (input) => isSafeGitRevision(input.ref) ? runGit(input.directory, [
|
|
9329
|
+
"merge-base",
|
|
9330
|
+
input.ref,
|
|
9331
|
+
"HEAD"
|
|
9332
|
+
]).pipe(Effect.map((result) => result.status === 0 ? trimOrNull(result.stdout) : null)) : Effect.succeed(null);
|
|
9284
9333
|
const githubRepo = (directory) => runGit(directory, [
|
|
9285
9334
|
"config",
|
|
9286
9335
|
"--get",
|
|
@@ -9356,6 +9405,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9356
9405
|
return {
|
|
9357
9406
|
currentBranch: yield* currentBranch(input.directory),
|
|
9358
9407
|
baseBranch: baseRef,
|
|
9408
|
+
diffBaseRef,
|
|
9359
9409
|
changedFiles: splitNullSeparated(diff.stdout),
|
|
9360
9410
|
isCurrentChanges: false
|
|
9361
9411
|
};
|
|
@@ -9367,6 +9417,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9367
9417
|
githubRepo,
|
|
9368
9418
|
githubViewerPermission,
|
|
9369
9419
|
branchExists,
|
|
9420
|
+
mergeBase,
|
|
9370
9421
|
diffSelection: ({ directory, explicitBaseBranch }) => Effect.gen(function* () {
|
|
9371
9422
|
if (explicitBaseBranch !== void 0 && explicitBaseBranch.trim().length === 0) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchInvalid({ detail: "Diff base branch cannot be empty." }) }));
|
|
9372
9423
|
if (explicitBaseBranch !== void 0) {
|
|
@@ -9424,6 +9475,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9424
9475
|
return {
|
|
9425
9476
|
currentBranch: resolvedCurrentBranch,
|
|
9426
9477
|
baseBranch,
|
|
9478
|
+
diffBaseRef: mergeBaseRef,
|
|
9427
9479
|
changedFiles: splitNullSeparated(diff.stdout),
|
|
9428
9480
|
isCurrentChanges: false
|
|
9429
9481
|
};
|
|
@@ -9445,6 +9497,12 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9445
9497
|
directory,
|
|
9446
9498
|
maxStdoutBytes: options?.maxBufferBytes
|
|
9447
9499
|
}).pipe(Effect.map((result) => result.status === 0 ? result.stdout : null)),
|
|
9500
|
+
showRefContent: ({ directory, ref, relativePath, options }) => isSafeGitRevision(ref) ? runCommand({
|
|
9501
|
+
command: "git",
|
|
9502
|
+
args: ["show", `${ref}:./${relativePath}`],
|
|
9503
|
+
directory,
|
|
9504
|
+
maxStdoutBytes: options?.maxBufferBytes
|
|
9505
|
+
}).pipe(Effect.map((result) => result.status === 0 ? result.stdout : null)) : Effect.succeed(null),
|
|
9448
9506
|
grep: (input) => Effect.gen(function* () {
|
|
9449
9507
|
const args = ["grep"];
|
|
9450
9508
|
if (input.listMatchingFiles ?? true) args.push("-l");
|
|
@@ -9480,9 +9538,11 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9480
9538
|
githubRepo: () => Effect.succeed(snapshot.githubRepo ?? null),
|
|
9481
9539
|
githubViewerPermission: () => Effect.succeed(snapshot.githubViewerPermission ?? null),
|
|
9482
9540
|
branchExists: (_directory, branch) => Effect.succeed(snapshot.branchExists?.get(branch) ?? false),
|
|
9541
|
+
mergeBase: ({ ref }) => Effect.succeed(snapshot.mergeBase?.get(ref) ?? null),
|
|
9483
9542
|
diffSelection: () => Effect.succeed(snapshot.diffSelection ?? null),
|
|
9484
9543
|
stagedFilePaths: () => Effect.succeed(snapshot.stagedFiles ?? []),
|
|
9485
9544
|
showStagedContent: (_directory, relativePath) => Effect.succeed(snapshot.stagedContent?.get(relativePath) ?? null),
|
|
9545
|
+
showRefContent: ({ ref, relativePath }) => Effect.succeed(snapshot.refContent?.get(`${ref}:${relativePath}`) ?? null),
|
|
9486
9546
|
grep: () => Effect.sync(() => {
|
|
9487
9547
|
const matches = snapshot.grepMatches;
|
|
9488
9548
|
if (matches === null || matches === void 0) return null;
|
|
@@ -10537,6 +10597,30 @@ const parseRuleCode = (code) => {
|
|
|
10537
10597
|
};
|
|
10538
10598
|
};
|
|
10539
10599
|
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "Bugs";
|
|
10600
|
+
/**
|
|
10601
|
+
* Maps oxlint's non-primary labels (`labels[1..]`) into related source
|
|
10602
|
+
* locations. Editors surface these as a diagnostic's
|
|
10603
|
+
* `relatedInformation`; non-editor consumers ignore the field. Labels
|
|
10604
|
+
* with empty text still carry a useful jump target, so they're kept
|
|
10605
|
+
* with a neutral message.
|
|
10606
|
+
*/
|
|
10607
|
+
const buildRelatedLocations = (labels, filePath) => {
|
|
10608
|
+
if (labels.length <= 1) return [];
|
|
10609
|
+
const related = [];
|
|
10610
|
+
for (let labelIndex = 1; labelIndex < labels.length; labelIndex++) {
|
|
10611
|
+
const label = labels[labelIndex];
|
|
10612
|
+
if (!label?.span) continue;
|
|
10613
|
+
related.push({
|
|
10614
|
+
filePath,
|
|
10615
|
+
line: label.span.line ?? 0,
|
|
10616
|
+
column: label.span.column ?? 0,
|
|
10617
|
+
offset: label.span.offset,
|
|
10618
|
+
length: label.span.length,
|
|
10619
|
+
message: label.label ?? ""
|
|
10620
|
+
});
|
|
10621
|
+
}
|
|
10622
|
+
return related;
|
|
10623
|
+
};
|
|
10540
10624
|
const isOxlintOutput = (value) => {
|
|
10541
10625
|
if (typeof value !== "object" || value === null) return false;
|
|
10542
10626
|
const candidate = value;
|
|
@@ -10573,8 +10657,11 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10573
10657
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
10574
10658
|
const primaryLabel = diagnostic.labels[0];
|
|
10575
10659
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
10660
|
+
const normalizedFilePath = diagnostic.filename.replaceAll("\\", "/");
|
|
10661
|
+
const primarySpan = primaryLabel?.span;
|
|
10662
|
+
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath);
|
|
10576
10663
|
return {
|
|
10577
|
-
filePath:
|
|
10664
|
+
filePath: normalizedFilePath,
|
|
10578
10665
|
plugin,
|
|
10579
10666
|
rule,
|
|
10580
10667
|
severity: diagnostic.severity,
|
|
@@ -10582,9 +10669,14 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10582
10669
|
message: cleaned.message,
|
|
10583
10670
|
help: cleaned.help,
|
|
10584
10671
|
url: diagnostic.url,
|
|
10585
|
-
line:
|
|
10586
|
-
column:
|
|
10587
|
-
|
|
10672
|
+
line: primarySpan?.line ?? 0,
|
|
10673
|
+
column: primarySpan?.column ?? 0,
|
|
10674
|
+
...primarySpan ? {
|
|
10675
|
+
offset: primarySpan.offset,
|
|
10676
|
+
length: primarySpan.length
|
|
10677
|
+
} : {},
|
|
10678
|
+
category: resolveDiagnosticCategory(plugin, rule),
|
|
10679
|
+
...relatedLocations.length > 0 ? { relatedLocations } : {}
|
|
10588
10680
|
};
|
|
10589
10681
|
});
|
|
10590
10682
|
};
|
|
@@ -11313,7 +11405,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
11313
11405
|
directory: scanDirectory,
|
|
11314
11406
|
repo
|
|
11315
11407
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
11316
|
-
const lintIncludePaths = computeJsxIncludePaths([...input.includePaths]) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
11408
|
+
const lintIncludePaths = (input.skipJsxIncludeFilter ? input.includePaths.length > 0 ? [...input.includePaths] : void 0 : computeJsxIncludePaths([...input.includePaths])) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
11317
11409
|
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path$1.resolve(scanDirectory, relativePath)) : [];
|
|
11318
11410
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
11319
11411
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
@@ -11559,19 +11651,60 @@ var NodeResolver = class NodeResolver extends Context.Service()("react-doctor/No
|
|
|
11559
11651
|
});
|
|
11560
11652
|
};
|
|
11561
11653
|
/**
|
|
11562
|
-
* Zip-Slip defense:
|
|
11563
|
-
*
|
|
11564
|
-
*
|
|
11565
|
-
*
|
|
11566
|
-
* working tree) can include `..` segments that escape the temp
|
|
11567
|
-
* tree. Resolve the candidate against the temp dir and reject any
|
|
11568
|
-
* result that lands outside it before `writeFileSync` runs.
|
|
11654
|
+
* Zip-Slip defense: relative paths come from git (`diff --name-only`), which
|
|
11655
|
+
* normalizes during ordinary adds, but a crafted index/pack/symlinked tree can
|
|
11656
|
+
* smuggle `..` segments that escape the temp root. Resolve against the temp dir
|
|
11657
|
+
* and reject anything that lands outside before writing.
|
|
11569
11658
|
*/
|
|
11570
11659
|
const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
11571
|
-
const relative = path
|
|
11572
|
-
return Boolean(relative) && !relative.startsWith("..") && !path
|
|
11660
|
+
const relative = path.relative(parentAbsolutePath, childAbsolutePath);
|
|
11661
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
11573
11662
|
};
|
|
11574
11663
|
/**
|
|
11664
|
+
* Writes a set of source files (supplied by `readContent` — e.g.
|
|
11665
|
+
* `git show <ref>:<path>` for a baseline tree, or `git show :<path>` for the
|
|
11666
|
+
* index) into a temp tree that mirrors the project layout, copying the
|
|
11667
|
+
* well-known project-config files from `directory` so oxlint resolves
|
|
11668
|
+
* tsconfig / lint config identically to the working tree. Shared by the staged
|
|
11669
|
+
* and baseline scan paths so the zip-slip guard lives in one audited place.
|
|
11670
|
+
* Per-file read failures skip that file (the scan proceeds with whatever read
|
|
11671
|
+
* cleanly) rather than sinking the whole snapshot.
|
|
11672
|
+
*/
|
|
11673
|
+
const materializeSourceTree = (input) => Effect.gen(function* () {
|
|
11674
|
+
const materializedFiles = [];
|
|
11675
|
+
const resolvedTempDirectory = path.resolve(input.tempDirectory);
|
|
11676
|
+
for (const relativePath of input.files) {
|
|
11677
|
+
const content = yield* input.readContent(relativePath).pipe(Effect.orElseSucceed(() => null));
|
|
11678
|
+
if (content === null) continue;
|
|
11679
|
+
const candidateTargetPath = path.resolve(resolvedTempDirectory, relativePath);
|
|
11680
|
+
if (!isPathInsideDirectory(candidateTargetPath, resolvedTempDirectory)) continue;
|
|
11681
|
+
yield* Effect.sync(() => {
|
|
11682
|
+
fs.mkdirSync(path.dirname(candidateTargetPath), { recursive: true });
|
|
11683
|
+
fs.writeFileSync(candidateTargetPath, content);
|
|
11684
|
+
});
|
|
11685
|
+
materializedFiles.push(relativePath);
|
|
11686
|
+
}
|
|
11687
|
+
yield* Effect.sync(() => {
|
|
11688
|
+
for (const configFilename of STAGED_FILES_PROJECT_CONFIG_FILENAMES) {
|
|
11689
|
+
const sourcePath = path.join(input.directory, configFilename);
|
|
11690
|
+
const targetPath = path.join(resolvedTempDirectory, configFilename);
|
|
11691
|
+
if (fs.existsSync(sourcePath) && !fs.existsSync(targetPath)) fs.cpSync(sourcePath, targetPath);
|
|
11692
|
+
}
|
|
11693
|
+
});
|
|
11694
|
+
return {
|
|
11695
|
+
tempDirectory: input.tempDirectory,
|
|
11696
|
+
materializedFiles,
|
|
11697
|
+
cleanup: () => {
|
|
11698
|
+
try {
|
|
11699
|
+
fs.rmSync(input.tempDirectory, {
|
|
11700
|
+
recursive: true,
|
|
11701
|
+
force: true
|
|
11702
|
+
});
|
|
11703
|
+
} catch {}
|
|
11704
|
+
}
|
|
11705
|
+
};
|
|
11706
|
+
});
|
|
11707
|
+
/**
|
|
11575
11708
|
* `StagedFiles` materializes the git-staged source files of a
|
|
11576
11709
|
* directory into a temp tree (mirroring the project layout and
|
|
11577
11710
|
* carrying over a fixed set of project config files) so oxlint can
|
|
@@ -11588,40 +11721,16 @@ var StagedFiles = class StagedFiles extends Context.Service()("react-doctor/Stag
|
|
|
11588
11721
|
const git = yield* Git;
|
|
11589
11722
|
return StagedFiles.of({
|
|
11590
11723
|
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(isLintableSourceFile))),
|
|
11591
|
-
materialize: ({ directory, stagedFiles, tempDirectory }) =>
|
|
11592
|
-
|
|
11593
|
-
|
|
11594
|
-
|
|
11595
|
-
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
fs$1.writeFileSync(candidateTargetPath, content);
|
|
11602
|
-
});
|
|
11603
|
-
materializedFiles.push(relativePath);
|
|
11604
|
-
}
|
|
11605
|
-
yield* Effect.sync(() => {
|
|
11606
|
-
for (const configFilename of STAGED_FILES_PROJECT_CONFIG_FILENAMES) {
|
|
11607
|
-
const sourcePath = path$1.join(directory, configFilename);
|
|
11608
|
-
const targetPath = path$1.join(resolvedTempDirectory, configFilename);
|
|
11609
|
-
if (fs$1.existsSync(sourcePath) && !fs$1.existsSync(targetPath)) fs$1.cpSync(sourcePath, targetPath);
|
|
11610
|
-
}
|
|
11611
|
-
});
|
|
11612
|
-
return {
|
|
11613
|
-
tempDirectory,
|
|
11614
|
-
stagedFiles: materializedFiles,
|
|
11615
|
-
cleanup: () => {
|
|
11616
|
-
try {
|
|
11617
|
-
fs$1.rmSync(tempDirectory, {
|
|
11618
|
-
recursive: true,
|
|
11619
|
-
force: true
|
|
11620
|
-
});
|
|
11621
|
-
} catch {}
|
|
11622
|
-
}
|
|
11623
|
-
};
|
|
11624
|
-
})
|
|
11724
|
+
materialize: ({ directory, stagedFiles, tempDirectory }) => materializeSourceTree({
|
|
11725
|
+
directory,
|
|
11726
|
+
files: stagedFiles,
|
|
11727
|
+
tempDirectory,
|
|
11728
|
+
readContent: (relativePath) => git.showStagedContent(directory, relativePath, { maxBufferBytes: GIT_SHOW_MAX_BUFFER_BYTES })
|
|
11729
|
+
}).pipe(Effect.map((tree) => ({
|
|
11730
|
+
tempDirectory: tree.tempDirectory,
|
|
11731
|
+
stagedFiles: tree.materializedFiles,
|
|
11732
|
+
cleanup: tree.cleanup
|
|
11733
|
+
})))
|
|
11625
11734
|
});
|
|
11626
11735
|
}));
|
|
11627
11736
|
/**
|
|
@@ -11668,18 +11777,22 @@ const safeGetErrorChain = (error) => {
|
|
|
11668
11777
|
};
|
|
11669
11778
|
const buildJsonReportError = (input) => {
|
|
11670
11779
|
const chain = safeGetErrorChain(input.error);
|
|
11780
|
+
const sentryEventId = input.sentryEventId ?? null;
|
|
11671
11781
|
const errorPayload = isReactDoctorError(input.error) ? {
|
|
11672
11782
|
message: formatReactDoctorError(input.error),
|
|
11673
11783
|
name: `ReactDoctorError(${input.error.reason._tag})`,
|
|
11674
|
-
chain
|
|
11784
|
+
chain,
|
|
11785
|
+
sentryEventId
|
|
11675
11786
|
} : input.error instanceof Error ? {
|
|
11676
11787
|
message: input.error.message || input.error.name || "Error",
|
|
11677
11788
|
name: input.error.name || "Error",
|
|
11678
|
-
chain
|
|
11789
|
+
chain,
|
|
11790
|
+
sentryEventId
|
|
11679
11791
|
} : {
|
|
11680
11792
|
message: safeStringify(input.error),
|
|
11681
11793
|
name: "Error",
|
|
11682
|
-
chain
|
|
11794
|
+
chain,
|
|
11795
|
+
sentryEventId
|
|
11683
11796
|
};
|
|
11684
11797
|
return {
|
|
11685
11798
|
schemaVersion: 1,
|
|
@@ -11755,12 +11868,10 @@ const buildJsonReport = (input) => {
|
|
|
11755
11868
|
const flattenedDiagnostics = projects.flatMap((entry) => entry.diagnostics);
|
|
11756
11869
|
const worstScoredProject = findWorstScoredProject(projects);
|
|
11757
11870
|
const summary = summarizeDiagnostics(flattenedDiagnostics, worstScoredProject?.score?.score ?? null, worstScoredProject?.score?.label ?? null);
|
|
11758
|
-
|
|
11759
|
-
schemaVersion: 1,
|
|
11871
|
+
const shared = {
|
|
11760
11872
|
version: input.version,
|
|
11761
11873
|
ok: true,
|
|
11762
11874
|
directory: input.directory,
|
|
11763
|
-
mode: input.mode,
|
|
11764
11875
|
diff: toJsonDiff(input.diff),
|
|
11765
11876
|
projects,
|
|
11766
11877
|
diagnostics: flattenedDiagnostics,
|
|
@@ -11768,6 +11879,22 @@ const buildJsonReport = (input) => {
|
|
|
11768
11879
|
elapsedMilliseconds: input.totalElapsedMilliseconds,
|
|
11769
11880
|
error: null
|
|
11770
11881
|
};
|
|
11882
|
+
if (input.baseline) return {
|
|
11883
|
+
schemaVersion: 2,
|
|
11884
|
+
mode: "baseline",
|
|
11885
|
+
baseline: {
|
|
11886
|
+
baseRef: input.baseline.baseRef,
|
|
11887
|
+
newCount: summary.totalDiagnosticCount,
|
|
11888
|
+
fixedCount: input.baseline.fixedCount,
|
|
11889
|
+
baseTotalCount: input.baseline.baseTotalCount
|
|
11890
|
+
},
|
|
11891
|
+
...shared
|
|
11892
|
+
};
|
|
11893
|
+
return {
|
|
11894
|
+
schemaVersion: 1,
|
|
11895
|
+
mode: input.mode,
|
|
11896
|
+
...shared
|
|
11897
|
+
};
|
|
11771
11898
|
};
|
|
11772
11899
|
/**
|
|
11773
11900
|
* Single source of truth for the skipped-check accounting shared by the
|
|
@@ -11789,6 +11916,45 @@ const buildSkippedChecks = (input) => {
|
|
|
11789
11916
|
skippedCheckReasons
|
|
11790
11917
|
};
|
|
11791
11918
|
};
|
|
11919
|
+
const fingerprintDiagnostic = (diagnostic, lineText) => {
|
|
11920
|
+
const ruleKey = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
11921
|
+
const snippet = lineText === null ? "" : createHash("sha1").update(lineText.trim()).digest("hex");
|
|
11922
|
+
return `${diagnostic.filePath}\u0000${ruleKey}\u0000${snippet}`;
|
|
11923
|
+
};
|
|
11924
|
+
/**
|
|
11925
|
+
* Diffs a head scan against a base scan to isolate the diagnostics a change
|
|
11926
|
+
* introduced (and count the ones it resolved). Matching is a multiset over a
|
|
11927
|
+
* position-independent fingerprint — `(filePath, plugin/rule, hash(flagged
|
|
11928
|
+
* line text))` — so inserting lines above an existing issue doesn't make it
|
|
11929
|
+
* look new, while a genuinely new occurrence (new line text, or one more of
|
|
11930
|
+
* the same) surfaces. Identical repeated findings are matched by count.
|
|
11931
|
+
*
|
|
11932
|
+
* v1 limitation: the fingerprint keys on the head-relative `filePath`, and base
|
|
11933
|
+
* content is read at that same path. A file renamed by the change therefore has
|
|
11934
|
+
* no base match, so its pre-existing findings are reported as new. This
|
|
11935
|
+
* over-reports (never hides a real issue) and is rare; rename-aware base
|
|
11936
|
+
* resolution is a follow-up.
|
|
11937
|
+
*/
|
|
11938
|
+
const computeDiagnosticDelta = (input) => {
|
|
11939
|
+
const unmatchedBaseByFingerprint = /* @__PURE__ */ new Map();
|
|
11940
|
+
for (const diagnostic of input.baseDiagnostics) {
|
|
11941
|
+
const key = fingerprintDiagnostic(diagnostic, input.readBaseLine(diagnostic.filePath, diagnostic.line));
|
|
11942
|
+
unmatchedBaseByFingerprint.set(key, (unmatchedBaseByFingerprint.get(key) ?? 0) + 1);
|
|
11943
|
+
}
|
|
11944
|
+
const newDiagnostics = [];
|
|
11945
|
+
for (const diagnostic of input.headDiagnostics) {
|
|
11946
|
+
const key = fingerprintDiagnostic(diagnostic, input.readHeadLine(diagnostic.filePath, diagnostic.line));
|
|
11947
|
+
const availableMatches = unmatchedBaseByFingerprint.get(key) ?? 0;
|
|
11948
|
+
if (availableMatches > 0) unmatchedBaseByFingerprint.set(key, availableMatches - 1);
|
|
11949
|
+
else newDiagnostics.push(diagnostic);
|
|
11950
|
+
}
|
|
11951
|
+
let fixedCount = 0;
|
|
11952
|
+
for (const remaining of unmatchedBaseByFingerprint.values()) fixedCount += remaining;
|
|
11953
|
+
return {
|
|
11954
|
+
newDiagnostics,
|
|
11955
|
+
fixedCount
|
|
11956
|
+
};
|
|
11957
|
+
};
|
|
11792
11958
|
/**
|
|
11793
11959
|
* Programmatic façade over `Git.diffSelection`. Async because the
|
|
11794
11960
|
* Git service runs through Effect's `ChildProcess` (true subprocess
|
|
@@ -11811,6 +11977,7 @@ const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.
|
|
|
11811
11977
|
return {
|
|
11812
11978
|
currentBranch: selection.currentBranch,
|
|
11813
11979
|
baseBranch: selection.baseBranch,
|
|
11980
|
+
...selection.diffBaseRef !== void 0 ? { diffBaseRef: selection.diffBaseRef } : {},
|
|
11814
11981
|
changedFiles: [...selection.changedFiles],
|
|
11815
11982
|
...selection.isCurrentChanges ? { isCurrentChanges: true } : {}
|
|
11816
11983
|
};
|
|
@@ -11870,10 +12037,9 @@ const CI_PROVIDER_BY_ENVIRONMENT_VARIABLE = [
|
|
|
11870
12037
|
];
|
|
11871
12038
|
const GITHUB_ACTION_MARKER_ENVIRONMENT_VARIABLE = "REACT_DOCTOR_GITHUB_ACTION";
|
|
11872
12039
|
const ACTION_INPUT_ENVIRONMENT_VARIABLES = {
|
|
11873
|
-
|
|
11874
|
-
nonBlocking: "REACT_DOCTOR_ACTION_NON_BLOCKING",
|
|
12040
|
+
blocking: "REACT_DOCTOR_ACTION_BLOCKING",
|
|
11875
12041
|
comment: "REACT_DOCTOR_ACTION_COMMENT",
|
|
11876
|
-
|
|
12042
|
+
reviewComments: "REACT_DOCTOR_ACTION_REVIEW_COMMENTS",
|
|
11877
12043
|
version: "REACT_DOCTOR_ACTION_VERSION"
|
|
11878
12044
|
};
|
|
11879
12045
|
const CODING_AGENT_BY_ENVIRONMENT_VARIABLE = [
|
|
@@ -11945,6 +12111,7 @@ const isNonInteractiveEnvironment = () => NON_INTERACTIVE_ENVIRONMENT_VARIABLES.
|
|
|
11945
12111
|
//#endregion
|
|
11946
12112
|
//#region src/cli/utils/constants.ts
|
|
11947
12113
|
const STAGED_FILES_TEMP_DIR_PREFIX = "react-doctor-staged-";
|
|
12114
|
+
const BASELINE_FILES_TEMP_DIR_PREFIX = "react-doctor-baseline-";
|
|
11948
12115
|
const CI_TRUST_COMPANIES = "PayPal, Rippling, and Alibaba";
|
|
11949
12116
|
const WELCOME_EXPLANATION_HOLD_MS = 1e3;
|
|
11950
12117
|
const CATEGORY_COUNTUP_SETTLE_HOLD_MS = 1e3;
|
|
@@ -11962,6 +12129,7 @@ const METRIC = {
|
|
|
11962
12129
|
scanScore: "scan.score",
|
|
11963
12130
|
scanClean: "scan.clean",
|
|
11964
12131
|
scanCheckSkipped: "scan.check_skipped",
|
|
12132
|
+
baselineDegraded: "baseline.degraded",
|
|
11965
12133
|
ruleFired: "rule.fired",
|
|
11966
12134
|
lintFailed: "lint.failed",
|
|
11967
12135
|
deadCodeFailed: "deadcode.failed",
|
|
@@ -11976,7 +12144,11 @@ const METRIC = {
|
|
|
11976
12144
|
installAgentHooks: "install.agent_hooks",
|
|
11977
12145
|
installDependency: "install.dependency",
|
|
11978
12146
|
rulesChanged: "rules.changed",
|
|
11979
|
-
rulesQueried: "rules.queried"
|
|
12147
|
+
rulesQueried: "rules.queried",
|
|
12148
|
+
lspSessionStarted: "lsp.session.started",
|
|
12149
|
+
lspScanCompleted: "lsp.scan.completed",
|
|
12150
|
+
lspScanDuration: "lsp.scan.duration",
|
|
12151
|
+
lspScanDiagnostics: "lsp.scan.diagnostics"
|
|
11980
12152
|
};
|
|
11981
12153
|
//#endregion
|
|
11982
12154
|
//#region src/cli/utils/noop-console.ts
|
|
@@ -12019,7 +12191,7 @@ const makeNoopConsole = () => ({
|
|
|
12019
12191
|
});
|
|
12020
12192
|
//#endregion
|
|
12021
12193
|
//#region src/cli/utils/version.ts
|
|
12022
|
-
const VERSION = "0.
|
|
12194
|
+
const VERSION = "0.4.0-dev.15bd9d8";
|
|
12023
12195
|
//#endregion
|
|
12024
12196
|
//#region src/cli/utils/json-mode.ts
|
|
12025
12197
|
let context = null;
|
|
@@ -12077,7 +12249,7 @@ const writeJsonReport = (report) => {
|
|
|
12077
12249
|
const serialized = context?.compact ? JSON.stringify(report) : JSON.stringify(report, null, 2);
|
|
12078
12250
|
process.stdout.write(`${serialized}\n`);
|
|
12079
12251
|
};
|
|
12080
|
-
const writeJsonErrorReport = (error) => {
|
|
12252
|
+
const writeJsonErrorReport = (error, sentryEventId) => {
|
|
12081
12253
|
if (!context) return;
|
|
12082
12254
|
try {
|
|
12083
12255
|
writeJsonReport(buildJsonReportError({
|
|
@@ -12085,7 +12257,8 @@ const writeJsonErrorReport = (error) => {
|
|
|
12085
12257
|
directory: context.directory,
|
|
12086
12258
|
error,
|
|
12087
12259
|
elapsedMilliseconds: performance.now() - context.startTime,
|
|
12088
|
-
mode: context.mode
|
|
12260
|
+
mode: context.mode,
|
|
12261
|
+
sentryEventId
|
|
12089
12262
|
}));
|
|
12090
12263
|
} catch {
|
|
12091
12264
|
process.stdout.write(INTERNAL_ERROR_JSON_FALLBACK);
|
|
@@ -12356,15 +12529,14 @@ const scrubSentryMetric = (metric) => {
|
|
|
12356
12529
|
}
|
|
12357
12530
|
};
|
|
12358
12531
|
//#endregion
|
|
12359
|
-
//#region src/
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
|
|
12365
|
-
|
|
12366
|
-
|
|
12367
|
-
const isEnvFlagEnabled = (value) => value === "1" || value?.toLowerCase() === "true";
|
|
12532
|
+
//#region src/cli/utils/sentry-config.ts
|
|
12533
|
+
/**
|
|
12534
|
+
* Shared Sentry configuration resolution — release, environment, and tracing
|
|
12535
|
+
* sample rate — derived from `VERSION` and the standard `SENTRY_*` env
|
|
12536
|
+
* overrides. Lives apart from `instrument.ts` (the CLI's run-context-aware
|
|
12537
|
+
* init) so both the CLI and the editor language server can resolve identical
|
|
12538
|
+
* release/environment values without the LSP pulling in CLI run-context code.
|
|
12539
|
+
*/
|
|
12368
12540
|
/**
|
|
12369
12541
|
* A version is a "dev" build when it's the unbuilt placeholder (`0.0.0`) or
|
|
12370
12542
|
* carries a prerelease suffix (e.g. the `-dev.<sha>` snapshots published from
|
|
@@ -12377,13 +12549,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12377
12549
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12378
12550
|
* standard `SENTRY_RELEASE` override.
|
|
12379
12551
|
*/
|
|
12380
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.
|
|
12552
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.0-dev.15bd9d8`;
|
|
12381
12553
|
/**
|
|
12382
12554
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12383
12555
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12384
12556
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12385
12557
|
*/
|
|
12386
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.
|
|
12558
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.0-dev.15bd9d8") ? "development" : "production");
|
|
12387
12559
|
/**
|
|
12388
12560
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12389
12561
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -12397,6 +12569,16 @@ const resolveTracesSampleRate = () => {
|
|
|
12397
12569
|
if (Number.isNaN(parsed) || parsed < 0 || parsed > 1) return 1;
|
|
12398
12570
|
return parsed;
|
|
12399
12571
|
};
|
|
12572
|
+
//#endregion
|
|
12573
|
+
//#region src/instrument.ts
|
|
12574
|
+
let isInitialized = false;
|
|
12575
|
+
let resolvedTracesSampleRate = 0;
|
|
12576
|
+
const shouldEnableSentry = () => {
|
|
12577
|
+
if (process.argv.includes("--no-score") || process.argv.includes("--no-telemetry")) return false;
|
|
12578
|
+
if (process.env.VITEST || process.env.NODE_ENV === "test") return false;
|
|
12579
|
+
return true;
|
|
12580
|
+
};
|
|
12581
|
+
const isEnvFlagEnabled = (value) => value === "1" || value?.toLowerCase() === "true";
|
|
12400
12582
|
/**
|
|
12401
12583
|
* Whether performance traces will actually be recorded — Sentry is live and the
|
|
12402
12584
|
* resolved sample rate is above zero. Used to gate the per-run root span and
|
|
@@ -15838,6 +16020,7 @@ const recordScanMetrics = (input) => {
|
|
|
15838
16020
|
if (result.diagnostics.length === 0 && !hasSkippedChecks) recordCount(METRIC.scanClean, 1, { mode: input.mode });
|
|
15839
16021
|
if (result.score) recordDistribution(METRIC.scanScore, result.score.score, { attributes: { mode: input.mode } });
|
|
15840
16022
|
else if (!input.noScore && !input.didLintFail) recordCount(METRIC.scoreUnavailable, 1, { mode: input.mode });
|
|
16023
|
+
if (input.baselineDegraded) recordCount(METRIC.baselineDegraded, 1);
|
|
15841
16024
|
if (input.didLintFail) recordCount(METRIC.lintFailed, 1, { reasonKind: input.lintFailureReasonKind });
|
|
15842
16025
|
if (input.didDeadCodeFail) recordCount(METRIC.deadCodeFailed, 1);
|
|
15843
16026
|
for (const check of result.skippedChecks) recordCount(METRIC.scanCheckSkipped, 1, {
|
|
@@ -15846,19 +16029,74 @@ const recordScanMetrics = (input) => {
|
|
|
15846
16029
|
});
|
|
15847
16030
|
};
|
|
15848
16031
|
//#endregion
|
|
15849
|
-
//#region src/cli/utils/
|
|
15850
|
-
|
|
15851
|
-
|
|
15852
|
-
|
|
15853
|
-
|
|
16032
|
+
//#region src/cli/utils/cli-logger.ts
|
|
16033
|
+
/**
|
|
16034
|
+
* Thin synchronous façade over Effect's `Console` module. Used by
|
|
16035
|
+
* the imperative CLI helper files (`select-projects`, `run-explain`,
|
|
16036
|
+
* `install-react-doctor`, the legacy paths in `cli/commands/inspect.ts`)
|
|
16037
|
+
* that aren't yet Effect-typed. Every call drains into a single
|
|
16038
|
+
* `Console.*` Effect via `Effect.runSync`, so the underlying logging
|
|
16039
|
+
* pipeline is identical to the canonical `yield* Console.log(...)`
|
|
16040
|
+
* call sites in the renderers. Convert callers to `Effect.gen` to
|
|
16041
|
+
* drop the bridge.
|
|
16042
|
+
*/
|
|
16043
|
+
const cliLogger = {
|
|
16044
|
+
log: (message) => {
|
|
16045
|
+
Effect.runSync(Console.log(message));
|
|
16046
|
+
},
|
|
16047
|
+
warn: (message) => {
|
|
16048
|
+
Effect.runSync(Console.warn(highlighter.warn(message)));
|
|
16049
|
+
},
|
|
16050
|
+
error: (message) => {
|
|
16051
|
+
Effect.runSync(Console.error(highlighter.error(message)));
|
|
16052
|
+
},
|
|
16053
|
+
info: (message) => {
|
|
16054
|
+
Effect.runSync(Console.info(highlighter.info(message)));
|
|
16055
|
+
},
|
|
16056
|
+
dim: (message) => {
|
|
16057
|
+
Effect.runSync(Console.log(highlighter.gray(message)));
|
|
16058
|
+
},
|
|
16059
|
+
success: (message) => {
|
|
16060
|
+
Effect.runSync(Console.log(highlighter.success(message)));
|
|
16061
|
+
},
|
|
16062
|
+
break: () => {
|
|
16063
|
+
Effect.runSync(Console.log(""));
|
|
16064
|
+
}
|
|
15854
16065
|
};
|
|
15855
16066
|
//#endregion
|
|
15856
|
-
//#region src/cli/utils/
|
|
15857
|
-
const
|
|
16067
|
+
//#region src/cli/utils/resolve-blocking-level.ts
|
|
16068
|
+
const VALID_BLOCKING_LEVELS = new Set([
|
|
15858
16069
|
"error",
|
|
15859
16070
|
"warning",
|
|
15860
16071
|
"none"
|
|
15861
16072
|
]);
|
|
16073
|
+
const DEFAULT_BLOCKING_LEVEL = "error";
|
|
16074
|
+
const isValidBlockingLevel = (level) => VALID_BLOCKING_LEVELS.has(level);
|
|
16075
|
+
const pickBlockingLevel = (flags, userConfig) => flags.blocking ?? flags.failOn ?? userConfig?.blocking ?? userConfig?.failOn;
|
|
16076
|
+
const resolveBlockingLevel = (flags, userConfig) => {
|
|
16077
|
+
const sourceValue = pickBlockingLevel(flags, userConfig) ?? DEFAULT_BLOCKING_LEVEL;
|
|
16078
|
+
if (isValidBlockingLevel(sourceValue)) return sourceValue;
|
|
16079
|
+
cliLogger.warn(`Invalid blocking level "${sourceValue}". Expected one of: error, warning, none. Falling back to "${DEFAULT_BLOCKING_LEVEL}".`);
|
|
16080
|
+
return DEFAULT_BLOCKING_LEVEL;
|
|
16081
|
+
};
|
|
16082
|
+
//#endregion
|
|
16083
|
+
//#region src/cli/utils/should-block-ci.ts
|
|
16084
|
+
const shouldBlockCi = (diagnostics, blockingLevel) => {
|
|
16085
|
+
if (blockingLevel === "none") return false;
|
|
16086
|
+
if (blockingLevel === "warning") return diagnostics.length > 0;
|
|
16087
|
+
return diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
16088
|
+
};
|
|
16089
|
+
//#endregion
|
|
16090
|
+
//#region src/cli/utils/to-category-key.ts
|
|
16091
|
+
/**
|
|
16092
|
+
* Lowercase, key-safe form of a rule category for the `diag.category.*`
|
|
16093
|
+
* telemetry attribute namespace (categories carry spaces / capitals, e.g.
|
|
16094
|
+
* "Performance" → `performance`, "Dead Code" → `dead_code`). Shared by the
|
|
16095
|
+
* CLI run event and the editor LSP wide event so both namespace identically.
|
|
16096
|
+
*/
|
|
16097
|
+
const toCategoryKey = (category) => category.toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
16098
|
+
//#endregion
|
|
16099
|
+
//#region src/cli/utils/build-run-event.ts
|
|
15862
16100
|
const readEnvBoolean = (name) => {
|
|
15863
16101
|
const value = process.env[name];
|
|
15864
16102
|
if (value === void 0) return null;
|
|
@@ -15870,12 +16108,11 @@ const resolveVersionPin = (versionInput) => {
|
|
|
15870
16108
|
if (/^(\.\.?\/|\/)/.test(versionInput)) return "local";
|
|
15871
16109
|
return "pinned";
|
|
15872
16110
|
};
|
|
15873
|
-
const
|
|
15874
|
-
const fromAction = process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.
|
|
15875
|
-
if (fromAction !== void 0 &&
|
|
15876
|
-
return userConfig?.failOn ?? "
|
|
16111
|
+
const resolveTelemetryBlocking = (userConfig) => {
|
|
16112
|
+
const fromAction = process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.blocking];
|
|
16113
|
+
if (fromAction !== void 0 && isValidBlockingLevel(fromAction)) return fromAction;
|
|
16114
|
+
return userConfig?.blocking ?? userConfig?.failOn ?? "error";
|
|
15877
16115
|
};
|
|
15878
|
-
const toCategoryKey = (category) => category.toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
15879
16116
|
const buildOutcomeAttributes = (input) => {
|
|
15880
16117
|
if (input.result === void 0) {
|
|
15881
16118
|
const error = input.error;
|
|
@@ -15889,9 +16126,9 @@ const buildOutcomeAttributes = (input) => {
|
|
|
15889
16126
|
}
|
|
15890
16127
|
const result = input.result;
|
|
15891
16128
|
const summary = summarizeDiagnostics(result.diagnostics);
|
|
15892
|
-
const
|
|
16129
|
+
const blockingLevel = resolveTelemetryBlocking(input.userConfig);
|
|
15893
16130
|
const gateDiagnostics = filterDiagnosticsForSurface(result.diagnostics, "ciFailure", input.userConfig);
|
|
15894
|
-
const wouldBlock = !input.scoreOnly &&
|
|
16131
|
+
const wouldBlock = !input.scoreOnly && !input.gateExempt && shouldBlockCi(gateDiagnostics, blockingLevel);
|
|
15895
16132
|
const hasSkippedChecks = result.skippedChecks.length > 0;
|
|
15896
16133
|
const isClean = result.diagnostics.length === 0 && !hasSkippedChecks;
|
|
15897
16134
|
const outcome = wouldBlock ? "blocked" : isClean ? "clean" : "ok";
|
|
@@ -15912,7 +16149,7 @@ const buildOutcomeAttributes = (input) => {
|
|
|
15912
16149
|
outcome,
|
|
15913
16150
|
exitCode: wouldBlock ? 1 : 0,
|
|
15914
16151
|
wouldBlock,
|
|
15915
|
-
|
|
16152
|
+
blocking: blockingLevel,
|
|
15916
16153
|
scanClean: isClean,
|
|
15917
16154
|
totalDiagnostics: summary.totalDiagnosticCount,
|
|
15918
16155
|
errorCount: summary.errorCount,
|
|
@@ -15933,6 +16170,12 @@ const buildOutcomeAttributes = (input) => {
|
|
|
15933
16170
|
didDeadCodeFail: input.didDeadCodeFail ?? null
|
|
15934
16171
|
};
|
|
15935
16172
|
for (const [category, count] of countByCategory) attributes[`diag.category.${toCategoryKey(category)}`] = count;
|
|
16173
|
+
if (result.baselineDelta) {
|
|
16174
|
+
attributes["baseline.new"] = summary.totalDiagnosticCount;
|
|
16175
|
+
attributes["baseline.fixed"] = result.baselineDelta.fixedCount;
|
|
16176
|
+
attributes["baseline.baseTotal"] = result.baselineDelta.baseTotalCount;
|
|
16177
|
+
attributes["baseline.degraded"] = false;
|
|
16178
|
+
} else if (input.gateExempt) attributes["baseline.degraded"] = true;
|
|
15936
16179
|
return attributes;
|
|
15937
16180
|
};
|
|
15938
16181
|
const buildCiAttributes = () => {
|
|
@@ -15940,9 +16183,8 @@ const buildCiAttributes = () => {
|
|
|
15940
16183
|
return {
|
|
15941
16184
|
actorAssociation: githubActorAssociation ?? null,
|
|
15942
16185
|
runnerOs: detectRunnerOs(),
|
|
15943
|
-
nonBlocking: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.nonBlocking),
|
|
15944
16186
|
comment: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.comment),
|
|
15945
|
-
|
|
16187
|
+
reviewComments: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.reviewComments),
|
|
15946
16188
|
versionPin: resolveVersionPin(process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.version])
|
|
15947
16189
|
};
|
|
15948
16190
|
};
|
|
@@ -15992,6 +16234,66 @@ const recordRunEvent = (rootSpan, input) => {
|
|
|
15992
16234
|
} catch {}
|
|
15993
16235
|
};
|
|
15994
16236
|
//#endregion
|
|
16237
|
+
//#region src/cli/utils/materialize-baseline-files.ts
|
|
16238
|
+
/**
|
|
16239
|
+
* Materializes the `ref` version of `files` into `tempDirectory` (via
|
|
16240
|
+
* `git show <ref>:<path>`), mirroring the project layout + head's config files
|
|
16241
|
+
* so the base lints under the same rules as head. Reuses the shared,
|
|
16242
|
+
* zip-slip-guarded `materializeSourceTree`. Per-file read misses (e.g. a file
|
|
16243
|
+
* the PR added, absent at base) are skipped, which is exactly what we want:
|
|
16244
|
+
* a brand-new file has no base counterpart, so all its findings are "new".
|
|
16245
|
+
*/
|
|
16246
|
+
const materializeBaselineFiles = (input) => Effect.runPromise(Effect.gen(function* () {
|
|
16247
|
+
const git = yield* Git;
|
|
16248
|
+
return yield* materializeSourceTree({
|
|
16249
|
+
directory: input.directory,
|
|
16250
|
+
files: input.files,
|
|
16251
|
+
tempDirectory: input.tempDirectory,
|
|
16252
|
+
readContent: (relativePath) => git.showRefContent({
|
|
16253
|
+
directory: input.directory,
|
|
16254
|
+
ref: input.ref,
|
|
16255
|
+
relativePath,
|
|
16256
|
+
options: { maxBufferBytes: GIT_SHOW_MAX_BUFFER_BYTES }
|
|
16257
|
+
})
|
|
16258
|
+
});
|
|
16259
|
+
}).pipe(Effect.provide(Git.layerNode)));
|
|
16260
|
+
/**
|
|
16261
|
+
* Resolves the commit a baseline scan should read base content from — the
|
|
16262
|
+
* merge-base of `ref` and HEAD, so "introduced" is measured against the branch
|
|
16263
|
+
* point. `null` when unresolvable (ref missing/unsafe, no merge-base).
|
|
16264
|
+
*/
|
|
16265
|
+
const resolveMergeBaseRef = async (directory, ref) => {
|
|
16266
|
+
try {
|
|
16267
|
+
return await Effect.runPromise(Effect.gen(function* () {
|
|
16268
|
+
return yield* (yield* Git).mergeBase({
|
|
16269
|
+
directory,
|
|
16270
|
+
ref
|
|
16271
|
+
});
|
|
16272
|
+
}).pipe(Effect.provide(Git.layerNode)));
|
|
16273
|
+
} catch {
|
|
16274
|
+
return null;
|
|
16275
|
+
}
|
|
16276
|
+
};
|
|
16277
|
+
//#endregion
|
|
16278
|
+
//#region src/cli/utils/read-source-line.ts
|
|
16279
|
+
/**
|
|
16280
|
+
* Builds a cached `(filePath, line) -> source text` reader rooted at
|
|
16281
|
+
* `rootDirectory`, used to fingerprint a diagnostic by the content of its
|
|
16282
|
+
* flagged line (see `computeDiagnosticDelta`). Wraps core's
|
|
16283
|
+
* `createNodeReadFileLinesSync` with per-file memoization + 1-indexed line
|
|
16284
|
+
* lookup; unreadable files / out-of-range lines return `null`.
|
|
16285
|
+
*/
|
|
16286
|
+
const createSourceLineReader = (rootDirectory) => {
|
|
16287
|
+
const readFileLines = createNodeReadFileLinesSync(rootDirectory);
|
|
16288
|
+
const fileLinesCache = /* @__PURE__ */ new Map();
|
|
16289
|
+
return (filePath, line) => {
|
|
16290
|
+
if (!fileLinesCache.has(filePath)) fileLinesCache.set(filePath, readFileLines(filePath));
|
|
16291
|
+
const lines = fileLinesCache.get(filePath) ?? null;
|
|
16292
|
+
if (lines === null || line < 1 || line > lines.length) return null;
|
|
16293
|
+
return lines[line - 1] ?? null;
|
|
16294
|
+
};
|
|
16295
|
+
};
|
|
16296
|
+
//#endregion
|
|
15995
16297
|
//#region src/cli/utils/build-no-score-message.ts
|
|
15996
16298
|
const ENTERPRISE_CONTACT_HINT = `Want something custom to your company? Contact us at ${ENTERPRISE_CONTACT_URL}.`;
|
|
15997
16299
|
const buildNoScoreMessage = (isScoreDisabled) => {
|
|
@@ -16450,10 +16752,10 @@ const canAnimateOnboarding = (stream = process.stdout) => {
|
|
|
16450
16752
|
};
|
|
16451
16753
|
//#endregion
|
|
16452
16754
|
//#region src/cli/utils/onboarding-state.ts
|
|
16453
|
-
const GLOBAL_CONFIG_PROJECT_NAME$
|
|
16755
|
+
const GLOBAL_CONFIG_PROJECT_NAME$2 = "react-doctor";
|
|
16454
16756
|
const ONBOARDED_AT_KEY = "onboardedAt";
|
|
16455
16757
|
const getOnboardingStore = (options = {}) => new Conf({
|
|
16456
|
-
projectName: GLOBAL_CONFIG_PROJECT_NAME$
|
|
16758
|
+
projectName: GLOBAL_CONFIG_PROJECT_NAME$2,
|
|
16457
16759
|
cwd: options.cwd
|
|
16458
16760
|
});
|
|
16459
16761
|
const hasCompletedOnboarding = (options = {}) => {
|
|
@@ -16735,41 +17037,6 @@ const printSummary = (input) => Effect.gen(function* () {
|
|
|
16735
17037
|
if (diagnosticsDirectory !== null && input.verbose) yield* Console.log(highlighter.gray(` Full diagnostics written to ${diagnosticsDirectory}`));
|
|
16736
17038
|
});
|
|
16737
17039
|
//#endregion
|
|
16738
|
-
//#region src/cli/utils/cli-logger.ts
|
|
16739
|
-
/**
|
|
16740
|
-
* Thin synchronous façade over Effect's `Console` module. Used by
|
|
16741
|
-
* the imperative CLI helper files (`select-projects`, `run-explain`,
|
|
16742
|
-
* `install-react-doctor`, the legacy paths in `cli/commands/inspect.ts`)
|
|
16743
|
-
* that aren't yet Effect-typed. Every call drains into a single
|
|
16744
|
-
* `Console.*` Effect via `Effect.runSync`, so the underlying logging
|
|
16745
|
-
* pipeline is identical to the canonical `yield* Console.log(...)`
|
|
16746
|
-
* call sites in the renderers. Convert callers to `Effect.gen` to
|
|
16747
|
-
* drop the bridge.
|
|
16748
|
-
*/
|
|
16749
|
-
const cliLogger = {
|
|
16750
|
-
log: (message) => {
|
|
16751
|
-
Effect.runSync(Console.log(message));
|
|
16752
|
-
},
|
|
16753
|
-
warn: (message) => {
|
|
16754
|
-
Effect.runSync(Console.warn(highlighter.warn(message)));
|
|
16755
|
-
},
|
|
16756
|
-
error: (message) => {
|
|
16757
|
-
Effect.runSync(Console.error(highlighter.error(message)));
|
|
16758
|
-
},
|
|
16759
|
-
info: (message) => {
|
|
16760
|
-
Effect.runSync(Console.info(highlighter.info(message)));
|
|
16761
|
-
},
|
|
16762
|
-
dim: (message) => {
|
|
16763
|
-
Effect.runSync(Console.log(highlighter.gray(message)));
|
|
16764
|
-
},
|
|
16765
|
-
success: (message) => {
|
|
16766
|
-
Effect.runSync(Console.log(highlighter.success(message)));
|
|
16767
|
-
},
|
|
16768
|
-
break: () => {
|
|
16769
|
-
Effect.runSync(Console.log(""));
|
|
16770
|
-
}
|
|
16771
|
-
};
|
|
16772
|
-
//#endregion
|
|
16773
17040
|
//#region src/cli/utils/should-auto-select-current-choice.ts
|
|
16774
17041
|
const shouldAutoSelectCurrentChoice = (choiceStates, cursor) => {
|
|
16775
17042
|
if (choiceStates.some((choiceState) => choiceState.selected)) return false;
|
|
@@ -16912,7 +17179,8 @@ const mergeInspectOptions = (inputOptions, userConfig) => ({
|
|
|
16912
17179
|
ignoredTags: buildIgnoredTags(userConfig),
|
|
16913
17180
|
outputSurface: inputOptions.outputSurface ?? "cli",
|
|
16914
17181
|
suppressRendering: inputOptions.suppressRendering ?? false,
|
|
16915
|
-
concurrency: inputOptions.concurrency
|
|
17182
|
+
concurrency: inputOptions.concurrency,
|
|
17183
|
+
baseline: inputOptions.baseline ?? null
|
|
16916
17184
|
});
|
|
16917
17185
|
const buildRunEventConfig = (options, userConfig, hasCustomConfig) => ({
|
|
16918
17186
|
parallel: options.concurrency !== void 0,
|
|
@@ -16966,6 +17234,75 @@ const inspect = async (directory, inputOptions = {}) => {
|
|
|
16966
17234
|
if (options.silent) setSpinnerSilent(wasSpinnerSilent);
|
|
16967
17235
|
}
|
|
16968
17236
|
};
|
|
17237
|
+
/**
|
|
17238
|
+
* Runs a second, lint-only scan over the changed files as they existed at the
|
|
17239
|
+
* baseline ref (materialized into a temp tree with head's config) and diffs it
|
|
17240
|
+
* against the head diagnostics, returning only the findings the change
|
|
17241
|
+
* introduced plus the fixed / base counts. No score, dead-code, progress, or
|
|
17242
|
+
* telemetry — it's a pure comparison pass. The temp tree is always cleaned up.
|
|
17243
|
+
*/
|
|
17244
|
+
const runBaselineComparison = async (params) => {
|
|
17245
|
+
const tempDirectory = mkdtempSync(path.join(tmpdir(), BASELINE_FILES_TEMP_DIR_PREFIX));
|
|
17246
|
+
const snapshot = await materializeBaselineFiles({
|
|
17247
|
+
directory: params.directory,
|
|
17248
|
+
ref: params.baselineRef,
|
|
17249
|
+
files: params.options.includePaths,
|
|
17250
|
+
tempDirectory
|
|
17251
|
+
}).catch((error) => {
|
|
17252
|
+
rmSync(tempDirectory, {
|
|
17253
|
+
recursive: true,
|
|
17254
|
+
force: true
|
|
17255
|
+
});
|
|
17256
|
+
throw error;
|
|
17257
|
+
});
|
|
17258
|
+
try {
|
|
17259
|
+
const baseLayers = buildRuntimeLayers({
|
|
17260
|
+
directory: snapshot.tempDirectory,
|
|
17261
|
+
hasConfigOverride: true,
|
|
17262
|
+
userConfig: params.userConfig,
|
|
17263
|
+
configSourceDirectory: null,
|
|
17264
|
+
shouldSkipLint: !params.options.lint || !params.resolvedNodeBinaryPath,
|
|
17265
|
+
shouldRunDeadCode: false,
|
|
17266
|
+
shouldComputeScore: false,
|
|
17267
|
+
shouldShowProgressSpinners: false,
|
|
17268
|
+
oxlintConcurrency: params.options.concurrency
|
|
17269
|
+
});
|
|
17270
|
+
const baseProgram = runInspect({
|
|
17271
|
+
directory: snapshot.tempDirectory,
|
|
17272
|
+
includePaths: params.options.includePaths,
|
|
17273
|
+
customRulesOnly: params.options.customRulesOnly,
|
|
17274
|
+
respectInlineDisables: params.options.respectInlineDisables,
|
|
17275
|
+
warnings: params.options.warnings,
|
|
17276
|
+
adoptExistingLintConfig: params.options.adoptExistingLintConfig,
|
|
17277
|
+
ignoredTags: params.options.ignoredTags,
|
|
17278
|
+
nodeBinaryPath: params.resolvedNodeBinaryPath ?? void 0,
|
|
17279
|
+
runDeadCode: false,
|
|
17280
|
+
isCi: params.options.isCi,
|
|
17281
|
+
doctorVersion: VERSION,
|
|
17282
|
+
runId: getRunId(),
|
|
17283
|
+
resolveLocalGithubViewerPermission: false,
|
|
17284
|
+
suppressScanSummary: true
|
|
17285
|
+
}, {});
|
|
17286
|
+
const baseOutput = await Effect.runPromise(restoreLegacyThrow(baseProgram.pipe(Effect.provide(baseLayers), Effect.provideService(Console.Console, silentConsole))));
|
|
17287
|
+
if (baseOutput.didLintFail) return null;
|
|
17288
|
+
const delta = computeDiagnosticDelta({
|
|
17289
|
+
headDiagnostics: params.headDiagnostics,
|
|
17290
|
+
baseDiagnostics: baseOutput.diagnostics,
|
|
17291
|
+
readHeadLine: createSourceLineReader(params.directory),
|
|
17292
|
+
readBaseLine: createSourceLineReader(snapshot.tempDirectory)
|
|
17293
|
+
});
|
|
17294
|
+
return {
|
|
17295
|
+
displayDiagnostics: delta.newDiagnostics,
|
|
17296
|
+
baselineDelta: {
|
|
17297
|
+
baseRef: params.baselineRef,
|
|
17298
|
+
fixedCount: delta.fixedCount,
|
|
17299
|
+
baseTotalCount: baseOutput.diagnostics.length
|
|
17300
|
+
}
|
|
17301
|
+
};
|
|
17302
|
+
} finally {
|
|
17303
|
+
snapshot.cleanup();
|
|
17304
|
+
}
|
|
17305
|
+
};
|
|
16969
17306
|
const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOverride, configSourceDirectory, startTime, rootSentrySpan) => {
|
|
16970
17307
|
const isDiffMode = options.includePaths.length > 0;
|
|
16971
17308
|
const resolvedNodeBinaryPath = await resolveOxlintNode(options.lint, options.scoreOnly || options.silent);
|
|
@@ -17016,7 +17353,23 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17016
17353
|
const lintFailureReason = lintBindingMissing ? `oxlint native binding not found for Node ${process.version}; expected one matching ${OXLINT_NODE_REQUIREMENT}` : output.lintFailureReason;
|
|
17017
17354
|
if (!options.scoreOnly && !lintBindingMissing && output.didLintFail && lintFailureReason !== null) if (output.lintFailureReasonKind === "native-binding-missing") runConsole(Console.log(highlighter.gray(` Upgrade to Node ${OXLINT_NODE_REQUIREMENT} or run: npx -p oxlint@latest react-doctor@latest`)));
|
|
17018
17355
|
else runConsole(Console.error(highlighter.error(lintFailureReason)));
|
|
17019
|
-
|
|
17356
|
+
let inspectDiagnostics = output.diagnostics;
|
|
17357
|
+
let baselineDelta;
|
|
17358
|
+
if (options.baseline && isDiffMode && !didLintFail) {
|
|
17359
|
+
const comparison = await runBaselineComparison({
|
|
17360
|
+
directory,
|
|
17361
|
+
options,
|
|
17362
|
+
userConfig,
|
|
17363
|
+
headDiagnostics: output.diagnostics,
|
|
17364
|
+
resolvedNodeBinaryPath,
|
|
17365
|
+
baselineRef: options.baseline.ref
|
|
17366
|
+
});
|
|
17367
|
+
if (comparison) {
|
|
17368
|
+
inspectDiagnostics = comparison.displayDiagnostics;
|
|
17369
|
+
baselineDelta = comparison.baselineDelta;
|
|
17370
|
+
}
|
|
17371
|
+
}
|
|
17372
|
+
const baselineDegraded = Boolean(options.baseline) && isDiffMode && baselineDelta === void 0;
|
|
17020
17373
|
const score = didLintFail ? null : output.score;
|
|
17021
17374
|
const elapsedMilliseconds = performance.now() - startTime;
|
|
17022
17375
|
const forceOnboarding = isOnboardingForced();
|
|
@@ -17036,7 +17389,8 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17036
17389
|
directory: output.resolvedDirectory,
|
|
17037
17390
|
scannedFileCount: output.scannedFileCount,
|
|
17038
17391
|
scannedFilePaths: output.scannedFilePaths,
|
|
17039
|
-
scanElapsedMilliseconds: output.scanElapsedMilliseconds
|
|
17392
|
+
scanElapsedMilliseconds: output.scanElapsedMilliseconds,
|
|
17393
|
+
baselineDelta
|
|
17040
17394
|
};
|
|
17041
17395
|
const result = await Effect.runPromise(finalizeAndRender(finalizeInput).pipe(options.silent ? Effect.provideService(Console.Console, silentConsole) : (program) => program));
|
|
17042
17396
|
if (shouldRecordOnboarding({
|
|
@@ -17045,9 +17399,11 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17045
17399
|
verbose: options.verbose,
|
|
17046
17400
|
isNonInteractiveEnvironment: options.isNonInteractiveEnvironment
|
|
17047
17401
|
})) markOnboardingComplete();
|
|
17402
|
+
const scanMode = baselineDelta ? "baseline" : isDiffMode ? "diff" : "full";
|
|
17048
17403
|
recordScanMetrics({
|
|
17049
17404
|
result,
|
|
17050
|
-
mode:
|
|
17405
|
+
mode: scanMode,
|
|
17406
|
+
baselineDegraded,
|
|
17051
17407
|
parallel: options.concurrency !== void 0,
|
|
17052
17408
|
workerCount: options.concurrency,
|
|
17053
17409
|
lint: options.lint,
|
|
@@ -17061,7 +17417,8 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17061
17417
|
recordRunEvent(rootSentrySpan, {
|
|
17062
17418
|
...buildRunEventConfig(options, userConfig, userConfig !== null),
|
|
17063
17419
|
result,
|
|
17064
|
-
mode:
|
|
17420
|
+
mode: scanMode,
|
|
17421
|
+
gateExempt: baselineDegraded,
|
|
17065
17422
|
didLintFail,
|
|
17066
17423
|
lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind,
|
|
17067
17424
|
lintPartialFailureCount: output.lintPartialFailures.length,
|
|
@@ -17070,7 +17427,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17070
17427
|
return result;
|
|
17071
17428
|
};
|
|
17072
17429
|
const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
17073
|
-
const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds } = input;
|
|
17430
|
+
const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds, baselineDelta } = input;
|
|
17074
17431
|
const { skippedChecks, skippedCheckReasons } = buildSkippedChecks({
|
|
17075
17432
|
didLintFail,
|
|
17076
17433
|
lintFailureReason,
|
|
@@ -17089,7 +17446,8 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
17089
17446
|
elapsedMilliseconds,
|
|
17090
17447
|
scannedFileCount,
|
|
17091
17448
|
scannedFilePaths,
|
|
17092
|
-
scanElapsedMilliseconds
|
|
17449
|
+
scanElapsedMilliseconds,
|
|
17450
|
+
...baselineDelta ? { baselineDelta } : {}
|
|
17093
17451
|
});
|
|
17094
17452
|
if (options.suppressRendering) return buildResult();
|
|
17095
17453
|
if (options.scoreOnly) {
|
|
@@ -17361,9 +17719,9 @@ const buildHandoffPayload = (input) => {
|
|
|
17361
17719
|
};
|
|
17362
17720
|
//#endregion
|
|
17363
17721
|
//#region src/cli/utils/is-command-available.ts
|
|
17364
|
-
const isWindows = process.platform === "win32";
|
|
17722
|
+
const isWindows$1 = process.platform === "win32";
|
|
17365
17723
|
const candidateFileNames = (command) => {
|
|
17366
|
-
if (!isWindows || path$1.extname(command)) return [command];
|
|
17724
|
+
if (!isWindows$1 || path$1.extname(command)) return [command];
|
|
17367
17725
|
return [command, ...(process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean).map((extension) => `${command}${extension}`)];
|
|
17368
17726
|
};
|
|
17369
17727
|
const isCommandAvailable = (command) => {
|
|
@@ -17372,7 +17730,7 @@ const isCommandAvailable = (command) => {
|
|
|
17372
17730
|
const binaryPath = path$1.join(directory, fileName);
|
|
17373
17731
|
try {
|
|
17374
17732
|
if (!fs$1.statSync(binaryPath).isFile()) continue;
|
|
17375
|
-
if (!isWindows) fs$1.accessSync(binaryPath, fs$1.constants.X_OK);
|
|
17733
|
+
if (!isWindows$1) fs$1.accessSync(binaryPath, fs$1.constants.X_OK);
|
|
17376
17734
|
return true;
|
|
17377
17735
|
} catch {}
|
|
17378
17736
|
}
|
|
@@ -17409,7 +17767,7 @@ const VITE_PLUS_HOOKS_PATH = ".vite-hooks";
|
|
|
17409
17767
|
const LEFTHOOK_CONFIG_FILES = ["lefthook.yml", "lefthook.yaml"];
|
|
17410
17768
|
const PRE_COMMIT_CONFIG_FILE = ".pre-commit-config.yaml";
|
|
17411
17769
|
const OVERCOMMIT_CONFIG_FILE = ".overcommit.yml";
|
|
17412
|
-
const REACT_DOCTOR_COMMAND = "react-doctor --staged --
|
|
17770
|
+
const REACT_DOCTOR_COMMAND = "react-doctor --staged --blocking warning";
|
|
17413
17771
|
const NON_BLOCKING_REACT_DOCTOR_COMMAND = [
|
|
17414
17772
|
"react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\");",
|
|
17415
17773
|
`if ${REACT_DOCTOR_COMMAND} > "$react_doctor_output" 2>&1; then`,
|
|
@@ -17678,22 +18036,22 @@ const buildAgentHookScript = () => [
|
|
|
17678
18036
|
"",
|
|
17679
18037
|
"run_react_doctor() {",
|
|
17680
18038
|
" if [ -x ./node_modules/.bin/react-doctor ]; then",
|
|
17681
|
-
" ./node_modules/.bin/react-doctor --verbose --diff --
|
|
18039
|
+
" ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
|
|
17682
18040
|
" return",
|
|
17683
18041
|
" fi",
|
|
17684
18042
|
"",
|
|
17685
18043
|
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
17686
|
-
" react-doctor --verbose --diff --
|
|
18044
|
+
" react-doctor --verbose --diff --blocking warning --no-score",
|
|
17687
18045
|
" return",
|
|
17688
18046
|
" fi",
|
|
17689
18047
|
"",
|
|
17690
18048
|
" if command -v pnpm >/dev/null 2>&1; then",
|
|
17691
|
-
" pnpm dlx react-doctor@latest --verbose --diff --
|
|
18049
|
+
" pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
17692
18050
|
" return",
|
|
17693
18051
|
" fi",
|
|
17694
18052
|
"",
|
|
17695
18053
|
" if command -v npx >/dev/null 2>&1; then",
|
|
17696
|
-
" npx --yes react-doctor@latest --verbose --diff --
|
|
18054
|
+
" npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
17697
18055
|
" return",
|
|
17698
18056
|
" fi",
|
|
17699
18057
|
"",
|
|
@@ -17785,6 +18143,11 @@ permissions:
|
|
|
17785
18143
|
# comments (PRs are issues under the hood). Not exercised on \`push\`
|
|
17786
18144
|
# events, so safe to drop if you only run on \`main\`.
|
|
17787
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
|
|
17788
18151
|
|
|
17789
18152
|
# Cancels any in-flight scan for the same PR (or branch, on push) the moment
|
|
17790
18153
|
# a new commit arrives, so reviewers only ever see the latest run.
|
|
@@ -17798,20 +18161,42 @@ jobs:
|
|
|
17798
18161
|
steps:
|
|
17799
18162
|
- uses: actions/checkout@v5
|
|
17800
18163
|
|
|
17801
|
-
- uses: millionco/react-doctor@
|
|
18164
|
+
- uses: millionco/react-doctor@v2
|
|
17802
18165
|
# Common configuration knobs — uncomment any to override the default.
|
|
17803
18166
|
# Full reference: https://www.react.doctor/ci
|
|
17804
18167
|
# with:
|
|
17805
|
-
#
|
|
17806
|
-
#
|
|
18168
|
+
# blocking: warning # Gate level: "error" (default) | "warning" | "none" (advisory)
|
|
18169
|
+
# scope: full # On PRs, scan the whole project instead of just changed files
|
|
17807
18170
|
# comment: false # Disable the sticky PR summary comment
|
|
17808
|
-
#
|
|
17809
|
-
#
|
|
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"
|
|
17810
18174
|
# directory: apps/web # Scan a sub-directory (default: ".")
|
|
17811
18175
|
# project: "web,admin" # In a monorepo, scan specific workspace project(s)
|
|
17812
18176
|
`;
|
|
17813
18177
|
const getReactDoctorWorkflowPath = (projectRoot) => path$1.join(projectRoot, ".github", "workflows", "react-doctor.yml");
|
|
17814
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
|
+
};
|
|
17815
18200
|
const installReactDoctorWorkflow = (projectRoot) => {
|
|
17816
18201
|
const workflowPath = getReactDoctorWorkflowPath(projectRoot);
|
|
17817
18202
|
if (fs$1.existsSync(workflowPath)) return {
|
|
@@ -17855,8 +18240,8 @@ const REACT_DOCTOR_BLOCK_PATTERN = new RegExp(`(?:${REACT_DOCTOR_BLOCK_START}[\\
|
|
|
17855
18240
|
const SHEBANG = "#!/bin/sh";
|
|
17856
18241
|
const SHEBANG_PREFIX = "#!";
|
|
17857
18242
|
const LOCAL_REACT_DOCTOR_BIN = "./node_modules/.bin/react-doctor";
|
|
17858
|
-
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --
|
|
17859
|
-
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --
|
|
18243
|
+
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --blocking warning";
|
|
18244
|
+
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --blocking warning";
|
|
17860
18245
|
const buildReactDoctorHookBlock = () => [
|
|
17861
18246
|
REACT_DOCTOR_BLOCK_START,
|
|
17862
18247
|
"react_doctor_scan_staged_files() {",
|
|
@@ -17937,11 +18322,11 @@ const installDirectGitHook = (options) => {
|
|
|
17937
18322
|
//#region src/cli/utils/install-git-hook-config-managers.ts
|
|
17938
18323
|
const appendStringCommand = (existingCommand) => {
|
|
17939
18324
|
const existingCommandText = typeof existingCommand === "string" ? existingCommand : Array.isArray(existingCommand) ? existingCommand.filter((entry) => typeof entry === "string").join("\n") : "";
|
|
17940
|
-
return existingCommandText.includes("react-doctor --staged --
|
|
18325
|
+
return existingCommandText.includes("react-doctor --staged --blocking warning") ? existingCommandText : [existingCommandText, NON_BLOCKING_REACT_DOCTOR_COMMAND].filter(Boolean).join("\n");
|
|
17941
18326
|
};
|
|
17942
18327
|
const appendArrayCommand = (existingCommands) => {
|
|
17943
18328
|
const commands = Array.isArray(existingCommands) ? existingCommands.filter((entry) => typeof entry === "string") : typeof existingCommands === "string" ? [existingCommands] : [];
|
|
17944
|
-
return commands.some((command) => command.includes("react-doctor --staged --
|
|
18329
|
+
return commands.some((command) => command.includes("react-doctor --staged --blocking warning")) ? commands : [...commands, NON_BLOCKING_REACT_DOCTOR_COMMAND];
|
|
17945
18330
|
};
|
|
17946
18331
|
const installPackageJsonHook = (options, strategy) => {
|
|
17947
18332
|
const packageJsonPath = getPackageJsonPath(options.projectRoot);
|
|
@@ -18238,7 +18623,7 @@ const installReactDoctorGitHook = (options) => {
|
|
|
18238
18623
|
};
|
|
18239
18624
|
//#endregion
|
|
18240
18625
|
//#region src/cli/utils/should-skip-prompts.ts
|
|
18241
|
-
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.
|
|
18626
|
+
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.json) || isNonInteractiveEnvironment() || !process.stdin.isTTY;
|
|
18242
18627
|
//#endregion
|
|
18243
18628
|
//#region src/cli/utils/install-react-doctor.ts
|
|
18244
18629
|
const SETUP_OPTION_GIT_HOOK = "git-hook";
|
|
@@ -18641,6 +19026,41 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18641
19026
|
for (const agent of selectedAgents) recordCount(METRIC.installAgent, 1, { agent });
|
|
18642
19027
|
};
|
|
18643
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
|
|
18644
19064
|
//#region src/cli/utils/install-skill-for-agent.ts
|
|
18645
19065
|
const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
|
|
18646
19066
|
const source = getSkillSourceDirectory();
|
|
@@ -18691,9 +19111,9 @@ const openUrl = (url) => {
|
|
|
18691
19111
|
//#endregion
|
|
18692
19112
|
//#region src/cli/utils/open-workflow-pull-request.ts
|
|
18693
19113
|
const NEW_BRANCH_PREFIX = "react-doctor/add-github-actions";
|
|
18694
|
-
const
|
|
18695
|
-
const
|
|
18696
|
-
const
|
|
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.
|
|
18697
19117
|
|
|
18698
19118
|
Docs: https://www.react.doctor/ci`;
|
|
18699
19119
|
const execFileAsync = promisify(execFile);
|
|
@@ -18745,6 +19165,9 @@ const findUniqueBranchName = async (cwd) => {
|
|
|
18745
19165
|
};
|
|
18746
19166
|
const openWorkflowPullRequest = async (params) => {
|
|
18747
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;
|
|
18748
19171
|
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
18749
19172
|
if (!repoRootProbe.success) return {
|
|
18750
19173
|
status: "not-attempted",
|
|
@@ -18811,7 +19234,7 @@ const openWorkflowPullRequest = async (params) => {
|
|
|
18811
19234
|
if (!(await run("git", [
|
|
18812
19235
|
"commit",
|
|
18813
19236
|
"-m",
|
|
18814
|
-
|
|
19237
|
+
commitMessage
|
|
18815
19238
|
], cwd)).success) {
|
|
18816
19239
|
await restoreToPreviousBranch(true);
|
|
18817
19240
|
return {
|
|
@@ -18835,9 +19258,9 @@ const openWorkflowPullRequest = async (params) => {
|
|
|
18835
19258
|
"pr",
|
|
18836
19259
|
"create",
|
|
18837
19260
|
"--title",
|
|
18838
|
-
|
|
19261
|
+
prTitle,
|
|
18839
19262
|
"--body",
|
|
18840
|
-
|
|
19263
|
+
prBody,
|
|
18841
19264
|
"--base",
|
|
18842
19265
|
defaultBranch,
|
|
18843
19266
|
"--head",
|
|
@@ -18865,6 +19288,7 @@ const stageWorkflowFile = async (params) => {
|
|
|
18865
19288
|
};
|
|
18866
19289
|
//#endregion
|
|
18867
19290
|
//#region src/cli/utils/launch-agent.ts
|
|
19291
|
+
const isWindows = process.platform === "win32";
|
|
18868
19292
|
const CLI_AGENT_BINARIES = {
|
|
18869
19293
|
"claude-code": "claude",
|
|
18870
19294
|
codex: "codex",
|
|
@@ -18875,14 +19299,47 @@ const CLI_AGENT_AUTO_FLAGS = {
|
|
|
18875
19299
|
codex: ["--yolo"],
|
|
18876
19300
|
cursor: ["--force"]
|
|
18877
19301
|
};
|
|
18878
|
-
const
|
|
18879
|
-
|
|
19302
|
+
const resolveWindowsCmdEntryScript = (command) => {
|
|
19303
|
+
if (!isWindows) return null;
|
|
19304
|
+
const pathDirectories = (process.env.PATH ?? "").split(path$1.delimiter).filter(Boolean);
|
|
19305
|
+
for (const directory of pathDirectories) {
|
|
19306
|
+
const cmdFilePath = path$1.join(directory, `${command}.cmd`);
|
|
19307
|
+
try {
|
|
19308
|
+
if (!fs$1.statSync(cmdFilePath).isFile()) continue;
|
|
19309
|
+
} catch {
|
|
19310
|
+
continue;
|
|
19311
|
+
}
|
|
19312
|
+
try {
|
|
19313
|
+
const entryScriptMatch = fs$1.readFileSync(cmdFilePath, "utf8").match(/"%(?:~dp0|dp0%)\\([^"]+\.(?:m?js|cjs))"/);
|
|
19314
|
+
if (!entryScriptMatch) continue;
|
|
19315
|
+
const resolvedScriptPath = path$1.resolve(directory, entryScriptMatch[1]);
|
|
19316
|
+
if (fs$1.statSync(resolvedScriptPath).isFile()) return resolvedScriptPath;
|
|
19317
|
+
} catch {}
|
|
19318
|
+
}
|
|
19319
|
+
return null;
|
|
19320
|
+
};
|
|
19321
|
+
const spawnAgent = (command, args, cwd, shell = false) => new Promise((resolve, reject) => {
|
|
19322
|
+
const child = spawn(command, [...args], {
|
|
18880
19323
|
cwd,
|
|
18881
|
-
stdio: "inherit"
|
|
19324
|
+
stdio: "inherit",
|
|
19325
|
+
shell
|
|
18882
19326
|
});
|
|
18883
19327
|
child.on("error", reject);
|
|
18884
19328
|
child.on("close", (code) => resolve(code ?? 0));
|
|
18885
19329
|
});
|
|
19330
|
+
const launchCliAgent = async (agentId, prompt, cwd) => {
|
|
19331
|
+
const binary = CLI_AGENT_BINARIES[agentId];
|
|
19332
|
+
const agentArgs = [...CLI_AGENT_AUTO_FLAGS[agentId], prompt];
|
|
19333
|
+
if (isWindows) {
|
|
19334
|
+
const entryScript = resolveWindowsCmdEntryScript(binary);
|
|
19335
|
+
if (entryScript) return spawnAgent(process.execPath, [entryScript, ...agentArgs], cwd);
|
|
19336
|
+
}
|
|
19337
|
+
try {
|
|
19338
|
+
return await spawnAgent(binary, agentArgs, cwd);
|
|
19339
|
+
} catch {
|
|
19340
|
+
throw new Error(`Failed to launch ${binary}`);
|
|
19341
|
+
}
|
|
19342
|
+
};
|
|
18886
19343
|
const CLIPBOARD_COMMANDS = [
|
|
18887
19344
|
{
|
|
18888
19345
|
binary: "pbcopy",
|
|
@@ -18955,6 +19412,77 @@ const setUpGitHubActions = async (rootDirectory) => {
|
|
|
18955
19412
|
}
|
|
18956
19413
|
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
18957
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
|
+
};
|
|
18958
19486
|
const SGR_BOLD_OFF = "\x1B[22m";
|
|
18959
19487
|
const ciQuestionMessage = [
|
|
18960
19488
|
"Add React Doctor to GitHub Actions?",
|
|
@@ -19002,7 +19530,8 @@ const detectLaunchableAgents = async () => {
|
|
|
19002
19530
|
const handoffToAgent = async (input) => {
|
|
19003
19531
|
if (!input.interactive || input.diagnostics.length === 0) return;
|
|
19004
19532
|
cliLogger.break();
|
|
19005
|
-
|
|
19533
|
+
const projectRootForCi = findNearestPackageDirectory(input.rootDirectory) ?? input.rootDirectory;
|
|
19534
|
+
if (!isReactDoctorWorkflowInstalled(projectRootForCi)) {
|
|
19006
19535
|
const ciOutcome = await askAddToGitHubActions();
|
|
19007
19536
|
recordCount(METRIC.agentHandoff, 1, {
|
|
19008
19537
|
outcome: `ci-${ciOutcome}`,
|
|
@@ -19013,7 +19542,7 @@ const handoffToAgent = async (input) => {
|
|
|
19013
19542
|
await setUpGitHubActions(input.rootDirectory);
|
|
19014
19543
|
cliLogger.break();
|
|
19015
19544
|
}
|
|
19016
|
-
}
|
|
19545
|
+
} else await maybeOfferActionUpgrade(projectRootForCi);
|
|
19017
19546
|
const { handoffTarget } = await prompts({
|
|
19018
19547
|
type: "select",
|
|
19019
19548
|
name: "handoffTarget",
|
|
@@ -19139,20 +19668,6 @@ export default ${serializeTsObjectLiteral(config)} satisfies ReactDoctorConfig;
|
|
|
19139
19668
|
return targetPath;
|
|
19140
19669
|
};
|
|
19141
19670
|
//#endregion
|
|
19142
|
-
//#region src/cli/utils/annotation-encoding.ts
|
|
19143
|
-
const encodeAnnotationProperty = (value) => value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A").replaceAll(":", "%3A").replaceAll(",", "%2C");
|
|
19144
|
-
const encodeAnnotationMessage = (value) => value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
19145
|
-
//#endregion
|
|
19146
|
-
//#region src/cli/utils/print-annotations.ts
|
|
19147
|
-
const printAnnotations = (diagnostics, routeToStderr) => {
|
|
19148
|
-
const writeLine = routeToStderr ? (line) => process.stderr.write(`${line}\n`) : (line) => process.stdout.write(`${line}\n`);
|
|
19149
|
-
for (const diagnostic of diagnostics) {
|
|
19150
|
-
const level = diagnostic.severity === "error" ? "error" : "warning";
|
|
19151
|
-
const title = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
19152
|
-
writeLine(`::${level} ${`file=${encodeAnnotationProperty(diagnostic.filePath)}`}${diagnostic.line > 0 ? `,line=${diagnostic.line}` : ""}${`,title=${encodeAnnotationProperty(title)}`}::${encodeAnnotationMessage(diagnostic.message)}`);
|
|
19153
|
-
}
|
|
19154
|
-
};
|
|
19155
|
-
//#endregion
|
|
19156
19671
|
//#region src/cli/utils/print-branded-header.ts
|
|
19157
19672
|
/**
|
|
19158
19673
|
* Single branded line every command prints first when not in JSON
|
|
@@ -19361,7 +19876,7 @@ const getSetupPromptStore = (options = {}) => new Conf({
|
|
|
19361
19876
|
projectName: GLOBAL_CONFIG_PROJECT_NAME,
|
|
19362
19877
|
cwd: options.cwd
|
|
19363
19878
|
});
|
|
19364
|
-
const getSetupPromptProjectKey = (projectRoot) =>
|
|
19879
|
+
const getSetupPromptProjectKey = (projectRoot) => hashProjectRoot(projectRoot);
|
|
19365
19880
|
const hasDisabledSetupPrompt = (projectRoot, storeOptions = {}) => {
|
|
19366
19881
|
try {
|
|
19367
19882
|
return getSetupPromptStore(storeOptions).get("projects", {})[getSetupPromptProjectKey(projectRoot)]?.setupPrompt === false;
|
|
@@ -19418,28 +19933,26 @@ const resolveParallelFlag = (parallel) => parallel === false ? 1 : void 0;
|
|
|
19418
19933
|
/**
|
|
19419
19934
|
* Translates CLI flags into the `InspectOptions` contract `inspect()`
|
|
19420
19935
|
* accepts. Flag-specific computed fields (`scoreOnly`, `noScore`,
|
|
19421
|
-
* `silent`, `
|
|
19422
|
-
*
|
|
19423
|
-
*
|
|
19424
|
-
*
|
|
19425
|
-
*
|
|
19426
|
-
*
|
|
19427
|
-
* can apply the one flag-and-config rule that flags own
|
|
19936
|
+
* `silent`, `isCi`) live here — there's no `userConfig` knob for them,
|
|
19937
|
+
* only flag derivation. The plain boolean knobs (`lint`, `deadCode`,
|
|
19938
|
+
* `verbose`) pass through unchanged: `inspect()` owns the
|
|
19939
|
+
* userConfig-fallback layer so the merge logic isn't duplicated. The
|
|
19940
|
+
* shell still hands `userConfig` in via `configOverride` and `noScore`
|
|
19941
|
+
* so this resolver can apply the one flag-and-config rule that flags own
|
|
19428
19942
|
* (`--score false` wins, otherwise inherit `userConfig.noScore`).
|
|
19429
19943
|
*/
|
|
19430
19944
|
const resolveCliInspectOptions = (flags, userConfig) => {
|
|
19431
|
-
const wantsWarningGate = (flags
|
|
19945
|
+
const wantsWarningGate = pickBlockingLevel(flags, userConfig) === "warning";
|
|
19432
19946
|
return {
|
|
19433
19947
|
lint: flags.lint,
|
|
19434
19948
|
deadCode: flags.deadCode,
|
|
19435
19949
|
verbose: flags.verbose,
|
|
19436
|
-
respectInlineDisables: flags.respectInlineDisables,
|
|
19437
|
-
warnings:
|
|
19950
|
+
respectInlineDisables: flags.respectInlineDisables === false ? false : void 0,
|
|
19951
|
+
warnings: wantsWarningGate ? true : flags.warnings,
|
|
19438
19952
|
scoreOnly: flags.score === true,
|
|
19439
19953
|
noScore: flags.score === false || flags.telemetry === false || (userConfig?.noScore ?? false),
|
|
19440
19954
|
isCi: isCiEnvironment(),
|
|
19441
19955
|
silent: Boolean(flags.json),
|
|
19442
|
-
outputSurface: flags.prComment ? "prComment" : "cli",
|
|
19443
19956
|
concurrency: resolveParallelFlag(flags.parallel)
|
|
19444
19957
|
};
|
|
19445
19958
|
};
|
|
@@ -19492,25 +20005,7 @@ const coerceDiffValue = (value) => {
|
|
|
19492
20005
|
};
|
|
19493
20006
|
//#endregion
|
|
19494
20007
|
//#region src/cli/utils/resolve-effective-diff.ts
|
|
19495
|
-
const resolveEffectiveDiff = (flags, userConfig) =>
|
|
19496
|
-
if (flags.full) return false;
|
|
19497
|
-
return coerceDiffValue(flags.diff ?? userConfig?.diff);
|
|
19498
|
-
};
|
|
19499
|
-
//#endregion
|
|
19500
|
-
//#region src/cli/utils/resolve-fail-on-level.ts
|
|
19501
|
-
const VALID_FAIL_ON_LEVELS = new Set([
|
|
19502
|
-
"error",
|
|
19503
|
-
"warning",
|
|
19504
|
-
"none"
|
|
19505
|
-
]);
|
|
19506
|
-
const DEFAULT_FAIL_ON_LEVEL = "none";
|
|
19507
|
-
const isValidFailOnLevel = (level) => VALID_FAIL_ON_LEVELS.has(level);
|
|
19508
|
-
const resolveFailOnLevel = (flags, userConfig) => {
|
|
19509
|
-
const sourceValue = flags.failOn ?? userConfig?.failOn ?? DEFAULT_FAIL_ON_LEVEL;
|
|
19510
|
-
if (isValidFailOnLevel(sourceValue)) return sourceValue;
|
|
19511
|
-
cliLogger.warn(`Invalid failOn level "${sourceValue}". Expected one of: error, warning, none. Falling back to "${DEFAULT_FAIL_ON_LEVEL}".`);
|
|
19512
|
-
return DEFAULT_FAIL_ON_LEVEL;
|
|
19513
|
-
};
|
|
20008
|
+
const resolveEffectiveDiff = (flags, userConfig) => coerceDiffValue(flags.diff ?? userConfig?.diff);
|
|
19514
20009
|
//#endregion
|
|
19515
20010
|
//#region src/cli/utils/resolve-project-diff-include-paths.ts
|
|
19516
20011
|
const resolveProjectDiffIncludePaths = (rootDirectory, projectDirectory, diffInfo) => {
|
|
@@ -19614,8 +20109,11 @@ const selectProjects = async (rootDirectory, projectFlag, skipPrompts) => {
|
|
|
19614
20109
|
}
|
|
19615
20110
|
return promptProjectSelection(packages, rootDirectory);
|
|
19616
20111
|
};
|
|
20112
|
+
const ALL_PROJECTS_SENTINEL = "*";
|
|
19617
20113
|
const resolveProjectFlag = (projectFlag, workspacePackages) => {
|
|
19618
|
-
const requestedNames = projectFlag.split(",").map((name) => name.trim());
|
|
20114
|
+
const requestedNames = projectFlag.split(",").map((name) => name.trim()).filter((name) => name.length > 0);
|
|
20115
|
+
if (requestedNames.length === 0) throw new CliInputError(`--project "${projectFlag}" did not name any project. Pass a project name, a comma-separated list, or "*" for all.`);
|
|
20116
|
+
if (requestedNames.includes(ALL_PROJECTS_SENTINEL)) return workspacePackages.map((workspacePackage) => workspacePackage.directory);
|
|
19619
20117
|
const resolvedDirectories = [];
|
|
19620
20118
|
for (const requestedName of requestedNames) {
|
|
19621
20119
|
const matched = workspacePackages.find((workspacePackage) => workspacePackage.name === requestedName || path$1.basename(workspacePackage.directory) === requestedName);
|
|
@@ -19688,6 +20186,16 @@ const runExplain = async (fileLineArgument, context) => {
|
|
|
19688
20186
|
}
|
|
19689
20187
|
};
|
|
19690
20188
|
//#endregion
|
|
20189
|
+
//#region src/cli/utils/warn-deprecated-fail-on.ts
|
|
20190
|
+
const warnDeprecatedFailOn = (flags, userConfig) => {
|
|
20191
|
+
const usedFlag = flags.failOn !== void 0;
|
|
20192
|
+
const usedConfig = userConfig?.failOn !== void 0;
|
|
20193
|
+
if (!usedFlag && !usedConfig) return;
|
|
20194
|
+
const source = usedFlag ? "The `--fail-on` flag" : "The `failOn` config option";
|
|
20195
|
+
const replacement = usedFlag ? "`--blocking <level>`" : "`blocking`";
|
|
20196
|
+
cliLogger.warn(`${source} is deprecated; rename it to ${replacement}.`);
|
|
20197
|
+
};
|
|
20198
|
+
//#endregion
|
|
19691
20199
|
//#region src/cli/utils/validate-mode-flags.ts
|
|
19692
20200
|
const validateModeFlags = (flags) => {
|
|
19693
20201
|
const coercedDiff = coerceDiffValue(flags.diff);
|
|
@@ -19695,36 +20203,44 @@ const validateModeFlags = (flags) => {
|
|
|
19695
20203
|
if (exclusiveModes.length > 1) throw new CliInputError(`Cannot combine ${exclusiveModes.join(" and ")}; pick one mode.`);
|
|
19696
20204
|
if (flags.score && flags.json) throw new CliInputError("Cannot combine --score and --json; pick one output mode.");
|
|
19697
20205
|
if (flags.score && flags.telemetry === false) throw new CliInputError("Cannot combine --score with --no-telemetry; --score prints the score that --no-telemetry disables.");
|
|
19698
|
-
if (flags.prComment && (flags.json || flags.score)) throw new CliInputError("--pr-comment cannot be combined with --json or --score.");
|
|
19699
|
-
if (flags.annotations && flags.score) throw new CliInputError("--annotations cannot be combined with --score.");
|
|
19700
|
-
if (flags.explain !== void 0 && flags.why !== void 0) throw new CliInputError("Use --explain or --why, not both — they're aliases of the same flag.");
|
|
19701
|
-
if ((flags.explain ?? flags.why) !== void 0 && (flags.json || flags.score || flags.annotations || flags.staged)) throw new CliInputError("--explain cannot be combined with --json, --score, --annotations, or --staged.");
|
|
19702
20206
|
};
|
|
19703
20207
|
//#endregion
|
|
19704
20208
|
//#region src/cli/commands/inspect.ts
|
|
19705
20209
|
/**
|
|
19706
20210
|
* Post-scan finalization shared by the staged-arm and project-loop
|
|
19707
|
-
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
19708
|
-
*
|
|
19709
|
-
* `
|
|
19710
|
-
*
|
|
20211
|
+
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
20212
|
+
* and set `process.exitCode = 1` when a diagnostic at or above the
|
|
20213
|
+
* `--blocking` threshold (default `"error"`) reaches the `ciFailure`
|
|
20214
|
+
* surface. `--blocking none` keeps the scan advisory (always exits 0).
|
|
19711
20215
|
*/
|
|
19712
20216
|
const finalizeScans = (input) => {
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
|
|
19721
|
-
|
|
19722
|
-
|
|
19723
|
-
|
|
20217
|
+
const baselineDeltas = input.completedScans.flatMap((scan) => scan.result.baselineDelta ? [scan.result.baselineDelta] : []);
|
|
20218
|
+
const baselineComputed = input.completedScans.length > 0 && input.completedScans.every((scan) => scan.result.baselineDelta !== void 0);
|
|
20219
|
+
const baselineDegraded = input.baselineIntended && !baselineComputed;
|
|
20220
|
+
const mode = baselineDegraded ? "diff" : input.mode;
|
|
20221
|
+
if (input.isJsonMode) {
|
|
20222
|
+
const baseline = baselineComputed && baselineDeltas.length > 0 ? {
|
|
20223
|
+
baseRef: baselineDeltas[0].baseRef,
|
|
20224
|
+
fixedCount: baselineDeltas.reduce((total, delta) => total + delta.fixedCount, 0),
|
|
20225
|
+
baseTotalCount: baselineDeltas.reduce((total, delta) => total + delta.baseTotalCount, 0)
|
|
20226
|
+
} : void 0;
|
|
20227
|
+
writeJsonReport(buildJsonReport({
|
|
20228
|
+
version: VERSION,
|
|
20229
|
+
directory: input.resolvedDirectory,
|
|
20230
|
+
mode,
|
|
20231
|
+
diff: input.diff,
|
|
20232
|
+
scans: input.completedScans,
|
|
20233
|
+
totalElapsedMilliseconds: performance.now() - input.startTime,
|
|
20234
|
+
baseline
|
|
20235
|
+
}));
|
|
20236
|
+
}
|
|
20237
|
+
if (input.isScoreOnly || baselineDegraded) return;
|
|
20238
|
+
if (shouldBlockCi(filterDiagnosticsForSurface(input.diagnostics, "ciFailure", input.userConfig), resolveBlockingLevel(input.flags, input.userConfig))) process.exitCode = 1;
|
|
19724
20239
|
};
|
|
19725
20240
|
const buildChangedFilesDiffInfo = (changedFiles) => ({
|
|
19726
20241
|
currentBranch: process.env.GITHUB_HEAD_REF?.trim() || null,
|
|
19727
20242
|
baseBranch: process.env.GITHUB_BASE_REF?.trim() || "pull request target",
|
|
20243
|
+
baseSha: process.env.REACT_DOCTOR_BASE_SHA?.trim() || void 0,
|
|
19728
20244
|
changedFiles,
|
|
19729
20245
|
isCurrentChanges: false
|
|
19730
20246
|
});
|
|
@@ -19767,11 +20283,12 @@ const inspectAction = async (directory, flags) => {
|
|
|
19767
20283
|
const userConfig = scanTarget.userConfig;
|
|
19768
20284
|
const resolvedDirectory = scanTarget.resolvedDirectory;
|
|
19769
20285
|
setJsonReportDirectory(resolvedDirectory);
|
|
20286
|
+
warnDeprecatedFailOn(flags, userConfig);
|
|
19770
20287
|
if (scanTarget.didRedirectViaRootDir && !isQuiet) {
|
|
19771
20288
|
cliLogger.dim(`Redirected to ${highlighter.info(toRelativePath(resolvedDirectory, requestedDirectory))} via react-doctor config "rootDir".`);
|
|
19772
20289
|
cliLogger.break();
|
|
19773
20290
|
}
|
|
19774
|
-
const explainArgument = flags.explain
|
|
20291
|
+
const explainArgument = flags.explain;
|
|
19775
20292
|
if (explainArgument !== void 0) {
|
|
19776
20293
|
await runExplain(explainArgument, {
|
|
19777
20294
|
resolvedDirectory,
|
|
@@ -19788,7 +20305,6 @@ const inspectAction = async (directory, flags) => {
|
|
|
19788
20305
|
const scanOptions = resolveCliInspectOptions(flags, userConfig);
|
|
19789
20306
|
const skipPrompts = shouldSkipPrompts({
|
|
19790
20307
|
yes: flags.yes,
|
|
19791
|
-
full: flags.full,
|
|
19792
20308
|
json: flags.json
|
|
19793
20309
|
});
|
|
19794
20310
|
if (flags.staged) {
|
|
@@ -19843,6 +20359,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19843
20359
|
}],
|
|
19844
20360
|
mode: "staged",
|
|
19845
20361
|
diff: null,
|
|
20362
|
+
baselineIntended: false,
|
|
19846
20363
|
isJsonMode,
|
|
19847
20364
|
isScoreOnly,
|
|
19848
20365
|
flags,
|
|
@@ -19856,11 +20373,12 @@ const inspectAction = async (directory, flags) => {
|
|
|
19856
20373
|
return;
|
|
19857
20374
|
}
|
|
19858
20375
|
const projectDirectories = await selectProjects(resolvedDirectory, flags.project, skipPrompts);
|
|
19859
|
-
const changedFilesDiffInfo = flags.changedFilesFrom
|
|
20376
|
+
const changedFilesDiffInfo = flags.changedFilesFrom ? buildChangedFilesDiffInfo(readChangedFilesFrom(path$1.resolve(flags.changedFilesFrom))) : null;
|
|
19860
20377
|
const effectiveDiff = resolveEffectiveDiff(flags, userConfig);
|
|
19861
20378
|
const diffInfo = changedFilesDiffInfo ?? (changedFilesDiffInfo === null && (effectiveDiff !== void 0 && effectiveDiff !== false || !skipPrompts && !isQuiet) ? await getDiffInfo(resolvedDirectory, typeof effectiveDiff === "string" ? effectiveDiff : void 0) : null);
|
|
19862
20379
|
const isDiffMode = changedFilesDiffInfo !== null || await resolveDiffMode(diffInfo, effectiveDiff, skipPrompts, isQuiet);
|
|
19863
|
-
|
|
20380
|
+
const baselineRef = isDiffMode && diffInfo && !diffInfo.isCurrentChanges ? diffInfo.baseSha ? await resolveMergeBaseRef(resolvedDirectory, diffInfo.baseSha) : diffInfo.diffBaseRef ?? await resolveMergeBaseRef(resolvedDirectory, diffInfo.baseBranch) : null;
|
|
20381
|
+
setJsonReportMode(baselineRef ? "baseline" : isDiffMode ? "diff" : "full");
|
|
19864
20382
|
if (isDiffMode && diffInfo && !isQuiet) {
|
|
19865
20383
|
if (diffInfo.isCurrentChanges) cliLogger.log("Scanning uncommitted changes");
|
|
19866
20384
|
else {
|
|
@@ -19890,7 +20408,8 @@ const inspectAction = async (directory, flags) => {
|
|
|
19890
20408
|
...scanOptions,
|
|
19891
20409
|
includePaths,
|
|
19892
20410
|
configOverride: userConfig,
|
|
19893
|
-
suppressRendering: isMultiProject
|
|
20411
|
+
suppressRendering: isMultiProject,
|
|
20412
|
+
baseline: baselineRef ? { ref: baselineRef } : void 0
|
|
19894
20413
|
});
|
|
19895
20414
|
allDiagnostics.push(...scanResult.diagnostics);
|
|
19896
20415
|
completedScans.push({
|
|
@@ -19912,8 +20431,9 @@ const inspectAction = async (directory, flags) => {
|
|
|
19912
20431
|
finalizeScans({
|
|
19913
20432
|
diagnostics: allDiagnostics,
|
|
19914
20433
|
completedScans,
|
|
19915
|
-
mode: isDiffMode ? "diff" : "full",
|
|
20434
|
+
mode: baselineRef ? "baseline" : isDiffMode ? "diff" : "full",
|
|
19916
20435
|
diff: isDiffMode ? diffInfo : null,
|
|
20436
|
+
baselineIntended: isDiffMode && diffInfo !== null && !diffInfo.isCurrentChanges,
|
|
19917
20437
|
isJsonMode,
|
|
19918
20438
|
isScoreOnly,
|
|
19919
20439
|
flags,
|
|
@@ -19951,7 +20471,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19951
20471
|
const isUserError = isExpectedUserError(error);
|
|
19952
20472
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
19953
20473
|
if (isJsonMode) {
|
|
19954
|
-
writeJsonErrorReport(error);
|
|
20474
|
+
writeJsonErrorReport(error, sentryEventId);
|
|
19955
20475
|
process.exitCode = 1;
|
|
19956
20476
|
return;
|
|
19957
20477
|
}
|
|
@@ -20540,6 +21060,20 @@ const versionAction = () => {
|
|
|
20540
21060
|
process.stdout.write(`${buildVersionString()}\n`);
|
|
20541
21061
|
};
|
|
20542
21062
|
//#endregion
|
|
21063
|
+
//#region src/cli/commands/why.ts
|
|
21064
|
+
/**
|
|
21065
|
+
* `why <file:line>` — explains why a rule fired (or why a suppression didn't
|
|
21066
|
+
* apply) at a specific location. A thin wrapper over the inspect flow's
|
|
21067
|
+
* single-location explain path so it reuses the same scan, config resolution,
|
|
21068
|
+
* and clean error handling. (Replaces the former `--explain` / `--why` flags.)
|
|
21069
|
+
*/
|
|
21070
|
+
const whyAction = async (location, options) => {
|
|
21071
|
+
await inspectAction(options.cwd ?? process.cwd(), {
|
|
21072
|
+
explain: location,
|
|
21073
|
+
project: options.project
|
|
21074
|
+
});
|
|
21075
|
+
};
|
|
21076
|
+
//#endregion
|
|
20543
21077
|
//#region src/cli/utils/apply-color-preference.ts
|
|
20544
21078
|
/**
|
|
20545
21079
|
* Resolve an explicit color preference from `--color` / `--no-color` or the
|
|
@@ -20641,13 +21175,32 @@ const normalizeHelpInvocation = (argv, knownCommands) => {
|
|
|
20641
21175
|
return [...nodeArguments, "--help"];
|
|
20642
21176
|
};
|
|
20643
21177
|
//#endregion
|
|
21178
|
+
//#region src/cli/utils/removed-cli-flags.ts
|
|
21179
|
+
const REMOVED_FLAGS = new Map([
|
|
21180
|
+
["--full", "use `--diff false` to force a full scan"],
|
|
21181
|
+
["--explain", "use the `why <file>:<line>` command"],
|
|
21182
|
+
["--why", "use the `why <file>:<line>` command"],
|
|
21183
|
+
["--pr-comment", "the GitHub Action posts the PR comment for you; remove this flag"]
|
|
21184
|
+
]);
|
|
21185
|
+
/**
|
|
21186
|
+
* Throws a clean {@link CliInputError} when a removed flag appears in argv,
|
|
21187
|
+
* pointing to its replacement. Run before flag stripping so a removed flag is a
|
|
21188
|
+
* loud, actionable error rather than a silent no-op.
|
|
21189
|
+
*/
|
|
21190
|
+
const assertNoRemovedFlags = (argv) => {
|
|
21191
|
+
for (const argument of argv.slice(2)) {
|
|
21192
|
+
if (argument === "--") return;
|
|
21193
|
+
const optionName = argument.includes("=") ? argument.slice(0, argument.indexOf("=")) : argument;
|
|
21194
|
+
const guidance = REMOVED_FLAGS.get(optionName);
|
|
21195
|
+
if (guidance !== void 0) throw new CliInputError(`\`${optionName}\` was removed — ${guidance}.`);
|
|
21196
|
+
}
|
|
21197
|
+
};
|
|
21198
|
+
//#endregion
|
|
20644
21199
|
//#region src/cli/utils/strip-unknown-cli-flags.ts
|
|
20645
21200
|
const ROOT_FLAG_SPEC = {
|
|
20646
21201
|
longOptionsWithoutValues: new Set([
|
|
20647
|
-
"--annotations",
|
|
20648
21202
|
"--color",
|
|
20649
21203
|
"--dead-code",
|
|
20650
|
-
"--full",
|
|
20651
21204
|
"--help",
|
|
20652
21205
|
"--json",
|
|
20653
21206
|
"--json-compact",
|
|
@@ -20660,8 +21213,6 @@ const ROOT_FLAG_SPEC = {
|
|
|
20660
21213
|
"--no-score",
|
|
20661
21214
|
"--no-telemetry",
|
|
20662
21215
|
"--no-warnings",
|
|
20663
|
-
"--pr-comment",
|
|
20664
|
-
"--respect-inline-disables",
|
|
20665
21216
|
"--score",
|
|
20666
21217
|
"--staged",
|
|
20667
21218
|
"--verbose",
|
|
@@ -20671,10 +21222,9 @@ const ROOT_FLAG_SPEC = {
|
|
|
20671
21222
|
]),
|
|
20672
21223
|
longOptionsWithRequiredValues: new Set([
|
|
20673
21224
|
"--changed-files-from",
|
|
20674
|
-
"--
|
|
21225
|
+
"--blocking",
|
|
20675
21226
|
"--fail-on",
|
|
20676
|
-
"--project"
|
|
20677
|
-
"--why"
|
|
21227
|
+
"--project"
|
|
20678
21228
|
]),
|
|
20679
21229
|
longOptionsWithOptionalValues: new Set(["--diff"]),
|
|
20680
21230
|
shortOptionsWithoutValues: new Set([
|
|
@@ -20730,6 +21280,17 @@ const COMMAND_FLAG_SPECS = new Map([
|
|
|
20730
21280
|
longOptionsWithOptionalValues: /* @__PURE__ */ new Set(),
|
|
20731
21281
|
shortOptionsWithoutValues: new Set(["-h"]),
|
|
20732
21282
|
shortOptionsWithRequiredValues: new Set(["-c"])
|
|
21283
|
+
}],
|
|
21284
|
+
["why", {
|
|
21285
|
+
longOptionsWithoutValues: new Set([
|
|
21286
|
+
"--color",
|
|
21287
|
+
"--help",
|
|
21288
|
+
"--no-color"
|
|
21289
|
+
]),
|
|
21290
|
+
longOptionsWithRequiredValues: new Set(["--cwd", "--project"]),
|
|
21291
|
+
longOptionsWithOptionalValues: /* @__PURE__ */ new Set(),
|
|
21292
|
+
shortOptionsWithoutValues: new Set(["-h"]),
|
|
21293
|
+
shortOptionsWithRequiredValues: new Set(["-c"])
|
|
20733
21294
|
}]
|
|
20734
21295
|
]);
|
|
20735
21296
|
const isFlagLike = (argument) => argument.startsWith("-") && argument !== "-";
|
|
@@ -20816,9 +21377,9 @@ ${formatExampleLines([
|
|
|
20816
21377
|
["react-doctor ./apps/web", "scan a specific directory"],
|
|
20817
21378
|
["react-doctor --diff main", "scan only files changed vs. main"],
|
|
20818
21379
|
["react-doctor --staged", "scan staged files (pre-commit hook)"],
|
|
20819
|
-
["react-doctor --
|
|
21380
|
+
["react-doctor --blocking warning", "fail CI on warnings too (default: error)"],
|
|
20820
21381
|
["react-doctor --json > report.json", "write a machine-readable report"],
|
|
20821
|
-
["react-doctor
|
|
21382
|
+
["react-doctor why src/App.tsx:42", "explain why a rule fired there"],
|
|
20822
21383
|
["react-doctor install", "set up the agent skill and git hook"]
|
|
20823
21384
|
])}
|
|
20824
21385
|
|
|
@@ -20844,8 +21405,9 @@ ${formatExampleLines([
|
|
|
20844
21405
|
${highlighter.dim("Learn more:")}
|
|
20845
21406
|
${highlighter.info(CANONICAL_GITHUB_URL)}
|
|
20846
21407
|
`;
|
|
20847
|
-
const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--
|
|
21408
|
+
const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--no-parallel", "lint serially with one worker (default: parallel across CPU cores; set the worker count with REACT_DOCTOR_PARALLEL)").option("--project <name>", "select workspace project (comma-separated for multiple)").option("--diff [base]", "scan only files changed vs base branch (pass `false` to force a full scan, overriding config)").addOption(new Option$1("--changed-files-from <file>", "scan source files listed in a newline-delimited changed-files file").hideHelp()).option("--no-score", "skip the score API, the share URL, and crash reporting").option("--no-telemetry", "alias for --no-score (skip the score API, share URL, and crash reporting)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--blocking <level>", "severity that fails CI: error (default), warning, or none (advisory)").addOption(new Option$1("--fail-on <level>", "[deprecated] alias for --blocking <level>").hideHelp()).option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").option("--warnings", "show warning-severity diagnostics (default)").option("--no-warnings", "hide warning-severity diagnostics (errors only)").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderRootHelpEpilog);
|
|
20848
21409
|
program.action(inspectAction);
|
|
21410
|
+
program.command("why <location>").description("Explain why a rule fired (or why a suppression didn't apply) at a file:line").option("--project <name>", "select workspace project (comma-separated for multiple)").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").action((location, options) => whyAction(location, options));
|
|
20849
21411
|
program.command("install").alias("setup").description("Install the react-doctor skill into your coding agents and optional git hook").option("-y, --yes", "skip prompts, install for all detected agents").option("--dry-run", "show what would be installed without writing files").option("--agent-hooks", "install native non-blocking agent hooks for Claude Code and Cursor").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderInstallHelpEpilog).action(installAction);
|
|
20850
21412
|
program.command("version").description("show the version with Node and platform info").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").action(versionAction);
|
|
20851
21413
|
const rules = program.command("rules").description("List, explain, and configure which React Doctor rules run");
|
|
@@ -20857,6 +21419,7 @@ rules.command("disable <rule>").description("Disable a rule so it never runs").o
|
|
|
20857
21419
|
rules.command("category <category> <severity>").description("Set the severity for a whole category (off, warn, error)").option("-c, --cwd <cwd>", "working directory", process.cwd()).action((category, severity, _options, command) => rulesCategoryAction(category, severity, command.optsWithGlobals()));
|
|
20858
21420
|
rules.command("ignore-tag <tag>").description("Skip a whole rule family by tag before linting (e.g. design)").option("-c, --cwd <cwd>", "working directory", process.cwd()).action((tag, _options, command) => rulesIgnoreTagAction(tag, command.optsWithGlobals()));
|
|
20859
21421
|
rules.command("unignore-tag <tag>").description("Stop ignoring a tag previously skipped via ignore-tag").option("-c, --cwd <cwd>", "working directory", process.cwd()).action((tag, _options, command) => rulesUnignoreTagAction(tag, command.optsWithGlobals()));
|
|
21422
|
+
program.command("experimental-lsp", { hidden: false }).description("[experimental] run the React Doctor language server over stdio (for editors)").allowUnknownOption().action(() => {});
|
|
20860
21423
|
process.stdout.on("error", (error) => {
|
|
20861
21424
|
if (error.code === "EPIPE") process.exit(0);
|
|
20862
21425
|
});
|
|
@@ -20868,11 +21431,11 @@ if (process.argv.includes("-V") && !strippedArgv.includes("-V")) {
|
|
|
20868
21431
|
}
|
|
20869
21432
|
applyColorPreference(strippedArgv);
|
|
20870
21433
|
const argv = normalizeHelpInvocation(strippedArgv, knownCommands);
|
|
20871
|
-
program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
21434
|
+
Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => program.parseAsync(argv)).then(() => flushSentry()).catch(async (error) => {
|
|
20872
21435
|
const isUserError = isExpectedUserError(error);
|
|
20873
21436
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
20874
21437
|
if (isJsonModeActive()) {
|
|
20875
|
-
writeJsonErrorReport(error);
|
|
21438
|
+
writeJsonErrorReport(error, sentryEventId);
|
|
20876
21439
|
process.exit(1);
|
|
20877
21440
|
}
|
|
20878
21441
|
if (isUserError) {
|
|
@@ -20885,4 +21448,4 @@ program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
|
20885
21448
|
export {};
|
|
20886
21449
|
|
|
20887
21450
|
//# sourceMappingURL=cli.js.map
|
|
20888
|
-
//# debugId=
|
|
21451
|
+
//# debugId=301c4437-ca87-5afb-b69d-b7a7c3678175
|