npm-dependency-visualizer 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +101 -3
- package/cli.js +126 -0
- package/docs/designs/SPEC.md +439 -0
- package/examples/npm-cli-arborist.md +496 -0
- package/examples/npm-cli-focus-filter.md +189 -0
- package/examples/npm-cli-focus-highlight.md +722 -0
- package/examples/npm-cli.md +689 -0
- package/package.json +20 -6
- package/src/errors.js +6 -0
- package/src/graph.js +409 -0
- package/src/input.js +135 -0
- package/src/output.js +72 -0
- package/src/render.js +227 -0
- package/src/select.js +66 -0
- package/test/cli.test.js +326 -0
- package/test/fixtures/complex/package-lock.json +116 -0
- package/test/fixtures/complex/package.json +33 -0
- package/test/fixtures/npm-cli/LICENSE +235 -0
- package/test/fixtures/npm-cli/README.md +19 -0
- package/test/fixtures/npm-cli/package-lock.json +15235 -0
- package/test/fixtures/npm-cli/package.json +267 -0
- package/test/graph.test.js +400 -0
- package/test/mermaid.test.js +141 -0
- package/test/output.test.js +32 -0
- package/test-support/fixtures.js +19 -0
- package/test-support/offline-guard.js +25 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "12.2.2",
|
|
3
|
+
"name": "npm",
|
|
4
|
+
"description": "a package manager for JavaScript",
|
|
5
|
+
"workspaces": [
|
|
6
|
+
"docs",
|
|
7
|
+
"smoke-tests",
|
|
8
|
+
"mock-globals",
|
|
9
|
+
"mock-registry",
|
|
10
|
+
"workspaces/*"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/",
|
|
14
|
+
"lib/",
|
|
15
|
+
"index.js",
|
|
16
|
+
"docs/content/",
|
|
17
|
+
"docs/output/",
|
|
18
|
+
"man/"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"install",
|
|
22
|
+
"modules",
|
|
23
|
+
"package manager",
|
|
24
|
+
"package.json"
|
|
25
|
+
],
|
|
26
|
+
"homepage": "https://docs.npmjs.com/",
|
|
27
|
+
"author": "GitHub Inc.",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/npm/cli.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/npm/cli/issues"
|
|
34
|
+
},
|
|
35
|
+
"main": "./index.js",
|
|
36
|
+
"bin": {
|
|
37
|
+
"npm": "bin/npm-cli.js",
|
|
38
|
+
"npx": "bin/npx-cli.js"
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": [
|
|
42
|
+
{
|
|
43
|
+
"default": "./index.js"
|
|
44
|
+
},
|
|
45
|
+
"./index.js"
|
|
46
|
+
],
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@isaacs/string-locale-compare": "^1.1.0",
|
|
51
|
+
"@npmcli/arborist": "^10.0.4",
|
|
52
|
+
"@npmcli/config": "^11.2.0",
|
|
53
|
+
"@npmcli/fs": "^6.0.0",
|
|
54
|
+
"@npmcli/git": "^8.0.0",
|
|
55
|
+
"@npmcli/map-workspaces": "^6.0.0",
|
|
56
|
+
"@npmcli/metavuln-calculator": "^10.0.0",
|
|
57
|
+
"@npmcli/package-json": "^8.0.0",
|
|
58
|
+
"@npmcli/promise-spawn": "^10.0.1",
|
|
59
|
+
"@npmcli/redact": "^5.0.0",
|
|
60
|
+
"@npmcli/run-script": "^11.0.0",
|
|
61
|
+
"@sigstore/tuf": "^5.0.0",
|
|
62
|
+
"abbrev": "^5.0.0",
|
|
63
|
+
"archy": "~1.0.0",
|
|
64
|
+
"bin-links": "^7.0.1",
|
|
65
|
+
"cacache": "^21.0.1",
|
|
66
|
+
"chalk": "^5.6.2",
|
|
67
|
+
"ci-info": "^4.4.0",
|
|
68
|
+
"diff": "^8.0.2",
|
|
69
|
+
"fastest-levenshtein": "^1.0.16",
|
|
70
|
+
"fs-minipass": "^3.0.3",
|
|
71
|
+
"glob": "^13.0.6",
|
|
72
|
+
"graceful-fs": "^4.2.11",
|
|
73
|
+
"hosted-git-info": "^10.1.1",
|
|
74
|
+
"ini": "^7.0.0",
|
|
75
|
+
"init-package-json": "^9.0.0",
|
|
76
|
+
"is-cidr": "^7.0.0",
|
|
77
|
+
"json-parse-even-better-errors": "^6.0.0",
|
|
78
|
+
"libnpmaccess": "^11.0.0",
|
|
79
|
+
"libnpmdiff": "^9.0.4",
|
|
80
|
+
"libnpmexec": "^11.0.5",
|
|
81
|
+
"libnpmfund": "^8.0.4",
|
|
82
|
+
"libnpmorg": "^9.0.0",
|
|
83
|
+
"libnpmpack": "^10.0.4",
|
|
84
|
+
"libnpmpublish": "^12.0.1",
|
|
85
|
+
"libnpmsearch": "^10.0.0",
|
|
86
|
+
"libnpmteam": "^9.0.0",
|
|
87
|
+
"libnpmversion": "^9.0.0",
|
|
88
|
+
"make-fetch-happen": "^16.0.1",
|
|
89
|
+
"minimatch": "^10.2.5",
|
|
90
|
+
"minipass": "^7.1.3",
|
|
91
|
+
"minipass-pipeline": "^1.2.4",
|
|
92
|
+
"ms": "^2.1.2",
|
|
93
|
+
"node-gyp": "^13.0.0",
|
|
94
|
+
"nopt": "^10.0.1",
|
|
95
|
+
"npm-audit-report": "^8.0.0",
|
|
96
|
+
"npm-install-checks": "^9.0.0",
|
|
97
|
+
"npm-package-arg": "^14.0.0",
|
|
98
|
+
"npm-pick-manifest": "^12.0.0",
|
|
99
|
+
"npm-profile": "^13.0.1",
|
|
100
|
+
"npm-registry-fetch": "^20.0.1",
|
|
101
|
+
"npm-user-validate": "^5.0.0",
|
|
102
|
+
"p-map": "^7.0.4",
|
|
103
|
+
"pacote": "^22.0.1",
|
|
104
|
+
"parse-conflict-json": "^6.0.0",
|
|
105
|
+
"proc-log": "^7.0.0",
|
|
106
|
+
"qrcode-terminal": "^0.12.0",
|
|
107
|
+
"read": "^6.0.0",
|
|
108
|
+
"semver": "^7.8.6",
|
|
109
|
+
"spdx-expression-parse": "^4.0.0",
|
|
110
|
+
"ssri": "^14.0.0",
|
|
111
|
+
"supports-color": "^10.2.2",
|
|
112
|
+
"tar": "^7.5.22",
|
|
113
|
+
"text-table": "~0.2.0",
|
|
114
|
+
"tiny-relative-date": "^2.0.2",
|
|
115
|
+
"treeverse": "^3.0.0",
|
|
116
|
+
"validate-npm-package-name": "^8.0.0",
|
|
117
|
+
"which": "^7.0.0"
|
|
118
|
+
},
|
|
119
|
+
"bundleDependencies": [
|
|
120
|
+
"@isaacs/string-locale-compare",
|
|
121
|
+
"@npmcli/arborist",
|
|
122
|
+
"@npmcli/config",
|
|
123
|
+
"@npmcli/fs",
|
|
124
|
+
"@npmcli/git",
|
|
125
|
+
"@npmcli/map-workspaces",
|
|
126
|
+
"@npmcli/metavuln-calculator",
|
|
127
|
+
"@npmcli/package-json",
|
|
128
|
+
"@npmcli/promise-spawn",
|
|
129
|
+
"@npmcli/redact",
|
|
130
|
+
"@npmcli/run-script",
|
|
131
|
+
"@sigstore/tuf",
|
|
132
|
+
"abbrev",
|
|
133
|
+
"archy",
|
|
134
|
+
"bin-links",
|
|
135
|
+
"cacache",
|
|
136
|
+
"chalk",
|
|
137
|
+
"ci-info",
|
|
138
|
+
"diff",
|
|
139
|
+
"fastest-levenshtein",
|
|
140
|
+
"fs-minipass",
|
|
141
|
+
"glob",
|
|
142
|
+
"graceful-fs",
|
|
143
|
+
"hosted-git-info",
|
|
144
|
+
"ini",
|
|
145
|
+
"init-package-json",
|
|
146
|
+
"is-cidr",
|
|
147
|
+
"json-parse-even-better-errors",
|
|
148
|
+
"libnpmaccess",
|
|
149
|
+
"libnpmdiff",
|
|
150
|
+
"libnpmexec",
|
|
151
|
+
"libnpmfund",
|
|
152
|
+
"libnpmorg",
|
|
153
|
+
"libnpmpack",
|
|
154
|
+
"libnpmpublish",
|
|
155
|
+
"libnpmsearch",
|
|
156
|
+
"libnpmteam",
|
|
157
|
+
"libnpmversion",
|
|
158
|
+
"make-fetch-happen",
|
|
159
|
+
"minimatch",
|
|
160
|
+
"minipass",
|
|
161
|
+
"minipass-pipeline",
|
|
162
|
+
"ms",
|
|
163
|
+
"node-gyp",
|
|
164
|
+
"nopt",
|
|
165
|
+
"npm-audit-report",
|
|
166
|
+
"npm-install-checks",
|
|
167
|
+
"npm-package-arg",
|
|
168
|
+
"npm-pick-manifest",
|
|
169
|
+
"npm-profile",
|
|
170
|
+
"npm-registry-fetch",
|
|
171
|
+
"npm-user-validate",
|
|
172
|
+
"p-map",
|
|
173
|
+
"pacote",
|
|
174
|
+
"parse-conflict-json",
|
|
175
|
+
"proc-log",
|
|
176
|
+
"qrcode-terminal",
|
|
177
|
+
"read",
|
|
178
|
+
"semver",
|
|
179
|
+
"spdx-expression-parse",
|
|
180
|
+
"ssri",
|
|
181
|
+
"supports-color",
|
|
182
|
+
"tar",
|
|
183
|
+
"text-table",
|
|
184
|
+
"tiny-relative-date",
|
|
185
|
+
"treeverse",
|
|
186
|
+
"validate-npm-package-name",
|
|
187
|
+
"which"
|
|
188
|
+
],
|
|
189
|
+
"devDependencies": {
|
|
190
|
+
"@npmcli/docs": "^1.0.0",
|
|
191
|
+
"@npmcli/eslint-config": "^5.1.0",
|
|
192
|
+
"@npmcli/installed-package-contents": "^5.0.0",
|
|
193
|
+
"@npmcli/mock-globals": "^1.0.0",
|
|
194
|
+
"@npmcli/mock-registry": "^1.0.0",
|
|
195
|
+
"@npmcli/name-from-folder": "^5.0.0",
|
|
196
|
+
"@npmcli/node-gyp": "^6.0.0",
|
|
197
|
+
"@npmcli/template-oss": "5.1.1",
|
|
198
|
+
"@tufjs/repo-mock": "^5.0.0",
|
|
199
|
+
"ajv": "^8.12.0",
|
|
200
|
+
"ajv-formats": "^3.0.1",
|
|
201
|
+
"ajv-formats-draft2019": "^1.6.1",
|
|
202
|
+
"cli-table3": "^0.6.4",
|
|
203
|
+
"diff": "^8.0.4",
|
|
204
|
+
"nock": "^14.0.0",
|
|
205
|
+
"npm-packlist": "^11.3.0",
|
|
206
|
+
"remark": "^15.0.1",
|
|
207
|
+
"remark-gfm": "^4.0.1",
|
|
208
|
+
"remark-github": "^12.0.0",
|
|
209
|
+
"rimraf": "^6.0.1",
|
|
210
|
+
"spawk": "^1.7.1",
|
|
211
|
+
"tap": "^16.3.9"
|
|
212
|
+
},
|
|
213
|
+
"scripts": {
|
|
214
|
+
"dependencies": "node scripts/bundle-and-gitignore-deps.js && node scripts/dependency-graph.js",
|
|
215
|
+
"dumpconf": "env | grep npm | sort | uniq",
|
|
216
|
+
"licenses": "npx licensee --production --errors-only",
|
|
217
|
+
"test": "tap",
|
|
218
|
+
"test:nocolor": "CI=true tap -Rclassic",
|
|
219
|
+
"test-all": "node . run test --workspaces --include-workspace-root --if-present",
|
|
220
|
+
"snap": "tap",
|
|
221
|
+
"prepack": "node . run build -w docs",
|
|
222
|
+
"posttest": "node . run lint",
|
|
223
|
+
"lint": "node . run eslint",
|
|
224
|
+
"lintfix": "node . run eslint -- --fix",
|
|
225
|
+
"lint-all": "node . run lint --workspaces --include-workspace-root --if-present",
|
|
226
|
+
"resetdeps": "node scripts/resetdeps.js",
|
|
227
|
+
"rp-pull-request": "node scripts/update-authors.js",
|
|
228
|
+
"postlint": "template-oss-check",
|
|
229
|
+
"template-oss-apply": "template-oss-apply --force",
|
|
230
|
+
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
|
|
231
|
+
},
|
|
232
|
+
"tap": {
|
|
233
|
+
"test-env": [
|
|
234
|
+
"LC_ALL=sk"
|
|
235
|
+
],
|
|
236
|
+
"node-arg": [
|
|
237
|
+
"--require",
|
|
238
|
+
"./scripts/disable-agent-for-tests.js"
|
|
239
|
+
],
|
|
240
|
+
"timeout": 600,
|
|
241
|
+
"nyc-arg": [
|
|
242
|
+
"--exclude",
|
|
243
|
+
"docs/**",
|
|
244
|
+
"--exclude",
|
|
245
|
+
"smoke-tests/**",
|
|
246
|
+
"--exclude",
|
|
247
|
+
"mock-globals/**",
|
|
248
|
+
"--exclude",
|
|
249
|
+
"mock-registry/**",
|
|
250
|
+
"--exclude",
|
|
251
|
+
"workspaces/**",
|
|
252
|
+
"--exclude",
|
|
253
|
+
"tap-snapshots/**"
|
|
254
|
+
],
|
|
255
|
+
"test-ignore": "^(docs|smoke-tests|mock-globals|mock-registry|workspaces)/"
|
|
256
|
+
},
|
|
257
|
+
"templateOSS": {
|
|
258
|
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
259
|
+
"version": "5.1.1",
|
|
260
|
+
"content": "./scripts/template-oss/root.js",
|
|
261
|
+
"updateNpm": false
|
|
262
|
+
},
|
|
263
|
+
"license": "Artistic-2.0",
|
|
264
|
+
"engines": {
|
|
265
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { test } from 'node:test'
|
|
3
|
+
import { buildGraph } from '../src/graph.js'
|
|
4
|
+
import { readInputs, validateInputs } from '../src/input.js'
|
|
5
|
+
import { renderReport } from '../src/render.js'
|
|
6
|
+
import { selectView } from '../src/select.js'
|
|
7
|
+
import { complexDirectory, edge, makeInputs, npmCliDirectory } from '../test-support/fixtures.js'
|
|
8
|
+
|
|
9
|
+
const complex = () => readInputs(complexDirectory)
|
|
10
|
+
const locations = view => new Set(view.nodes.map(node => node.key))
|
|
11
|
+
|
|
12
|
+
test('resolves hoisted and nested instances without confusing location and dependency edges', async () => {
|
|
13
|
+
const graph = buildGraph(await complex())
|
|
14
|
+
assert.equal(graph.exitCode, 0)
|
|
15
|
+
assert.equal(graph.nodes.size, 16)
|
|
16
|
+
assert.equal(graph.edges.length, 20)
|
|
17
|
+
assert.equal(edge(graph, 'node_modules/a', 'shared', 'prod').target, 'node_modules/a/node_modules/shared')
|
|
18
|
+
assert.equal(edge(graph, 'node_modules/a', 'shared', 'peer').target, 'node_modules/shared')
|
|
19
|
+
assert.equal(edge(graph, 'node_modules/b', 'shared', 'prod').target, 'node_modules/shared')
|
|
20
|
+
assert.equal(edge(graph, 'node_modules/a/node_modules/deep', 'shared', 'prod').target, 'node_modules/a/node_modules/shared')
|
|
21
|
+
assert.equal(edge(graph, 'node_modules/a/node_modules/shared', 'hoisted', 'prod').target, 'node_modules/hoisted')
|
|
22
|
+
assert.equal(edge(graph, '', 'hoisted', 'prod'), undefined)
|
|
23
|
+
assert.equal(edge(graph, 'node_modules/cycle', 'a', 'prod').target, 'node_modules/a')
|
|
24
|
+
|
|
25
|
+
const markdown = renderReport(selectView(graph))
|
|
26
|
+
assert.match(markdown, /shared@1\.2\.0 #91;node_modules\/a\/node_modules\/shared#93;/)
|
|
27
|
+
assert.match(markdown, /shared@1\.2\.0 #91;node_modules\/shared#93;/)
|
|
28
|
+
assert.match(markdown, /prod: shared @ \^1\.0\.0/)
|
|
29
|
+
assert.match(markdown, /peer: shared @ \^1\.0\.0/)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('includes root dev edges only when requested and keeps shared prod dependencies', async () => {
|
|
33
|
+
const input = await complex()
|
|
34
|
+
const production = buildGraph(input)
|
|
35
|
+
const withDev = buildGraph(input, { includeDev: true })
|
|
36
|
+
assert.equal(production.nodes.has('node_modules/both'), true)
|
|
37
|
+
assert.equal(edge(production, '', 'both', 'prod').spec, '^1.0.0')
|
|
38
|
+
assert.equal(edge(production, '', 'both', 'dev'), undefined)
|
|
39
|
+
assert.equal(production.nodes.has('node_modules/dev'), false)
|
|
40
|
+
assert.equal(withDev.nodes.size, 18)
|
|
41
|
+
assert.equal(withDev.edges.length, 23)
|
|
42
|
+
assert.equal(edge(withDev, '', 'both', 'dev').target, 'node_modules/both')
|
|
43
|
+
assert.equal(edge(withDev, '', 'dev', 'dev').target, 'node_modules/dev')
|
|
44
|
+
assert.equal(edge(withDev, 'node_modules/dev', 'dev-child', 'prod').target, 'node_modules/dev-child')
|
|
45
|
+
assert.equal(withDev.nodes.has('node_modules/transitive-dev'), false)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('preserves optional, peer, alias, scoped, git, and tarball declarations', async () => {
|
|
49
|
+
const graph = buildGraph(await complex())
|
|
50
|
+
assert.equal(edge(graph, '', 'opt', 'prod'), undefined)
|
|
51
|
+
assert.equal(edge(graph, '', 'opt', 'optional').spec, '~2.0.0')
|
|
52
|
+
assert.equal(graph.nodes.get(edge(graph, '', 'absent-opt', 'optional').target).status, 'not recorded (optional)')
|
|
53
|
+
assert.equal(graph.nodes.get(edge(graph, '', 'maybe-peer', 'peer').target).status, 'not recorded (optional)')
|
|
54
|
+
assert.equal(edge(graph, 'node_modules/a', 'host', 'peer').target, 'node_modules/host')
|
|
55
|
+
assert.equal(graph.nodes.get('node_modules/alias').actualName, 'real-lib')
|
|
56
|
+
assert.equal(edge(graph, '', 'alias', 'prod').spec, 'npm:real-lib@^3.0.0')
|
|
57
|
+
assert.equal(edge(graph, '', '@scope/tool', 'prod').spec, 'git+https://example.invalid/tool.git#v2')
|
|
58
|
+
assert.equal(edge(graph, '', 'remote', 'prod').spec, 'https://example.invalid/remote.tgz')
|
|
59
|
+
assert.equal(graph.diagnostics.filter(item => item.code === 'optional-not-recorded').length, 2)
|
|
60
|
+
|
|
61
|
+
const report = renderReport(selectView(graph))
|
|
62
|
+
assert.match(report, /alias \(package real-lib\)@3\.4\.0/)
|
|
63
|
+
assert.match(report, /Root overrides are present/)
|
|
64
|
+
assert.match(report, /optional peer: maybe-peer @ \^1\.0\.0/)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('infers an unambiguous alias name without inventing unknown names', () => {
|
|
68
|
+
const input = makeInputs(
|
|
69
|
+
{ name: 'root', version: '1', dependencies: { alias: 'npm:@scope/real@^3', unknown: 'npm:bad alias' } },
|
|
70
|
+
{ 'node_modules/alias': { version: '3.2.0' }, 'node_modules/unknown': { version: '1.0.0' } },
|
|
71
|
+
)
|
|
72
|
+
const graph = buildGraph(input)
|
|
73
|
+
assert.equal(graph.nodes.get('node_modules/alias').actualName, '@scope/real')
|
|
74
|
+
assert.equal(graph.nodes.get('node_modules/unknown').actualName, null)
|
|
75
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'alias-name-missing'), true)
|
|
76
|
+
assert.match(renderReport(selectView(graph)), /unknown \(package name not recorded\)@1\.0\.0/)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('focus highlights every match and ancestor path while preserving unrelated branches', async () => {
|
|
80
|
+
const graph = buildGraph(await complex())
|
|
81
|
+
const view = selectView(graph, { focus: 'shared' })
|
|
82
|
+
assert.equal(view.matchCount, 2)
|
|
83
|
+
assert.equal(view.focusMode, 'highlight')
|
|
84
|
+
assert.deepEqual(view.nodes, [...graph.nodes.values()])
|
|
85
|
+
assert.deepEqual(view.edges, graph.edges)
|
|
86
|
+
assert.deepEqual(view.matchedNodes, new Set([
|
|
87
|
+
'node_modules/a/node_modules/shared',
|
|
88
|
+
'node_modules/shared',
|
|
89
|
+
]))
|
|
90
|
+
assert.deepEqual(view.focusNodes, new Set([
|
|
91
|
+
'',
|
|
92
|
+
'node_modules/a',
|
|
93
|
+
'node_modules/b',
|
|
94
|
+
'node_modules/cycle',
|
|
95
|
+
'node_modules/a/node_modules/deep',
|
|
96
|
+
'node_modules/a/node_modules/shared',
|
|
97
|
+
'node_modules/shared',
|
|
98
|
+
]))
|
|
99
|
+
assert.equal(view.omittedNodes, 0)
|
|
100
|
+
assert.equal(view.omittedEdges, 0)
|
|
101
|
+
assert.equal(view.focusEdges.has(edge(graph, 'node_modules/cycle', 'a', 'prod')), true)
|
|
102
|
+
assert.equal(view.focusEdges.has(edge(graph, 'node_modules/a', 'shared', 'prod')), true)
|
|
103
|
+
assert.equal(view.focusEdges.has(edge(graph, 'node_modules/a', 'shared', 'peer')), true)
|
|
104
|
+
assert.equal(view.focusEdges.has(edge(graph, 'node_modules/a/node_modules/shared', 'hoisted', 'prod')), false)
|
|
105
|
+
assert.equal(view.focusEdges.has(edge(graph, '', 'alias', 'prod')), false)
|
|
106
|
+
assert.throws(() => selectView(graph, { focus: 'no-such-package' }), /No reachable dependency/)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('filter mode keeps matches and ancestor context, not unrelated descendants', async () => {
|
|
110
|
+
const graph = buildGraph(await complex())
|
|
111
|
+
const highlighted = selectView(graph, { focus: 'shared' })
|
|
112
|
+
const view = selectView(graph, { focus: 'shared', focusMode: 'filter' })
|
|
113
|
+
assert.equal(view.focusMode, 'filter')
|
|
114
|
+
assert.deepEqual(locations(view), highlighted.focusNodes)
|
|
115
|
+
assert.deepEqual(view.matchedNodes, highlighted.matchedNodes)
|
|
116
|
+
assert.deepEqual(new Set(view.edges), highlighted.focusEdges)
|
|
117
|
+
assert.equal(locations(view).has('node_modules/hoisted'), false)
|
|
118
|
+
assert.equal(view.omittedNodes, graph.nodes.size - view.nodes.length)
|
|
119
|
+
assert.equal(view.omittedEdges, graph.edges.length - view.edges.length)
|
|
120
|
+
assert.throws(() => selectView(graph, { focus: 'no-such-package' }), /No reachable dependency/)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('depth uses shortest graph distance after focus and reports hidden matches', async () => {
|
|
124
|
+
const graph = buildGraph(await complex())
|
|
125
|
+
const zero = selectView(graph, { depth: 0 })
|
|
126
|
+
assert.deepEqual(locations(zero), new Set(['']))
|
|
127
|
+
assert.equal(zero.edges.length, 0)
|
|
128
|
+
assert.equal(zero.omittedNodes, 15)
|
|
129
|
+
assert.equal(zero.omittedEdges, 20)
|
|
130
|
+
|
|
131
|
+
const two = selectView(graph, { depth: 2 })
|
|
132
|
+
assert.equal(locations(two).has('node_modules/a/node_modules/shared'), true)
|
|
133
|
+
assert.equal(locations(two).has('node_modules/hoisted'), false)
|
|
134
|
+
const focused = selectView(graph, { focus: 'shared', depth: 1 })
|
|
135
|
+
assert.deepEqual(locations(focused), locations(selectView(graph, { depth: 1 })))
|
|
136
|
+
assert.equal(focused.hiddenMatches, 2)
|
|
137
|
+
assert.equal(focused.matchCount, 2)
|
|
138
|
+
assert.match(renderReport(focused), /Matching instances hidden by depth: 2 of 2/)
|
|
139
|
+
const filtered = selectView(graph, { focus: 'shared', focusMode: 'filter', depth: 1 })
|
|
140
|
+
assert.deepEqual(locations(filtered), new Set(['', 'node_modules/a', 'node_modules/b']))
|
|
141
|
+
assert.equal(filtered.hiddenMatches, 2)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('focus uses declared alias and placeholder names without highlighting unrelated nodes', async () => {
|
|
145
|
+
const graph = buildGraph(await complex())
|
|
146
|
+
const alias = selectView(graph, { focus: 'alias' })
|
|
147
|
+
assert.deepEqual(alias.matchedNodes, new Set(['node_modules/alias']))
|
|
148
|
+
assert.deepEqual(alias.focusNodes, new Set(['', 'node_modules/alias']))
|
|
149
|
+
assert.throws(() => selectView(graph, { focus: 'real-lib' }), /No reachable dependency/)
|
|
150
|
+
|
|
151
|
+
const placeholder = edge(graph, '', 'absent-opt', 'optional').target
|
|
152
|
+
const missing = selectView(graph, { focus: 'absent-opt' })
|
|
153
|
+
assert.deepEqual(missing.matchedNodes, new Set([placeholder]))
|
|
154
|
+
assert.deepEqual(missing.focusNodes, new Set(['', placeholder]))
|
|
155
|
+
assert.equal(missing.focusEdges.size, 1)
|
|
156
|
+
assert.equal(missing.omittedNodes, 0)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('with --no-workspaces, workspace and local links stop resolution without falling back or traversing', () => {
|
|
160
|
+
const manifest = {
|
|
161
|
+
name: 'workspace-root',
|
|
162
|
+
version: '1',
|
|
163
|
+
workspaces: ['packages/*'],
|
|
164
|
+
dependencies: { parent: '^1', workspace: 'file:packages/workspace' },
|
|
165
|
+
}
|
|
166
|
+
const input = makeInputs(manifest, {
|
|
167
|
+
'node_modules/parent': { version: '1', dependencies: { target: '^1' } },
|
|
168
|
+
'node_modules/parent/node_modules/target': { link: true, resolved: 'packages/workspace' },
|
|
169
|
+
'node_modules/target': { version: '1' },
|
|
170
|
+
'node_modules/workspace': { link: true, resolved: 'packages/workspace' },
|
|
171
|
+
'packages/workspace': { name: 'workspace', version: '1', dependencies: { hidden: '^1' } },
|
|
172
|
+
'node_modules/hidden': { version: '1' },
|
|
173
|
+
})
|
|
174
|
+
const graph = buildGraph(input, { workspaces: false })
|
|
175
|
+
assert.equal(graph.exitCode, 0)
|
|
176
|
+
assert.deepEqual(new Set(graph.nodes.keys()), new Set(['', 'node_modules/parent']))
|
|
177
|
+
assert.equal(graph.excludedBoundaries.length, 2)
|
|
178
|
+
assert.equal(graph.excludedProjectRecords, 1)
|
|
179
|
+
assert.equal(graph.diagnostics.filter(item => item.code === 'link-excluded').length, 2)
|
|
180
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'workspace-excluded'), true)
|
|
181
|
+
assert.throws(() => selectView(graph, { focus: 'workspace' }), /No reachable dependency/)
|
|
182
|
+
assert.equal(graph.workspacesExcluded, true)
|
|
183
|
+
assert.ok(renderReport(selectView(graph)).includes('Workspaces: excluded by --no-workspaces.'))
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const workspaceInputs = () => makeInputs(
|
|
187
|
+
{
|
|
188
|
+
name: 'ws-root',
|
|
189
|
+
version: '1',
|
|
190
|
+
workspaces: ['packages/*', 'tools/**', '!packages/ignored'],
|
|
191
|
+
dependencies: { a: '^1', local: 'file:../local' },
|
|
192
|
+
devDependencies: { rootdev: '^1' },
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
'node_modules/a': { link: true, resolved: 'packages/a' },
|
|
196
|
+
'node_modules/b': { link: true, resolved: 'packages/b' },
|
|
197
|
+
'node_modules/deep': { link: true, resolved: 'tools/nested/deep' },
|
|
198
|
+
'node_modules/ignored': { link: true, resolved: 'packages/ignored' },
|
|
199
|
+
'node_modules/local': { link: true, resolved: '../local' },
|
|
200
|
+
'packages/a': {
|
|
201
|
+
name: 'a',
|
|
202
|
+
version: '1.0.0',
|
|
203
|
+
dependencies: { b: '^2', shared: '^1', own: '^1' },
|
|
204
|
+
devDependencies: { adev: '^1' },
|
|
205
|
+
},
|
|
206
|
+
'packages/a/node_modules/own': { version: '3', devDependencies: { transitive: '^1' } },
|
|
207
|
+
'packages/b': { name: 'b', version: '2.0.0', dependencies: { shared: '^1' } },
|
|
208
|
+
'tools/nested/deep': { name: 'deep', version: '1.0.0', devDependencies: { deepdev: '^1' } },
|
|
209
|
+
'packages/ignored': { name: 'ignored', version: '1' },
|
|
210
|
+
'../local': { name: 'local', version: '1' },
|
|
211
|
+
'node_modules/shared': { version: '1' },
|
|
212
|
+
'node_modules/rootdev': { version: '1' },
|
|
213
|
+
'node_modules/adev': { version: '1' },
|
|
214
|
+
'node_modules/deepdev': { version: '1' },
|
|
215
|
+
'node_modules/transitive': { version: '1' },
|
|
216
|
+
},
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
test('workspaces are traversed by default through declared dependencies only', () => {
|
|
220
|
+
const graph = buildGraph(workspaceInputs())
|
|
221
|
+
assert.equal(graph.exitCode, 0)
|
|
222
|
+
assert.equal(edge(graph, '', 'a', 'prod').target, 'packages/a')
|
|
223
|
+
assert.equal(graph.nodes.get('packages/a').kind, 'workspace')
|
|
224
|
+
assert.equal(graph.nodes.has('node_modules/a'), false)
|
|
225
|
+
assert.equal(edge(graph, 'packages/a', 'b', 'prod').target, 'packages/b')
|
|
226
|
+
assert.equal(edge(graph, 'packages/a', 'own', 'prod').target, 'packages/a/node_modules/own')
|
|
227
|
+
assert.equal(edge(graph, 'packages/a', 'shared', 'prod').target, 'node_modules/shared')
|
|
228
|
+
assert.equal(edge(graph, 'packages/b', 'shared', 'prod').target, 'node_modules/shared')
|
|
229
|
+
assert.equal(graph.nodes.has('tools/nested/deep'), false)
|
|
230
|
+
assert.equal(graph.nodes.has('node_modules/adev'), false)
|
|
231
|
+
assert.deepEqual(graph.workspaces, { declared: 3, reached: 2, entryPoints: 0 })
|
|
232
|
+
assert.equal(graph.excludedProjectRecords, 2)
|
|
233
|
+
assert.equal(graph.diagnostics.some(item => item.name === 'local' && item.code === 'link-excluded'), true)
|
|
234
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'local-project-excluded'), true)
|
|
235
|
+
|
|
236
|
+
const report = renderReport(selectView(graph))
|
|
237
|
+
assert.ok(report.includes('[["a@1.0.0 (workspace)"]]'))
|
|
238
|
+
assert.ok(report.includes('Workspaces: included; reached 2 of 3 workspace projects.'))
|
|
239
|
+
assert.ok(report.includes('double-bordered (subroutine) nodes'))
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('--include-dev follows root and every workspace devDependencies but not transitive ones', () => {
|
|
243
|
+
const graph = buildGraph(workspaceInputs(), { includeDev: true })
|
|
244
|
+
assert.equal(edge(graph, '', 'rootdev', 'dev').target, 'node_modules/rootdev')
|
|
245
|
+
assert.equal(edge(graph, 'packages/a', 'adev', 'dev').target, 'node_modules/adev')
|
|
246
|
+
assert.equal(edge(graph, 'packages/a/node_modules/own', 'transitive', 'dev'), undefined)
|
|
247
|
+
assert.equal(graph.nodes.get('tools/nested/deep').kind, 'workspace')
|
|
248
|
+
assert.equal(edge(graph, 'tools/nested/deep', 'deepdev', 'dev').target, 'node_modules/deepdev')
|
|
249
|
+
assert.equal(graph.incoming.get('tools/nested/deep').length, 0)
|
|
250
|
+
assert.equal(graph.edges.some(item => item.source === '' && item.target === 'tools/nested/deep'), false)
|
|
251
|
+
assert.deepEqual(graph.workspaces, { declared: 3, reached: 3, entryPoints: 3 })
|
|
252
|
+
assert.equal(locations(selectView(graph, { depth: 1 })).has('node_modules/deepdev'), true)
|
|
253
|
+
const report = renderReport(selectView(graph))
|
|
254
|
+
assert.match(report, /root and workspace development dependencies/)
|
|
255
|
+
assert.match(report, /all 3 workspace projects are entry points, without root edges/)
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
test('--workspace starts at a workspace selected by name or location', () => {
|
|
259
|
+
for (const workspace of ['deep', 'tools/nested/deep']) {
|
|
260
|
+
const graph = buildGraph(workspaceInputs(), { includeDev: true, workspace })
|
|
261
|
+
assert.equal(graph.root.key, 'tools/nested/deep')
|
|
262
|
+
assert.equal(graph.nodes.has(''), false)
|
|
263
|
+
assert.equal(edge(graph, 'tools/nested/deep', 'deepdev', 'dev').target, 'node_modules/deepdev')
|
|
264
|
+
assert.ok(renderReport(selectView(graph)).includes('Start node: workspace deep at tools/nested/deep.'))
|
|
265
|
+
}
|
|
266
|
+
assert.throws(() => buildGraph(workspaceInputs(), { workspace: 'ignored' }), /No workspace named/)
|
|
267
|
+
assert.throws(() => buildGraph(workspaceInputs(), { workspace: 'nope' }), /No workspace named/)
|
|
268
|
+
assert.throws(() => buildGraph(workspaceInputs(), { workspace: 'a', workspaces: false }), /--no-workspaces/)
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('unsupported private peers and missing required dependencies are diagnostic, even when filtered', async () => {
|
|
272
|
+
const input = await complex()
|
|
273
|
+
input.lockfile.packages['node_modules/a'].peerDependencies.private = '^1'
|
|
274
|
+
input.lockfile.packages['node_modules/a'].peerDependencies.optionalPrivate = '^1'
|
|
275
|
+
input.lockfile.packages['node_modules/a'].peerDependenciesMeta = { optionalPrivate: { optional: true } }
|
|
276
|
+
input.lockfile.packages['node_modules/a/node_modules/private'] = { version: '1' }
|
|
277
|
+
input.lockfile.packages['node_modules/a/node_modules/optionalPrivate'] = { version: '1' }
|
|
278
|
+
delete input.lockfile.packages['node_modules/b']
|
|
279
|
+
const graph = buildGraph(input)
|
|
280
|
+
|
|
281
|
+
assert.equal(graph.exitCode, 2)
|
|
282
|
+
assert.equal(graph.nodes.has('node_modules/a/node_modules/private'), false)
|
|
283
|
+
const peer = graph.nodes.get(edge(graph, 'node_modules/a', 'private', 'peer').target)
|
|
284
|
+
assert.equal(peer.status, 'unresolved')
|
|
285
|
+
const optionalPeer = graph.nodes.get(edge(graph, 'node_modules/a', 'optionalPrivate', 'peer').target)
|
|
286
|
+
assert.equal(optionalPeer.status, 'unresolved')
|
|
287
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'peer-private-placement'), true)
|
|
288
|
+
assert.equal(graph.nodes.get(edge(graph, '', 'b', 'prod').target).status, 'unresolved')
|
|
289
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'dependency-unresolved'), true)
|
|
290
|
+
const report = renderReport(selectView(graph, { depth: 0 }))
|
|
291
|
+
assert.match(report, /unsupported private candidate/)
|
|
292
|
+
assert.match(report, /dependency-unresolved/)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('missing requirements with different roles retain distinct placeholders', () => {
|
|
296
|
+
const graph = buildGraph(makeInputs(
|
|
297
|
+
{ name: 'root', version: '1', dependencies: { parent: '^1' } },
|
|
298
|
+
{ 'node_modules/parent': {
|
|
299
|
+
version: '1',
|
|
300
|
+
dependencies: { missing: '^1' },
|
|
301
|
+
peerDependencies: { missing: '^2' },
|
|
302
|
+
} },
|
|
303
|
+
))
|
|
304
|
+
const production = edge(graph, 'node_modules/parent', 'missing', 'prod')
|
|
305
|
+
const peer = edge(graph, 'node_modules/parent', 'missing', 'peer')
|
|
306
|
+
assert.notEqual(production.target, peer.target)
|
|
307
|
+
assert.equal(graph.nodes.get(production.target).status, 'unresolved')
|
|
308
|
+
assert.equal(graph.nodes.get(peer.target).status, 'unresolved')
|
|
309
|
+
assert.equal(selectView(graph, { focus: 'missing' }).matchCount, 2)
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
test('missing selected versions are reported without inventing them', () => {
|
|
313
|
+
const graph = buildGraph(makeInputs(
|
|
314
|
+
{ name: 'root', dependencies: { dep: '^1' } },
|
|
315
|
+
{ 'node_modules/dep': {} },
|
|
316
|
+
))
|
|
317
|
+
assert.equal(graph.exitCode, 2)
|
|
318
|
+
assert.equal(graph.nodes.get('node_modules/dep').version, null)
|
|
319
|
+
assert.match(renderReport(selectView(graph)), /dep@version not recorded/)
|
|
320
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'version-missing'), true)
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('lockfile v2 packages are authoritative and overrides do not cause false invalidity claims', () => {
|
|
324
|
+
const manifest = { name: 'root', version: '1', dependencies: { dep: '^9' }, overrides: { dep: '1' } }
|
|
325
|
+
const inputs = makeInputs(manifest, { 'node_modules/dep': { version: '1' } }, 2)
|
|
326
|
+
inputs.lockfile.dependencies = { dep: { version: '999' }, phantom: { version: '1' } }
|
|
327
|
+
const graph = buildGraph(inputs)
|
|
328
|
+
const v3 = buildGraph(makeInputs(manifest, { 'node_modules/dep': { version: '1' } }, 3))
|
|
329
|
+
assert.equal(graph.exitCode, 0)
|
|
330
|
+
assert.equal(graph.nodes.get('node_modules/dep').version, '1')
|
|
331
|
+
assert.equal(graph.nodes.has('node_modules/phantom'), false)
|
|
332
|
+
assert.deepEqual([...graph.nodes], [...v3.nodes])
|
|
333
|
+
assert.deepEqual(graph.edges, v3.edges)
|
|
334
|
+
assert.match(renderReport(selectView(graph)), /not computed effective overrides/)
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
test('pinned npm/cli graph with workspaces matches Arborist-audited counts', async () => {
|
|
338
|
+
const input = await readInputs(npmCliDirectory)
|
|
339
|
+
const graph = buildGraph(input)
|
|
340
|
+
assert.equal(graph.nodes.size, 149)
|
|
341
|
+
assert.equal(graph.edges.length, 359)
|
|
342
|
+
assert.deepEqual(graph.workspaces, { declared: 16, reached: 12, entryPoints: 0 })
|
|
343
|
+
assert.equal(graph.excludedBoundaries.length, 0)
|
|
344
|
+
assert.equal(graph.excludedProjectRecords, 0)
|
|
345
|
+
assert.equal(graph.exitCode, 0)
|
|
346
|
+
assert.equal(edge(graph, '', '@npmcli/arborist', 'prod').target, 'workspaces/arborist')
|
|
347
|
+
assert.equal(graph.nodes.get('workspaces/arborist').kind, 'workspace')
|
|
348
|
+
|
|
349
|
+
const withDev = buildGraph(input, { includeDev: true })
|
|
350
|
+
assert.equal(withDev.nodes.size, 1201)
|
|
351
|
+
assert.equal(withDev.edges.length, 2406)
|
|
352
|
+
assert.deepEqual(withDev.workspaces, { declared: 16, reached: 16, entryPoints: 16 })
|
|
353
|
+
|
|
354
|
+
const arborist = buildGraph(input, { workspace: '@npmcli/arborist' })
|
|
355
|
+
assert.equal(arborist.root.key, 'workspaces/arborist')
|
|
356
|
+
assert.equal(arborist.exitCode, 0)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
test('pinned npm/cli root graph with --no-workspaces matches the independently audited counts and records', async () => {
|
|
360
|
+
const input = await readInputs(npmCliDirectory)
|
|
361
|
+
const graph = buildGraph(input, { workspaces: false })
|
|
362
|
+
assert.equal(input.lockfile.lockfileVersion, 3)
|
|
363
|
+
assert.equal(graph.nodes.size, 125)
|
|
364
|
+
assert.equal(graph.edges.length, 255)
|
|
365
|
+
assert.equal(graph.excludedBoundaries.length, 12)
|
|
366
|
+
assert.equal(graph.excludedProjectRecords, 20)
|
|
367
|
+
assert.equal(graph.exitCode, 0)
|
|
368
|
+
assert.equal(edge(graph, '', 'glob', 'prod').spec, '^13.0.6')
|
|
369
|
+
assert.equal(graph.nodes.get('node_modules/glob').version, '13.0.6')
|
|
370
|
+
assert.equal(edge(graph, 'node_modules/glob', 'minimatch', 'prod').spec, '^10.2.2')
|
|
371
|
+
assert.equal(edge(graph, 'node_modules/glob', 'minimatch', 'prod').target, 'node_modules/minimatch')
|
|
372
|
+
assert.equal(graph.nodes.has('node_modules/@npmcli/arborist'), false)
|
|
373
|
+
assert.equal(graph.diagnostics.some(item => item.name === '@npmcli/arborist' && item.code === 'link-excluded'), true)
|
|
374
|
+
assert.equal(graph.diagnostics.some(item => item.code === 'workspace-excluded'), true)
|
|
375
|
+
assert.equal(locations(selectView(graph, { focus: 'glob' })).has('node_modules/glob'), true)
|
|
376
|
+
|
|
377
|
+
const withDev = buildGraph(input, { includeDev: true, workspaces: false })
|
|
378
|
+
assert.equal(withDev.nodes.size, 1066)
|
|
379
|
+
assert.equal(withDev.edges.length, 2042)
|
|
380
|
+
assert.equal(edge(withDev, '', 'diff', 'prod').target, 'node_modules/diff')
|
|
381
|
+
assert.equal(edge(withDev, '', 'diff', 'dev').target, 'node_modules/diff')
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
test('input validation detects stale, malformed, and unsupported lockfiles', async () => {
|
|
385
|
+
const input = await complex()
|
|
386
|
+
const manifest = structuredClone(input.manifest)
|
|
387
|
+
const lockfile = structuredClone(input.lockfile)
|
|
388
|
+
lockfile.packages[''].dependencies.a = '^100'
|
|
389
|
+
assert.throws(() => validateInputs(manifest, lockfile), /dependencies\["a"\]/)
|
|
390
|
+
lockfile.packages[''].dependencies.a = manifest.dependencies.a
|
|
391
|
+
delete lockfile.packages[''].dependencies.opt
|
|
392
|
+
assert.doesNotThrow(() => validateInputs(manifest, lockfile))
|
|
393
|
+
lockfile.lockfileVersion = 1
|
|
394
|
+
assert.throws(() => validateInputs(manifest, lockfile), /Unsupported lockfileVersion 1/)
|
|
395
|
+
lockfile.lockfileVersion = 3
|
|
396
|
+
delete lockfile.packages['']
|
|
397
|
+
assert.throws(() => validateInputs(manifest, lockfile), /root entry/)
|
|
398
|
+
assert.throws(() => validateInputs([], lockfile), /package\.json must be an object/)
|
|
399
|
+
assert.throws(() => makeInputs({ dependencies: { x: 1 } }), /string specifications/)
|
|
400
|
+
})
|