react-doctor 0.2.18-dev.f375dbb → 0.3.0-dev.7593271
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 +18 -2
- package/bin/react-doctor.js +9 -1
- package/dist/cli.js +1683 -641
- package/dist/index.d.ts +150 -13
- package/dist/index.js +455 -250
- package/dist/lsp.js +10804 -0
- package/package.json +9 -5
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]="3c457dc9-865a-5459-b923-a0fb762b158f")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
|
-
import * as
|
|
6
|
-
import path
|
|
4
|
+
import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import * as path$1 from "node:path";
|
|
6
|
+
import path from "node:path";
|
|
7
7
|
import * as fs$1 from "node:fs";
|
|
8
|
-
import 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,15 +34,15 @@ 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
41
|
import * as Tracer from "effect/Tracer";
|
|
40
|
-
import
|
|
41
|
-
import { stripVTControlCharacters } from "node:util";
|
|
42
|
+
import { promisify, stripVTControlCharacters } from "node:util";
|
|
42
43
|
import tty from "node:tty";
|
|
43
44
|
import { codeFrameColumns } from "@babel/code-frame";
|
|
44
45
|
import Conf from "conf";
|
|
45
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
46
46
|
import basePrompts from "prompts";
|
|
47
47
|
import { SKILL_MANIFEST_FILE, detectInstalledSkillAgents, getSkillAgentConfig, getSkillAgentTypes, installSkillsFromSource } from "agent-install";
|
|
48
48
|
import { fileURLToPath } from "node:url";
|
|
@@ -1088,7 +1088,7 @@ var require_suggestSimilar = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
|
1088
1088
|
var require_command = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
1089
1089
|
const EventEmitter = __require("node:events").EventEmitter;
|
|
1090
1090
|
const childProcess = __require("node:child_process");
|
|
1091
|
-
const path$
|
|
1091
|
+
const path$2 = __require("node:path");
|
|
1092
1092
|
const fs$2 = __require("node:fs");
|
|
1093
1093
|
const process$3 = __require("node:process");
|
|
1094
1094
|
const { Argument, humanReadableArgName } = require_argument();
|
|
@@ -2008,9 +2008,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2008
2008
|
".cjs"
|
|
2009
2009
|
];
|
|
2010
2010
|
function findFile(baseDir, baseName) {
|
|
2011
|
-
const localBin = path$
|
|
2011
|
+
const localBin = path$2.resolve(baseDir, baseName);
|
|
2012
2012
|
if (fs$2.existsSync(localBin)) return localBin;
|
|
2013
|
-
if (sourceExt.includes(path$
|
|
2013
|
+
if (sourceExt.includes(path$2.extname(baseName))) return void 0;
|
|
2014
2014
|
const foundExt = sourceExt.find((ext) => fs$2.existsSync(`${localBin}${ext}`));
|
|
2015
2015
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
2016
2016
|
}
|
|
@@ -2025,17 +2025,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2025
2025
|
} catch {
|
|
2026
2026
|
resolvedScriptPath = this._scriptPath;
|
|
2027
2027
|
}
|
|
2028
|
-
executableDir = path$
|
|
2028
|
+
executableDir = path$2.resolve(path$2.dirname(resolvedScriptPath), executableDir);
|
|
2029
2029
|
}
|
|
2030
2030
|
if (executableDir) {
|
|
2031
2031
|
let localFile = findFile(executableDir, executableFile);
|
|
2032
2032
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2033
|
-
const legacyName = path$
|
|
2033
|
+
const legacyName = path$2.basename(this._scriptPath, path$2.extname(this._scriptPath));
|
|
2034
2034
|
if (legacyName !== this._name) localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
2035
2035
|
}
|
|
2036
2036
|
executableFile = localFile || executableFile;
|
|
2037
2037
|
}
|
|
2038
|
-
launchWithNode = sourceExt.includes(path$
|
|
2038
|
+
launchWithNode = sourceExt.includes(path$2.extname(executableFile));
|
|
2039
2039
|
let proc;
|
|
2040
2040
|
if (process$3.platform !== "win32") if (launchWithNode) {
|
|
2041
2041
|
args.unshift(executableFile);
|
|
@@ -2803,7 +2803,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2803
2803
|
* @return {Command}
|
|
2804
2804
|
*/
|
|
2805
2805
|
nameFromFilename(filename) {
|
|
2806
|
-
this._name = path$
|
|
2806
|
+
this._name = path$2.basename(filename, path$2.extname(filename));
|
|
2807
2807
|
return this;
|
|
2808
2808
|
}
|
|
2809
2809
|
/**
|
|
@@ -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) => {
|
|
@@ -5102,7 +5146,7 @@ var AmbiguousProjectError = class extends Error {
|
|
|
5102
5146
|
const isProjectDiscoveryError = (value) => value instanceof ProjectNotFoundError || value instanceof NoReactDependencyError || value instanceof PackageJsonNotFoundError || value instanceof NotADirectoryError || value instanceof AmbiguousProjectError;
|
|
5103
5147
|
const isFile = (filePath) => {
|
|
5104
5148
|
try {
|
|
5105
|
-
return fs.statSync(filePath).isFile();
|
|
5149
|
+
return fs$1.statSync(filePath).isFile();
|
|
5106
5150
|
} catch {
|
|
5107
5151
|
return false;
|
|
5108
5152
|
}
|
|
@@ -5129,9 +5173,9 @@ const isLintableSourceFile = (filePath) => SOURCE_FILE_PATTERN.test(filePath) &&
|
|
|
5129
5173
|
const isMinifiedSource = (absolutePath) => {
|
|
5130
5174
|
let fileDescriptor;
|
|
5131
5175
|
try {
|
|
5132
|
-
fileDescriptor = fs.openSync(absolutePath, "r");
|
|
5176
|
+
fileDescriptor = fs$1.openSync(absolutePath, "r");
|
|
5133
5177
|
const buffer = Buffer.alloc(MINIFIED_SNIFF_BYTES);
|
|
5134
|
-
const bytesRead = fs.readSync(fileDescriptor, buffer, 0, MINIFIED_SNIFF_BYTES, 0);
|
|
5178
|
+
const bytesRead = fs$1.readSync(fileDescriptor, buffer, 0, MINIFIED_SNIFF_BYTES, 0);
|
|
5135
5179
|
const prefix = buffer.toString("utf8", 0, bytesRead);
|
|
5136
5180
|
const lines = prefix.split("\n");
|
|
5137
5181
|
const longestLineLength = lines.reduce((longest, line) => Math.max(longest, line.length), 0);
|
|
@@ -5140,13 +5184,13 @@ const isMinifiedSource = (absolutePath) => {
|
|
|
5140
5184
|
} catch {
|
|
5141
5185
|
return false;
|
|
5142
5186
|
} finally {
|
|
5143
|
-
if (fileDescriptor !== void 0) fs.closeSync(fileDescriptor);
|
|
5187
|
+
if (fileDescriptor !== void 0) fs$1.closeSync(fileDescriptor);
|
|
5144
5188
|
}
|
|
5145
5189
|
};
|
|
5146
5190
|
const isLargeMinifiedFile = (absolutePath) => {
|
|
5147
5191
|
let sizeBytes;
|
|
5148
5192
|
try {
|
|
5149
|
-
sizeBytes = fs.statSync(absolutePath).size;
|
|
5193
|
+
sizeBytes = fs$1.statSync(absolutePath).size;
|
|
5150
5194
|
} catch {
|
|
5151
5195
|
return false;
|
|
5152
5196
|
}
|
|
@@ -5157,7 +5201,10 @@ const IGNORABLE_READDIR_ERROR_CODES = new Set([
|
|
|
5157
5201
|
"EACCES",
|
|
5158
5202
|
"EPERM",
|
|
5159
5203
|
"ENOENT",
|
|
5160
|
-
"ENOTDIR"
|
|
5204
|
+
"ENOTDIR",
|
|
5205
|
+
"EINVAL",
|
|
5206
|
+
"ELOOP",
|
|
5207
|
+
"ENAMETOOLONG"
|
|
5161
5208
|
]);
|
|
5162
5209
|
const isIgnorableReaddirError = (error) => {
|
|
5163
5210
|
if (typeof error !== "object" || error === null) return false;
|
|
@@ -5166,7 +5213,7 @@ const isIgnorableReaddirError = (error) => {
|
|
|
5166
5213
|
};
|
|
5167
5214
|
const readDirectoryEntries = (directoryPath) => {
|
|
5168
5215
|
try {
|
|
5169
|
-
return fs.readdirSync(directoryPath, { withFileTypes: true });
|
|
5216
|
+
return fs$1.readdirSync(directoryPath, { withFileTypes: true });
|
|
5170
5217
|
} catch (error) {
|
|
5171
5218
|
if (isIgnorableReaddirError(error)) return [];
|
|
5172
5219
|
throw error;
|
|
@@ -5180,10 +5227,10 @@ const countSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
5180
5227
|
const entries = readDirectoryEntries(currentDirectory);
|
|
5181
5228
|
for (const entry of entries) {
|
|
5182
5229
|
if (entry.isDirectory()) {
|
|
5183
|
-
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(path.join(currentDirectory, entry.name));
|
|
5230
|
+
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(path$1.join(currentDirectory, entry.name));
|
|
5184
5231
|
continue;
|
|
5185
5232
|
}
|
|
5186
|
-
if (entry.isFile() && isLintableSourceFile(entry.name) && !isLargeMinifiedFile(path.join(currentDirectory, entry.name))) count++;
|
|
5233
|
+
if (entry.isFile() && isLintableSourceFile(entry.name) && !isLargeMinifiedFile(path$1.join(currentDirectory, entry.name))) count++;
|
|
5187
5234
|
}
|
|
5188
5235
|
}
|
|
5189
5236
|
return count;
|
|
@@ -5201,13 +5248,13 @@ const countSourceFilesViaGit = (rootDirectory) => {
|
|
|
5201
5248
|
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
5202
5249
|
});
|
|
5203
5250
|
if (result.error || result.status !== 0) return null;
|
|
5204
|
-
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath) && !isLargeMinifiedFile(path.resolve(rootDirectory, filePath))).length;
|
|
5251
|
+
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath) && !isLargeMinifiedFile(path$1.resolve(rootDirectory, filePath))).length;
|
|
5205
5252
|
};
|
|
5206
5253
|
const countSourceFiles = (rootDirectory) => countSourceFilesViaGit(rootDirectory) ?? countSourceFilesViaFilesystem(rootDirectory);
|
|
5207
5254
|
const cachedPackageJsons = /* @__PURE__ */ new Map();
|
|
5208
5255
|
const readPackageJsonUncached = (packageJsonPath) => {
|
|
5209
5256
|
try {
|
|
5210
|
-
return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
5257
|
+
return JSON.parse(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
5211
5258
|
} catch (error) {
|
|
5212
5259
|
if (error instanceof SyntaxError) return {};
|
|
5213
5260
|
if (error instanceof Error && "code" in error) {
|
|
@@ -5218,7 +5265,7 @@ const readPackageJsonUncached = (packageJsonPath) => {
|
|
|
5218
5265
|
}
|
|
5219
5266
|
};
|
|
5220
5267
|
const readPackageJson$1 = (packageJsonPath) => {
|
|
5221
|
-
const absolutePath = path.resolve(packageJsonPath);
|
|
5268
|
+
const absolutePath = path$1.resolve(packageJsonPath);
|
|
5222
5269
|
const cached = cachedPackageJsons.get(absolutePath);
|
|
5223
5270
|
if (cached !== void 0) return cached;
|
|
5224
5271
|
const result = readPackageJsonUncached(absolutePath);
|
|
@@ -5226,18 +5273,18 @@ const readPackageJson$1 = (packageJsonPath) => {
|
|
|
5226
5273
|
return result;
|
|
5227
5274
|
};
|
|
5228
5275
|
const isMonorepoRoot = (directory) => {
|
|
5229
|
-
if (isFile(path.join(directory, "pnpm-workspace.yaml"))) return true;
|
|
5230
|
-
if (isFile(path.join(directory, "nx.json"))) return true;
|
|
5231
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
5276
|
+
if (isFile(path$1.join(directory, "pnpm-workspace.yaml"))) return true;
|
|
5277
|
+
if (isFile(path$1.join(directory, "nx.json"))) return true;
|
|
5278
|
+
const packageJsonPath = path$1.join(directory, "package.json");
|
|
5232
5279
|
if (!isFile(packageJsonPath)) return false;
|
|
5233
5280
|
const packageJson = readPackageJson$1(packageJsonPath);
|
|
5234
5281
|
return Array.isArray(packageJson.workspaces) || Boolean(packageJson.workspaces?.packages);
|
|
5235
5282
|
};
|
|
5236
5283
|
const findMonorepoRoot = (startDirectory) => {
|
|
5237
|
-
let currentDirectory = path.dirname(startDirectory);
|
|
5238
|
-
while (currentDirectory !== path.dirname(currentDirectory)) {
|
|
5284
|
+
let currentDirectory = path$1.dirname(startDirectory);
|
|
5285
|
+
while (currentDirectory !== path$1.dirname(currentDirectory)) {
|
|
5239
5286
|
if (isMonorepoRoot(currentDirectory)) return currentDirectory;
|
|
5240
|
-
currentDirectory = path.dirname(currentDirectory);
|
|
5287
|
+
currentDirectory = path$1.dirname(currentDirectory);
|
|
5241
5288
|
}
|
|
5242
5289
|
return null;
|
|
5243
5290
|
};
|
|
@@ -5251,7 +5298,7 @@ const findMonorepoRoot = (startDirectory) => {
|
|
|
5251
5298
|
* `detectReactCompiler`. All three previously inlined their own
|
|
5252
5299
|
* byte-equivalent copy.
|
|
5253
5300
|
*/
|
|
5254
|
-
const isProjectBoundary = (directory) => fs.existsSync(path.join(directory, ".git")) || isMonorepoRoot(directory);
|
|
5301
|
+
const isProjectBoundary = (directory) => fs$1.existsSync(path$1.join(directory, ".git")) || isMonorepoRoot(directory);
|
|
5255
5302
|
const REACT_COMPILER_PACKAGES = new Set([
|
|
5256
5303
|
"babel-plugin-react-compiler",
|
|
5257
5304
|
"react-compiler-runtime",
|
|
@@ -5298,10 +5345,10 @@ const hasCompilerPackage = (packageJson) => {
|
|
|
5298
5345
|
};
|
|
5299
5346
|
const hasCompilerInConfigFile = (filePath) => {
|
|
5300
5347
|
if (!isFile(filePath)) return false;
|
|
5301
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
5348
|
+
const content = fs$1.readFileSync(filePath, "utf-8");
|
|
5302
5349
|
return REACT_COMPILER_ENABLED_FLAG_PATTERN.test(content) || REACT_COMPILER_PACKAGE_REFERENCE_PATTERN.test(content);
|
|
5303
5350
|
};
|
|
5304
|
-
const hasCompilerInConfigFiles = (directory, filenames) => filenames.some((filename) => hasCompilerInConfigFile(path.join(directory, filename)));
|
|
5351
|
+
const hasCompilerInConfigFiles = (directory, filenames) => filenames.some((filename) => hasCompilerInConfigFile(path$1.join(directory, filename)));
|
|
5305
5352
|
const detectReactCompiler = (directory, packageJson) => {
|
|
5306
5353
|
if (hasCompilerPackage(packageJson)) return true;
|
|
5307
5354
|
if (hasCompilerInConfigFiles(directory, NEXT_CONFIG_FILENAMES)) return true;
|
|
@@ -5309,14 +5356,14 @@ const detectReactCompiler = (directory, packageJson) => {
|
|
|
5309
5356
|
if (hasCompilerInConfigFiles(directory, VITE_CONFIG_FILENAMES)) return true;
|
|
5310
5357
|
if (hasCompilerInConfigFiles(directory, EXPO_APP_CONFIG_FILENAMES)) return true;
|
|
5311
5358
|
if (isProjectBoundary(directory)) return false;
|
|
5312
|
-
let ancestorDirectory = path.dirname(directory);
|
|
5313
|
-
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
5314
|
-
const ancestorPackagePath = path.join(ancestorDirectory, "package.json");
|
|
5359
|
+
let ancestorDirectory = path$1.dirname(directory);
|
|
5360
|
+
while (ancestorDirectory !== path$1.dirname(ancestorDirectory)) {
|
|
5361
|
+
const ancestorPackagePath = path$1.join(ancestorDirectory, "package.json");
|
|
5315
5362
|
if (isFile(ancestorPackagePath)) {
|
|
5316
5363
|
if (hasCompilerPackage(readPackageJson$1(ancestorPackagePath))) return true;
|
|
5317
5364
|
}
|
|
5318
5365
|
if (isProjectBoundary(ancestorDirectory)) return false;
|
|
5319
|
-
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
5366
|
+
ancestorDirectory = path$1.dirname(ancestorDirectory);
|
|
5320
5367
|
}
|
|
5321
5368
|
return false;
|
|
5322
5369
|
};
|
|
@@ -5502,12 +5549,12 @@ const resolveVersionFromCatalog = (catalog, packageName) => {
|
|
|
5502
5549
|
return null;
|
|
5503
5550
|
};
|
|
5504
5551
|
const parsePnpmWorkspaceCatalogs = (rootDirectory) => {
|
|
5505
|
-
const workspacePath = path.join(rootDirectory, "pnpm-workspace.yaml");
|
|
5552
|
+
const workspacePath = path$1.join(rootDirectory, "pnpm-workspace.yaml");
|
|
5506
5553
|
if (!isFile(workspacePath)) return {
|
|
5507
5554
|
defaultCatalog: {},
|
|
5508
5555
|
namedCatalogs: {}
|
|
5509
5556
|
};
|
|
5510
|
-
const content = fs.readFileSync(workspacePath, "utf-8");
|
|
5557
|
+
const content = fs$1.readFileSync(workspacePath, "utf-8");
|
|
5511
5558
|
const defaultCatalog = {};
|
|
5512
5559
|
const namedCatalogs = {};
|
|
5513
5560
|
let currentSection = "none";
|
|
@@ -5688,7 +5735,7 @@ const getDependencyDeclaration = ({ packageJson, packageName, sections }) => {
|
|
|
5688
5735
|
};
|
|
5689
5736
|
const isDirectory = (directoryPath) => {
|
|
5690
5737
|
try {
|
|
5691
|
-
return fs.statSync(directoryPath).isDirectory();
|
|
5738
|
+
return fs$1.statSync(directoryPath).isDirectory();
|
|
5692
5739
|
} catch {
|
|
5693
5740
|
return false;
|
|
5694
5741
|
}
|
|
@@ -5699,23 +5746,23 @@ const NX_PROJECT_DISCOVERY_DIRS = [
|
|
|
5699
5746
|
"packages"
|
|
5700
5747
|
];
|
|
5701
5748
|
const getNxWorkspaceDirectories = (rootDirectory) => {
|
|
5702
|
-
if (!isFile(path.join(rootDirectory, "nx.json"))) return [];
|
|
5749
|
+
if (!isFile(path$1.join(rootDirectory, "nx.json"))) return [];
|
|
5703
5750
|
const collected = [];
|
|
5704
5751
|
for (const candidate of NX_PROJECT_DISCOVERY_DIRS) {
|
|
5705
|
-
const candidatePath = path.join(rootDirectory, candidate);
|
|
5752
|
+
const candidatePath = path$1.join(rootDirectory, candidate);
|
|
5706
5753
|
if (!isDirectory(candidatePath)) continue;
|
|
5707
5754
|
for (const entry of readDirectoryEntries(candidatePath)) {
|
|
5708
5755
|
if (!entry.isDirectory()) continue;
|
|
5709
|
-
const projectDirectory = path.join(candidatePath, entry.name);
|
|
5710
|
-
if (isFile(path.join(projectDirectory, "project.json")) || isFile(path.join(projectDirectory, "package.json"))) collected.push(`${candidate}/${entry.name}`);
|
|
5756
|
+
const projectDirectory = path$1.join(candidatePath, entry.name);
|
|
5757
|
+
if (isFile(path$1.join(projectDirectory, "project.json")) || isFile(path$1.join(projectDirectory, "package.json"))) collected.push(`${candidate}/${entry.name}`);
|
|
5711
5758
|
}
|
|
5712
5759
|
}
|
|
5713
5760
|
return collected;
|
|
5714
5761
|
};
|
|
5715
5762
|
const parsePnpmWorkspacePatterns = (rootDirectory) => {
|
|
5716
|
-
const workspacePath = path.join(rootDirectory, "pnpm-workspace.yaml");
|
|
5763
|
+
const workspacePath = path$1.join(rootDirectory, "pnpm-workspace.yaml");
|
|
5717
5764
|
if (!isFile(workspacePath)) return [];
|
|
5718
|
-
const content = fs.readFileSync(workspacePath, "utf-8");
|
|
5765
|
+
const content = fs$1.readFileSync(workspacePath, "utf-8");
|
|
5719
5766
|
const patterns = [];
|
|
5720
5767
|
let isInsidePackagesBlock = false;
|
|
5721
5768
|
for (const line of content.split("\n")) {
|
|
@@ -5745,18 +5792,18 @@ const parseReactMajor = (reactVersion) => {
|
|
|
5745
5792
|
const resolveWorkspaceDirectories = (rootDirectory, pattern) => {
|
|
5746
5793
|
const cleanPattern = pattern.replace(/["']/g, "").replace(/\/\*\*$/, "/*");
|
|
5747
5794
|
if (!cleanPattern.includes("*")) {
|
|
5748
|
-
const directoryPath = path.join(rootDirectory, cleanPattern);
|
|
5749
|
-
if (isDirectory(directoryPath) && isFile(path.join(directoryPath, "package.json"))) return [directoryPath];
|
|
5795
|
+
const directoryPath = path$1.join(rootDirectory, cleanPattern);
|
|
5796
|
+
if (isDirectory(directoryPath) && isFile(path$1.join(directoryPath, "package.json"))) return [directoryPath];
|
|
5750
5797
|
return [];
|
|
5751
5798
|
}
|
|
5752
5799
|
const wildcardIndex = cleanPattern.indexOf("*");
|
|
5753
|
-
const baseDirectory = path.join(rootDirectory, cleanPattern.slice(0, wildcardIndex));
|
|
5800
|
+
const baseDirectory = path$1.join(rootDirectory, cleanPattern.slice(0, wildcardIndex));
|
|
5754
5801
|
const suffixAfterWildcard = cleanPattern.slice(wildcardIndex + 1);
|
|
5755
5802
|
if (!isDirectory(baseDirectory)) return [];
|
|
5756
5803
|
const resolved = [];
|
|
5757
5804
|
for (const entry of readDirectoryEntries(baseDirectory)) {
|
|
5758
|
-
const entryPath = path.join(baseDirectory, entry.name, suffixAfterWildcard);
|
|
5759
|
-
if (isDirectory(entryPath) && isFile(path.join(entryPath, "package.json"))) resolved.push(entryPath);
|
|
5805
|
+
const entryPath = path$1.join(baseDirectory, entry.name, suffixAfterWildcard);
|
|
5806
|
+
if (isDirectory(entryPath) && isFile(path$1.join(entryPath, "package.json"))) resolved.push(entryPath);
|
|
5760
5807
|
}
|
|
5761
5808
|
return resolved;
|
|
5762
5809
|
};
|
|
@@ -5783,7 +5830,7 @@ const findReactInWorkspaces = (rootDirectory, packageJson) => {
|
|
|
5783
5830
|
for (const pattern of patterns) {
|
|
5784
5831
|
const directories = resolveWorkspaceDirectories(rootDirectory, pattern);
|
|
5785
5832
|
for (const workspaceDirectory of directories) {
|
|
5786
|
-
const workspacePackageJson = readPackageJson$1(path.join(workspaceDirectory, "package.json"));
|
|
5833
|
+
const workspacePackageJson = readPackageJson$1(path$1.join(workspaceDirectory, "package.json"));
|
|
5787
5834
|
const info = extractDependencyInfo(workspacePackageJson);
|
|
5788
5835
|
const reactVersion = resolveWorkspaceDependencyVersion({
|
|
5789
5836
|
concreteVersion: info.reactVersion,
|
|
@@ -5837,11 +5884,11 @@ const findReactInWorkspaces = (rootDirectory, packageJson) => {
|
|
|
5837
5884
|
const findDependencyInfoFromMonorepoRoot = (directory) => {
|
|
5838
5885
|
const monorepoRoot = findMonorepoRoot(directory);
|
|
5839
5886
|
if (!monorepoRoot) return EMPTY_DEPENDENCY_INFO;
|
|
5840
|
-
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
5887
|
+
const monorepoPackageJsonPath = path$1.join(monorepoRoot, "package.json");
|
|
5841
5888
|
if (!isFile(monorepoPackageJsonPath)) return EMPTY_DEPENDENCY_INFO;
|
|
5842
5889
|
const rootPackageJson = readPackageJson$1(monorepoPackageJsonPath);
|
|
5843
5890
|
const rootInfo = extractDependencyInfo(rootPackageJson);
|
|
5844
|
-
const leafPackageJsonPath = path.join(directory, "package.json");
|
|
5891
|
+
const leafPackageJsonPath = path$1.join(directory, "package.json");
|
|
5845
5892
|
const leafPackageJson = isFile(leafPackageJsonPath) ? readPackageJson$1(leafPackageJsonPath) : null;
|
|
5846
5893
|
const leafReactDeclaration = leafPackageJson ? getDependencyDeclaration({
|
|
5847
5894
|
packageJson: leafPackageJson,
|
|
@@ -5895,7 +5942,7 @@ const findInWorkspacePackageJsons = (rootDirectory, rootPackageJson, select) =>
|
|
|
5895
5942
|
for (const workspaceDirectory of directories) {
|
|
5896
5943
|
if (visitedDirectories.has(workspaceDirectory)) continue;
|
|
5897
5944
|
visitedDirectories.add(workspaceDirectory);
|
|
5898
|
-
const value = select(readPackageJson$1(path.join(workspaceDirectory, "package.json")));
|
|
5945
|
+
const value = select(readPackageJson$1(path$1.join(workspaceDirectory, "package.json")));
|
|
5899
5946
|
if (value !== null) return value;
|
|
5900
5947
|
}
|
|
5901
5948
|
}
|
|
@@ -5940,6 +5987,23 @@ const getExpoDependencySpec = (packageJson) => {
|
|
|
5940
5987
|
return typeof spec === "string" ? spec : null;
|
|
5941
5988
|
};
|
|
5942
5989
|
const findExpoVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getExpoDependencySpec);
|
|
5990
|
+
const SHOPIFY_FLASH_LIST_PACKAGE_NAME = "@shopify/flash-list";
|
|
5991
|
+
const getShopifyFlashListDependencySpec = (packageJson) => {
|
|
5992
|
+
const spec = packageJson.dependencies?.["@shopify/flash-list"] ?? packageJson.devDependencies?.["@shopify/flash-list"] ?? packageJson.peerDependencies?.["@shopify/flash-list"] ?? packageJson.optionalDependencies?.["@shopify/flash-list"];
|
|
5993
|
+
return typeof spec === "string" ? spec : null;
|
|
5994
|
+
};
|
|
5995
|
+
const findShopifyFlashListVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getShopifyFlashListDependencySpec);
|
|
5996
|
+
const resolveCatalogBackedDependencyVersion = ({ rootDirectory, rootPackageJson, packageName, version }) => {
|
|
5997
|
+
if (version === null || !isCatalogReference(version)) return version;
|
|
5998
|
+
const catalogName = extractCatalogName(version);
|
|
5999
|
+
const resolvedLocalVersion = resolveCatalogVersion(rootPackageJson, packageName, rootDirectory, catalogName);
|
|
6000
|
+
if (resolvedLocalVersion) return resolvedLocalVersion;
|
|
6001
|
+
const monorepoRoot = findMonorepoRoot(rootDirectory);
|
|
6002
|
+
if (!monorepoRoot) return version;
|
|
6003
|
+
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
6004
|
+
if (!isFile(monorepoPackageJsonPath)) return version;
|
|
6005
|
+
return resolveCatalogVersion(readPackageJson$1(monorepoPackageJsonPath), packageName, monorepoRoot, catalogName) ?? version;
|
|
6006
|
+
};
|
|
5943
6007
|
const getPreactVersion = (packageJson) => {
|
|
5944
6008
|
return {
|
|
5945
6009
|
...packageJson.peerDependencies,
|
|
@@ -6010,7 +6074,7 @@ const hasReactDependency = (packageJson) => {
|
|
|
6010
6074
|
return Object.keys(allDependencies).some((packageName) => REACT_DEPENDENCY_NAMES.has(packageName));
|
|
6011
6075
|
};
|
|
6012
6076
|
const listWorkspacePackages = (rootDirectory) => {
|
|
6013
|
-
const packageJsonPath = path.join(rootDirectory, "package.json");
|
|
6077
|
+
const packageJsonPath = path$1.join(rootDirectory, "package.json");
|
|
6014
6078
|
if (!isFile(packageJsonPath)) return [];
|
|
6015
6079
|
const packageJson = readPackageJson$1(packageJsonPath);
|
|
6016
6080
|
const patterns = getWorkspacePatterns(rootDirectory, packageJson);
|
|
@@ -6023,16 +6087,16 @@ const listWorkspacePackages = (rootDirectory) => {
|
|
|
6023
6087
|
packages.push(workspacePackage);
|
|
6024
6088
|
};
|
|
6025
6089
|
if (hasReactDependency(packageJson)) pushIfNew({
|
|
6026
|
-
name: packageJson.name ?? path.basename(rootDirectory),
|
|
6090
|
+
name: packageJson.name ?? path$1.basename(rootDirectory),
|
|
6027
6091
|
directory: rootDirectory
|
|
6028
6092
|
});
|
|
6029
6093
|
for (const pattern of patterns) {
|
|
6030
6094
|
const directories = resolveWorkspaceDirectories(rootDirectory, pattern);
|
|
6031
6095
|
for (const workspaceDirectory of directories) {
|
|
6032
|
-
const workspacePackageJson = readPackageJson$1(path.join(workspaceDirectory, "package.json"));
|
|
6096
|
+
const workspacePackageJson = readPackageJson$1(path$1.join(workspaceDirectory, "package.json"));
|
|
6033
6097
|
if (!hasReactDependency(workspacePackageJson)) continue;
|
|
6034
6098
|
pushIfNew({
|
|
6035
|
-
name: workspacePackageJson.name ?? path.basename(workspaceDirectory),
|
|
6099
|
+
name: workspacePackageJson.name ?? path$1.basename(workspaceDirectory),
|
|
6036
6100
|
directory: workspaceDirectory
|
|
6037
6101
|
});
|
|
6038
6102
|
}
|
|
@@ -6042,11 +6106,11 @@ const listWorkspacePackages = (rootDirectory) => {
|
|
|
6042
6106
|
const toReactWorkspacePackages = (directories) => {
|
|
6043
6107
|
const packages = [];
|
|
6044
6108
|
for (const directory of directories) {
|
|
6045
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
6109
|
+
const packageJsonPath = path$1.join(directory, "package.json");
|
|
6046
6110
|
if (!isFile(packageJsonPath)) continue;
|
|
6047
6111
|
const packageJson = readPackageJson$1(packageJsonPath);
|
|
6048
6112
|
if (!hasReactDependency(packageJson)) continue;
|
|
6049
|
-
const name = packageJson.name ?? path.basename(directory);
|
|
6113
|
+
const name = packageJson.name ?? path$1.basename(directory);
|
|
6050
6114
|
packages.push({
|
|
6051
6115
|
name,
|
|
6052
6116
|
directory
|
|
@@ -6055,7 +6119,7 @@ const toReactWorkspacePackages = (directories) => {
|
|
|
6055
6119
|
return packages;
|
|
6056
6120
|
};
|
|
6057
6121
|
const listManifestWorkspacePackages = (rootDirectory) => {
|
|
6058
|
-
if (isFile(path.join(rootDirectory, "package.json"))) return listWorkspacePackages(rootDirectory);
|
|
6122
|
+
if (isFile(path$1.join(rootDirectory, "package.json"))) return listWorkspacePackages(rootDirectory);
|
|
6059
6123
|
const patterns = parsePnpmWorkspacePatterns(rootDirectory);
|
|
6060
6124
|
const nxPatterns = patterns.length > 0 ? [] : getNxWorkspaceDirectories(rootDirectory);
|
|
6061
6125
|
return toReactWorkspacePackages((patterns.length > 0 ? patterns : nxPatterns).flatMap((pattern) => resolveWorkspaceDirectories(rootDirectory, pattern)));
|
|
@@ -6076,11 +6140,11 @@ const discoverReactSubprojectsByFilesystem = (rootDirectory) => {
|
|
|
6076
6140
|
const current = pendingDirectories.pop();
|
|
6077
6141
|
if (!current) continue;
|
|
6078
6142
|
const { directory: currentDirectory, depth } = current;
|
|
6079
|
-
const packageJsonPath = path.join(currentDirectory, "package.json");
|
|
6143
|
+
const packageJsonPath = path$1.join(currentDirectory, "package.json");
|
|
6080
6144
|
if (isFile(packageJsonPath)) {
|
|
6081
6145
|
const packageJson = readPackageJson$1(packageJsonPath);
|
|
6082
6146
|
if (hasReactDependency(packageJson)) {
|
|
6083
|
-
const name = packageJson.name ?? path.basename(currentDirectory);
|
|
6147
|
+
const name = packageJson.name ?? path$1.basename(currentDirectory);
|
|
6084
6148
|
packages.push({
|
|
6085
6149
|
name,
|
|
6086
6150
|
directory: currentDirectory
|
|
@@ -6092,7 +6156,7 @@ const discoverReactSubprojectsByFilesystem = (rootDirectory) => {
|
|
|
6092
6156
|
for (const entry of entries) {
|
|
6093
6157
|
if (!entry.isDirectory() || entry.name.startsWith(".") || IGNORED_DIRECTORIES.has(entry.name) || NON_PROJECT_DIRECTORIES.has(entry.name)) continue;
|
|
6094
6158
|
pendingDirectories.push({
|
|
6095
|
-
directory: path.join(currentDirectory, entry.name),
|
|
6159
|
+
directory: path$1.join(currentDirectory, entry.name),
|
|
6096
6160
|
depth: depth + 1
|
|
6097
6161
|
});
|
|
6098
6162
|
}
|
|
@@ -6109,7 +6173,7 @@ const cachedProjectInfos = /* @__PURE__ */ new Map();
|
|
|
6109
6173
|
const discoverProject = (directory) => {
|
|
6110
6174
|
const cached = cachedProjectInfos.get(directory);
|
|
6111
6175
|
if (cached !== void 0) return cached;
|
|
6112
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
6176
|
+
const packageJsonPath = path$1.join(directory, "package.json");
|
|
6113
6177
|
if (!isFile(packageJsonPath)) throw new PackageJsonNotFoundError(directory);
|
|
6114
6178
|
const packageJson = readPackageJson$1(packageJsonPath);
|
|
6115
6179
|
let { reactVersion, tailwindVersion, zodVersion, framework } = extractDependencyInfo(packageJson);
|
|
@@ -6146,7 +6210,7 @@ const discoverProject = (directory) => {
|
|
|
6146
6210
|
if (!reactVersion || !tailwindVersion || !zodVersion) {
|
|
6147
6211
|
const monorepoRoot = findMonorepoRoot(directory);
|
|
6148
6212
|
if (monorepoRoot) {
|
|
6149
|
-
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
6213
|
+
const monorepoPackageJsonPath = path$1.join(monorepoRoot, "package.json");
|
|
6150
6214
|
if (isFile(monorepoPackageJsonPath)) {
|
|
6151
6215
|
const rootPackageJson = readPackageJson$1(monorepoPackageJsonPath);
|
|
6152
6216
|
if (!reactVersion && reactDeclaration.hasDeclaration) reactVersion = resolveCatalogVersion(rootPackageJson, "react", monorepoRoot, reactDeclaration.catalogReference);
|
|
@@ -6172,23 +6236,22 @@ const discoverProject = (directory) => {
|
|
|
6172
6236
|
if (!reactVersion && reactDeclaration.version && !isCatalogReference(reactDeclaration.version)) reactVersion = reactDeclaration.version;
|
|
6173
6237
|
if (!tailwindVersion && tailwindDeclaration.version && !isCatalogReference(tailwindDeclaration.version)) tailwindVersion = tailwindDeclaration.version;
|
|
6174
6238
|
if (!zodVersion && zodDeclaration.version && !isCatalogReference(zodDeclaration.version)) zodVersion = zodDeclaration.version;
|
|
6175
|
-
const projectName = packageJson.name ?? path.basename(directory);
|
|
6176
|
-
const hasTypeScript = fs.existsSync(path.join(directory, "tsconfig.json"));
|
|
6239
|
+
const projectName = packageJson.name ?? path$1.basename(directory);
|
|
6240
|
+
const hasTypeScript = fs$1.existsSync(path$1.join(directory, "tsconfig.json"));
|
|
6177
6241
|
const sourceFileCount = countSourceFiles(directory);
|
|
6178
6242
|
const hasReactNativeWorkspace = framework === "expo" || framework === "react-native" || hasReactNativeWorkspaceAnywhere(directory, packageJson);
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
}
|
|
6243
|
+
const expoVersion = hasReactNativeWorkspace ? resolveCatalogBackedDependencyVersion({
|
|
6244
|
+
rootDirectory: directory,
|
|
6245
|
+
rootPackageJson: packageJson,
|
|
6246
|
+
packageName: "expo",
|
|
6247
|
+
version: findExpoVersion(directory, packageJson)
|
|
6248
|
+
}) : null;
|
|
6249
|
+
const shopifyFlashListVersion = hasReactNativeWorkspace ? resolveCatalogBackedDependencyVersion({
|
|
6250
|
+
rootDirectory: directory,
|
|
6251
|
+
rootPackageJson: packageJson,
|
|
6252
|
+
packageName: SHOPIFY_FLASH_LIST_PACKAGE_NAME,
|
|
6253
|
+
version: findShopifyFlashListVersion(directory, packageJson)
|
|
6254
|
+
}) : null;
|
|
6192
6255
|
const hasReanimated = hasReactNativeWorkspace && someWorkspacePackageJson(directory, packageJson, isPackageJsonReanimatedAware);
|
|
6193
6256
|
const preactVersion = getPreactVersion(packageJson);
|
|
6194
6257
|
const projectInfo = {
|
|
@@ -6207,6 +6270,8 @@ const discoverProject = (directory) => {
|
|
|
6207
6270
|
preactMajorVersion: parseReactMajor(preactVersion),
|
|
6208
6271
|
hasReactNativeWorkspace,
|
|
6209
6272
|
expoVersion,
|
|
6273
|
+
shopifyFlashListVersion,
|
|
6274
|
+
shopifyFlashListMajorVersion: shopifyFlashListVersion === null ? null : getLowestDependencyMajor(shopifyFlashListVersion),
|
|
6210
6275
|
hasReanimated,
|
|
6211
6276
|
sourceFileCount
|
|
6212
6277
|
};
|
|
@@ -6282,6 +6347,7 @@ const MILLISECONDS_PER_SECOND = 1e3;
|
|
|
6282
6347
|
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
6283
6348
|
const ENTERPRISE_CONTACT_URL = "https://react.doctor/enterprise";
|
|
6284
6349
|
const SHARE_BASE_URL = "https://react.doctor/share";
|
|
6350
|
+
const CI_URL = "https://react.doctor/ci";
|
|
6285
6351
|
const DOCS_URL = "https://react.doctor/docs";
|
|
6286
6352
|
const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
|
|
6287
6353
|
const FETCH_TIMEOUT_MS = 1e4;
|
|
@@ -6822,12 +6888,12 @@ const findNearestPackageDirectory$1 = (filename) => {
|
|
|
6822
6888
|
if (!filename) return null;
|
|
6823
6889
|
const fromCache = cachedPackageDirectoryByFilename.get(filename);
|
|
6824
6890
|
if (fromCache !== void 0) return fromCache;
|
|
6825
|
-
let currentDirectory = path.dirname(filename);
|
|
6891
|
+
let currentDirectory = path$1.dirname(filename);
|
|
6826
6892
|
while (true) {
|
|
6827
|
-
const candidatePackageJsonPath = path.join(currentDirectory, "package.json");
|
|
6893
|
+
const candidatePackageJsonPath = path$1.join(currentDirectory, "package.json");
|
|
6828
6894
|
let hasPackageJson = false;
|
|
6829
6895
|
try {
|
|
6830
|
-
hasPackageJson = fs.statSync(candidatePackageJsonPath).isFile();
|
|
6896
|
+
hasPackageJson = fs$1.statSync(candidatePackageJsonPath).isFile();
|
|
6831
6897
|
} catch {
|
|
6832
6898
|
hasPackageJson = false;
|
|
6833
6899
|
}
|
|
@@ -6835,7 +6901,7 @@ const findNearestPackageDirectory$1 = (filename) => {
|
|
|
6835
6901
|
cachedPackageDirectoryByFilename.set(filename, currentDirectory);
|
|
6836
6902
|
return currentDirectory;
|
|
6837
6903
|
}
|
|
6838
|
-
const parentDirectory = path.dirname(currentDirectory);
|
|
6904
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
6839
6905
|
if (parentDirectory === currentDirectory) {
|
|
6840
6906
|
cachedPackageDirectoryByFilename.set(filename, null);
|
|
6841
6907
|
return null;
|
|
@@ -6845,7 +6911,7 @@ const findNearestPackageDirectory$1 = (filename) => {
|
|
|
6845
6911
|
};
|
|
6846
6912
|
const readManifest = (packageJsonPath) => {
|
|
6847
6913
|
try {
|
|
6848
|
-
const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
6914
|
+
const parsed = JSON.parse(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
6849
6915
|
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
6850
6916
|
return null;
|
|
6851
6917
|
} catch {
|
|
@@ -6856,8 +6922,8 @@ const hasPublishContract = (manifest) => typeof manifest.name === "string" && ma
|
|
|
6856
6922
|
const classifyByDirectoryCohort = (packageDirectory) => {
|
|
6857
6923
|
let current = packageDirectory;
|
|
6858
6924
|
while (true) {
|
|
6859
|
-
if (path.basename(current) === "apps") return "app";
|
|
6860
|
-
const parent = path.dirname(current);
|
|
6925
|
+
if (path$1.basename(current) === "apps") return "app";
|
|
6926
|
+
const parent = path$1.dirname(current);
|
|
6861
6927
|
if (parent === current) return null;
|
|
6862
6928
|
current = parent;
|
|
6863
6929
|
}
|
|
@@ -6868,10 +6934,10 @@ const classifyPackageRole = (filename) => {
|
|
|
6868
6934
|
if (!packageDirectory) return "unknown";
|
|
6869
6935
|
const cached = cachedRoleByPackageDirectory.get(packageDirectory);
|
|
6870
6936
|
if (cached !== void 0) return cached;
|
|
6871
|
-
const manifest = readManifest(path.join(packageDirectory, "package.json"));
|
|
6937
|
+
const manifest = readManifest(path$1.join(packageDirectory, "package.json"));
|
|
6872
6938
|
let result;
|
|
6873
6939
|
if (manifest && hasPublishContract(manifest)) result = "library";
|
|
6874
|
-
else result = classifyByDirectoryCohort(path.dirname(packageDirectory)) ?? "unknown";
|
|
6940
|
+
else result = classifyByDirectoryCohort(path$1.dirname(packageDirectory)) ?? "unknown";
|
|
6875
6941
|
cachedRoleByPackageDirectory.set(packageDirectory, result);
|
|
6876
6942
|
return result;
|
|
6877
6943
|
};
|
|
@@ -7523,12 +7589,12 @@ const loadModuleConfig = async (filePath) => {
|
|
|
7523
7589
|
const imported = await jiti.import(filePath);
|
|
7524
7590
|
return imported?.default ?? imported;
|
|
7525
7591
|
};
|
|
7526
|
-
const readDataConfig = (filePath) => parseJSON5(fs.readFileSync(filePath, "utf-8"));
|
|
7592
|
+
const readDataConfig = (filePath) => parseJSON5(fs$1.readFileSync(filePath, "utf-8"));
|
|
7527
7593
|
const readEmbeddedPackageJsonConfig = (directory) => {
|
|
7528
|
-
const packageJsonPath = path.join(directory, PACKAGE_JSON_FILENAME);
|
|
7594
|
+
const packageJsonPath = path$1.join(directory, PACKAGE_JSON_FILENAME);
|
|
7529
7595
|
if (!isFile(packageJsonPath)) return null;
|
|
7530
7596
|
try {
|
|
7531
|
-
const packageJson = parseJSON5(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
7597
|
+
const packageJson = parseJSON5(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
7532
7598
|
if (isPlainObject(packageJson)) {
|
|
7533
7599
|
const embeddedConfig = packageJson[PACKAGE_JSON_CONFIG_KEY$1];
|
|
7534
7600
|
if (isPlainObject(embeddedConfig)) return embeddedConfig;
|
|
@@ -7542,14 +7608,14 @@ const loadPackageJsonConfig = (directory) => {
|
|
|
7542
7608
|
return {
|
|
7543
7609
|
config: validateConfigTypes(embeddedConfig),
|
|
7544
7610
|
sourceDirectory: directory,
|
|
7545
|
-
configFilePath: path.join(directory, PACKAGE_JSON_FILENAME),
|
|
7611
|
+
configFilePath: path$1.join(directory, PACKAGE_JSON_FILENAME),
|
|
7546
7612
|
format: "package-json"
|
|
7547
7613
|
};
|
|
7548
7614
|
};
|
|
7549
7615
|
const loadConfigFromDirectory = async (directory) => {
|
|
7550
7616
|
let sawBrokenConfigFile = false;
|
|
7551
7617
|
for (const extension of CONFIG_EXTENSIONS) {
|
|
7552
|
-
const filePath = path.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
7618
|
+
const filePath = path$1.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
7553
7619
|
if (!isFile(filePath)) continue;
|
|
7554
7620
|
const isDataFile = DATA_CONFIG_EXTENSIONS.has(extension);
|
|
7555
7621
|
try {
|
|
@@ -7575,7 +7641,7 @@ const loadConfigFromDirectory = async (directory) => {
|
|
|
7575
7641
|
status: "found",
|
|
7576
7642
|
loaded: packageJsonConfig
|
|
7577
7643
|
};
|
|
7578
|
-
if (isFile(path.join(directory, LEGACY_CONFIG_FILENAME))) warn(`${LEGACY_CONFIG_FILENAME} is no longer read — rename it to ${CONFIG_BASENAME}.json (or author a ${CONFIG_BASENAME}.ts).`);
|
|
7644
|
+
if (isFile(path$1.join(directory, LEGACY_CONFIG_FILENAME))) warn(`${LEGACY_CONFIG_FILENAME} is no longer read — rename it to ${CONFIG_BASENAME}.json (or author a ${CONFIG_BASENAME}.ts).`);
|
|
7579
7645
|
return {
|
|
7580
7646
|
status: sawBrokenConfigFile ? "invalid" : "absent",
|
|
7581
7647
|
loaded: null
|
|
@@ -7589,12 +7655,12 @@ const loadConfigWalkingUp = async (rootDirectory) => {
|
|
|
7589
7655
|
const localResult = await loadConfigFromDirectory(rootDirectory);
|
|
7590
7656
|
if (localResult.status === "found") return localResult.loaded;
|
|
7591
7657
|
if (localResult.status === "invalid" || isProjectBoundary(rootDirectory)) return null;
|
|
7592
|
-
let ancestorDirectory = path.dirname(rootDirectory);
|
|
7593
|
-
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
7658
|
+
let ancestorDirectory = path$1.dirname(rootDirectory);
|
|
7659
|
+
while (ancestorDirectory !== path$1.dirname(ancestorDirectory)) {
|
|
7594
7660
|
const ancestorResult = await loadConfigFromDirectory(ancestorDirectory);
|
|
7595
7661
|
if (ancestorResult.status === "found") return ancestorResult.loaded;
|
|
7596
7662
|
if (isProjectBoundary(ancestorDirectory)) return null;
|
|
7597
|
-
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
7663
|
+
ancestorDirectory = path$1.dirname(ancestorDirectory);
|
|
7598
7664
|
}
|
|
7599
7665
|
return null;
|
|
7600
7666
|
};
|
|
@@ -7606,7 +7672,7 @@ const loadConfigWithSource = (rootDirectory) => {
|
|
|
7606
7672
|
return loadPromise;
|
|
7607
7673
|
};
|
|
7608
7674
|
const directoryHasCurrentConfig = (directory) => {
|
|
7609
|
-
for (const extension of CONFIG_EXTENSIONS) if (isFile(path.join(directory, `${CONFIG_BASENAME}.${extension}`))) return true;
|
|
7675
|
+
for (const extension of CONFIG_EXTENSIONS) if (isFile(path$1.join(directory, `${CONFIG_BASENAME}.${extension}`))) return true;
|
|
7610
7676
|
return readEmbeddedPackageJsonConfig(directory) !== null;
|
|
7611
7677
|
};
|
|
7612
7678
|
/**
|
|
@@ -7620,13 +7686,13 @@ const findLegacyConfig = (rootDirectory) => {
|
|
|
7620
7686
|
let directory = rootDirectory;
|
|
7621
7687
|
while (true) {
|
|
7622
7688
|
if (directoryHasCurrentConfig(directory)) return null;
|
|
7623
|
-
const legacyFilePath = path.join(directory, LEGACY_CONFIG_FILENAME);
|
|
7689
|
+
const legacyFilePath = path$1.join(directory, LEGACY_CONFIG_FILENAME);
|
|
7624
7690
|
if (isFile(legacyFilePath)) return {
|
|
7625
7691
|
legacyFilePath,
|
|
7626
7692
|
directory
|
|
7627
7693
|
};
|
|
7628
7694
|
if (isProjectBoundary(directory)) return null;
|
|
7629
|
-
const parentDirectory = path.dirname(directory);
|
|
7695
|
+
const parentDirectory = path$1.dirname(directory);
|
|
7630
7696
|
if (parentDirectory === directory) return null;
|
|
7631
7697
|
directory = parentDirectory;
|
|
7632
7698
|
}
|
|
@@ -7637,7 +7703,7 @@ const resolveConfigRootDir = (config, configSourceDirectory) => {
|
|
|
7637
7703
|
if (typeof rawRootDir !== "string") return null;
|
|
7638
7704
|
const trimmedRootDir = rawRootDir.trim();
|
|
7639
7705
|
if (trimmedRootDir.length === 0) return null;
|
|
7640
|
-
const resolvedRootDir = path.isAbsolute(trimmedRootDir) ? trimmedRootDir : path.resolve(configSourceDirectory, trimmedRootDir);
|
|
7706
|
+
const resolvedRootDir = path$1.isAbsolute(trimmedRootDir) ? trimmedRootDir : path$1.resolve(configSourceDirectory, trimmedRootDir);
|
|
7641
7707
|
if (resolvedRootDir === configSourceDirectory) return null;
|
|
7642
7708
|
if (!isDirectory(resolvedRootDir)) {
|
|
7643
7709
|
Effect.runSync(Console.warn(`react-doctor config "rootDir" points to "${rawRootDir}" (resolved to ${resolvedRootDir}), which is not a directory. Ignoring.`));
|
|
@@ -7646,12 +7712,12 @@ const resolveConfigRootDir = (config, configSourceDirectory) => {
|
|
|
7646
7712
|
return resolvedRootDir;
|
|
7647
7713
|
};
|
|
7648
7714
|
const resolveDiagnoseTarget = (directory, options = {}) => {
|
|
7649
|
-
if (isFile(path.join(directory, "package.json"))) return directory;
|
|
7715
|
+
if (isFile(path$1.join(directory, "package.json"))) return directory;
|
|
7650
7716
|
const reactSubprojects = discoverReactSubprojects(directory);
|
|
7651
7717
|
if (reactSubprojects.length === 0) return null;
|
|
7652
7718
|
if (reactSubprojects.length === 1) return reactSubprojects[0].directory;
|
|
7653
7719
|
if (options.allowAmbiguous === true) return null;
|
|
7654
|
-
throw new AmbiguousProjectError(directory, reactSubprojects.map((subproject) => path.relative(directory, subproject.directory)).toSorted());
|
|
7720
|
+
throw new AmbiguousProjectError(directory, reactSubprojects.map((subproject) => path$1.relative(directory, subproject.directory)).toSorted());
|
|
7655
7721
|
};
|
|
7656
7722
|
/**
|
|
7657
7723
|
* The canonical entry-point translation shared by every public shell
|
|
@@ -7677,14 +7743,14 @@ const resolveDiagnoseTarget = (directory, options = {}) => {
|
|
|
7677
7743
|
* shell in agreement on what "the scan directory" means.
|
|
7678
7744
|
*/
|
|
7679
7745
|
const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
7680
|
-
const absoluteRequested = path.resolve(requestedDirectory);
|
|
7746
|
+
const absoluteRequested = path$1.resolve(requestedDirectory);
|
|
7681
7747
|
const loadedConfig = await loadConfigWithSource(absoluteRequested);
|
|
7682
7748
|
const userConfig = loadedConfig?.config ?? null;
|
|
7683
7749
|
const configSourceDirectory = loadedConfig?.sourceDirectory ?? null;
|
|
7684
7750
|
const redirectedDirectory = resolveConfigRootDir(userConfig, configSourceDirectory);
|
|
7685
7751
|
const directoryAfterRedirect = redirectedDirectory ?? absoluteRequested;
|
|
7686
7752
|
const resolvedDirectory = resolveDiagnoseTarget(directoryAfterRedirect, options) ?? directoryAfterRedirect;
|
|
7687
|
-
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory, { kind: "missing-path" });
|
|
7753
|
+
if (!isDirectory(resolvedDirectory)) throw fs$1.existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory, { kind: "missing-path" });
|
|
7688
7754
|
return {
|
|
7689
7755
|
resolvedDirectory,
|
|
7690
7756
|
requestedDirectory: absoluteRequested,
|
|
@@ -7695,7 +7761,7 @@ const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
|
7695
7761
|
};
|
|
7696
7762
|
const getDirectDependencyNames = (packageJson) => new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.devDependencies ?? {})]);
|
|
7697
7763
|
const buildExpoCheckContext = (rootDirectory, expoVersion) => {
|
|
7698
|
-
const packageJson = readPackageJson$1(path.join(rootDirectory, "package.json"));
|
|
7764
|
+
const packageJson = readPackageJson$1(path$1.join(rootDirectory, "package.json"));
|
|
7699
7765
|
return {
|
|
7700
7766
|
rootDirectory,
|
|
7701
7767
|
packageJson,
|
|
@@ -7765,7 +7831,7 @@ const LOCAL_ENV_FILE_NAMES = [
|
|
|
7765
7831
|
const checkExpoEnvLocalFiles = (context) => {
|
|
7766
7832
|
const { rootDirectory } = context;
|
|
7767
7833
|
const committedEnvFiles = LOCAL_ENV_FILE_NAMES.filter((fileName) => {
|
|
7768
|
-
const filePath = path.join(rootDirectory, fileName);
|
|
7834
|
+
const filePath = path$1.join(rootDirectory, fileName);
|
|
7769
7835
|
if (!isFile(filePath)) return false;
|
|
7770
7836
|
return isPathGitIgnored(rootDirectory, filePath) === false;
|
|
7771
7837
|
});
|
|
@@ -7899,17 +7965,17 @@ const checkExpoFlaggedDependencies = (context) => FLAGGED_DEPENDENCIES.filter((f
|
|
|
7899
7965
|
help: flaggedDependency.help
|
|
7900
7966
|
}));
|
|
7901
7967
|
const findLocalModuleNativeFiles = (rootDirectory) => {
|
|
7902
|
-
const modulesDirectory = path.join(rootDirectory, "modules");
|
|
7968
|
+
const modulesDirectory = path$1.join(rootDirectory, "modules");
|
|
7903
7969
|
if (!isDirectory(modulesDirectory)) return [];
|
|
7904
7970
|
const nativeFilePaths = [];
|
|
7905
7971
|
for (const moduleEntry of readDirectoryEntries(modulesDirectory)) {
|
|
7906
7972
|
if (!moduleEntry.isDirectory()) continue;
|
|
7907
|
-
const moduleDirectory = path.join(modulesDirectory, moduleEntry.name);
|
|
7908
|
-
const gradlePath = path.join(moduleDirectory, "android", "build.gradle");
|
|
7973
|
+
const moduleDirectory = path$1.join(modulesDirectory, moduleEntry.name);
|
|
7974
|
+
const gradlePath = path$1.join(moduleDirectory, "android", "build.gradle");
|
|
7909
7975
|
if (isFile(gradlePath)) nativeFilePaths.push(gradlePath);
|
|
7910
|
-
const iosDirectory = path.join(moduleDirectory, "ios");
|
|
7976
|
+
const iosDirectory = path$1.join(moduleDirectory, "ios");
|
|
7911
7977
|
if (isDirectory(iosDirectory)) {
|
|
7912
|
-
for (const iosEntry of readDirectoryEntries(iosDirectory)) if (iosEntry.isFile() && iosEntry.name.endsWith(".podspec")) nativeFilePaths.push(path.join(iosDirectory, iosEntry.name));
|
|
7978
|
+
for (const iosEntry of readDirectoryEntries(iosDirectory)) if (iosEntry.isFile() && iosEntry.name.endsWith(".podspec")) nativeFilePaths.push(path$1.join(iosDirectory, iosEntry.name));
|
|
7913
7979
|
}
|
|
7914
7980
|
}
|
|
7915
7981
|
return nativeFilePaths;
|
|
@@ -7917,7 +7983,7 @@ const findLocalModuleNativeFiles = (rootDirectory) => {
|
|
|
7917
7983
|
const checkExpoGitignore = (context) => {
|
|
7918
7984
|
const { rootDirectory } = context;
|
|
7919
7985
|
const diagnostics = [];
|
|
7920
|
-
const expoStateDirectory = path.join(rootDirectory, ".expo");
|
|
7986
|
+
const expoStateDirectory = path$1.join(rootDirectory, ".expo");
|
|
7921
7987
|
if (isDirectory(expoStateDirectory) && isPathGitIgnored(rootDirectory, expoStateDirectory) === false) diagnostics.push(buildExpoDiagnostic({
|
|
7922
7988
|
rule: "expo-gitignore",
|
|
7923
7989
|
message: "The `.expo` directory is not ignored by Git — it holds machine-specific device history and dev-server settings that should not be committed",
|
|
@@ -7939,7 +8005,7 @@ const LOCKFILE_NAMES = [
|
|
|
7939
8005
|
];
|
|
7940
8006
|
const checkExpoLockfile = (context) => {
|
|
7941
8007
|
const workspaceRoot = isMonorepoRoot(context.rootDirectory) ? context.rootDirectory : findMonorepoRoot(context.rootDirectory) ?? context.rootDirectory;
|
|
7942
|
-
const presentLockfiles = LOCKFILE_NAMES.filter((lockfileName) => isFile(path.join(workspaceRoot, lockfileName)));
|
|
8008
|
+
const presentLockfiles = LOCKFILE_NAMES.filter((lockfileName) => isFile(path$1.join(workspaceRoot, lockfileName)));
|
|
7943
8009
|
if (presentLockfiles.length === 0) return [buildExpoDiagnostic({
|
|
7944
8010
|
rule: "expo-lockfile",
|
|
7945
8011
|
message: "No lock file detected at the project root — installs are not reproducible, and EAS Build cannot infer your package manager",
|
|
@@ -7964,18 +8030,18 @@ const EXPO_METRO_CONFIG_EXTEND_SIGNALS = [
|
|
|
7964
8030
|
"getSentryExpoConfig"
|
|
7965
8031
|
];
|
|
7966
8032
|
const checkExpoMetroConfig = (context) => {
|
|
7967
|
-
const metroConfigPath = METRO_CONFIG_FILE_NAMES.map((fileName) => path.join(context.rootDirectory, fileName)).find((candidatePath) => isFile(candidatePath));
|
|
8033
|
+
const metroConfigPath = METRO_CONFIG_FILE_NAMES.map((fileName) => path$1.join(context.rootDirectory, fileName)).find((candidatePath) => isFile(candidatePath));
|
|
7968
8034
|
if (metroConfigPath === void 0) return [];
|
|
7969
8035
|
let contents;
|
|
7970
8036
|
try {
|
|
7971
|
-
contents = fs.readFileSync(metroConfigPath, "utf-8");
|
|
8037
|
+
contents = fs$1.readFileSync(metroConfigPath, "utf-8");
|
|
7972
8038
|
} catch {
|
|
7973
8039
|
return [];
|
|
7974
8040
|
}
|
|
7975
8041
|
if (EXPO_METRO_CONFIG_EXTEND_SIGNALS.some((signal) => contents.includes(signal))) return [];
|
|
7976
8042
|
return [buildExpoDiagnostic({
|
|
7977
8043
|
rule: "expo-metro-config",
|
|
7978
|
-
filePath: path.basename(metroConfigPath),
|
|
8044
|
+
filePath: path$1.basename(metroConfigPath),
|
|
7979
8045
|
message: "Your metro.config does not extend `expo/metro-config` — a custom Metro config that doesn't extend Expo's leads to unexpected, hard-to-debug bundling issues",
|
|
7980
8046
|
help: "Update your metro config to extend `expo/metro-config`. See https://docs.expo.dev/guides/customizing-metro/"
|
|
7981
8047
|
})];
|
|
@@ -8021,16 +8087,16 @@ const NO_CONFIG = {
|
|
|
8021
8087
|
const decodeExpoConfig = (filePath) => {
|
|
8022
8088
|
let raw;
|
|
8023
8089
|
try {
|
|
8024
|
-
raw = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
8090
|
+
raw = JSON.parse(fs$1.readFileSync(filePath, "utf-8"));
|
|
8025
8091
|
} catch {
|
|
8026
8092
|
return null;
|
|
8027
8093
|
}
|
|
8028
8094
|
return Option.getOrNull(Schema.decodeUnknownOption(AppManifestSchema)(raw))?.expo ?? null;
|
|
8029
8095
|
};
|
|
8030
8096
|
const readExpoAppConfig = (rootDirectory) => {
|
|
8031
|
-
if (APP_CONFIG_DYNAMIC_FILES.some((fileName) => isFile(path.join(rootDirectory, fileName)))) return NO_CONFIG;
|
|
8097
|
+
if (APP_CONFIG_DYNAMIC_FILES.some((fileName) => isFile(path$1.join(rootDirectory, fileName)))) return NO_CONFIG;
|
|
8032
8098
|
for (const fileName of APP_CONFIG_JSON_FILES) {
|
|
8033
|
-
const filePath = path.join(rootDirectory, fileName);
|
|
8099
|
+
const filePath = path$1.join(rootDirectory, fileName);
|
|
8034
8100
|
if (!isFile(filePath)) continue;
|
|
8035
8101
|
const config = decodeExpoConfig(filePath);
|
|
8036
8102
|
if (config) return {
|
|
@@ -8177,12 +8243,12 @@ const parseHardeningSettings = (content) => {
|
|
|
8177
8243
|
};
|
|
8178
8244
|
};
|
|
8179
8245
|
const isPnpmManagedProject = (rootDirectory) => {
|
|
8180
|
-
if (isFile(path.join(rootDirectory, PNPM_LOCKFILE))) return true;
|
|
8181
|
-
if (isFile(path.join(rootDirectory, PNPM_WORKSPACE_FILE))) return true;
|
|
8182
|
-
const packageJsonPath = path.join(rootDirectory, PACKAGE_JSON_FILE);
|
|
8246
|
+
if (isFile(path$1.join(rootDirectory, PNPM_LOCKFILE))) return true;
|
|
8247
|
+
if (isFile(path$1.join(rootDirectory, PNPM_WORKSPACE_FILE))) return true;
|
|
8248
|
+
const packageJsonPath = path$1.join(rootDirectory, PACKAGE_JSON_FILE);
|
|
8183
8249
|
if (!isFile(packageJsonPath)) return false;
|
|
8184
8250
|
try {
|
|
8185
|
-
const packageJsonRaw = fs.readFileSync(packageJsonPath, "utf-8");
|
|
8251
|
+
const packageJsonRaw = fs$1.readFileSync(packageJsonPath, "utf-8");
|
|
8186
8252
|
const packageJson = JSON.parse(packageJsonRaw);
|
|
8187
8253
|
if (packageJson !== null && typeof packageJson === "object" && "packageManager" in packageJson && typeof packageJson.packageManager === "string" && packageJson.packageManager.startsWith("pnpm@")) return true;
|
|
8188
8254
|
} catch {
|
|
@@ -8203,8 +8269,8 @@ const buildHardeningDiagnostic = (input) => ({
|
|
|
8203
8269
|
});
|
|
8204
8270
|
const checkPnpmHardening = (rootDirectory) => {
|
|
8205
8271
|
if (!isPnpmManagedProject(rootDirectory)) return [];
|
|
8206
|
-
const workspacePath = path.join(rootDirectory, PNPM_WORKSPACE_FILE);
|
|
8207
|
-
const settings = parseHardeningSettings(isFile(workspacePath) ? fs.readFileSync(workspacePath, "utf-8") : "");
|
|
8272
|
+
const workspacePath = path$1.join(rootDirectory, PNPM_WORKSPACE_FILE);
|
|
8273
|
+
const settings = parseHardeningSettings(isFile(workspacePath) ? fs$1.readFileSync(workspacePath, "utf-8") : "");
|
|
8208
8274
|
const diagnostics = [];
|
|
8209
8275
|
if (settings.minimumReleaseAge === null) diagnostics.push(buildHardeningDiagnostic({
|
|
8210
8276
|
message: "pnpm-workspace.yaml is missing `minimumReleaseAge` — newly published versions can ship malware that gets caught and unpublished within hours",
|
|
@@ -8234,7 +8300,7 @@ const isBuilderBobLibrary = (packageJson) => {
|
|
|
8234
8300
|
return typeof bobConfig === "object" && bobConfig !== null;
|
|
8235
8301
|
};
|
|
8236
8302
|
const checkReactNativeLibraryDependencies = (rootDirectory) => {
|
|
8237
|
-
const packageJson = readPackageJson$1(path.join(rootDirectory, "package.json"));
|
|
8303
|
+
const packageJson = readPackageJson$1(path$1.join(rootDirectory, "package.json"));
|
|
8238
8304
|
if (!isBuilderBobLibrary(packageJson)) return [];
|
|
8239
8305
|
const misplaced = ["react", "react-native"].filter((name) => packageJson.dependencies?.[name] !== void 0);
|
|
8240
8306
|
if (misplaced.length === 0) return [];
|
|
@@ -8263,11 +8329,11 @@ const BABEL_CONFIG_FILE_NAMES = [
|
|
|
8263
8329
|
const LEGACY_PRESET_SPEC = "module:metro-react-native-babel-preset";
|
|
8264
8330
|
const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
8265
8331
|
for (const fileName of BABEL_CONFIG_FILE_NAMES) {
|
|
8266
|
-
const filePath = path.join(rootDirectory, fileName);
|
|
8332
|
+
const filePath = path$1.join(rootDirectory, fileName);
|
|
8267
8333
|
if (!isFile(filePath)) continue;
|
|
8268
8334
|
let contents;
|
|
8269
8335
|
try {
|
|
8270
|
-
contents = fs.readFileSync(filePath, "utf-8");
|
|
8336
|
+
contents = fs$1.readFileSync(filePath, "utf-8");
|
|
8271
8337
|
} catch {
|
|
8272
8338
|
continue;
|
|
8273
8339
|
}
|
|
@@ -8312,7 +8378,7 @@ const MISSING_REDUCED_MOTION_DIAGNOSTIC = {
|
|
|
8312
8378
|
category: "Accessibility"
|
|
8313
8379
|
};
|
|
8314
8380
|
const checkReducedMotion = (rootDirectory) => {
|
|
8315
|
-
const packageJsonPath = path.join(rootDirectory, "package.json");
|
|
8381
|
+
const packageJsonPath = path$1.join(rootDirectory, "package.json");
|
|
8316
8382
|
if (!isFile(packageJsonPath)) return [];
|
|
8317
8383
|
let hasMotionLibrary = false;
|
|
8318
8384
|
try {
|
|
@@ -8456,7 +8522,7 @@ const isTruthyLinguistAttribute = (token) => {
|
|
|
8456
8522
|
const parseGitattributesLinguistPaths = (filePath) => {
|
|
8457
8523
|
let content;
|
|
8458
8524
|
try {
|
|
8459
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
8525
|
+
content = fs$1.readFileSync(filePath, "utf-8");
|
|
8460
8526
|
} catch {
|
|
8461
8527
|
return [];
|
|
8462
8528
|
}
|
|
@@ -8478,7 +8544,7 @@ const stripGitignoreEscape = (pattern) => {
|
|
|
8478
8544
|
const readIgnoreFile = (filePath) => {
|
|
8479
8545
|
let content;
|
|
8480
8546
|
try {
|
|
8481
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
8547
|
+
content = fs$1.readFileSync(filePath, "utf-8");
|
|
8482
8548
|
} catch (error) {
|
|
8483
8549
|
const errnoCode = error?.code;
|
|
8484
8550
|
if (errnoCode && errnoCode !== "ENOENT") Effect.runSync(Console.warn(`Could not read ignore file ${filePath}: ${errnoCode}`));
|
|
@@ -8507,8 +8573,8 @@ const computeIgnorePatterns = (rootDirectory) => {
|
|
|
8507
8573
|
seen.add(pattern);
|
|
8508
8574
|
patterns.push(pattern);
|
|
8509
8575
|
};
|
|
8510
|
-
for (const filename of IGNORE_FILENAMES) for (const pattern of readIgnoreFile(path.join(rootDirectory, filename))) addPattern(pattern);
|
|
8511
|
-
for (const linguistPath of parseGitattributesLinguistPaths(path.join(rootDirectory, ".gitattributes"))) addPattern(linguistPath);
|
|
8576
|
+
for (const filename of IGNORE_FILENAMES) for (const pattern of readIgnoreFile(path$1.join(rootDirectory, filename))) addPattern(pattern);
|
|
8577
|
+
for (const linguistPath of parseGitattributesLinguistPaths(path$1.join(rootDirectory, ".gitattributes"))) addPattern(linguistPath);
|
|
8512
8578
|
return patterns;
|
|
8513
8579
|
};
|
|
8514
8580
|
const collectIgnorePatterns = (rootDirectory) => {
|
|
@@ -8518,6 +8584,63 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
8518
8584
|
cachedPatternsByRoot.set(rootDirectory, patterns);
|
|
8519
8585
|
return patterns;
|
|
8520
8586
|
};
|
|
8587
|
+
const KNIP_JSON_FILENAME = "knip.json";
|
|
8588
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8589
|
+
const readJsonFileSafe = (filePath) => {
|
|
8590
|
+
let rawContents;
|
|
8591
|
+
try {
|
|
8592
|
+
rawContents = fs.readFileSync(filePath, "utf-8");
|
|
8593
|
+
} catch {
|
|
8594
|
+
return null;
|
|
8595
|
+
}
|
|
8596
|
+
try {
|
|
8597
|
+
return JSON.parse(rawContents);
|
|
8598
|
+
} catch {
|
|
8599
|
+
return null;
|
|
8600
|
+
}
|
|
8601
|
+
};
|
|
8602
|
+
const readKnipConfig = (rootDirectory) => {
|
|
8603
|
+
const knipJson = readJsonFileSafe(path.join(rootDirectory, KNIP_JSON_FILENAME));
|
|
8604
|
+
if (isRecord$1(knipJson)) return knipJson;
|
|
8605
|
+
const packageJson = readJsonFileSafe(path.join(rootDirectory, "package.json"));
|
|
8606
|
+
const packageKnipConfig = isRecord$1(packageJson) ? packageJson.knip : null;
|
|
8607
|
+
return isRecord$1(packageKnipConfig) ? packageKnipConfig : null;
|
|
8608
|
+
};
|
|
8609
|
+
const normalizePatternList = (value) => {
|
|
8610
|
+
if (typeof value === "string" && value.length > 0) return [value];
|
|
8611
|
+
if (!Array.isArray(value)) return [];
|
|
8612
|
+
return value.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
8613
|
+
};
|
|
8614
|
+
const prefixWorkspacePatterns = (workspacePattern, patterns) => {
|
|
8615
|
+
const normalizedWorkspacePattern = workspacePattern.replace(/\/+$/, "");
|
|
8616
|
+
return patterns.map((pattern) => pattern.startsWith("!") ? `!${normalizedWorkspacePattern}/${pattern.slice(1)}` : `${normalizedWorkspacePattern}/${pattern}`);
|
|
8617
|
+
};
|
|
8618
|
+
const collectKnipWorkspacePatterns = (workspaces, settingName) => {
|
|
8619
|
+
if (!isRecord$1(workspaces)) return [];
|
|
8620
|
+
const patterns = [];
|
|
8621
|
+
for (const [workspacePattern, workspaceConfig] of Object.entries(workspaces)) {
|
|
8622
|
+
if (!isRecord$1(workspaceConfig)) continue;
|
|
8623
|
+
patterns.push(...prefixWorkspacePatterns(workspacePattern, normalizePatternList(workspaceConfig[settingName])));
|
|
8624
|
+
}
|
|
8625
|
+
return patterns;
|
|
8626
|
+
};
|
|
8627
|
+
const collectKnipPatterns = (rootDirectory, settingName) => {
|
|
8628
|
+
const config = readKnipConfig(rootDirectory);
|
|
8629
|
+
if (!config) return [];
|
|
8630
|
+
return [...normalizePatternList(config[settingName]), ...collectKnipWorkspacePatterns(config.workspaces, settingName)];
|
|
8631
|
+
};
|
|
8632
|
+
const collectDeadCodeIgnorePatterns = (rootDirectory, userConfig) => {
|
|
8633
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8634
|
+
const sources = [
|
|
8635
|
+
readIgnoreFile(path.join(rootDirectory, ".gitignore")),
|
|
8636
|
+
collectIgnorePatterns(rootDirectory),
|
|
8637
|
+
userConfig?.ignore?.files ?? [],
|
|
8638
|
+
collectKnipPatterns(rootDirectory, "ignore")
|
|
8639
|
+
];
|
|
8640
|
+
for (const source of sources) for (const pattern of source) seen.add(pattern);
|
|
8641
|
+
return [...seen].filter((pattern) => pattern.length > 0);
|
|
8642
|
+
};
|
|
8643
|
+
const collectDeadCodeEntryPatterns = (rootDirectory) => [...new Set(collectKnipPatterns(rootDirectory, "entry"))].filter((pattern) => pattern.length > 0);
|
|
8521
8644
|
/**
|
|
8522
8645
|
* Resolves a path to its canonical, symlink-free form, falling back to
|
|
8523
8646
|
* the input when it cannot be realpath'd (broken symlink, permission
|
|
@@ -8535,7 +8658,7 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
8535
8658
|
*/
|
|
8536
8659
|
const toCanonicalPath = (filePath) => {
|
|
8537
8660
|
try {
|
|
8538
|
-
return fs.realpathSync(filePath);
|
|
8661
|
+
return fs$1.realpathSync(filePath);
|
|
8539
8662
|
} catch {
|
|
8540
8663
|
return filePath;
|
|
8541
8664
|
}
|
|
@@ -8543,6 +8666,7 @@ const toCanonicalPath = (filePath) => {
|
|
|
8543
8666
|
const DEAD_CODE_PLUGIN = "deslop";
|
|
8544
8667
|
const DEAD_CODE_CATEGORY = "Maintainability";
|
|
8545
8668
|
const TSCONFIG_FILENAMES$1 = ["tsconfig.json", "tsconfig.base.json"];
|
|
8669
|
+
const isRecord$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8546
8670
|
const DEAD_CODE_WORKER_SCRIPT = `
|
|
8547
8671
|
const inputChunks = [];
|
|
8548
8672
|
process.stdin.on("data", (chunk) => inputChunks.push(chunk));
|
|
@@ -8583,6 +8707,9 @@ process.stdin.on("end", () => {
|
|
|
8583
8707
|
const { analyze, defineConfig } = await import(workerInput.deslopJsModuleSpecifier);
|
|
8584
8708
|
const config = {
|
|
8585
8709
|
rootDir: workerInput.rootDirectory,
|
|
8710
|
+
...(workerInput.entryPatterns.length > 0
|
|
8711
|
+
? { entryPatterns: workerInput.entryPatterns }
|
|
8712
|
+
: {}),
|
|
8586
8713
|
...(workerInput.tsConfigPath ? { tsConfigPath: workerInput.tsConfigPath } : {}),
|
|
8587
8714
|
...(workerInput.ignorePatterns.length > 0
|
|
8588
8715
|
? { ignorePatterns: workerInput.ignorePatterns }
|
|
@@ -8598,25 +8725,14 @@ process.stdin.on("end", () => {
|
|
|
8598
8725
|
`;
|
|
8599
8726
|
const resolveTsConfigPath = (rootDirectory) => {
|
|
8600
8727
|
for (const filename of TSCONFIG_FILENAMES$1) {
|
|
8601
|
-
const candidate = path.join(rootDirectory, filename);
|
|
8602
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
8728
|
+
const candidate = path$1.join(rootDirectory, filename);
|
|
8729
|
+
if (fs$1.existsSync(candidate)) return candidate;
|
|
8603
8730
|
}
|
|
8604
8731
|
};
|
|
8605
|
-
const collectDeadCodeIgnorePatterns = (rootDirectory, userConfig) => {
|
|
8606
|
-
const seen = /* @__PURE__ */ new Set();
|
|
8607
|
-
const sources = [
|
|
8608
|
-
readIgnoreFile(path.join(rootDirectory, ".gitignore")),
|
|
8609
|
-
collectIgnorePatterns(rootDirectory),
|
|
8610
|
-
userConfig?.ignore?.files ?? []
|
|
8611
|
-
];
|
|
8612
|
-
for (const source of sources) for (const pattern of source) seen.add(pattern);
|
|
8613
|
-
return [...seen].filter((pattern) => pattern.length > 0);
|
|
8614
|
-
};
|
|
8615
8732
|
const toRelativeFilePath = (rootDirectory, filePath) => {
|
|
8616
8733
|
const relative = toRelativePath(filePath, rootDirectory);
|
|
8617
8734
|
return relative.length > 0 ? relative : filePath.replace(/\\/g, "/");
|
|
8618
8735
|
};
|
|
8619
|
-
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8620
8736
|
const parseArray = (value, label) => {
|
|
8621
8737
|
if (!Array.isArray(value)) throw new Error(`Dead-code worker returned invalid ${label}.`);
|
|
8622
8738
|
return value;
|
|
@@ -8640,7 +8756,7 @@ const parseUnusedFiles = (value) => {
|
|
|
8640
8756
|
const values = parseArray(value, "unusedFiles");
|
|
8641
8757
|
const unusedFiles = [];
|
|
8642
8758
|
for (const [index, entry] of values.entries()) {
|
|
8643
|
-
if (!isRecord$
|
|
8759
|
+
if (!isRecord$2(entry)) throw new Error(`Dead-code worker returned invalid unusedFiles[${index}].`);
|
|
8644
8760
|
unusedFiles.push({ path: parseString(entry.path, `unusedFiles[${index}].path`) });
|
|
8645
8761
|
}
|
|
8646
8762
|
return unusedFiles;
|
|
@@ -8649,7 +8765,7 @@ const parseUnusedExports = (value) => {
|
|
|
8649
8765
|
const values = parseArray(value, "unusedExports");
|
|
8650
8766
|
const unusedExports = [];
|
|
8651
8767
|
for (const [index, entry] of values.entries()) {
|
|
8652
|
-
if (!isRecord$
|
|
8768
|
+
if (!isRecord$2(entry)) throw new Error(`Dead-code worker returned invalid unusedExports[${index}].`);
|
|
8653
8769
|
unusedExports.push({
|
|
8654
8770
|
path: parseString(entry.path, `unusedExports[${index}].path`),
|
|
8655
8771
|
name: parseString(entry.name, `unusedExports[${index}].name`),
|
|
@@ -8664,7 +8780,7 @@ const parseUnusedDependencies = (value) => {
|
|
|
8664
8780
|
const values = parseArray(value, "unusedDependencies");
|
|
8665
8781
|
const unusedDependencies = [];
|
|
8666
8782
|
for (const [index, entry] of values.entries()) {
|
|
8667
|
-
if (!isRecord$
|
|
8783
|
+
if (!isRecord$2(entry)) throw new Error(`Dead-code worker returned invalid unusedDependencies[${index}].`);
|
|
8668
8784
|
unusedDependencies.push({
|
|
8669
8785
|
name: parseString(entry.name, `unusedDependencies[${index}].name`),
|
|
8670
8786
|
isDevDependency: parseBoolean(entry.isDevDependency, `unusedDependencies[${index}].isDevDependency`)
|
|
@@ -8676,13 +8792,13 @@ const parseCircularDependencies = (value) => {
|
|
|
8676
8792
|
const values = parseArray(value, "circularDependencies");
|
|
8677
8793
|
const circularDependencies = [];
|
|
8678
8794
|
for (const [index, entry] of values.entries()) {
|
|
8679
|
-
if (!isRecord$
|
|
8795
|
+
if (!isRecord$2(entry)) throw new Error(`Dead-code worker returned invalid circularDependencies[${index}].`);
|
|
8680
8796
|
circularDependencies.push({ files: parseStringArray(entry.files, `circularDependencies[${index}].files`) });
|
|
8681
8797
|
}
|
|
8682
8798
|
return circularDependencies;
|
|
8683
8799
|
};
|
|
8684
8800
|
const parseDeadCodeWorkerResult = (value) => {
|
|
8685
|
-
if (!isRecord$
|
|
8801
|
+
if (!isRecord$2(value)) throw new Error("Dead-code worker returned an invalid result.");
|
|
8686
8802
|
return {
|
|
8687
8803
|
unusedFiles: parseUnusedFiles(value.unusedFiles),
|
|
8688
8804
|
unusedExports: parseUnusedExports(value.unusedExports),
|
|
@@ -8691,7 +8807,7 @@ const parseDeadCodeWorkerResult = (value) => {
|
|
|
8691
8807
|
};
|
|
8692
8808
|
};
|
|
8693
8809
|
const parseDeadCodeWorkerError = (value) => {
|
|
8694
|
-
if (!isRecord$
|
|
8810
|
+
if (!isRecord$2(value) || typeof value.message !== "string") return { message: "Dead-code worker failed." };
|
|
8695
8811
|
return {
|
|
8696
8812
|
...typeof value.name === "string" ? { name: value.name } : {},
|
|
8697
8813
|
message: value.message,
|
|
@@ -8699,7 +8815,7 @@ const parseDeadCodeWorkerError = (value) => {
|
|
|
8699
8815
|
};
|
|
8700
8816
|
};
|
|
8701
8817
|
const parseDeadCodeWorkerMessage = (value) => {
|
|
8702
|
-
if (!isRecord$
|
|
8818
|
+
if (!isRecord$2(value)) throw new Error("Dead-code worker returned an invalid message.");
|
|
8703
8819
|
if (value.ok === true) return {
|
|
8704
8820
|
ok: true,
|
|
8705
8821
|
result: value.result
|
|
@@ -8798,10 +8914,12 @@ const runDeadCodeWorkerWithTimeout = (handle, timeoutMs) => new Promise((resolve
|
|
|
8798
8914
|
const checkDeadCode = async (options) => {
|
|
8799
8915
|
const { userConfig } = options;
|
|
8800
8916
|
const rootDirectory = toCanonicalPath(options.rootDirectory);
|
|
8801
|
-
if (!fs.existsSync(path.join(rootDirectory, "package.json"))) return [];
|
|
8917
|
+
if (!fs$1.existsSync(path$1.join(rootDirectory, "package.json"))) return [];
|
|
8918
|
+
const entryPatterns = collectDeadCodeEntryPatterns(rootDirectory);
|
|
8802
8919
|
const ignorePatterns = collectDeadCodeIgnorePatterns(rootDirectory, userConfig);
|
|
8803
8920
|
const result = parseDeadCodeWorkerResult(await runDeadCodeWorkerWithTimeout((options.createWorker ?? createDeadCodeWorker)({
|
|
8804
8921
|
rootDirectory,
|
|
8922
|
+
entryPatterns,
|
|
8805
8923
|
tsConfigPath: resolveTsConfigPath(rootDirectory),
|
|
8806
8924
|
ignorePatterns,
|
|
8807
8925
|
deslopJsModuleSpecifier: options.deslopJsModuleSpecifier ?? import.meta.resolve("deslop-js")
|
|
@@ -8903,7 +9021,7 @@ const isDiagnosticOnSurface = (diagnostic, surface, config) => {
|
|
|
8903
9021
|
return true;
|
|
8904
9022
|
};
|
|
8905
9023
|
const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
|
|
8906
|
-
const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(path.resolve(rootDirectory, relativePath)));
|
|
9024
|
+
const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(path$1.resolve(rootDirectory, relativePath)));
|
|
8907
9025
|
const listSourceFilesViaGit = (rootDirectory) => {
|
|
8908
9026
|
const result = spawnSync("git", [
|
|
8909
9027
|
"ls-files",
|
|
@@ -8926,12 +9044,12 @@ const listSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
8926
9044
|
const currentDirectory = stack.pop();
|
|
8927
9045
|
const entries = readDirectoryEntries(currentDirectory);
|
|
8928
9046
|
for (const entry of entries) {
|
|
8929
|
-
const absolutePath = path.join(currentDirectory, entry.name);
|
|
9047
|
+
const absolutePath = path$1.join(currentDirectory, entry.name);
|
|
8930
9048
|
if (entry.isDirectory()) {
|
|
8931
9049
|
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(absolutePath);
|
|
8932
9050
|
continue;
|
|
8933
9051
|
}
|
|
8934
|
-
if (entry.isFile() && isLintableSourceFile(entry.name)) filePaths.push(path.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
9052
|
+
if (entry.isFile() && isLintableSourceFile(entry.name)) filePaths.push(path$1.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
8935
9053
|
}
|
|
8936
9054
|
}
|
|
8937
9055
|
return filePaths;
|
|
@@ -8990,9 +9108,9 @@ var DeadCode = class DeadCode extends Context.Service()("react-doctor/DeadCode")
|
|
|
8990
9108
|
};
|
|
8991
9109
|
const createNodeReadFileLinesSync = (rootDirectory) => {
|
|
8992
9110
|
return (filePath) => {
|
|
8993
|
-
const absolutePath = path.isAbsolute(filePath) ? filePath : path.join(rootDirectory, filePath);
|
|
9111
|
+
const absolutePath = path$1.isAbsolute(filePath) ? filePath : path$1.join(rootDirectory, filePath);
|
|
8994
9112
|
try {
|
|
8995
|
-
return fs.readFileSync(absolutePath, "utf-8").split("\n");
|
|
9113
|
+
return fs$1.readFileSync(absolutePath, "utf-8").split("\n");
|
|
8996
9114
|
} catch {
|
|
8997
9115
|
return null;
|
|
8998
9116
|
}
|
|
@@ -9012,7 +9130,7 @@ var Files = class Files extends Context.Service()("react-doctor/Files") {
|
|
|
9012
9130
|
* pattern in react-doctor-evals' test layers.
|
|
9013
9131
|
*/
|
|
9014
9132
|
static layerInMemory = (tree) => {
|
|
9015
|
-
const resolveAbsolute = (filePath, rootDirectory) =>
|
|
9133
|
+
const resolveAbsolute = (filePath, rootDirectory) => path$1.isAbsolute(filePath) ? filePath : `${rootDirectory}/${filePath}`;
|
|
9016
9134
|
return Layer.succeed(Files, Files.of({
|
|
9017
9135
|
readLines: (input) => Effect.sync(() => {
|
|
9018
9136
|
const absolute = resolveAbsolute(input.filePath, input.rootDirectory);
|
|
@@ -9207,6 +9325,11 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9207
9325
|
branch
|
|
9208
9326
|
]).pipe(Effect.map((result) => result.status === 0));
|
|
9209
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);
|
|
9210
9333
|
const githubRepo = (directory) => runGit(directory, [
|
|
9211
9334
|
"config",
|
|
9212
9335
|
"--get",
|
|
@@ -9282,6 +9405,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9282
9405
|
return {
|
|
9283
9406
|
currentBranch: yield* currentBranch(input.directory),
|
|
9284
9407
|
baseBranch: baseRef,
|
|
9408
|
+
diffBaseRef,
|
|
9285
9409
|
changedFiles: splitNullSeparated(diff.stdout),
|
|
9286
9410
|
isCurrentChanges: false
|
|
9287
9411
|
};
|
|
@@ -9293,6 +9417,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9293
9417
|
githubRepo,
|
|
9294
9418
|
githubViewerPermission,
|
|
9295
9419
|
branchExists,
|
|
9420
|
+
mergeBase,
|
|
9296
9421
|
diffSelection: ({ directory, explicitBaseBranch }) => Effect.gen(function* () {
|
|
9297
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." }) }));
|
|
9298
9423
|
if (explicitBaseBranch !== void 0) {
|
|
@@ -9350,6 +9475,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9350
9475
|
return {
|
|
9351
9476
|
currentBranch: resolvedCurrentBranch,
|
|
9352
9477
|
baseBranch,
|
|
9478
|
+
diffBaseRef: mergeBaseRef,
|
|
9353
9479
|
changedFiles: splitNullSeparated(diff.stdout),
|
|
9354
9480
|
isCurrentChanges: false
|
|
9355
9481
|
};
|
|
@@ -9371,6 +9497,12 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9371
9497
|
directory,
|
|
9372
9498
|
maxStdoutBytes: options?.maxBufferBytes
|
|
9373
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),
|
|
9374
9506
|
grep: (input) => Effect.gen(function* () {
|
|
9375
9507
|
const args = ["grep"];
|
|
9376
9508
|
if (input.listMatchingFiles ?? true) args.push("-l");
|
|
@@ -9406,9 +9538,11 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9406
9538
|
githubRepo: () => Effect.succeed(snapshot.githubRepo ?? null),
|
|
9407
9539
|
githubViewerPermission: () => Effect.succeed(snapshot.githubViewerPermission ?? null),
|
|
9408
9540
|
branchExists: (_directory, branch) => Effect.succeed(snapshot.branchExists?.get(branch) ?? false),
|
|
9541
|
+
mergeBase: ({ ref }) => Effect.succeed(snapshot.mergeBase?.get(ref) ?? null),
|
|
9409
9542
|
diffSelection: () => Effect.succeed(snapshot.diffSelection ?? null),
|
|
9410
9543
|
stagedFilePaths: () => Effect.succeed(snapshot.stagedFiles ?? []),
|
|
9411
9544
|
showStagedContent: (_directory, relativePath) => Effect.succeed(snapshot.stagedContent?.get(relativePath) ?? null),
|
|
9545
|
+
showRefContent: ({ ref, relativePath }) => Effect.succeed(snapshot.refContent?.get(`${ref}:${relativePath}`) ?? null),
|
|
9412
9546
|
grep: () => Effect.sync(() => {
|
|
9413
9547
|
const matches = snapshot.grepMatches;
|
|
9414
9548
|
if (matches === null || matches === void 0) return null;
|
|
@@ -9502,7 +9636,7 @@ const canOxlintExtendConfig = (configPath) => {
|
|
|
9502
9636
|
if (!configPath.endsWith(".eslintrc.json")) return true;
|
|
9503
9637
|
let parsed;
|
|
9504
9638
|
try {
|
|
9505
|
-
parsed = parseJsonOrJsonc(fs.readFileSync(configPath, "utf-8"));
|
|
9639
|
+
parsed = parseJsonOrJsonc(fs$1.readFileSync(configPath, "utf-8"));
|
|
9506
9640
|
} catch {
|
|
9507
9641
|
return true;
|
|
9508
9642
|
}
|
|
@@ -9515,7 +9649,7 @@ const canOxlintExtendConfig = (configPath) => {
|
|
|
9515
9649
|
};
|
|
9516
9650
|
const findFirstLintConfigInDirectory = (directory) => {
|
|
9517
9651
|
for (const filename of ADOPTABLE_LINT_CONFIG_FILENAMES) {
|
|
9518
|
-
const candidatePath = path.join(directory, filename);
|
|
9652
|
+
const candidatePath = path$1.join(directory, filename);
|
|
9519
9653
|
if (isFile(candidatePath)) return candidatePath;
|
|
9520
9654
|
}
|
|
9521
9655
|
return null;
|
|
@@ -9524,12 +9658,12 @@ const detectUserLintConfigPaths = (rootDirectory) => {
|
|
|
9524
9658
|
const directLintConfig = findFirstLintConfigInDirectory(rootDirectory);
|
|
9525
9659
|
if (directLintConfig) return [directLintConfig];
|
|
9526
9660
|
if (isProjectBoundary(rootDirectory)) return [];
|
|
9527
|
-
let ancestorDirectory = path.dirname(rootDirectory);
|
|
9528
|
-
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
9661
|
+
let ancestorDirectory = path$1.dirname(rootDirectory);
|
|
9662
|
+
while (ancestorDirectory !== path$1.dirname(ancestorDirectory)) {
|
|
9529
9663
|
const ancestorLintConfig = findFirstLintConfigInDirectory(ancestorDirectory);
|
|
9530
9664
|
if (ancestorLintConfig) return [ancestorLintConfig];
|
|
9531
9665
|
if (isProjectBoundary(ancestorDirectory)) return [];
|
|
9532
|
-
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
9666
|
+
ancestorDirectory = path$1.dirname(ancestorDirectory);
|
|
9533
9667
|
}
|
|
9534
9668
|
return [];
|
|
9535
9669
|
};
|
|
@@ -9558,10 +9692,10 @@ const findFilesWithDisableDirectivesViaFilesystem = (rootDirectory, includePaths
|
|
|
9558
9692
|
const matches = [];
|
|
9559
9693
|
const checkFile = (relativePath) => {
|
|
9560
9694
|
if (!isLintableSourceFile(relativePath)) return;
|
|
9561
|
-
const absolutePath = path.join(rootDirectory, relativePath);
|
|
9695
|
+
const absolutePath = path$1.join(rootDirectory, relativePath);
|
|
9562
9696
|
let content;
|
|
9563
9697
|
try {
|
|
9564
|
-
content = fs.readFileSync(absolutePath, "utf-8");
|
|
9698
|
+
content = fs$1.readFileSync(absolutePath, "utf-8");
|
|
9565
9699
|
} catch {
|
|
9566
9700
|
return;
|
|
9567
9701
|
}
|
|
@@ -9579,12 +9713,12 @@ const findFilesWithDisableDirectivesViaFilesystem = (rootDirectory, includePaths
|
|
|
9579
9713
|
for (const entry of entries) {
|
|
9580
9714
|
if (entry.isDirectory()) {
|
|
9581
9715
|
if (entry.name.startsWith(".") || IGNORED_DIRECTORIES.has(entry.name)) continue;
|
|
9582
|
-
stack.push(path.join(current, entry.name));
|
|
9716
|
+
stack.push(path$1.join(current, entry.name));
|
|
9583
9717
|
continue;
|
|
9584
9718
|
}
|
|
9585
9719
|
if (!entry.isFile()) continue;
|
|
9586
|
-
const absolute = path.join(current, entry.name);
|
|
9587
|
-
checkFile(path.relative(rootDirectory, absolute));
|
|
9720
|
+
const absolute = path$1.join(current, entry.name);
|
|
9721
|
+
checkFile(path$1.relative(rootDirectory, absolute));
|
|
9588
9722
|
}
|
|
9589
9723
|
}
|
|
9590
9724
|
return matches;
|
|
@@ -9599,7 +9733,7 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
9599
9733
|
if (isRestored) return;
|
|
9600
9734
|
isRestored = true;
|
|
9601
9735
|
for (const [absolutePath, originalContent] of originalContents) try {
|
|
9602
|
-
fs.writeFileSync(absolutePath, originalContent);
|
|
9736
|
+
fs$1.writeFileSync(absolutePath, originalContent);
|
|
9603
9737
|
} catch (error) {
|
|
9604
9738
|
process.stderr.write(`[react-doctor] Failed to restore inline disable directives in ${absolutePath}: ${error instanceof Error ? error.message : String(error)}\n[react-doctor] Run: git checkout -- ${absolutePath}\n`);
|
|
9605
9739
|
}
|
|
@@ -9607,17 +9741,17 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
9607
9741
|
const onExit = () => restore();
|
|
9608
9742
|
process.once("exit", onExit);
|
|
9609
9743
|
for (const relativePath of filePaths) {
|
|
9610
|
-
const absolutePath = path.join(rootDirectory, relativePath);
|
|
9744
|
+
const absolutePath = path$1.join(rootDirectory, relativePath);
|
|
9611
9745
|
let originalContent;
|
|
9612
9746
|
try {
|
|
9613
|
-
originalContent = fs.readFileSync(absolutePath, "utf-8");
|
|
9747
|
+
originalContent = fs$1.readFileSync(absolutePath, "utf-8");
|
|
9614
9748
|
} catch {
|
|
9615
9749
|
continue;
|
|
9616
9750
|
}
|
|
9617
9751
|
const neutralizedContent = neutralizeContent(originalContent);
|
|
9618
9752
|
if (neutralizedContent !== originalContent) {
|
|
9619
9753
|
originalContents.set(absolutePath, originalContent);
|
|
9620
|
-
fs.writeFileSync(absolutePath, neutralizedContent);
|
|
9754
|
+
fs$1.writeFileSync(absolutePath, neutralizedContent);
|
|
9621
9755
|
}
|
|
9622
9756
|
}
|
|
9623
9757
|
return () => {
|
|
@@ -9754,11 +9888,11 @@ const filterRulesToAvailable = (rules, pluginNamespace, availableRuleNames) => {
|
|
|
9754
9888
|
* renamed.
|
|
9755
9889
|
*/
|
|
9756
9890
|
const resolveUserPlugin = (spec, configSourceDirectory) => {
|
|
9757
|
-
const isRelative = spec.startsWith("./") || spec.startsWith("../") || path.isAbsolute(spec);
|
|
9758
|
-
const candidateRequire = createRequire(path.join(configSourceDirectory, "noop.js"));
|
|
9891
|
+
const isRelative = spec.startsWith("./") || spec.startsWith("../") || path$1.isAbsolute(spec);
|
|
9892
|
+
const candidateRequire = createRequire(path$1.join(configSourceDirectory, "noop.js"));
|
|
9759
9893
|
let resolvedSpecifier;
|
|
9760
9894
|
try {
|
|
9761
|
-
resolvedSpecifier = isRelative ? path.resolve(configSourceDirectory, spec) : candidateRequire.resolve(spec);
|
|
9895
|
+
resolvedSpecifier = isRelative ? path$1.resolve(configSourceDirectory, spec) : candidateRequire.resolve(spec);
|
|
9762
9896
|
} catch (error) {
|
|
9763
9897
|
warnConfigIssue(`config.plugins entry "${spec}" could not be resolved from ${configSourceDirectory}: ${error instanceof Error ? error.message : String(error)}`);
|
|
9764
9898
|
return null;
|
|
@@ -9798,8 +9932,8 @@ const resolveUserPlugins = (specs, configSourceDirectory) => {
|
|
|
9798
9932
|
return resolved;
|
|
9799
9933
|
};
|
|
9800
9934
|
const resolveSettingsRootDirectory = (rootDirectory) => {
|
|
9801
|
-
if (!fs.existsSync(rootDirectory)) return rootDirectory;
|
|
9802
|
-
return fs.realpathSync(rootDirectory);
|
|
9935
|
+
if (!fs$1.existsSync(rootDirectory)) return rootDirectory;
|
|
9936
|
+
return fs$1.realpathSync(rootDirectory);
|
|
9803
9937
|
};
|
|
9804
9938
|
const resolveCompilerCleanupBucketSeverity = (ruleKey, severityControls) => {
|
|
9805
9939
|
if (!COMPILER_CLEANUP_RULE_KEYS.has(ruleKey)) return void 0;
|
|
@@ -9875,6 +10009,7 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
9875
10009
|
settings: { "react-doctor": {
|
|
9876
10010
|
framework: project.framework,
|
|
9877
10011
|
rootDirectory: resolveSettingsRootDirectory(project.rootDirectory),
|
|
10012
|
+
...project.shopifyFlashListMajorVersion !== null ? { shopifyFlashListMajorVersion: project.shopifyFlashListMajorVersion } : {},
|
|
9878
10013
|
...serverAuthFunctionNames && serverAuthFunctionNames.length > 0 ? { serverAuthFunctionNames: [...serverAuthFunctionNames] } : {}
|
|
9879
10014
|
} },
|
|
9880
10015
|
rules: {
|
|
@@ -9887,13 +10022,13 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
9887
10022
|
const esmRequire = createRequire(import.meta.url);
|
|
9888
10023
|
const resolveOxlintBinary = () => {
|
|
9889
10024
|
const oxlintMainPath = esmRequire.resolve("oxlint");
|
|
9890
|
-
const oxlintPackageDirectory = path.resolve(path.dirname(oxlintMainPath), "..");
|
|
9891
|
-
return path.join(oxlintPackageDirectory, "bin", "oxlint");
|
|
10025
|
+
const oxlintPackageDirectory = path$1.resolve(path$1.dirname(oxlintMainPath), "..");
|
|
10026
|
+
return path$1.join(oxlintPackageDirectory, "bin", "oxlint");
|
|
9892
10027
|
};
|
|
9893
10028
|
const resolvePluginPath = () => esmRequire.resolve("oxlint-plugin-react-doctor");
|
|
9894
10029
|
const TSCONFIG_FILENAMES = ["tsconfig.json", "tsconfig.base.json"];
|
|
9895
10030
|
const resolveTsConfigRelativePath = (rootDirectory) => {
|
|
9896
|
-
for (const filename of TSCONFIG_FILENAMES) if (fs.existsSync(path.join(rootDirectory, filename))) return `./${filename}`;
|
|
10031
|
+
for (const filename of TSCONFIG_FILENAMES) if (fs$1.existsSync(path$1.join(rootDirectory, filename))) return `./${filename}`;
|
|
9897
10032
|
return null;
|
|
9898
10033
|
};
|
|
9899
10034
|
const dedupeDiagnostics = (diagnostics) => {
|
|
@@ -10393,10 +10528,10 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
10393
10528
|
if (!diagnostic.message.startsWith(REACT_HOOK_USE_MESSAGE_PREFIX)) return false;
|
|
10394
10529
|
const primaryLabel = diagnostic.labels[0];
|
|
10395
10530
|
if (!primaryLabel) return false;
|
|
10396
|
-
const absolutePath = path.isAbsolute(diagnostic.filename) ? diagnostic.filename : path.join(rootDirectory, diagnostic.filename);
|
|
10531
|
+
const absolutePath = path$1.isAbsolute(diagnostic.filename) ? diagnostic.filename : path$1.join(rootDirectory, diagnostic.filename);
|
|
10397
10532
|
let sourceText;
|
|
10398
10533
|
try {
|
|
10399
|
-
sourceText = fs.readFileSync(absolutePath, "utf-8");
|
|
10534
|
+
sourceText = fs$1.readFileSync(absolutePath, "utf-8");
|
|
10400
10535
|
} catch {
|
|
10401
10536
|
return false;
|
|
10402
10537
|
}
|
|
@@ -10462,6 +10597,30 @@ const parseRuleCode = (code) => {
|
|
|
10462
10597
|
};
|
|
10463
10598
|
};
|
|
10464
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
|
+
};
|
|
10465
10624
|
const isOxlintOutput = (value) => {
|
|
10466
10625
|
if (typeof value !== "object" || value === null) return false;
|
|
10467
10626
|
const candidate = value;
|
|
@@ -10487,7 +10646,7 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10487
10646
|
if (!isOxlintOutput(parsed)) throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
|
|
10488
10647
|
const minifiedFileCache = /* @__PURE__ */ new Map();
|
|
10489
10648
|
const isMinifiedDiagnosticFile = (filename) => {
|
|
10490
|
-
const absolutePath = path.isAbsolute(filename) ? filename : path.resolve(rootDirectory || ".", filename);
|
|
10649
|
+
const absolutePath = path$1.isAbsolute(filename) ? filename : path$1.resolve(rootDirectory || ".", filename);
|
|
10491
10650
|
const cached = minifiedFileCache.get(absolutePath);
|
|
10492
10651
|
if (cached !== void 0) return cached;
|
|
10493
10652
|
const minified = isMinifiedSource(absolutePath);
|
|
@@ -10498,8 +10657,11 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10498
10657
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
10499
10658
|
const primaryLabel = diagnostic.labels[0];
|
|
10500
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);
|
|
10501
10663
|
return {
|
|
10502
|
-
filePath:
|
|
10664
|
+
filePath: normalizedFilePath,
|
|
10503
10665
|
plugin,
|
|
10504
10666
|
rule,
|
|
10505
10667
|
severity: diagnostic.severity,
|
|
@@ -10507,9 +10669,14 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10507
10669
|
message: cleaned.message,
|
|
10508
10670
|
help: cleaned.help,
|
|
10509
10671
|
url: diagnostic.url,
|
|
10510
|
-
line:
|
|
10511
|
-
column:
|
|
10512
|
-
|
|
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 } : {}
|
|
10513
10680
|
};
|
|
10514
10681
|
});
|
|
10515
10682
|
};
|
|
@@ -10754,12 +10921,12 @@ const validateRuleRegistration = () => {
|
|
|
10754
10921
|
* legitimate overwriter is `this` runner inside the same temp dir.
|
|
10755
10922
|
*/
|
|
10756
10923
|
const writeOxlintConfig = (configPath, configToWrite) => {
|
|
10757
|
-
fs.rmSync(configPath, { force: true });
|
|
10758
|
-
const fileHandle = fs.openSync(configPath, "wx", 384);
|
|
10924
|
+
fs$1.rmSync(configPath, { force: true });
|
|
10925
|
+
const fileHandle = fs$1.openSync(configPath, "wx", 384);
|
|
10759
10926
|
try {
|
|
10760
|
-
fs.writeFileSync(fileHandle, JSON.stringify(configToWrite));
|
|
10927
|
+
fs$1.writeFileSync(fileHandle, JSON.stringify(configToWrite));
|
|
10761
10928
|
} finally {
|
|
10762
|
-
fs.closeSync(fileHandle);
|
|
10929
|
+
fs$1.closeSync(fileHandle);
|
|
10763
10930
|
}
|
|
10764
10931
|
};
|
|
10765
10932
|
/**
|
|
@@ -10800,8 +10967,8 @@ const runOxlint = async (options) => {
|
|
|
10800
10967
|
userPlugins
|
|
10801
10968
|
});
|
|
10802
10969
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : await neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
10803
|
-
const configDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
10804
|
-
const configPath = path.join(configDirectory, "oxlintrc.json");
|
|
10970
|
+
const configDirectory = fs$1.mkdtempSync(path$1.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
10971
|
+
const configPath = path$1.join(configDirectory, "oxlintrc.json");
|
|
10805
10972
|
try {
|
|
10806
10973
|
const baseArgs = [
|
|
10807
10974
|
resolveOxlintBinary(),
|
|
@@ -10816,8 +10983,8 @@ const runOxlint = async (options) => {
|
|
|
10816
10983
|
}
|
|
10817
10984
|
const combinedPatterns = collectIgnorePatterns(rootDirectory);
|
|
10818
10985
|
if (combinedPatterns.length > 0) {
|
|
10819
|
-
const combinedIgnorePath = path.join(configDirectory, "combined.ignore");
|
|
10820
|
-
fs.writeFileSync(combinedIgnorePath, `${combinedPatterns.join("\n")}\n`);
|
|
10986
|
+
const combinedIgnorePath = path$1.join(configDirectory, "combined.ignore");
|
|
10987
|
+
fs$1.writeFileSync(combinedIgnorePath, `${combinedPatterns.join("\n")}\n`);
|
|
10821
10988
|
baseArgs.push("--ignore-path", combinedIgnorePath);
|
|
10822
10989
|
}
|
|
10823
10990
|
const fileBatches = batchIncludePaths(baseArgs, includePaths !== void 0 ? includePaths : listSourceFiles(rootDirectory));
|
|
@@ -10843,7 +11010,7 @@ const runOxlint = async (options) => {
|
|
|
10843
11010
|
}
|
|
10844
11011
|
} finally {
|
|
10845
11012
|
restoreDisableDirectives();
|
|
10846
|
-
fs.rmSync(configDirectory, {
|
|
11013
|
+
fs$1.rmSync(configDirectory, {
|
|
10847
11014
|
recursive: true,
|
|
10848
11015
|
force: true
|
|
10849
11016
|
});
|
|
@@ -11045,7 +11212,7 @@ var Reporter = class Reporter extends Context.Service()("react-doctor/Reporter")
|
|
|
11045
11212
|
* `Diagnostic` schema.
|
|
11046
11213
|
*/
|
|
11047
11214
|
static layerNdjson = (filePath) => Layer.effect(Reporter, Effect.sync(() => {
|
|
11048
|
-
fs$1.mkdirSync(
|
|
11215
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
11049
11216
|
const handle = fs$1.openSync(filePath, "a");
|
|
11050
11217
|
const encode = Schema.encodeUnknownSync(Diagnostic);
|
|
11051
11218
|
const emit = (diagnostic) => Effect.sync(() => {
|
|
@@ -11096,6 +11263,7 @@ const calculateScore = async (diagnostics, options = {}) => {
|
|
|
11096
11263
|
...typeof options.metadata?.sourceFileCount === "number" ? { sourceFileCount: options.metadata.sourceFileCount } : {},
|
|
11097
11264
|
...options.metadata?.defaultBranch ? { defaultBranch: options.metadata.defaultBranch } : {},
|
|
11098
11265
|
...options.metadata?.doctorVersion ? { doctorVersion: options.metadata.doctorVersion } : {},
|
|
11266
|
+
...options.metadata?.runId ? { runId: options.metadata.runId } : {},
|
|
11099
11267
|
...options.metadata?.githubEventName ? { githubEventName: options.metadata.githubEventName } : {},
|
|
11100
11268
|
...options.metadata?.githubActorAssociation ? { githubActorAssociation: options.metadata.githubActorAssociation } : {},
|
|
11101
11269
|
...options.metadata?.githubViewerPermission ? { githubViewerPermission: options.metadata.githubViewerPermission } : {}
|
|
@@ -11154,7 +11322,7 @@ const getStringProperty = (value, propertyName) => {
|
|
|
11154
11322
|
const readGithubEventPayload = (eventPath) => {
|
|
11155
11323
|
if (eventPath === void 0 || eventPath.length === 0) return null;
|
|
11156
11324
|
try {
|
|
11157
|
-
return JSON.parse(readFileSync(eventPath, "utf8"));
|
|
11325
|
+
return JSON.parse(fs$1.readFileSync(eventPath, "utf8"));
|
|
11158
11326
|
} catch {
|
|
11159
11327
|
return null;
|
|
11160
11328
|
}
|
|
@@ -11237,8 +11405,8 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
11237
11405
|
directory: scanDirectory,
|
|
11238
11406
|
repo
|
|
11239
11407
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
11240
|
-
const lintIncludePaths = computeJsxIncludePaths([...input.includePaths]) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
11241
|
-
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path.resolve(scanDirectory, relativePath)) : [];
|
|
11408
|
+
const lintIncludePaths = (input.skipJsxIncludeFilter ? input.includePaths.length > 0 ? [...input.includePaths] : void 0 : computeJsxIncludePaths([...input.includePaths])) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
11409
|
+
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path$1.resolve(scanDirectory, relativePath)) : [];
|
|
11242
11410
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
11243
11411
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
11244
11412
|
yield* beforeLint(project, lintIncludePaths ?? void 0);
|
|
@@ -11335,6 +11503,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
11335
11503
|
sourceFileCount: project.sourceFileCount,
|
|
11336
11504
|
...defaultBranch !== null ? { defaultBranch } : {},
|
|
11337
11505
|
...input.doctorVersion !== void 0 ? { doctorVersion: input.doctorVersion } : {},
|
|
11506
|
+
...input.runId !== void 0 ? { runId: input.runId } : {},
|
|
11338
11507
|
...githubActionsScoreMetadata,
|
|
11339
11508
|
...githubViewerPermission !== null ? { githubViewerPermission } : {}
|
|
11340
11509
|
};
|
|
@@ -11388,25 +11557,25 @@ const isNodeVersionCompatibleWithOxlint = ({ major, minor }) => {
|
|
|
11388
11557
|
const isCurrentNodeCompatibleWithOxlint = () => isNodeVersionCompatibleWithOxlint(parseNodeVersion(process.version));
|
|
11389
11558
|
const getNvmDirectory = () => {
|
|
11390
11559
|
const envNvmDirectory = process.env.NVM_DIR;
|
|
11391
|
-
if (envNvmDirectory && existsSync(envNvmDirectory)) return envNvmDirectory;
|
|
11392
|
-
const defaultNvmDirectory = path.join(os.homedir(), ".nvm");
|
|
11393
|
-
if (existsSync(defaultNvmDirectory)) return defaultNvmDirectory;
|
|
11560
|
+
if (envNvmDirectory && fs$1.existsSync(envNvmDirectory)) return envNvmDirectory;
|
|
11561
|
+
const defaultNvmDirectory = path$1.join(os.homedir(), ".nvm");
|
|
11562
|
+
if (fs$1.existsSync(defaultNvmDirectory)) return defaultNvmDirectory;
|
|
11394
11563
|
return null;
|
|
11395
11564
|
};
|
|
11396
11565
|
const isNvmInstalled = () => getNvmDirectory() !== null;
|
|
11397
11566
|
const findCompatibleNvmBinary = () => {
|
|
11398
11567
|
const nvmDirectory = getNvmDirectory();
|
|
11399
11568
|
if (!nvmDirectory) return null;
|
|
11400
|
-
const versionsDirectory = path.join(nvmDirectory, "versions", "node");
|
|
11401
|
-
if (!existsSync(versionsDirectory)) return null;
|
|
11402
|
-
const compatibleVersions = readdirSync(versionsDirectory).filter((directoryName) => directoryName.startsWith("v")).map((directoryName) => ({
|
|
11569
|
+
const versionsDirectory = path$1.join(nvmDirectory, "versions", "node");
|
|
11570
|
+
if (!fs$1.existsSync(versionsDirectory)) return null;
|
|
11571
|
+
const compatibleVersions = fs$1.readdirSync(versionsDirectory).filter((directoryName) => directoryName.startsWith("v")).map((directoryName) => ({
|
|
11403
11572
|
directoryName,
|
|
11404
11573
|
...parseNodeVersion(directoryName)
|
|
11405
11574
|
})).filter((version) => isNodeVersionCompatibleWithOxlint(version)).sort((versionA, versionB) => versionB.major - versionA.major || versionB.minor - versionA.minor || versionB.patch - versionA.patch);
|
|
11406
11575
|
if (compatibleVersions.length === 0) return null;
|
|
11407
11576
|
const bestVersion = compatibleVersions[0];
|
|
11408
|
-
const binaryPath = path.join(versionsDirectory, bestVersion.directoryName, "bin", "node");
|
|
11409
|
-
return existsSync(binaryPath) ? binaryPath : null;
|
|
11577
|
+
const binaryPath = path$1.join(versionsDirectory, bestVersion.directoryName, "bin", "node");
|
|
11578
|
+
return fs$1.existsSync(binaryPath) ? binaryPath : null;
|
|
11410
11579
|
};
|
|
11411
11580
|
const getNodeVersionFromBinary = (binaryPath) => {
|
|
11412
11581
|
const result = spawnSync(binaryPath, ["--version"], { encoding: "utf-8" });
|
|
@@ -11416,8 +11585,8 @@ const getNodeVersionFromBinary = (binaryPath) => {
|
|
|
11416
11585
|
const installNodeViaNvm = () => {
|
|
11417
11586
|
const nvmDirectory = getNvmDirectory();
|
|
11418
11587
|
if (!nvmDirectory) return false;
|
|
11419
|
-
const nvmScript = path.join(nvmDirectory, "nvm.sh");
|
|
11420
|
-
if (!existsSync(nvmScript)) return false;
|
|
11588
|
+
const nvmScript = path$1.join(nvmDirectory, "nvm.sh");
|
|
11589
|
+
if (!fs$1.existsSync(nvmScript)) return false;
|
|
11421
11590
|
const result = spawnSync("bash", ["-c", ". \"$NVM_SCRIPT\" && nvm install \"$NODE_MAJOR\""], {
|
|
11422
11591
|
stdio: "inherit",
|
|
11423
11592
|
env: {
|
|
@@ -11482,19 +11651,60 @@ var NodeResolver = class NodeResolver extends Context.Service()("react-doctor/No
|
|
|
11482
11651
|
});
|
|
11483
11652
|
};
|
|
11484
11653
|
/**
|
|
11485
|
-
* Zip-Slip defense:
|
|
11486
|
-
*
|
|
11487
|
-
*
|
|
11488
|
-
*
|
|
11489
|
-
* working tree) can include `..` segments that escape the temp
|
|
11490
|
-
* tree. Resolve the candidate against the temp dir and reject any
|
|
11491
|
-
* 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.
|
|
11492
11658
|
*/
|
|
11493
11659
|
const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
11494
11660
|
const relative = path.relative(parentAbsolutePath, childAbsolutePath);
|
|
11495
11661
|
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
11496
11662
|
};
|
|
11497
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
|
+
/**
|
|
11498
11708
|
* `StagedFiles` materializes the git-staged source files of a
|
|
11499
11709
|
* directory into a temp tree (mirroring the project layout and
|
|
11500
11710
|
* carrying over a fixed set of project config files) so oxlint can
|
|
@@ -11511,40 +11721,16 @@ var StagedFiles = class StagedFiles extends Context.Service()("react-doctor/Stag
|
|
|
11511
11721
|
const git = yield* Git;
|
|
11512
11722
|
return StagedFiles.of({
|
|
11513
11723
|
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(isLintableSourceFile))),
|
|
11514
|
-
materialize: ({ directory, stagedFiles, tempDirectory }) =>
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
fs.writeFileSync(candidateTargetPath, content);
|
|
11525
|
-
});
|
|
11526
|
-
materializedFiles.push(relativePath);
|
|
11527
|
-
}
|
|
11528
|
-
yield* Effect.sync(() => {
|
|
11529
|
-
for (const configFilename of STAGED_FILES_PROJECT_CONFIG_FILENAMES) {
|
|
11530
|
-
const sourcePath = path.join(directory, configFilename);
|
|
11531
|
-
const targetPath = path.join(resolvedTempDirectory, configFilename);
|
|
11532
|
-
if (fs.existsSync(sourcePath) && !fs.existsSync(targetPath)) fs.cpSync(sourcePath, targetPath);
|
|
11533
|
-
}
|
|
11534
|
-
});
|
|
11535
|
-
return {
|
|
11536
|
-
tempDirectory,
|
|
11537
|
-
stagedFiles: materializedFiles,
|
|
11538
|
-
cleanup: () => {
|
|
11539
|
-
try {
|
|
11540
|
-
fs.rmSync(tempDirectory, {
|
|
11541
|
-
recursive: true,
|
|
11542
|
-
force: true
|
|
11543
|
-
});
|
|
11544
|
-
} catch {}
|
|
11545
|
-
}
|
|
11546
|
-
};
|
|
11547
|
-
})
|
|
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
|
+
})))
|
|
11548
11734
|
});
|
|
11549
11735
|
}));
|
|
11550
11736
|
/**
|
|
@@ -11591,18 +11777,22 @@ const safeGetErrorChain = (error) => {
|
|
|
11591
11777
|
};
|
|
11592
11778
|
const buildJsonReportError = (input) => {
|
|
11593
11779
|
const chain = safeGetErrorChain(input.error);
|
|
11780
|
+
const sentryEventId = input.sentryEventId ?? null;
|
|
11594
11781
|
const errorPayload = isReactDoctorError(input.error) ? {
|
|
11595
11782
|
message: formatReactDoctorError(input.error),
|
|
11596
11783
|
name: `ReactDoctorError(${input.error.reason._tag})`,
|
|
11597
|
-
chain
|
|
11784
|
+
chain,
|
|
11785
|
+
sentryEventId
|
|
11598
11786
|
} : input.error instanceof Error ? {
|
|
11599
11787
|
message: input.error.message || input.error.name || "Error",
|
|
11600
11788
|
name: input.error.name || "Error",
|
|
11601
|
-
chain
|
|
11789
|
+
chain,
|
|
11790
|
+
sentryEventId
|
|
11602
11791
|
} : {
|
|
11603
11792
|
message: safeStringify(input.error),
|
|
11604
11793
|
name: "Error",
|
|
11605
|
-
chain
|
|
11794
|
+
chain,
|
|
11795
|
+
sentryEventId
|
|
11606
11796
|
};
|
|
11607
11797
|
return {
|
|
11608
11798
|
schemaVersion: 1,
|
|
@@ -11678,12 +11868,10 @@ const buildJsonReport = (input) => {
|
|
|
11678
11868
|
const flattenedDiagnostics = projects.flatMap((entry) => entry.diagnostics);
|
|
11679
11869
|
const worstScoredProject = findWorstScoredProject(projects);
|
|
11680
11870
|
const summary = summarizeDiagnostics(flattenedDiagnostics, worstScoredProject?.score?.score ?? null, worstScoredProject?.score?.label ?? null);
|
|
11681
|
-
|
|
11682
|
-
schemaVersion: 1,
|
|
11871
|
+
const shared = {
|
|
11683
11872
|
version: input.version,
|
|
11684
11873
|
ok: true,
|
|
11685
11874
|
directory: input.directory,
|
|
11686
|
-
mode: input.mode,
|
|
11687
11875
|
diff: toJsonDiff(input.diff),
|
|
11688
11876
|
projects,
|
|
11689
11877
|
diagnostics: flattenedDiagnostics,
|
|
@@ -11691,6 +11879,22 @@ const buildJsonReport = (input) => {
|
|
|
11691
11879
|
elapsedMilliseconds: input.totalElapsedMilliseconds,
|
|
11692
11880
|
error: null
|
|
11693
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
|
+
};
|
|
11694
11898
|
};
|
|
11695
11899
|
/**
|
|
11696
11900
|
* Single source of truth for the skipped-check accounting shared by the
|
|
@@ -11712,6 +11916,45 @@ const buildSkippedChecks = (input) => {
|
|
|
11712
11916
|
skippedCheckReasons
|
|
11713
11917
|
};
|
|
11714
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
|
+
};
|
|
11715
11958
|
/**
|
|
11716
11959
|
* Programmatic façade over `Git.diffSelection`. Async because the
|
|
11717
11960
|
* Git service runs through Effect's `ChildProcess` (true subprocess
|
|
@@ -11734,6 +11977,7 @@ const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.
|
|
|
11734
11977
|
return {
|
|
11735
11978
|
currentBranch: selection.currentBranch,
|
|
11736
11979
|
baseBranch: selection.baseBranch,
|
|
11980
|
+
...selection.diffBaseRef !== void 0 ? { diffBaseRef: selection.diffBaseRef } : {},
|
|
11737
11981
|
changedFiles: [...selection.changedFiles],
|
|
11738
11982
|
...selection.isCurrentChanges ? { isCurrentChanges: true } : {}
|
|
11739
11983
|
};
|
|
@@ -11791,6 +12035,13 @@ const CI_PROVIDER_BY_ENVIRONMENT_VARIABLE = [
|
|
|
11791
12035
|
["TRAVIS", "travis"],
|
|
11792
12036
|
["DRONE", "drone"]
|
|
11793
12037
|
];
|
|
12038
|
+
const GITHUB_ACTION_MARKER_ENVIRONMENT_VARIABLE = "REACT_DOCTOR_GITHUB_ACTION";
|
|
12039
|
+
const ACTION_INPUT_ENVIRONMENT_VARIABLES = {
|
|
12040
|
+
blocking: "REACT_DOCTOR_ACTION_BLOCKING",
|
|
12041
|
+
comment: "REACT_DOCTOR_ACTION_COMMENT",
|
|
12042
|
+
reviewComments: "REACT_DOCTOR_ACTION_REVIEW_COMMENTS",
|
|
12043
|
+
version: "REACT_DOCTOR_ACTION_VERSION"
|
|
12044
|
+
};
|
|
11794
12045
|
const CODING_AGENT_BY_ENVIRONMENT_VARIABLE = [
|
|
11795
12046
|
["CLAUDECODE", "claude-code"],
|
|
11796
12047
|
["CLAUDE_CODE", "claude-code"],
|
|
@@ -11817,6 +12068,9 @@ const detectCiProvider = () => {
|
|
|
11817
12068
|
for (const [environmentVariable, provider] of CI_PROVIDER_BY_ENVIRONMENT_VARIABLE) if (process.env[environmentVariable]) return provider;
|
|
11818
12069
|
return isCiFlagSet(process.env.CI) ? "unknown" : null;
|
|
11819
12070
|
};
|
|
12071
|
+
const isOfficialGithubAction = () => Boolean(process.env[GITHUB_ACTION_MARKER_ENVIRONMENT_VARIABLE]);
|
|
12072
|
+
const detectCiEventName = () => process.env.GITHUB_EVENT_NAME?.trim() || null;
|
|
12073
|
+
const detectRunnerOs = () => process.env.RUNNER_OS?.trim() || null;
|
|
11820
12074
|
const detectCodingAgentFromValue = () => {
|
|
11821
12075
|
for (const environmentVariable of CODING_AGENT_ENVIRONMENT_VALUE_VARIABLES) {
|
|
11822
12076
|
const value = process.env[environmentVariable]?.toLowerCase();
|
|
@@ -11857,8 +12111,9 @@ const isNonInteractiveEnvironment = () => NON_INTERACTIVE_ENVIRONMENT_VARIABLES.
|
|
|
11857
12111
|
//#endregion
|
|
11858
12112
|
//#region src/cli/utils/constants.ts
|
|
11859
12113
|
const STAGED_FILES_TEMP_DIR_PREFIX = "react-doctor-staged-";
|
|
11860
|
-
const
|
|
11861
|
-
const
|
|
12114
|
+
const BASELINE_FILES_TEMP_DIR_PREFIX = "react-doctor-baseline-";
|
|
12115
|
+
const CI_TRUST_COMPANIES = "PayPal, Rippling, and Alibaba";
|
|
12116
|
+
const WELCOME_EXPLANATION_HOLD_MS = 1e3;
|
|
11862
12117
|
const CATEGORY_COUNTUP_SETTLE_HOLD_MS = 1e3;
|
|
11863
12118
|
const INTERNAL_ERROR_JSON_FALLBACK = "{\"schemaVersion\":1,\"ok\":false,\"error\":{\"message\":\"Internal error\",\"name\":\"Error\",\"chain\":[]}}\n";
|
|
11864
12119
|
const SENTRY_FLUSH_TIMEOUT_MS = 2e3;
|
|
@@ -11874,6 +12129,7 @@ const METRIC = {
|
|
|
11874
12129
|
scanScore: "scan.score",
|
|
11875
12130
|
scanClean: "scan.clean",
|
|
11876
12131
|
scanCheckSkipped: "scan.check_skipped",
|
|
12132
|
+
baselineDegraded: "baseline.degraded",
|
|
11877
12133
|
ruleFired: "rule.fired",
|
|
11878
12134
|
lintFailed: "lint.failed",
|
|
11879
12135
|
deadCodeFailed: "deadcode.failed",
|
|
@@ -11888,7 +12144,11 @@ const METRIC = {
|
|
|
11888
12144
|
installAgentHooks: "install.agent_hooks",
|
|
11889
12145
|
installDependency: "install.dependency",
|
|
11890
12146
|
rulesChanged: "rules.changed",
|
|
11891
|
-
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"
|
|
11892
12152
|
};
|
|
11893
12153
|
//#endregion
|
|
11894
12154
|
//#region src/cli/utils/noop-console.ts
|
|
@@ -11931,7 +12191,7 @@ const makeNoopConsole = () => ({
|
|
|
11931
12191
|
});
|
|
11932
12192
|
//#endregion
|
|
11933
12193
|
//#region src/cli/utils/version.ts
|
|
11934
|
-
const VERSION = "0.
|
|
12194
|
+
const VERSION = "0.3.0-dev.7593271";
|
|
11935
12195
|
//#endregion
|
|
11936
12196
|
//#region src/cli/utils/json-mode.ts
|
|
11937
12197
|
let context = null;
|
|
@@ -11989,7 +12249,7 @@ const writeJsonReport = (report) => {
|
|
|
11989
12249
|
const serialized = context?.compact ? JSON.stringify(report) : JSON.stringify(report, null, 2);
|
|
11990
12250
|
process.stdout.write(`${serialized}\n`);
|
|
11991
12251
|
};
|
|
11992
|
-
const writeJsonErrorReport = (error) => {
|
|
12252
|
+
const writeJsonErrorReport = (error, sentryEventId) => {
|
|
11993
12253
|
if (!context) return;
|
|
11994
12254
|
try {
|
|
11995
12255
|
writeJsonReport(buildJsonReportError({
|
|
@@ -11997,13 +12257,21 @@ const writeJsonErrorReport = (error) => {
|
|
|
11997
12257
|
directory: context.directory,
|
|
11998
12258
|
error,
|
|
11999
12259
|
elapsedMilliseconds: performance.now() - context.startTime,
|
|
12000
|
-
mode: context.mode
|
|
12260
|
+
mode: context.mode,
|
|
12261
|
+
sentryEventId
|
|
12001
12262
|
}));
|
|
12002
12263
|
} catch {
|
|
12003
12264
|
process.stdout.write(INTERNAL_ERROR_JSON_FALLBACK);
|
|
12004
12265
|
}
|
|
12005
12266
|
};
|
|
12006
12267
|
//#endregion
|
|
12268
|
+
//#region src/cli/utils/run-id.ts
|
|
12269
|
+
let cachedRunId;
|
|
12270
|
+
const getRunId = () => {
|
|
12271
|
+
cachedRunId ??= randomUUID();
|
|
12272
|
+
return cachedRunId;
|
|
12273
|
+
};
|
|
12274
|
+
//#endregion
|
|
12007
12275
|
//#region src/cli/utils/scrub-sensitive-text.ts
|
|
12008
12276
|
const HOME_DIRECTORY = os.homedir();
|
|
12009
12277
|
const USER_HOME_PATTERNS = [/[A-Za-z]:[\\/]Users[\\/][^\\/]+/gi, /(?:\/Users\/|\/home\/)[^/\\]+/gi];
|
|
@@ -12058,6 +12326,7 @@ const buildRunContext = () => {
|
|
|
12058
12326
|
const userArguments = process.argv.slice(2);
|
|
12059
12327
|
return {
|
|
12060
12328
|
version: VERSION,
|
|
12329
|
+
runId: getRunId(),
|
|
12061
12330
|
origin: detectOrigin(),
|
|
12062
12331
|
command: detectCommand(userArguments),
|
|
12063
12332
|
argv: scrubSensitivePaths(userArguments.join(" ")),
|
|
@@ -12068,6 +12337,8 @@ const buildRunContext = () => {
|
|
|
12068
12337
|
arch: process.arch,
|
|
12069
12338
|
ci: isCiEnvironment(),
|
|
12070
12339
|
ciProvider: detectCiProvider(),
|
|
12340
|
+
eventName: detectCiEventName(),
|
|
12341
|
+
viaAction: isOfficialGithubAction(),
|
|
12071
12342
|
codingAgent: detectCodingAgent(),
|
|
12072
12343
|
interactive: !isNonInteractiveEnvironment(),
|
|
12073
12344
|
jsonMode: isJsonModeActive(),
|
|
@@ -12136,6 +12407,8 @@ const buildSentryScope = (runContext = buildRunContext()) => {
|
|
|
12136
12407
|
command: runContext.command,
|
|
12137
12408
|
ci: runContext.ci,
|
|
12138
12409
|
ciProvider: runContext.ciProvider,
|
|
12410
|
+
eventName: runContext.eventName,
|
|
12411
|
+
viaAction: runContext.viaAction,
|
|
12139
12412
|
codingAgent: runContext.codingAgent,
|
|
12140
12413
|
interactive: runContext.interactive,
|
|
12141
12414
|
jsonMode: runContext.jsonMode,
|
|
@@ -12256,15 +12529,14 @@ const scrubSentryMetric = (metric) => {
|
|
|
12256
12529
|
}
|
|
12257
12530
|
};
|
|
12258
12531
|
//#endregion
|
|
12259
|
-
//#region src/
|
|
12260
|
-
|
|
12261
|
-
|
|
12262
|
-
|
|
12263
|
-
|
|
12264
|
-
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
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
|
+
*/
|
|
12268
12540
|
/**
|
|
12269
12541
|
* A version is a "dev" build when it's the unbuilt placeholder (`0.0.0`) or
|
|
12270
12542
|
* carries a prerelease suffix (e.g. the `-dev.<sha>` snapshots published from
|
|
@@ -12277,13 +12549,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12277
12549
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12278
12550
|
* standard `SENTRY_RELEASE` override.
|
|
12279
12551
|
*/
|
|
12280
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.
|
|
12552
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.3.0-dev.7593271`;
|
|
12281
12553
|
/**
|
|
12282
12554
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12283
12555
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12284
12556
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12285
12557
|
*/
|
|
12286
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.
|
|
12558
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.3.0-dev.7593271") ? "development" : "production");
|
|
12287
12559
|
/**
|
|
12288
12560
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12289
12561
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -12297,6 +12569,16 @@ const resolveTracesSampleRate = () => {
|
|
|
12297
12569
|
if (Number.isNaN(parsed) || parsed < 0 || parsed > 1) return 1;
|
|
12298
12570
|
return parsed;
|
|
12299
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";
|
|
12300
12582
|
/**
|
|
12301
12583
|
* Whether performance traces will actually be recorded — Sentry is live and the
|
|
12302
12584
|
* resolved sample rate is above zero. Used to gate the per-run root span and
|
|
@@ -15448,6 +15730,7 @@ const noopHandle = Object.freeze({
|
|
|
15448
15730
|
update: () => {},
|
|
15449
15731
|
succeed: () => {},
|
|
15450
15732
|
fail: () => {},
|
|
15733
|
+
warn: () => {},
|
|
15451
15734
|
stop: () => {}
|
|
15452
15735
|
});
|
|
15453
15736
|
const spinner = (text) => ({ start() {
|
|
@@ -15478,6 +15761,11 @@ const spinner = (text) => ({ start() {
|
|
|
15478
15761
|
didFinalize = true;
|
|
15479
15762
|
instance.fail(displayText);
|
|
15480
15763
|
},
|
|
15764
|
+
warn(displayText) {
|
|
15765
|
+
if (didFinalize) return;
|
|
15766
|
+
didFinalize = true;
|
|
15767
|
+
instance.warn(displayText);
|
|
15768
|
+
},
|
|
15481
15769
|
stop() {
|
|
15482
15770
|
if (didFinalize) return;
|
|
15483
15771
|
didFinalize = true;
|
|
@@ -15732,6 +16020,7 @@ const recordScanMetrics = (input) => {
|
|
|
15732
16020
|
if (result.diagnostics.length === 0 && !hasSkippedChecks) recordCount(METRIC.scanClean, 1, { mode: input.mode });
|
|
15733
16021
|
if (result.score) recordDistribution(METRIC.scanScore, result.score.score, { attributes: { mode: input.mode } });
|
|
15734
16022
|
else if (!input.noScore && !input.didLintFail) recordCount(METRIC.scoreUnavailable, 1, { mode: input.mode });
|
|
16023
|
+
if (input.baselineDegraded) recordCount(METRIC.baselineDegraded, 1);
|
|
15735
16024
|
if (input.didLintFail) recordCount(METRIC.lintFailed, 1, { reasonKind: input.lintFailureReasonKind });
|
|
15736
16025
|
if (input.didDeadCodeFail) recordCount(METRIC.deadCodeFailed, 1);
|
|
15737
16026
|
for (const check of result.skippedChecks) recordCount(METRIC.scanCheckSkipped, 1, {
|
|
@@ -15740,6 +16029,271 @@ const recordScanMetrics = (input) => {
|
|
|
15740
16029
|
});
|
|
15741
16030
|
};
|
|
15742
16031
|
//#endregion
|
|
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
|
+
}
|
|
16065
|
+
};
|
|
16066
|
+
//#endregion
|
|
16067
|
+
//#region src/cli/utils/resolve-blocking-level.ts
|
|
16068
|
+
const VALID_BLOCKING_LEVELS = new Set([
|
|
16069
|
+
"error",
|
|
16070
|
+
"warning",
|
|
16071
|
+
"none"
|
|
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
|
|
16100
|
+
const readEnvBoolean = (name) => {
|
|
16101
|
+
const value = process.env[name];
|
|
16102
|
+
if (value === void 0) return null;
|
|
16103
|
+
return value.toLowerCase() === "true" || value === "1";
|
|
16104
|
+
};
|
|
16105
|
+
const resolveVersionPin = (versionInput) => {
|
|
16106
|
+
if (versionInput === void 0 || versionInput.trim() === "") return null;
|
|
16107
|
+
if (versionInput === "latest") return "latest";
|
|
16108
|
+
if (/^(\.\.?\/|\/)/.test(versionInput)) return "local";
|
|
16109
|
+
return "pinned";
|
|
16110
|
+
};
|
|
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";
|
|
16115
|
+
};
|
|
16116
|
+
const buildOutcomeAttributes = (input) => {
|
|
16117
|
+
if (input.result === void 0) {
|
|
16118
|
+
const error = input.error;
|
|
16119
|
+
const known = isReactDoctorError(error);
|
|
16120
|
+
return {
|
|
16121
|
+
outcome: "error",
|
|
16122
|
+
exitCode: 1,
|
|
16123
|
+
knownError: known,
|
|
16124
|
+
errorTag: known ? error.reason._tag : error instanceof Error ? error.name : null
|
|
16125
|
+
};
|
|
16126
|
+
}
|
|
16127
|
+
const result = input.result;
|
|
16128
|
+
const summary = summarizeDiagnostics(result.diagnostics);
|
|
16129
|
+
const blockingLevel = resolveTelemetryBlocking(input.userConfig);
|
|
16130
|
+
const gateDiagnostics = filterDiagnosticsForSurface(result.diagnostics, "ciFailure", input.userConfig);
|
|
16131
|
+
const wouldBlock = !input.scoreOnly && !input.gateExempt && shouldBlockCi(gateDiagnostics, blockingLevel);
|
|
16132
|
+
const hasSkippedChecks = result.skippedChecks.length > 0;
|
|
16133
|
+
const isClean = result.diagnostics.length === 0 && !hasSkippedChecks;
|
|
16134
|
+
const outcome = wouldBlock ? "blocked" : isClean ? "clean" : "ok";
|
|
16135
|
+
const firings = summarizeRuleFirings(result.diagnostics);
|
|
16136
|
+
const countByRule = /* @__PURE__ */ new Map();
|
|
16137
|
+
const countByCategory = /* @__PURE__ */ new Map();
|
|
16138
|
+
for (const firing of firings) {
|
|
16139
|
+
countByRule.set(firing.rule, (countByRule.get(firing.rule) ?? 0) + firing.count);
|
|
16140
|
+
countByCategory.set(firing.category, (countByCategory.get(firing.category) ?? 0) + firing.count);
|
|
16141
|
+
}
|
|
16142
|
+
let topRule = null;
|
|
16143
|
+
let topRuleCount = 0;
|
|
16144
|
+
for (const [rule, count] of countByRule) if (count > topRuleCount) {
|
|
16145
|
+
topRule = rule;
|
|
16146
|
+
topRuleCount = count;
|
|
16147
|
+
}
|
|
16148
|
+
const attributes = {
|
|
16149
|
+
outcome,
|
|
16150
|
+
exitCode: wouldBlock ? 1 : 0,
|
|
16151
|
+
wouldBlock,
|
|
16152
|
+
blocking: blockingLevel,
|
|
16153
|
+
scanClean: isClean,
|
|
16154
|
+
totalDiagnostics: summary.totalDiagnosticCount,
|
|
16155
|
+
errorCount: summary.errorCount,
|
|
16156
|
+
warningCount: summary.warningCount,
|
|
16157
|
+
affectedFiles: summary.affectedFileCount,
|
|
16158
|
+
distinctRulesFired: countByRule.size,
|
|
16159
|
+
topRule,
|
|
16160
|
+
scannedFileCount: result.scannedFileCount ?? null,
|
|
16161
|
+
elapsedMs: result.elapsedMilliseconds,
|
|
16162
|
+
scanPhaseMs: result.scanElapsedMilliseconds ?? null,
|
|
16163
|
+
score: result.score ? result.score.score : null,
|
|
16164
|
+
scoreLabel: result.score ? result.score.label : null,
|
|
16165
|
+
scoreAvailable: result.score !== null,
|
|
16166
|
+
skippedCheckCount: result.skippedChecks.length,
|
|
16167
|
+
didLintFail: input.didLintFail ?? null,
|
|
16168
|
+
lintFailureReasonKind: input.lintFailureReasonKind ?? null,
|
|
16169
|
+
lintPartialFailureCount: input.lintPartialFailureCount ?? null,
|
|
16170
|
+
didDeadCodeFail: input.didDeadCodeFail ?? null
|
|
16171
|
+
};
|
|
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;
|
|
16179
|
+
return attributes;
|
|
16180
|
+
};
|
|
16181
|
+
const buildCiAttributes = () => {
|
|
16182
|
+
const { githubActorAssociation } = resolveGithubActionsScoreMetadata();
|
|
16183
|
+
return {
|
|
16184
|
+
actorAssociation: githubActorAssociation ?? null,
|
|
16185
|
+
runnerOs: detectRunnerOs(),
|
|
16186
|
+
comment: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.comment),
|
|
16187
|
+
reviewComments: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.reviewComments),
|
|
16188
|
+
versionPin: resolveVersionPin(process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.version])
|
|
16189
|
+
};
|
|
16190
|
+
};
|
|
16191
|
+
const buildConfigAttributes = (input) => {
|
|
16192
|
+
const ruleOverrides = input.userConfig?.rules ?? {};
|
|
16193
|
+
const ruleKeys = Object.keys(ruleOverrides);
|
|
16194
|
+
return {
|
|
16195
|
+
mode: input.mode,
|
|
16196
|
+
parallel: input.parallel,
|
|
16197
|
+
workerCount: input.workerCount ?? null,
|
|
16198
|
+
lint: input.lint,
|
|
16199
|
+
deadCode: input.deadCode,
|
|
16200
|
+
scoreOnly: input.scoreOnly,
|
|
16201
|
+
noScore: input.noScore,
|
|
16202
|
+
respectInlineDisables: input.respectInlineDisables,
|
|
16203
|
+
showWarnings: input.showWarnings,
|
|
16204
|
+
ignoredTagCount: input.ignoredTagCount,
|
|
16205
|
+
hasCustomConfig: input.hasCustomConfig,
|
|
16206
|
+
rulesConfigured: ruleKeys.length,
|
|
16207
|
+
rulesDisabled: ruleKeys.filter((key) => ruleOverrides[key] === "off").length
|
|
16208
|
+
};
|
|
16209
|
+
};
|
|
16210
|
+
/**
|
|
16211
|
+
* Projects a scan into the flat attribute set for its root span — the canonical
|
|
16212
|
+
* per-scan "wide event". Pure and exported so the projection (outcome
|
|
16213
|
+
* precedence, rule/category rollups, CI knobs, config shape) is unit-testable
|
|
16214
|
+
* without a live Sentry client. `null` values are dropped so absent signals
|
|
16215
|
+
* never become misleading `"null"` attributes. The run + project base context
|
|
16216
|
+
* (version, command, ci/provider, framework, …) is already on the span from
|
|
16217
|
+
* `withSentryRunSpan` / `recordSentryProjectContext`, so this adds only what
|
|
16218
|
+
* those don't carry.
|
|
16219
|
+
*/
|
|
16220
|
+
const buildRunEventAttributes = (input) => toSpanAttributes({
|
|
16221
|
+
...buildConfigAttributes(input),
|
|
16222
|
+
...buildCiAttributes(),
|
|
16223
|
+
...buildOutcomeAttributes(input)
|
|
16224
|
+
});
|
|
16225
|
+
/**
|
|
16226
|
+
* Stamps the wide-event attributes onto the run's root span. A guarded no-op
|
|
16227
|
+
* when tracing is off (no `rootSpan`) and swallow-on-throw, so telemetry can
|
|
16228
|
+
* never break the run.
|
|
16229
|
+
*/
|
|
16230
|
+
const recordRunEvent = (rootSpan, input) => {
|
|
16231
|
+
if (!rootSpan) return;
|
|
16232
|
+
try {
|
|
16233
|
+
rootSpan.setAttributes(buildRunEventAttributes(input));
|
|
16234
|
+
} catch {}
|
|
16235
|
+
};
|
|
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
|
|
15743
16297
|
//#region src/cli/utils/build-no-score-message.ts
|
|
15744
16298
|
const ENTERPRISE_CONTACT_HINT = `Want something custom to your company? Contact us at ${ENTERPRISE_CONTACT_URL}.`;
|
|
15745
16299
|
const buildNoScoreMessage = (isScoreDisabled) => {
|
|
@@ -15840,10 +16394,10 @@ const boxText = (content, innerWidth) => {
|
|
|
15840
16394
|
*/
|
|
15841
16395
|
const buildCodeFrame = (input) => {
|
|
15842
16396
|
if (input.line <= 0) return null;
|
|
15843
|
-
const absolutePath = path.isAbsolute(input.filePath) ? input.filePath : path.resolve(input.rootDirectory || ".", input.filePath);
|
|
16397
|
+
const absolutePath = path$1.isAbsolute(input.filePath) ? input.filePath : path$1.resolve(input.rootDirectory || ".", input.filePath);
|
|
15844
16398
|
let source;
|
|
15845
16399
|
try {
|
|
15846
|
-
source = fs.readFileSync(absolutePath, "utf8");
|
|
16400
|
+
source = fs$1.readFileSync(absolutePath, "utf8");
|
|
15847
16401
|
} catch {
|
|
15848
16402
|
return null;
|
|
15849
16403
|
}
|
|
@@ -15931,17 +16485,21 @@ const formatTrailingSiteBadge = (count) => {
|
|
|
15931
16485
|
const badge = formatSiteCountBadge(count);
|
|
15932
16486
|
return badge.length > 0 ? ` ${highlighter.gray(badge)}` : "";
|
|
15933
16487
|
};
|
|
15934
|
-
const
|
|
16488
|
+
const CATEGORY_DISPLAY_RANK = new Map(DIAGNOSTIC_CATEGORY_BUCKETS.map((category, index) => [category, index]));
|
|
16489
|
+
const compareCategoriesByDisplayRank = (categoryA, categoryB) => {
|
|
16490
|
+
const rankA = CATEGORY_DISPLAY_RANK.get(categoryA);
|
|
16491
|
+
const rankB = CATEGORY_DISPLAY_RANK.get(categoryB);
|
|
16492
|
+
if (rankA !== void 0 && rankB !== void 0) return rankA - rankB;
|
|
16493
|
+
if (rankA !== void 0) return -1;
|
|
16494
|
+
if (rankB !== void 0) return 1;
|
|
16495
|
+
return categoryA.localeCompare(categoryB);
|
|
16496
|
+
};
|
|
15935
16497
|
const buildCategoryDiagnosticGroups = (diagnostics, rulePriority) => {
|
|
15936
16498
|
return [...groupBy(diagnostics, (diagnostic) => diagnostic.category).entries()].map(([category, categoryDiagnostics]) => ({
|
|
15937
16499
|
category,
|
|
15938
16500
|
diagnostics: categoryDiagnostics,
|
|
15939
16501
|
ruleGroups: buildSortedRuleGroups(categoryDiagnostics, rulePriority)
|
|
15940
|
-
})).toSorted((categoryGroupA, categoryGroupB) =>
|
|
15941
|
-
const priorityDelta = compareByRulePriority(categoryTopRuleKey(categoryGroupA), categoryTopRuleKey(categoryGroupB), rulePriority);
|
|
15942
|
-
if (priorityDelta !== 0) return priorityDelta;
|
|
15943
|
-
return categoryGroupA.category.localeCompare(categoryGroupB.category);
|
|
15944
|
-
});
|
|
16502
|
+
})).toSorted((categoryGroupA, categoryGroupB) => compareCategoriesByDisplayRank(categoryGroupA.category, categoryGroupB.category));
|
|
15945
16503
|
};
|
|
15946
16504
|
const formatCategoryTallyLine = (tally, errorShown, warningShown) => {
|
|
15947
16505
|
const parts = [];
|
|
@@ -16044,7 +16602,7 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
|
|
|
16044
16602
|
const fixRecipeLine = formatFixRecipeLine(representative);
|
|
16045
16603
|
if (fixRecipeLine) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${fixRecipeLine}`));
|
|
16046
16604
|
}
|
|
16047
|
-
const renderCodeFrame = severity === "error"
|
|
16605
|
+
const renderCodeFrame = severity === "error";
|
|
16048
16606
|
const sites = renderEverySite ? ruleDiagnostics : [representative];
|
|
16049
16607
|
for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame));
|
|
16050
16608
|
return lines;
|
|
@@ -16055,19 +16613,8 @@ const buildOverflowSummaryLine = (diagnostics, rulePriority) => {
|
|
|
16055
16613
|
const errorRuleGroups = selectErrorRuleGroups(diagnostics, rulePriority);
|
|
16056
16614
|
const shownErrorRuleCount = Math.min(3, errorRuleGroups.length);
|
|
16057
16615
|
if (diagnostics.length <= shownErrorRuleCount) return void 0;
|
|
16058
|
-
const hiddenErrorRuleCount = errorRuleGroups.length - shownErrorRuleCount;
|
|
16059
|
-
const warningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
|
|
16060
|
-
const parts = [];
|
|
16061
|
-
if (hiddenErrorRuleCount > 0) {
|
|
16062
|
-
const ruleNoun = hiddenErrorRuleCount === 1 ? "rule" : "rules";
|
|
16063
|
-
parts.push(highlighter.bold(highlighter.error(`+${hiddenErrorRuleCount} more ${ruleNoun}`)));
|
|
16064
|
-
}
|
|
16065
|
-
if (warningCount > 0) {
|
|
16066
|
-
const warningNoun = warningCount === 1 ? "warning" : "warnings";
|
|
16067
|
-
parts.push(highlighter.bold(highlighter.warn(`+${warningCount} optional ${warningNoun}`)));
|
|
16068
|
-
}
|
|
16069
16616
|
const command = highlighter.bold(highlighter.info("npx react-doctor@latest --verbose"));
|
|
16070
|
-
return ` ${
|
|
16617
|
+
return ` ${highlighter.dim("Run")} ${command} ${highlighter.dim("to list every error and warning")}`;
|
|
16071
16618
|
};
|
|
16072
16619
|
const getTopErrorRuleKeys = (diagnostics, limit, rulePriority) => new Set(selectTopErrorRuleGroups(diagnostics, limit, rulePriority).map(([ruleKey]) => ruleKey));
|
|
16073
16620
|
const buildTopErrorsSection = (diagnostics, resolveSourceRoot, rulePriority) => {
|
|
@@ -16076,11 +16623,7 @@ const buildTopErrorsSection = (diagnostics, resolveSourceRoot, rulePriority) =>
|
|
|
16076
16623
|
lines: [],
|
|
16077
16624
|
blockOffsets: []
|
|
16078
16625
|
};
|
|
16079
|
-
const lines = [
|
|
16080
|
-
buildSectionDivider(),
|
|
16081
|
-
` ${highlighter.bold(`Top ${topRuleGroups.length} ${topRuleGroups.length === 1 ? "error" : "errors"} you should fix`)}`,
|
|
16082
|
-
""
|
|
16083
|
-
];
|
|
16626
|
+
const lines = [` ${highlighter.bold(`Top ${topRuleGroups.length} ${topRuleGroups.length === 1 ? "error" : "errors"} you should fix`)}`, ""];
|
|
16084
16627
|
const blockOffsets = [];
|
|
16085
16628
|
for (const [ruleKey, ruleDiagnostics] of topRuleGroups) {
|
|
16086
16629
|
blockOffsets.push(lines.length);
|
|
@@ -16110,12 +16653,11 @@ const joinSections = (...sections) => {
|
|
|
16110
16653
|
sectionStarts
|
|
16111
16654
|
};
|
|
16112
16655
|
};
|
|
16113
|
-
const
|
|
16656
|
+
const buildOverviewHeaderLines = (diagnostics) => {
|
|
16114
16657
|
const totalIssueCount = diagnostics.length;
|
|
16115
16658
|
if (totalIssueCount === 0) return [];
|
|
16116
|
-
const
|
|
16117
|
-
|
|
16118
|
-
return [` ${(errorCount > 0 ? highlighter.error : warningCount > 0 ? highlighter.warn : highlighter.dim)(`${totalIssueCount} ${totalIssueCount === 1 ? "issue" : "issues"}`)}`];
|
|
16659
|
+
const issueNoun = totalIssueCount === 1 ? "issue" : "issues";
|
|
16660
|
+
return [` ${highlighter.bold(`All ${totalIssueCount} ${issueNoun}`)}`];
|
|
16119
16661
|
};
|
|
16120
16662
|
/**
|
|
16121
16663
|
* Effect-typed diagnostics renderer. Internal helpers build the
|
|
@@ -16139,8 +16681,9 @@ const printDiagnostics = (diagnostics, isVerbose, sourceRoot, rulePriority, isAg
|
|
|
16139
16681
|
const overflowLine = isVerbose ? void 0 : buildOverflowSummaryLine(diagnostics, rulePriority);
|
|
16140
16682
|
const categoryTallies = buildCategoryDiagnosticGroups(diagnostics, rulePriority).map(buildCategoryTally);
|
|
16141
16683
|
const categoryLines = buildCategoryTallyLines(categoryTallies);
|
|
16142
|
-
const
|
|
16143
|
-
const
|
|
16684
|
+
const overviewDividerLines = detailLines.length > 0 && categoryLines.length > 0 ? [buildSectionDivider()] : [];
|
|
16685
|
+
const { lines, sectionStarts } = joinSections(detailLines, overviewDividerLines, buildOverviewHeaderLines(diagnostics), categoryLines, overflowLine ? [overflowLine] : []);
|
|
16686
|
+
const [detailStart, , , categoryStart] = sectionStarts;
|
|
16144
16687
|
const pauseBeforeLineIndices = detailStart == null ? /* @__PURE__ */ new Set() : new Set(topErrorBlockOffsets.map((offset) => detailStart + offset));
|
|
16145
16688
|
let lineIndex = 0;
|
|
16146
16689
|
while (lineIndex < lines.length) {
|
|
@@ -16438,10 +16981,13 @@ const printNoScoreHeader = (noScoreMessage) => Effect.gen(function* () {
|
|
|
16438
16981
|
//#endregion
|
|
16439
16982
|
//#region src/cli/utils/write-diagnostics-directory.ts
|
|
16440
16983
|
const writeDiagnosticsDirectory = (diagnostics) => {
|
|
16441
|
-
const outputDirectory = join(tmpdir(), `react-doctor-${randomUUID()}`);
|
|
16442
|
-
mkdirSync(outputDirectory, { recursive: true });
|
|
16443
|
-
for (const [ruleKey, ruleDiagnostics] of buildSortedRuleGroups(diagnostics))
|
|
16444
|
-
|
|
16984
|
+
const outputDirectory = path$1.join(tmpdir(), `react-doctor-${randomUUID()}`);
|
|
16985
|
+
fs$1.mkdirSync(outputDirectory, { recursive: true });
|
|
16986
|
+
for (const [ruleKey, ruleDiagnostics] of buildSortedRuleGroups(diagnostics)) {
|
|
16987
|
+
const fileName = ruleKey.replace(/\//g, "--") + ".txt";
|
|
16988
|
+
fs$1.writeFileSync(path$1.join(outputDirectory, fileName), formatRuleSummary(ruleKey, ruleDiagnostics));
|
|
16989
|
+
}
|
|
16990
|
+
fs$1.writeFileSync(path$1.join(outputDirectory, "diagnostics.json"), JSON.stringify(diagnostics));
|
|
16445
16991
|
return outputDirectory;
|
|
16446
16992
|
};
|
|
16447
16993
|
//#endregion
|
|
@@ -16491,41 +17037,6 @@ const printSummary = (input) => Effect.gen(function* () {
|
|
|
16491
17037
|
if (diagnosticsDirectory !== null && input.verbose) yield* Console.log(highlighter.gray(` Full diagnostics written to ${diagnosticsDirectory}`));
|
|
16492
17038
|
});
|
|
16493
17039
|
//#endregion
|
|
16494
|
-
//#region src/cli/utils/cli-logger.ts
|
|
16495
|
-
/**
|
|
16496
|
-
* Thin synchronous façade over Effect's `Console` module. Used by
|
|
16497
|
-
* the imperative CLI helper files (`select-projects`, `run-explain`,
|
|
16498
|
-
* `install-react-doctor`, the legacy paths in `cli/commands/inspect.ts`)
|
|
16499
|
-
* that aren't yet Effect-typed. Every call drains into a single
|
|
16500
|
-
* `Console.*` Effect via `Effect.runSync`, so the underlying logging
|
|
16501
|
-
* pipeline is identical to the canonical `yield* Console.log(...)`
|
|
16502
|
-
* call sites in the renderers. Convert callers to `Effect.gen` to
|
|
16503
|
-
* drop the bridge.
|
|
16504
|
-
*/
|
|
16505
|
-
const cliLogger = {
|
|
16506
|
-
log: (message) => {
|
|
16507
|
-
Effect.runSync(Console.log(message));
|
|
16508
|
-
},
|
|
16509
|
-
warn: (message) => {
|
|
16510
|
-
Effect.runSync(Console.warn(highlighter.warn(message)));
|
|
16511
|
-
},
|
|
16512
|
-
error: (message) => {
|
|
16513
|
-
Effect.runSync(Console.error(highlighter.error(message)));
|
|
16514
|
-
},
|
|
16515
|
-
info: (message) => {
|
|
16516
|
-
Effect.runSync(Console.info(highlighter.info(message)));
|
|
16517
|
-
},
|
|
16518
|
-
dim: (message) => {
|
|
16519
|
-
Effect.runSync(Console.log(highlighter.gray(message)));
|
|
16520
|
-
},
|
|
16521
|
-
success: (message) => {
|
|
16522
|
-
Effect.runSync(Console.log(highlighter.success(message)));
|
|
16523
|
-
},
|
|
16524
|
-
break: () => {
|
|
16525
|
-
Effect.runSync(Console.log(""));
|
|
16526
|
-
}
|
|
16527
|
-
};
|
|
16528
|
-
//#endregion
|
|
16529
17040
|
//#region src/cli/utils/should-auto-select-current-choice.ts
|
|
16530
17041
|
const shouldAutoSelectCurrentChoice = (choiceStates, cursor) => {
|
|
16531
17042
|
if (choiceStates.some((choiceState) => choiceState.selected)) return false;
|
|
@@ -16668,7 +17179,21 @@ const mergeInspectOptions = (inputOptions, userConfig) => ({
|
|
|
16668
17179
|
ignoredTags: buildIgnoredTags(userConfig),
|
|
16669
17180
|
outputSurface: inputOptions.outputSurface ?? "cli",
|
|
16670
17181
|
suppressRendering: inputOptions.suppressRendering ?? false,
|
|
16671
|
-
concurrency: inputOptions.concurrency
|
|
17182
|
+
concurrency: inputOptions.concurrency,
|
|
17183
|
+
baseline: inputOptions.baseline ?? null
|
|
17184
|
+
});
|
|
17185
|
+
const buildRunEventConfig = (options, userConfig, hasCustomConfig) => ({
|
|
17186
|
+
parallel: options.concurrency !== void 0,
|
|
17187
|
+
workerCount: options.concurrency,
|
|
17188
|
+
lint: options.lint,
|
|
17189
|
+
deadCode: options.deadCode,
|
|
17190
|
+
scoreOnly: options.scoreOnly,
|
|
17191
|
+
noScore: options.noScore,
|
|
17192
|
+
respectInlineDisables: options.respectInlineDisables,
|
|
17193
|
+
showWarnings: options.warnings,
|
|
17194
|
+
ignoredTagCount: options.ignoredTags.size,
|
|
17195
|
+
hasCustomConfig,
|
|
17196
|
+
userConfig
|
|
16672
17197
|
});
|
|
16673
17198
|
const inspect = async (directory, inputOptions = {}) => {
|
|
16674
17199
|
const startTime = performance.now();
|
|
@@ -16691,13 +17216,93 @@ const inspect = async (directory, inputOptions = {}) => {
|
|
|
16691
17216
|
const wasSpinnerSilent = isSpinnerSilent();
|
|
16692
17217
|
if (options.silent) setSpinnerSilent(true);
|
|
16693
17218
|
try {
|
|
16694
|
-
const result = await withSentryRunSpan((rootSentrySpan) =>
|
|
17219
|
+
const result = await withSentryRunSpan(async (rootSentrySpan) => {
|
|
17220
|
+
try {
|
|
17221
|
+
return await runInspectWithRuntime(scanDirectory, options, userConfig, hasConfigOverride, configSourceDirectory, startTime, rootSentrySpan);
|
|
17222
|
+
} catch (error) {
|
|
17223
|
+
recordRunEvent(rootSentrySpan, {
|
|
17224
|
+
...buildRunEventConfig(options, userConfig, userConfig !== null),
|
|
17225
|
+
mode: options.includePaths.length > 0 ? "diff" : "full",
|
|
17226
|
+
error
|
|
17227
|
+
});
|
|
17228
|
+
throw error;
|
|
17229
|
+
}
|
|
17230
|
+
});
|
|
16695
17231
|
resetSentryRunState();
|
|
16696
17232
|
return result;
|
|
16697
17233
|
} finally {
|
|
16698
17234
|
if (options.silent) setSpinnerSilent(wasSpinnerSilent);
|
|
16699
17235
|
}
|
|
16700
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
|
+
};
|
|
16701
17306
|
const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOverride, configSourceDirectory, startTime, rootSentrySpan) => {
|
|
16702
17307
|
const isDiffMode = options.includePaths.length > 0;
|
|
16703
17308
|
const resolvedNodeBinaryPath = await resolveOxlintNode(options.lint, options.scoreOnly || options.silent);
|
|
@@ -16726,6 +17331,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16726
17331
|
runDeadCode: options.deadCode,
|
|
16727
17332
|
isCi: options.isCi,
|
|
16728
17333
|
doctorVersion: VERSION,
|
|
17334
|
+
runId: getRunId(),
|
|
16729
17335
|
resolveLocalGithubViewerPermission: !options.noScore,
|
|
16730
17336
|
suppressScanSummary: options.suppressRendering
|
|
16731
17337
|
}, { beforeLint: (projectInfo, lintIncludePaths) => Effect.gen(function* () {
|
|
@@ -16747,7 +17353,23 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16747
17353
|
const lintFailureReason = lintBindingMissing ? `oxlint native binding not found for Node ${process.version}; expected one matching ${OXLINT_NODE_REQUIREMENT}` : output.lintFailureReason;
|
|
16748
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`)));
|
|
16749
17355
|
else runConsole(Console.error(highlighter.error(lintFailureReason)));
|
|
16750
|
-
|
|
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;
|
|
16751
17373
|
const score = didLintFail ? null : output.score;
|
|
16752
17374
|
const elapsedMilliseconds = performance.now() - startTime;
|
|
16753
17375
|
const forceOnboarding = isOnboardingForced();
|
|
@@ -16767,7 +17389,8 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16767
17389
|
directory: output.resolvedDirectory,
|
|
16768
17390
|
scannedFileCount: output.scannedFileCount,
|
|
16769
17391
|
scannedFilePaths: output.scannedFilePaths,
|
|
16770
|
-
scanElapsedMilliseconds: output.scanElapsedMilliseconds
|
|
17392
|
+
scanElapsedMilliseconds: output.scanElapsedMilliseconds,
|
|
17393
|
+
baselineDelta
|
|
16771
17394
|
};
|
|
16772
17395
|
const result = await Effect.runPromise(finalizeAndRender(finalizeInput).pipe(options.silent ? Effect.provideService(Console.Console, silentConsole) : (program) => program));
|
|
16773
17396
|
if (shouldRecordOnboarding({
|
|
@@ -16776,9 +17399,11 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16776
17399
|
verbose: options.verbose,
|
|
16777
17400
|
isNonInteractiveEnvironment: options.isNonInteractiveEnvironment
|
|
16778
17401
|
})) markOnboardingComplete();
|
|
17402
|
+
const scanMode = baselineDelta ? "baseline" : isDiffMode ? "diff" : "full";
|
|
16779
17403
|
recordScanMetrics({
|
|
16780
17404
|
result,
|
|
16781
|
-
mode:
|
|
17405
|
+
mode: scanMode,
|
|
17406
|
+
baselineDegraded,
|
|
16782
17407
|
parallel: options.concurrency !== void 0,
|
|
16783
17408
|
workerCount: options.concurrency,
|
|
16784
17409
|
lint: options.lint,
|
|
@@ -16789,10 +17414,20 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16789
17414
|
lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind,
|
|
16790
17415
|
didDeadCodeFail: output.didDeadCodeFail
|
|
16791
17416
|
});
|
|
17417
|
+
recordRunEvent(rootSentrySpan, {
|
|
17418
|
+
...buildRunEventConfig(options, userConfig, userConfig !== null),
|
|
17419
|
+
result,
|
|
17420
|
+
mode: scanMode,
|
|
17421
|
+
gateExempt: baselineDegraded,
|
|
17422
|
+
didLintFail,
|
|
17423
|
+
lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind,
|
|
17424
|
+
lintPartialFailureCount: output.lintPartialFailures.length,
|
|
17425
|
+
didDeadCodeFail: output.didDeadCodeFail
|
|
17426
|
+
});
|
|
16792
17427
|
return result;
|
|
16793
17428
|
};
|
|
16794
17429
|
const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
16795
|
-
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;
|
|
16796
17431
|
const { skippedChecks, skippedCheckReasons } = buildSkippedChecks({
|
|
16797
17432
|
didLintFail,
|
|
16798
17433
|
lintFailureReason,
|
|
@@ -16811,7 +17446,8 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
16811
17446
|
elapsedMilliseconds,
|
|
16812
17447
|
scannedFileCount,
|
|
16813
17448
|
scannedFilePaths,
|
|
16814
|
-
scanElapsedMilliseconds
|
|
17449
|
+
scanElapsedMilliseconds,
|
|
17450
|
+
...baselineDelta ? { baselineDelta } : {}
|
|
16815
17451
|
});
|
|
16816
17452
|
if (options.suppressRendering) return buildResult();
|
|
16817
17453
|
if (options.scoreOnly) {
|
|
@@ -17052,7 +17688,16 @@ const buildHandoffPayload = (input) => {
|
|
|
17052
17688
|
try {
|
|
17053
17689
|
diagnosticsDirectory = writeDiagnosticsDirectory([...input.diagnostics]);
|
|
17054
17690
|
} catch {}
|
|
17055
|
-
const lines = [
|
|
17691
|
+
const lines = [
|
|
17692
|
+
"Before fixing anything, first ask me whether I'd like to add React Doctor to CI so every pull request is scanned automatically. Explain that:",
|
|
17693
|
+
`- It's used by teams at ${CI_TRUST_COMPANIES}.`,
|
|
17694
|
+
"- I don't have to fix everything at once; CI keeps new PRs clean while I incrementally pay down the existing issues.",
|
|
17695
|
+
`- Setup guide: ${CI_URL}`,
|
|
17696
|
+
"If I say yes, run `npx react-doctor install` (or add the GitHub Actions workflow). Either way, then continue with the fixes below.",
|
|
17697
|
+
"",
|
|
17698
|
+
`Fix the top ${topGroups.length} React Doctor ${topGroups.length === 1 ? "issue" : "issues"} in ${input.projectName} on this pass — leave the rest for a follow-up.`,
|
|
17699
|
+
""
|
|
17700
|
+
];
|
|
17056
17701
|
topGroups.forEach(([ruleKey, ruleDiagnostics], index) => {
|
|
17057
17702
|
const representative = ruleDiagnostics[0];
|
|
17058
17703
|
const severityLabel = representative.severity === "error" ? "ERROR" : "WARN";
|
|
@@ -17076,16 +17721,16 @@ const buildHandoffPayload = (input) => {
|
|
|
17076
17721
|
//#region src/cli/utils/is-command-available.ts
|
|
17077
17722
|
const isWindows = process.platform === "win32";
|
|
17078
17723
|
const candidateFileNames = (command) => {
|
|
17079
|
-
if (!isWindows || path.extname(command)) return [command];
|
|
17724
|
+
if (!isWindows || path$1.extname(command)) return [command];
|
|
17080
17725
|
return [command, ...(process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean).map((extension) => `${command}${extension}`)];
|
|
17081
17726
|
};
|
|
17082
17727
|
const isCommandAvailable = (command) => {
|
|
17083
|
-
const pathDirectories = (process.env.PATH ?? "").split(path.delimiter).filter(Boolean);
|
|
17728
|
+
const pathDirectories = (process.env.PATH ?? "").split(path$1.delimiter).filter(Boolean);
|
|
17084
17729
|
for (const directory of pathDirectories) for (const fileName of candidateFileNames(command)) {
|
|
17085
|
-
const binaryPath = path.join(directory, fileName);
|
|
17730
|
+
const binaryPath = path$1.join(directory, fileName);
|
|
17086
17731
|
try {
|
|
17087
|
-
if (!statSync(binaryPath).isFile()) continue;
|
|
17088
|
-
if (!isWindows) accessSync(binaryPath, constants.X_OK);
|
|
17732
|
+
if (!fs$1.statSync(binaryPath).isFile()) continue;
|
|
17733
|
+
if (!isWindows) fs$1.accessSync(binaryPath, fs$1.constants.X_OK);
|
|
17089
17734
|
return true;
|
|
17090
17735
|
} catch {}
|
|
17091
17736
|
}
|
|
@@ -17122,7 +17767,7 @@ const VITE_PLUS_HOOKS_PATH = ".vite-hooks";
|
|
|
17122
17767
|
const LEFTHOOK_CONFIG_FILES = ["lefthook.yml", "lefthook.yaml"];
|
|
17123
17768
|
const PRE_COMMIT_CONFIG_FILE = ".pre-commit-config.yaml";
|
|
17124
17769
|
const OVERCOMMIT_CONFIG_FILE = ".overcommit.yml";
|
|
17125
|
-
const REACT_DOCTOR_COMMAND = "react-doctor --staged --
|
|
17770
|
+
const REACT_DOCTOR_COMMAND = "react-doctor --staged --blocking warning";
|
|
17126
17771
|
const NON_BLOCKING_REACT_DOCTOR_COMMAND = [
|
|
17127
17772
|
"react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\");",
|
|
17128
17773
|
`if ${REACT_DOCTOR_COMMAND} > "$react_doctor_output" 2>&1; then`,
|
|
@@ -17148,18 +17793,18 @@ const runGit = (projectRoot, args) => {
|
|
|
17148
17793
|
return null;
|
|
17149
17794
|
}
|
|
17150
17795
|
};
|
|
17151
|
-
const resolveGitPath = (baseDirectory, value) => path.isAbsolute(value) ? value : path.resolve(baseDirectory, value);
|
|
17796
|
+
const resolveGitPath = (baseDirectory, value) => path$1.isAbsolute(value) ? value : path$1.resolve(baseDirectory, value);
|
|
17152
17797
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17153
|
-
const getPackageJsonPath = (projectRoot) => path.join(projectRoot, PACKAGE_JSON_FILE_NAME);
|
|
17798
|
+
const getPackageJsonPath = (projectRoot) => path$1.join(projectRoot, PACKAGE_JSON_FILE_NAME);
|
|
17154
17799
|
const readPackageJson = (projectRoot) => {
|
|
17155
17800
|
try {
|
|
17156
|
-
return JSON.parse(readFileSync(getPackageJsonPath(projectRoot), "utf8"));
|
|
17801
|
+
return JSON.parse(fs$1.readFileSync(getPackageJsonPath(projectRoot), "utf8"));
|
|
17157
17802
|
} catch {
|
|
17158
17803
|
return null;
|
|
17159
17804
|
}
|
|
17160
17805
|
};
|
|
17161
17806
|
const writeJsonFile$1 = (filePath, value) => {
|
|
17162
|
-
writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
17807
|
+
fs$1.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
17163
17808
|
};
|
|
17164
17809
|
const packageHasDependency = (projectRoot, dependencyName) => {
|
|
17165
17810
|
const packageJson = readPackageJson(projectRoot);
|
|
@@ -17198,12 +17843,12 @@ const DEPENDENCY_FIELD_NAMES = [
|
|
|
17198
17843
|
];
|
|
17199
17844
|
const isReactDoctorScriptCommand = (value) => typeof value === "string" && /\breact-doctor\b/.test(value);
|
|
17200
17845
|
const findNearestPackageDirectory = (startDirectory, stopDirectory) => {
|
|
17201
|
-
let currentDirectory = path.resolve(startDirectory);
|
|
17202
|
-
const resolvedStopDirectory = stopDirectory === void 0 ? void 0 : path.resolve(stopDirectory);
|
|
17846
|
+
let currentDirectory = path$1.resolve(startDirectory);
|
|
17847
|
+
const resolvedStopDirectory = stopDirectory === void 0 ? void 0 : path$1.resolve(stopDirectory);
|
|
17203
17848
|
while (true) {
|
|
17204
|
-
if (existsSync(getPackageJsonPath(currentDirectory))) return currentDirectory;
|
|
17849
|
+
if (fs$1.existsSync(getPackageJsonPath(currentDirectory))) return currentDirectory;
|
|
17205
17850
|
if (currentDirectory === resolvedStopDirectory) return null;
|
|
17206
|
-
const parentDirectory = path.dirname(currentDirectory);
|
|
17851
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
17207
17852
|
if (parentDirectory === currentDirectory) return null;
|
|
17208
17853
|
currentDirectory = parentDirectory;
|
|
17209
17854
|
}
|
|
@@ -17293,24 +17938,24 @@ const CURSOR_HOOKS_SCHEMA_VERSION = 1;
|
|
|
17293
17938
|
const JSON_INDENT_SPACES$1 = 2;
|
|
17294
17939
|
const isSupportedAgent = (agent) => agent === CLAUDE_AGENT || agent === CURSOR_AGENT;
|
|
17295
17940
|
const readJsonFile = (filePath, fallback) => {
|
|
17296
|
-
if (!existsSync(filePath)) return fallback;
|
|
17297
|
-
const content = readFileSync(filePath, "utf8").trim();
|
|
17941
|
+
if (!fs$1.existsSync(filePath)) return fallback;
|
|
17942
|
+
const content = fs$1.readFileSync(filePath, "utf8").trim();
|
|
17298
17943
|
if (content.length === 0) return fallback;
|
|
17299
17944
|
return JSON.parse(content);
|
|
17300
17945
|
};
|
|
17301
17946
|
const writeJsonFile = (filePath, value) => {
|
|
17302
|
-
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
17303
|
-
writeFileSync(filePath, `${JSON.stringify(value, null, JSON_INDENT_SPACES$1)}\n`);
|
|
17947
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
17948
|
+
fs$1.writeFileSync(filePath, `${JSON.stringify(value, null, JSON_INDENT_SPACES$1)}\n`);
|
|
17304
17949
|
};
|
|
17305
17950
|
const writeHookScript = (filePath) => {
|
|
17306
|
-
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
17307
|
-
writeFileSync(filePath, buildAgentHookScript());
|
|
17308
|
-
chmodSync(filePath, 493);
|
|
17951
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
17952
|
+
fs$1.writeFileSync(filePath, buildAgentHookScript());
|
|
17953
|
+
fs$1.chmodSync(filePath, 493);
|
|
17309
17954
|
};
|
|
17310
17955
|
const hasClaudeHookCommand = (groups) => groups.some((group) => (group.hooks ?? []).some((hook) => hook.command === CLAUDE_HOOK_COMMAND));
|
|
17311
17956
|
const installClaudeHook = (projectRoot) => {
|
|
17312
|
-
const settingsPath = path.join(projectRoot, CLAUDE_SETTINGS_RELATIVE_PATH);
|
|
17313
|
-
const hookPath = path.join(projectRoot, CLAUDE_HOOK_RELATIVE_PATH);
|
|
17957
|
+
const settingsPath = path$1.join(projectRoot, CLAUDE_SETTINGS_RELATIVE_PATH);
|
|
17958
|
+
const hookPath = path$1.join(projectRoot, CLAUDE_HOOK_RELATIVE_PATH);
|
|
17314
17959
|
const settings = readJsonFile(settingsPath, {});
|
|
17315
17960
|
const hooks = { ...settings.hooks ?? {} };
|
|
17316
17961
|
const postToolBatchHooks = [...hooks.PostToolBatch ?? []];
|
|
@@ -17328,8 +17973,8 @@ const installClaudeHook = (projectRoot) => {
|
|
|
17328
17973
|
};
|
|
17329
17974
|
const hasCursorHookCommand = (handlers) => handlers.some((handler) => handler.command === CURSOR_HOOK_RELATIVE_PATH);
|
|
17330
17975
|
const installCursorHook = (projectRoot) => {
|
|
17331
|
-
const configPath = path.join(projectRoot, CURSOR_HOOKS_RELATIVE_PATH);
|
|
17332
|
-
const hookPath = path.join(projectRoot, CURSOR_HOOK_RELATIVE_PATH);
|
|
17976
|
+
const configPath = path$1.join(projectRoot, CURSOR_HOOKS_RELATIVE_PATH);
|
|
17977
|
+
const hookPath = path$1.join(projectRoot, CURSOR_HOOK_RELATIVE_PATH);
|
|
17333
17978
|
const config = readJsonFile(configPath, {});
|
|
17334
17979
|
const hooks = { ...config.hooks ?? {} };
|
|
17335
17980
|
const postToolUseHooks = [...hooks.postToolUse ?? []];
|
|
@@ -17391,22 +18036,22 @@ const buildAgentHookScript = () => [
|
|
|
17391
18036
|
"",
|
|
17392
18037
|
"run_react_doctor() {",
|
|
17393
18038
|
" if [ -x ./node_modules/.bin/react-doctor ]; then",
|
|
17394
|
-
" ./node_modules/.bin/react-doctor --verbose --diff --
|
|
18039
|
+
" ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
|
|
17395
18040
|
" return",
|
|
17396
18041
|
" fi",
|
|
17397
18042
|
"",
|
|
17398
18043
|
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
17399
|
-
" react-doctor --verbose --diff --
|
|
18044
|
+
" react-doctor --verbose --diff --blocking warning --no-score",
|
|
17400
18045
|
" return",
|
|
17401
18046
|
" fi",
|
|
17402
18047
|
"",
|
|
17403
18048
|
" if command -v pnpm >/dev/null 2>&1; then",
|
|
17404
|
-
" pnpm dlx react-doctor@latest --verbose --diff --
|
|
18049
|
+
" pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
17405
18050
|
" return",
|
|
17406
18051
|
" fi",
|
|
17407
18052
|
"",
|
|
17408
18053
|
" if command -v npx >/dev/null 2>&1; then",
|
|
17409
|
-
" npx --yes react-doctor@latest --verbose --diff --
|
|
18054
|
+
" npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
17410
18055
|
" return",
|
|
17411
18056
|
" fi",
|
|
17412
18057
|
"",
|
|
@@ -17465,6 +18110,102 @@ const installReactDoctorAgentHooks = (options) => {
|
|
|
17465
18110
|
};
|
|
17466
18111
|
};
|
|
17467
18112
|
//#endregion
|
|
18113
|
+
//#region src/cli/utils/install-github-workflow.ts
|
|
18114
|
+
const buildWorkflowContent = () => `# React Doctor — finds security, performance, correctness, accessibility,
|
|
18115
|
+
# bundle-size, and architecture issues in React codebases.
|
|
18116
|
+
#
|
|
18117
|
+
# Docs: https://www.react.doctor/ci
|
|
18118
|
+
# Source: https://github.com/millionco/react-doctor
|
|
18119
|
+
|
|
18120
|
+
name: React Doctor
|
|
18121
|
+
|
|
18122
|
+
on:
|
|
18123
|
+
pull_request:
|
|
18124
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
18125
|
+
# Scans \`main\` on every push so you get a health-score trend on the
|
|
18126
|
+
# default branch — useful for tracking the overall number commit-by-commit
|
|
18127
|
+
# and catching regressions that slipped past PR review. PR-specific steps
|
|
18128
|
+
# (the sticky summary comment) are skipped automatically on \`push\` events.
|
|
18129
|
+
# Comment this block out if you only want PR-time scans.
|
|
18130
|
+
push:
|
|
18131
|
+
branches: [main]
|
|
18132
|
+
|
|
18133
|
+
permissions:
|
|
18134
|
+
# \`actions/checkout\` needs this to read the repo source.
|
|
18135
|
+
contents: read
|
|
18136
|
+
# Two uses: (1) reads the PR's changed-file list so the scan only checks
|
|
18137
|
+
# what the PR touched (faster, scoped to the diff), and (2) posts/updates
|
|
18138
|
+
# the sticky React Doctor summary comment on the PR. Downgrade \`write\` to
|
|
18139
|
+
# \`read\` to keep the changed-file scan but disable comment posting.
|
|
18140
|
+
pull-requests: write
|
|
18141
|
+
# The sticky-comment step uses GitHub's \`issues.createComment\` /
|
|
18142
|
+
# \`issues.updateComment\` endpoints — those are the same APIs that back PR
|
|
18143
|
+
# comments (PRs are issues under the hood). Not exercised on \`push\`
|
|
18144
|
+
# events, so safe to drop if you only run on \`main\`.
|
|
18145
|
+
issues: write
|
|
18146
|
+
|
|
18147
|
+
# Cancels any in-flight scan for the same PR (or branch, on push) the moment
|
|
18148
|
+
# a new commit arrives, so reviewers only ever see the latest run.
|
|
18149
|
+
concurrency:
|
|
18150
|
+
group: react-doctor-\${{ github.event.pull_request.number || github.ref }}
|
|
18151
|
+
cancel-in-progress: true
|
|
18152
|
+
|
|
18153
|
+
jobs:
|
|
18154
|
+
react-doctor:
|
|
18155
|
+
runs-on: ubuntu-latest
|
|
18156
|
+
steps:
|
|
18157
|
+
- uses: actions/checkout@v5
|
|
18158
|
+
|
|
18159
|
+
- uses: millionco/react-doctor@v1
|
|
18160
|
+
# Common configuration knobs — uncomment any to override the default.
|
|
18161
|
+
# Full reference: https://www.react.doctor/ci
|
|
18162
|
+
# with:
|
|
18163
|
+
# non-blocking: true # Report findings but always exit 0 (won't fail the PR check)
|
|
18164
|
+
# fail-on: warning # Gate level: "error" (default) | "warning" | "none"
|
|
18165
|
+
# comment: false # Disable the sticky PR summary comment
|
|
18166
|
+
# annotations: false # Disable inline GitHub Actions annotations on changed files
|
|
18167
|
+
# version: "0.2.18" # Pin to a specific react-doctor version instead of "latest"
|
|
18168
|
+
# directory: apps/web # Scan a sub-directory (default: ".")
|
|
18169
|
+
# project: "web,admin" # In a monorepo, scan specific workspace project(s)
|
|
18170
|
+
`;
|
|
18171
|
+
const getReactDoctorWorkflowPath = (projectRoot) => path$1.join(projectRoot, ".github", "workflows", "react-doctor.yml");
|
|
18172
|
+
const isReactDoctorWorkflowInstalled = (projectRoot) => fs$1.existsSync(getReactDoctorWorkflowPath(projectRoot));
|
|
18173
|
+
const installReactDoctorWorkflow = (projectRoot) => {
|
|
18174
|
+
const workflowPath = getReactDoctorWorkflowPath(projectRoot);
|
|
18175
|
+
if (fs$1.existsSync(workflowPath)) return {
|
|
18176
|
+
status: "exists",
|
|
18177
|
+
workflowPath
|
|
18178
|
+
};
|
|
18179
|
+
try {
|
|
18180
|
+
fs$1.mkdirSync(path$1.dirname(workflowPath), { recursive: true });
|
|
18181
|
+
fs$1.writeFileSync(workflowPath, buildWorkflowContent());
|
|
18182
|
+
return {
|
|
18183
|
+
status: "created",
|
|
18184
|
+
workflowPath
|
|
18185
|
+
};
|
|
18186
|
+
} catch {
|
|
18187
|
+
return {
|
|
18188
|
+
status: "failed",
|
|
18189
|
+
workflowPath
|
|
18190
|
+
};
|
|
18191
|
+
}
|
|
18192
|
+
};
|
|
18193
|
+
//#endregion
|
|
18194
|
+
//#region src/cli/utils/report-workflow-result.ts
|
|
18195
|
+
const reportWorkflowResult = (workflowSpinner, result, projectRoot) => {
|
|
18196
|
+
if (result.status === "failed") {
|
|
18197
|
+
workflowSpinner.fail("Couldn't write the GitHub Actions workflow.");
|
|
18198
|
+
return false;
|
|
18199
|
+
}
|
|
18200
|
+
if (result.status === "exists") {
|
|
18201
|
+
workflowSpinner.succeed("GitHub Actions workflow already configured.");
|
|
18202
|
+
return false;
|
|
18203
|
+
}
|
|
18204
|
+
workflowSpinner.succeed(`GitHub Actions workflow added at ${path$1.relative(projectRoot, result.workflowPath)}.`);
|
|
18205
|
+
recordCount(METRIC.installWorkflow, 1);
|
|
18206
|
+
return true;
|
|
18207
|
+
};
|
|
18208
|
+
//#endregion
|
|
17468
18209
|
//#region src/cli/utils/install-git-hook-file.ts
|
|
17469
18210
|
const REACT_DOCTOR_BLOCK_START = "# react-doctor hook start";
|
|
17470
18211
|
const REACT_DOCTOR_BLOCK_END = "# react-doctor hook end";
|
|
@@ -17472,8 +18213,8 @@ const REACT_DOCTOR_BLOCK_PATTERN = new RegExp(`(?:${REACT_DOCTOR_BLOCK_START}[\\
|
|
|
17472
18213
|
const SHEBANG = "#!/bin/sh";
|
|
17473
18214
|
const SHEBANG_PREFIX = "#!";
|
|
17474
18215
|
const LOCAL_REACT_DOCTOR_BIN = "./node_modules/.bin/react-doctor";
|
|
17475
|
-
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --
|
|
17476
|
-
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --
|
|
18216
|
+
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --blocking warning";
|
|
18217
|
+
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --blocking warning";
|
|
17477
18218
|
const buildReactDoctorHookBlock = () => [
|
|
17478
18219
|
REACT_DOCTOR_BLOCK_START,
|
|
17479
18220
|
"react_doctor_scan_staged_files() {",
|
|
@@ -17526,23 +18267,23 @@ const mergeHookContent = (existingContent) => {
|
|
|
17526
18267
|
return `${SHEBANG}\n\n${hookBlock}${normalizedExistingContent}`;
|
|
17527
18268
|
};
|
|
17528
18269
|
const removeLegacyManagedRunner = (projectRoot) => {
|
|
17529
|
-
const runnerPath = path.join(projectRoot, LEGACY_HOOK_RUNNER_RELATIVE_PATH);
|
|
17530
|
-
rmSync(runnerPath, { force: true });
|
|
17531
|
-
for (const directory of [path.dirname(runnerPath), path.join(projectRoot, ".react-doctor")]) try {
|
|
17532
|
-
rmdirSync(directory);
|
|
18270
|
+
const runnerPath = path$1.join(projectRoot, LEGACY_HOOK_RUNNER_RELATIVE_PATH);
|
|
18271
|
+
fs$1.rmSync(runnerPath, { force: true });
|
|
18272
|
+
for (const directory of [path$1.dirname(runnerPath), path$1.join(projectRoot, ".react-doctor")]) try {
|
|
18273
|
+
fs$1.rmdirSync(directory);
|
|
17533
18274
|
} catch {}
|
|
17534
18275
|
};
|
|
17535
18276
|
const installDirectGitHook = (options) => {
|
|
17536
|
-
const didHookExist = existsSync(options.hookPath);
|
|
17537
|
-
const nextContent = mergeHookContent(didHookExist ? readFileSync(options.hookPath, "utf8") : "");
|
|
18277
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18278
|
+
const nextContent = mergeHookContent(didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "");
|
|
17538
18279
|
if (options.hooksPathConfig !== void 0) runGit(options.projectRoot, [
|
|
17539
18280
|
"config",
|
|
17540
18281
|
"core.hooksPath",
|
|
17541
18282
|
options.hooksPathConfig
|
|
17542
18283
|
]);
|
|
17543
|
-
mkdirSync(path.dirname(options.hookPath), { recursive: true });
|
|
17544
|
-
writeFileSync(options.hookPath, nextContent);
|
|
17545
|
-
chmodSync(options.hookPath, 493);
|
|
18284
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18285
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
18286
|
+
fs$1.chmodSync(options.hookPath, 493);
|
|
17546
18287
|
removeLegacyManagedRunner(options.projectRoot);
|
|
17547
18288
|
return {
|
|
17548
18289
|
hookPath: options.hookPath,
|
|
@@ -17554,15 +18295,15 @@ const installDirectGitHook = (options) => {
|
|
|
17554
18295
|
//#region src/cli/utils/install-git-hook-config-managers.ts
|
|
17555
18296
|
const appendStringCommand = (existingCommand) => {
|
|
17556
18297
|
const existingCommandText = typeof existingCommand === "string" ? existingCommand : Array.isArray(existingCommand) ? existingCommand.filter((entry) => typeof entry === "string").join("\n") : "";
|
|
17557
|
-
return existingCommandText.includes("react-doctor --staged --
|
|
18298
|
+
return existingCommandText.includes("react-doctor --staged --blocking warning") ? existingCommandText : [existingCommandText, NON_BLOCKING_REACT_DOCTOR_COMMAND].filter(Boolean).join("\n");
|
|
17558
18299
|
};
|
|
17559
18300
|
const appendArrayCommand = (existingCommands) => {
|
|
17560
18301
|
const commands = Array.isArray(existingCommands) ? existingCommands.filter((entry) => typeof entry === "string") : typeof existingCommands === "string" ? [existingCommands] : [];
|
|
17561
|
-
return commands.some((command) => command.includes("react-doctor --staged --
|
|
18302
|
+
return commands.some((command) => command.includes("react-doctor --staged --blocking warning")) ? commands : [...commands, NON_BLOCKING_REACT_DOCTOR_COMMAND];
|
|
17562
18303
|
};
|
|
17563
18304
|
const installPackageJsonHook = (options, strategy) => {
|
|
17564
18305
|
const packageJsonPath = getPackageJsonPath(options.projectRoot);
|
|
17565
|
-
const didHookExist = existsSync(packageJsonPath);
|
|
18306
|
+
const didHookExist = fs$1.existsSync(packageJsonPath);
|
|
17566
18307
|
const packageJson = readPackageJson(options.projectRoot);
|
|
17567
18308
|
const nextPackageJson = isRecord(packageJson) ? { ...packageJson } : {};
|
|
17568
18309
|
const parentKeys = strategy.path.slice(0, -1);
|
|
@@ -17675,12 +18416,12 @@ const appendLefthookCommand = (content) => {
|
|
|
17675
18416
|
return ensureTrailingNewline(`${normalizedContent.slice(0, insertIndex)}${insertBlock}${normalizedContent.slice(insertIndex)}`);
|
|
17676
18417
|
};
|
|
17677
18418
|
const installLefthook = (options) => {
|
|
17678
|
-
const didHookExist = existsSync(options.hookPath);
|
|
17679
|
-
const existingContent = didHookExist ? readFileSync(options.hookPath, "utf8") : "";
|
|
18419
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18420
|
+
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
17680
18421
|
if (!existingContent.includes("react-doctor")) {
|
|
17681
18422
|
const nextContent = appendLefthookCommand(existingContent);
|
|
17682
|
-
mkdirSync(path.dirname(options.hookPath), { recursive: true });
|
|
17683
|
-
writeFileSync(options.hookPath, nextContent);
|
|
18423
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18424
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
17684
18425
|
}
|
|
17685
18426
|
removeLegacyManagedRunner(options.projectRoot);
|
|
17686
18427
|
return {
|
|
@@ -17690,8 +18431,8 @@ const installLefthook = (options) => {
|
|
|
17690
18431
|
};
|
|
17691
18432
|
};
|
|
17692
18433
|
const installPreCommit = (options) => {
|
|
17693
|
-
const didHookExist = existsSync(options.hookPath);
|
|
17694
|
-
const existingContent = didHookExist ? readFileSync(options.hookPath, "utf8") : "";
|
|
18434
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18435
|
+
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
17695
18436
|
if (!existingContent.includes("id: react-doctor")) {
|
|
17696
18437
|
const hasReposKey = /^repos:\s*$/m.test(existingContent);
|
|
17697
18438
|
const localHookBlock = [
|
|
@@ -17705,8 +18446,8 @@ const installPreCommit = (options) => {
|
|
|
17705
18446
|
""
|
|
17706
18447
|
].join("\n");
|
|
17707
18448
|
const nextContent = hasReposKey ? `${ensureTrailingNewline(existingContent)}${localHookBlock}` : `repos:\n${localHookBlock}`;
|
|
17708
|
-
mkdirSync(path.dirname(options.hookPath), { recursive: true });
|
|
17709
|
-
writeFileSync(options.hookPath, nextContent);
|
|
18449
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18450
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
17710
18451
|
}
|
|
17711
18452
|
removeLegacyManagedRunner(options.projectRoot);
|
|
17712
18453
|
return {
|
|
@@ -17716,8 +18457,8 @@ const installPreCommit = (options) => {
|
|
|
17716
18457
|
};
|
|
17717
18458
|
};
|
|
17718
18459
|
const installOvercommit = (options) => {
|
|
17719
|
-
const didHookExist = existsSync(options.hookPath);
|
|
17720
|
-
const existingContent = didHookExist ? readFileSync(options.hookPath, "utf8") : "";
|
|
18460
|
+
const didHookExist = fs$1.existsSync(options.hookPath);
|
|
18461
|
+
const existingContent = didHookExist ? fs$1.readFileSync(options.hookPath, "utf8") : "";
|
|
17721
18462
|
if (!existingContent.includes("ReactDoctor")) {
|
|
17722
18463
|
const nextContent = appendIndentedBlockToTopLevelSection(existingContent, "PreCommit", [
|
|
17723
18464
|
" ReactDoctor:",
|
|
@@ -17725,8 +18466,8 @@ const installOvercommit = (options) => {
|
|
|
17725
18466
|
` command: ['sh', '-c', '${NON_BLOCKING_REACT_DOCTOR_COMMAND}']`,
|
|
17726
18467
|
""
|
|
17727
18468
|
]);
|
|
17728
|
-
mkdirSync(path.dirname(options.hookPath), { recursive: true });
|
|
17729
|
-
writeFileSync(options.hookPath, nextContent);
|
|
18469
|
+
fs$1.mkdirSync(path$1.dirname(options.hookPath), { recursive: true });
|
|
18470
|
+
fs$1.writeFileSync(options.hookPath, nextContent);
|
|
17730
18471
|
}
|
|
17731
18472
|
removeLegacyManagedRunner(options.projectRoot);
|
|
17732
18473
|
return {
|
|
@@ -17737,21 +18478,21 @@ const installOvercommit = (options) => {
|
|
|
17737
18478
|
};
|
|
17738
18479
|
//#endregion
|
|
17739
18480
|
//#region src/cli/utils/install-git-hook.ts
|
|
17740
|
-
const isHuskyProject = (projectRoot) => existsSync(path.join(projectRoot, ".husky")) || packageHasDependency(projectRoot, "husky");
|
|
18481
|
+
const isHuskyProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, ".husky")) || packageHasDependency(projectRoot, "husky");
|
|
17741
18482
|
const isVitePlusProject = (projectRoot) => packageHasDependency(projectRoot, "vite-plus");
|
|
17742
18483
|
const isSimpleGitHooksProject = (projectRoot) => {
|
|
17743
18484
|
const packageJson = readPackageJson(projectRoot);
|
|
17744
|
-
return isRecord(packageJson) && isRecord(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || existsSync(path.join(projectRoot, ".simple-git-hooks.cjs"));
|
|
18485
|
+
return isRecord(packageJson) && isRecord(packageJson["simple-git-hooks"]) || packageHasDependency(projectRoot, "simple-git-hooks") || fs$1.existsSync(path$1.join(projectRoot, ".simple-git-hooks.cjs"));
|
|
17745
18486
|
};
|
|
17746
18487
|
const getLefthookConfigPath = (projectRoot) => {
|
|
17747
18488
|
for (const fileName of LEFTHOOK_CONFIG_FILES) {
|
|
17748
|
-
const filePath = path.join(projectRoot, fileName);
|
|
17749
|
-
if (existsSync(filePath)) return filePath;
|
|
18489
|
+
const filePath = path$1.join(projectRoot, fileName);
|
|
18490
|
+
if (fs$1.existsSync(filePath)) return filePath;
|
|
17750
18491
|
}
|
|
17751
|
-
return packageHasDependency(projectRoot, "lefthook") ? path.join(projectRoot, LEFTHOOK_CONFIG_FILES[0] ?? "lefthook.yml") : null;
|
|
18492
|
+
return packageHasDependency(projectRoot, "lefthook") ? path$1.join(projectRoot, LEFTHOOK_CONFIG_FILES[0] ?? "lefthook.yml") : null;
|
|
17752
18493
|
};
|
|
17753
|
-
const isPreCommitProject = (projectRoot) => existsSync(path.join(projectRoot, PRE_COMMIT_CONFIG_FILE));
|
|
17754
|
-
const isOvercommitProject = (projectRoot) => existsSync(path.join(projectRoot, ".overcommit.yml")) || packageHasDependency(projectRoot, "overcommit");
|
|
18494
|
+
const isPreCommitProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, PRE_COMMIT_CONFIG_FILE));
|
|
18495
|
+
const isOvercommitProject = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, ".overcommit.yml")) || packageHasDependency(projectRoot, "overcommit");
|
|
17755
18496
|
const isYorkieProject = (projectRoot) => packageHasRecordKey(projectRoot, "gitHooks") || packageHasDependency(projectRoot, "yorkie");
|
|
17756
18497
|
const isGhooksProject = (projectRoot) => packageHasDependency(projectRoot, "ghooks") || packageHasNestedRecordKey(projectRoot, "config", "ghooks");
|
|
17757
18498
|
const isGitHooksJsProject = (projectRoot) => packageHasRecordKey(projectRoot, "git-hooks") || packageHasDependency(projectRoot, "git-hooks-js");
|
|
@@ -17767,24 +18508,24 @@ const detectGitHookTarget = (projectRoot) => {
|
|
|
17767
18508
|
"core.hooksPath"
|
|
17768
18509
|
]);
|
|
17769
18510
|
if (configuredHooksPath !== null && configuredHooksPath.length > 0) return {
|
|
17770
|
-
hookPath: path.join(resolveGitPath(topLevel, configuredHooksPath), HOOK_FILE_NAME),
|
|
18511
|
+
hookPath: path$1.join(resolveGitPath(topLevel, configuredHooksPath), HOOK_FILE_NAME),
|
|
17771
18512
|
runnerRoot: topLevel,
|
|
17772
18513
|
kind: "configured"
|
|
17773
18514
|
};
|
|
17774
18515
|
if (isHuskyProject(topLevel)) return {
|
|
17775
|
-
hookPath: path.join(topLevel, HUSKY_HOOKS_PATH, HOOK_FILE_NAME),
|
|
18516
|
+
hookPath: path$1.join(topLevel, HUSKY_HOOKS_PATH, HOOK_FILE_NAME),
|
|
17776
18517
|
runnerRoot: topLevel,
|
|
17777
18518
|
kind: "husky",
|
|
17778
18519
|
hooksPathConfig: HUSKY_HOOKS_PATH
|
|
17779
18520
|
};
|
|
17780
18521
|
if (isVitePlusProject(topLevel)) return {
|
|
17781
|
-
hookPath: path.join(topLevel, VITE_PLUS_HOOKS_PATH, HOOK_FILE_NAME),
|
|
18522
|
+
hookPath: path$1.join(topLevel, VITE_PLUS_HOOKS_PATH, HOOK_FILE_NAME),
|
|
17782
18523
|
runnerRoot: topLevel,
|
|
17783
18524
|
kind: "vite-plus",
|
|
17784
18525
|
hooksPathConfig: VITE_PLUS_HOOKS_PATH
|
|
17785
18526
|
};
|
|
17786
18527
|
if (isSimpleGitHooksProject(topLevel)) return {
|
|
17787
|
-
hookPath: path.join(topLevel, "package.json"),
|
|
18528
|
+
hookPath: path$1.join(topLevel, "package.json"),
|
|
17788
18529
|
runnerRoot: topLevel,
|
|
17789
18530
|
kind: "simple-git-hooks"
|
|
17790
18531
|
};
|
|
@@ -17795,12 +18536,12 @@ const detectGitHookTarget = (projectRoot) => {
|
|
|
17795
18536
|
kind: "lefthook"
|
|
17796
18537
|
};
|
|
17797
18538
|
if (isPreCommitProject(topLevel)) return {
|
|
17798
|
-
hookPath: path.join(topLevel, PRE_COMMIT_CONFIG_FILE),
|
|
18539
|
+
hookPath: path$1.join(topLevel, PRE_COMMIT_CONFIG_FILE),
|
|
17799
18540
|
runnerRoot: topLevel,
|
|
17800
18541
|
kind: "pre-commit"
|
|
17801
18542
|
};
|
|
17802
18543
|
if (isOvercommitProject(topLevel)) return {
|
|
17803
|
-
hookPath: path.join(topLevel, OVERCOMMIT_CONFIG_FILE),
|
|
18544
|
+
hookPath: path$1.join(topLevel, OVERCOMMIT_CONFIG_FILE),
|
|
17804
18545
|
runnerRoot: topLevel,
|
|
17805
18546
|
kind: "overcommit"
|
|
17806
18547
|
};
|
|
@@ -17855,7 +18596,7 @@ const installReactDoctorGitHook = (options) => {
|
|
|
17855
18596
|
};
|
|
17856
18597
|
//#endregion
|
|
17857
18598
|
//#region src/cli/utils/should-skip-prompts.ts
|
|
17858
|
-
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.
|
|
18599
|
+
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.json) || isNonInteractiveEnvironment() || !process.stdin.isTTY;
|
|
17859
18600
|
//#endregion
|
|
17860
18601
|
//#region src/cli/utils/install-react-doctor.ts
|
|
17861
18602
|
const SETUP_OPTION_GIT_HOOK = "git-hook";
|
|
@@ -17896,30 +18637,30 @@ const PACKAGE_MANAGER_LOCKFILES = [
|
|
|
17896
18637
|
}
|
|
17897
18638
|
];
|
|
17898
18639
|
const findNearestFileDirectory = (startDirectory, fileNames) => {
|
|
17899
|
-
let currentDirectory = path.resolve(startDirectory);
|
|
18640
|
+
let currentDirectory = path$1.resolve(startDirectory);
|
|
17900
18641
|
while (true) {
|
|
17901
|
-
if (fileNames.some((fileName) => existsSync(path.join(currentDirectory, fileName)))) return currentDirectory;
|
|
17902
|
-
const parentDirectory = path.dirname(currentDirectory);
|
|
18642
|
+
if (fileNames.some((fileName) => fs$1.existsSync(path$1.join(currentDirectory, fileName)))) return currentDirectory;
|
|
18643
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
17903
18644
|
if (parentDirectory === currentDirectory) return null;
|
|
17904
18645
|
currentDirectory = parentDirectory;
|
|
17905
18646
|
}
|
|
17906
18647
|
};
|
|
17907
18648
|
const detectPackageManager = (projectRoot) => {
|
|
17908
|
-
let currentDirectory = path.resolve(projectRoot);
|
|
18649
|
+
let currentDirectory = path$1.resolve(projectRoot);
|
|
17909
18650
|
while (true) {
|
|
17910
18651
|
const packageJson = readPackageJson(currentDirectory);
|
|
17911
18652
|
if (isRecord(packageJson) && typeof packageJson.packageManager === "string") {
|
|
17912
18653
|
const packageManagerName = packageJson.packageManager.split("@")[0];
|
|
17913
18654
|
if (packageManagerName === "pnpm" || packageManagerName === "yarn" || packageManagerName === "bun" || packageManagerName === "npm") return packageManagerName;
|
|
17914
18655
|
}
|
|
17915
|
-
const parentDirectory = path.dirname(currentDirectory);
|
|
18656
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
17916
18657
|
if (parentDirectory === currentDirectory) break;
|
|
17917
18658
|
currentDirectory = parentDirectory;
|
|
17918
18659
|
}
|
|
17919
18660
|
const lockfileDirectory = findNearestFileDirectory(projectRoot, PACKAGE_MANAGER_LOCKFILES.map((lockfile) => lockfile.fileName));
|
|
17920
|
-
return PACKAGE_MANAGER_LOCKFILES.find((lockfile) => lockfileDirectory !== null && existsSync(path.join(lockfileDirectory, lockfile.fileName)))?.packageManager ?? "npm";
|
|
18661
|
+
return PACKAGE_MANAGER_LOCKFILES.find((lockfile) => lockfileDirectory !== null && fs$1.existsSync(path$1.join(lockfileDirectory, lockfile.fileName)))?.packageManager ?? "npm";
|
|
17921
18662
|
};
|
|
17922
|
-
const packageManagerNeedsWorkspaceFlag = (projectRoot) => existsSync(path.join(projectRoot, "pnpm-workspace.yaml")) || findNearestFileDirectory(projectRoot, ["pnpm-workspace.yaml"]) !== null;
|
|
18663
|
+
const packageManagerNeedsWorkspaceFlag = (projectRoot) => fs$1.existsSync(path$1.join(projectRoot, "pnpm-workspace.yaml")) || findNearestFileDirectory(projectRoot, ["pnpm-workspace.yaml"]) !== null;
|
|
17923
18664
|
const buildInstallCommand = (projectRoot) => {
|
|
17924
18665
|
const packageManager = detectPackageManager(projectRoot);
|
|
17925
18666
|
const packageSpecifier = `${DOCTOR_PACKAGE_NAME}@latest`;
|
|
@@ -17961,14 +18702,10 @@ const buildInstallCommand = (projectRoot) => {
|
|
|
17961
18702
|
cwd: projectRoot
|
|
17962
18703
|
};
|
|
17963
18704
|
};
|
|
17964
|
-
const
|
|
17965
|
-
|
|
18705
|
+
const execFileAsync$1 = promisify(execFile);
|
|
18706
|
+
const defaultInstallDependencyRunner = async (input) => {
|
|
18707
|
+
await execFileAsync$1(input.command, [...input.args], {
|
|
17966
18708
|
cwd: input.cwd,
|
|
17967
|
-
stdio: [
|
|
17968
|
-
"ignore",
|
|
17969
|
-
"pipe",
|
|
17970
|
-
"pipe"
|
|
17971
|
-
],
|
|
17972
18709
|
env: {
|
|
17973
18710
|
...process.env,
|
|
17974
18711
|
REACT_DOCTOR_INSTALL: "1"
|
|
@@ -18033,11 +18770,15 @@ const formatDependencyInstallMessage = (result) => {
|
|
|
18033
18770
|
if (result.dependencyStatus === "created") return "Installed dev dependency: react-doctor.";
|
|
18034
18771
|
if (result.dependencyStatus === "existing") return "React Doctor dependency already exists.";
|
|
18035
18772
|
if (result.dependencyReason === "invalid-dev-dependencies") return "Skipped dev dependency install: devDependencies field is not an object.";
|
|
18036
|
-
if (result.dependencyReason === "trust-policy-blocked") return
|
|
18037
|
-
if (result.dependencyReason === "install-command-failed") return
|
|
18773
|
+
if (result.dependencyReason === "trust-policy-blocked") return "Local install skipped by your package manager's supply-chain trust policy (safe to ignore for pre-release packages).";
|
|
18774
|
+
if (result.dependencyReason === "install-command-failed") return "Local install failed: your package manager rejected the command.";
|
|
18038
18775
|
return "Skipped dev dependency install: package.json missing or invalid.";
|
|
18039
18776
|
};
|
|
18040
|
-
const
|
|
18777
|
+
const buildDependencyFollowUp = (result) => {
|
|
18778
|
+
if (result.dependencyReason !== "trust-policy-blocked" && result.dependencyReason !== "install-command-failed") return;
|
|
18779
|
+
return ` React Doctor still works via \`npx react-doctor\`. To install locally: ${result.installCommand ?? `npm install --save-dev react-doctor@latest`}`;
|
|
18780
|
+
};
|
|
18781
|
+
const installReactDoctorScriptStep = (projectRoot) => {
|
|
18041
18782
|
const scriptSpinner = spinner("Installing React Doctor package script...").start();
|
|
18042
18783
|
try {
|
|
18043
18784
|
const scriptResult = installDoctorScript({ projectRoot });
|
|
@@ -18046,6 +18787,9 @@ const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) =>
|
|
|
18046
18787
|
scriptSpinner.fail("Failed to install React Doctor package script.");
|
|
18047
18788
|
throw error;
|
|
18048
18789
|
}
|
|
18790
|
+
};
|
|
18791
|
+
const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) => {
|
|
18792
|
+
installReactDoctorScriptStep(projectRoot);
|
|
18049
18793
|
const dependencySpinner = spinner("Installing React Doctor package...").start();
|
|
18050
18794
|
try {
|
|
18051
18795
|
const dependencyResult = await installReactDoctorDependency({
|
|
@@ -18058,7 +18802,11 @@ const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) =>
|
|
|
18058
18802
|
packageManager: detectPackageManager(projectRoot)
|
|
18059
18803
|
});
|
|
18060
18804
|
if (dependencyResult.dependencyStatus === "skipped") {
|
|
18061
|
-
|
|
18805
|
+
const message = formatDependencyInstallMessage(dependencyResult);
|
|
18806
|
+
if (dependencyResult.dependencyReason === "trust-policy-blocked") dependencySpinner.warn(message);
|
|
18807
|
+
else dependencySpinner.fail(message);
|
|
18808
|
+
const followUp = buildDependencyFollowUp(dependencyResult);
|
|
18809
|
+
if (followUp !== void 0) cliLogger.dim(followUp);
|
|
18062
18810
|
return dependencyResult;
|
|
18063
18811
|
}
|
|
18064
18812
|
dependencySpinner.succeed(formatDependencyInstallMessage(dependencyResult));
|
|
@@ -18069,17 +18817,17 @@ const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) =>
|
|
|
18069
18817
|
}
|
|
18070
18818
|
};
|
|
18071
18819
|
const getSkillSourceDirectory = () => {
|
|
18072
|
-
const distDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
18073
|
-
return path.join(distDirectory, "skills", SKILL_NAME);
|
|
18820
|
+
const distDirectory = path$1.dirname(fileURLToPath(import.meta.url));
|
|
18821
|
+
return path$1.join(distDirectory, "skills", SKILL_NAME);
|
|
18074
18822
|
};
|
|
18075
18823
|
const findBundledSiblingSkills = (primarySkillDir) => {
|
|
18076
|
-
const skillsParent = path.dirname(primarySkillDir);
|
|
18077
|
-
if (!existsSync(skillsParent)) return [];
|
|
18078
|
-
const resolvedPrimary = path.resolve(primarySkillDir);
|
|
18079
|
-
return readdirSync(skillsParent, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => ({
|
|
18824
|
+
const skillsParent = path$1.dirname(primarySkillDir);
|
|
18825
|
+
if (!fs$1.existsSync(skillsParent)) return [];
|
|
18826
|
+
const resolvedPrimary = path$1.resolve(primarySkillDir);
|
|
18827
|
+
return fs$1.readdirSync(skillsParent, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => ({
|
|
18080
18828
|
name: entry.name,
|
|
18081
|
-
source: path.join(skillsParent, entry.name)
|
|
18082
|
-
})).filter((sibling) => path.resolve(sibling.source) !== resolvedPrimary && existsSync(path.join(sibling.source, SKILL_MANIFEST_FILE)));
|
|
18829
|
+
source: path$1.join(skillsParent, entry.name)
|
|
18830
|
+
})).filter((sibling) => path$1.resolve(sibling.source) !== resolvedPrimary && fs$1.existsSync(path$1.join(sibling.source, SKILL_MANIFEST_FILE)));
|
|
18083
18831
|
};
|
|
18084
18832
|
const installBundledSiblingSkills = async (primarySkillDir, agents, projectRoot) => {
|
|
18085
18833
|
const installedSkillNames = [];
|
|
@@ -18096,35 +18844,11 @@ const installBundledSiblingSkills = async (primarySkillDir, agents, projectRoot)
|
|
|
18096
18844
|
return installedSkillNames;
|
|
18097
18845
|
};
|
|
18098
18846
|
const canInstallNativeAgentHooks = (agents) => agents.some((agent) => agent === "claude-code" || agent === "cursor");
|
|
18099
|
-
const buildWorkflowContent = () => [
|
|
18100
|
-
"name: React Doctor",
|
|
18101
|
-
"",
|
|
18102
|
-
"on:",
|
|
18103
|
-
" pull_request:",
|
|
18104
|
-
" types: [opened, synchronize, reopened, ready_for_review]",
|
|
18105
|
-
"",
|
|
18106
|
-
"permissions:",
|
|
18107
|
-
" contents: read",
|
|
18108
|
-
" pull-requests: write",
|
|
18109
|
-
" issues: write",
|
|
18110
|
-
"",
|
|
18111
|
-
"concurrency:",
|
|
18112
|
-
" group: react-doctor-${{ github.event.pull_request.number || github.ref }}",
|
|
18113
|
-
" cancel-in-progress: true",
|
|
18114
|
-
"",
|
|
18115
|
-
"jobs:",
|
|
18116
|
-
" react-doctor:",
|
|
18117
|
-
" runs-on: ubuntu-latest",
|
|
18118
|
-
" steps:",
|
|
18119
|
-
" - uses: actions/checkout@v5",
|
|
18120
|
-
" - uses: millionco/react-doctor@main",
|
|
18121
|
-
""
|
|
18122
|
-
].join("\n");
|
|
18123
18847
|
const runInstallReactDoctor = async (options = {}) => {
|
|
18124
18848
|
const requestedProjectRoot = options.projectRoot ?? process.cwd();
|
|
18125
18849
|
const projectRoot = findNearestPackageDirectory(requestedProjectRoot) ?? requestedProjectRoot;
|
|
18126
18850
|
const sourceDir = options.sourceDir ?? getSkillSourceDirectory();
|
|
18127
|
-
if (!existsSync(path.join(sourceDir, SKILL_MANIFEST_FILE))) {
|
|
18851
|
+
if (!fs$1.existsSync(path$1.join(sourceDir, SKILL_MANIFEST_FILE))) {
|
|
18128
18852
|
cliLogger.error(`Could not locate the ${SKILL_NAME} skill bundled with this package.`);
|
|
18129
18853
|
process.exitCode = 1;
|
|
18130
18854
|
return;
|
|
@@ -18155,10 +18879,8 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18155
18879
|
min: 1
|
|
18156
18880
|
}, promptOptions)).agents ?? [];
|
|
18157
18881
|
if (selectedAgents.length === 0) return;
|
|
18158
|
-
const
|
|
18159
|
-
const
|
|
18160
|
-
const hasExistingWorkflows = existsSync(workflowsDirectory);
|
|
18161
|
-
const canInstallWorkflow = !existsSync(workflowTargetPath);
|
|
18882
|
+
const workflowTargetPath = getReactDoctorWorkflowPath(projectRoot);
|
|
18883
|
+
const canInstallWorkflow = !isReactDoctorWorkflowInstalled(projectRoot);
|
|
18162
18884
|
const setupActionChoices = [
|
|
18163
18885
|
...gitHookPath === null || gitHookPath === void 0 ? [] : [{
|
|
18164
18886
|
title: "Pre-commit hook",
|
|
@@ -18176,7 +18898,7 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18176
18898
|
title: "GitHub Actions workflow",
|
|
18177
18899
|
description: "Scan pull requests in CI",
|
|
18178
18900
|
value: SETUP_OPTION_WORKFLOW,
|
|
18179
|
-
selected:
|
|
18901
|
+
selected: true
|
|
18180
18902
|
}] : []
|
|
18181
18903
|
];
|
|
18182
18904
|
const setupChoices = setupActionChoices.length === 0 ? [] : [{
|
|
@@ -18196,7 +18918,7 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18196
18918
|
const didSkipOptionalSetup = selectedSetupActions.length === 0 && selectedSetupOptions.includes(SETUP_OPTION_SKIP);
|
|
18197
18919
|
const shouldInstallGitHook = gitHookPath != null && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_GIT_HOOK));
|
|
18198
18920
|
const shouldInstallAgentHooks = Boolean(options.agentHooks) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_AGENT_HOOKS);
|
|
18199
|
-
const shouldInstallWorkflow =
|
|
18921
|
+
const shouldInstallWorkflow = canInstallWorkflow && (Boolean(options.yes) || !didSkipOptionalSetup && selectedSetupActions.includes(SETUP_OPTION_WORKFLOW));
|
|
18200
18922
|
if (options.dryRun) {
|
|
18201
18923
|
cliLogger.log(`Dry run — would install ${SKILL_NAME} skill for:`);
|
|
18202
18924
|
for (const agent of selectedAgents) cliLogger.dim(` - ${getSkillAgentConfig(agent).displayName}`);
|
|
@@ -18206,7 +18928,7 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18206
18928
|
cliLogger.dim(" Dev dependency: react-doctor");
|
|
18207
18929
|
if (shouldInstallGitHook) cliLogger.dim(` Git hook: ${gitHookPath}`);
|
|
18208
18930
|
if (shouldInstallAgentHooks) cliLogger.dim(" Agent hooks: Claude Code / Cursor when selected");
|
|
18209
|
-
if (shouldInstallWorkflow) cliLogger.dim(` GitHub Actions workflow: ${path.relative(projectRoot, workflowTargetPath)}`);
|
|
18931
|
+
if (shouldInstallWorkflow) cliLogger.dim(` GitHub Actions workflow: ${path$1.relative(projectRoot, workflowTargetPath)}`);
|
|
18210
18932
|
return;
|
|
18211
18933
|
}
|
|
18212
18934
|
const installSpinner = spinner(`Installing ${SKILL_NAME} skill...`).start();
|
|
@@ -18264,23 +18986,13 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18264
18986
|
throw error;
|
|
18265
18987
|
}
|
|
18266
18988
|
}
|
|
18267
|
-
|
|
18268
|
-
|
|
18269
|
-
const workflowSpinner = spinner("Adding GitHub Actions workflow...").start();
|
|
18270
|
-
try {
|
|
18271
|
-
writeFileSync(workflowTargetPath, buildWorkflowContent());
|
|
18272
|
-
workflowSpinner.succeed(`GitHub Actions workflow added at ${path.relative(projectRoot, workflowTargetPath)}.`);
|
|
18273
|
-
recordCount(METRIC.installWorkflow, 1);
|
|
18274
|
-
} catch (error) {
|
|
18275
|
-
workflowSpinner.fail("Failed to add GitHub Actions workflow.");
|
|
18276
|
-
throw error;
|
|
18277
|
-
}
|
|
18278
|
-
}
|
|
18989
|
+
let didInstallWorkflow = false;
|
|
18990
|
+
if (shouldInstallWorkflow) didInstallWorkflow = reportWorkflowResult(spinner("Adding GitHub Actions workflow...").start(), installReactDoctorWorkflow(projectRoot), projectRoot);
|
|
18279
18991
|
recordCount(METRIC.installCompleted, 1, {
|
|
18280
18992
|
agentsCount: selectedAgents.length,
|
|
18281
18993
|
gitHook: shouldInstallGitHook,
|
|
18282
18994
|
agentHooks: shouldInstallAgentHooks,
|
|
18283
|
-
workflow:
|
|
18995
|
+
workflow: didInstallWorkflow,
|
|
18284
18996
|
dependencyStatus: dependencyResult.dependencyStatus,
|
|
18285
18997
|
packageManager: detectPackageManager(projectRoot)
|
|
18286
18998
|
});
|
|
@@ -18290,7 +19002,7 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
18290
19002
|
//#region src/cli/utils/install-skill-for-agent.ts
|
|
18291
19003
|
const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
|
|
18292
19004
|
const source = getSkillSourceDirectory();
|
|
18293
|
-
if (!existsSync(join(source, SKILL_MANIFEST_FILE))) return false;
|
|
19005
|
+
if (!fs$1.existsSync(path$1.join(source, SKILL_MANIFEST_FILE))) return false;
|
|
18294
19006
|
const result = await installSkillsFromSource({
|
|
18295
19007
|
source,
|
|
18296
19008
|
agents: [agent],
|
|
@@ -18300,6 +19012,216 @@ const installReactDoctorSkillForAgent = async (agent, projectRoot) => {
|
|
|
18300
19012
|
return result.skills.length > 0 && result.failed.length === 0;
|
|
18301
19013
|
};
|
|
18302
19014
|
//#endregion
|
|
19015
|
+
//#region src/cli/utils/open-url.ts
|
|
19016
|
+
const resolveOpenCommand = (url) => {
|
|
19017
|
+
if (process$1.platform === "darwin") return {
|
|
19018
|
+
command: "open",
|
|
19019
|
+
args: [url]
|
|
19020
|
+
};
|
|
19021
|
+
if (process$1.platform === "win32") return {
|
|
19022
|
+
command: "cmd",
|
|
19023
|
+
args: [
|
|
19024
|
+
"/c",
|
|
19025
|
+
"start",
|
|
19026
|
+
"",
|
|
19027
|
+
url
|
|
19028
|
+
]
|
|
19029
|
+
};
|
|
19030
|
+
return {
|
|
19031
|
+
command: "xdg-open",
|
|
19032
|
+
args: [url]
|
|
19033
|
+
};
|
|
19034
|
+
};
|
|
19035
|
+
const openUrl = (url) => {
|
|
19036
|
+
try {
|
|
19037
|
+
const { command, args } = resolveOpenCommand(url);
|
|
19038
|
+
const child = spawn(command, args, {
|
|
19039
|
+
detached: true,
|
|
19040
|
+
stdio: "ignore"
|
|
19041
|
+
});
|
|
19042
|
+
child.on("error", () => {});
|
|
19043
|
+
child.unref();
|
|
19044
|
+
return true;
|
|
19045
|
+
} catch {
|
|
19046
|
+
return false;
|
|
19047
|
+
}
|
|
19048
|
+
};
|
|
19049
|
+
//#endregion
|
|
19050
|
+
//#region src/cli/utils/open-workflow-pull-request.ts
|
|
19051
|
+
const NEW_BRANCH_PREFIX = "react-doctor/add-github-actions";
|
|
19052
|
+
const COMMIT_MESSAGE = "ci: add React Doctor GitHub Actions workflow";
|
|
19053
|
+
const PR_TITLE = "Add React Doctor to GitHub Actions";
|
|
19054
|
+
const PR_BODY = `Adds a [React Doctor](https://www.react.doctor) scan to every pull request and every push to the default branch. The workflow file is documented inline.
|
|
19055
|
+
|
|
19056
|
+
Docs: https://www.react.doctor/ci`;
|
|
19057
|
+
const execFileAsync = promisify(execFile);
|
|
19058
|
+
const run = async (command, args, cwd) => {
|
|
19059
|
+
try {
|
|
19060
|
+
const { stdout, stderr } = await execFileAsync(command, [...args], {
|
|
19061
|
+
cwd,
|
|
19062
|
+
encoding: "utf8"
|
|
19063
|
+
});
|
|
19064
|
+
return {
|
|
19065
|
+
success: true,
|
|
19066
|
+
stdout: stdout.trim(),
|
|
19067
|
+
stderr: stderr.trim()
|
|
19068
|
+
};
|
|
19069
|
+
} catch (error) {
|
|
19070
|
+
const failure = error;
|
|
19071
|
+
return {
|
|
19072
|
+
success: false,
|
|
19073
|
+
stdout: (failure.stdout ?? "").trim(),
|
|
19074
|
+
stderr: (failure.stderr ?? "").trim()
|
|
19075
|
+
};
|
|
19076
|
+
}
|
|
19077
|
+
};
|
|
19078
|
+
const detectDefaultBranch = async (cwd) => {
|
|
19079
|
+
const symRef = await run("git", ["symbolic-ref", "refs/remotes/origin/HEAD"], cwd);
|
|
19080
|
+
if (symRef.success) {
|
|
19081
|
+
const branchMatch = symRef.stdout.match(/refs\/remotes\/origin\/(.+)$/);
|
|
19082
|
+
if (branchMatch) return branchMatch[1];
|
|
19083
|
+
}
|
|
19084
|
+
if ((await run("git", [
|
|
19085
|
+
"rev-parse",
|
|
19086
|
+
"--verify",
|
|
19087
|
+
"origin/main"
|
|
19088
|
+
], cwd)).success) return "main";
|
|
19089
|
+
if ((await run("git", [
|
|
19090
|
+
"rev-parse",
|
|
19091
|
+
"--verify",
|
|
19092
|
+
"origin/master"
|
|
19093
|
+
], cwd)).success) return "master";
|
|
19094
|
+
return null;
|
|
19095
|
+
};
|
|
19096
|
+
const findUniqueBranchName = async (cwd) => {
|
|
19097
|
+
if (!(await run("git", [
|
|
19098
|
+
"rev-parse",
|
|
19099
|
+
"--verify",
|
|
19100
|
+
NEW_BRANCH_PREFIX
|
|
19101
|
+
], cwd)).success) return NEW_BRANCH_PREFIX;
|
|
19102
|
+
return `${NEW_BRANCH_PREFIX}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 16).replace(/[-:T]/g, "")}`;
|
|
19103
|
+
};
|
|
19104
|
+
const openWorkflowPullRequest = async (params) => {
|
|
19105
|
+
const workflowPath = path$1.resolve(params.workflowPath);
|
|
19106
|
+
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
19107
|
+
if (!repoRootProbe.success) return {
|
|
19108
|
+
status: "not-attempted",
|
|
19109
|
+
reason: "not-a-git-repo"
|
|
19110
|
+
};
|
|
19111
|
+
const cwd = repoRootProbe.stdout;
|
|
19112
|
+
if (!isCommandAvailable("gh")) return {
|
|
19113
|
+
status: "not-attempted",
|
|
19114
|
+
reason: "gh-not-installed"
|
|
19115
|
+
};
|
|
19116
|
+
if (!(await run("gh", ["auth", "status"], cwd)).success) return {
|
|
19117
|
+
status: "not-attempted",
|
|
19118
|
+
reason: "gh-not-authenticated"
|
|
19119
|
+
};
|
|
19120
|
+
const defaultBranch = await detectDefaultBranch(cwd);
|
|
19121
|
+
if (!defaultBranch) return {
|
|
19122
|
+
status: "not-attempted",
|
|
19123
|
+
reason: "no-default-branch"
|
|
19124
|
+
};
|
|
19125
|
+
const previousBranchProbe = await run("git", [
|
|
19126
|
+
"rev-parse",
|
|
19127
|
+
"--abbrev-ref",
|
|
19128
|
+
"HEAD"
|
|
19129
|
+
], cwd);
|
|
19130
|
+
if (!previousBranchProbe.success || previousBranchProbe.stdout === "HEAD") return {
|
|
19131
|
+
status: "not-attempted",
|
|
19132
|
+
reason: "detached-head"
|
|
19133
|
+
};
|
|
19134
|
+
const previousBranch = previousBranchProbe.stdout;
|
|
19135
|
+
await run("git", [
|
|
19136
|
+
"fetch",
|
|
19137
|
+
"origin",
|
|
19138
|
+
defaultBranch
|
|
19139
|
+
], cwd);
|
|
19140
|
+
const newBranch = await findUniqueBranchName(cwd);
|
|
19141
|
+
if (!(await run("git", [
|
|
19142
|
+
"checkout",
|
|
19143
|
+
"-b",
|
|
19144
|
+
newBranch,
|
|
19145
|
+
`origin/${defaultBranch}`
|
|
19146
|
+
], cwd)).success) return {
|
|
19147
|
+
status: "not-attempted",
|
|
19148
|
+
reason: "checkout-failed"
|
|
19149
|
+
};
|
|
19150
|
+
const restoreToPreviousBranch = async (deleteNewBranch) => {
|
|
19151
|
+
await run("git", ["checkout", previousBranch], cwd);
|
|
19152
|
+
if (deleteNewBranch) await run("git", [
|
|
19153
|
+
"branch",
|
|
19154
|
+
"-D",
|
|
19155
|
+
newBranch
|
|
19156
|
+
], cwd);
|
|
19157
|
+
};
|
|
19158
|
+
if (!(await run("git", [
|
|
19159
|
+
"add",
|
|
19160
|
+
"--",
|
|
19161
|
+
path$1.relative(cwd, workflowPath)
|
|
19162
|
+
], cwd)).success) {
|
|
19163
|
+
await restoreToPreviousBranch(true);
|
|
19164
|
+
return {
|
|
19165
|
+
status: "not-attempted",
|
|
19166
|
+
reason: "git-add-failed"
|
|
19167
|
+
};
|
|
19168
|
+
}
|
|
19169
|
+
if (!(await run("git", [
|
|
19170
|
+
"commit",
|
|
19171
|
+
"-m",
|
|
19172
|
+
COMMIT_MESSAGE
|
|
19173
|
+
], cwd)).success) {
|
|
19174
|
+
await restoreToPreviousBranch(true);
|
|
19175
|
+
return {
|
|
19176
|
+
status: "not-attempted",
|
|
19177
|
+
reason: "git-commit-failed"
|
|
19178
|
+
};
|
|
19179
|
+
}
|
|
19180
|
+
if (!(await run("git", [
|
|
19181
|
+
"push",
|
|
19182
|
+
"-u",
|
|
19183
|
+
"origin",
|
|
19184
|
+
newBranch
|
|
19185
|
+
], cwd)).success) {
|
|
19186
|
+
await restoreToPreviousBranch(true);
|
|
19187
|
+
return {
|
|
19188
|
+
status: "not-attempted",
|
|
19189
|
+
reason: "git-push-failed"
|
|
19190
|
+
};
|
|
19191
|
+
}
|
|
19192
|
+
const prCreate = await run("gh", [
|
|
19193
|
+
"pr",
|
|
19194
|
+
"create",
|
|
19195
|
+
"--title",
|
|
19196
|
+
PR_TITLE,
|
|
19197
|
+
"--body",
|
|
19198
|
+
PR_BODY,
|
|
19199
|
+
"--base",
|
|
19200
|
+
defaultBranch,
|
|
19201
|
+
"--head",
|
|
19202
|
+
newBranch
|
|
19203
|
+
], cwd);
|
|
19204
|
+
await restoreToPreviousBranch(false);
|
|
19205
|
+
if (!prCreate.success) return {
|
|
19206
|
+
status: "branch-pushed",
|
|
19207
|
+
branch: newBranch
|
|
19208
|
+
};
|
|
19209
|
+
return {
|
|
19210
|
+
status: "pr-opened",
|
|
19211
|
+
url: prCreate.stdout.split(/\r?\n/).filter(Boolean).pop() ?? ""
|
|
19212
|
+
};
|
|
19213
|
+
};
|
|
19214
|
+
const stageWorkflowFile = async (params) => {
|
|
19215
|
+
const workflowPath = path$1.resolve(params.workflowPath);
|
|
19216
|
+
const repoRootProbe = await run("git", ["rev-parse", "--show-toplevel"], path$1.dirname(workflowPath));
|
|
19217
|
+
if (!repoRootProbe.success) return false;
|
|
19218
|
+
return (await run("git", [
|
|
19219
|
+
"add",
|
|
19220
|
+
"--",
|
|
19221
|
+
path$1.relative(repoRootProbe.stdout, workflowPath)
|
|
19222
|
+
], repoRootProbe.stdout)).success;
|
|
19223
|
+
};
|
|
19224
|
+
//#endregion
|
|
18303
19225
|
//#region src/cli/utils/launch-agent.ts
|
|
18304
19226
|
const CLI_AGENT_BINARIES = {
|
|
18305
19227
|
"claude-code": "claude",
|
|
@@ -18354,6 +19276,9 @@ const copyToClipboard = (text) => {
|
|
|
18354
19276
|
};
|
|
18355
19277
|
//#endregion
|
|
18356
19278
|
//#region src/cli/utils/handoff-to-agent.ts
|
|
19279
|
+
const CI_YES_CHOICE = "ci-yes";
|
|
19280
|
+
const CI_LEARN_MORE_CHOICE = "ci-learn-more";
|
|
19281
|
+
const CI_NO_CHOICE = "ci-no";
|
|
18357
19282
|
const CLIPBOARD_CHOICE = "clipboard";
|
|
18358
19283
|
const SKIP_CHOICE = "skip";
|
|
18359
19284
|
const printPayload = (payload) => {
|
|
@@ -18362,6 +19287,72 @@ const printPayload = (payload) => {
|
|
|
18362
19287
|
cliLogger.log(payload);
|
|
18363
19288
|
cliLogger.log(highlighter.dim("──────────────────────"));
|
|
18364
19289
|
};
|
|
19290
|
+
const setUpGitHubActions = async (rootDirectory) => {
|
|
19291
|
+
const projectRoot = findNearestPackageDirectory(rootDirectory) ?? rootDirectory;
|
|
19292
|
+
try {
|
|
19293
|
+
installReactDoctorScriptStep(projectRoot);
|
|
19294
|
+
} catch {}
|
|
19295
|
+
const workflowSpinner = spinner("Adding GitHub Actions workflow...").start();
|
|
19296
|
+
const workflowResult = installReactDoctorWorkflow(projectRoot);
|
|
19297
|
+
reportWorkflowResult(workflowSpinner, workflowResult, projectRoot);
|
|
19298
|
+
cliLogger.break();
|
|
19299
|
+
if (workflowResult.status === "failed") {
|
|
19300
|
+
cliLogger.log(` Couldn't set up GitHub Actions automatically. Follow the guide at ${highlighter.info(CI_URL)}`);
|
|
19301
|
+
return;
|
|
19302
|
+
}
|
|
19303
|
+
if (workflowResult.status === "created") {
|
|
19304
|
+
const pullRequestSpinner = spinner("Opening a pull request for review...").start();
|
|
19305
|
+
const pullRequestResult = await openWorkflowPullRequest({ workflowPath: workflowResult.workflowPath });
|
|
19306
|
+
if (pullRequestResult.status === "pr-opened") pullRequestSpinner.succeed(`Opened pull request for review: ${highlighter.info(pullRequestResult.url)}`);
|
|
19307
|
+
else if (pullRequestResult.status === "branch-pushed") pullRequestSpinner.warn(`Pushed branch ${highlighter.bold(pullRequestResult.branch)} but couldn't open a PR. Open one with: gh pr create --head ${pullRequestResult.branch}`);
|
|
19308
|
+
else {
|
|
19309
|
+
pullRequestSpinner.stop();
|
|
19310
|
+
if (await stageWorkflowFile({ workflowPath: workflowResult.workflowPath })) cliLogger.log(` Staged the workflow file. Commit it to start scanning every pull request.`);
|
|
19311
|
+
else cliLogger.log(" React Doctor will now scan every new pull request automatically.");
|
|
19312
|
+
}
|
|
19313
|
+
}
|
|
19314
|
+
cliLogger.log(` Learn more: ${highlighter.info(CI_URL)}`);
|
|
19315
|
+
};
|
|
19316
|
+
const SGR_BOLD_OFF = "\x1B[22m";
|
|
19317
|
+
const ciQuestionMessage = [
|
|
19318
|
+
"Add React Doctor to GitHub Actions?",
|
|
19319
|
+
`${SGR_BOLD_OFF} ${highlighter.dim("Scan every pull request to prevent new React issues while you fix the backlog.")}`,
|
|
19320
|
+
`${SGR_BOLD_OFF} ${highlighter.dim(`Used by teams at ${CI_TRUST_COMPANIES}.`)}`
|
|
19321
|
+
].join("\n");
|
|
19322
|
+
const askAddToGitHubActions = async () => {
|
|
19323
|
+
while (true) {
|
|
19324
|
+
const { ciChoice } = await prompts({
|
|
19325
|
+
type: "select",
|
|
19326
|
+
name: "ciChoice",
|
|
19327
|
+
message: ciQuestionMessage,
|
|
19328
|
+
hint: " ",
|
|
19329
|
+
choices: [
|
|
19330
|
+
{
|
|
19331
|
+
title: "Yes (recommended)",
|
|
19332
|
+
description: "Adds the workflow file and a doctor package script",
|
|
19333
|
+
value: CI_YES_CHOICE
|
|
19334
|
+
},
|
|
19335
|
+
{
|
|
19336
|
+
title: "Learn more",
|
|
19337
|
+
description: highlighter.info(CI_URL),
|
|
19338
|
+
value: CI_LEARN_MORE_CHOICE
|
|
19339
|
+
},
|
|
19340
|
+
{
|
|
19341
|
+
title: "No, thanks",
|
|
19342
|
+
description: "Continue to the agent handoff",
|
|
19343
|
+
value: CI_NO_CHOICE
|
|
19344
|
+
}
|
|
19345
|
+
],
|
|
19346
|
+
initial: 0
|
|
19347
|
+
}, { onCancel: () => true });
|
|
19348
|
+
if (ciChoice === void 0) return "cancel";
|
|
19349
|
+
if (ciChoice === CI_YES_CHOICE) return "yes";
|
|
19350
|
+
if (ciChoice === CI_NO_CHOICE) return "no";
|
|
19351
|
+
const opened = openUrl(CI_URL);
|
|
19352
|
+
cliLogger.log(opened ? `Opened ${highlighter.info(CI_URL)} in your browser.` : `Visit ${highlighter.info(CI_URL)} to learn more.`);
|
|
19353
|
+
cliLogger.break();
|
|
19354
|
+
}
|
|
19355
|
+
};
|
|
18365
19356
|
const detectLaunchableAgents = async () => {
|
|
18366
19357
|
const detected = new Set(await detectAvailableAgents());
|
|
18367
19358
|
return Object.keys(CLI_AGENT_BINARIES).filter((agentId) => detected.has(agentId) && isCommandAvailable(CLI_AGENT_BINARIES[agentId]));
|
|
@@ -18369,10 +19360,22 @@ const detectLaunchableAgents = async () => {
|
|
|
18369
19360
|
const handoffToAgent = async (input) => {
|
|
18370
19361
|
if (!input.interactive || input.diagnostics.length === 0) return;
|
|
18371
19362
|
cliLogger.break();
|
|
19363
|
+
if (!isReactDoctorWorkflowInstalled(findNearestPackageDirectory(input.rootDirectory) ?? input.rootDirectory)) {
|
|
19364
|
+
const ciOutcome = await askAddToGitHubActions();
|
|
19365
|
+
recordCount(METRIC.agentHandoff, 1, {
|
|
19366
|
+
outcome: `ci-${ciOutcome}`,
|
|
19367
|
+
diagnosticsCount: input.diagnostics.length
|
|
19368
|
+
});
|
|
19369
|
+
if (ciOutcome === "cancel") return;
|
|
19370
|
+
if (ciOutcome === "yes") {
|
|
19371
|
+
await setUpGitHubActions(input.rootDirectory);
|
|
19372
|
+
cliLogger.break();
|
|
19373
|
+
}
|
|
19374
|
+
}
|
|
18372
19375
|
const { handoffTarget } = await prompts({
|
|
18373
19376
|
type: "select",
|
|
18374
19377
|
name: "handoffTarget",
|
|
18375
|
-
message: "
|
|
19378
|
+
message: "What would you like to do next?",
|
|
18376
19379
|
choices: [
|
|
18377
19380
|
...(await detectLaunchableAgents()).map((agentId) => ({
|
|
18378
19381
|
title: getSkillAgentConfig(agentId).displayName,
|
|
@@ -18437,7 +19440,7 @@ const handoffToAgent = async (input) => {
|
|
|
18437
19440
|
*/
|
|
18438
19441
|
const readObjectFile = (filePath) => {
|
|
18439
19442
|
try {
|
|
18440
|
-
const parsed = parseJSON5(readFileSync(filePath, "utf-8"));
|
|
19443
|
+
const parsed = parseJSON5(fs$1.readFileSync(filePath, "utf-8"));
|
|
18441
19444
|
return isPlainObject(parsed) ? parsed : null;
|
|
18442
19445
|
} catch {
|
|
18443
19446
|
return null;
|
|
@@ -18484,29 +19487,16 @@ const migrateLegacyConfig = (legacy) => {
|
|
|
18484
19487
|
if (!parsed) return null;
|
|
18485
19488
|
const config = { ...parsed };
|
|
18486
19489
|
delete config.$schema;
|
|
18487
|
-
const targetPath = path.join(legacy.directory, MIGRATED_CONFIG_FILENAME);
|
|
18488
|
-
|
|
19490
|
+
const targetPath = path$1.join(legacy.directory, MIGRATED_CONFIG_FILENAME);
|
|
19491
|
+
const contents = `import type { ReactDoctorConfig } from "react-doctor/api";
|
|
18489
19492
|
|
|
18490
19493
|
export default ${serializeTsObjectLiteral(config)} satisfies ReactDoctorConfig;
|
|
18491
|
-
|
|
18492
|
-
|
|
19494
|
+
`;
|
|
19495
|
+
fs$1.writeFileSync(targetPath, contents);
|
|
19496
|
+
fs$1.rmSync(legacy.legacyFilePath, { force: true });
|
|
18493
19497
|
return targetPath;
|
|
18494
19498
|
};
|
|
18495
19499
|
//#endregion
|
|
18496
|
-
//#region src/cli/utils/annotation-encoding.ts
|
|
18497
|
-
const encodeAnnotationProperty = (value) => value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A").replaceAll(":", "%3A").replaceAll(",", "%2C");
|
|
18498
|
-
const encodeAnnotationMessage = (value) => value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
18499
|
-
//#endregion
|
|
18500
|
-
//#region src/cli/utils/print-annotations.ts
|
|
18501
|
-
const printAnnotations = (diagnostics, routeToStderr) => {
|
|
18502
|
-
const writeLine = routeToStderr ? (line) => process.stderr.write(`${line}\n`) : (line) => process.stdout.write(`${line}\n`);
|
|
18503
|
-
for (const diagnostic of diagnostics) {
|
|
18504
|
-
const level = diagnostic.severity === "error" ? "error" : "warning";
|
|
18505
|
-
const title = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
18506
|
-
writeLine(`::${level} ${`file=${encodeAnnotationProperty(diagnostic.filePath)}`}${diagnostic.line > 0 ? `,line=${diagnostic.line}` : ""}${`,title=${encodeAnnotationProperty(title)}`}::${encodeAnnotationMessage(diagnostic.message)}`);
|
|
18507
|
-
}
|
|
18508
|
-
};
|
|
18509
|
-
//#endregion
|
|
18510
19500
|
//#region src/cli/utils/print-branded-header.ts
|
|
18511
19501
|
/**
|
|
18512
19502
|
* Single branded line every command prints first when not in JSON
|
|
@@ -18529,25 +19519,27 @@ const HAPPY_FACE_LINES = [
|
|
|
18529
19519
|
"│ ▽ │",
|
|
18530
19520
|
"└─────┘"
|
|
18531
19521
|
];
|
|
18532
|
-
const typeLine = (linePrefix, text, style) => Effect.gen(function* () {
|
|
19522
|
+
const typeLine = (linePrefix, text, style, charDelayMs) => Effect.gen(function* () {
|
|
18533
19523
|
const characters = [...text];
|
|
18534
19524
|
for (let length = 1; length <= characters.length; length += 1) {
|
|
18535
19525
|
yield* writeStdout(`\r${linePrefix}${style(characters.slice(0, length).join(""))}\x1b[K`);
|
|
18536
|
-
yield* Effect.sleep(
|
|
19526
|
+
yield* Effect.sleep(charDelayMs);
|
|
18537
19527
|
}
|
|
18538
19528
|
});
|
|
18539
|
-
const playWelcomeScene = () => Effect.gen(function* () {
|
|
19529
|
+
const playWelcomeScene = (options = {}) => Effect.gen(function* () {
|
|
19530
|
+
const speedMultiplier = options.speedMultiplier ?? 1;
|
|
19531
|
+
const charDelayMs = 16 / speedMultiplier;
|
|
19532
|
+
const interLineDelayMs = 250 / speedMultiplier;
|
|
19533
|
+
const explanationHoldMs = WELCOME_EXPLANATION_HOLD_MS / speedMultiplier;
|
|
18540
19534
|
const face = HAPPY_FACE_LINES.map((line) => highlighter.success(line));
|
|
18541
19535
|
const mouthPrefix = ` ${face[2] ?? ""} `;
|
|
18542
19536
|
yield* writeStdout(`\n${face.map((line) => ` ${line}`).join("\n")}\n`);
|
|
18543
19537
|
yield* writeStdout("\x1B[3A");
|
|
18544
|
-
yield* typeLine(` ${face[1] ?? ""} `, "Welcome to React Doctor", (fragment) => highlighter.bold(fragment));
|
|
18545
|
-
yield* Effect.sleep(
|
|
19538
|
+
yield* typeLine(` ${face[1] ?? ""} `, "Welcome to React Doctor", (fragment) => highlighter.bold(fragment), charDelayMs);
|
|
19539
|
+
yield* Effect.sleep(interLineDelayMs);
|
|
18546
19540
|
yield* writeStdout("\x1B[1B");
|
|
18547
|
-
yield* typeLine(mouthPrefix, "I diagnose your React code for bugs, security & performance.", (fragment) => highlighter.dim(fragment));
|
|
18548
|
-
yield* Effect.sleep(
|
|
18549
|
-
yield* typeLine(mouthPrefix, "Let's scan your codebase...", (fragment) => highlighter.dim(fragment));
|
|
18550
|
-
yield* Effect.sleep(WELCOME_HOLD_MS);
|
|
19541
|
+
yield* typeLine(mouthPrefix, "I diagnose your React code for bugs, security & performance.", (fragment) => highlighter.dim(fragment), charDelayMs);
|
|
19542
|
+
yield* Effect.sleep(explanationHoldMs);
|
|
18551
19543
|
yield* writeStdout("\x1B[3A\r\x1B[0J");
|
|
18552
19544
|
});
|
|
18553
19545
|
//#endregion
|
|
@@ -18605,13 +19597,19 @@ const toForwardSlashes = (filePath) => filePath.replaceAll("\\", "/");
|
|
|
18605
19597
|
const isSafeRelativePath = (filePath) => {
|
|
18606
19598
|
if (filePath.length === 0) return false;
|
|
18607
19599
|
if (filePath.includes("\0")) return false;
|
|
18608
|
-
if (path.isAbsolute(filePath)) return false;
|
|
18609
|
-
const normalized = path.posix.normalize(filePath);
|
|
19600
|
+
if (path$1.isAbsolute(filePath)) return false;
|
|
19601
|
+
const normalized = path$1.posix.normalize(filePath);
|
|
18610
19602
|
if (normalized === "." || normalized.startsWith("../") || normalized === "..") return false;
|
|
18611
19603
|
return normalized === filePath;
|
|
18612
19604
|
};
|
|
18613
19605
|
const readChangedFilesFrom = (filePath) => {
|
|
18614
|
-
|
|
19606
|
+
let raw;
|
|
19607
|
+
try {
|
|
19608
|
+
raw = fs$1.readFileSync(filePath, "utf8");
|
|
19609
|
+
} catch (error) {
|
|
19610
|
+
const errorCode = error?.code;
|
|
19611
|
+
throw new CliInputError(`Could not read the --changed-files-from file "${filePath}"${errorCode ? ` (${errorCode})` : ""}. Pass a path to a readable text file that lists changed files, one per line.`);
|
|
19612
|
+
}
|
|
18615
19613
|
const uniqueFiles = /* @__PURE__ */ new Set();
|
|
18616
19614
|
for (const line of raw.split(/\r?\n/)) {
|
|
18617
19615
|
const candidate = toForwardSlashes(line.trim());
|
|
@@ -18707,7 +19705,7 @@ const getSetupPromptStore = (options = {}) => new Conf({
|
|
|
18707
19705
|
projectName: GLOBAL_CONFIG_PROJECT_NAME,
|
|
18708
19706
|
cwd: options.cwd
|
|
18709
19707
|
});
|
|
18710
|
-
const getSetupPromptProjectKey = (projectRoot) => createHash("sha256").update(path.resolve(projectRoot)).digest("hex");
|
|
19708
|
+
const getSetupPromptProjectKey = (projectRoot) => createHash("sha256").update(path$1.resolve(projectRoot)).digest("hex");
|
|
18711
19709
|
const hasDisabledSetupPrompt = (projectRoot, storeOptions = {}) => {
|
|
18712
19710
|
try {
|
|
18713
19711
|
return getSetupPromptStore(storeOptions).get("projects", {})[getSetupPromptProjectKey(projectRoot)]?.setupPrompt === false;
|
|
@@ -18764,28 +19762,26 @@ const resolveParallelFlag = (parallel) => parallel === false ? 1 : void 0;
|
|
|
18764
19762
|
/**
|
|
18765
19763
|
* Translates CLI flags into the `InspectOptions` contract `inspect()`
|
|
18766
19764
|
* accepts. Flag-specific computed fields (`scoreOnly`, `noScore`,
|
|
18767
|
-
* `silent`, `
|
|
18768
|
-
*
|
|
18769
|
-
*
|
|
18770
|
-
*
|
|
18771
|
-
*
|
|
18772
|
-
*
|
|
18773
|
-
* can apply the one flag-and-config rule that flags own
|
|
19765
|
+
* `silent`, `isCi`) live here — there's no `userConfig` knob for them,
|
|
19766
|
+
* only flag derivation. The plain boolean knobs (`lint`, `deadCode`,
|
|
19767
|
+
* `verbose`) pass through unchanged: `inspect()` owns the
|
|
19768
|
+
* userConfig-fallback layer so the merge logic isn't duplicated. The
|
|
19769
|
+
* shell still hands `userConfig` in via `configOverride` and `noScore`
|
|
19770
|
+
* so this resolver can apply the one flag-and-config rule that flags own
|
|
18774
19771
|
* (`--score false` wins, otherwise inherit `userConfig.noScore`).
|
|
18775
19772
|
*/
|
|
18776
19773
|
const resolveCliInspectOptions = (flags, userConfig) => {
|
|
18777
|
-
const wantsWarningGate = (flags
|
|
19774
|
+
const wantsWarningGate = pickBlockingLevel(flags, userConfig) === "warning";
|
|
18778
19775
|
return {
|
|
18779
19776
|
lint: flags.lint,
|
|
18780
19777
|
deadCode: flags.deadCode,
|
|
18781
19778
|
verbose: flags.verbose,
|
|
18782
|
-
respectInlineDisables: flags.respectInlineDisables,
|
|
18783
|
-
warnings:
|
|
19779
|
+
respectInlineDisables: flags.respectInlineDisables === false ? false : void 0,
|
|
19780
|
+
warnings: wantsWarningGate ? true : flags.warnings,
|
|
18784
19781
|
scoreOnly: flags.score === true,
|
|
18785
19782
|
noScore: flags.score === false || flags.telemetry === false || (userConfig?.noScore ?? false),
|
|
18786
19783
|
isCi: isCiEnvironment(),
|
|
18787
19784
|
silent: Boolean(flags.json),
|
|
18788
|
-
outputSurface: flags.prComment ? "prComment" : "cli",
|
|
18789
19785
|
concurrency: resolveParallelFlag(flags.parallel)
|
|
18790
19786
|
};
|
|
18791
19787
|
};
|
|
@@ -18838,33 +19834,15 @@ const coerceDiffValue = (value) => {
|
|
|
18838
19834
|
};
|
|
18839
19835
|
//#endregion
|
|
18840
19836
|
//#region src/cli/utils/resolve-effective-diff.ts
|
|
18841
|
-
const resolveEffectiveDiff = (flags, userConfig) =>
|
|
18842
|
-
if (flags.full) return false;
|
|
18843
|
-
return coerceDiffValue(flags.diff ?? userConfig?.diff);
|
|
18844
|
-
};
|
|
18845
|
-
//#endregion
|
|
18846
|
-
//#region src/cli/utils/resolve-fail-on-level.ts
|
|
18847
|
-
const VALID_FAIL_ON_LEVELS = new Set([
|
|
18848
|
-
"error",
|
|
18849
|
-
"warning",
|
|
18850
|
-
"none"
|
|
18851
|
-
]);
|
|
18852
|
-
const DEFAULT_FAIL_ON_LEVEL = "none";
|
|
18853
|
-
const isValidFailOnLevel = (level) => VALID_FAIL_ON_LEVELS.has(level);
|
|
18854
|
-
const resolveFailOnLevel = (flags, userConfig) => {
|
|
18855
|
-
const sourceValue = flags.failOn ?? userConfig?.failOn ?? DEFAULT_FAIL_ON_LEVEL;
|
|
18856
|
-
if (isValidFailOnLevel(sourceValue)) return sourceValue;
|
|
18857
|
-
cliLogger.warn(`Invalid failOn level "${sourceValue}". Expected one of: error, warning, none. Falling back to "${DEFAULT_FAIL_ON_LEVEL}".`);
|
|
18858
|
-
return DEFAULT_FAIL_ON_LEVEL;
|
|
18859
|
-
};
|
|
19837
|
+
const resolveEffectiveDiff = (flags, userConfig) => coerceDiffValue(flags.diff ?? userConfig?.diff);
|
|
18860
19838
|
//#endregion
|
|
18861
19839
|
//#region src/cli/utils/resolve-project-diff-include-paths.ts
|
|
18862
19840
|
const resolveProjectDiffIncludePaths = (rootDirectory, projectDirectory, diffInfo) => {
|
|
18863
19841
|
const changedSourceFiles = filterSourceFiles(diffInfo.changedFiles);
|
|
18864
|
-
const relativeProjectDirectory = toForwardSlashes(path.relative(rootDirectory, projectDirectory));
|
|
19842
|
+
const relativeProjectDirectory = toForwardSlashes(path$1.relative(rootDirectory, projectDirectory));
|
|
18865
19843
|
if (relativeProjectDirectory.length === 0) return changedSourceFiles;
|
|
18866
19844
|
if (relativeProjectDirectory.startsWith("../") || relativeProjectDirectory === "..") return [];
|
|
18867
|
-
if (path.isAbsolute(relativeProjectDirectory)) return [];
|
|
19845
|
+
if (path$1.isAbsolute(relativeProjectDirectory)) return [];
|
|
18868
19846
|
const projectPrefix = `${relativeProjectDirectory}/`;
|
|
18869
19847
|
return changedSourceFiles.flatMap((filePath) => {
|
|
18870
19848
|
const normalizedFilePath = toForwardSlashes(filePath);
|
|
@@ -18910,15 +19888,15 @@ const buildDiagnosticIssueUrl = (input) => {
|
|
|
18910
19888
|
//#endregion
|
|
18911
19889
|
//#region src/cli/utils/find-owning-project.ts
|
|
18912
19890
|
const findOwningProjectDirectory = (rootDirectory, filePath) => {
|
|
18913
|
-
const absoluteFile = path.isAbsolute(filePath) ? filePath : path.resolve(rootDirectory, filePath);
|
|
19891
|
+
const absoluteFile = path$1.isAbsolute(filePath) ? filePath : path$1.resolve(rootDirectory, filePath);
|
|
18914
19892
|
const workspacePackages = listWorkspacePackages(rootDirectory);
|
|
18915
19893
|
const candidates = workspacePackages.length > 0 ? workspacePackages : discoverReactSubprojects(rootDirectory);
|
|
18916
19894
|
if (candidates.length === 0) return rootDirectory;
|
|
18917
19895
|
let bestMatch = null;
|
|
18918
19896
|
for (const candidate of candidates) {
|
|
18919
|
-
const candidateDirectory = path.resolve(candidate.directory);
|
|
18920
|
-
const relativeFromCandidate = path.relative(candidateDirectory, absoluteFile);
|
|
18921
|
-
if (relativeFromCandidate.startsWith("..") || path.isAbsolute(relativeFromCandidate)) continue;
|
|
19897
|
+
const candidateDirectory = path$1.resolve(candidate.directory);
|
|
19898
|
+
const relativeFromCandidate = path$1.relative(candidateDirectory, absoluteFile);
|
|
19899
|
+
if (relativeFromCandidate.startsWith("..") || path$1.isAbsolute(relativeFromCandidate)) continue;
|
|
18922
19900
|
const depth = candidateDirectory.length;
|
|
18923
19901
|
if (!bestMatch || depth > bestMatch.depth) bestMatch = {
|
|
18924
19902
|
directory: candidate.directory,
|
|
@@ -18945,7 +19923,7 @@ const parseFileLineArgument = (rawArgument) => {
|
|
|
18945
19923
|
//#endregion
|
|
18946
19924
|
//#region src/cli/utils/select-projects.ts
|
|
18947
19925
|
const selectProjects = async (rootDirectory, projectFlag, skipPrompts) => {
|
|
18948
|
-
const hasRootPackageJson = isFile(path.join(rootDirectory, "package.json"));
|
|
19926
|
+
const hasRootPackageJson = isFile(path$1.join(rootDirectory, "package.json"));
|
|
18949
19927
|
let packages = listWorkspacePackages(rootDirectory);
|
|
18950
19928
|
if (packages.length === 0 && (!hasRootPackageJson || isMonorepoRoot(rootDirectory))) packages = discoverReactSubprojects(rootDirectory);
|
|
18951
19929
|
if (packages.length === 0) return [rootDirectory];
|
|
@@ -18960,11 +19938,14 @@ const selectProjects = async (rootDirectory, projectFlag, skipPrompts) => {
|
|
|
18960
19938
|
}
|
|
18961
19939
|
return promptProjectSelection(packages, rootDirectory);
|
|
18962
19940
|
};
|
|
19941
|
+
const ALL_PROJECTS_SENTINEL = "*";
|
|
18963
19942
|
const resolveProjectFlag = (projectFlag, workspacePackages) => {
|
|
18964
|
-
const requestedNames = projectFlag.split(",").map((name) => name.trim());
|
|
19943
|
+
const requestedNames = projectFlag.split(",").map((name) => name.trim()).filter((name) => name.length > 0);
|
|
19944
|
+
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.`);
|
|
19945
|
+
if (requestedNames.includes(ALL_PROJECTS_SENTINEL)) return workspacePackages.map((workspacePackage) => workspacePackage.directory);
|
|
18965
19946
|
const resolvedDirectories = [];
|
|
18966
19947
|
for (const requestedName of requestedNames) {
|
|
18967
|
-
const matched = workspacePackages.find((workspacePackage) => workspacePackage.name === requestedName || path.basename(workspacePackage.directory) === requestedName);
|
|
19948
|
+
const matched = workspacePackages.find((workspacePackage) => workspacePackage.name === requestedName || path$1.basename(workspacePackage.directory) === requestedName);
|
|
18968
19949
|
if (!matched) throw new CliInputError(`Project "${requestedName}" not found. Available: ${workspacePackages.map((workspacePackage) => workspacePackage.name).join(", ")}`);
|
|
18969
19950
|
resolvedDirectories.push(matched.directory);
|
|
18970
19951
|
}
|
|
@@ -18980,7 +19961,7 @@ const promptProjectSelection = async (workspacePackages, rootDirectory) => {
|
|
|
18980
19961
|
message: "Select projects",
|
|
18981
19962
|
choices: workspacePackages.map((workspacePackage) => ({
|
|
18982
19963
|
title: workspacePackage.name,
|
|
18983
|
-
description: path.relative(rootDirectory, workspacePackage.directory),
|
|
19964
|
+
description: path$1.relative(rootDirectory, workspacePackage.directory),
|
|
18984
19965
|
value: workspacePackage.directory
|
|
18985
19966
|
})),
|
|
18986
19967
|
min: 1
|
|
@@ -19034,11 +20015,14 @@ const runExplain = async (fileLineArgument, context) => {
|
|
|
19034
20015
|
}
|
|
19035
20016
|
};
|
|
19036
20017
|
//#endregion
|
|
19037
|
-
//#region src/cli/utils/
|
|
19038
|
-
const
|
|
19039
|
-
|
|
19040
|
-
|
|
19041
|
-
|
|
20018
|
+
//#region src/cli/utils/warn-deprecated-fail-on.ts
|
|
20019
|
+
const warnDeprecatedFailOn = (flags, userConfig) => {
|
|
20020
|
+
const usedFlag = flags.failOn !== void 0;
|
|
20021
|
+
const usedConfig = userConfig?.failOn !== void 0;
|
|
20022
|
+
if (!usedFlag && !usedConfig) return;
|
|
20023
|
+
const source = usedFlag ? "The `--fail-on` flag" : "The `failOn` config option";
|
|
20024
|
+
const replacement = usedFlag ? "`--blocking <level>`" : "`blocking`";
|
|
20025
|
+
cliLogger.warn(`${source} is deprecated; rename it to ${replacement}.`);
|
|
19042
20026
|
};
|
|
19043
20027
|
//#endregion
|
|
19044
20028
|
//#region src/cli/utils/validate-mode-flags.ts
|
|
@@ -19046,39 +20030,46 @@ const validateModeFlags = (flags) => {
|
|
|
19046
20030
|
const coercedDiff = coerceDiffValue(flags.diff);
|
|
19047
20031
|
const exclusiveModes = [flags.staged ? "--staged" : null, coercedDiff !== void 0 && coercedDiff !== false ? "--diff" : null].filter((modeName) => modeName !== null);
|
|
19048
20032
|
if (exclusiveModes.length > 1) throw new CliInputError(`Cannot combine ${exclusiveModes.join(" and ")}; pick one mode.`);
|
|
19049
|
-
if (flags.yes && flags.full) throw new CliInputError("Cannot combine --yes and --full; pick one.");
|
|
19050
20033
|
if (flags.score && flags.json) throw new CliInputError("Cannot combine --score and --json; pick one output mode.");
|
|
19051
20034
|
if (flags.score && flags.telemetry === false) throw new CliInputError("Cannot combine --score with --no-telemetry; --score prints the score that --no-telemetry disables.");
|
|
19052
|
-
if (flags.prComment && (flags.json || flags.score)) throw new CliInputError("--pr-comment cannot be combined with --json or --score.");
|
|
19053
|
-
if (flags.annotations && flags.score) throw new CliInputError("--annotations cannot be combined with --score.");
|
|
19054
|
-
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.");
|
|
19055
|
-
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.");
|
|
19056
20035
|
};
|
|
19057
20036
|
//#endregion
|
|
19058
20037
|
//#region src/cli/commands/inspect.ts
|
|
19059
20038
|
/**
|
|
19060
20039
|
* Post-scan finalization shared by the staged-arm and project-loop
|
|
19061
|
-
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
19062
|
-
*
|
|
19063
|
-
* `
|
|
19064
|
-
*
|
|
20040
|
+
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
20041
|
+
* and set `process.exitCode = 1` when a diagnostic at or above the
|
|
20042
|
+
* `--blocking` threshold (default `"error"`) reaches the `ciFailure`
|
|
20043
|
+
* surface. `--blocking none` keeps the scan advisory (always exits 0).
|
|
19065
20044
|
*/
|
|
19066
20045
|
const finalizeScans = (input) => {
|
|
19067
|
-
|
|
19068
|
-
|
|
19069
|
-
|
|
19070
|
-
|
|
19071
|
-
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
19076
|
-
|
|
19077
|
-
|
|
20046
|
+
const baselineDeltas = input.completedScans.flatMap((scan) => scan.result.baselineDelta ? [scan.result.baselineDelta] : []);
|
|
20047
|
+
const baselineComputed = input.completedScans.length > 0 && input.completedScans.every((scan) => scan.result.baselineDelta !== void 0);
|
|
20048
|
+
const baselineDegraded = input.baselineIntended && !baselineComputed;
|
|
20049
|
+
const mode = baselineDegraded ? "diff" : input.mode;
|
|
20050
|
+
if (input.isJsonMode) {
|
|
20051
|
+
const baseline = baselineComputed && baselineDeltas.length > 0 ? {
|
|
20052
|
+
baseRef: baselineDeltas[0].baseRef,
|
|
20053
|
+
fixedCount: baselineDeltas.reduce((total, delta) => total + delta.fixedCount, 0),
|
|
20054
|
+
baseTotalCount: baselineDeltas.reduce((total, delta) => total + delta.baseTotalCount, 0)
|
|
20055
|
+
} : void 0;
|
|
20056
|
+
writeJsonReport(buildJsonReport({
|
|
20057
|
+
version: VERSION,
|
|
20058
|
+
directory: input.resolvedDirectory,
|
|
20059
|
+
mode,
|
|
20060
|
+
diff: input.diff,
|
|
20061
|
+
scans: input.completedScans,
|
|
20062
|
+
totalElapsedMilliseconds: performance.now() - input.startTime,
|
|
20063
|
+
baseline
|
|
20064
|
+
}));
|
|
20065
|
+
}
|
|
20066
|
+
if (input.isScoreOnly || baselineDegraded) return;
|
|
20067
|
+
if (shouldBlockCi(filterDiagnosticsForSurface(input.diagnostics, "ciFailure", input.userConfig), resolveBlockingLevel(input.flags, input.userConfig))) process.exitCode = 1;
|
|
19078
20068
|
};
|
|
19079
20069
|
const buildChangedFilesDiffInfo = (changedFiles) => ({
|
|
19080
20070
|
currentBranch: process.env.GITHUB_HEAD_REF?.trim() || null,
|
|
19081
20071
|
baseBranch: process.env.GITHUB_BASE_REF?.trim() || "pull request target",
|
|
20072
|
+
baseSha: process.env.REACT_DOCTOR_BASE_SHA?.trim() || void 0,
|
|
19082
20073
|
changedFiles,
|
|
19083
20074
|
isCurrentChanges: false
|
|
19084
20075
|
});
|
|
@@ -19104,7 +20095,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19104
20095
|
const isScoreOnly = Boolean(flags.score);
|
|
19105
20096
|
const isJsonMode = Boolean(flags.json);
|
|
19106
20097
|
const isQuiet = isScoreOnly || isJsonMode;
|
|
19107
|
-
const requestedDirectory = path.resolve(directory);
|
|
20098
|
+
const requestedDirectory = path$1.resolve(directory);
|
|
19108
20099
|
const startTime = performance.now();
|
|
19109
20100
|
if (isJsonMode) enableJsonMode({
|
|
19110
20101
|
compact: Boolean(flags.jsonCompact),
|
|
@@ -19121,11 +20112,12 @@ const inspectAction = async (directory, flags) => {
|
|
|
19121
20112
|
const userConfig = scanTarget.userConfig;
|
|
19122
20113
|
const resolvedDirectory = scanTarget.resolvedDirectory;
|
|
19123
20114
|
setJsonReportDirectory(resolvedDirectory);
|
|
20115
|
+
warnDeprecatedFailOn(flags, userConfig);
|
|
19124
20116
|
if (scanTarget.didRedirectViaRootDir && !isQuiet) {
|
|
19125
20117
|
cliLogger.dim(`Redirected to ${highlighter.info(toRelativePath(resolvedDirectory, requestedDirectory))} via react-doctor config "rootDir".`);
|
|
19126
20118
|
cliLogger.break();
|
|
19127
20119
|
}
|
|
19128
|
-
const explainArgument = flags.explain
|
|
20120
|
+
const explainArgument = flags.explain;
|
|
19129
20121
|
if (explainArgument !== void 0) {
|
|
19130
20122
|
await runExplain(explainArgument, {
|
|
19131
20123
|
resolvedDirectory,
|
|
@@ -19135,12 +20127,13 @@ const inspectAction = async (directory, flags) => {
|
|
|
19135
20127
|
});
|
|
19136
20128
|
return;
|
|
19137
20129
|
}
|
|
19138
|
-
if (!isQuiet) if (
|
|
19139
|
-
|
|
20130
|
+
if (!isQuiet) if (!flags.verbose && canAnimateOnboarding(process.stdout)) {
|
|
20131
|
+
const isReturningUser = !isOnboardingForced() && hasCompletedOnboarding();
|
|
20132
|
+
await Effect.runPromise(playWelcomeScene({ speedMultiplier: isReturningUser ? 2 : 1 }));
|
|
20133
|
+
} else Effect.runSync(printBrandedHeader);
|
|
19140
20134
|
const scanOptions = resolveCliInspectOptions(flags, userConfig);
|
|
19141
20135
|
const skipPrompts = shouldSkipPrompts({
|
|
19142
20136
|
yes: flags.yes,
|
|
19143
|
-
full: flags.full,
|
|
19144
20137
|
json: flags.json
|
|
19145
20138
|
});
|
|
19146
20139
|
if (flags.staged) {
|
|
@@ -19162,9 +20155,9 @@ const inspectAction = async (directory, flags) => {
|
|
|
19162
20155
|
cliLogger.log(`Scanning ${highlighter.info(`${stagedFiles.length}`)} staged files...`);
|
|
19163
20156
|
cliLogger.break();
|
|
19164
20157
|
}
|
|
19165
|
-
const tempDirectory = mkdtempSync(path.join(tmpdir(), STAGED_FILES_TEMP_DIR_PREFIX));
|
|
20158
|
+
const tempDirectory = fs$1.mkdtempSync(path$1.join(tmpdir(), STAGED_FILES_TEMP_DIR_PREFIX));
|
|
19166
20159
|
const snapshot = await materializeStagedFiles(resolvedDirectory, stagedFiles, tempDirectory).catch((error) => {
|
|
19167
|
-
rmSync(tempDirectory, {
|
|
20160
|
+
fs$1.rmSync(tempDirectory, {
|
|
19168
20161
|
recursive: true,
|
|
19169
20162
|
force: true
|
|
19170
20163
|
});
|
|
@@ -19178,7 +20171,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19178
20171
|
});
|
|
19179
20172
|
const remappedDiagnostics = scanResult.diagnostics.map((diagnostic) => ({
|
|
19180
20173
|
...diagnostic,
|
|
19181
|
-
filePath: path.isAbsolute(diagnostic.filePath) ? diagnostic.filePath.replaceAll(snapshot.tempDirectory, () => resolvedDirectory) : diagnostic.filePath
|
|
20174
|
+
filePath: path$1.isAbsolute(diagnostic.filePath) ? diagnostic.filePath.replaceAll(snapshot.tempDirectory, () => resolvedDirectory) : diagnostic.filePath
|
|
19182
20175
|
}));
|
|
19183
20176
|
finalizeScans({
|
|
19184
20177
|
diagnostics: remappedDiagnostics,
|
|
@@ -19195,6 +20188,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19195
20188
|
}],
|
|
19196
20189
|
mode: "staged",
|
|
19197
20190
|
diff: null,
|
|
20191
|
+
baselineIntended: false,
|
|
19198
20192
|
isJsonMode,
|
|
19199
20193
|
isScoreOnly,
|
|
19200
20194
|
flags,
|
|
@@ -19208,11 +20202,12 @@ const inspectAction = async (directory, flags) => {
|
|
|
19208
20202
|
return;
|
|
19209
20203
|
}
|
|
19210
20204
|
const projectDirectories = await selectProjects(resolvedDirectory, flags.project, skipPrompts);
|
|
19211
|
-
const changedFilesDiffInfo = flags.changedFilesFrom
|
|
20205
|
+
const changedFilesDiffInfo = flags.changedFilesFrom ? buildChangedFilesDiffInfo(readChangedFilesFrom(path$1.resolve(flags.changedFilesFrom))) : null;
|
|
19212
20206
|
const effectiveDiff = resolveEffectiveDiff(flags, userConfig);
|
|
19213
20207
|
const diffInfo = changedFilesDiffInfo ?? (changedFilesDiffInfo === null && (effectiveDiff !== void 0 && effectiveDiff !== false || !skipPrompts && !isQuiet) ? await getDiffInfo(resolvedDirectory, typeof effectiveDiff === "string" ? effectiveDiff : void 0) : null);
|
|
19214
20208
|
const isDiffMode = changedFilesDiffInfo !== null || await resolveDiffMode(diffInfo, effectiveDiff, skipPrompts, isQuiet);
|
|
19215
|
-
|
|
20209
|
+
const baselineRef = isDiffMode && diffInfo && !diffInfo.isCurrentChanges ? diffInfo.baseSha ? await resolveMergeBaseRef(resolvedDirectory, diffInfo.baseSha) : diffInfo.diffBaseRef ?? await resolveMergeBaseRef(resolvedDirectory, diffInfo.baseBranch) : null;
|
|
20210
|
+
setJsonReportMode(baselineRef ? "baseline" : isDiffMode ? "diff" : "full");
|
|
19216
20211
|
if (isDiffMode && diffInfo && !isQuiet) {
|
|
19217
20212
|
if (diffInfo.isCurrentChanges) cliLogger.log("Scanning uncommitted changes");
|
|
19218
20213
|
else {
|
|
@@ -19242,7 +20237,8 @@ const inspectAction = async (directory, flags) => {
|
|
|
19242
20237
|
...scanOptions,
|
|
19243
20238
|
includePaths,
|
|
19244
20239
|
configOverride: userConfig,
|
|
19245
|
-
suppressRendering: isMultiProject
|
|
20240
|
+
suppressRendering: isMultiProject,
|
|
20241
|
+
baseline: baselineRef ? { ref: baselineRef } : void 0
|
|
19246
20242
|
});
|
|
19247
20243
|
allDiagnostics.push(...scanResult.diagnostics);
|
|
19248
20244
|
completedScans.push({
|
|
@@ -19258,14 +20254,15 @@ const inspectAction = async (directory, flags) => {
|
|
|
19258
20254
|
userConfig,
|
|
19259
20255
|
verbose: Boolean(flags.verbose),
|
|
19260
20256
|
isOffline: !shouldShowShareLink,
|
|
19261
|
-
projectName: path.basename(resolvedDirectory)
|
|
20257
|
+
projectName: path$1.basename(resolvedDirectory)
|
|
19262
20258
|
}));
|
|
19263
20259
|
}
|
|
19264
20260
|
finalizeScans({
|
|
19265
20261
|
diagnostics: allDiagnostics,
|
|
19266
20262
|
completedScans,
|
|
19267
|
-
mode: isDiffMode ? "diff" : "full",
|
|
20263
|
+
mode: baselineRef ? "baseline" : isDiffMode ? "diff" : "full",
|
|
19268
20264
|
diff: isDiffMode ? diffInfo : null,
|
|
20265
|
+
baselineIntended: isDiffMode && diffInfo !== null && !diffInfo.isCurrentChanges,
|
|
19269
20266
|
isJsonMode,
|
|
19270
20267
|
isScoreOnly,
|
|
19271
20268
|
flags,
|
|
@@ -19277,7 +20274,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19277
20274
|
if (!isQuiet && !skipPrompts && process.stdout.isTTY === true && !isCiOrCodingAgentEnvironment() && surfaceDiagnostics.length > 0) {
|
|
19278
20275
|
await handoffToAgent({
|
|
19279
20276
|
diagnostics: surfaceDiagnostics,
|
|
19280
|
-
projectName: path.basename(resolvedDirectory),
|
|
20277
|
+
projectName: path$1.basename(resolvedDirectory),
|
|
19281
20278
|
rootDirectory: resolvedDirectory,
|
|
19282
20279
|
interactive: true
|
|
19283
20280
|
});
|
|
@@ -19303,7 +20300,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19303
20300
|
const isUserError = isExpectedUserError(error);
|
|
19304
20301
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
19305
20302
|
if (isJsonMode) {
|
|
19306
|
-
writeJsonErrorReport(error);
|
|
20303
|
+
writeJsonErrorReport(error, sentryEventId);
|
|
19307
20304
|
process.exitCode = 1;
|
|
19308
20305
|
return;
|
|
19309
20306
|
}
|
|
@@ -19461,7 +20458,7 @@ const resolveRuleConfigTarget = async (projectRoot) => {
|
|
|
19461
20458
|
}
|
|
19462
20459
|
return {
|
|
19463
20460
|
format: "json",
|
|
19464
|
-
filePath: path.join(projectRoot, NEW_CONFIG_FILENAME),
|
|
20461
|
+
filePath: path$1.join(projectRoot, NEW_CONFIG_FILENAME),
|
|
19465
20462
|
directory: projectRoot,
|
|
19466
20463
|
exists: false,
|
|
19467
20464
|
config: {}
|
|
@@ -19469,17 +20466,19 @@ const resolveRuleConfigTarget = async (projectRoot) => {
|
|
|
19469
20466
|
};
|
|
19470
20467
|
const writeJsonConfig = (filePath, nextConfig) => {
|
|
19471
20468
|
const { $schema, ...rest } = nextConfig;
|
|
19472
|
-
|
|
20469
|
+
const serialized = JSON.stringify({
|
|
19473
20470
|
$schema: $schema ?? "https://react.doctor/schema/config.json",
|
|
19474
20471
|
...rest
|
|
19475
|
-
}, null, JSON_INDENT_SPACES)
|
|
20472
|
+
}, null, JSON_INDENT_SPACES);
|
|
20473
|
+
fs$1.writeFileSync(filePath, `${serialized}\n`);
|
|
19476
20474
|
};
|
|
19477
20475
|
const writePackageJsonConfig = (filePath, nextConfig) => {
|
|
19478
20476
|
const packageJson = readObjectFile(filePath) ?? {};
|
|
19479
|
-
|
|
20477
|
+
const serialized = JSON.stringify({
|
|
19480
20478
|
...packageJson,
|
|
19481
20479
|
[PACKAGE_JSON_CONFIG_KEY]: nextConfig
|
|
19482
|
-
}, null, JSON_INDENT_SPACES)
|
|
20480
|
+
}, null, JSON_INDENT_SPACES);
|
|
20481
|
+
fs$1.writeFileSync(filePath, `${serialized}\n`);
|
|
19483
20482
|
};
|
|
19484
20483
|
const syncManagedKeys = (target, nextConfig) => {
|
|
19485
20484
|
for (const key of MANAGED_KEYS) {
|
|
@@ -19640,7 +20639,7 @@ const SEVERITY_VALUES = [
|
|
|
19640
20639
|
];
|
|
19641
20640
|
const recordRulesInvocation = () => recordCount(METRIC.cliInvoked, 1, { command: "rules" });
|
|
19642
20641
|
const resolveProjectRoot = (options) => {
|
|
19643
|
-
const requestedDirectory = path.resolve(options.cwd ?? process.cwd());
|
|
20642
|
+
const requestedDirectory = path$1.resolve(options.cwd ?? process.cwd());
|
|
19644
20643
|
return findNearestPackageDirectory(requestedDirectory) ?? requestedDirectory;
|
|
19645
20644
|
};
|
|
19646
20645
|
const parseSeverity = (value) => SEVERITY_VALUES.includes(value) ? value : null;
|
|
@@ -19654,7 +20653,7 @@ const reportRuleNotFound = (ruleQuery) => {
|
|
|
19654
20653
|
process.exitCode = 1;
|
|
19655
20654
|
};
|
|
19656
20655
|
const describeTargetPath = (target) => {
|
|
19657
|
-
const relativePath = path.relative(process.cwd(), target.filePath);
|
|
20656
|
+
const relativePath = path$1.relative(process.cwd(), target.filePath);
|
|
19658
20657
|
const displayPath = relativePath.length > 0 && !relativePath.startsWith("..") ? relativePath : target.filePath;
|
|
19659
20658
|
return target.exists ? displayPath : `${displayPath} ${highlighter.dim("(created)")}`;
|
|
19660
20659
|
};
|
|
@@ -19890,6 +20889,20 @@ const versionAction = () => {
|
|
|
19890
20889
|
process.stdout.write(`${buildVersionString()}\n`);
|
|
19891
20890
|
};
|
|
19892
20891
|
//#endregion
|
|
20892
|
+
//#region src/cli/commands/why.ts
|
|
20893
|
+
/**
|
|
20894
|
+
* `why <file:line>` — explains why a rule fired (or why a suppression didn't
|
|
20895
|
+
* apply) at a specific location. A thin wrapper over the inspect flow's
|
|
20896
|
+
* single-location explain path so it reuses the same scan, config resolution,
|
|
20897
|
+
* and clean error handling. (Replaces the former `--explain` / `--why` flags.)
|
|
20898
|
+
*/
|
|
20899
|
+
const whyAction = async (location, options) => {
|
|
20900
|
+
await inspectAction(options.cwd ?? process.cwd(), {
|
|
20901
|
+
explain: location,
|
|
20902
|
+
project: options.project
|
|
20903
|
+
});
|
|
20904
|
+
};
|
|
20905
|
+
//#endregion
|
|
19893
20906
|
//#region src/cli/utils/apply-color-preference.ts
|
|
19894
20907
|
/**
|
|
19895
20908
|
* Resolve an explicit color preference from `--color` / `--no-color` or the
|
|
@@ -19991,13 +21004,32 @@ const normalizeHelpInvocation = (argv, knownCommands) => {
|
|
|
19991
21004
|
return [...nodeArguments, "--help"];
|
|
19992
21005
|
};
|
|
19993
21006
|
//#endregion
|
|
21007
|
+
//#region src/cli/utils/removed-cli-flags.ts
|
|
21008
|
+
const REMOVED_FLAGS = new Map([
|
|
21009
|
+
["--full", "use `--diff false` to force a full scan"],
|
|
21010
|
+
["--explain", "use the `why <file>:<line>` command"],
|
|
21011
|
+
["--why", "use the `why <file>:<line>` command"],
|
|
21012
|
+
["--pr-comment", "the GitHub Action posts the PR comment for you; remove this flag"]
|
|
21013
|
+
]);
|
|
21014
|
+
/**
|
|
21015
|
+
* Throws a clean {@link CliInputError} when a removed flag appears in argv,
|
|
21016
|
+
* pointing to its replacement. Run before flag stripping so a removed flag is a
|
|
21017
|
+
* loud, actionable error rather than a silent no-op.
|
|
21018
|
+
*/
|
|
21019
|
+
const assertNoRemovedFlags = (argv) => {
|
|
21020
|
+
for (const argument of argv.slice(2)) {
|
|
21021
|
+
if (argument === "--") return;
|
|
21022
|
+
const optionName = argument.includes("=") ? argument.slice(0, argument.indexOf("=")) : argument;
|
|
21023
|
+
const guidance = REMOVED_FLAGS.get(optionName);
|
|
21024
|
+
if (guidance !== void 0) throw new CliInputError(`\`${optionName}\` was removed — ${guidance}.`);
|
|
21025
|
+
}
|
|
21026
|
+
};
|
|
21027
|
+
//#endregion
|
|
19994
21028
|
//#region src/cli/utils/strip-unknown-cli-flags.ts
|
|
19995
21029
|
const ROOT_FLAG_SPEC = {
|
|
19996
21030
|
longOptionsWithoutValues: new Set([
|
|
19997
|
-
"--annotations",
|
|
19998
21031
|
"--color",
|
|
19999
21032
|
"--dead-code",
|
|
20000
|
-
"--full",
|
|
20001
21033
|
"--help",
|
|
20002
21034
|
"--json",
|
|
20003
21035
|
"--json-compact",
|
|
@@ -20010,8 +21042,6 @@ const ROOT_FLAG_SPEC = {
|
|
|
20010
21042
|
"--no-score",
|
|
20011
21043
|
"--no-telemetry",
|
|
20012
21044
|
"--no-warnings",
|
|
20013
|
-
"--pr-comment",
|
|
20014
|
-
"--respect-inline-disables",
|
|
20015
21045
|
"--score",
|
|
20016
21046
|
"--staged",
|
|
20017
21047
|
"--verbose",
|
|
@@ -20021,10 +21051,9 @@ const ROOT_FLAG_SPEC = {
|
|
|
20021
21051
|
]),
|
|
20022
21052
|
longOptionsWithRequiredValues: new Set([
|
|
20023
21053
|
"--changed-files-from",
|
|
20024
|
-
"--
|
|
21054
|
+
"--blocking",
|
|
20025
21055
|
"--fail-on",
|
|
20026
|
-
"--project"
|
|
20027
|
-
"--why"
|
|
21056
|
+
"--project"
|
|
20028
21057
|
]),
|
|
20029
21058
|
longOptionsWithOptionalValues: new Set(["--diff"]),
|
|
20030
21059
|
shortOptionsWithoutValues: new Set([
|
|
@@ -20080,6 +21109,17 @@ const COMMAND_FLAG_SPECS = new Map([
|
|
|
20080
21109
|
longOptionsWithOptionalValues: /* @__PURE__ */ new Set(),
|
|
20081
21110
|
shortOptionsWithoutValues: new Set(["-h"]),
|
|
20082
21111
|
shortOptionsWithRequiredValues: new Set(["-c"])
|
|
21112
|
+
}],
|
|
21113
|
+
["why", {
|
|
21114
|
+
longOptionsWithoutValues: new Set([
|
|
21115
|
+
"--color",
|
|
21116
|
+
"--help",
|
|
21117
|
+
"--no-color"
|
|
21118
|
+
]),
|
|
21119
|
+
longOptionsWithRequiredValues: new Set(["--cwd", "--project"]),
|
|
21120
|
+
longOptionsWithOptionalValues: /* @__PURE__ */ new Set(),
|
|
21121
|
+
shortOptionsWithoutValues: new Set(["-h"]),
|
|
21122
|
+
shortOptionsWithRequiredValues: new Set(["-c"])
|
|
20083
21123
|
}]
|
|
20084
21124
|
]);
|
|
20085
21125
|
const isFlagLike = (argument) => argument.startsWith("-") && argument !== "-";
|
|
@@ -20166,9 +21206,9 @@ ${formatExampleLines([
|
|
|
20166
21206
|
["react-doctor ./apps/web", "scan a specific directory"],
|
|
20167
21207
|
["react-doctor --diff main", "scan only files changed vs. main"],
|
|
20168
21208
|
["react-doctor --staged", "scan staged files (pre-commit hook)"],
|
|
20169
|
-
["react-doctor --
|
|
21209
|
+
["react-doctor --blocking warning", "fail CI on warnings too (default: error)"],
|
|
20170
21210
|
["react-doctor --json > report.json", "write a machine-readable report"],
|
|
20171
|
-
["react-doctor
|
|
21211
|
+
["react-doctor why src/App.tsx:42", "explain why a rule fired there"],
|
|
20172
21212
|
["react-doctor install", "set up the agent skill and git hook"]
|
|
20173
21213
|
])}
|
|
20174
21214
|
|
|
@@ -20194,8 +21234,9 @@ ${formatExampleLines([
|
|
|
20194
21234
|
${highlighter.dim("Learn more:")}
|
|
20195
21235
|
${highlighter.info(CANONICAL_GITHUB_URL)}
|
|
20196
21236
|
`;
|
|
20197
|
-
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("--
|
|
21237
|
+
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);
|
|
20198
21238
|
program.action(inspectAction);
|
|
21239
|
+
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));
|
|
20199
21240
|
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);
|
|
20200
21241
|
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);
|
|
20201
21242
|
const rules = program.command("rules").description("List, explain, and configure which React Doctor rules run");
|
|
@@ -20207,6 +21248,7 @@ rules.command("disable <rule>").description("Disable a rule so it never runs").o
|
|
|
20207
21248
|
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()));
|
|
20208
21249
|
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()));
|
|
20209
21250
|
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()));
|
|
21251
|
+
program.command("experimental-lsp", { hidden: false }).description("[experimental] run the React Doctor language server over stdio (for editors)").allowUnknownOption().action(() => {});
|
|
20210
21252
|
process.stdout.on("error", (error) => {
|
|
20211
21253
|
if (error.code === "EPIPE") process.exit(0);
|
|
20212
21254
|
});
|
|
@@ -20218,11 +21260,11 @@ if (process.argv.includes("-V") && !strippedArgv.includes("-V")) {
|
|
|
20218
21260
|
}
|
|
20219
21261
|
applyColorPreference(strippedArgv);
|
|
20220
21262
|
const argv = normalizeHelpInvocation(strippedArgv, knownCommands);
|
|
20221
|
-
program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
21263
|
+
Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => program.parseAsync(argv)).then(() => flushSentry()).catch(async (error) => {
|
|
20222
21264
|
const isUserError = isExpectedUserError(error);
|
|
20223
21265
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
20224
21266
|
if (isJsonModeActive()) {
|
|
20225
|
-
writeJsonErrorReport(error);
|
|
21267
|
+
writeJsonErrorReport(error, sentryEventId);
|
|
20226
21268
|
process.exit(1);
|
|
20227
21269
|
}
|
|
20228
21270
|
if (isUserError) {
|
|
@@ -20235,4 +21277,4 @@ program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
|
20235
21277
|
export {};
|
|
20236
21278
|
|
|
20237
21279
|
//# sourceMappingURL=cli.js.map
|
|
20238
|
-
//# debugId=
|
|
21280
|
+
//# debugId=3c457dc9-865a-5459-b923-a0fb762b158f
|