dep-brain 1.0.0 → 1.0.1
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/CHANGELOG.md +8 -0
- package/dist/checks/risk.js +13 -2
- package/dist/checks/unused.js +38 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 1.0.1
|
|
6
|
+
|
|
7
|
+
- Reduced NestJS unused false positives for implicit runtime packages such as `@nestjs/platform-express` and `reflect-metadata`.
|
|
8
|
+
- Added script binary inference for common tooling packages used through `nest`, `eslint`, `jest`, `ts-node`, and related commands.
|
|
9
|
+
- Reduced risk-report noise by suppressing high-trust findings and medium-trust dev dependency findings.
|
|
10
|
+
- Stopped treating "no releases published in the last 30 days" as a standalone risk signal.
|
|
11
|
+
- Added regression tests for NestJS/tooling unused detection and weak risk-signal suppression.
|
|
12
|
+
|
|
5
13
|
## 1.0.0
|
|
6
14
|
|
|
7
15
|
- Stable v1 CLI and library release for explainable dependency intelligence.
|
package/dist/checks/risk.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function findRiskDependencies(graph, options = {}) {
|
|
|
18
18
|
? "devDependencies"
|
|
19
19
|
: "unknown";
|
|
20
20
|
const assessment = assessRisk(metadata, dependencyType);
|
|
21
|
-
if (assessment.
|
|
21
|
+
if (!shouldReportRisk(assessment.trustScore, dependencyType)) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
return {
|
|
@@ -105,7 +105,9 @@ function assessRisk(metadata, dependencyType) {
|
|
|
105
105
|
reasonCodes.push("single_maintainer");
|
|
106
106
|
weight += 2;
|
|
107
107
|
}
|
|
108
|
-
if (
|
|
108
|
+
if (reasons.length > 0 &&
|
|
109
|
+
metadata.recentReleaseCount !== null &&
|
|
110
|
+
metadata.recentReleaseCount === 0) {
|
|
109
111
|
reasons.push("No releases published in the last 30 days");
|
|
110
112
|
reasonCodes.push("no_recent_release");
|
|
111
113
|
weight += 1;
|
|
@@ -133,6 +135,15 @@ function assessRisk(metadata, dependencyType) {
|
|
|
133
135
|
}
|
|
134
136
|
};
|
|
135
137
|
}
|
|
138
|
+
function shouldReportRisk(trustScore, dependencyType) {
|
|
139
|
+
if (trustScore === "high") {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (dependencyType === "devDependencies" && trustScore !== "low") {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
136
147
|
function buildRiskRecommendation(reasons, confidence, trustScore) {
|
|
137
148
|
return {
|
|
138
149
|
action: "review",
|
package/dist/checks/unused.js
CHANGED
|
@@ -3,6 +3,22 @@ const SOURCE_FILE_PATTERN = /\.(c|m)?(t|j)sx?$/;
|
|
|
3
3
|
const CONFIG_FILE_PATTERN = /(^|[\\/])(vite|vitest|jest|eslint|prettier|rollup|webpack|babel|tsup|eslint\.config|commitlint|playwright|storybook|tailwind|postcss)\.config\.(c|m)?(t|j)s$/;
|
|
4
4
|
const TEST_FILE_PATTERN = /(^|[\\/])(__tests__|test|tests|spec|specs)([\\/]|$)|\.(test|spec)\.(c|m)?(t|j)sx?$/;
|
|
5
5
|
const RUNTIME_DIR_PATTERN = /(^|[\\/])(src|app|lib|server|client|pages|components)([\\/]|$)/;
|
|
6
|
+
const SCRIPT_BINARY_PACKAGE_MAP = {
|
|
7
|
+
eslint: [
|
|
8
|
+
"eslint",
|
|
9
|
+
"@typescript-eslint/eslint-plugin",
|
|
10
|
+
"@typescript-eslint/parser",
|
|
11
|
+
"eslint-config-prettier",
|
|
12
|
+
"eslint-plugin-prettier"
|
|
13
|
+
],
|
|
14
|
+
jest: ["jest", "ts-jest"],
|
|
15
|
+
nest: ["@nestjs/cli", "@nestjs/schematics"],
|
|
16
|
+
prettier: ["prettier"],
|
|
17
|
+
ts_jest: ["ts-jest"],
|
|
18
|
+
ts_loader: ["ts-loader"],
|
|
19
|
+
ts_node: ["ts-node", "tsconfig-paths"],
|
|
20
|
+
webpack: ["webpack", "ts-loader"]
|
|
21
|
+
};
|
|
6
22
|
export async function findUnusedDependencies(rootDir, graph, fileEntries, options) {
|
|
7
23
|
const projectFiles = fileEntries
|
|
8
24
|
.map((entry) => entry.path)
|
|
@@ -26,6 +42,9 @@ export async function findUnusedDependencies(rootDir, graph, fileEntries, option
|
|
|
26
42
|
}
|
|
27
43
|
for (const referencedBinary of extractScriptReferences(graph.scripts)) {
|
|
28
44
|
devUsed.add(referencedBinary);
|
|
45
|
+
for (const packageName of inferPackagesFromScriptReference(referencedBinary)) {
|
|
46
|
+
devUsed.add(packageName);
|
|
47
|
+
}
|
|
29
48
|
}
|
|
30
49
|
const hasTypeScriptSources = projectFiles.some((filePath) => /\.(c|m)?tsx?$/.test(filePath));
|
|
31
50
|
if (options.hasTypeScriptConfig) {
|
|
@@ -33,6 +52,7 @@ export async function findUnusedDependencies(rootDir, graph, fileEntries, option
|
|
|
33
52
|
}
|
|
34
53
|
const unusedDependencies = Object.keys(graph.dependencies)
|
|
35
54
|
.filter((name) => !runtimeUsed.has(name))
|
|
55
|
+
.filter((name) => !isImplicitlyUsedRuntimeDependency(name, graph, runtimeUsed))
|
|
36
56
|
.map((name) => buildUnusedDependency(name, "dependencies"));
|
|
37
57
|
const unusedDevDependencies = Object.keys(graph.devDependencies)
|
|
38
58
|
.filter((name) => !devUsed.has(name) && !runtimeUsed.has(name))
|
|
@@ -121,6 +141,24 @@ function normalizeScriptToken(token) {
|
|
|
121
141
|
}
|
|
122
142
|
return token.replace(/\.cmd$/i, "");
|
|
123
143
|
}
|
|
144
|
+
function inferPackagesFromScriptReference(reference) {
|
|
145
|
+
const normalized = reference.replace(/[-/]/g, "_");
|
|
146
|
+
return SCRIPT_BINARY_PACKAGE_MAP[normalized] ?? [];
|
|
147
|
+
}
|
|
148
|
+
function isImplicitlyUsedRuntimeDependency(name, graph, runtimeUsed) {
|
|
149
|
+
if (name === "@nestjs/platform-express" &&
|
|
150
|
+
(runtimeUsed.has("@nestjs/core") || Boolean(graph.dependencies["@nestjs/core"]))) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (name === "reflect-metadata" &&
|
|
154
|
+
(hasNestDependency(graph.dependencies) || hasNestDependency(graph.devDependencies))) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
function hasNestDependency(dependencies) {
|
|
160
|
+
return Object.keys(dependencies).some((dependency) => dependency.startsWith("@nestjs/"));
|
|
161
|
+
}
|
|
124
162
|
function isImplicitlyUsedDevDependency(name, hasTypeScriptSources, hasTypeScriptConfig) {
|
|
125
163
|
if (name === "typescript" && (hasTypeScriptSources || hasTypeScriptConfig)) {
|
|
126
164
|
return true;
|