dependency-detective 0.2.0 → 0.4.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/README.md +224 -172
- package/index.js +31 -26
- package/package.json +15 -9
- package/src/alternative-suggester.js +24 -56
- package/src/analyzer.js +221 -120
- package/src/ast-parser.js +85 -79
- package/src/config-scanner.js +128 -65
- package/src/script-scanner.js +77 -0
- package/src/security-checker.js +56 -45
- package/src/unused-detector.js +69 -49
- package/src/util/concurrency.js +15 -0
- package/.claude/worktrees/amazing-bartik-b7ca06/.claude/settings.local.json +0 -19
- package/.claude/worktrees/amazing-bartik-b7ca06/LICENSE +0 -21
- package/.claude/worktrees/amazing-bartik-b7ca06/README.md +0 -151
- package/.claude/worktrees/amazing-bartik-b7ca06/docs/superpowers/specs/2026-05-09-correctness-fixes-design.md +0 -118
- package/.claude/worktrees/amazing-bartik-b7ca06/index.js +0 -19
- package/.claude/worktrees/amazing-bartik-b7ca06/package-lock.json +0 -915
- package/.claude/worktrees/amazing-bartik-b7ca06/package.json +0 -36
- package/.claude/worktrees/amazing-bartik-b7ca06/src/alternative-suggester.js +0 -64
- package/.claude/worktrees/amazing-bartik-b7ca06/src/analyzer.js +0 -141
- package/.claude/worktrees/amazing-bartik-b7ca06/src/security-checker.js +0 -62
- package/.claude/worktrees/amazing-bartik-b7ca06/src/unused-detector.js +0 -71
package/src/config-scanner.js
CHANGED
|
@@ -1,65 +1,128 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const CONFIG_FILES = [
|
|
5
|
-
'tailwind.config.js',
|
|
6
|
-
'tailwind.config.ts',
|
|
7
|
-
'postcss.config.js',
|
|
8
|
-
'postcss.config.cjs',
|
|
9
|
-
'babel.config.js',
|
|
10
|
-
'babel.config.json',
|
|
11
|
-
'jest.config.js',
|
|
12
|
-
'jest.config.ts',
|
|
13
|
-
'vite.config.js',
|
|
14
|
-
'vite.config.ts',
|
|
15
|
-
'webpack.config.js',
|
|
16
|
-
'webpack.config.cjs',
|
|
17
|
-
'prettier.config.js',
|
|
18
|
-
|
|
19
|
-
'.
|
|
20
|
-
'.
|
|
21
|
-
'.
|
|
22
|
-
'.
|
|
23
|
-
'.
|
|
24
|
-
'
|
|
25
|
-
|
|
26
|
-
'
|
|
27
|
-
'.
|
|
28
|
-
'.
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const CONFIG_FILES = [
|
|
5
|
+
'tailwind.config.js',
|
|
6
|
+
'tailwind.config.ts',
|
|
7
|
+
'postcss.config.js',
|
|
8
|
+
'postcss.config.cjs',
|
|
9
|
+
'babel.config.js',
|
|
10
|
+
'babel.config.json',
|
|
11
|
+
'jest.config.js',
|
|
12
|
+
'jest.config.ts',
|
|
13
|
+
'vite.config.js',
|
|
14
|
+
'vite.config.ts',
|
|
15
|
+
'webpack.config.js',
|
|
16
|
+
'webpack.config.cjs',
|
|
17
|
+
'prettier.config.js',
|
|
18
|
+
// ESLint flat config (default since ESLint 9)
|
|
19
|
+
'eslint.config.js',
|
|
20
|
+
'eslint.config.mjs',
|
|
21
|
+
'eslint.config.cjs',
|
|
22
|
+
'eslint.config.ts',
|
|
23
|
+
'eslint.config.mts',
|
|
24
|
+
'eslint.config.cts',
|
|
25
|
+
// ESLint legacy config
|
|
26
|
+
'.eslintrc',
|
|
27
|
+
'.eslintrc.js',
|
|
28
|
+
'.eslintrc.cjs',
|
|
29
|
+
'.eslintrc.json',
|
|
30
|
+
'.eslintrc.yaml',
|
|
31
|
+
'.eslintrc.yml',
|
|
32
|
+
'.babelrc',
|
|
33
|
+
'.babelrc.json',
|
|
34
|
+
'vitest.config.js',
|
|
35
|
+
'vitest.config.ts',
|
|
36
|
+
'tsconfig.json',
|
|
37
|
+
'.stylelintrc',
|
|
38
|
+
'.stylelintrc.json',
|
|
39
|
+
'svelte.config.js',
|
|
40
|
+
'astro.config.mjs',
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
function escapeRegex(str) {
|
|
44
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isReferenced(content, depName) {
|
|
48
|
+
const pattern = new RegExp(`['"\`]${escapeRegex(depName)}['"\`/]`);
|
|
49
|
+
return pattern.test(content);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Legacy ESLint configs can name plugins and shareable configs by short name
|
|
53
|
+
// ("react" for eslint-plugin-react), and YAML configs leave names unquoted.
|
|
54
|
+
const ESLINT_LEGACY_FILES = new Set([
|
|
55
|
+
'.eslintrc',
|
|
56
|
+
'.eslintrc.js',
|
|
57
|
+
'.eslintrc.cjs',
|
|
58
|
+
'.eslintrc.json',
|
|
59
|
+
'.eslintrc.yaml',
|
|
60
|
+
'.eslintrc.yml',
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The short names ESLint accepts for a plugin or shareable-config package:
|
|
65
|
+
* eslint-plugin-react → react
|
|
66
|
+
* eslint-config-airbnb → airbnb
|
|
67
|
+
* @typescript-eslint/eslint-plugin → @typescript-eslint
|
|
68
|
+
* @scope/eslint-plugin-foo → @scope/foo
|
|
69
|
+
*/
|
|
70
|
+
export function eslintShortNames(depName) {
|
|
71
|
+
const unscoped = depName.match(/^eslint-(?:plugin|config)-(.+)$/);
|
|
72
|
+
if (unscoped) return [unscoped[1]];
|
|
73
|
+
|
|
74
|
+
const scoped = depName.match(/^(@[^/]+)\/eslint-(?:plugin|config)(?:-(.+))?$/);
|
|
75
|
+
if (scoped) return [scoped[2] ? `${scoped[1]}/${scoped[2]}` : scoped[1]];
|
|
76
|
+
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether a legacy ESLint config refers to depName, by full or short name,
|
|
82
|
+
* quoted or not. Matches `react`, `plugin:react/recommended` and rule keys
|
|
83
|
+
* like `react/jsx-key`, but not `react-hooks`.
|
|
84
|
+
*/
|
|
85
|
+
export function isEslintReference(content, depName) {
|
|
86
|
+
const names = [depName, ...eslintShortNames(depName)];
|
|
87
|
+
if (names.length === 1) return false;
|
|
88
|
+
return names.some((name) =>
|
|
89
|
+
new RegExp(`(?:^|[\\s'"\`\\[,:])${escapeRegex(name)}(?:$|[\\s'"\`\\],/])`, 'm').test(content)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function scanConfigFiles(directory, dependencyNames, packageJson = {}) {
|
|
94
|
+
if (!Array.isArray(dependencyNames) && !dependencyNames?.[Symbol.iterator]) {
|
|
95
|
+
return new Set();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const referenced = new Set();
|
|
99
|
+
|
|
100
|
+
const check = (content, eslintLegacy) => {
|
|
101
|
+
for (const depName of dependencyNames) {
|
|
102
|
+
if (
|
|
103
|
+
isReferenced(content, depName) ||
|
|
104
|
+
(eslintLegacy && isEslintReference(content, depName))
|
|
105
|
+
) {
|
|
106
|
+
referenced.add(depName);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
await Promise.all(
|
|
112
|
+
CONFIG_FILES.map(async (configFile) => {
|
|
113
|
+
let content;
|
|
114
|
+
try {
|
|
115
|
+
content = await fs.promises.readFile(path.join(directory, configFile), 'utf8');
|
|
116
|
+
} catch {
|
|
117
|
+
return; // file missing or unreadable — skip
|
|
118
|
+
}
|
|
119
|
+
check(content, ESLINT_LEGACY_FILES.has(configFile));
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (packageJson?.eslintConfig) {
|
|
124
|
+
check(JSON.stringify(packageJson.eslintConfig), true);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return referenced;
|
|
128
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// Used when a package isn't installed, so its `bin` field can't be read.
|
|
5
|
+
// Only packages whose command differs from their package name are listed.
|
|
6
|
+
const KNOWN_COMMANDS = {
|
|
7
|
+
typescript: ['tsc', 'tsserver'],
|
|
8
|
+
'npm-run-all': ['npm-run-all', 'run-s', 'run-p'],
|
|
9
|
+
'npm-run-all2': ['npm-run-all', 'run-s', 'run-p'],
|
|
10
|
+
'@angular/cli': ['ng'],
|
|
11
|
+
'@nestjs/cli': ['nest'],
|
|
12
|
+
'@biomejs/biome': ['biome'],
|
|
13
|
+
'@playwright/test': ['playwright'],
|
|
14
|
+
'@changesets/cli': ['changeset'],
|
|
15
|
+
'@11ty/eleventy': ['eleventy'],
|
|
16
|
+
'@sveltejs/kit': ['svelte-kit'],
|
|
17
|
+
'@tauri-apps/cli': ['tauri'],
|
|
18
|
+
'@vue/cli-service': ['vue-cli-service'],
|
|
19
|
+
'@storybook/cli': ['storybook', 'sb'],
|
|
20
|
+
'@graphql-codegen/cli': ['graphql-codegen', 'gql-gen'],
|
|
21
|
+
'ts-node': ['ts-node', 'ts-node-esm'],
|
|
22
|
+
'webpack-cli': ['webpack-cli', 'webpack'],
|
|
23
|
+
'http-server': ['http-server', 'hs'],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function escapeRegex(str) {
|
|
27
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The command names a dependency can be invoked by in npm scripts: its own
|
|
32
|
+
* name plus every key of its `bin` field (read from node_modules). A string
|
|
33
|
+
* `bin` installs a command named after the package, minus any scope.
|
|
34
|
+
*/
|
|
35
|
+
export function commandNames(directory, depName) {
|
|
36
|
+
const names = new Set([depName]);
|
|
37
|
+
|
|
38
|
+
let bin;
|
|
39
|
+
try {
|
|
40
|
+
const pkgPath = path.join(directory, 'node_modules', depName, 'package.json');
|
|
41
|
+
bin = JSON.parse(fs.readFileSync(pkgPath, 'utf8')).bin;
|
|
42
|
+
} catch {
|
|
43
|
+
for (const cmd of KNOWN_COMMANDS[depName] ?? []) names.add(cmd);
|
|
44
|
+
return [...names];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof bin === 'string') {
|
|
48
|
+
names.add(depName.startsWith('@') ? depName.split('/')[1] : depName);
|
|
49
|
+
} else if (bin && typeof bin === 'object') {
|
|
50
|
+
for (const cmd of Object.keys(bin)) names.add(cmd);
|
|
51
|
+
}
|
|
52
|
+
return [...names];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether any script invokes `command` as a whole word: at the start, after
|
|
57
|
+
* whitespace, a quote, `&&`/`||`/`;`/`(`, or a path such as node_modules/.bin/.
|
|
58
|
+
*/
|
|
59
|
+
export function scriptsUse(scripts, command) {
|
|
60
|
+
const pattern = new RegExp(
|
|
61
|
+
`(?:^|[\\s'"/(;&|])${escapeRegex(command)}(?:$|[\\s'"/);&|])`
|
|
62
|
+
);
|
|
63
|
+
return scripts.some((script) => pattern.test(script));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function findScriptReferences(directory, dependencyNames, scriptsObject = {}) {
|
|
67
|
+
const scripts = Object.values(scriptsObject);
|
|
68
|
+
const referenced = new Set();
|
|
69
|
+
if (scripts.length === 0) return referenced;
|
|
70
|
+
|
|
71
|
+
for (const dep of dependencyNames) {
|
|
72
|
+
if (commandNames(directory, dep).some((cmd) => scriptsUse(scripts, cmd))) {
|
|
73
|
+
referenced.add(dep);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return referenced;
|
|
77
|
+
}
|
package/src/security-checker.js
CHANGED
|
@@ -1,58 +1,69 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { mapWithConcurrency } from './util/concurrency.js';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const vulnerabilities = {};
|
|
6
|
+
const OSV_ENDPOINT = 'https://api.osv.dev/v1/query';
|
|
7
|
+
const CONCURRENCY = 8;
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
function fixedVersions(vuln, packageName) {
|
|
10
|
+
const fixed = new Set();
|
|
11
|
+
for (const affected of vuln.affected ?? []) {
|
|
12
|
+
if (affected.package?.name !== packageName) continue;
|
|
13
|
+
for (const range of affected.ranges ?? []) {
|
|
14
|
+
for (const event of range.events ?? []) {
|
|
15
|
+
if (event.fixed) fixed.add(event.fixed);
|
|
15
16
|
}
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.error(
|
|
18
|
-
`Failed to check vulnerabilities for ${depName}: ${error.message}`
|
|
19
|
-
);
|
|
20
17
|
}
|
|
21
18
|
}
|
|
19
|
+
return fixed.size > 0 ? [...fixed].join(', ') : null;
|
|
20
|
+
}
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
export function mapOsvVulns(vulns = [], packageName) {
|
|
23
|
+
return vulns.map((v) => ({
|
|
24
|
+
id: v.id ?? null,
|
|
25
|
+
severity: v.database_specific?.severity ?? 'UNKNOWN',
|
|
26
|
+
title: v.summary ?? v.id ?? 'Unknown vulnerability',
|
|
27
|
+
fixedIn: fixedVersions(v, packageName),
|
|
28
|
+
url: v.id ? `https://osv.dev/vulnerability/${v.id}` : null,
|
|
29
|
+
}));
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
export function resolveInstalledVersion(directory, dep) {
|
|
27
33
|
try {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
);
|
|
34
|
+
const pkgPath = path.join(directory, 'node_modules', dep, 'package.json');
|
|
35
|
+
return JSON.parse(fs.readFileSync(pkgPath, 'utf8')).version || null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
export async function checkVulnerabilities(dependencies, directory) {
|
|
42
|
+
const deps = Object.keys(dependencies);
|
|
43
|
+
const vulnerabilities = {};
|
|
44
|
+
const skipped = [];
|
|
45
|
+
let attempted = 0;
|
|
46
|
+
let errored = 0;
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (error.response && error.response.status === 401) {
|
|
46
|
-
console.error(
|
|
47
|
-
`Failed to authenticate with Snyk API. Please check your SNYK_API_TOKEN.`
|
|
48
|
-
);
|
|
49
|
-
} else if (error.response && error.response.status === 404) {
|
|
50
|
-
console.error(`Package ${packageName} not found in Snyk database.`);
|
|
51
|
-
} else {
|
|
52
|
-
console.error(
|
|
53
|
-
`Failed to fetch vulnerabilities for ${packageName}: ${error.message}`
|
|
54
|
-
);
|
|
48
|
+
await mapWithConcurrency(deps, CONCURRENCY, async (dep) => {
|
|
49
|
+
const version = resolveInstalledVersion(directory, dep);
|
|
50
|
+
if (!version) {
|
|
51
|
+
skipped.push(dep);
|
|
52
|
+
return;
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
attempted++;
|
|
55
|
+
try {
|
|
56
|
+
const res = await axios.post(OSV_ENDPOINT, {
|
|
57
|
+
version,
|
|
58
|
+
package: { name: dep, ecosystem: 'npm' },
|
|
59
|
+
});
|
|
60
|
+
const issues = mapOsvVulns(res.data?.vulns, dep);
|
|
61
|
+
if (issues.length > 0) vulnerabilities[dep] = issues;
|
|
62
|
+
} catch {
|
|
63
|
+
errored++;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const failed = attempted > 0 && errored === attempted;
|
|
68
|
+
return { vulnerabilities, skipped, failed };
|
|
58
69
|
}
|
package/src/unused-detector.js
CHANGED
|
@@ -1,49 +1,69 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { glob } from 'glob';
|
|
3
|
+
import { parseFileImports } from './ast-parser.js';
|
|
4
|
+
import { scanConfigFiles } from './config-scanner.js';
|
|
5
|
+
import { findScriptReferences } from './script-scanner.js';
|
|
6
|
+
|
|
7
|
+
export function resolveTypesUsage(referenced, deps) {
|
|
8
|
+
const used = new Set();
|
|
9
|
+
for (const dep of deps) {
|
|
10
|
+
if (!dep.startsWith('@types/')) continue;
|
|
11
|
+
if (dep === '@types/node') {
|
|
12
|
+
used.add(dep);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const base = dep.slice('@types/'.length);
|
|
16
|
+
// @types encodes scoped packages as `scope__name` → `@scope/name`
|
|
17
|
+
const baseName = base.includes('__') ? '@' + base.replace('__', '/') : base;
|
|
18
|
+
if (referenced.has(baseName)) used.add(dep);
|
|
19
|
+
}
|
|
20
|
+
return used;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function findUnusedDependencies(directory, dependencies, packageJson) {
|
|
24
|
+
const allDeps = Object.keys(dependencies);
|
|
25
|
+
const warnings = [];
|
|
26
|
+
|
|
27
|
+
const files = await glob('**/*.{js,jsx,ts,tsx,mjs,cjs}', {
|
|
28
|
+
cwd: directory,
|
|
29
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/build/**'],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const parsed = await Promise.all(
|
|
33
|
+
files.map((file) => parseFileImports(path.join(directory, file)))
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const allDepsSet = new Set(allDeps);
|
|
37
|
+
const referenced = new Set();
|
|
38
|
+
const allReferenced = new Set();
|
|
39
|
+
for (const { referenced: fileRefs, warnings: fileWarnings } of parsed) {
|
|
40
|
+
for (const pkg of fileRefs) {
|
|
41
|
+
allReferenced.add(pkg);
|
|
42
|
+
if (allDepsSet.has(pkg)) referenced.add(pkg);
|
|
43
|
+
}
|
|
44
|
+
warnings.push(...fileWarnings);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const configReferenced = await scanConfigFiles(directory, allDeps, packageJson);
|
|
48
|
+
for (const pkg of configReferenced) referenced.add(pkg);
|
|
49
|
+
|
|
50
|
+
const scriptReferenced = findScriptReferences(directory, allDeps, packageJson.scripts);
|
|
51
|
+
for (const pkg of scriptReferenced) referenced.add(pkg);
|
|
52
|
+
|
|
53
|
+
// @types/* resolution: use the full referenced set (all imports, not only deps)
|
|
54
|
+
const typesUsed = resolveTypesUsage(allReferenced, allDeps);
|
|
55
|
+
for (const dep of typesUsed) referenced.add(dep);
|
|
56
|
+
|
|
57
|
+
const unusedDeps = [];
|
|
58
|
+
for (const dep of allDeps) {
|
|
59
|
+
if (!referenced.has(dep)) {
|
|
60
|
+
unusedDeps.push({
|
|
61
|
+
name: dep,
|
|
62
|
+
version: dependencies[dep],
|
|
63
|
+
reason: 'Not imported in any source or config file',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { unusedDeps, warnings };
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export async function mapWithConcurrency(items, limit, fn) {
|
|
2
|
+
const results = new Array(items.length);
|
|
3
|
+
let index = 0;
|
|
4
|
+
|
|
5
|
+
async function worker() {
|
|
6
|
+
while (index < items.length) {
|
|
7
|
+
const current = index++;
|
|
8
|
+
results[current] = await fn(items[current], current);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const workerCount = Math.min(limit, items.length);
|
|
13
|
+
await Promise.all(Array.from({ length: workerCount }, () => worker()));
|
|
14
|
+
return results;
|
|
15
|
+
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Read(//c/Users/Marvin Kudjo/dependency-detective/**)",
|
|
5
|
-
"Bash(node index.js --no-suggestions)",
|
|
6
|
-
"Bash(node index.js --help)",
|
|
7
|
-
"Bash(node index.js --ignore axios,chalk --no-suggestions)",
|
|
8
|
-
"Bash(node index.js --ignore axios,chalk --no-suggestions --verbose)",
|
|
9
|
-
"Bash(node index.js --no-suggestions --verbose)",
|
|
10
|
-
"Bash(npm install *)",
|
|
11
|
-
"Bash(node -e \"import\\('@babel/parser'\\).then\\(m => console.log\\('ok:', typeof m.parse\\)\\)\")",
|
|
12
|
-
"Bash(node --input-type=module)",
|
|
13
|
-
"Bash(node index.js --no-suggestions --directory .)",
|
|
14
|
-
"Bash(node -e ' *)",
|
|
15
|
-
"Bash(node -e \"const r = require\\('./package.json'\\); console.log\\(r.version\\)\")",
|
|
16
|
-
"Bash(npm version *)"
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Marvin Ackerman
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|