react-doctor 0.5.1-dev.fee3fc4 → 0.5.2-dev.022790b
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 +287 -102
- package/dist/index.d.ts +7 -0
- package/dist/index.js +249 -80
- package/dist/lsp.js +250 -81
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -9452,6 +9452,7 @@ interface DiagnosticRelatedLocation {
|
|
|
9452
9452
|
endColumn?: number;
|
|
9453
9453
|
message: string;
|
|
9454
9454
|
}
|
|
9455
|
+
type DiagnosticFileContext = "test" | "story" | "production";
|
|
9455
9456
|
interface Diagnostic {
|
|
9456
9457
|
filePath: string;
|
|
9457
9458
|
plugin: string;
|
|
@@ -9478,6 +9479,12 @@ interface Diagnostic {
|
|
|
9478
9479
|
/** 1-indexed end column of the primary span, when derivable. */
|
|
9479
9480
|
endColumn?: number;
|
|
9480
9481
|
category: string;
|
|
9482
|
+
/**
|
|
9483
|
+
* Set when the file never ships to users (`"test"` / `"story"`), so
|
|
9484
|
+
* renderers can label the site instead of implying production impact.
|
|
9485
|
+
* Omitted for production files (the default).
|
|
9486
|
+
*/
|
|
9487
|
+
fileContext?: Exclude<DiagnosticFileContext, "production">;
|
|
9481
9488
|
suppressionHint?: string;
|
|
9482
9489
|
/** Secondary source locations (oxlint's non-primary labels). */
|
|
9483
9490
|
relatedLocations?: DiagnosticRelatedLocation[];
|
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]="3f550091-4631-5201-b95e-820dcdff2adb")}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,9 +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
38543
|
const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
|
|
38479
|
-
const
|
|
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
|
+
};
|
|
38480
38552
|
const PLUGIN_CATEGORY_MAP = {
|
|
38481
38553
|
react: "Bugs",
|
|
38482
38554
|
"react-hooks": "Bugs",
|
|
@@ -38515,10 +38587,19 @@ const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
|
38515
38587
|
};
|
|
38516
38588
|
};
|
|
38517
38589
|
const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
|
|
38518
|
-
if (plugin === "react-hooks-js")
|
|
38519
|
-
message
|
|
38520
|
-
|
|
38521
|
-
|
|
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
|
+
}
|
|
38522
38603
|
return {
|
|
38523
38604
|
message: message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || message,
|
|
38524
38605
|
help: help || getRuleRecommendation(rule, project) || ""
|
|
@@ -39185,7 +39266,7 @@ const ScoreApiResponseSchema = Struct({
|
|
|
39185
39266
|
})))
|
|
39186
39267
|
});
|
|
39187
39268
|
const parseScoreResult = (value) => getOrNull(decodeUnknownOption(ScoreApiResponseSchema)(value));
|
|
39188
|
-
const
|
|
39269
|
+
const stripLocalFileFields = (diagnostics) => diagnostics.map(({ filePath: _filePath, fileContext: _fileContext, ...rest }) => rest);
|
|
39189
39270
|
const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
39190
39271
|
const describeFailure = (error) => {
|
|
39191
39272
|
if (isAbortError(error)) return `timed out after ${FETCH_TIMEOUT_MS / 1e3}s`;
|
|
@@ -39198,7 +39279,7 @@ const calculateScore = async (diagnostics, options = {}) => {
|
|
|
39198
39279
|
const requestUrl = options.isCi ? `${SCORE_API_URL}?ci=1` : SCORE_API_URL;
|
|
39199
39280
|
try {
|
|
39200
39281
|
const compressedBody = gzipSync(JSON.stringify({
|
|
39201
|
-
diagnostics:
|
|
39282
|
+
diagnostics: stripLocalFileFields(diagnostics),
|
|
39202
39283
|
...options.metadata?.repo ? { repo: options.metadata.repo } : {},
|
|
39203
39284
|
...options.metadata?.sha ? { sha: options.metadata.sha } : {},
|
|
39204
39285
|
...options.metadata?.framework ? { framework: options.metadata.framework } : {},
|
|
@@ -39254,42 +39335,74 @@ var Score = class Score extends Service()("react-doctor/Score") {
|
|
|
39254
39335
|
}) }));
|
|
39255
39336
|
static layerOf = (result) => succeed$3(Score, Score.of({ compute: () => succeed$2(result) }));
|
|
39256
39337
|
};
|
|
39257
|
-
const
|
|
39338
|
+
const isControlCharacter = (codePoint) => codePoint <= 31 || codePoint >= 127 && codePoint <= 159;
|
|
39339
|
+
const sanitizeTerminalText = (value) => {
|
|
39340
|
+
let sanitized = "";
|
|
39341
|
+
for (const character of value) {
|
|
39342
|
+
if (isControlCharacter(character.codePointAt(0) ?? 0)) continue;
|
|
39343
|
+
sanitized += character === "`" ? "'" : character;
|
|
39344
|
+
}
|
|
39345
|
+
return sanitized;
|
|
39346
|
+
};
|
|
39347
|
+
const SocketScoreSchema = Struct({
|
|
39258
39348
|
overall: Number$1,
|
|
39259
39349
|
license: Number$1,
|
|
39260
39350
|
maintenance: Number$1,
|
|
39261
39351
|
quality: Number$1,
|
|
39262
39352
|
supplyChain: Number$1,
|
|
39263
39353
|
vulnerability: Number$1
|
|
39264
|
-
})
|
|
39265
|
-
const
|
|
39266
|
-
|
|
39267
|
-
|
|
39268
|
-
|
|
39269
|
-
|
|
39270
|
-
|
|
39271
|
-
|
|
39272
|
-
|
|
39273
|
-
|
|
39274
|
-
|
|
39275
|
-
|
|
39354
|
+
});
|
|
39355
|
+
const SocketAlertSchema = Struct({
|
|
39356
|
+
type: String$1,
|
|
39357
|
+
severity: String$1,
|
|
39358
|
+
file: optional(NullOr(String$1)),
|
|
39359
|
+
props: optional(NullOr(Struct({ note: optional(NullOr(String$1)) })))
|
|
39360
|
+
});
|
|
39361
|
+
const SocketArtifactSchema = Struct({ score: optional(SocketScoreSchema) });
|
|
39362
|
+
const RawAlertsSchema = Struct({ alerts: optional(NullOr(ArraySchema(Unknown))) });
|
|
39363
|
+
const decodeArtifact = decodeUnknownOption(SocketArtifactSchema);
|
|
39364
|
+
const decodeRawAlerts = decodeUnknownOption(RawAlertsSchema);
|
|
39365
|
+
const decodeAlert = decodeUnknownOption(SocketAlertSchema);
|
|
39366
|
+
const extractAlerts = (parsed) => {
|
|
39367
|
+
const rawAlerts = getOrNull(decodeRawAlerts(parsed))?.alerts;
|
|
39368
|
+
if (!rawAlerts) return [];
|
|
39369
|
+
const alerts = [];
|
|
39370
|
+
for (const candidate of rawAlerts) {
|
|
39371
|
+
const alert = getOrNull(decodeAlert(candidate));
|
|
39372
|
+
if (alert !== null) alerts.push(alert);
|
|
39373
|
+
}
|
|
39374
|
+
return alerts;
|
|
39375
|
+
};
|
|
39376
|
+
const GATED_AXES = [{
|
|
39377
|
+
key: "supplyChain",
|
|
39378
|
+
label: "supply chain",
|
|
39379
|
+
guidance: {
|
|
39380
|
+
meaning: "risky install-time behavior — install scripts, obfuscated or native code, network/filesystem/shell access, or typosquatting",
|
|
39381
|
+
remediation: "Confirm this is the package you meant to install, and prefer a more established, audited alternative"
|
|
39382
|
+
}
|
|
39383
|
+
}, {
|
|
39384
|
+
key: "vulnerability",
|
|
39385
|
+
label: "vulnerability",
|
|
39386
|
+
guidance: {
|
|
39387
|
+
meaning: "known security vulnerabilities (CVEs) affecting this version",
|
|
39388
|
+
remediation: "Upgrade to a version with no known advisories (run `npm audit` to find one), or replace it"
|
|
39389
|
+
}
|
|
39390
|
+
}];
|
|
39391
|
+
const CONTEXT_AXES = [
|
|
39276
39392
|
{
|
|
39277
39393
|
key: "maintenance",
|
|
39278
|
-
label: "maintenance"
|
|
39279
|
-
gates: false
|
|
39394
|
+
label: "maintenance"
|
|
39280
39395
|
},
|
|
39281
39396
|
{
|
|
39282
39397
|
key: "quality",
|
|
39283
|
-
label: "quality"
|
|
39284
|
-
gates: false
|
|
39398
|
+
label: "quality"
|
|
39285
39399
|
},
|
|
39286
39400
|
{
|
|
39287
39401
|
key: "license",
|
|
39288
|
-
label: "license"
|
|
39289
|
-
gates: false
|
|
39402
|
+
label: "license"
|
|
39290
39403
|
}
|
|
39291
39404
|
];
|
|
39292
|
-
const
|
|
39405
|
+
const SCORE_AXES = [...GATED_AXES, ...CONTEXT_AXES];
|
|
39293
39406
|
const worstGatedAxis = (score) => {
|
|
39294
39407
|
let worst = GATED_AXES[0];
|
|
39295
39408
|
for (const axis of GATED_AXES) if (score[axis.key] < score[worst.key]) worst = axis;
|
|
@@ -39312,8 +39425,7 @@ const resolveConcreteVersion = (spec) => {
|
|
|
39312
39425
|
const trimmed = spec.trim();
|
|
39313
39426
|
if (trimmed.length === 0) return null;
|
|
39314
39427
|
if (trimmed.includes(":")) return null;
|
|
39315
|
-
|
|
39316
|
-
return match ? match[0] : null;
|
|
39428
|
+
return import_semver.minVersion(trimmed)?.version ?? null;
|
|
39317
39429
|
};
|
|
39318
39430
|
const locateDependencyKey = (packageJsonText, section, name) => {
|
|
39319
39431
|
const needle = `"${name}"`;
|
|
@@ -39372,7 +39484,7 @@ const readPackageJsonText = (packageJsonPath) => {
|
|
|
39372
39484
|
}
|
|
39373
39485
|
};
|
|
39374
39486
|
const toPurl = (dependency) => `pkg:npm/${dependency.name}@${dependency.version}`;
|
|
39375
|
-
const
|
|
39487
|
+
const parseArtifactFromBody = (body) => {
|
|
39376
39488
|
for (const line of body.split("\n")) {
|
|
39377
39489
|
if (line.trim().length === 0) continue;
|
|
39378
39490
|
let parsed;
|
|
@@ -39382,26 +39494,30 @@ const parseScoreFromBody = (body) => {
|
|
|
39382
39494
|
continue;
|
|
39383
39495
|
}
|
|
39384
39496
|
const artifact = getOrNull(decodeArtifact(parsed));
|
|
39385
|
-
if (artifact?.score) return
|
|
39497
|
+
if (artifact?.score) return {
|
|
39498
|
+
score: artifact.score,
|
|
39499
|
+
alerts: extractAlerts(parsed)
|
|
39500
|
+
};
|
|
39386
39501
|
}
|
|
39387
39502
|
return null;
|
|
39388
39503
|
};
|
|
39389
|
-
const
|
|
39504
|
+
const fetchSocketArtifact = (dependency) => tryPromise(async (signal) => {
|
|
39390
39505
|
const requestUrl = `${SOCKET_FREE_PURL_API_BASE}/${encodeURIComponent(toPurl(dependency))}`;
|
|
39391
39506
|
const response = await fetch(requestUrl, {
|
|
39392
39507
|
headers: { "User-Agent": SOCKET_FREE_USER_AGENT },
|
|
39393
39508
|
signal
|
|
39394
39509
|
});
|
|
39395
39510
|
if (!response.ok) return null;
|
|
39396
|
-
return
|
|
39397
|
-
}).pipe(timeout(FETCH_TIMEOUT_MS), orElseSucceed(() => null), tap$1((
|
|
39511
|
+
return parseArtifactFromBody(await response.text());
|
|
39512
|
+
}).pipe(timeout(FETCH_TIMEOUT_MS), orElseSucceed(() => null), tap$1((artifact) => {
|
|
39398
39513
|
const scoreAttributes = {};
|
|
39399
|
-
if (
|
|
39400
|
-
scoreAttributes["socket.score.overall"] = toHundred(score.overall);
|
|
39401
|
-
for (const axis of SCORE_AXES) scoreAttributes[`socket.score.${axis.key}`] = toHundred(score[axis.key]);
|
|
39514
|
+
if (artifact !== null) {
|
|
39515
|
+
scoreAttributes["socket.score.overall"] = toHundred(artifact.score.overall);
|
|
39516
|
+
for (const axis of SCORE_AXES) scoreAttributes[`socket.score.${axis.key}`] = toHundred(artifact.score[axis.key]);
|
|
39517
|
+
scoreAttributes["socket.alert.count"] = artifact.alerts.length;
|
|
39402
39518
|
}
|
|
39403
39519
|
return annotateCurrentSpan({
|
|
39404
|
-
"socket.scored":
|
|
39520
|
+
"socket.scored": artifact !== null,
|
|
39405
39521
|
...scoreAttributes
|
|
39406
39522
|
});
|
|
39407
39523
|
}), withSpan("SupplyChain.fetchScore", { attributes: {
|
|
@@ -39409,16 +39525,69 @@ const fetchSocketScore = (dependency) => tryPromise(async (signal) => {
|
|
|
39409
39525
|
"socket.version": dependency.version,
|
|
39410
39526
|
"socket.purl": toPurl(dependency)
|
|
39411
39527
|
} }));
|
|
39412
|
-
const
|
|
39413
|
-
const
|
|
39528
|
+
const formatOtherAxisScores = (score, failingKey) => SCORE_AXES.filter((axis) => axis.key !== failingKey).map((axis) => `${axis.label} ${toHundred(score[axis.key])}`).join(", ");
|
|
39529
|
+
const ALERT_SEVERITY_RANK = {
|
|
39530
|
+
critical: 4,
|
|
39531
|
+
high: 3,
|
|
39532
|
+
middle: 2,
|
|
39533
|
+
medium: 2,
|
|
39534
|
+
low: 1
|
|
39535
|
+
};
|
|
39536
|
+
const severityRank = (severity) => ALERT_SEVERITY_RANK[severity.toLowerCase()] ?? 0;
|
|
39537
|
+
const displaySeverity = (severity) => {
|
|
39538
|
+
const normalized = sanitizeTerminalText(severity.toLowerCase());
|
|
39539
|
+
return normalized === "middle" ? "medium" : normalized;
|
|
39540
|
+
};
|
|
39541
|
+
const ALERT_TYPE_LABELS = {
|
|
39542
|
+
malware: "known malware",
|
|
39543
|
+
gptMalware: "AI-detected malware",
|
|
39544
|
+
gptSecurity: "AI-detected security risk",
|
|
39545
|
+
gptAnomaly: "AI-detected code anomaly",
|
|
39546
|
+
envVars: "environment-variable access",
|
|
39547
|
+
usesEval: "use of eval",
|
|
39548
|
+
troll: "protestware",
|
|
39549
|
+
didYouMean: "possible typosquat",
|
|
39550
|
+
typosquat: "possible typosquat"
|
|
39551
|
+
};
|
|
39552
|
+
const humanizeAlertType = (type) => type.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
|
|
39553
|
+
const friendlyAlertType = (type) => ALERT_TYPE_LABELS[type] ?? sanitizeTerminalText(humanizeAlertType(type));
|
|
39554
|
+
const summarizeAlertNote = (note) => {
|
|
39555
|
+
const collapsed = sanitizeTerminalText(note.replace(/\s+/g, " ").trim());
|
|
39556
|
+
const firstSentence = collapsed.split(/(?<=\.)\s/)[0] || collapsed;
|
|
39557
|
+
if (firstSentence.length <= 160) return firstSentence.replace(/\.$/, "");
|
|
39558
|
+
return `${firstSentence.slice(0, 160).trimEnd()}…`;
|
|
39559
|
+
};
|
|
39560
|
+
const selectTopAlerts = (alerts) => [...alerts].sort((left, right) => severityRank(right.severity) - severityRank(left.severity)).slice(0, 3);
|
|
39561
|
+
const formatAlertReason = (topAlerts, totalCount) => {
|
|
39562
|
+
if (topAlerts.length === 1) {
|
|
39563
|
+
const [alert] = topAlerts;
|
|
39564
|
+
const location = alert.file ? ` in \`${sanitizeTerminalText(alert.file)}\`` : "";
|
|
39565
|
+
const note = alert.props?.note ? summarizeAlertNote(alert.props.note) : null;
|
|
39566
|
+
const detail = note ? `: "${note}"` : "";
|
|
39567
|
+
return `Socket flagged a ${displaySeverity(alert.severity)} ${friendlyAlertType(alert.type)} alert${location}${detail}.`;
|
|
39568
|
+
}
|
|
39569
|
+
return `Socket flagged ${totalCount} alerts (${topAlerts.map((alert) => friendlyAlertType(alert.type)).join(", ")}${totalCount > topAlerts.length ? ` (+${totalCount - topAlerts.length} more)` : ""}); most severe: ${displaySeverity(topAlerts[0].severity)}.`;
|
|
39570
|
+
};
|
|
39571
|
+
const formatDependencyIdentity = (dependency) => import_semver.valid(dependency.spec) !== null ? `${dependency.name}@${dependency.version}` : `${dependency.name}@${dependency.version} (lowest version "${dependency.spec}" allows)`;
|
|
39572
|
+
const buildSupplyChainHelp = (dependency, failingAxis, topAlerts, packagePageUrl, options) => {
|
|
39573
|
+
const hasCriticalAlert = topAlerts.some((alert) => alert.severity.toLowerCase() === "critical");
|
|
39574
|
+
const entry = `\`"${dependency.name}": "${dependency.spec}"\``;
|
|
39575
|
+
return `${hasCriticalAlert ? `Treat ${dependency.name} as compromised — do not ship it. Remove ${entry} from package.json and your lockfile, then audit anything it ran.` : `${failingAxis.guidance.remediation}; update ${entry} in package.json.`} Full report: ${packagePageUrl}. ${hasCriticalAlert ? `Only if you've confirmed this is a false positive, set \`supplyChain.enabled: false\`.` : `If you've reviewed and accepted this package, raise \`supplyChain.minScore\` (currently ${options.minScore}) or set \`supplyChain.severity: "warning"\`.`}`;
|
|
39576
|
+
};
|
|
39577
|
+
const buildLowScoreDiagnostic = (dependency, artifact, failingAxis, options) => {
|
|
39414
39578
|
const packagePageUrl = `${SOCKET_PACKAGE_PAGE_BASE}/${dependency.name}/overview/${dependency.version}`;
|
|
39579
|
+
const failingScore = toHundred(artifact.score[failingAxis.key]);
|
|
39580
|
+
const topAlerts = selectTopAlerts(artifact.alerts);
|
|
39581
|
+
const reason = topAlerts.length > 0 ? formatAlertReason(topAlerts, artifact.alerts.length) : `This points to ${failingAxis.guidance.meaning}.`;
|
|
39582
|
+
const headline = `\`${formatDependencyIdentity(dependency)}\` scored ${failingScore}/100 on Socket's ${failingAxis.label} axis (minimum ${options.minScore}).`;
|
|
39583
|
+
const otherAxes = `Other axes — ${formatOtherAxisScores(artifact.score, failingAxis.key)}.`;
|
|
39415
39584
|
return {
|
|
39416
39585
|
filePath: "package.json",
|
|
39417
39586
|
plugin: SUPPLY_CHAIN_PLUGIN,
|
|
39418
39587
|
rule: SUPPLY_CHAIN_RULE,
|
|
39419
39588
|
severity: options.severity,
|
|
39420
|
-
message:
|
|
39421
|
-
help:
|
|
39589
|
+
message: `${headline} ${reason} ${otherAxes}`,
|
|
39590
|
+
help: buildSupplyChainHelp(dependency, failingAxis, topAlerts, packagePageUrl, options),
|
|
39422
39591
|
url: packagePageUrl,
|
|
39423
39592
|
line: dependency.line,
|
|
39424
39593
|
column: dependency.column,
|
|
@@ -39444,14 +39613,14 @@ const checkSupplyChain = (input) => gen(function* () {
|
|
|
39444
39613
|
const packageJsonPath = Path.join(input.rootDirectory, "package.json");
|
|
39445
39614
|
const dependencies = collectDependenciesToScore(readPackageJson(packageJsonPath), readPackageJsonText(packageJsonPath), options.includeDevDependencies);
|
|
39446
39615
|
if (dependencies.length === 0) return [];
|
|
39447
|
-
const
|
|
39616
|
+
const artifacts = yield* forEach$1(dependencies, fetchSocketArtifact, { concurrency: 8 });
|
|
39448
39617
|
const diagnostics = [];
|
|
39449
39618
|
for (let index = 0; index < dependencies.length; index += 1) {
|
|
39450
|
-
const
|
|
39451
|
-
if (!
|
|
39452
|
-
const worstAxis = worstGatedAxis(score);
|
|
39453
|
-
if (toHundred(score[worstAxis.key]) >= options.minScore) continue;
|
|
39454
|
-
diagnostics.push(buildLowScoreDiagnostic(dependencies[index],
|
|
39619
|
+
const artifact = artifacts[index];
|
|
39620
|
+
if (!artifact) continue;
|
|
39621
|
+
const worstAxis = worstGatedAxis(artifact.score);
|
|
39622
|
+
if (toHundred(artifact.score[worstAxis.key]) >= options.minScore) continue;
|
|
39623
|
+
diagnostics.push(buildLowScoreDiagnostic(dependencies[index], artifact, worstAxis, options));
|
|
39455
39624
|
}
|
|
39456
39625
|
return diagnostics;
|
|
39457
39626
|
});
|
|
@@ -40273,4 +40442,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
40273
40442
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
40274
40443
|
|
|
40275
40444
|
//# sourceMappingURL=index.js.map
|
|
40276
|
-
//# debugId=
|
|
40445
|
+
//# debugId=3f550091-4631-5201-b95e-820dcdff2adb
|