@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.10
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-APACHE +202 -0
- package/bin/compare.js +132 -0
- package/bin/deptree.js +211 -0
- package/bin/npmrc.js +21 -0
- package/cargo.d.ts +223 -0
- package/cargo.js +6 -0
- package/npm.d.ts +321 -0
- package/npm.js +7 -0
- package/package.json +92 -11
- package/pnpm.d.ts +401 -81
- package/pnpm.js +4 -9
- package/soldeer.d.ts +235 -0
- package/soldeer.js +6 -0
- package/src/cargo/crate.js +183 -0
- package/src/cargo/inputs.js +81 -0
- package/src/cargo/members.js +90 -0
- package/src/cargo/registry.js +65 -0
- package/src/cargo/tree.js +125 -0
- package/src/cargo/workspace.js +177 -0
- package/src/concurrent.js +32 -0
- package/src/error.js +8 -10
- package/src/glob.js +55 -0
- package/src/hash.js +51 -16
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +124 -42
- package/src/npm/bins.js +54 -0
- package/src/npm/compat.js +97 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +75 -0
- package/src/npm/manifests.js +130 -0
- package/src/npm/package.js +57 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +139 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +26 -45
- package/src/pnpm/bins.js +202 -322
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +230 -0
- package/src/pnpm/filename.js +19 -16
- package/src/pnpm/frozen.js +29 -73
- package/src/pnpm/gitignore.js +138 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +26 -34
- package/src/pnpm/hoist.js +96 -59
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +177 -0
- package/src/pnpm/install.js +123 -124
- package/src/pnpm/local.js +95 -40
- package/src/pnpm/minimatch.js +319 -0
- package/src/pnpm/nm-hoist-graph.js +299 -0
- package/src/pnpm/nm-hoist.js +149 -0
- package/src/pnpm/npm-packlist.js +217 -0
- package/src/pnpm/overrides.js +11 -51
- package/src/pnpm/package.js +123 -0
- package/src/pnpm/packlist.js +176 -81
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +132 -89
- package/src/pnpm/readers.js +122 -77
- package/src/pnpm/settings.js +74 -95
- package/src/pnpm/tree.js +216 -237
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +152 -126
- package/src/project.js +56 -0
- package/src/soldeer/config.js +63 -0
- package/src/soldeer/git.js +52 -0
- package/src/soldeer/inputs.js +30 -0
- package/src/soldeer/tree.js +83 -0
- package/src/soldeer/zip.js +121 -0
- package/src/tarball.js +123 -131
- package/src/yarn1/bins.js +28 -0
- package/src/yarn1/compat.js +67 -0
- package/src/yarn1/hoist.js +249 -0
- package/src/yarn1/inputs.js +83 -0
- package/src/yarn1/manifest.js +64 -0
- package/src/yarn1/package.js +206 -0
- package/src/yarn1/peers.js +51 -0
- package/src/yarn1/requests.js +74 -0
- package/src/yarn1/resolve.js +289 -0
- package/src/yarn1/settings.js +95 -0
- package/src/yarn1/tree.js +219 -0
- package/yarn1.d.ts +368 -0
- package/yarn1.js +7 -0
- package/src/pnpm/npmrc.js +0 -31
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/checks.js
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
// Checks
|
|
2
|
-
//
|
|
3
|
-
// tree it installs always is: where one fails, the lockfile was not
|
|
4
|
-
// written by pnpm as it stands, or the tree would not be one tree
|
|
5
|
-
// everywhere it is installed.
|
|
1
|
+
// Checks pnpm does not make, of what a lockfile pnpm writes always holds to or
|
|
2
|
+
// a tree it installs always is.
|
|
6
3
|
|
|
7
4
|
import { DeptreeError, quote } from '../error.js'
|
|
8
|
-
import { fold } from '../mount.js'
|
|
9
5
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// marks it: one marked otherwise would be left out, or kept, where it
|
|
13
|
-
// should not be.
|
|
6
|
+
// pnpm marks a snapshot optional exactly where no importer requires it; one
|
|
7
|
+
// marked otherwise would be left out, or kept, where it should not be.
|
|
14
8
|
export function checkOptional(lockfile) {
|
|
15
9
|
const required = new Set()
|
|
16
|
-
const queue = []
|
|
17
10
|
const reach = (targets) => {
|
|
18
|
-
for (const target of Object.values(targets))
|
|
19
|
-
if (target.startsWith('link:') || required.has(target)) continue
|
|
20
|
-
required.add(target)
|
|
21
|
-
queue.push(target)
|
|
22
|
-
}
|
|
11
|
+
for (const target of Object.values(targets)) if (!target.startsWith('link:')) required.add(target)
|
|
23
12
|
}
|
|
24
13
|
for (const importer of Object.values(lockfile.importers)) {
|
|
25
14
|
reach(importer.dependencies)
|
|
26
15
|
reach(importer.devDependencies)
|
|
27
16
|
}
|
|
28
|
-
|
|
17
|
+
for (const key of required) reach(lockfile.packages[key].dependencies)
|
|
29
18
|
for (const [key, pkg] of Object.entries(lockfile.packages)) {
|
|
30
19
|
if (pkg.optional === required.has(key)) {
|
|
31
20
|
throw new DeptreeError(`marked ${pkg.optional ? 'optional where an importer requires it' : 'required where only optional dependencies reach it'}, which pnpm never writes`, `snapshots[${quote(key)}]`)
|
|
@@ -33,24 +22,8 @@ export function checkOptional(lockfile) {
|
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
24
|
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
// lost: such a tree is refused where the host is macOS.
|
|
39
|
-
export function checkCollisions(vfs) {
|
|
40
|
-
for (const { path, type } of vfs.walk('/')) {
|
|
41
|
-
if (type !== 'directory') continue
|
|
42
|
-
const folded = new Map()
|
|
43
|
-
for (const name of vfs.readdir(path)) {
|
|
44
|
-
const key = fold(name)
|
|
45
|
-
if (folded.has(key)) throw new DeptreeError(`${quote(folded.get(key))} and ${quote(name)} are one name on macOS`, quote(path))
|
|
46
|
-
folded.set(key, name)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Every link into node_modules leads to a directory in the tree; a link
|
|
52
|
-
// out of it leads to a project or a `link:` directory, which the tree
|
|
53
|
-
// does not hold.
|
|
25
|
+
// Only links into node_modules are checked: a link out of it leads to a
|
|
26
|
+
// project or a `link:` directory, which the tree does not hold.
|
|
54
27
|
export function checkLinks(vfs, links) {
|
|
55
28
|
for (const [path, target] of links) {
|
|
56
29
|
if (!target.startsWith('node_modules/') && !target.includes('/node_modules/')) continue
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// A package's commands as @pnpm/package-bins reads them to link its bins, or
|
|
2
|
+
// pnpm 12's bin_resolver crate, which reads a package.json unnormalized. pnpm 9
|
|
3
|
+
// filters a command by its name before it drops the scope, and links a `bin`
|
|
4
|
+
// string or a directories.bin wherever it leads.
|
|
5
|
+
|
|
6
|
+
import { compareVersions, valid } from '@preventive/upstream/semver.js'
|
|
7
|
+
import { basename, compareNames, join } from '@preventive/vfs/path.js'
|
|
8
|
+
import { DeptreeError, quote } from '../error.js'
|
|
9
|
+
import { checkNesting } from '../manifest.js'
|
|
10
|
+
import { within } from '../mount.js'
|
|
11
|
+
|
|
12
|
+
// A package whose directory has no package.json is still linked by these names
|
|
13
|
+
// by pnpm 10, to the runtime's binary inside it; pnpm 9 links none.
|
|
14
|
+
const RUNTIMES = { __proto__: null, node: 'bin/node', deno: 'deno', bun: 'bun' }
|
|
15
|
+
|
|
16
|
+
// The packages pnpm 11 and 12 take to own a command by a name not their own.
|
|
17
|
+
const OWNERS = { __proto__: null, npx: ['npm'], pn: ['pnpm', '@pnpm/exe'], pnpm: ['@pnpm/exe'], pnpx: ['pnpm', '@pnpm/exe'], pnx: ['pnpm', '@pnpm/exe'] }
|
|
18
|
+
|
|
19
|
+
const collator = new Intl.Collator('en')
|
|
20
|
+
const decoder = new TextDecoder('utf-8', { fatal: true })
|
|
21
|
+
|
|
22
|
+
// As path.join spells it, or undefined where is-subdir finds it out of `dir`.
|
|
23
|
+
function inPackage(dir, rel, where) {
|
|
24
|
+
if (typeof rel !== 'string') throw new DeptreeError(`${quote(String(rel))} is not a path, which pnpm fails on`, where)
|
|
25
|
+
const path = join(dir, rel)
|
|
26
|
+
if (path.endsWith('/')) throw new DeptreeError(`${quote(rel)} ends in a slash, which is not supported`, where)
|
|
27
|
+
return within(dir, path) ? path : undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Stands for the commands of a directory whose bins are not known here.
|
|
31
|
+
export const UNKNOWN = { unknown: true }
|
|
32
|
+
|
|
33
|
+
// As tinyglobby's `**` finds them, or with `dots` as pnpm 12's walk does.
|
|
34
|
+
function filesUnder(files, base, dir, { dots = false } = {}) {
|
|
35
|
+
const prefix = dir === base ? '' : `${dir.slice(base.length + 1)}/`
|
|
36
|
+
const found = [...files].filter(([path, file]) => file.data !== undefined && path.startsWith(prefix)).map(([path]) => path.slice(prefix.length))
|
|
37
|
+
return dots ? found : found.filter((rest) => !rest.split('/').some((name) => name.startsWith('.')))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Which of two of one name wins turns on the order directories are read in.
|
|
41
|
+
function filesAsCommands(found, root, common) {
|
|
42
|
+
const names = found.map((path) => basename(path))
|
|
43
|
+
const counts = new Map()
|
|
44
|
+
for (const name of names) counts.set(name, (counts.get(name) ?? 0) + 1)
|
|
45
|
+
return found.map((path, i) => ({ ...common, name: names[i], target: `${root}/${path}`, unordered: counts.get(names[i]) > 1 }))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// pnpm 11 looks a name up among OWNERS as a plain object's key, and fails on
|
|
49
|
+
// one that Object.prototype has.
|
|
50
|
+
function owns({ name, pkgName, own }, major, where) {
|
|
51
|
+
if (own || name === pkgName) return true
|
|
52
|
+
if (major < 11) return false
|
|
53
|
+
if (major === 11 && name in Object.prototype) throw new DeptreeError(`two bins are named ${quote(name)}, which pnpm 11 fails on`, where)
|
|
54
|
+
return OWNERS[name]?.includes(pkgName) === true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// pnpm's runtimeHasNodeDownloaded.
|
|
58
|
+
function downloadsNode(runtime, where) {
|
|
59
|
+
if (!runtime) return false
|
|
60
|
+
if (!Array.isArray(runtime)) return runtime.name === 'node' && runtime.onFail === 'download'
|
|
61
|
+
for (const item of runtime) {
|
|
62
|
+
if (item == null) throw new DeptreeError('its engines.runtime lists nothing where pnpm reads a runtime, which pnpm fails on', where)
|
|
63
|
+
if (item.name === 'node') return item.onFail === 'download'
|
|
64
|
+
}
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// pnpm 12's command names: those encodeURIComponent leaves as they are.
|
|
69
|
+
const safeName = (name) => name === '$' || (name !== '.' && name !== '..' && /^[\w\-.!~*'()]+$/u.test(name))
|
|
70
|
+
|
|
71
|
+
// pnpm 12 reads a package's own package.json from its store where it has the
|
|
72
|
+
// package, which drops a null `bin`, and as fetched otherwise.
|
|
73
|
+
function commands12(dir, manifest, files, base, where) {
|
|
74
|
+
const name = typeof manifest.name === 'string' ? manifest.name : undefined
|
|
75
|
+
const common = { pkgName: name ?? '', pkgVersion: manifest.version, owner: base }
|
|
76
|
+
const { bin } = manifest
|
|
77
|
+
if (bin === null && typeof manifest.directories?.bin === 'string' && files !== undefined && dir === base) {
|
|
78
|
+
throw new DeptreeError('its bin is null beside a directories.bin, which pnpm 12 links as its store has the package or not', where)
|
|
79
|
+
}
|
|
80
|
+
if (bin !== undefined && bin !== '') {
|
|
81
|
+
const entries = typeof bin === 'string' ? (name === undefined ? [] : [[name, bin]])
|
|
82
|
+
: bin !== null && typeof bin === 'object' && !Array.isArray(bin) ? Object.entries(bin).filter(([, rel]) => typeof rel === 'string') : []
|
|
83
|
+
const commands = []
|
|
84
|
+
for (const [command, rel] of entries) {
|
|
85
|
+
const unscoped = command[0] === '@' && command.includes('/') ? command.slice(command.indexOf('/') + 1) : command
|
|
86
|
+
if (!safeName(unscoped) || rel.startsWith('/')) continue
|
|
87
|
+
const target = inPackage(dir, rel, where)
|
|
88
|
+
if (target !== undefined) commands.push({ ...common, name: unscoped, target })
|
|
89
|
+
}
|
|
90
|
+
return commands
|
|
91
|
+
}
|
|
92
|
+
const binDir = manifest.directories?.bin
|
|
93
|
+
if (typeof binDir !== 'string') return []
|
|
94
|
+
const root = inPackage(dir, binDir, where)
|
|
95
|
+
if (root === undefined || binDir.startsWith('/')) return []
|
|
96
|
+
if (files === undefined) return [UNKNOWN]
|
|
97
|
+
return filesAsCommands(filesUnder(files, base, root, { dots: true }).filter((path) => safeName(basename(path))), root, common)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const outOf = (rel, where) => new DeptreeError(`${quote(rel)} leads out of the package, which pnpm 9 links a bin to all the same, and that is not supported`, where)
|
|
101
|
+
|
|
102
|
+
const uriSafe = (name) => name === encodeURIComponent(name) || name === '$'
|
|
103
|
+
|
|
104
|
+
// pnpm 9 also takes a scope with whatever follows it.
|
|
105
|
+
const takes9 = (command) => uriSafe(command) || command[0] === '@'
|
|
106
|
+
|
|
107
|
+
// `files` are the holding package's (itself, or the one bundling it), by path
|
|
108
|
+
// under `base`; both are undefined for a project or `link:` target.
|
|
109
|
+
export function commandsOf(dir, manifest, files, base, where, major) {
|
|
110
|
+
if (major >= 12) return commands12(dir, manifest, files, base, where)
|
|
111
|
+
const common = { pkgName: manifest.name, pkgVersion: manifest.version, owner: base }
|
|
112
|
+
if (typeof manifest.bin === 'string' && !manifest.name) throw new DeptreeError('it has a bin and no name, which pnpm fails on', where)
|
|
113
|
+
// pnpm 9 knows no runtime.
|
|
114
|
+
if (major >= 10 && downloadsNode(manifest.engines?.runtime, where)) {
|
|
115
|
+
throw new DeptreeError('its engines.runtime has pnpm look for a Node to run its bins with, which is not supported', where)
|
|
116
|
+
}
|
|
117
|
+
if (manifest.bin) {
|
|
118
|
+
const string = typeof manifest.bin === 'string'
|
|
119
|
+
const entries = string ? [[manifest.name, manifest.bin]] : Object.entries(manifest.bin)
|
|
120
|
+
const commands = []
|
|
121
|
+
for (const [command, rel] of entries) {
|
|
122
|
+
const name = command[0] === '@' ? command.slice(command.indexOf('/') + 1) : command
|
|
123
|
+
if (!(major < 10 ? string || takes9(command) : uriSafe(name))) continue
|
|
124
|
+
if (name === '' || name === '.' || name === '..' || name.includes('/')) {
|
|
125
|
+
if (major >= 11) continue
|
|
126
|
+
throw new DeptreeError(`a bin named ${quote(name)} is not supported`, where)
|
|
127
|
+
}
|
|
128
|
+
const target = inPackage(dir, rel, where)
|
|
129
|
+
if (target === undefined && major < 10 && string) throw outOf(rel, where)
|
|
130
|
+
if (target !== undefined) commands.push({ ...common, name, target })
|
|
131
|
+
}
|
|
132
|
+
return commands
|
|
133
|
+
}
|
|
134
|
+
const binDir = manifest.directories?.bin
|
|
135
|
+
if (!binDir) return []
|
|
136
|
+
const root = inPackage(dir, binDir, where)
|
|
137
|
+
if (root === undefined && major < 10) throw outOf(binDir, where)
|
|
138
|
+
if (root === undefined) return []
|
|
139
|
+
if (files === undefined) return [UNKNOWN]
|
|
140
|
+
return filesAsCommands(filesUnder(files, base, root), root, common)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// compareCommandsInConflict, which pnpm keeps the greater of (pnpm 12's
|
|
144
|
+
// pick_winner, which keeps the first of a tie). pnpm compares names with
|
|
145
|
+
// localeCompare, read here as English.
|
|
146
|
+
export function compare(a, b, where, major) {
|
|
147
|
+
const aOwns = owns(a, major, where)
|
|
148
|
+
const bOwns = owns(b, major, where)
|
|
149
|
+
if (aOwns !== bOwns) return aOwns ? 1 : -1
|
|
150
|
+
if (major >= 12) {
|
|
151
|
+
if (a.pkgName !== b.pkgName) return compareNames(b.pkgName, a.pkgName)
|
|
152
|
+
const versions = [a.pkgVersion, b.pkgVersion].map((version) => (typeof version === 'string' ? valid(version) : null))
|
|
153
|
+
return versions.includes(null) ? 0 : compareVersions(versions[0], versions[1])
|
|
154
|
+
}
|
|
155
|
+
if (a.pkgName !== b.pkgName) {
|
|
156
|
+
if (typeof a.pkgName !== 'string' || typeof b.pkgName !== 'string') throw new DeptreeError(`two bins named ${quote(a.name)} are of packages not both named, which pnpm fails on`, where)
|
|
157
|
+
return collator.compare(a.pkgName, b.pkgName)
|
|
158
|
+
}
|
|
159
|
+
if (valid(a.pkgVersion) === null || valid(b.pkgVersion) === null) throw new DeptreeError(`two bins named ${quote(a.name)} are of ${quote(a.pkgName)} at versions pnpm cannot compare, which it fails on`, where)
|
|
160
|
+
return compareVersions(a.pkgVersion, b.pkgVersion)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// As normalize-package-data leaves it for pnpm's readPackageJson.
|
|
164
|
+
export function normalized(manifest, where) {
|
|
165
|
+
const name = manifest.name || ''
|
|
166
|
+
if (typeof name !== 'string') throw new DeptreeError('its package.json\'s name is not a string, which pnpm fails on', where)
|
|
167
|
+
const trimmed = name.trim()
|
|
168
|
+
const scoped = /^@([^/]+)\/([^/]+)$/u.exec(trimmed)
|
|
169
|
+
const encoded = (part) => part === encodeURIComponent(part)
|
|
170
|
+
const validName = trimmed === '' || (!trimmed.startsWith('.') && trimmed.toLowerCase() !== 'node_modules' && trimmed.toLowerCase() !== 'favicon.ico'
|
|
171
|
+
&& ((scoped !== null && encoded(scoped[1]) && encoded(scoped[2])) || (!/[/@\s+%:]/u.test(trimmed) && encoded(trimmed))))
|
|
172
|
+
if (!validName) throw new DeptreeError(`its package.json's name, ${quote(trimmed)}, is one pnpm fails on`, where)
|
|
173
|
+
const version = manifest.version ? valid(manifest.version, { loose: true }) : ''
|
|
174
|
+
if (version === null) throw new DeptreeError(`its package.json's version, ${quote(String(manifest.version))}, is one pnpm fails on`, where)
|
|
175
|
+
return { ...manifest, name: trimmed, version }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// As pnpm's readModulesDir finds them.
|
|
179
|
+
function bundledIn(files) {
|
|
180
|
+
const names = new Set()
|
|
181
|
+
for (const path of files.keys()) {
|
|
182
|
+
const parts = path.split('/')
|
|
183
|
+
if (parts[0] !== 'node_modules' || parts.length < 3 || parts[1].startsWith('.')) continue
|
|
184
|
+
if (!parts[1].startsWith('@')) names.add(parts[1])
|
|
185
|
+
else if (parts.length > 3) names.add(`${parts[1]}/${parts[2]}`)
|
|
186
|
+
}
|
|
187
|
+
return [...names]
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function parseManifest(file, where) {
|
|
191
|
+
try {
|
|
192
|
+
const manifest = JSON.parse(decoder.decode(file.data))
|
|
193
|
+
if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) throw new Error('not an object')
|
|
194
|
+
return checkNesting(manifest, where)
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof DeptreeError) throw error
|
|
197
|
+
throw new DeptreeError('a package.json pnpm reads for its bins is not JSON, which pnpm fails on', where)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// For a bundled package with no package.json, pnpm 11 reads the bins of any
|
|
202
|
+
// directory above it, up to /, whose publishConfig.directory it is.
|
|
203
|
+
export function bundledCommands(node, where, major) {
|
|
204
|
+
const commands = []
|
|
205
|
+
for (const name of bundledIn(node.files)) {
|
|
206
|
+
const here = `${where}: node_modules/${name}`
|
|
207
|
+
const file = node.files.get(`node_modules/${name}/package.json`)
|
|
208
|
+
const dir = `${node.dir}/node_modules/${name}`
|
|
209
|
+
if (file !== undefined) {
|
|
210
|
+
const manifest = parseManifest(file, here)
|
|
211
|
+
commands.push(...commandsOf(dir, major >= 12 ? manifest : normalized(manifest, here), node.files, node.dir, here, major))
|
|
212
|
+
} else if (major >= 11) {
|
|
213
|
+
if (major < 12) throw new DeptreeError('it bundles a package with no package.json, whose bins pnpm 11 looks for above it', here)
|
|
214
|
+
} else if (major >= 10 && name in RUNTIMES) {
|
|
215
|
+
commands.push({ name, target: `${dir}/${RUNTIMES[name]}`, owner: node.dir, own: true, pkgName: '', pkgVersion: '' })
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return commands
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Every path the package and those it bundles name as bins, linked or not.
|
|
222
|
+
export function binsOf(node, manifest, files, major) {
|
|
223
|
+
const where = quote(node.key)
|
|
224
|
+
const bins = new Map()
|
|
225
|
+
for (const { target, name, pkgName, pkgVersion } of [...commandsOf(node.dir, manifest, files, node.dir, where, major), ...bundledCommands({ ...node, files }, where, major)]) {
|
|
226
|
+
const path = target.slice(node.dir.length + 1)
|
|
227
|
+
bins.set(path, [...bins.get(path) ?? [], JSON.stringify([name, pkgName, pkgVersion])].sort())
|
|
228
|
+
}
|
|
229
|
+
return bins
|
|
230
|
+
}
|
package/src/pnpm/filename.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
// The directory pnpm
|
|
2
|
-
// depPathToFilename (@pnpm/dependency-path) spells it:
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// that runs past `virtualStoreDirMaxLength` or has a capital in it, cut
|
|
6
|
-
// short and ended with `_` and 32 hex characters of its SHA-256.
|
|
7
|
-
// `a@1.0.0(b@2.0.0)` is `a@1.0.0_b@2.0.0`, `@s/a@1.0.0` `@s+a@1.0.0`.
|
|
8
|
-
//
|
|
9
|
-
// pnpm 11 escapes a trailing dot or space as well, each made `+`, and then
|
|
10
|
-
// hashes the name whatever its length; a snapshot of the registry never
|
|
11
|
-
// ends in either. pnpm 9 hashed with MD5 in base32, which is not done here.
|
|
1
|
+
// The directory pnpm gives a snapshot under node_modules/.pnpm, as its
|
|
2
|
+
// depPathToFilename (@pnpm/dependency-path) spells it: `a@1.0.0(b@2.0.0)` is
|
|
3
|
+
// `a@1.0.0_b@2.0.0`, `@s/a@1.0.0` `@s+a@1.0.0`, and one too long or with a
|
|
4
|
+
// capital is cut short and hashed.
|
|
12
5
|
|
|
13
6
|
import { quote } from '../error.js'
|
|
14
|
-
import { sha256Hex } from '../hash.js'
|
|
7
|
+
import { md5Base32, sha256Hex } from '../hash.js'
|
|
15
8
|
|
|
16
|
-
const
|
|
9
|
+
const encoder = new TextEncoder()
|
|
10
|
+
|
|
11
|
+
// pnpm 12 cuts by bytes, back to where a character starts.
|
|
12
|
+
function cut(filename, length, major) {
|
|
13
|
+
if (major < 12) return filename.slice(0, length)
|
|
14
|
+
return filename.slice(0, encoder.encodeInto(filename, new Uint8Array(length)).read)
|
|
15
|
+
}
|
|
17
16
|
|
|
18
17
|
export async function depPathToFilename(depPath, maxLength, major = 10) {
|
|
19
|
-
let filename = depPath.replace(/[\\/:*?"<>|#]/gu, '+')
|
|
18
|
+
let filename = depPath.replace(major < 10 ? /[\\/:*?"<>|]/gu : /[\\/:*?"<>|#]/gu, '+')
|
|
20
19
|
if (filename.includes('(')) filename = filename.replace(/\)$/u, '').replace(/\)\(|\(|\)/gu, '_')
|
|
21
20
|
const hashed = filename
|
|
22
21
|
const trailing = major >= 11 ? /[. ]*$/u.exec(filename)[0].length : 0
|
|
23
22
|
if (trailing > 0) filename = `${filename.slice(0, -trailing)}${'+'.repeat(trailing)}`
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const length = major >= 12 ? encoder.encode(filename).length : filename.length
|
|
24
|
+
const lower = major >= 12 ? filename.replace(/[A-Z]+/gu, (capitals) => capitals.toLowerCase()) : filename.toLowerCase()
|
|
25
|
+
if (trailing === 0 && length <= maxLength && filename === lower) return filename
|
|
26
|
+
// By pnpm's createBase32Hash, or createShortHash.
|
|
27
|
+
const hash = `_${major < 10 ? md5Base32(hashed, quote(depPath)) : (await sha256Hex(hashed, quote(depPath))).slice(0, 32)}`
|
|
28
|
+
return `${cut(filename, Math.max(maxLength - hash.length, 0), major)}${hash}`
|
|
26
29
|
}
|
package/src/pnpm/frozen.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
// What pnpm 11's frozen install
|
|
2
|
-
//
|
|
3
|
-
// repository and commit alike are the same; a catalog dependency has to
|
|
4
|
-
// have resolved to the version the lockfile's catalog records; and a
|
|
5
|
-
// dependency on a workspace package has to be linked exactly where the
|
|
6
|
-
// package's version is in its range — which pnpm 10 checks only when it
|
|
7
|
-
// resolves.
|
|
1
|
+
// What pnpm 11's frozen install checks of each project that pnpm 10 checks only
|
|
2
|
+
// when it resolves (@pnpm/lockfile.verification).
|
|
8
3
|
|
|
9
4
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
10
5
|
import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
11
6
|
import { join } from '@preventive/vfs/path.js'
|
|
12
7
|
import { DeptreeError, quote } from '../error.js'
|
|
8
|
+
import { own } from '../manifest.js'
|
|
9
|
+
import { within } from '../mount.js'
|
|
13
10
|
import { catalogEntry, catalogOf } from './overrides.js'
|
|
14
11
|
|
|
15
12
|
const GIT_HOSTS = new Set(['github.com', 'gitlab.com', 'bitbucket.org'])
|
|
@@ -22,8 +19,7 @@ function gitUrl(host, path, committish) {
|
|
|
22
19
|
return `git+https://${host}/${repository}.git${committish ? `#${committish}` : ''}`
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
// A git specifier as one URL, as gitSpecifiersAreEquivalent spells it
|
|
26
|
-
// undefined for one that is not.
|
|
22
|
+
// A git specifier as one URL, as gitSpecifiersAreEquivalent spells it.
|
|
27
23
|
function gitSpecifier(specifier) {
|
|
28
24
|
const hash = specifier.indexOf('#')
|
|
29
25
|
const committish = hash === -1 ? undefined : specifier.slice(hash + 1)
|
|
@@ -47,9 +43,7 @@ function gitSpecifier(specifier) {
|
|
|
47
43
|
return gitUrl(host, path, committish)
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
// dependencySpecifiersAreEqual: pnpm 11
|
|
51
|
-
// repository and commit, however spelled, to be the same; pnpm 10 only
|
|
52
|
-
// two spelled the same.
|
|
46
|
+
// dependencySpecifiersAreEqual: pnpm 11 matches git specifiers however spelled.
|
|
53
47
|
export function sameSpecifier(a, b, major) {
|
|
54
48
|
if (a === b) return true
|
|
55
49
|
if (major < 11 || a === undefined || b === undefined) return false
|
|
@@ -57,9 +51,7 @@ export function sameSpecifier(a, b, major) {
|
|
|
57
51
|
return git !== undefined && git === gitSpecifier(b)
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
//
|
|
61
|
-
// it, peers and all left out: a key of the alias's own name is its
|
|
62
|
-
// version.
|
|
54
|
+
// A target under the alias's own name is spelled as its version alone.
|
|
63
55
|
export const resolvedOf = (alias, target) => packageKeyOf(target.startsWith(`${alias}@`) ? target.slice(alias.length + 1) : target)
|
|
64
56
|
|
|
65
57
|
const targetOf = (importer, alias) => importer.dependencies[alias] ?? importer.devDependencies[alias] ?? importer.optionalDependencies[alias]
|
|
@@ -77,9 +69,7 @@ export function checkCatalogResolutions(importer, catalogs, where) {
|
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
|
|
80
|
-
//
|
|
81
|
-
// lockfile's directory as the lockfile's links are; one from the home
|
|
82
|
-
// directory or the root cannot be told here.
|
|
72
|
+
// Relative to the lockfile's directory, as the lockfile's links are.
|
|
83
73
|
function specPath(dir, path, where) {
|
|
84
74
|
const clean = path.startsWith('./') ? path.slice(2) : path
|
|
85
75
|
if (/^(?:~[/\\]|[/\\]|[A-Za-z]:)/u.test(clean) || clean.includes('\\')) throw new DeptreeError(`${quote(path)} is not a path from the project, which is not supported`, where)
|
|
@@ -87,38 +77,21 @@ function specPath(dir, path, where) {
|
|
|
87
77
|
}
|
|
88
78
|
|
|
89
79
|
const isWorkspacePath = (spec) => /^(?:[./\\]|~[/\\]|[A-Za-z]:)/u.test(spec)
|
|
90
|
-
// Of two paths in the lockfile's normal form, whether one is the other or
|
|
91
|
-
// in it.
|
|
92
|
-
const within = (parent, child) => child === parent || (parent === '.' ? child !== '..' && !child.startsWith('../') : child.startsWith(`${parent}/`))
|
|
93
80
|
|
|
94
|
-
function
|
|
81
|
+
export function parseSpec(spec, alias) {
|
|
95
82
|
if (spec.startsWith('workspace:')) {
|
|
96
83
|
const raw = spec.slice('workspace:'.length)
|
|
97
84
|
const at = raw.lastIndexOf('@')
|
|
98
|
-
return isWorkspacePath(raw) || at <= 0 ? alias : raw.slice(0, at)
|
|
85
|
+
return { name: isWorkspacePath(raw) || at <= 0 ? alias : raw.slice(0, at), range: at > 0 ? raw.slice(at + 1) || '*' : raw }
|
|
99
86
|
}
|
|
100
87
|
if (spec.startsWith('npm:')) {
|
|
101
88
|
const raw = spec.slice('npm:'.length)
|
|
102
|
-
if (validRange(raw) !== null) return alias
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return alias
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function versionRange(spec) {
|
|
110
|
-
if (spec.startsWith('workspace:')) {
|
|
111
|
-
const raw = spec.slice('workspace:'.length)
|
|
112
|
-
const at = raw.lastIndexOf('@')
|
|
113
|
-
return at > 0 ? raw.slice(at + 1) || '*' : raw
|
|
114
|
-
}
|
|
115
|
-
if (spec.startsWith('npm:')) {
|
|
116
|
-
const raw = spec.slice('npm:'.length)
|
|
117
|
-
if (validRange(raw) !== null) return raw
|
|
118
|
-
const at = raw.indexOf('@', 1)
|
|
119
|
-
return at === -1 ? '*' : raw.slice(at + 1) || '*'
|
|
89
|
+
if (validRange(raw) !== null) return { name: alias, range: raw }
|
|
90
|
+
const last = raw.lastIndexOf('@')
|
|
91
|
+
const first = raw.indexOf('@', 1)
|
|
92
|
+
return { name: last > 0 ? raw.slice(0, last) : raw, range: first === -1 ? '*' : raw.slice(first + 1) || '*' }
|
|
120
93
|
}
|
|
121
|
-
return spec
|
|
94
|
+
return { name: alias, range: spec }
|
|
122
95
|
}
|
|
123
96
|
|
|
124
97
|
const inRange = (version, range) => range === '*' || range === '^' || range === '~' || (typeof version === 'string' && satisfies(version, range, { loose: true }))
|
|
@@ -128,27 +101,21 @@ const isTag = (range) => valid(range, { loose: true }) === null && validRange(ra
|
|
|
128
101
|
|
|
129
102
|
export const KINDS = ['optionalDependencies', 'dependencies', 'devDependencies']
|
|
130
103
|
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
// led by a backslash, a path to pnpm on Windows alone, is taken for one
|
|
134
|
-
// too, for specPath to refuse, as a lockfile pnpm writes elsewhere never
|
|
135
|
-
// links it.
|
|
104
|
+
// A path led by a backslash, a path only on Windows, is taken too for specPath
|
|
105
|
+
// to refuse, as a lockfile pnpm writes elsewhere never links it.
|
|
136
106
|
function pathOf(spec) {
|
|
137
107
|
if (spec.startsWith('link:') || spec.startsWith('file:')) return spec.slice(5)
|
|
138
108
|
const path = spec.startsWith('workspace:') ? spec.slice('workspace:'.length) : spec
|
|
139
109
|
return isWorkspacePath(path) ? path : undefined
|
|
140
110
|
}
|
|
141
111
|
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
// `workspace:` path to that, and pnpm 10, or pnpm 11 a path alone, would
|
|
146
|
-
// link whatever the lockfile says. A `file:` one is pnpm's to link, where
|
|
147
|
-
// it does.
|
|
112
|
+
// Stricter than pnpm, which checks only a `link:` or `workspace:` path, and
|
|
113
|
+
// only from pnpm 11: a lockfile pnpm writes always links where the hooked
|
|
114
|
+
// package.json names a directory.
|
|
148
115
|
export function checkLinkTargets({ id, manifest, importer }, where) {
|
|
149
116
|
for (const kind of KINDS) {
|
|
150
117
|
for (const [alias, target] of Object.entries(importer[kind])) {
|
|
151
|
-
const spec = manifest[kind]
|
|
118
|
+
const spec = own(manifest[kind], alias)
|
|
152
119
|
if (!spec || !target.startsWith('link:') || importer.specifiers[alias].startsWith('file:')) continue
|
|
153
120
|
const path = pathOf(spec)
|
|
154
121
|
const linkedTo = target.slice('link:'.length)
|
|
@@ -159,9 +126,7 @@ export function checkLinkTargets({ id, manifest, importer }, where) {
|
|
|
159
126
|
}
|
|
160
127
|
}
|
|
161
128
|
|
|
162
|
-
//
|
|
163
|
-
// pnpm 11 links it from, its publishConfig.directory among them; and the
|
|
164
|
-
// directory of each by name and version, of which no two may be one.
|
|
129
|
+
// pnpm 11 links a project from its publishConfig.directory too.
|
|
165
130
|
export function indexProjects(projects) {
|
|
166
131
|
const byName = new Map()
|
|
167
132
|
const byDir = new Map()
|
|
@@ -178,29 +143,20 @@ export function indexProjects(projects) {
|
|
|
178
143
|
return { projects, byName, byDir }
|
|
179
144
|
}
|
|
180
145
|
|
|
181
|
-
// checkLinkedPackagesAreUpToDate
|
|
182
|
-
// names, which checkLinkTargets
|
|
183
|
-
// project's package.json as read through the read-package hook, `index`
|
|
184
|
-
// indexProjects's, and `linkWorkspacePackages` the setting.
|
|
146
|
+
// checkLinkedPackagesAreUpToDate on the hooked package.json, less the
|
|
147
|
+
// directories it names, which checkLinkTargets checks.
|
|
185
148
|
export function checkLinkedPackages({ manifest, importer, index: { projects, byName, byDir }, linkWorkspacePackages }, where) {
|
|
186
149
|
const outdated = (detail) => new DeptreeError(`the lockfile is not up to date with this package.json, which pnpm 11 refuses a frozen install for: ${detail}`, where)
|
|
187
150
|
for (const kind of KINDS) {
|
|
188
|
-
const wanted = manifest[kind]
|
|
189
|
-
if (wanted == null) continue
|
|
190
151
|
for (const [alias, target] of Object.entries(importer[kind])) {
|
|
191
|
-
const spec =
|
|
152
|
+
const spec = own(manifest[kind], alias)
|
|
192
153
|
if (!spec) continue
|
|
193
|
-
const here = `${where}.${kind}.${alias}`
|
|
194
154
|
const workspaceRange = spec.startsWith('workspace:') && !isWorkspacePath(spec.slice('workspace:'.length))
|
|
195
155
|
const linked = target.startsWith('link:')
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
// is installed is held to tree.js's checkSource.
|
|
199
|
-
const local = importer.specifiers[alias].startsWith('file:') || packageKeyOf(target).includes('@file:')
|
|
200
|
-
if (local) continue
|
|
156
|
+
// pnpm 11's frozen install skips a local directory or tarball.
|
|
157
|
+
if (importer.specifiers[alias].startsWith('file:') || packageKeyOf(target).includes('@file:')) continue
|
|
201
158
|
if (linked && pathOf(spec) !== undefined) continue
|
|
202
|
-
const name =
|
|
203
|
-
const range = versionRange(spec)
|
|
159
|
+
const { name, range } = parseSpec(spec, alias)
|
|
204
160
|
if (linked && isTag(range)) continue
|
|
205
161
|
const named = byName.get(name)
|
|
206
162
|
const dir = linked ? target.slice('link:'.length) : named?.get(resolvedOf(alias, target))
|
|
@@ -213,7 +169,7 @@ export function checkLinkedPackages({ manifest, importer, index: { projects, byN
|
|
|
213
169
|
if (linked && workspaceRange && named !== undefined && ![...named.values()].some((root) => within(root, dir))) {
|
|
214
170
|
throw outdated(`${alias} is linked to ${quote(dir)}, which is in no workspace package named ${quote(name)}`)
|
|
215
171
|
}
|
|
216
|
-
if (!byDir.has(dir)) throw new DeptreeError(`it is linked to ${quote(dir)}, which is no project, and whose package.json pnpm 11 reads`,
|
|
172
|
+
if (!byDir.has(dir)) throw new DeptreeError(`it is linked to ${quote(dir)}, which is no project, and whose package.json pnpm 11 reads`, `${where}.${kind}.${alias}`)
|
|
217
173
|
const { version } = byDir.get(dir)
|
|
218
174
|
if (linked !== inRange(version, range)) {
|
|
219
175
|
throw outdated(linked ? `the linked workspace package ${alias} (${version ?? 'unknown'}) is not in the range ${quote(spec)}` : `the workspace package ${alias} (${version ?? 'unknown'}) is in the range ${quote(spec)} and not linked`)
|