react-doctor 0.2.18-dev.f375dbb → 0.3.0-dev.915745e
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 +13 -1
- package/bin/react-doctor.js +9 -1
- package/dist/cli.js +1187 -468
- package/dist/index.d.ts +44 -1
- package/dist/index.js +334 -210
- package/dist/lsp.js +10741 -0
- package/package.json +9 -5
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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]="ac54f8ec-45d1-5b7d-8208-35f50f4c4973")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
5
|
import * as fs$1 from "node:fs";
|
|
6
|
-
import fs
|
|
7
|
-
import * as
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import * as path$1 from "node:path";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { spawn, spawnSync } from "node:child_process";
|
|
10
10
|
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";
|
|
@@ -33,6 +33,7 @@ import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
|
33
33
|
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
34
34
|
import * as ts from "typescript";
|
|
35
35
|
import { gzipSync } from "node:zlib";
|
|
36
|
+
import "effect/Exit";
|
|
36
37
|
//#region \0rolldown/runtime.js
|
|
37
38
|
var __create$1 = Object.create;
|
|
38
39
|
var __defProp$1 = Object.defineProperty;
|
|
@@ -58,6 +59,16 @@ var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(
|
|
|
58
59
|
//#endregion
|
|
59
60
|
//#region ../core/dist/schemas.js
|
|
60
61
|
const Severity = Schema.Literals(["error", "warning"]);
|
|
62
|
+
var DiagnosticRelatedLocation = class extends Schema.Class("DiagnosticRelatedLocation")({
|
|
63
|
+
filePath: Schema.String,
|
|
64
|
+
line: Schema.Number,
|
|
65
|
+
column: Schema.Number,
|
|
66
|
+
offset: Schema.optional(Schema.Number),
|
|
67
|
+
length: Schema.optional(Schema.Number),
|
|
68
|
+
endLine: Schema.optional(Schema.Number),
|
|
69
|
+
endColumn: Schema.optional(Schema.Number),
|
|
70
|
+
message: Schema.String
|
|
71
|
+
}) {};
|
|
61
72
|
var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
62
73
|
filePath: Schema.String,
|
|
63
74
|
plugin: Schema.String,
|
|
@@ -69,8 +80,13 @@ var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
|
69
80
|
url: Schema.optional(Schema.String),
|
|
70
81
|
line: Schema.Number,
|
|
71
82
|
column: Schema.Number,
|
|
83
|
+
offset: Schema.optional(Schema.Number),
|
|
84
|
+
length: Schema.optional(Schema.Number),
|
|
85
|
+
endLine: Schema.optional(Schema.Number),
|
|
86
|
+
endColumn: Schema.optional(Schema.Number),
|
|
72
87
|
category: Schema.String,
|
|
73
|
-
suppressionHint: Schema.optional(Schema.String)
|
|
88
|
+
suppressionHint: Schema.optional(Schema.String),
|
|
89
|
+
relatedLocations: Schema.optional(Schema.Array(DiagnosticRelatedLocation))
|
|
74
90
|
}) {};
|
|
75
91
|
const JsonReportMode = Schema.Literals([
|
|
76
92
|
"full",
|
|
@@ -2075,7 +2091,7 @@ var AmbiguousProjectError = class extends Error {
|
|
|
2075
2091
|
const isProjectDiscoveryError = (value) => value instanceof ProjectNotFoundError || value instanceof NoReactDependencyError || value instanceof PackageJsonNotFoundError || value instanceof NotADirectoryError || value instanceof AmbiguousProjectError;
|
|
2076
2092
|
const isFile = (filePath) => {
|
|
2077
2093
|
try {
|
|
2078
|
-
return fs.statSync(filePath).isFile();
|
|
2094
|
+
return fs$1.statSync(filePath).isFile();
|
|
2079
2095
|
} catch {
|
|
2080
2096
|
return false;
|
|
2081
2097
|
}
|
|
@@ -2102,9 +2118,9 @@ const isLintableSourceFile = (filePath) => SOURCE_FILE_PATTERN.test(filePath) &&
|
|
|
2102
2118
|
const isMinifiedSource = (absolutePath) => {
|
|
2103
2119
|
let fileDescriptor;
|
|
2104
2120
|
try {
|
|
2105
|
-
fileDescriptor = fs.openSync(absolutePath, "r");
|
|
2121
|
+
fileDescriptor = fs$1.openSync(absolutePath, "r");
|
|
2106
2122
|
const buffer = Buffer.alloc(MINIFIED_SNIFF_BYTES);
|
|
2107
|
-
const bytesRead = fs.readSync(fileDescriptor, buffer, 0, MINIFIED_SNIFF_BYTES, 0);
|
|
2123
|
+
const bytesRead = fs$1.readSync(fileDescriptor, buffer, 0, MINIFIED_SNIFF_BYTES, 0);
|
|
2108
2124
|
const prefix = buffer.toString("utf8", 0, bytesRead);
|
|
2109
2125
|
const lines = prefix.split("\n");
|
|
2110
2126
|
const longestLineLength = lines.reduce((longest, line) => Math.max(longest, line.length), 0);
|
|
@@ -2113,13 +2129,13 @@ const isMinifiedSource = (absolutePath) => {
|
|
|
2113
2129
|
} catch {
|
|
2114
2130
|
return false;
|
|
2115
2131
|
} finally {
|
|
2116
|
-
if (fileDescriptor !== void 0) fs.closeSync(fileDescriptor);
|
|
2132
|
+
if (fileDescriptor !== void 0) fs$1.closeSync(fileDescriptor);
|
|
2117
2133
|
}
|
|
2118
2134
|
};
|
|
2119
2135
|
const isLargeMinifiedFile = (absolutePath) => {
|
|
2120
2136
|
let sizeBytes;
|
|
2121
2137
|
try {
|
|
2122
|
-
sizeBytes = fs.statSync(absolutePath).size;
|
|
2138
|
+
sizeBytes = fs$1.statSync(absolutePath).size;
|
|
2123
2139
|
} catch {
|
|
2124
2140
|
return false;
|
|
2125
2141
|
}
|
|
@@ -2130,7 +2146,10 @@ const IGNORABLE_READDIR_ERROR_CODES = new Set([
|
|
|
2130
2146
|
"EACCES",
|
|
2131
2147
|
"EPERM",
|
|
2132
2148
|
"ENOENT",
|
|
2133
|
-
"ENOTDIR"
|
|
2149
|
+
"ENOTDIR",
|
|
2150
|
+
"EINVAL",
|
|
2151
|
+
"ELOOP",
|
|
2152
|
+
"ENAMETOOLONG"
|
|
2134
2153
|
]);
|
|
2135
2154
|
const isIgnorableReaddirError = (error) => {
|
|
2136
2155
|
if (typeof error !== "object" || error === null) return false;
|
|
@@ -2139,7 +2158,7 @@ const isIgnorableReaddirError = (error) => {
|
|
|
2139
2158
|
};
|
|
2140
2159
|
const readDirectoryEntries = (directoryPath) => {
|
|
2141
2160
|
try {
|
|
2142
|
-
return fs.readdirSync(directoryPath, { withFileTypes: true });
|
|
2161
|
+
return fs$1.readdirSync(directoryPath, { withFileTypes: true });
|
|
2143
2162
|
} catch (error) {
|
|
2144
2163
|
if (isIgnorableReaddirError(error)) return [];
|
|
2145
2164
|
throw error;
|
|
@@ -2153,10 +2172,10 @@ const countSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
2153
2172
|
const entries = readDirectoryEntries(currentDirectory);
|
|
2154
2173
|
for (const entry of entries) {
|
|
2155
2174
|
if (entry.isDirectory()) {
|
|
2156
|
-
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(path.join(currentDirectory, entry.name));
|
|
2175
|
+
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(path$1.join(currentDirectory, entry.name));
|
|
2157
2176
|
continue;
|
|
2158
2177
|
}
|
|
2159
|
-
if (entry.isFile() && isLintableSourceFile(entry.name) && !isLargeMinifiedFile(path.join(currentDirectory, entry.name))) count++;
|
|
2178
|
+
if (entry.isFile() && isLintableSourceFile(entry.name) && !isLargeMinifiedFile(path$1.join(currentDirectory, entry.name))) count++;
|
|
2160
2179
|
}
|
|
2161
2180
|
}
|
|
2162
2181
|
return count;
|
|
@@ -2174,7 +2193,7 @@ const countSourceFilesViaGit = (rootDirectory) => {
|
|
|
2174
2193
|
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
2175
2194
|
});
|
|
2176
2195
|
if (result.error || result.status !== 0) return null;
|
|
2177
|
-
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath) && !isLargeMinifiedFile(path.resolve(rootDirectory, filePath))).length;
|
|
2196
|
+
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath) && !isLargeMinifiedFile(path$1.resolve(rootDirectory, filePath))).length;
|
|
2178
2197
|
};
|
|
2179
2198
|
const countSourceFiles = (rootDirectory) => countSourceFilesViaGit(rootDirectory) ?? countSourceFilesViaFilesystem(rootDirectory);
|
|
2180
2199
|
const cachedPackageJsons = /* @__PURE__ */ new Map();
|
|
@@ -2183,7 +2202,7 @@ const clearPackageJsonCache = () => {
|
|
|
2183
2202
|
};
|
|
2184
2203
|
const readPackageJsonUncached = (packageJsonPath) => {
|
|
2185
2204
|
try {
|
|
2186
|
-
return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
2205
|
+
return JSON.parse(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
2187
2206
|
} catch (error) {
|
|
2188
2207
|
if (error instanceof SyntaxError) return {};
|
|
2189
2208
|
if (error instanceof Error && "code" in error) {
|
|
@@ -2194,7 +2213,7 @@ const readPackageJsonUncached = (packageJsonPath) => {
|
|
|
2194
2213
|
}
|
|
2195
2214
|
};
|
|
2196
2215
|
const readPackageJson = (packageJsonPath) => {
|
|
2197
|
-
const absolutePath = path.resolve(packageJsonPath);
|
|
2216
|
+
const absolutePath = path$1.resolve(packageJsonPath);
|
|
2198
2217
|
const cached = cachedPackageJsons.get(absolutePath);
|
|
2199
2218
|
if (cached !== void 0) return cached;
|
|
2200
2219
|
const result = readPackageJsonUncached(absolutePath);
|
|
@@ -2202,18 +2221,18 @@ const readPackageJson = (packageJsonPath) => {
|
|
|
2202
2221
|
return result;
|
|
2203
2222
|
};
|
|
2204
2223
|
const isMonorepoRoot = (directory) => {
|
|
2205
|
-
if (isFile(path.join(directory, "pnpm-workspace.yaml"))) return true;
|
|
2206
|
-
if (isFile(path.join(directory, "nx.json"))) return true;
|
|
2207
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
2224
|
+
if (isFile(path$1.join(directory, "pnpm-workspace.yaml"))) return true;
|
|
2225
|
+
if (isFile(path$1.join(directory, "nx.json"))) return true;
|
|
2226
|
+
const packageJsonPath = path$1.join(directory, "package.json");
|
|
2208
2227
|
if (!isFile(packageJsonPath)) return false;
|
|
2209
2228
|
const packageJson = readPackageJson(packageJsonPath);
|
|
2210
2229
|
return Array.isArray(packageJson.workspaces) || Boolean(packageJson.workspaces?.packages);
|
|
2211
2230
|
};
|
|
2212
2231
|
const findMonorepoRoot = (startDirectory) => {
|
|
2213
|
-
let currentDirectory = path.dirname(startDirectory);
|
|
2214
|
-
while (currentDirectory !== path.dirname(currentDirectory)) {
|
|
2232
|
+
let currentDirectory = path$1.dirname(startDirectory);
|
|
2233
|
+
while (currentDirectory !== path$1.dirname(currentDirectory)) {
|
|
2215
2234
|
if (isMonorepoRoot(currentDirectory)) return currentDirectory;
|
|
2216
|
-
currentDirectory = path.dirname(currentDirectory);
|
|
2235
|
+
currentDirectory = path$1.dirname(currentDirectory);
|
|
2217
2236
|
}
|
|
2218
2237
|
return null;
|
|
2219
2238
|
};
|
|
@@ -2227,7 +2246,7 @@ const findMonorepoRoot = (startDirectory) => {
|
|
|
2227
2246
|
* `detectReactCompiler`. All three previously inlined their own
|
|
2228
2247
|
* byte-equivalent copy.
|
|
2229
2248
|
*/
|
|
2230
|
-
const isProjectBoundary = (directory) => fs.existsSync(path.join(directory, ".git")) || isMonorepoRoot(directory);
|
|
2249
|
+
const isProjectBoundary = (directory) => fs$1.existsSync(path$1.join(directory, ".git")) || isMonorepoRoot(directory);
|
|
2231
2250
|
const REACT_COMPILER_PACKAGES = new Set([
|
|
2232
2251
|
"babel-plugin-react-compiler",
|
|
2233
2252
|
"react-compiler-runtime",
|
|
@@ -2274,10 +2293,10 @@ const hasCompilerPackage = (packageJson) => {
|
|
|
2274
2293
|
};
|
|
2275
2294
|
const hasCompilerInConfigFile = (filePath) => {
|
|
2276
2295
|
if (!isFile(filePath)) return false;
|
|
2277
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
2296
|
+
const content = fs$1.readFileSync(filePath, "utf-8");
|
|
2278
2297
|
return REACT_COMPILER_ENABLED_FLAG_PATTERN.test(content) || REACT_COMPILER_PACKAGE_REFERENCE_PATTERN.test(content);
|
|
2279
2298
|
};
|
|
2280
|
-
const hasCompilerInConfigFiles = (directory, filenames) => filenames.some((filename) => hasCompilerInConfigFile(path.join(directory, filename)));
|
|
2299
|
+
const hasCompilerInConfigFiles = (directory, filenames) => filenames.some((filename) => hasCompilerInConfigFile(path$1.join(directory, filename)));
|
|
2281
2300
|
const detectReactCompiler = (directory, packageJson) => {
|
|
2282
2301
|
if (hasCompilerPackage(packageJson)) return true;
|
|
2283
2302
|
if (hasCompilerInConfigFiles(directory, NEXT_CONFIG_FILENAMES)) return true;
|
|
@@ -2285,14 +2304,14 @@ const detectReactCompiler = (directory, packageJson) => {
|
|
|
2285
2304
|
if (hasCompilerInConfigFiles(directory, VITE_CONFIG_FILENAMES)) return true;
|
|
2286
2305
|
if (hasCompilerInConfigFiles(directory, EXPO_APP_CONFIG_FILENAMES)) return true;
|
|
2287
2306
|
if (isProjectBoundary(directory)) return false;
|
|
2288
|
-
let ancestorDirectory = path.dirname(directory);
|
|
2289
|
-
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
2290
|
-
const ancestorPackagePath = path.join(ancestorDirectory, "package.json");
|
|
2307
|
+
let ancestorDirectory = path$1.dirname(directory);
|
|
2308
|
+
while (ancestorDirectory !== path$1.dirname(ancestorDirectory)) {
|
|
2309
|
+
const ancestorPackagePath = path$1.join(ancestorDirectory, "package.json");
|
|
2291
2310
|
if (isFile(ancestorPackagePath)) {
|
|
2292
2311
|
if (hasCompilerPackage(readPackageJson(ancestorPackagePath))) return true;
|
|
2293
2312
|
}
|
|
2294
2313
|
if (isProjectBoundary(ancestorDirectory)) return false;
|
|
2295
|
-
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
2314
|
+
ancestorDirectory = path$1.dirname(ancestorDirectory);
|
|
2296
2315
|
}
|
|
2297
2316
|
return false;
|
|
2298
2317
|
};
|
|
@@ -2478,12 +2497,12 @@ const resolveVersionFromCatalog = (catalog, packageName) => {
|
|
|
2478
2497
|
return null;
|
|
2479
2498
|
};
|
|
2480
2499
|
const parsePnpmWorkspaceCatalogs = (rootDirectory) => {
|
|
2481
|
-
const workspacePath = path.join(rootDirectory, "pnpm-workspace.yaml");
|
|
2500
|
+
const workspacePath = path$1.join(rootDirectory, "pnpm-workspace.yaml");
|
|
2482
2501
|
if (!isFile(workspacePath)) return {
|
|
2483
2502
|
defaultCatalog: {},
|
|
2484
2503
|
namedCatalogs: {}
|
|
2485
2504
|
};
|
|
2486
|
-
const content = fs.readFileSync(workspacePath, "utf-8");
|
|
2505
|
+
const content = fs$1.readFileSync(workspacePath, "utf-8");
|
|
2487
2506
|
const defaultCatalog = {};
|
|
2488
2507
|
const namedCatalogs = {};
|
|
2489
2508
|
let currentSection = "none";
|
|
@@ -2664,7 +2683,7 @@ const getDependencyDeclaration = ({ packageJson, packageName, sections }) => {
|
|
|
2664
2683
|
};
|
|
2665
2684
|
const isDirectory = (directoryPath) => {
|
|
2666
2685
|
try {
|
|
2667
|
-
return fs.statSync(directoryPath).isDirectory();
|
|
2686
|
+
return fs$1.statSync(directoryPath).isDirectory();
|
|
2668
2687
|
} catch {
|
|
2669
2688
|
return false;
|
|
2670
2689
|
}
|
|
@@ -2675,23 +2694,23 @@ const NX_PROJECT_DISCOVERY_DIRS = [
|
|
|
2675
2694
|
"packages"
|
|
2676
2695
|
];
|
|
2677
2696
|
const getNxWorkspaceDirectories = (rootDirectory) => {
|
|
2678
|
-
if (!isFile(path.join(rootDirectory, "nx.json"))) return [];
|
|
2697
|
+
if (!isFile(path$1.join(rootDirectory, "nx.json"))) return [];
|
|
2679
2698
|
const collected = [];
|
|
2680
2699
|
for (const candidate of NX_PROJECT_DISCOVERY_DIRS) {
|
|
2681
|
-
const candidatePath = path.join(rootDirectory, candidate);
|
|
2700
|
+
const candidatePath = path$1.join(rootDirectory, candidate);
|
|
2682
2701
|
if (!isDirectory(candidatePath)) continue;
|
|
2683
2702
|
for (const entry of readDirectoryEntries(candidatePath)) {
|
|
2684
2703
|
if (!entry.isDirectory()) continue;
|
|
2685
|
-
const projectDirectory = path.join(candidatePath, entry.name);
|
|
2686
|
-
if (isFile(path.join(projectDirectory, "project.json")) || isFile(path.join(projectDirectory, "package.json"))) collected.push(`${candidate}/${entry.name}`);
|
|
2704
|
+
const projectDirectory = path$1.join(candidatePath, entry.name);
|
|
2705
|
+
if (isFile(path$1.join(projectDirectory, "project.json")) || isFile(path$1.join(projectDirectory, "package.json"))) collected.push(`${candidate}/${entry.name}`);
|
|
2687
2706
|
}
|
|
2688
2707
|
}
|
|
2689
2708
|
return collected;
|
|
2690
2709
|
};
|
|
2691
2710
|
const parsePnpmWorkspacePatterns = (rootDirectory) => {
|
|
2692
|
-
const workspacePath = path.join(rootDirectory, "pnpm-workspace.yaml");
|
|
2711
|
+
const workspacePath = path$1.join(rootDirectory, "pnpm-workspace.yaml");
|
|
2693
2712
|
if (!isFile(workspacePath)) return [];
|
|
2694
|
-
const content = fs.readFileSync(workspacePath, "utf-8");
|
|
2713
|
+
const content = fs$1.readFileSync(workspacePath, "utf-8");
|
|
2695
2714
|
const patterns = [];
|
|
2696
2715
|
let isInsidePackagesBlock = false;
|
|
2697
2716
|
for (const line of content.split("\n")) {
|
|
@@ -2721,18 +2740,18 @@ const parseReactMajor = (reactVersion) => {
|
|
|
2721
2740
|
const resolveWorkspaceDirectories = (rootDirectory, pattern) => {
|
|
2722
2741
|
const cleanPattern = pattern.replace(/["']/g, "").replace(/\/\*\*$/, "/*");
|
|
2723
2742
|
if (!cleanPattern.includes("*")) {
|
|
2724
|
-
const directoryPath = path.join(rootDirectory, cleanPattern);
|
|
2725
|
-
if (isDirectory(directoryPath) && isFile(path.join(directoryPath, "package.json"))) return [directoryPath];
|
|
2743
|
+
const directoryPath = path$1.join(rootDirectory, cleanPattern);
|
|
2744
|
+
if (isDirectory(directoryPath) && isFile(path$1.join(directoryPath, "package.json"))) return [directoryPath];
|
|
2726
2745
|
return [];
|
|
2727
2746
|
}
|
|
2728
2747
|
const wildcardIndex = cleanPattern.indexOf("*");
|
|
2729
|
-
const baseDirectory = path.join(rootDirectory, cleanPattern.slice(0, wildcardIndex));
|
|
2748
|
+
const baseDirectory = path$1.join(rootDirectory, cleanPattern.slice(0, wildcardIndex));
|
|
2730
2749
|
const suffixAfterWildcard = cleanPattern.slice(wildcardIndex + 1);
|
|
2731
2750
|
if (!isDirectory(baseDirectory)) return [];
|
|
2732
2751
|
const resolved = [];
|
|
2733
2752
|
for (const entry of readDirectoryEntries(baseDirectory)) {
|
|
2734
|
-
const entryPath = path.join(baseDirectory, entry.name, suffixAfterWildcard);
|
|
2735
|
-
if (isDirectory(entryPath) && isFile(path.join(entryPath, "package.json"))) resolved.push(entryPath);
|
|
2753
|
+
const entryPath = path$1.join(baseDirectory, entry.name, suffixAfterWildcard);
|
|
2754
|
+
if (isDirectory(entryPath) && isFile(path$1.join(entryPath, "package.json"))) resolved.push(entryPath);
|
|
2736
2755
|
}
|
|
2737
2756
|
return resolved;
|
|
2738
2757
|
};
|
|
@@ -2759,7 +2778,7 @@ const findReactInWorkspaces = (rootDirectory, packageJson) => {
|
|
|
2759
2778
|
for (const pattern of patterns) {
|
|
2760
2779
|
const directories = resolveWorkspaceDirectories(rootDirectory, pattern);
|
|
2761
2780
|
for (const workspaceDirectory of directories) {
|
|
2762
|
-
const workspacePackageJson = readPackageJson(path.join(workspaceDirectory, "package.json"));
|
|
2781
|
+
const workspacePackageJson = readPackageJson(path$1.join(workspaceDirectory, "package.json"));
|
|
2763
2782
|
const info = extractDependencyInfo(workspacePackageJson);
|
|
2764
2783
|
const reactVersion = resolveWorkspaceDependencyVersion({
|
|
2765
2784
|
concreteVersion: info.reactVersion,
|
|
@@ -2813,11 +2832,11 @@ const findReactInWorkspaces = (rootDirectory, packageJson) => {
|
|
|
2813
2832
|
const findDependencyInfoFromMonorepoRoot = (directory) => {
|
|
2814
2833
|
const monorepoRoot = findMonorepoRoot(directory);
|
|
2815
2834
|
if (!monorepoRoot) return EMPTY_DEPENDENCY_INFO;
|
|
2816
|
-
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
2835
|
+
const monorepoPackageJsonPath = path$1.join(monorepoRoot, "package.json");
|
|
2817
2836
|
if (!isFile(monorepoPackageJsonPath)) return EMPTY_DEPENDENCY_INFO;
|
|
2818
2837
|
const rootPackageJson = readPackageJson(monorepoPackageJsonPath);
|
|
2819
2838
|
const rootInfo = extractDependencyInfo(rootPackageJson);
|
|
2820
|
-
const leafPackageJsonPath = path.join(directory, "package.json");
|
|
2839
|
+
const leafPackageJsonPath = path$1.join(directory, "package.json");
|
|
2821
2840
|
const leafPackageJson = isFile(leafPackageJsonPath) ? readPackageJson(leafPackageJsonPath) : null;
|
|
2822
2841
|
const leafReactDeclaration = leafPackageJson ? getDependencyDeclaration({
|
|
2823
2842
|
packageJson: leafPackageJson,
|
|
@@ -2871,7 +2890,7 @@ const findInWorkspacePackageJsons = (rootDirectory, rootPackageJson, select) =>
|
|
|
2871
2890
|
for (const workspaceDirectory of directories) {
|
|
2872
2891
|
if (visitedDirectories.has(workspaceDirectory)) continue;
|
|
2873
2892
|
visitedDirectories.add(workspaceDirectory);
|
|
2874
|
-
const value = select(readPackageJson(path.join(workspaceDirectory, "package.json")));
|
|
2893
|
+
const value = select(readPackageJson(path$1.join(workspaceDirectory, "package.json")));
|
|
2875
2894
|
if (value !== null) return value;
|
|
2876
2895
|
}
|
|
2877
2896
|
}
|
|
@@ -2916,6 +2935,23 @@ const getExpoDependencySpec = (packageJson) => {
|
|
|
2916
2935
|
return typeof spec === "string" ? spec : null;
|
|
2917
2936
|
};
|
|
2918
2937
|
const findExpoVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getExpoDependencySpec);
|
|
2938
|
+
const SHOPIFY_FLASH_LIST_PACKAGE_NAME = "@shopify/flash-list";
|
|
2939
|
+
const getShopifyFlashListDependencySpec = (packageJson) => {
|
|
2940
|
+
const spec = packageJson.dependencies?.["@shopify/flash-list"] ?? packageJson.devDependencies?.["@shopify/flash-list"] ?? packageJson.peerDependencies?.["@shopify/flash-list"] ?? packageJson.optionalDependencies?.["@shopify/flash-list"];
|
|
2941
|
+
return typeof spec === "string" ? spec : null;
|
|
2942
|
+
};
|
|
2943
|
+
const findShopifyFlashListVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getShopifyFlashListDependencySpec);
|
|
2944
|
+
const resolveCatalogBackedDependencyVersion = ({ rootDirectory, rootPackageJson, packageName, version }) => {
|
|
2945
|
+
if (version === null || !isCatalogReference(version)) return version;
|
|
2946
|
+
const catalogName = extractCatalogName(version);
|
|
2947
|
+
const resolvedLocalVersion = resolveCatalogVersion(rootPackageJson, packageName, rootDirectory, catalogName);
|
|
2948
|
+
if (resolvedLocalVersion) return resolvedLocalVersion;
|
|
2949
|
+
const monorepoRoot = findMonorepoRoot(rootDirectory);
|
|
2950
|
+
if (!monorepoRoot) return version;
|
|
2951
|
+
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
2952
|
+
if (!isFile(monorepoPackageJsonPath)) return version;
|
|
2953
|
+
return resolveCatalogVersion(readPackageJson(monorepoPackageJsonPath), packageName, monorepoRoot, catalogName) ?? version;
|
|
2954
|
+
};
|
|
2919
2955
|
const getPreactVersion = (packageJson) => {
|
|
2920
2956
|
return {
|
|
2921
2957
|
...packageJson.peerDependencies,
|
|
@@ -2986,7 +3022,7 @@ const hasReactDependency = (packageJson) => {
|
|
|
2986
3022
|
return Object.keys(allDependencies).some((packageName) => REACT_DEPENDENCY_NAMES.has(packageName));
|
|
2987
3023
|
};
|
|
2988
3024
|
const listWorkspacePackages = (rootDirectory) => {
|
|
2989
|
-
const packageJsonPath = path.join(rootDirectory, "package.json");
|
|
3025
|
+
const packageJsonPath = path$1.join(rootDirectory, "package.json");
|
|
2990
3026
|
if (!isFile(packageJsonPath)) return [];
|
|
2991
3027
|
const packageJson = readPackageJson(packageJsonPath);
|
|
2992
3028
|
const patterns = getWorkspacePatterns(rootDirectory, packageJson);
|
|
@@ -2999,16 +3035,16 @@ const listWorkspacePackages = (rootDirectory) => {
|
|
|
2999
3035
|
packages.push(workspacePackage);
|
|
3000
3036
|
};
|
|
3001
3037
|
if (hasReactDependency(packageJson)) pushIfNew({
|
|
3002
|
-
name: packageJson.name ?? path.basename(rootDirectory),
|
|
3038
|
+
name: packageJson.name ?? path$1.basename(rootDirectory),
|
|
3003
3039
|
directory: rootDirectory
|
|
3004
3040
|
});
|
|
3005
3041
|
for (const pattern of patterns) {
|
|
3006
3042
|
const directories = resolveWorkspaceDirectories(rootDirectory, pattern);
|
|
3007
3043
|
for (const workspaceDirectory of directories) {
|
|
3008
|
-
const workspacePackageJson = readPackageJson(path.join(workspaceDirectory, "package.json"));
|
|
3044
|
+
const workspacePackageJson = readPackageJson(path$1.join(workspaceDirectory, "package.json"));
|
|
3009
3045
|
if (!hasReactDependency(workspacePackageJson)) continue;
|
|
3010
3046
|
pushIfNew({
|
|
3011
|
-
name: workspacePackageJson.name ?? path.basename(workspaceDirectory),
|
|
3047
|
+
name: workspacePackageJson.name ?? path$1.basename(workspaceDirectory),
|
|
3012
3048
|
directory: workspaceDirectory
|
|
3013
3049
|
});
|
|
3014
3050
|
}
|
|
@@ -3018,11 +3054,11 @@ const listWorkspacePackages = (rootDirectory) => {
|
|
|
3018
3054
|
const toReactWorkspacePackages = (directories) => {
|
|
3019
3055
|
const packages = [];
|
|
3020
3056
|
for (const directory of directories) {
|
|
3021
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
3057
|
+
const packageJsonPath = path$1.join(directory, "package.json");
|
|
3022
3058
|
if (!isFile(packageJsonPath)) continue;
|
|
3023
3059
|
const packageJson = readPackageJson(packageJsonPath);
|
|
3024
3060
|
if (!hasReactDependency(packageJson)) continue;
|
|
3025
|
-
const name = packageJson.name ?? path.basename(directory);
|
|
3061
|
+
const name = packageJson.name ?? path$1.basename(directory);
|
|
3026
3062
|
packages.push({
|
|
3027
3063
|
name,
|
|
3028
3064
|
directory
|
|
@@ -3031,7 +3067,7 @@ const toReactWorkspacePackages = (directories) => {
|
|
|
3031
3067
|
return packages;
|
|
3032
3068
|
};
|
|
3033
3069
|
const listManifestWorkspacePackages = (rootDirectory) => {
|
|
3034
|
-
if (isFile(path.join(rootDirectory, "package.json"))) return listWorkspacePackages(rootDirectory);
|
|
3070
|
+
if (isFile(path$1.join(rootDirectory, "package.json"))) return listWorkspacePackages(rootDirectory);
|
|
3035
3071
|
const patterns = parsePnpmWorkspacePatterns(rootDirectory);
|
|
3036
3072
|
const nxPatterns = patterns.length > 0 ? [] : getNxWorkspaceDirectories(rootDirectory);
|
|
3037
3073
|
return toReactWorkspacePackages((patterns.length > 0 ? patterns : nxPatterns).flatMap((pattern) => resolveWorkspaceDirectories(rootDirectory, pattern)));
|
|
@@ -3052,11 +3088,11 @@ const discoverReactSubprojectsByFilesystem = (rootDirectory) => {
|
|
|
3052
3088
|
const current = pendingDirectories.pop();
|
|
3053
3089
|
if (!current) continue;
|
|
3054
3090
|
const { directory: currentDirectory, depth } = current;
|
|
3055
|
-
const packageJsonPath = path.join(currentDirectory, "package.json");
|
|
3091
|
+
const packageJsonPath = path$1.join(currentDirectory, "package.json");
|
|
3056
3092
|
if (isFile(packageJsonPath)) {
|
|
3057
3093
|
const packageJson = readPackageJson(packageJsonPath);
|
|
3058
3094
|
if (hasReactDependency(packageJson)) {
|
|
3059
|
-
const name = packageJson.name ?? path.basename(currentDirectory);
|
|
3095
|
+
const name = packageJson.name ?? path$1.basename(currentDirectory);
|
|
3060
3096
|
packages.push({
|
|
3061
3097
|
name,
|
|
3062
3098
|
directory: currentDirectory
|
|
@@ -3068,7 +3104,7 @@ const discoverReactSubprojectsByFilesystem = (rootDirectory) => {
|
|
|
3068
3104
|
for (const entry of entries) {
|
|
3069
3105
|
if (!entry.isDirectory() || entry.name.startsWith(".") || IGNORED_DIRECTORIES.has(entry.name) || NON_PROJECT_DIRECTORIES.has(entry.name)) continue;
|
|
3070
3106
|
pendingDirectories.push({
|
|
3071
|
-
directory: path.join(currentDirectory, entry.name),
|
|
3107
|
+
directory: path$1.join(currentDirectory, entry.name),
|
|
3072
3108
|
depth: depth + 1
|
|
3073
3109
|
});
|
|
3074
3110
|
}
|
|
@@ -3088,7 +3124,7 @@ const clearProjectCache = () => {
|
|
|
3088
3124
|
const discoverProject = (directory) => {
|
|
3089
3125
|
const cached = cachedProjectInfos.get(directory);
|
|
3090
3126
|
if (cached !== void 0) return cached;
|
|
3091
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
3127
|
+
const packageJsonPath = path$1.join(directory, "package.json");
|
|
3092
3128
|
if (!isFile(packageJsonPath)) throw new PackageJsonNotFoundError(directory);
|
|
3093
3129
|
const packageJson = readPackageJson(packageJsonPath);
|
|
3094
3130
|
let { reactVersion, tailwindVersion, zodVersion, framework } = extractDependencyInfo(packageJson);
|
|
@@ -3125,7 +3161,7 @@ const discoverProject = (directory) => {
|
|
|
3125
3161
|
if (!reactVersion || !tailwindVersion || !zodVersion) {
|
|
3126
3162
|
const monorepoRoot = findMonorepoRoot(directory);
|
|
3127
3163
|
if (monorepoRoot) {
|
|
3128
|
-
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
3164
|
+
const monorepoPackageJsonPath = path$1.join(monorepoRoot, "package.json");
|
|
3129
3165
|
if (isFile(monorepoPackageJsonPath)) {
|
|
3130
3166
|
const rootPackageJson = readPackageJson(monorepoPackageJsonPath);
|
|
3131
3167
|
if (!reactVersion && reactDeclaration.hasDeclaration) reactVersion = resolveCatalogVersion(rootPackageJson, "react", monorepoRoot, reactDeclaration.catalogReference);
|
|
@@ -3151,23 +3187,22 @@ const discoverProject = (directory) => {
|
|
|
3151
3187
|
if (!reactVersion && reactDeclaration.version && !isCatalogReference(reactDeclaration.version)) reactVersion = reactDeclaration.version;
|
|
3152
3188
|
if (!tailwindVersion && tailwindDeclaration.version && !isCatalogReference(tailwindDeclaration.version)) tailwindVersion = tailwindDeclaration.version;
|
|
3153
3189
|
if (!zodVersion && zodDeclaration.version && !isCatalogReference(zodDeclaration.version)) zodVersion = zodDeclaration.version;
|
|
3154
|
-
const projectName = packageJson.name ?? path.basename(directory);
|
|
3155
|
-
const hasTypeScript = fs.existsSync(path.join(directory, "tsconfig.json"));
|
|
3190
|
+
const projectName = packageJson.name ?? path$1.basename(directory);
|
|
3191
|
+
const hasTypeScript = fs$1.existsSync(path$1.join(directory, "tsconfig.json"));
|
|
3156
3192
|
const sourceFileCount = countSourceFiles(directory);
|
|
3157
3193
|
const hasReactNativeWorkspace = framework === "expo" || framework === "react-native" || hasReactNativeWorkspaceAnywhere(directory, packageJson);
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
}
|
|
3194
|
+
const expoVersion = hasReactNativeWorkspace ? resolveCatalogBackedDependencyVersion({
|
|
3195
|
+
rootDirectory: directory,
|
|
3196
|
+
rootPackageJson: packageJson,
|
|
3197
|
+
packageName: "expo",
|
|
3198
|
+
version: findExpoVersion(directory, packageJson)
|
|
3199
|
+
}) : null;
|
|
3200
|
+
const shopifyFlashListVersion = hasReactNativeWorkspace ? resolveCatalogBackedDependencyVersion({
|
|
3201
|
+
rootDirectory: directory,
|
|
3202
|
+
rootPackageJson: packageJson,
|
|
3203
|
+
packageName: SHOPIFY_FLASH_LIST_PACKAGE_NAME,
|
|
3204
|
+
version: findShopifyFlashListVersion(directory, packageJson)
|
|
3205
|
+
}) : null;
|
|
3171
3206
|
const hasReanimated = hasReactNativeWorkspace && someWorkspacePackageJson(directory, packageJson, isPackageJsonReanimatedAware);
|
|
3172
3207
|
const preactVersion = getPreactVersion(packageJson);
|
|
3173
3208
|
const projectInfo = {
|
|
@@ -3186,6 +3221,8 @@ const discoverProject = (directory) => {
|
|
|
3186
3221
|
preactMajorVersion: parseReactMajor(preactVersion),
|
|
3187
3222
|
hasReactNativeWorkspace,
|
|
3188
3223
|
expoVersion,
|
|
3224
|
+
shopifyFlashListVersion,
|
|
3225
|
+
shopifyFlashListMajorVersion: shopifyFlashListVersion === null ? null : getLowestDependencyMajor(shopifyFlashListVersion),
|
|
3189
3226
|
hasReanimated,
|
|
3190
3227
|
sourceFileCount
|
|
3191
3228
|
};
|
|
@@ -3793,12 +3830,12 @@ const findNearestPackageDirectory = (filename) => {
|
|
|
3793
3830
|
if (!filename) return null;
|
|
3794
3831
|
const fromCache = cachedPackageDirectoryByFilename.get(filename);
|
|
3795
3832
|
if (fromCache !== void 0) return fromCache;
|
|
3796
|
-
let currentDirectory = path.dirname(filename);
|
|
3833
|
+
let currentDirectory = path$1.dirname(filename);
|
|
3797
3834
|
while (true) {
|
|
3798
|
-
const candidatePackageJsonPath = path.join(currentDirectory, "package.json");
|
|
3835
|
+
const candidatePackageJsonPath = path$1.join(currentDirectory, "package.json");
|
|
3799
3836
|
let hasPackageJson = false;
|
|
3800
3837
|
try {
|
|
3801
|
-
hasPackageJson = fs.statSync(candidatePackageJsonPath).isFile();
|
|
3838
|
+
hasPackageJson = fs$1.statSync(candidatePackageJsonPath).isFile();
|
|
3802
3839
|
} catch {
|
|
3803
3840
|
hasPackageJson = false;
|
|
3804
3841
|
}
|
|
@@ -3806,7 +3843,7 @@ const findNearestPackageDirectory = (filename) => {
|
|
|
3806
3843
|
cachedPackageDirectoryByFilename.set(filename, currentDirectory);
|
|
3807
3844
|
return currentDirectory;
|
|
3808
3845
|
}
|
|
3809
|
-
const parentDirectory = path.dirname(currentDirectory);
|
|
3846
|
+
const parentDirectory = path$1.dirname(currentDirectory);
|
|
3810
3847
|
if (parentDirectory === currentDirectory) {
|
|
3811
3848
|
cachedPackageDirectoryByFilename.set(filename, null);
|
|
3812
3849
|
return null;
|
|
@@ -3816,7 +3853,7 @@ const findNearestPackageDirectory = (filename) => {
|
|
|
3816
3853
|
};
|
|
3817
3854
|
const readManifest = (packageJsonPath) => {
|
|
3818
3855
|
try {
|
|
3819
|
-
const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
3856
|
+
const parsed = JSON.parse(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
3820
3857
|
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
3821
3858
|
return null;
|
|
3822
3859
|
} catch {
|
|
@@ -3827,8 +3864,8 @@ const hasPublishContract = (manifest) => typeof manifest.name === "string" && ma
|
|
|
3827
3864
|
const classifyByDirectoryCohort = (packageDirectory) => {
|
|
3828
3865
|
let current = packageDirectory;
|
|
3829
3866
|
while (true) {
|
|
3830
|
-
if (path.basename(current) === "apps") return "app";
|
|
3831
|
-
const parent = path.dirname(current);
|
|
3867
|
+
if (path$1.basename(current) === "apps") return "app";
|
|
3868
|
+
const parent = path$1.dirname(current);
|
|
3832
3869
|
if (parent === current) return null;
|
|
3833
3870
|
current = parent;
|
|
3834
3871
|
}
|
|
@@ -3843,10 +3880,10 @@ const classifyPackageRole = (filename) => {
|
|
|
3843
3880
|
if (!packageDirectory) return "unknown";
|
|
3844
3881
|
const cached = cachedRoleByPackageDirectory.get(packageDirectory);
|
|
3845
3882
|
if (cached !== void 0) return cached;
|
|
3846
|
-
const manifest = readManifest(path.join(packageDirectory, "package.json"));
|
|
3883
|
+
const manifest = readManifest(path$1.join(packageDirectory, "package.json"));
|
|
3847
3884
|
let result;
|
|
3848
3885
|
if (manifest && hasPublishContract(manifest)) result = "library";
|
|
3849
|
-
else result = classifyByDirectoryCohort(path.dirname(packageDirectory)) ?? "unknown";
|
|
3886
|
+
else result = classifyByDirectoryCohort(path$1.dirname(packageDirectory)) ?? "unknown";
|
|
3850
3887
|
cachedRoleByPackageDirectory.set(packageDirectory, result);
|
|
3851
3888
|
return result;
|
|
3852
3889
|
};
|
|
@@ -4498,12 +4535,12 @@ const loadModuleConfig = async (filePath) => {
|
|
|
4498
4535
|
const imported = await jiti.import(filePath);
|
|
4499
4536
|
return imported?.default ?? imported;
|
|
4500
4537
|
};
|
|
4501
|
-
const readDataConfig = (filePath) => parseJSON5(fs.readFileSync(filePath, "utf-8"));
|
|
4538
|
+
const readDataConfig = (filePath) => parseJSON5(fs$1.readFileSync(filePath, "utf-8"));
|
|
4502
4539
|
const readEmbeddedPackageJsonConfig = (directory) => {
|
|
4503
|
-
const packageJsonPath = path.join(directory, PACKAGE_JSON_FILENAME);
|
|
4540
|
+
const packageJsonPath = path$1.join(directory, PACKAGE_JSON_FILENAME);
|
|
4504
4541
|
if (!isFile(packageJsonPath)) return null;
|
|
4505
4542
|
try {
|
|
4506
|
-
const packageJson = parseJSON5(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
4543
|
+
const packageJson = parseJSON5(fs$1.readFileSync(packageJsonPath, "utf-8"));
|
|
4507
4544
|
if (isPlainObject(packageJson)) {
|
|
4508
4545
|
const embeddedConfig = packageJson[PACKAGE_JSON_CONFIG_KEY];
|
|
4509
4546
|
if (isPlainObject(embeddedConfig)) return embeddedConfig;
|
|
@@ -4517,14 +4554,14 @@ const loadPackageJsonConfig = (directory) => {
|
|
|
4517
4554
|
return {
|
|
4518
4555
|
config: validateConfigTypes(embeddedConfig),
|
|
4519
4556
|
sourceDirectory: directory,
|
|
4520
|
-
configFilePath: path.join(directory, PACKAGE_JSON_FILENAME),
|
|
4557
|
+
configFilePath: path$1.join(directory, PACKAGE_JSON_FILENAME),
|
|
4521
4558
|
format: "package-json"
|
|
4522
4559
|
};
|
|
4523
4560
|
};
|
|
4524
4561
|
const loadConfigFromDirectory = async (directory) => {
|
|
4525
4562
|
let sawBrokenConfigFile = false;
|
|
4526
4563
|
for (const extension of CONFIG_EXTENSIONS) {
|
|
4527
|
-
const filePath = path.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
4564
|
+
const filePath = path$1.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
4528
4565
|
if (!isFile(filePath)) continue;
|
|
4529
4566
|
const isDataFile = DATA_CONFIG_EXTENSIONS.has(extension);
|
|
4530
4567
|
try {
|
|
@@ -4550,7 +4587,7 @@ const loadConfigFromDirectory = async (directory) => {
|
|
|
4550
4587
|
status: "found",
|
|
4551
4588
|
loaded: packageJsonConfig
|
|
4552
4589
|
};
|
|
4553
|
-
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).`);
|
|
4590
|
+
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).`);
|
|
4554
4591
|
return {
|
|
4555
4592
|
status: sawBrokenConfigFile ? "invalid" : "absent",
|
|
4556
4593
|
loaded: null
|
|
@@ -4564,12 +4601,12 @@ const loadConfigWalkingUp = async (rootDirectory) => {
|
|
|
4564
4601
|
const localResult = await loadConfigFromDirectory(rootDirectory);
|
|
4565
4602
|
if (localResult.status === "found") return localResult.loaded;
|
|
4566
4603
|
if (localResult.status === "invalid" || isProjectBoundary(rootDirectory)) return null;
|
|
4567
|
-
let ancestorDirectory = path.dirname(rootDirectory);
|
|
4568
|
-
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
4604
|
+
let ancestorDirectory = path$1.dirname(rootDirectory);
|
|
4605
|
+
while (ancestorDirectory !== path$1.dirname(ancestorDirectory)) {
|
|
4569
4606
|
const ancestorResult = await loadConfigFromDirectory(ancestorDirectory);
|
|
4570
4607
|
if (ancestorResult.status === "found") return ancestorResult.loaded;
|
|
4571
4608
|
if (isProjectBoundary(ancestorDirectory)) return null;
|
|
4572
|
-
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
4609
|
+
ancestorDirectory = path$1.dirname(ancestorDirectory);
|
|
4573
4610
|
}
|
|
4574
4611
|
return null;
|
|
4575
4612
|
};
|
|
@@ -4586,7 +4623,7 @@ const resolveConfigRootDir = (config, configSourceDirectory) => {
|
|
|
4586
4623
|
if (typeof rawRootDir !== "string") return null;
|
|
4587
4624
|
const trimmedRootDir = rawRootDir.trim();
|
|
4588
4625
|
if (trimmedRootDir.length === 0) return null;
|
|
4589
|
-
const resolvedRootDir = path.isAbsolute(trimmedRootDir) ? trimmedRootDir : path.resolve(configSourceDirectory, trimmedRootDir);
|
|
4626
|
+
const resolvedRootDir = path$1.isAbsolute(trimmedRootDir) ? trimmedRootDir : path$1.resolve(configSourceDirectory, trimmedRootDir);
|
|
4590
4627
|
if (resolvedRootDir === configSourceDirectory) return null;
|
|
4591
4628
|
if (!isDirectory(resolvedRootDir)) {
|
|
4592
4629
|
Effect.runSync(Console.warn(`react-doctor config "rootDir" points to "${rawRootDir}" (resolved to ${resolvedRootDir}), which is not a directory. Ignoring.`));
|
|
@@ -4595,12 +4632,12 @@ const resolveConfigRootDir = (config, configSourceDirectory) => {
|
|
|
4595
4632
|
return resolvedRootDir;
|
|
4596
4633
|
};
|
|
4597
4634
|
const resolveDiagnoseTarget = (directory, options = {}) => {
|
|
4598
|
-
if (isFile(path.join(directory, "package.json"))) return directory;
|
|
4635
|
+
if (isFile(path$1.join(directory, "package.json"))) return directory;
|
|
4599
4636
|
const reactSubprojects = discoverReactSubprojects(directory);
|
|
4600
4637
|
if (reactSubprojects.length === 0) return null;
|
|
4601
4638
|
if (reactSubprojects.length === 1) return reactSubprojects[0].directory;
|
|
4602
4639
|
if (options.allowAmbiguous === true) return null;
|
|
4603
|
-
throw new AmbiguousProjectError(directory, reactSubprojects.map((subproject) => path.relative(directory, subproject.directory)).toSorted());
|
|
4640
|
+
throw new AmbiguousProjectError(directory, reactSubprojects.map((subproject) => path$1.relative(directory, subproject.directory)).toSorted());
|
|
4604
4641
|
};
|
|
4605
4642
|
/**
|
|
4606
4643
|
* The canonical entry-point translation shared by every public shell
|
|
@@ -4626,14 +4663,14 @@ const resolveDiagnoseTarget = (directory, options = {}) => {
|
|
|
4626
4663
|
* shell in agreement on what "the scan directory" means.
|
|
4627
4664
|
*/
|
|
4628
4665
|
const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
4629
|
-
const absoluteRequested = path.resolve(requestedDirectory);
|
|
4666
|
+
const absoluteRequested = path$1.resolve(requestedDirectory);
|
|
4630
4667
|
const loadedConfig = await loadConfigWithSource(absoluteRequested);
|
|
4631
4668
|
const userConfig = loadedConfig?.config ?? null;
|
|
4632
4669
|
const configSourceDirectory = loadedConfig?.sourceDirectory ?? null;
|
|
4633
4670
|
const redirectedDirectory = resolveConfigRootDir(userConfig, configSourceDirectory);
|
|
4634
4671
|
const directoryAfterRedirect = redirectedDirectory ?? absoluteRequested;
|
|
4635
4672
|
const resolvedDirectory = resolveDiagnoseTarget(directoryAfterRedirect, options) ?? directoryAfterRedirect;
|
|
4636
|
-
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory, { kind: "missing-path" });
|
|
4673
|
+
if (!isDirectory(resolvedDirectory)) throw fs$1.existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory, { kind: "missing-path" });
|
|
4637
4674
|
return {
|
|
4638
4675
|
resolvedDirectory,
|
|
4639
4676
|
requestedDirectory: absoluteRequested,
|
|
@@ -4644,7 +4681,7 @@ const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
|
4644
4681
|
};
|
|
4645
4682
|
const getDirectDependencyNames = (packageJson) => new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.devDependencies ?? {})]);
|
|
4646
4683
|
const buildExpoCheckContext = (rootDirectory, expoVersion) => {
|
|
4647
|
-
const packageJson = readPackageJson(path.join(rootDirectory, "package.json"));
|
|
4684
|
+
const packageJson = readPackageJson(path$1.join(rootDirectory, "package.json"));
|
|
4648
4685
|
return {
|
|
4649
4686
|
rootDirectory,
|
|
4650
4687
|
packageJson,
|
|
@@ -4714,7 +4751,7 @@ const LOCAL_ENV_FILE_NAMES = [
|
|
|
4714
4751
|
const checkExpoEnvLocalFiles = (context) => {
|
|
4715
4752
|
const { rootDirectory } = context;
|
|
4716
4753
|
const committedEnvFiles = LOCAL_ENV_FILE_NAMES.filter((fileName) => {
|
|
4717
|
-
const filePath = path.join(rootDirectory, fileName);
|
|
4754
|
+
const filePath = path$1.join(rootDirectory, fileName);
|
|
4718
4755
|
if (!isFile(filePath)) return false;
|
|
4719
4756
|
return isPathGitIgnored(rootDirectory, filePath) === false;
|
|
4720
4757
|
});
|
|
@@ -4848,17 +4885,17 @@ const checkExpoFlaggedDependencies = (context) => FLAGGED_DEPENDENCIES.filter((f
|
|
|
4848
4885
|
help: flaggedDependency.help
|
|
4849
4886
|
}));
|
|
4850
4887
|
const findLocalModuleNativeFiles = (rootDirectory) => {
|
|
4851
|
-
const modulesDirectory = path.join(rootDirectory, "modules");
|
|
4888
|
+
const modulesDirectory = path$1.join(rootDirectory, "modules");
|
|
4852
4889
|
if (!isDirectory(modulesDirectory)) return [];
|
|
4853
4890
|
const nativeFilePaths = [];
|
|
4854
4891
|
for (const moduleEntry of readDirectoryEntries(modulesDirectory)) {
|
|
4855
4892
|
if (!moduleEntry.isDirectory()) continue;
|
|
4856
|
-
const moduleDirectory = path.join(modulesDirectory, moduleEntry.name);
|
|
4857
|
-
const gradlePath = path.join(moduleDirectory, "android", "build.gradle");
|
|
4893
|
+
const moduleDirectory = path$1.join(modulesDirectory, moduleEntry.name);
|
|
4894
|
+
const gradlePath = path$1.join(moduleDirectory, "android", "build.gradle");
|
|
4858
4895
|
if (isFile(gradlePath)) nativeFilePaths.push(gradlePath);
|
|
4859
|
-
const iosDirectory = path.join(moduleDirectory, "ios");
|
|
4896
|
+
const iosDirectory = path$1.join(moduleDirectory, "ios");
|
|
4860
4897
|
if (isDirectory(iosDirectory)) {
|
|
4861
|
-
for (const iosEntry of readDirectoryEntries(iosDirectory)) if (iosEntry.isFile() && iosEntry.name.endsWith(".podspec")) nativeFilePaths.push(path.join(iosDirectory, iosEntry.name));
|
|
4898
|
+
for (const iosEntry of readDirectoryEntries(iosDirectory)) if (iosEntry.isFile() && iosEntry.name.endsWith(".podspec")) nativeFilePaths.push(path$1.join(iosDirectory, iosEntry.name));
|
|
4862
4899
|
}
|
|
4863
4900
|
}
|
|
4864
4901
|
return nativeFilePaths;
|
|
@@ -4866,7 +4903,7 @@ const findLocalModuleNativeFiles = (rootDirectory) => {
|
|
|
4866
4903
|
const checkExpoGitignore = (context) => {
|
|
4867
4904
|
const { rootDirectory } = context;
|
|
4868
4905
|
const diagnostics = [];
|
|
4869
|
-
const expoStateDirectory = path.join(rootDirectory, ".expo");
|
|
4906
|
+
const expoStateDirectory = path$1.join(rootDirectory, ".expo");
|
|
4870
4907
|
if (isDirectory(expoStateDirectory) && isPathGitIgnored(rootDirectory, expoStateDirectory) === false) diagnostics.push(buildExpoDiagnostic({
|
|
4871
4908
|
rule: "expo-gitignore",
|
|
4872
4909
|
message: "The `.expo` directory is not ignored by Git — it holds machine-specific device history and dev-server settings that should not be committed",
|
|
@@ -4888,7 +4925,7 @@ const LOCKFILE_NAMES = [
|
|
|
4888
4925
|
];
|
|
4889
4926
|
const checkExpoLockfile = (context) => {
|
|
4890
4927
|
const workspaceRoot = isMonorepoRoot(context.rootDirectory) ? context.rootDirectory : findMonorepoRoot(context.rootDirectory) ?? context.rootDirectory;
|
|
4891
|
-
const presentLockfiles = LOCKFILE_NAMES.filter((lockfileName) => isFile(path.join(workspaceRoot, lockfileName)));
|
|
4928
|
+
const presentLockfiles = LOCKFILE_NAMES.filter((lockfileName) => isFile(path$1.join(workspaceRoot, lockfileName)));
|
|
4892
4929
|
if (presentLockfiles.length === 0) return [buildExpoDiagnostic({
|
|
4893
4930
|
rule: "expo-lockfile",
|
|
4894
4931
|
message: "No lock file detected at the project root — installs are not reproducible, and EAS Build cannot infer your package manager",
|
|
@@ -4913,18 +4950,18 @@ const EXPO_METRO_CONFIG_EXTEND_SIGNALS = [
|
|
|
4913
4950
|
"getSentryExpoConfig"
|
|
4914
4951
|
];
|
|
4915
4952
|
const checkExpoMetroConfig = (context) => {
|
|
4916
|
-
const metroConfigPath = METRO_CONFIG_FILE_NAMES.map((fileName) => path.join(context.rootDirectory, fileName)).find((candidatePath) => isFile(candidatePath));
|
|
4953
|
+
const metroConfigPath = METRO_CONFIG_FILE_NAMES.map((fileName) => path$1.join(context.rootDirectory, fileName)).find((candidatePath) => isFile(candidatePath));
|
|
4917
4954
|
if (metroConfigPath === void 0) return [];
|
|
4918
4955
|
let contents;
|
|
4919
4956
|
try {
|
|
4920
|
-
contents = fs.readFileSync(metroConfigPath, "utf-8");
|
|
4957
|
+
contents = fs$1.readFileSync(metroConfigPath, "utf-8");
|
|
4921
4958
|
} catch {
|
|
4922
4959
|
return [];
|
|
4923
4960
|
}
|
|
4924
4961
|
if (EXPO_METRO_CONFIG_EXTEND_SIGNALS.some((signal) => contents.includes(signal))) return [];
|
|
4925
4962
|
return [buildExpoDiagnostic({
|
|
4926
4963
|
rule: "expo-metro-config",
|
|
4927
|
-
filePath: path.basename(metroConfigPath),
|
|
4964
|
+
filePath: path$1.basename(metroConfigPath),
|
|
4928
4965
|
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",
|
|
4929
4966
|
help: "Update your metro config to extend `expo/metro-config`. See https://docs.expo.dev/guides/customizing-metro/"
|
|
4930
4967
|
})];
|
|
@@ -4970,16 +5007,16 @@ const NO_CONFIG = {
|
|
|
4970
5007
|
const decodeExpoConfig = (filePath) => {
|
|
4971
5008
|
let raw;
|
|
4972
5009
|
try {
|
|
4973
|
-
raw = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
5010
|
+
raw = JSON.parse(fs$1.readFileSync(filePath, "utf-8"));
|
|
4974
5011
|
} catch {
|
|
4975
5012
|
return null;
|
|
4976
5013
|
}
|
|
4977
5014
|
return Option.getOrNull(Schema.decodeUnknownOption(AppManifestSchema)(raw))?.expo ?? null;
|
|
4978
5015
|
};
|
|
4979
5016
|
const readExpoAppConfig = (rootDirectory) => {
|
|
4980
|
-
if (APP_CONFIG_DYNAMIC_FILES.some((fileName) => isFile(path.join(rootDirectory, fileName)))) return NO_CONFIG;
|
|
5017
|
+
if (APP_CONFIG_DYNAMIC_FILES.some((fileName) => isFile(path$1.join(rootDirectory, fileName)))) return NO_CONFIG;
|
|
4981
5018
|
for (const fileName of APP_CONFIG_JSON_FILES) {
|
|
4982
|
-
const filePath = path.join(rootDirectory, fileName);
|
|
5019
|
+
const filePath = path$1.join(rootDirectory, fileName);
|
|
4983
5020
|
if (!isFile(filePath)) continue;
|
|
4984
5021
|
const config = decodeExpoConfig(filePath);
|
|
4985
5022
|
if (config) return {
|
|
@@ -5126,12 +5163,12 @@ const parseHardeningSettings = (content) => {
|
|
|
5126
5163
|
};
|
|
5127
5164
|
};
|
|
5128
5165
|
const isPnpmManagedProject = (rootDirectory) => {
|
|
5129
|
-
if (isFile(path.join(rootDirectory, PNPM_LOCKFILE))) return true;
|
|
5130
|
-
if (isFile(path.join(rootDirectory, PNPM_WORKSPACE_FILE))) return true;
|
|
5131
|
-
const packageJsonPath = path.join(rootDirectory, PACKAGE_JSON_FILE);
|
|
5166
|
+
if (isFile(path$1.join(rootDirectory, PNPM_LOCKFILE))) return true;
|
|
5167
|
+
if (isFile(path$1.join(rootDirectory, PNPM_WORKSPACE_FILE))) return true;
|
|
5168
|
+
const packageJsonPath = path$1.join(rootDirectory, PACKAGE_JSON_FILE);
|
|
5132
5169
|
if (!isFile(packageJsonPath)) return false;
|
|
5133
5170
|
try {
|
|
5134
|
-
const packageJsonRaw = fs.readFileSync(packageJsonPath, "utf-8");
|
|
5171
|
+
const packageJsonRaw = fs$1.readFileSync(packageJsonPath, "utf-8");
|
|
5135
5172
|
const packageJson = JSON.parse(packageJsonRaw);
|
|
5136
5173
|
if (packageJson !== null && typeof packageJson === "object" && "packageManager" in packageJson && typeof packageJson.packageManager === "string" && packageJson.packageManager.startsWith("pnpm@")) return true;
|
|
5137
5174
|
} catch {
|
|
@@ -5152,8 +5189,8 @@ const buildHardeningDiagnostic = (input) => ({
|
|
|
5152
5189
|
});
|
|
5153
5190
|
const checkPnpmHardening = (rootDirectory) => {
|
|
5154
5191
|
if (!isPnpmManagedProject(rootDirectory)) return [];
|
|
5155
|
-
const workspacePath = path.join(rootDirectory, PNPM_WORKSPACE_FILE);
|
|
5156
|
-
const settings = parseHardeningSettings(isFile(workspacePath) ? fs.readFileSync(workspacePath, "utf-8") : "");
|
|
5192
|
+
const workspacePath = path$1.join(rootDirectory, PNPM_WORKSPACE_FILE);
|
|
5193
|
+
const settings = parseHardeningSettings(isFile(workspacePath) ? fs$1.readFileSync(workspacePath, "utf-8") : "");
|
|
5157
5194
|
const diagnostics = [];
|
|
5158
5195
|
if (settings.minimumReleaseAge === null) diagnostics.push(buildHardeningDiagnostic({
|
|
5159
5196
|
message: "pnpm-workspace.yaml is missing `minimumReleaseAge` — newly published versions can ship malware that gets caught and unpublished within hours",
|
|
@@ -5183,7 +5220,7 @@ const isBuilderBobLibrary = (packageJson) => {
|
|
|
5183
5220
|
return typeof bobConfig === "object" && bobConfig !== null;
|
|
5184
5221
|
};
|
|
5185
5222
|
const checkReactNativeLibraryDependencies = (rootDirectory) => {
|
|
5186
|
-
const packageJson = readPackageJson(path.join(rootDirectory, "package.json"));
|
|
5223
|
+
const packageJson = readPackageJson(path$1.join(rootDirectory, "package.json"));
|
|
5187
5224
|
if (!isBuilderBobLibrary(packageJson)) return [];
|
|
5188
5225
|
const misplaced = ["react", "react-native"].filter((name) => packageJson.dependencies?.[name] !== void 0);
|
|
5189
5226
|
if (misplaced.length === 0) return [];
|
|
@@ -5212,11 +5249,11 @@ const BABEL_CONFIG_FILE_NAMES = [
|
|
|
5212
5249
|
const LEGACY_PRESET_SPEC = "module:metro-react-native-babel-preset";
|
|
5213
5250
|
const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
5214
5251
|
for (const fileName of BABEL_CONFIG_FILE_NAMES) {
|
|
5215
|
-
const filePath = path.join(rootDirectory, fileName);
|
|
5252
|
+
const filePath = path$1.join(rootDirectory, fileName);
|
|
5216
5253
|
if (!isFile(filePath)) continue;
|
|
5217
5254
|
let contents;
|
|
5218
5255
|
try {
|
|
5219
|
-
contents = fs.readFileSync(filePath, "utf-8");
|
|
5256
|
+
contents = fs$1.readFileSync(filePath, "utf-8");
|
|
5220
5257
|
} catch {
|
|
5221
5258
|
continue;
|
|
5222
5259
|
}
|
|
@@ -5261,7 +5298,7 @@ const MISSING_REDUCED_MOTION_DIAGNOSTIC = {
|
|
|
5261
5298
|
category: "Accessibility"
|
|
5262
5299
|
};
|
|
5263
5300
|
const checkReducedMotion = (rootDirectory) => {
|
|
5264
|
-
const packageJsonPath = path.join(rootDirectory, "package.json");
|
|
5301
|
+
const packageJsonPath = path$1.join(rootDirectory, "package.json");
|
|
5265
5302
|
if (!isFile(packageJsonPath)) return [];
|
|
5266
5303
|
let hasMotionLibrary = false;
|
|
5267
5304
|
try {
|
|
@@ -5386,7 +5423,7 @@ const isTruthyLinguistAttribute = (token) => {
|
|
|
5386
5423
|
const parseGitattributesLinguistPaths = (filePath) => {
|
|
5387
5424
|
let content;
|
|
5388
5425
|
try {
|
|
5389
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
5426
|
+
content = fs$1.readFileSync(filePath, "utf-8");
|
|
5390
5427
|
} catch {
|
|
5391
5428
|
return [];
|
|
5392
5429
|
}
|
|
@@ -5408,7 +5445,7 @@ const stripGitignoreEscape = (pattern) => {
|
|
|
5408
5445
|
const readIgnoreFile = (filePath) => {
|
|
5409
5446
|
let content;
|
|
5410
5447
|
try {
|
|
5411
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
5448
|
+
content = fs$1.readFileSync(filePath, "utf-8");
|
|
5412
5449
|
} catch (error) {
|
|
5413
5450
|
const errnoCode = error?.code;
|
|
5414
5451
|
if (errnoCode && errnoCode !== "ENOENT") Effect.runSync(Console.warn(`Could not read ignore file ${filePath}: ${errnoCode}`));
|
|
@@ -5440,8 +5477,8 @@ const computeIgnorePatterns = (rootDirectory) => {
|
|
|
5440
5477
|
seen.add(pattern);
|
|
5441
5478
|
patterns.push(pattern);
|
|
5442
5479
|
};
|
|
5443
|
-
for (const filename of IGNORE_FILENAMES) for (const pattern of readIgnoreFile(path.join(rootDirectory, filename))) addPattern(pattern);
|
|
5444
|
-
for (const linguistPath of parseGitattributesLinguistPaths(path.join(rootDirectory, ".gitattributes"))) addPattern(linguistPath);
|
|
5480
|
+
for (const filename of IGNORE_FILENAMES) for (const pattern of readIgnoreFile(path$1.join(rootDirectory, filename))) addPattern(pattern);
|
|
5481
|
+
for (const linguistPath of parseGitattributesLinguistPaths(path$1.join(rootDirectory, ".gitattributes"))) addPattern(linguistPath);
|
|
5445
5482
|
return patterns;
|
|
5446
5483
|
};
|
|
5447
5484
|
const collectIgnorePatterns = (rootDirectory) => {
|
|
@@ -5451,6 +5488,63 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
5451
5488
|
cachedPatternsByRoot.set(rootDirectory, patterns);
|
|
5452
5489
|
return patterns;
|
|
5453
5490
|
};
|
|
5491
|
+
const KNIP_JSON_FILENAME = "knip.json";
|
|
5492
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5493
|
+
const readJsonFileSafe = (filePath) => {
|
|
5494
|
+
let rawContents;
|
|
5495
|
+
try {
|
|
5496
|
+
rawContents = fs.readFileSync(filePath, "utf-8");
|
|
5497
|
+
} catch {
|
|
5498
|
+
return null;
|
|
5499
|
+
}
|
|
5500
|
+
try {
|
|
5501
|
+
return JSON.parse(rawContents);
|
|
5502
|
+
} catch {
|
|
5503
|
+
return null;
|
|
5504
|
+
}
|
|
5505
|
+
};
|
|
5506
|
+
const readKnipConfig = (rootDirectory) => {
|
|
5507
|
+
const knipJson = readJsonFileSafe(path.join(rootDirectory, KNIP_JSON_FILENAME));
|
|
5508
|
+
if (isRecord$1(knipJson)) return knipJson;
|
|
5509
|
+
const packageJson = readJsonFileSafe(path.join(rootDirectory, "package.json"));
|
|
5510
|
+
const packageKnipConfig = isRecord$1(packageJson) ? packageJson.knip : null;
|
|
5511
|
+
return isRecord$1(packageKnipConfig) ? packageKnipConfig : null;
|
|
5512
|
+
};
|
|
5513
|
+
const normalizePatternList = (value) => {
|
|
5514
|
+
if (typeof value === "string" && value.length > 0) return [value];
|
|
5515
|
+
if (!Array.isArray(value)) return [];
|
|
5516
|
+
return value.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
5517
|
+
};
|
|
5518
|
+
const prefixWorkspacePatterns = (workspacePattern, patterns) => {
|
|
5519
|
+
const normalizedWorkspacePattern = workspacePattern.replace(/\/+$/, "");
|
|
5520
|
+
return patterns.map((pattern) => pattern.startsWith("!") ? `!${normalizedWorkspacePattern}/${pattern.slice(1)}` : `${normalizedWorkspacePattern}/${pattern}`);
|
|
5521
|
+
};
|
|
5522
|
+
const collectKnipWorkspacePatterns = (workspaces, settingName) => {
|
|
5523
|
+
if (!isRecord$1(workspaces)) return [];
|
|
5524
|
+
const patterns = [];
|
|
5525
|
+
for (const [workspacePattern, workspaceConfig] of Object.entries(workspaces)) {
|
|
5526
|
+
if (!isRecord$1(workspaceConfig)) continue;
|
|
5527
|
+
patterns.push(...prefixWorkspacePatterns(workspacePattern, normalizePatternList(workspaceConfig[settingName])));
|
|
5528
|
+
}
|
|
5529
|
+
return patterns;
|
|
5530
|
+
};
|
|
5531
|
+
const collectKnipPatterns = (rootDirectory, settingName) => {
|
|
5532
|
+
const config = readKnipConfig(rootDirectory);
|
|
5533
|
+
if (!config) return [];
|
|
5534
|
+
return [...normalizePatternList(config[settingName]), ...collectKnipWorkspacePatterns(config.workspaces, settingName)];
|
|
5535
|
+
};
|
|
5536
|
+
const collectDeadCodeIgnorePatterns = (rootDirectory, userConfig) => {
|
|
5537
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5538
|
+
const sources = [
|
|
5539
|
+
readIgnoreFile(path.join(rootDirectory, ".gitignore")),
|
|
5540
|
+
collectIgnorePatterns(rootDirectory),
|
|
5541
|
+
userConfig?.ignore?.files ?? [],
|
|
5542
|
+
collectKnipPatterns(rootDirectory, "ignore")
|
|
5543
|
+
];
|
|
5544
|
+
for (const source of sources) for (const pattern of source) seen.add(pattern);
|
|
5545
|
+
return [...seen].filter((pattern) => pattern.length > 0);
|
|
5546
|
+
};
|
|
5547
|
+
const collectDeadCodeEntryPatterns = (rootDirectory) => [...new Set(collectKnipPatterns(rootDirectory, "entry"))].filter((pattern) => pattern.length > 0);
|
|
5454
5548
|
/**
|
|
5455
5549
|
* Resolves a path to its canonical, symlink-free form, falling back to
|
|
5456
5550
|
* the input when it cannot be realpath'd (broken symlink, permission
|
|
@@ -5468,7 +5562,7 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
5468
5562
|
*/
|
|
5469
5563
|
const toCanonicalPath = (filePath) => {
|
|
5470
5564
|
try {
|
|
5471
|
-
return fs.realpathSync(filePath);
|
|
5565
|
+
return fs$1.realpathSync(filePath);
|
|
5472
5566
|
} catch {
|
|
5473
5567
|
return filePath;
|
|
5474
5568
|
}
|
|
@@ -5476,6 +5570,7 @@ const toCanonicalPath = (filePath) => {
|
|
|
5476
5570
|
const DEAD_CODE_PLUGIN = "deslop";
|
|
5477
5571
|
const DEAD_CODE_CATEGORY = "Maintainability";
|
|
5478
5572
|
const TSCONFIG_FILENAMES$1 = ["tsconfig.json", "tsconfig.base.json"];
|
|
5573
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5479
5574
|
const DEAD_CODE_WORKER_SCRIPT = `
|
|
5480
5575
|
const inputChunks = [];
|
|
5481
5576
|
process.stdin.on("data", (chunk) => inputChunks.push(chunk));
|
|
@@ -5516,6 +5611,9 @@ process.stdin.on("end", () => {
|
|
|
5516
5611
|
const { analyze, defineConfig } = await import(workerInput.deslopJsModuleSpecifier);
|
|
5517
5612
|
const config = {
|
|
5518
5613
|
rootDir: workerInput.rootDirectory,
|
|
5614
|
+
...(workerInput.entryPatterns.length > 0
|
|
5615
|
+
? { entryPatterns: workerInput.entryPatterns }
|
|
5616
|
+
: {}),
|
|
5519
5617
|
...(workerInput.tsConfigPath ? { tsConfigPath: workerInput.tsConfigPath } : {}),
|
|
5520
5618
|
...(workerInput.ignorePatterns.length > 0
|
|
5521
5619
|
? { ignorePatterns: workerInput.ignorePatterns }
|
|
@@ -5531,25 +5629,14 @@ process.stdin.on("end", () => {
|
|
|
5531
5629
|
`;
|
|
5532
5630
|
const resolveTsConfigPath = (rootDirectory) => {
|
|
5533
5631
|
for (const filename of TSCONFIG_FILENAMES$1) {
|
|
5534
|
-
const candidate = path.join(rootDirectory, filename);
|
|
5535
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
5632
|
+
const candidate = path$1.join(rootDirectory, filename);
|
|
5633
|
+
if (fs$1.existsSync(candidate)) return candidate;
|
|
5536
5634
|
}
|
|
5537
5635
|
};
|
|
5538
|
-
const collectDeadCodeIgnorePatterns = (rootDirectory, userConfig) => {
|
|
5539
|
-
const seen = /* @__PURE__ */ new Set();
|
|
5540
|
-
const sources = [
|
|
5541
|
-
readIgnoreFile(path.join(rootDirectory, ".gitignore")),
|
|
5542
|
-
collectIgnorePatterns(rootDirectory),
|
|
5543
|
-
userConfig?.ignore?.files ?? []
|
|
5544
|
-
];
|
|
5545
|
-
for (const source of sources) for (const pattern of source) seen.add(pattern);
|
|
5546
|
-
return [...seen].filter((pattern) => pattern.length > 0);
|
|
5547
|
-
};
|
|
5548
5636
|
const toRelativeFilePath = (rootDirectory, filePath) => {
|
|
5549
5637
|
const relative = toRelativePath(filePath, rootDirectory);
|
|
5550
5638
|
return relative.length > 0 ? relative : filePath.replace(/\\/g, "/");
|
|
5551
5639
|
};
|
|
5552
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5553
5640
|
const parseArray = (value, label) => {
|
|
5554
5641
|
if (!Array.isArray(value)) throw new Error(`Dead-code worker returned invalid ${label}.`);
|
|
5555
5642
|
return value;
|
|
@@ -5731,10 +5818,12 @@ const runDeadCodeWorkerWithTimeout = (handle, timeoutMs) => new Promise((resolve
|
|
|
5731
5818
|
const checkDeadCode = async (options) => {
|
|
5732
5819
|
const { userConfig } = options;
|
|
5733
5820
|
const rootDirectory = toCanonicalPath(options.rootDirectory);
|
|
5734
|
-
if (!fs.existsSync(path.join(rootDirectory, "package.json"))) return [];
|
|
5821
|
+
if (!fs$1.existsSync(path$1.join(rootDirectory, "package.json"))) return [];
|
|
5822
|
+
const entryPatterns = collectDeadCodeEntryPatterns(rootDirectory);
|
|
5735
5823
|
const ignorePatterns = collectDeadCodeIgnorePatterns(rootDirectory, userConfig);
|
|
5736
5824
|
const result = parseDeadCodeWorkerResult(await runDeadCodeWorkerWithTimeout((options.createWorker ?? createDeadCodeWorker)({
|
|
5737
5825
|
rootDirectory,
|
|
5826
|
+
entryPatterns,
|
|
5738
5827
|
tsConfigPath: resolveTsConfigPath(rootDirectory),
|
|
5739
5828
|
ignorePatterns,
|
|
5740
5829
|
deslopJsModuleSpecifier: options.deslopJsModuleSpecifier ?? import.meta.resolve("deslop-js")
|
|
@@ -5836,7 +5925,7 @@ const isDiagnosticOnSurface = (diagnostic, surface, config) => {
|
|
|
5836
5925
|
return true;
|
|
5837
5926
|
};
|
|
5838
5927
|
const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
|
|
5839
|
-
const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(path.resolve(rootDirectory, relativePath)));
|
|
5928
|
+
const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(path$1.resolve(rootDirectory, relativePath)));
|
|
5840
5929
|
const listSourceFilesViaGit = (rootDirectory) => {
|
|
5841
5930
|
const result = spawnSync("git", [
|
|
5842
5931
|
"ls-files",
|
|
@@ -5859,12 +5948,12 @@ const listSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
5859
5948
|
const currentDirectory = stack.pop();
|
|
5860
5949
|
const entries = readDirectoryEntries(currentDirectory);
|
|
5861
5950
|
for (const entry of entries) {
|
|
5862
|
-
const absolutePath = path.join(currentDirectory, entry.name);
|
|
5951
|
+
const absolutePath = path$1.join(currentDirectory, entry.name);
|
|
5863
5952
|
if (entry.isDirectory()) {
|
|
5864
5953
|
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(absolutePath);
|
|
5865
5954
|
continue;
|
|
5866
5955
|
}
|
|
5867
|
-
if (entry.isFile() && isLintableSourceFile(entry.name)) filePaths.push(path.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
5956
|
+
if (entry.isFile() && isLintableSourceFile(entry.name)) filePaths.push(path$1.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
5868
5957
|
}
|
|
5869
5958
|
}
|
|
5870
5959
|
return filePaths;
|
|
@@ -5923,9 +6012,9 @@ var DeadCode = class DeadCode extends Context.Service()("react-doctor/DeadCode")
|
|
|
5923
6012
|
};
|
|
5924
6013
|
const createNodeReadFileLinesSync = (rootDirectory) => {
|
|
5925
6014
|
return (filePath) => {
|
|
5926
|
-
const absolutePath = path.isAbsolute(filePath) ? filePath : path.join(rootDirectory, filePath);
|
|
6015
|
+
const absolutePath = path$1.isAbsolute(filePath) ? filePath : path$1.join(rootDirectory, filePath);
|
|
5927
6016
|
try {
|
|
5928
|
-
return fs.readFileSync(absolutePath, "utf-8").split("\n");
|
|
6017
|
+
return fs$1.readFileSync(absolutePath, "utf-8").split("\n");
|
|
5929
6018
|
} catch {
|
|
5930
6019
|
return null;
|
|
5931
6020
|
}
|
|
@@ -5945,7 +6034,7 @@ var Files = class Files extends Context.Service()("react-doctor/Files") {
|
|
|
5945
6034
|
* pattern in react-doctor-evals' test layers.
|
|
5946
6035
|
*/
|
|
5947
6036
|
static layerInMemory = (tree) => {
|
|
5948
|
-
const resolveAbsolute = (filePath, rootDirectory) =>
|
|
6037
|
+
const resolveAbsolute = (filePath, rootDirectory) => path$1.isAbsolute(filePath) ? filePath : `${rootDirectory}/${filePath}`;
|
|
5949
6038
|
return Layer.succeed(Files, Files.of({
|
|
5950
6039
|
readLines: (input) => Effect.sync(() => {
|
|
5951
6040
|
const absolute = resolveAbsolute(input.filePath, input.rootDirectory);
|
|
@@ -6435,7 +6524,7 @@ const canOxlintExtendConfig = (configPath) => {
|
|
|
6435
6524
|
if (!configPath.endsWith(".eslintrc.json")) return true;
|
|
6436
6525
|
let parsed;
|
|
6437
6526
|
try {
|
|
6438
|
-
parsed = parseJsonOrJsonc(fs.readFileSync(configPath, "utf-8"));
|
|
6527
|
+
parsed = parseJsonOrJsonc(fs$1.readFileSync(configPath, "utf-8"));
|
|
6439
6528
|
} catch {
|
|
6440
6529
|
return true;
|
|
6441
6530
|
}
|
|
@@ -6448,7 +6537,7 @@ const canOxlintExtendConfig = (configPath) => {
|
|
|
6448
6537
|
};
|
|
6449
6538
|
const findFirstLintConfigInDirectory = (directory) => {
|
|
6450
6539
|
for (const filename of ADOPTABLE_LINT_CONFIG_FILENAMES) {
|
|
6451
|
-
const candidatePath = path.join(directory, filename);
|
|
6540
|
+
const candidatePath = path$1.join(directory, filename);
|
|
6452
6541
|
if (isFile(candidatePath)) return candidatePath;
|
|
6453
6542
|
}
|
|
6454
6543
|
return null;
|
|
@@ -6457,12 +6546,12 @@ const detectUserLintConfigPaths = (rootDirectory) => {
|
|
|
6457
6546
|
const directLintConfig = findFirstLintConfigInDirectory(rootDirectory);
|
|
6458
6547
|
if (directLintConfig) return [directLintConfig];
|
|
6459
6548
|
if (isProjectBoundary(rootDirectory)) return [];
|
|
6460
|
-
let ancestorDirectory = path.dirname(rootDirectory);
|
|
6461
|
-
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
6549
|
+
let ancestorDirectory = path$1.dirname(rootDirectory);
|
|
6550
|
+
while (ancestorDirectory !== path$1.dirname(ancestorDirectory)) {
|
|
6462
6551
|
const ancestorLintConfig = findFirstLintConfigInDirectory(ancestorDirectory);
|
|
6463
6552
|
if (ancestorLintConfig) return [ancestorLintConfig];
|
|
6464
6553
|
if (isProjectBoundary(ancestorDirectory)) return [];
|
|
6465
|
-
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
6554
|
+
ancestorDirectory = path$1.dirname(ancestorDirectory);
|
|
6466
6555
|
}
|
|
6467
6556
|
return [];
|
|
6468
6557
|
};
|
|
@@ -6491,10 +6580,10 @@ const findFilesWithDisableDirectivesViaFilesystem = (rootDirectory, includePaths
|
|
|
6491
6580
|
const matches = [];
|
|
6492
6581
|
const checkFile = (relativePath) => {
|
|
6493
6582
|
if (!isLintableSourceFile(relativePath)) return;
|
|
6494
|
-
const absolutePath = path.join(rootDirectory, relativePath);
|
|
6583
|
+
const absolutePath = path$1.join(rootDirectory, relativePath);
|
|
6495
6584
|
let content;
|
|
6496
6585
|
try {
|
|
6497
|
-
content = fs.readFileSync(absolutePath, "utf-8");
|
|
6586
|
+
content = fs$1.readFileSync(absolutePath, "utf-8");
|
|
6498
6587
|
} catch {
|
|
6499
6588
|
return;
|
|
6500
6589
|
}
|
|
@@ -6512,12 +6601,12 @@ const findFilesWithDisableDirectivesViaFilesystem = (rootDirectory, includePaths
|
|
|
6512
6601
|
for (const entry of entries) {
|
|
6513
6602
|
if (entry.isDirectory()) {
|
|
6514
6603
|
if (entry.name.startsWith(".") || IGNORED_DIRECTORIES.has(entry.name)) continue;
|
|
6515
|
-
stack.push(path.join(current, entry.name));
|
|
6604
|
+
stack.push(path$1.join(current, entry.name));
|
|
6516
6605
|
continue;
|
|
6517
6606
|
}
|
|
6518
6607
|
if (!entry.isFile()) continue;
|
|
6519
|
-
const absolute = path.join(current, entry.name);
|
|
6520
|
-
checkFile(path.relative(rootDirectory, absolute));
|
|
6608
|
+
const absolute = path$1.join(current, entry.name);
|
|
6609
|
+
checkFile(path$1.relative(rootDirectory, absolute));
|
|
6521
6610
|
}
|
|
6522
6611
|
}
|
|
6523
6612
|
return matches;
|
|
@@ -6532,7 +6621,7 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
6532
6621
|
if (isRestored) return;
|
|
6533
6622
|
isRestored = true;
|
|
6534
6623
|
for (const [absolutePath, originalContent] of originalContents) try {
|
|
6535
|
-
fs.writeFileSync(absolutePath, originalContent);
|
|
6624
|
+
fs$1.writeFileSync(absolutePath, originalContent);
|
|
6536
6625
|
} catch (error) {
|
|
6537
6626
|
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`);
|
|
6538
6627
|
}
|
|
@@ -6540,17 +6629,17 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
6540
6629
|
const onExit = () => restore();
|
|
6541
6630
|
process.once("exit", onExit);
|
|
6542
6631
|
for (const relativePath of filePaths) {
|
|
6543
|
-
const absolutePath = path.join(rootDirectory, relativePath);
|
|
6632
|
+
const absolutePath = path$1.join(rootDirectory, relativePath);
|
|
6544
6633
|
let originalContent;
|
|
6545
6634
|
try {
|
|
6546
|
-
originalContent = fs.readFileSync(absolutePath, "utf-8");
|
|
6635
|
+
originalContent = fs$1.readFileSync(absolutePath, "utf-8");
|
|
6547
6636
|
} catch {
|
|
6548
6637
|
continue;
|
|
6549
6638
|
}
|
|
6550
6639
|
const neutralizedContent = neutralizeContent(originalContent);
|
|
6551
6640
|
if (neutralizedContent !== originalContent) {
|
|
6552
6641
|
originalContents.set(absolutePath, originalContent);
|
|
6553
|
-
fs.writeFileSync(absolutePath, neutralizedContent);
|
|
6642
|
+
fs$1.writeFileSync(absolutePath, neutralizedContent);
|
|
6554
6643
|
}
|
|
6555
6644
|
}
|
|
6556
6645
|
return () => {
|
|
@@ -6687,11 +6776,11 @@ const filterRulesToAvailable = (rules, pluginNamespace, availableRuleNames) => {
|
|
|
6687
6776
|
* renamed.
|
|
6688
6777
|
*/
|
|
6689
6778
|
const resolveUserPlugin = (spec, configSourceDirectory) => {
|
|
6690
|
-
const isRelative = spec.startsWith("./") || spec.startsWith("../") || path.isAbsolute(spec);
|
|
6691
|
-
const candidateRequire = createRequire(path.join(configSourceDirectory, "noop.js"));
|
|
6779
|
+
const isRelative = spec.startsWith("./") || spec.startsWith("../") || path$1.isAbsolute(spec);
|
|
6780
|
+
const candidateRequire = createRequire(path$1.join(configSourceDirectory, "noop.js"));
|
|
6692
6781
|
let resolvedSpecifier;
|
|
6693
6782
|
try {
|
|
6694
|
-
resolvedSpecifier = isRelative ? path.resolve(configSourceDirectory, spec) : candidateRequire.resolve(spec);
|
|
6783
|
+
resolvedSpecifier = isRelative ? path$1.resolve(configSourceDirectory, spec) : candidateRequire.resolve(spec);
|
|
6695
6784
|
} catch (error) {
|
|
6696
6785
|
warnConfigIssue(`config.plugins entry "${spec}" could not be resolved from ${configSourceDirectory}: ${error instanceof Error ? error.message : String(error)}`);
|
|
6697
6786
|
return null;
|
|
@@ -6731,8 +6820,8 @@ const resolveUserPlugins = (specs, configSourceDirectory) => {
|
|
|
6731
6820
|
return resolved;
|
|
6732
6821
|
};
|
|
6733
6822
|
const resolveSettingsRootDirectory = (rootDirectory) => {
|
|
6734
|
-
if (!fs.existsSync(rootDirectory)) return rootDirectory;
|
|
6735
|
-
return fs.realpathSync(rootDirectory);
|
|
6823
|
+
if (!fs$1.existsSync(rootDirectory)) return rootDirectory;
|
|
6824
|
+
return fs$1.realpathSync(rootDirectory);
|
|
6736
6825
|
};
|
|
6737
6826
|
const resolveCompilerCleanupBucketSeverity = (ruleKey, severityControls) => {
|
|
6738
6827
|
if (!COMPILER_CLEANUP_RULE_KEYS.has(ruleKey)) return void 0;
|
|
@@ -6808,6 +6897,7 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
6808
6897
|
settings: { "react-doctor": {
|
|
6809
6898
|
framework: project.framework,
|
|
6810
6899
|
rootDirectory: resolveSettingsRootDirectory(project.rootDirectory),
|
|
6900
|
+
...project.shopifyFlashListMajorVersion !== null ? { shopifyFlashListMajorVersion: project.shopifyFlashListMajorVersion } : {},
|
|
6811
6901
|
...serverAuthFunctionNames && serverAuthFunctionNames.length > 0 ? { serverAuthFunctionNames: [...serverAuthFunctionNames] } : {}
|
|
6812
6902
|
} },
|
|
6813
6903
|
rules: {
|
|
@@ -6820,13 +6910,13 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
6820
6910
|
const esmRequire = createRequire(import.meta.url);
|
|
6821
6911
|
const resolveOxlintBinary = () => {
|
|
6822
6912
|
const oxlintMainPath = esmRequire.resolve("oxlint");
|
|
6823
|
-
const oxlintPackageDirectory = path.resolve(path.dirname(oxlintMainPath), "..");
|
|
6824
|
-
return path.join(oxlintPackageDirectory, "bin", "oxlint");
|
|
6913
|
+
const oxlintPackageDirectory = path$1.resolve(path$1.dirname(oxlintMainPath), "..");
|
|
6914
|
+
return path$1.join(oxlintPackageDirectory, "bin", "oxlint");
|
|
6825
6915
|
};
|
|
6826
6916
|
const resolvePluginPath = () => esmRequire.resolve("oxlint-plugin-react-doctor");
|
|
6827
6917
|
const TSCONFIG_FILENAMES = ["tsconfig.json", "tsconfig.base.json"];
|
|
6828
6918
|
const resolveTsConfigRelativePath = (rootDirectory) => {
|
|
6829
|
-
for (const filename of TSCONFIG_FILENAMES) if (fs.existsSync(path.join(rootDirectory, filename))) return `./${filename}`;
|
|
6919
|
+
for (const filename of TSCONFIG_FILENAMES) if (fs$1.existsSync(path$1.join(rootDirectory, filename))) return `./${filename}`;
|
|
6830
6920
|
return null;
|
|
6831
6921
|
};
|
|
6832
6922
|
const dedupeDiagnostics = (diagnostics) => {
|
|
@@ -7326,10 +7416,10 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
7326
7416
|
if (!diagnostic.message.startsWith(REACT_HOOK_USE_MESSAGE_PREFIX)) return false;
|
|
7327
7417
|
const primaryLabel = diagnostic.labels[0];
|
|
7328
7418
|
if (!primaryLabel) return false;
|
|
7329
|
-
const absolutePath = path.isAbsolute(diagnostic.filename) ? diagnostic.filename : path.join(rootDirectory, diagnostic.filename);
|
|
7419
|
+
const absolutePath = path$1.isAbsolute(diagnostic.filename) ? diagnostic.filename : path$1.join(rootDirectory, diagnostic.filename);
|
|
7330
7420
|
let sourceText;
|
|
7331
7421
|
try {
|
|
7332
|
-
sourceText = fs.readFileSync(absolutePath, "utf-8");
|
|
7422
|
+
sourceText = fs$1.readFileSync(absolutePath, "utf-8");
|
|
7333
7423
|
} catch {
|
|
7334
7424
|
return false;
|
|
7335
7425
|
}
|
|
@@ -7395,6 +7485,30 @@ const parseRuleCode = (code) => {
|
|
|
7395
7485
|
};
|
|
7396
7486
|
};
|
|
7397
7487
|
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "Bugs";
|
|
7488
|
+
/**
|
|
7489
|
+
* Maps oxlint's non-primary labels (`labels[1..]`) into related source
|
|
7490
|
+
* locations. Editors surface these as a diagnostic's
|
|
7491
|
+
* `relatedInformation`; non-editor consumers ignore the field. Labels
|
|
7492
|
+
* with empty text still carry a useful jump target, so they're kept
|
|
7493
|
+
* with a neutral message.
|
|
7494
|
+
*/
|
|
7495
|
+
const buildRelatedLocations = (labels, filePath) => {
|
|
7496
|
+
if (labels.length <= 1) return [];
|
|
7497
|
+
const related = [];
|
|
7498
|
+
for (let labelIndex = 1; labelIndex < labels.length; labelIndex++) {
|
|
7499
|
+
const label = labels[labelIndex];
|
|
7500
|
+
if (!label?.span) continue;
|
|
7501
|
+
related.push({
|
|
7502
|
+
filePath,
|
|
7503
|
+
line: label.span.line ?? 0,
|
|
7504
|
+
column: label.span.column ?? 0,
|
|
7505
|
+
offset: label.span.offset,
|
|
7506
|
+
length: label.span.length,
|
|
7507
|
+
message: label.label ?? ""
|
|
7508
|
+
});
|
|
7509
|
+
}
|
|
7510
|
+
return related;
|
|
7511
|
+
};
|
|
7398
7512
|
const isOxlintOutput = (value) => {
|
|
7399
7513
|
if (typeof value !== "object" || value === null) return false;
|
|
7400
7514
|
const candidate = value;
|
|
@@ -7420,7 +7534,7 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
7420
7534
|
if (!isOxlintOutput(parsed)) throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
|
|
7421
7535
|
const minifiedFileCache = /* @__PURE__ */ new Map();
|
|
7422
7536
|
const isMinifiedDiagnosticFile = (filename) => {
|
|
7423
|
-
const absolutePath = path.isAbsolute(filename) ? filename : path.resolve(rootDirectory || ".", filename);
|
|
7537
|
+
const absolutePath = path$1.isAbsolute(filename) ? filename : path$1.resolve(rootDirectory || ".", filename);
|
|
7424
7538
|
const cached = minifiedFileCache.get(absolutePath);
|
|
7425
7539
|
if (cached !== void 0) return cached;
|
|
7426
7540
|
const minified = isMinifiedSource(absolutePath);
|
|
@@ -7431,8 +7545,11 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
7431
7545
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
7432
7546
|
const primaryLabel = diagnostic.labels[0];
|
|
7433
7547
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
7548
|
+
const normalizedFilePath = diagnostic.filename.replaceAll("\\", "/");
|
|
7549
|
+
const primarySpan = primaryLabel?.span;
|
|
7550
|
+
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath);
|
|
7434
7551
|
return {
|
|
7435
|
-
filePath:
|
|
7552
|
+
filePath: normalizedFilePath,
|
|
7436
7553
|
plugin,
|
|
7437
7554
|
rule,
|
|
7438
7555
|
severity: diagnostic.severity,
|
|
@@ -7440,9 +7557,14 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
7440
7557
|
message: cleaned.message,
|
|
7441
7558
|
help: cleaned.help,
|
|
7442
7559
|
url: diagnostic.url,
|
|
7443
|
-
line:
|
|
7444
|
-
column:
|
|
7445
|
-
|
|
7560
|
+
line: primarySpan?.line ?? 0,
|
|
7561
|
+
column: primarySpan?.column ?? 0,
|
|
7562
|
+
...primarySpan ? {
|
|
7563
|
+
offset: primarySpan.offset,
|
|
7564
|
+
length: primarySpan.length
|
|
7565
|
+
} : {},
|
|
7566
|
+
category: resolveDiagnosticCategory(plugin, rule),
|
|
7567
|
+
...relatedLocations.length > 0 ? { relatedLocations } : {}
|
|
7446
7568
|
};
|
|
7447
7569
|
});
|
|
7448
7570
|
};
|
|
@@ -7687,12 +7809,12 @@ const validateRuleRegistration = () => {
|
|
|
7687
7809
|
* legitimate overwriter is `this` runner inside the same temp dir.
|
|
7688
7810
|
*/
|
|
7689
7811
|
const writeOxlintConfig = (configPath, configToWrite) => {
|
|
7690
|
-
fs.rmSync(configPath, { force: true });
|
|
7691
|
-
const fileHandle = fs.openSync(configPath, "wx", 384);
|
|
7812
|
+
fs$1.rmSync(configPath, { force: true });
|
|
7813
|
+
const fileHandle = fs$1.openSync(configPath, "wx", 384);
|
|
7692
7814
|
try {
|
|
7693
|
-
fs.writeFileSync(fileHandle, JSON.stringify(configToWrite));
|
|
7815
|
+
fs$1.writeFileSync(fileHandle, JSON.stringify(configToWrite));
|
|
7694
7816
|
} finally {
|
|
7695
|
-
fs.closeSync(fileHandle);
|
|
7817
|
+
fs$1.closeSync(fileHandle);
|
|
7696
7818
|
}
|
|
7697
7819
|
};
|
|
7698
7820
|
/**
|
|
@@ -7733,8 +7855,8 @@ const runOxlint = async (options) => {
|
|
|
7733
7855
|
userPlugins
|
|
7734
7856
|
});
|
|
7735
7857
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : await neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
7736
|
-
const configDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
7737
|
-
const configPath = path.join(configDirectory, "oxlintrc.json");
|
|
7858
|
+
const configDirectory = fs$1.mkdtempSync(path$1.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
7859
|
+
const configPath = path$1.join(configDirectory, "oxlintrc.json");
|
|
7738
7860
|
try {
|
|
7739
7861
|
const baseArgs = [
|
|
7740
7862
|
resolveOxlintBinary(),
|
|
@@ -7749,8 +7871,8 @@ const runOxlint = async (options) => {
|
|
|
7749
7871
|
}
|
|
7750
7872
|
const combinedPatterns = collectIgnorePatterns(rootDirectory);
|
|
7751
7873
|
if (combinedPatterns.length > 0) {
|
|
7752
|
-
const combinedIgnorePath = path.join(configDirectory, "combined.ignore");
|
|
7753
|
-
fs.writeFileSync(combinedIgnorePath, `${combinedPatterns.join("\n")}\n`);
|
|
7874
|
+
const combinedIgnorePath = path$1.join(configDirectory, "combined.ignore");
|
|
7875
|
+
fs$1.writeFileSync(combinedIgnorePath, `${combinedPatterns.join("\n")}\n`);
|
|
7754
7876
|
baseArgs.push("--ignore-path", combinedIgnorePath);
|
|
7755
7877
|
}
|
|
7756
7878
|
const fileBatches = batchIncludePaths(baseArgs, includePaths !== void 0 ? includePaths : listSourceFiles(rootDirectory));
|
|
@@ -7776,7 +7898,7 @@ const runOxlint = async (options) => {
|
|
|
7776
7898
|
}
|
|
7777
7899
|
} finally {
|
|
7778
7900
|
restoreDisableDirectives();
|
|
7779
|
-
fs.rmSync(configDirectory, {
|
|
7901
|
+
fs$1.rmSync(configDirectory, {
|
|
7780
7902
|
recursive: true,
|
|
7781
7903
|
force: true
|
|
7782
7904
|
});
|
|
@@ -7978,7 +8100,7 @@ var Reporter = class Reporter extends Context.Service()("react-doctor/Reporter")
|
|
|
7978
8100
|
* `Diagnostic` schema.
|
|
7979
8101
|
*/
|
|
7980
8102
|
static layerNdjson = (filePath) => Layer.effect(Reporter, Effect.sync(() => {
|
|
7981
|
-
fs$1.mkdirSync(
|
|
8103
|
+
fs$1.mkdirSync(path$1.dirname(filePath), { recursive: true });
|
|
7982
8104
|
const handle = fs$1.openSync(filePath, "a");
|
|
7983
8105
|
const encode = Schema.encodeUnknownSync(Diagnostic);
|
|
7984
8106
|
const emit = (diagnostic) => Effect.sync(() => {
|
|
@@ -8029,6 +8151,7 @@ const calculateScore = async (diagnostics, options = {}) => {
|
|
|
8029
8151
|
...typeof options.metadata?.sourceFileCount === "number" ? { sourceFileCount: options.metadata.sourceFileCount } : {},
|
|
8030
8152
|
...options.metadata?.defaultBranch ? { defaultBranch: options.metadata.defaultBranch } : {},
|
|
8031
8153
|
...options.metadata?.doctorVersion ? { doctorVersion: options.metadata.doctorVersion } : {},
|
|
8154
|
+
...options.metadata?.runId ? { runId: options.metadata.runId } : {},
|
|
8032
8155
|
...options.metadata?.githubEventName ? { githubEventName: options.metadata.githubEventName } : {},
|
|
8033
8156
|
...options.metadata?.githubActorAssociation ? { githubActorAssociation: options.metadata.githubActorAssociation } : {},
|
|
8034
8157
|
...options.metadata?.githubViewerPermission ? { githubViewerPermission: options.metadata.githubViewerPermission } : {}
|
|
@@ -8087,7 +8210,7 @@ const getStringProperty = (value, propertyName) => {
|
|
|
8087
8210
|
const readGithubEventPayload = (eventPath) => {
|
|
8088
8211
|
if (eventPath === void 0 || eventPath.length === 0) return null;
|
|
8089
8212
|
try {
|
|
8090
|
-
return JSON.parse(readFileSync(eventPath, "utf8"));
|
|
8213
|
+
return JSON.parse(fs$1.readFileSync(eventPath, "utf8"));
|
|
8091
8214
|
} catch {
|
|
8092
8215
|
return null;
|
|
8093
8216
|
}
|
|
@@ -8170,8 +8293,8 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
8170
8293
|
directory: scanDirectory,
|
|
8171
8294
|
repo
|
|
8172
8295
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
8173
|
-
const lintIncludePaths = computeJsxIncludePaths([...input.includePaths]) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
8174
|
-
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path.resolve(scanDirectory, relativePath)) : [];
|
|
8296
|
+
const lintIncludePaths = (input.skipJsxIncludeFilter ? input.includePaths.length > 0 ? [...input.includePaths] : void 0 : computeJsxIncludePaths([...input.includePaths])) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
8297
|
+
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path$1.resolve(scanDirectory, relativePath)) : [];
|
|
8175
8298
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
8176
8299
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
8177
8300
|
yield* beforeLint(project, lintIncludePaths ?? void 0);
|
|
@@ -8268,6 +8391,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
8268
8391
|
sourceFileCount: project.sourceFileCount,
|
|
8269
8392
|
...defaultBranch !== null ? { defaultBranch } : {},
|
|
8270
8393
|
...input.doctorVersion !== void 0 ? { doctorVersion: input.doctorVersion } : {},
|
|
8394
|
+
...input.runId !== void 0 ? { runId: input.runId } : {},
|
|
8271
8395
|
...githubActionsScoreMetadata,
|
|
8272
8396
|
...githubViewerPermission !== null ? { githubViewerPermission } : {}
|
|
8273
8397
|
};
|
|
@@ -8321,25 +8445,25 @@ const isNodeVersionCompatibleWithOxlint = ({ major, minor }) => {
|
|
|
8321
8445
|
const isCurrentNodeCompatibleWithOxlint = () => isNodeVersionCompatibleWithOxlint(parseNodeVersion(process.version));
|
|
8322
8446
|
const getNvmDirectory = () => {
|
|
8323
8447
|
const envNvmDirectory = process.env.NVM_DIR;
|
|
8324
|
-
if (envNvmDirectory && existsSync(envNvmDirectory)) return envNvmDirectory;
|
|
8325
|
-
const defaultNvmDirectory = path.join(os.homedir(), ".nvm");
|
|
8326
|
-
if (existsSync(defaultNvmDirectory)) return defaultNvmDirectory;
|
|
8448
|
+
if (envNvmDirectory && fs$1.existsSync(envNvmDirectory)) return envNvmDirectory;
|
|
8449
|
+
const defaultNvmDirectory = path$1.join(os.homedir(), ".nvm");
|
|
8450
|
+
if (fs$1.existsSync(defaultNvmDirectory)) return defaultNvmDirectory;
|
|
8327
8451
|
return null;
|
|
8328
8452
|
};
|
|
8329
8453
|
const isNvmInstalled = () => getNvmDirectory() !== null;
|
|
8330
8454
|
const findCompatibleNvmBinary = () => {
|
|
8331
8455
|
const nvmDirectory = getNvmDirectory();
|
|
8332
8456
|
if (!nvmDirectory) return null;
|
|
8333
|
-
const versionsDirectory = path.join(nvmDirectory, "versions", "node");
|
|
8334
|
-
if (!existsSync(versionsDirectory)) return null;
|
|
8335
|
-
const compatibleVersions = readdirSync(versionsDirectory).filter((directoryName) => directoryName.startsWith("v")).map((directoryName) => ({
|
|
8457
|
+
const versionsDirectory = path$1.join(nvmDirectory, "versions", "node");
|
|
8458
|
+
if (!fs$1.existsSync(versionsDirectory)) return null;
|
|
8459
|
+
const compatibleVersions = fs$1.readdirSync(versionsDirectory).filter((directoryName) => directoryName.startsWith("v")).map((directoryName) => ({
|
|
8336
8460
|
directoryName,
|
|
8337
8461
|
...parseNodeVersion(directoryName)
|
|
8338
8462
|
})).filter((version) => isNodeVersionCompatibleWithOxlint(version)).sort((versionA, versionB) => versionB.major - versionA.major || versionB.minor - versionA.minor || versionB.patch - versionA.patch);
|
|
8339
8463
|
if (compatibleVersions.length === 0) return null;
|
|
8340
8464
|
const bestVersion = compatibleVersions[0];
|
|
8341
|
-
const binaryPath = path.join(versionsDirectory, bestVersion.directoryName, "bin", "node");
|
|
8342
|
-
return existsSync(binaryPath) ? binaryPath : null;
|
|
8465
|
+
const binaryPath = path$1.join(versionsDirectory, bestVersion.directoryName, "bin", "node");
|
|
8466
|
+
return fs$1.existsSync(binaryPath) ? binaryPath : null;
|
|
8343
8467
|
};
|
|
8344
8468
|
const getNodeVersionFromBinary = (binaryPath) => {
|
|
8345
8469
|
const result = spawnSync(binaryPath, ["--version"], { encoding: "utf-8" });
|
|
@@ -8349,8 +8473,8 @@ const getNodeVersionFromBinary = (binaryPath) => {
|
|
|
8349
8473
|
const installNodeViaNvm = () => {
|
|
8350
8474
|
const nvmDirectory = getNvmDirectory();
|
|
8351
8475
|
if (!nvmDirectory) return false;
|
|
8352
|
-
const nvmScript = path.join(nvmDirectory, "nvm.sh");
|
|
8353
|
-
if (!existsSync(nvmScript)) return false;
|
|
8476
|
+
const nvmScript = path$1.join(nvmDirectory, "nvm.sh");
|
|
8477
|
+
if (!fs$1.existsSync(nvmScript)) return false;
|
|
8354
8478
|
const result = spawnSync("bash", ["-c", ". \"$NVM_SCRIPT\" && nvm install \"$NODE_MAJOR\""], {
|
|
8355
8479
|
stdio: "inherit",
|
|
8356
8480
|
env: {
|
|
@@ -8413,8 +8537,8 @@ const resolveNodeForOxlint = () => {
|
|
|
8413
8537
|
* result that lands outside it before `writeFileSync` runs.
|
|
8414
8538
|
*/
|
|
8415
8539
|
const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
8416
|
-
const relative = path.relative(parentAbsolutePath, childAbsolutePath);
|
|
8417
|
-
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
8540
|
+
const relative = path$1.relative(parentAbsolutePath, childAbsolutePath);
|
|
8541
|
+
return Boolean(relative) && !relative.startsWith("..") && !path$1.isAbsolute(relative);
|
|
8418
8542
|
};
|
|
8419
8543
|
(class StagedFiles extends Context.Service()("react-doctor/StagedFiles") {
|
|
8420
8544
|
static layerNode = Layer.effect(StagedFiles, Effect.gen(function* () {
|
|
@@ -8423,23 +8547,23 @@ const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
|
8423
8547
|
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(isLintableSourceFile))),
|
|
8424
8548
|
materialize: ({ directory, stagedFiles, tempDirectory }) => Effect.gen(function* () {
|
|
8425
8549
|
const materializedFiles = [];
|
|
8426
|
-
const resolvedTempDirectory = path.resolve(tempDirectory);
|
|
8550
|
+
const resolvedTempDirectory = path$1.resolve(tempDirectory);
|
|
8427
8551
|
for (const relativePath of stagedFiles) {
|
|
8428
8552
|
const content = yield* git.showStagedContent(directory, relativePath, { maxBufferBytes: GIT_SHOW_MAX_BUFFER_BYTES }).pipe(Effect.orElseSucceed(() => null));
|
|
8429
8553
|
if (content === null) continue;
|
|
8430
|
-
const candidateTargetPath = path.resolve(resolvedTempDirectory, relativePath);
|
|
8554
|
+
const candidateTargetPath = path$1.resolve(resolvedTempDirectory, relativePath);
|
|
8431
8555
|
if (!isPathInsideDirectory(candidateTargetPath, resolvedTempDirectory)) continue;
|
|
8432
8556
|
yield* Effect.sync(() => {
|
|
8433
|
-
fs.mkdirSync(path.dirname(candidateTargetPath), { recursive: true });
|
|
8434
|
-
fs.writeFileSync(candidateTargetPath, content);
|
|
8557
|
+
fs$1.mkdirSync(path$1.dirname(candidateTargetPath), { recursive: true });
|
|
8558
|
+
fs$1.writeFileSync(candidateTargetPath, content);
|
|
8435
8559
|
});
|
|
8436
8560
|
materializedFiles.push(relativePath);
|
|
8437
8561
|
}
|
|
8438
8562
|
yield* Effect.sync(() => {
|
|
8439
8563
|
for (const configFilename of STAGED_FILES_PROJECT_CONFIG_FILENAMES) {
|
|
8440
|
-
const sourcePath = path.join(directory, configFilename);
|
|
8441
|
-
const targetPath = path.join(resolvedTempDirectory, configFilename);
|
|
8442
|
-
if (fs.existsSync(sourcePath) && !fs.existsSync(targetPath)) fs.cpSync(sourcePath, targetPath);
|
|
8564
|
+
const sourcePath = path$1.join(directory, configFilename);
|
|
8565
|
+
const targetPath = path$1.join(resolvedTempDirectory, configFilename);
|
|
8566
|
+
if (fs$1.existsSync(sourcePath) && !fs$1.existsSync(targetPath)) fs$1.cpSync(sourcePath, targetPath);
|
|
8443
8567
|
}
|
|
8444
8568
|
});
|
|
8445
8569
|
return {
|
|
@@ -8447,7 +8571,7 @@ const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
|
8447
8571
|
stagedFiles: materializedFiles,
|
|
8448
8572
|
cleanup: () => {
|
|
8449
8573
|
try {
|
|
8450
|
-
fs.rmSync(tempDirectory, {
|
|
8574
|
+
fs$1.rmSync(tempDirectory, {
|
|
8451
8575
|
recursive: true,
|
|
8452
8576
|
force: true
|
|
8453
8577
|
});
|
|
@@ -8724,4 +8848,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
8724
8848
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
8725
8849
|
|
|
8726
8850
|
//# sourceMappingURL=index.js.map
|
|
8727
|
-
//# debugId=
|
|
8851
|
+
//# debugId=ac54f8ec-45d1-5b7d-8208-35f50f4c4973
|