react-doctor 0.5.1-dev.2f26228 → 0.5.1-dev.3de9106
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/dist/cli.js +405 -158
- package/dist/index.d.ts +92 -46
- package/dist/index.js +251 -57
- package/dist/lsp.js +153 -52
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5c0d7930-333e-5d67-93cf-63eae9bd87f8")}catch(e){}}();
|
|
3
3
|
import { r as __toESM$1, t as __commonJSMin$1 } from "./chunk-N93fKeF6.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import * as NFS from "node:fs";
|
|
@@ -13,9 +13,10 @@ import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_
|
|
|
13
13
|
import * as OS from "node:os";
|
|
14
14
|
import os from "node:os";
|
|
15
15
|
import { parseJSON5 } from "confbox";
|
|
16
|
+
import * as NodeUrl from "node:url";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
16
18
|
import { createJiti } from "jiti";
|
|
17
19
|
import * as Crypto from "node:crypto";
|
|
18
|
-
import * as NodeUrl from "node:url";
|
|
19
20
|
import { gzipSync } from "node:zlib";
|
|
20
21
|
//#region ../../node_modules/.pnpm/effect@4.0.0-beta.70/node_modules/effect/dist/Pipeable.js
|
|
21
22
|
/**
|
|
@@ -19253,6 +19254,7 @@ var Diagnostic = class extends Class("Diagnostic")({
|
|
|
19253
19254
|
endLine: optional(Number$1),
|
|
19254
19255
|
endColumn: optional(Number$1),
|
|
19255
19256
|
category: String$1,
|
|
19257
|
+
fileContext: optional(Literals(["test", "story"])),
|
|
19256
19258
|
suppressionHint: optional(String$1),
|
|
19257
19259
|
relatedLocations: optional(ArraySchema(DiagnosticRelatedLocation))
|
|
19258
19260
|
}) {};
|
|
@@ -34570,8 +34572,10 @@ const isFileIgnoredByPatterns = (filePath, rootDirectory, patterns) => {
|
|
|
34570
34572
|
const relativePath = toRelativePath(filePath, rootDirectory);
|
|
34571
34573
|
return patterns.some((pattern) => pattern.test(relativePath));
|
|
34572
34574
|
};
|
|
34575
|
+
const SCRIPT_EXTENSION_FRAGMENT = "[cm]?[jt]sx?";
|
|
34576
|
+
const STORY_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:stories|story)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
|
|
34577
|
+
const TEST_FILE_SUFFIX_PATTERN = new RegExp(`\\.(?:test|spec|fixture|fixtures)\\.(?:${SCRIPT_EXTENSION_FRAGMENT})$`);
|
|
34573
34578
|
const TEST_FILE_DIRECTORY_PATTERN = /(?:^|\/)(?:__tests__|__test__|tests|test|__mocks__|cypress|e2e|playwright)\//;
|
|
34574
|
-
const TEST_FILE_SUFFIX_PATTERN = /\.(?:test|spec|stories|story|fixture|fixtures)\.(?:[cm]?[jt]sx?)$/;
|
|
34575
34579
|
const FIXTURE_PROJECT_PATTERN = /\/(?:fixtures|__fixtures__)\//;
|
|
34576
34580
|
const SOURCE_ROOT_PATTERN = /\/(?:src|app|lib|components|pages|features|modules|packages|apps|frontend|client)\//g;
|
|
34577
34581
|
const stripAboveSourceRoot = (relativePath) => {
|
|
@@ -34582,12 +34586,23 @@ const stripAboveSourceRoot = (relativePath) => {
|
|
|
34582
34586
|
if (lastIdx >= 0) return relativePath.slice(lastIdx);
|
|
34583
34587
|
return relativePath.slice(fixtureMatch.index + fixtureMatch[0].length - 1);
|
|
34584
34588
|
};
|
|
34585
|
-
|
|
34586
|
-
|
|
34589
|
+
/**
|
|
34590
|
+
* Classifies where a file sits relative to shipped code. A finding in a
|
|
34591
|
+
* `.stories.tsx` or `.spec.ts` file never runs in front of users, so
|
|
34592
|
+
* renderers label those sites instead of framing them as production
|
|
34593
|
+
* impact (`rn-no-raw-text` in a spec doesn't say users crash).
|
|
34594
|
+
*
|
|
34595
|
+
* `"story"` is the `.stories.*` / `.story.*` suffix; `"test"` is the
|
|
34596
|
+
* test/spec/fixture suffixes and test directories; `"production"` is
|
|
34597
|
+
* the default.
|
|
34598
|
+
*/
|
|
34599
|
+
const classifyFileContext = (relativePath) => {
|
|
34600
|
+
if (relativePath.length === 0) return "production";
|
|
34587
34601
|
const forwardSlashed = relativePath.replaceAll("\\", "/");
|
|
34588
|
-
if (
|
|
34602
|
+
if (STORY_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "story";
|
|
34603
|
+
if (TEST_FILE_SUFFIX_PATTERN.test(forwardSlashed)) return "test";
|
|
34589
34604
|
const scoped = stripAboveSourceRoot(forwardSlashed);
|
|
34590
|
-
return TEST_FILE_DIRECTORY_PATTERN.test(scoped);
|
|
34605
|
+
return TEST_FILE_DIRECTORY_PATTERN.test(scoped) ? "test" : "production";
|
|
34591
34606
|
};
|
|
34592
34607
|
/**
|
|
34593
34608
|
* Resolves the user-configured severity override for a rule.
|
|
@@ -34811,6 +34826,8 @@ const collectStringSet = (values) => {
|
|
|
34811
34826
|
* 5. `rn-no-raw-text` suppression via configured `textComponents` and
|
|
34812
34827
|
* `rawTextWrapperComponents` (config-driven JSX enclosure checks)
|
|
34813
34828
|
* 6. inline suppressions (`// react-doctor-disable-next-line ...`)
|
|
34829
|
+
* 7. file-context stamping (`fileContext: "test" | "story"` on
|
|
34830
|
+
* survivors in non-production files, so renderers can label them)
|
|
34814
34831
|
*
|
|
34815
34832
|
* Returns `null` when the diagnostic is dropped, the (possibly
|
|
34816
34833
|
* severity-restamped) diagnostic otherwise.
|
|
@@ -34830,7 +34847,7 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34830
34847
|
const hasTextComponents = textComponentNames.size > 0;
|
|
34831
34848
|
const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
|
|
34832
34849
|
const fileLinesCache = /* @__PURE__ */ new Map();
|
|
34833
|
-
const
|
|
34850
|
+
const fileContextCache = /* @__PURE__ */ new Map();
|
|
34834
34851
|
const libraryFileCache = /* @__PURE__ */ new Map();
|
|
34835
34852
|
const isLibraryFile = (filePath) => {
|
|
34836
34853
|
let cached = libraryFileCache.get(filePath);
|
|
@@ -34847,11 +34864,11 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34847
34864
|
fileLinesCache.set(filePath, lines);
|
|
34848
34865
|
return lines;
|
|
34849
34866
|
};
|
|
34850
|
-
const
|
|
34851
|
-
let cached =
|
|
34867
|
+
const getFileContext = (filePath) => {
|
|
34868
|
+
let cached = fileContextCache.get(filePath);
|
|
34852
34869
|
if (cached === void 0) {
|
|
34853
|
-
cached =
|
|
34854
|
-
|
|
34870
|
+
cached = classifyFileContext(filePath);
|
|
34871
|
+
fileContextCache.set(filePath, cached);
|
|
34855
34872
|
}
|
|
34856
34873
|
return cached;
|
|
34857
34874
|
};
|
|
@@ -34860,7 +34877,7 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34860
34877
|
const rule = reactDoctorPlugin.rules[diagnostic.rule];
|
|
34861
34878
|
if (!rule?.tags?.includes("test-noise")) return false;
|
|
34862
34879
|
if (rule.tags.includes("migration-hint")) return false;
|
|
34863
|
-
return
|
|
34880
|
+
return getFileContext(diagnostic.filePath) !== "production";
|
|
34864
34881
|
};
|
|
34865
34882
|
const isRuleIgnored = (ruleIdentifier) => {
|
|
34866
34883
|
for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
|
|
@@ -34917,6 +34934,11 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
34917
34934
|
};
|
|
34918
34935
|
}
|
|
34919
34936
|
}
|
|
34937
|
+
const fileContext = getFileContext(current.filePath);
|
|
34938
|
+
if (fileContext !== "production") current = {
|
|
34939
|
+
...current,
|
|
34940
|
+
fileContext
|
|
34941
|
+
};
|
|
34920
34942
|
return current;
|
|
34921
34943
|
} };
|
|
34922
34944
|
};
|
|
@@ -35313,10 +35335,41 @@ const PACKAGE_JSON_CONFIG_KEY = "reactDoctor";
|
|
|
35313
35335
|
const LEGACY_CONFIG_FILENAME = "react-doctor.config.json";
|
|
35314
35336
|
const jiti = createJiti(import.meta.url);
|
|
35315
35337
|
const formatError = (error) => error instanceof Error ? error.message : String(error);
|
|
35316
|
-
const
|
|
35317
|
-
const imported = await
|
|
35338
|
+
const importDefaultExport = async (jitiInstance, filePath) => {
|
|
35339
|
+
const imported = await jitiInstance.import(filePath);
|
|
35318
35340
|
return imported?.default ?? imported;
|
|
35319
35341
|
};
|
|
35342
|
+
const SELF_PACKAGE_IMPORT_SPECIFIER = "react-doctor/api";
|
|
35343
|
+
const SELF_PACKAGE_RESOLVE_TARGETS = ["react-doctor/api", "@react-doctor/core"];
|
|
35344
|
+
const MODULE_NOT_FOUND_ERROR_CODES = new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
35345
|
+
let selfAliasJiti;
|
|
35346
|
+
const getSelfAliasJiti = () => {
|
|
35347
|
+
if (selfAliasJiti !== void 0) return selfAliasJiti;
|
|
35348
|
+
for (const resolveTarget of SELF_PACKAGE_RESOLVE_TARGETS) try {
|
|
35349
|
+
const aliasTargetPath = fileURLToPath(jiti.esmResolve(resolveTarget));
|
|
35350
|
+
selfAliasJiti = createJiti(import.meta.url, { alias: { [SELF_PACKAGE_IMPORT_SPECIFIER]: aliasTargetPath } });
|
|
35351
|
+
return selfAliasJiti;
|
|
35352
|
+
} catch {
|
|
35353
|
+
continue;
|
|
35354
|
+
}
|
|
35355
|
+
selfAliasJiti = null;
|
|
35356
|
+
return selfAliasJiti;
|
|
35357
|
+
};
|
|
35358
|
+
const isSelfPackageResolutionError = (error) => error instanceof Error && "code" in error && typeof error.code === "string" && MODULE_NOT_FOUND_ERROR_CODES.has(error.code) && error.message.includes(SELF_PACKAGE_IMPORT_SPECIFIER);
|
|
35359
|
+
const loadModuleConfig = async (filePath) => {
|
|
35360
|
+
try {
|
|
35361
|
+
return await importDefaultExport(jiti, filePath);
|
|
35362
|
+
} catch (error) {
|
|
35363
|
+
if (!isSelfPackageResolutionError(error)) throw error;
|
|
35364
|
+
const aliasJiti = getSelfAliasJiti();
|
|
35365
|
+
if (!aliasJiti) throw error;
|
|
35366
|
+
try {
|
|
35367
|
+
return await importDefaultExport(aliasJiti, filePath);
|
|
35368
|
+
} catch (retryError) {
|
|
35369
|
+
throw new Error(`${formatError(error)} (retry with ${SELF_PACKAGE_IMPORT_SPECIFIER} aliased to the running react-doctor package also failed: ${formatError(retryError)})`, { cause: retryError });
|
|
35370
|
+
}
|
|
35371
|
+
}
|
|
35372
|
+
};
|
|
35320
35373
|
const readDataConfig = (filePath) => parseJSON5(NFS.readFileSync(filePath, "utf-8"));
|
|
35321
35374
|
const readEmbeddedPackageJsonConfig = (directory) => {
|
|
35322
35375
|
const packageJsonPath = Path.join(directory, PACKAGE_JSON_FILENAME);
|
|
@@ -36024,6 +36077,17 @@ const checkPnpmHardening = (rootDirectory) => {
|
|
|
36024
36077
|
}));
|
|
36025
36078
|
return diagnostics;
|
|
36026
36079
|
};
|
|
36080
|
+
const buildReactNativeDiagnostic = (input) => ({
|
|
36081
|
+
filePath: input.filePath,
|
|
36082
|
+
plugin: "react-doctor",
|
|
36083
|
+
rule: input.rule,
|
|
36084
|
+
severity: input.severity ?? "warning",
|
|
36085
|
+
message: input.message,
|
|
36086
|
+
help: input.help,
|
|
36087
|
+
line: input.line ?? 0,
|
|
36088
|
+
column: input.column ?? 0,
|
|
36089
|
+
category: input.category ?? "Correctness"
|
|
36090
|
+
});
|
|
36027
36091
|
const BUILDER_BOB_PACKAGE = "react-native-builder-bob";
|
|
36028
36092
|
const isBuilderBobLibrary = (packageJson) => {
|
|
36029
36093
|
const bobConfig = packageJson[BUILDER_BOB_PACKAGE];
|
|
@@ -36035,17 +36099,12 @@ const checkReactNativeLibraryDependencies = (rootDirectory) => {
|
|
|
36035
36099
|
const misplaced = ["react", "react-native"].filter((name) => packageJson.dependencies?.[name] !== void 0);
|
|
36036
36100
|
if (misplaced.length === 0) return [];
|
|
36037
36101
|
const quoted = misplaced.map((name) => `"${name}"`).join(" and ");
|
|
36038
|
-
return [{
|
|
36102
|
+
return [buildReactNativeDiagnostic({
|
|
36039
36103
|
filePath: "package.json",
|
|
36040
|
-
plugin: "react-doctor",
|
|
36041
36104
|
rule: "rn-library-react-in-dependencies",
|
|
36042
|
-
severity: "warning",
|
|
36043
36105
|
message: `This react-native-builder-bob library lists ${quoted} in \`dependencies\` — that ships a second copy into consumer apps, causing "Invalid hook call" (duplicate React) and duplicate-native-module crashes.`,
|
|
36044
|
-
help: `Move ${quoted} to \`peerDependencies\` (keep ${misplaced.length === 1 ? "it" : "them"} in \`devDependencies\` for local development)
|
|
36045
|
-
|
|
36046
|
-
column: 0,
|
|
36047
|
-
category: "Correctness"
|
|
36048
|
-
}];
|
|
36106
|
+
help: `Move ${quoted} to \`peerDependencies\` (keep ${misplaced.length === 1 ? "it" : "them"} in \`devDependencies\` for local development).`
|
|
36107
|
+
})];
|
|
36049
36108
|
};
|
|
36050
36109
|
const BABEL_CONFIG_FILE_NAMES = [
|
|
36051
36110
|
"babel.config.js",
|
|
@@ -36057,6 +36116,8 @@ const BABEL_CONFIG_FILE_NAMES = [
|
|
|
36057
36116
|
".babelrc.json"
|
|
36058
36117
|
];
|
|
36059
36118
|
const LEGACY_PRESET_SPEC = "module:metro-react-native-babel-preset";
|
|
36119
|
+
const MODERN_PRESET_REFERENCE = new RegExp(`['"]module:@react-native/babel-preset['"]`);
|
|
36120
|
+
const ENABLE_BABEL_RUNTIME_VERSION = /enableBabelRuntime["']?\s*:\s*['"]/;
|
|
36060
36121
|
const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
36061
36122
|
for (const fileName of BABEL_CONFIG_FILE_NAMES) {
|
|
36062
36123
|
const filePath = Path.join(rootDirectory, fileName);
|
|
@@ -36067,18 +36128,20 @@ const checkReactNativeMetroBabelPreset = (rootDirectory) => {
|
|
|
36067
36128
|
} catch {
|
|
36068
36129
|
continue;
|
|
36069
36130
|
}
|
|
36070
|
-
if (
|
|
36071
|
-
return [{
|
|
36131
|
+
if (contents.includes(LEGACY_PRESET_SPEC)) return [buildReactNativeDiagnostic({
|
|
36072
36132
|
filePath: fileName,
|
|
36073
|
-
plugin: "react-doctor",
|
|
36074
36133
|
rule: "rn-no-metro-babel-preset",
|
|
36075
36134
|
severity: "error",
|
|
36076
36135
|
message: "`module:metro-react-native-babel-preset` was renamed to `@react-native/babel-preset` and is no longer installed by React Native 0.73+ — this preset reference fails to resolve and breaks the Metro/Babel transform.",
|
|
36077
|
-
help: "Replace the preset with `module:@react-native/babel-preset` (or `babel-preset-expo` on Expo) and remove the old `metro-react-native-babel-preset` dependency."
|
|
36078
|
-
|
|
36079
|
-
|
|
36080
|
-
|
|
36081
|
-
|
|
36136
|
+
help: "Replace the preset with `module:@react-native/babel-preset` (or `babel-preset-expo` on Expo) and remove the old `metro-react-native-babel-preset` dependency."
|
|
36137
|
+
})];
|
|
36138
|
+
if (MODERN_PRESET_REFERENCE.test(contents) && !ENABLE_BABEL_RUNTIME_VERSION.test(contents)) return [buildReactNativeDiagnostic({
|
|
36139
|
+
filePath: fileName,
|
|
36140
|
+
rule: "rn-no-metro-babel-runtime-version",
|
|
36141
|
+
severity: "warning",
|
|
36142
|
+
message: "`module:@react-native/babel-preset` has no `enableBabelRuntime` version, so Babel runtime helpers can be duplicated across files instead of imported once from @babel/runtime, increasing the JS bundle size.",
|
|
36143
|
+
help: "Set `enableBabelRuntime` to the @babel/runtime version from package.json, e.g. `['module:@react-native/babel-preset', { enableBabelRuntime: '^7.26.0' }]`."
|
|
36144
|
+
})];
|
|
36082
36145
|
}
|
|
36083
36146
|
return [];
|
|
36084
36147
|
};
|
|
@@ -38474,8 +38537,18 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
38474
38537
|
return bindingResolution !== null && !bindingResolution.isReactUseBinding;
|
|
38475
38538
|
};
|
|
38476
38539
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
38540
|
+
const LEADING_SEVERITY_LABEL_PATTERN = /^(?:Error|Warning):\s*/;
|
|
38541
|
+
const TRAILING_PERIOD_PATTERN = /\.$/;
|
|
38477
38542
|
const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
|
|
38478
|
-
const
|
|
38543
|
+
const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
|
|
38544
|
+
const REACT_COMPILER_IMPACT = "This component misses React Compiler's automatic memoization & re-renders more than it should";
|
|
38545
|
+
const REACT_COMPILER_ACTION = "Rewrite the flagged code so the compiler can optimize it.";
|
|
38546
|
+
const REACT_COMPILER_GENERIC_MESSAGE = `${REACT_COMPILER_IMPACT}. ${REACT_COMPILER_ACTION}`;
|
|
38547
|
+
const buildReactCompilerMessage = (reasonSummary) => {
|
|
38548
|
+
const normalizedSummary = reasonSummary.replace(TRAILING_PERIOD_PATTERN, "");
|
|
38549
|
+
if (!normalizedSummary) return REACT_COMPILER_GENERIC_MESSAGE;
|
|
38550
|
+
return `${REACT_COMPILER_IMPACT}: ${normalizedSummary}. ${REACT_COMPILER_ACTION}`;
|
|
38551
|
+
};
|
|
38479
38552
|
const PLUGIN_CATEGORY_MAP = {
|
|
38480
38553
|
react: "Bugs",
|
|
38481
38554
|
"react-hooks": "Bugs",
|
|
@@ -38502,7 +38575,10 @@ const getRuleRecommendation = (ruleName, project) => {
|
|
|
38502
38575
|
};
|
|
38503
38576
|
const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
|
|
38504
38577
|
const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
|
|
38505
|
-
const resolveDiagnosticTitle = (plugin, rule) =>
|
|
38578
|
+
const resolveDiagnosticTitle = (plugin, rule) => {
|
|
38579
|
+
if (plugin !== "react-hooks-js") return getRuleTitle(rule);
|
|
38580
|
+
return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
|
|
38581
|
+
};
|
|
38506
38582
|
const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
38507
38583
|
const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
|
|
38508
38584
|
return {
|
|
@@ -38511,10 +38587,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
|
38511
38587
|
};
|
|
38512
38588
|
};
|
|
38513
38589
|
const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
|
|
38514
|
-
if (plugin === "react-hooks-js")
|
|
38515
|
-
message
|
|
38516
|
-
|
|
38517
|
-
|
|
38590
|
+
if (plugin === "react-hooks-js") {
|
|
38591
|
+
const bailoutReason = message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim().replace(LEADING_SEVERITY_LABEL_PATTERN, "").trim();
|
|
38592
|
+
if (rule === "todo") return {
|
|
38593
|
+
message: REACT_COMPILER_GENERIC_MESSAGE,
|
|
38594
|
+
help: appendReanimatedSharedValueHint(bailoutReason || help, rule, project)
|
|
38595
|
+
};
|
|
38596
|
+
const [reasonSummary = "", ...reasonDetailLines] = bailoutReason.split("\n");
|
|
38597
|
+
const reasonDetail = reasonDetailLines.join("\n").trim();
|
|
38598
|
+
return {
|
|
38599
|
+
message: buildReactCompilerMessage(reasonSummary.trim()),
|
|
38600
|
+
help: appendReanimatedSharedValueHint(reasonDetail || help, rule, project)
|
|
38601
|
+
};
|
|
38602
|
+
}
|
|
38518
38603
|
return {
|
|
38519
38604
|
message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
|
|
38520
38605
|
help: help || getRuleRecommendation(rule, project) || ""
|
|
@@ -39181,7 +39266,7 @@ const ScoreApiResponseSchema = Struct({
|
|
|
39181
39266
|
})))
|
|
39182
39267
|
});
|
|
39183
39268
|
const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
|
|
39184
|
-
const
|
|
39269
|
+
const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
|
|
39185
39270
|
const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
39186
39271
|
const describeFailure = (error) => {
|
|
39187
39272
|
if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
|
|
@@ -39194,7 +39279,7 @@ const calculateScore = async (diagnostics, options = {}) => {
|
|
|
39194
39279
|
const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
|
|
39195
39280
|
try {
|
|
39196
39281
|
const compressedBody = gzipSync(JSON.stringify({
|
|
39197
|
-
diagnostics:
|
|
39282
|
+
diagnostics: stripLocalFileFields(diagnostics),
|
|
39198
39283
|
...options.metadata?.repo ? { repo: options.metadata.repo } : {},
|
|
39199
39284
|
...options.metadata?.sha ? { sha: options.metadata.sha } : {},
|
|
39200
39285
|
...options.metadata?.framework ? { framework: options.metadata.framework } : {},
|
|
@@ -39261,25 +39346,36 @@ const decodeArtifact = decodeUnknownOption(Struct({ score: optional(Struct({
|
|
|
39261
39346
|
const SCORE_AXES = [
|
|
39262
39347
|
{
|
|
39263
39348
|
key: "supplyChain",
|
|
39264
|
-
label: "supply chain"
|
|
39349
|
+
label: "supply chain",
|
|
39350
|
+
gates: true
|
|
39265
39351
|
},
|
|
39266
39352
|
{
|
|
39267
39353
|
key: "vulnerability",
|
|
39268
|
-
label: "vulnerability"
|
|
39354
|
+
label: "vulnerability",
|
|
39355
|
+
gates: true
|
|
39269
39356
|
},
|
|
39270
39357
|
{
|
|
39271
39358
|
key: "maintenance",
|
|
39272
|
-
label: "maintenance"
|
|
39359
|
+
label: "maintenance",
|
|
39360
|
+
gates: false
|
|
39273
39361
|
},
|
|
39274
39362
|
{
|
|
39275
39363
|
key: "quality",
|
|
39276
|
-
label: "quality"
|
|
39364
|
+
label: "quality",
|
|
39365
|
+
gates: false
|
|
39277
39366
|
},
|
|
39278
39367
|
{
|
|
39279
39368
|
key: "license",
|
|
39280
|
-
label: "license"
|
|
39369
|
+
label: "license",
|
|
39370
|
+
gates: false
|
|
39281
39371
|
}
|
|
39282
39372
|
];
|
|
39373
|
+
const GATED_AXES = SCORE_AXES.filter((axis) => axis.gates);
|
|
39374
|
+
const worstGatedAxis = (score) => {
|
|
39375
|
+
let worst = GATED_AXES[0];
|
|
39376
|
+
for (const axis of GATED_AXES) if (score[axis.key] < score[worst.key]) worst = axis;
|
|
39377
|
+
return worst;
|
|
39378
|
+
};
|
|
39283
39379
|
const clampScore = (value) => {
|
|
39284
39380
|
if (!Number.isFinite(value)) return 50;
|
|
39285
39381
|
return Math.min(Math.max(value, 0), 100);
|
|
@@ -39395,15 +39491,14 @@ const fetchSocketScore = (dependency) => tryPromise(async (signal) => {
|
|
|
39395
39491
|
"socket.purl": toPurl(dependency)
|
|
39396
39492
|
} }));
|
|
39397
39493
|
const formatAxisScores = (score) => SCORE_AXES.map((axis) => `${axis.label} ${toHundred(score[axis.key])}`).join(", ");
|
|
39398
|
-
const buildLowScoreDiagnostic = (dependency, score, options) => {
|
|
39399
|
-
const overall = toHundred(score.overall);
|
|
39494
|
+
const buildLowScoreDiagnostic = (dependency, score, failingAxis, options) => {
|
|
39400
39495
|
const packagePageUrl = `${SOCKET_PACKAGE_PAGE_BASE}/${dependency.name}/overview/${dependency.version}`;
|
|
39401
39496
|
return {
|
|
39402
39497
|
filePath: "package.json",
|
|
39403
39498
|
plugin: SUPPLY_CHAIN_PLUGIN,
|
|
39404
39499
|
rule: SUPPLY_CHAIN_RULE,
|
|
39405
39500
|
severity: options.severity,
|
|
39406
|
-
message: `\`${dependency.name}\` (declared in package.json as "${dependency.spec}", scored at ${dependency.version}) has a Socket
|
|
39501
|
+
message: `\`${dependency.name}\` (declared in package.json as "${dependency.spec}", scored at ${dependency.version}) has a Socket ${failingAxis.label} score of ${toHundred(score[failingAxis.key])}/100 (below the minimum of ${options.minScore}). Axis scores — ${formatAxisScores(score)}.`,
|
|
39407
39502
|
help: `Update or replace the \`"${dependency.name}": "${dependency.spec}"\` entry in package.json. Review ${dependency.name} on Socket: ${packagePageUrl}. Or raise \`supplyChain.minScore\` if you have vetted and accepted this package.`,
|
|
39408
39503
|
url: packagePageUrl,
|
|
39409
39504
|
line: dependency.line,
|
|
@@ -39415,7 +39510,9 @@ const buildLowScoreDiagnostic = (dependency, score, options) => {
|
|
|
39415
39510
|
* Scores every direct dependency in the project's `package.json` against
|
|
39416
39511
|
* Socket.dev's free PURL endpoint (the same one Socket Firewall's free tier
|
|
39417
39512
|
* uses — no API key) and returns a diagnostic for each dependency whose
|
|
39418
|
-
* Socket
|
|
39513
|
+
* worst Socket *security* axis — supply chain or vulnerability — is below
|
|
39514
|
+
* the configured `minScore`. The quality / maintenance / license axes are
|
|
39515
|
+
* reported as context but never gate (see GATED_AXES).
|
|
39419
39516
|
*
|
|
39420
39517
|
* Lookups run with bounded concurrency via `Effect.forEach`. The check is
|
|
39421
39518
|
* total/fail-open: each per-package lookup already recovers to `null`
|
|
@@ -39433,8 +39530,9 @@ const checkSupplyChain = (input) => gen(function* () {
|
|
|
39433
39530
|
for (let index = 0; index < dependencies.length; index += 1) {
|
|
39434
39531
|
const score = scores[index];
|
|
39435
39532
|
if (!score) continue;
|
|
39436
|
-
|
|
39437
|
-
|
|
39533
|
+
const worstAxis = worstGatedAxis(score);
|
|
39534
|
+
if (toHundred(score[worstAxis.key]) >= options.minScore) continue;
|
|
39535
|
+
diagnostics.push(buildLowScoreDiagnostic(dependencies[index], score, worstAxis, options));
|
|
39438
39536
|
}
|
|
39439
39537
|
return diagnostics;
|
|
39440
39538
|
});
|
|
@@ -39442,7 +39540,8 @@ const checkSupplyChain = (input) => gen(function* () {
|
|
|
39442
39540
|
* `SupplyChain` scores the project's direct dependencies against Socket.dev's
|
|
39443
39541
|
* free, keyless PURL endpoint — the same lookup Socket Firewall's free tier
|
|
39444
39542
|
* (`sfw`) performs — and streams a diagnostic for each dependency whose
|
|
39445
|
-
* Socket
|
|
39543
|
+
* worst Socket security axis (supply chain or vulnerability) falls below
|
|
39544
|
+
* the configured `supplyChain.minScore`.
|
|
39446
39545
|
*
|
|
39447
39546
|
* Runs by default (one network request per dependency); the orchestrator
|
|
39448
39547
|
* provides `layerOf([])` only when the user opts out via
|
|
@@ -40085,13 +40184,55 @@ const clearAutoSuppressionCaches = () => {};
|
|
|
40085
40184
|
* untouched so the loader sees the same plain object either way.
|
|
40086
40185
|
*/
|
|
40087
40186
|
const defineConfig = (config) => config;
|
|
40187
|
+
const unionValues = (baseValues, overrideValues) => [...new Set([...baseValues, ...overrideValues])];
|
|
40188
|
+
const mergeIgnores = (baseIgnore, overrideIgnore) => {
|
|
40189
|
+
const mergedIgnore = {
|
|
40190
|
+
...baseIgnore,
|
|
40191
|
+
...overrideIgnore
|
|
40192
|
+
};
|
|
40193
|
+
if (baseIgnore.rules && overrideIgnore.rules) mergedIgnore.rules = unionValues(baseIgnore.rules, overrideIgnore.rules);
|
|
40194
|
+
if (baseIgnore.files && overrideIgnore.files) mergedIgnore.files = unionValues(baseIgnore.files, overrideIgnore.files);
|
|
40195
|
+
if (baseIgnore.tags && overrideIgnore.tags) mergedIgnore.tags = unionValues(baseIgnore.tags, overrideIgnore.tags);
|
|
40196
|
+
if (baseIgnore.overrides && overrideIgnore.overrides) mergedIgnore.overrides = [...baseIgnore.overrides, ...overrideIgnore.overrides];
|
|
40197
|
+
return mergedIgnore;
|
|
40198
|
+
};
|
|
40199
|
+
/**
|
|
40200
|
+
* Layer one `ReactDoctorConfig` on top of another, additively: `rules` /
|
|
40201
|
+
* `categories` / `supplyChain` merge per key, `ignore` lists union
|
|
40202
|
+
* (`ignore.overrides` concatenate), and every other field is a scalar the
|
|
40203
|
+
* override simply wins on when set. Returns the base unchanged when there
|
|
40204
|
+
* is no override, and vice versa — so callers can thread `null` /
|
|
40205
|
+
* `undefined` through without special-casing.
|
|
40206
|
+
*/
|
|
40207
|
+
const mergeReactDoctorConfigs = (baseConfig, overrideConfig) => {
|
|
40208
|
+
if (overrideConfig === void 0) return baseConfig;
|
|
40209
|
+
if (baseConfig === null) return overrideConfig;
|
|
40210
|
+
const mergedConfig = {
|
|
40211
|
+
...baseConfig,
|
|
40212
|
+
...overrideConfig
|
|
40213
|
+
};
|
|
40214
|
+
if (baseConfig.rules && overrideConfig.rules) mergedConfig.rules = {
|
|
40215
|
+
...baseConfig.rules,
|
|
40216
|
+
...overrideConfig.rules
|
|
40217
|
+
};
|
|
40218
|
+
if (baseConfig.categories && overrideConfig.categories) mergedConfig.categories = {
|
|
40219
|
+
...baseConfig.categories,
|
|
40220
|
+
...overrideConfig.categories
|
|
40221
|
+
};
|
|
40222
|
+
if (baseConfig.supplyChain && overrideConfig.supplyChain) mergedConfig.supplyChain = {
|
|
40223
|
+
...baseConfig.supplyChain,
|
|
40224
|
+
...overrideConfig.supplyChain
|
|
40225
|
+
};
|
|
40226
|
+
if (baseConfig.ignore && overrideConfig.ignore) mergedConfig.ignore = mergeIgnores(baseConfig.ignore, overrideConfig.ignore);
|
|
40227
|
+
return mergedConfig;
|
|
40228
|
+
};
|
|
40088
40229
|
//#endregion
|
|
40089
40230
|
//#region ../api/dist/index.js
|
|
40090
|
-
const buildDiagnoseLayer = (config,
|
|
40091
|
-
const configLayer =
|
|
40231
|
+
const buildDiagnoseLayer = (config, configOverrideTarget) => {
|
|
40232
|
+
const configLayer = configOverrideTarget === void 0 ? Config.layerNode : Config.layerOf({
|
|
40092
40233
|
config,
|
|
40093
|
-
resolvedDirectory:
|
|
40094
|
-
configSourceDirectory:
|
|
40234
|
+
resolvedDirectory: configOverrideTarget.resolvedDirectory,
|
|
40235
|
+
configSourceDirectory: configOverrideTarget.configSourceDirectory
|
|
40095
40236
|
});
|
|
40096
40237
|
return mergeAll$1(Project.layerNode, configLayer, DeadCode.layerNode, Files.layerNode, Git.layerNode, Linter.layerOxlint, LintPartialFailures.layerLive, Progress.layerNoop, Reporter.layerNoop, Score.layerHttp, config?.supplyChain?.enabled !== false ? SupplyChain.layerNode : SupplyChain.layerOf([]));
|
|
40097
40238
|
};
|
|
@@ -40123,11 +40264,64 @@ const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
|
|
|
40123
40264
|
elapsedMilliseconds
|
|
40124
40265
|
};
|
|
40125
40266
|
};
|
|
40126
|
-
const
|
|
40267
|
+
const diagnoseDirectory = async (directory, options) => {
|
|
40127
40268
|
const startTime = globalThis.performance.now();
|
|
40128
40269
|
const scanTarget = await resolveScanTarget(directory);
|
|
40129
40270
|
return outputToDiagnoseResult(await runPromise(restoreLegacyThrow(buildInspectProgram(scanTarget, options).pipe(provide(buildDiagnoseLayer(scanTarget.userConfig)), provide(layerOtlp)))), globalThis.performance.now() - startTime);
|
|
40130
40271
|
};
|
|
40272
|
+
const findWorstScore = (projectResults) => {
|
|
40273
|
+
let worstResult = null;
|
|
40274
|
+
let worstScore = Number.POSITIVE_INFINITY;
|
|
40275
|
+
for (const projectResult of projectResults) {
|
|
40276
|
+
if (!projectResult.ok || projectResult.score === null) continue;
|
|
40277
|
+
if (projectResult.score.score < worstScore) {
|
|
40278
|
+
worstScore = projectResult.score.score;
|
|
40279
|
+
worstResult = projectResult.score;
|
|
40280
|
+
}
|
|
40281
|
+
}
|
|
40282
|
+
return worstResult;
|
|
40283
|
+
};
|
|
40284
|
+
const diagnoseProject = async (projectDefinition, baseOptions, batchConfig) => {
|
|
40285
|
+
const startTime = globalThis.performance.now();
|
|
40286
|
+
try {
|
|
40287
|
+
const scanTarget = await resolveScanTarget(projectDefinition.directory);
|
|
40288
|
+
const { directory: _, config: projectConfig, ...perProjectOptions } = projectDefinition;
|
|
40289
|
+
const didOverrideConfig = batchConfig !== void 0 || projectConfig !== void 0;
|
|
40290
|
+
const effectiveConfig = mergeReactDoctorConfigs(mergeReactDoctorConfigs(scanTarget.userConfig, batchConfig), projectConfig);
|
|
40291
|
+
const program = buildInspectProgram(scanTarget, {
|
|
40292
|
+
...baseOptions,
|
|
40293
|
+
...perProjectOptions
|
|
40294
|
+
}, effectiveConfig ?? void 0);
|
|
40295
|
+
const didOverridePlugins = batchConfig?.plugins !== void 0 || projectConfig?.plugins !== void 0;
|
|
40296
|
+
const layer = buildDiagnoseLayer(effectiveConfig, didOverrideConfig ? {
|
|
40297
|
+
resolvedDirectory: scanTarget.resolvedDirectory,
|
|
40298
|
+
configSourceDirectory: didOverridePlugins ? null : scanTarget.configSourceDirectory
|
|
40299
|
+
} : void 0);
|
|
40300
|
+
return {
|
|
40301
|
+
ok: true,
|
|
40302
|
+
...outputToDiagnoseResult(await runPromise(restoreLegacyThrow(program.pipe(provide(layer), provide(layerOtlp)))), globalThis.performance.now() - startTime),
|
|
40303
|
+
directory: scanTarget.resolvedDirectory
|
|
40304
|
+
};
|
|
40305
|
+
} catch (error) {
|
|
40306
|
+
return {
|
|
40307
|
+
ok: false,
|
|
40308
|
+
directory: projectDefinition.directory,
|
|
40309
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
40310
|
+
};
|
|
40311
|
+
}
|
|
40312
|
+
};
|
|
40313
|
+
const diagnoseProjectBatch = async (input) => {
|
|
40314
|
+
const startTime = globalThis.performance.now();
|
|
40315
|
+
const { projects, concurrency, config: batchConfig, ...baseOptions } = input;
|
|
40316
|
+
const projectResults = await mapWithConcurrency(projects, concurrency ?? 4, (projectDefinition) => diagnoseProject(projectDefinition, baseOptions, batchConfig));
|
|
40317
|
+
return {
|
|
40318
|
+
projects: projectResults,
|
|
40319
|
+
diagnostics: projectResults.flatMap((projectResult) => projectResult.ok ? projectResult.diagnostics : []),
|
|
40320
|
+
score: findWorstScore(projectResults),
|
|
40321
|
+
elapsedMilliseconds: globalThis.performance.now() - startTime
|
|
40322
|
+
};
|
|
40323
|
+
};
|
|
40324
|
+
const diagnose = (async (directoryOrInput, options = {}) => typeof directoryOrInput === "string" ? diagnoseDirectory(directoryOrInput, options) : diagnoseProjectBatch(directoryOrInput));
|
|
40131
40325
|
//#endregion
|
|
40132
40326
|
//#region src/index.ts
|
|
40133
40327
|
const clearCaches = () => {
|
|
@@ -40160,4 +40354,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
40160
40354
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
40161
40355
|
|
|
40162
40356
|
//# sourceMappingURL=index.js.map
|
|
40163
|
-
//# debugId=
|
|
40357
|
+
//# debugId=5c0d7930-333e-5d67-93cf-63eae9bd87f8
|