dependency-detective 0.4.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/package.json +12 -5
- 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/tests/alternative-suggester.test.js +0 -28
- package/tests/analyzer.test.js +0 -97
- package/tests/ast-parser.test.js +0 -32
- package/tests/concurrency.test.js +0 -24
- package/tests/config-scanner.test.js +0 -87
- package/tests/fixtures/sample-imports.js +0 -6
- package/tests/script-scanner.test.js +0 -61
- package/tests/security-checker.test.js +0 -55
- package/tests/unused-detector.test.js +0 -18
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { commandNames, scriptsUse, findScriptReferences } from '../src/script-scanner.js';
|
|
7
|
-
|
|
8
|
-
function tempProject(installed = {}) {
|
|
9
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dd-scripts-'));
|
|
10
|
-
for (const [name, pkg] of Object.entries(installed)) {
|
|
11
|
-
const pkgDir = path.join(dir, 'node_modules', name);
|
|
12
|
-
fs.mkdirSync(pkgDir, { recursive: true });
|
|
13
|
-
fs.writeFileSync(path.join(pkgDir, 'package.json'), JSON.stringify({ name, ...pkg }));
|
|
14
|
-
}
|
|
15
|
-
return dir;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
test('commandNames reads object and string bin fields from node_modules', () => {
|
|
19
|
-
const dir = tempProject({
|
|
20
|
-
typescript: { bin: { tsc: './bin/tsc', tsserver: './bin/tsserver' } },
|
|
21
|
-
'@scope/tool': { bin: './cli.js' },
|
|
22
|
-
});
|
|
23
|
-
assert.deepEqual(commandNames(dir, 'typescript').sort(), ['tsc', 'tsserver', 'typescript']);
|
|
24
|
-
assert.deepEqual(commandNames(dir, '@scope/tool').sort(), ['@scope/tool', 'tool']);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('commandNames falls back to known commands when the package is not installed', () => {
|
|
28
|
-
const dir = tempProject();
|
|
29
|
-
assert.ok(commandNames(dir, 'typescript').includes('tsc'));
|
|
30
|
-
assert.ok(commandNames(dir, 'npm-run-all').includes('run-s'));
|
|
31
|
-
assert.deepEqual(commandNames(dir, 'left-pad'), ['left-pad']);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('scriptsUse matches commands chained, prefixed, or via npx and .bin paths', () => {
|
|
35
|
-
const uses = (script, cmd) => scriptsUse([script], cmd);
|
|
36
|
-
assert.ok(uses('tsc -p .', 'tsc'));
|
|
37
|
-
assert.ok(uses('npm run clean&&tsc', 'tsc'));
|
|
38
|
-
assert.ok(uses('cross-env NODE_ENV=production tsc', 'tsc'));
|
|
39
|
-
assert.ok(uses('npx tsc --noEmit', 'tsc'));
|
|
40
|
-
assert.ok(uses('node_modules/.bin/tsc', 'tsc'));
|
|
41
|
-
assert.ok(uses('(tsc; echo done)', 'tsc'));
|
|
42
|
-
assert.ok(uses('lint-staged || exit 1', 'lint-staged'));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('scriptsUse does not match other words containing the command', () => {
|
|
46
|
-
assert.ok(!scriptsUse(['tsc-watch src'], 'tsc'));
|
|
47
|
-
assert.ok(!scriptsUse(['echo mytsc'], 'tsc'));
|
|
48
|
-
assert.ok(!scriptsUse(['run-script build'], 'run-s'));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('findScriptReferences returns packages whose commands appear in scripts', () => {
|
|
52
|
-
const dir = tempProject({
|
|
53
|
-
typescript: { bin: { tsc: './bin/tsc' } },
|
|
54
|
-
'@biomejs/biome': { bin: { biome: './bin/biome' } },
|
|
55
|
-
rimraf: { bin: { rimraf: './dist/bin.js' } },
|
|
56
|
-
lodash: {},
|
|
57
|
-
});
|
|
58
|
-
const scripts = { build: 'rimraf dist && tsc', lint: 'biome check .' };
|
|
59
|
-
const found = findScriptReferences(dir, ['typescript', '@biomejs/biome', 'rimraf', 'lodash'], scripts);
|
|
60
|
-
assert.deepEqual([...found].sort(), ['@biomejs/biome', 'rimraf', 'typescript']);
|
|
61
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mapOsvVulns } from '../src/security-checker.js';
|
|
4
|
-
|
|
5
|
-
test('mapOsvVulns maps OSV entries to a short display shape', () => {
|
|
6
|
-
const vulns = [
|
|
7
|
-
{
|
|
8
|
-
id: 'GHSA-1',
|
|
9
|
-
summary: 'Prototype pollution',
|
|
10
|
-
details: 'A very long markdown write-up that should not be printed',
|
|
11
|
-
database_specific: { severity: 'HIGH' },
|
|
12
|
-
affected: [
|
|
13
|
-
{
|
|
14
|
-
package: { ecosystem: 'npm', name: 'lodash' },
|
|
15
|
-
ranges: [{ type: 'SEMVER', events: [{ introduced: '0' }, { fixed: '4.17.21' }] }],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
];
|
|
20
|
-
assert.deepEqual(mapOsvVulns(vulns, 'lodash'), [
|
|
21
|
-
{
|
|
22
|
-
id: 'GHSA-1',
|
|
23
|
-
severity: 'HIGH',
|
|
24
|
-
title: 'Prototype pollution',
|
|
25
|
-
fixedIn: '4.17.21',
|
|
26
|
-
url: 'https://osv.dev/vulnerability/GHSA-1',
|
|
27
|
-
},
|
|
28
|
-
]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('mapOsvVulns only reads fixed versions for the queried package', () => {
|
|
32
|
-
const [mapped] = mapOsvVulns(
|
|
33
|
-
[
|
|
34
|
-
{
|
|
35
|
-
id: 'GHSA-3',
|
|
36
|
-
affected: [
|
|
37
|
-
{ package: { name: 'other' }, ranges: [{ events: [{ fixed: '9.9.9' }] }] },
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
'lodash'
|
|
42
|
-
);
|
|
43
|
-
assert.equal(mapped.fixedIn, null);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('mapOsvVulns falls back when fields are missing', () => {
|
|
47
|
-
const [mapped] = mapOsvVulns([{ id: 'GHSA-2' }], 'x');
|
|
48
|
-
assert.equal(mapped.severity, 'UNKNOWN');
|
|
49
|
-
assert.equal(mapped.title, 'GHSA-2');
|
|
50
|
-
assert.equal(mapped.fixedIn, null);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('mapOsvVulns handles undefined input', () => {
|
|
54
|
-
assert.deepEqual(mapOsvVulns(), []);
|
|
55
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { resolveTypesUsage } from '../src/unused-detector.js';
|
|
4
|
-
|
|
5
|
-
test('marks @types/* used when its base package is referenced', () => {
|
|
6
|
-
const referenced = new Set(['react', '@babel/core']);
|
|
7
|
-
const deps = ['@types/react', '@types/babel__core', '@types/lodash', '@types/node'];
|
|
8
|
-
const used = resolveTypesUsage(referenced, deps);
|
|
9
|
-
assert.ok(used.has('@types/react'), 'react referenced');
|
|
10
|
-
assert.ok(used.has('@types/babel__core'), 'maps to @babel/core');
|
|
11
|
-
assert.ok(used.has('@types/node'), 'node always used');
|
|
12
|
-
assert.ok(!used.has('@types/lodash'), 'lodash not referenced');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('ignores non-@types deps', () => {
|
|
16
|
-
const used = resolveTypesUsage(new Set(['react']), ['react', 'lodash']);
|
|
17
|
-
assert.equal(used.size, 0);
|
|
18
|
-
});
|