@preventive/deptree 1.0.0-alpha.5 → 1.0.0-alpha.6
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/npm.d.ts +288 -0
- package/npm.js +7 -0
- package/package.json +36 -10
- package/pnpm.d.ts +116 -22
- package/pnpm.js +2 -10
- package/soldeer.d.ts +13 -0
- package/soldeer.js +1 -7
- package/src/concurrent.js +16 -17
- package/src/error.js +5 -9
- package/src/glob.js +55 -0
- package/src/hash.js +64 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +59 -10
- package/src/mount.js +95 -44
- package/src/npm/bins.js +71 -0
- package/src/npm/compat.js +92 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +80 -0
- package/src/npm/manifests.js +138 -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 +136 -0
- package/src/npm/versions.js +20 -0
- package/src/{pnpm/npmrc.js → npmrc.js} +5 -11
- package/src/patch.js +21 -31
- package/src/pnpm/bins.js +32 -103
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +49 -86
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +27 -70
- package/src/pnpm/gitignore.js +137 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +65 -55
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +67 -40
- package/src/pnpm/install.js +72 -115
- package/src/pnpm/local.js +21 -40
- package/src/pnpm/minimatch.js +328 -0
- package/src/pnpm/npm-packlist.js +221 -0
- package/src/pnpm/overrides.js +10 -49
- package/src/pnpm/package.js +120 -0
- package/src/pnpm/packlist.js +168 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +46 -55
- package/src/pnpm/settings.js +60 -97
- package/src/pnpm/tree.js +134 -149
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +122 -131
- package/src/project.js +41 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +2 -5
- package/src/soldeer/tree.js +20 -56
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +38 -142
- package/src/yarn1/bins.js +9 -19
- package/src/yarn1/compat.js +9 -28
- package/src/yarn1/hoist.js +53 -68
- package/src/yarn1/inputs.js +16 -51
- package/src/yarn1/manifest.js +8 -23
- package/src/yarn1/package.js +24 -63
- package/src/yarn1/peers.js +8 -15
- package/src/yarn1/requests.js +19 -37
- package/src/yarn1/resolve.js +35 -111
- package/src/yarn1/settings.js +14 -41
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +30 -2
- package/yarn1.js +1 -8
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/tree.js
CHANGED
|
@@ -1,72 +1,59 @@
|
|
|
1
|
-
//
|
|
2
|
-
// with the isolated linker,
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// node_modules/.pnpm/node_modules and node_modules, and each project's
|
|
6
|
-
// direct dependencies in its own node_modules. Every link is relative, as
|
|
7
|
-
// pnpm makes them outside Windows, and a `link:` leads where the lockfile
|
|
8
|
-
// says whether or not anything is there: the tree holds node_modules and
|
|
9
|
-
// nothing else of the projects.
|
|
10
|
-
//
|
|
11
|
-
// Not written: bins and their shims (node_modules/.bin), though what
|
|
12
|
-
// linking them does to the files they run is (bins.js); .modules.yaml,
|
|
13
|
-
// .pnpm/lock.yaml and the workspace state, which are pnpm's own; and
|
|
14
|
-
// anything a lifecycle script would build. The tree is always the one
|
|
15
|
-
// `pnpm install --ignore-scripts` makes: no script is run, a project's or
|
|
16
|
-
// a dependency's, whatever the settings allow, and patches are applied all
|
|
17
|
-
// the same, as pnpm applies them before any script.
|
|
18
|
-
//
|
|
19
|
-
// Each package is fetched once, and each snapshot's files composed in
|
|
20
|
-
// memory — its package's, patched, bins fixed — before one write of each.
|
|
1
|
+
// The node_modules tree pnpm 9, 10, 11 or 12 installs from a frozen lockfile
|
|
2
|
+
// with the isolated linker and --ignore-scripts, in a Vfs rooted at the
|
|
3
|
+
// lockfile's directory; patched still, as pnpm patches before scripts. Bins are
|
|
4
|
+
// not linked, though what linking does to their files is (bins.js).
|
|
21
5
|
|
|
22
6
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
23
|
-
import { Vfs
|
|
7
|
+
import { Vfs } from '@preventive/vfs'
|
|
24
8
|
import { dirname, relative } from '@preventive/vfs/path.js'
|
|
25
9
|
import { eachConcurrently } from '../concurrent.js'
|
|
26
|
-
import { DeptreeError, quote } from '../error.js'
|
|
27
|
-
import { checkNoModules, mount } from '../mount.js'
|
|
10
|
+
import { DeptreeError, quote, refusalOf } from '../error.js'
|
|
11
|
+
import { checkNoModules, checkWrite, fold, isInside, makeDirs, mount, writeLink } from '../mount.js'
|
|
28
12
|
import { applyPatch, parsePatch } from '../patch.js'
|
|
29
|
-
import {
|
|
13
|
+
import { checkProject, typeOf } from '../project.js'
|
|
14
|
+
import { REGISTRY, tarballUrl } from '../tarball.js'
|
|
30
15
|
import { binTargets, checkPatchOfBins, fixBin, requiresBuild } from './bins.js'
|
|
31
16
|
import { buildGraph } from './graph.js'
|
|
32
17
|
import { hoist } from './hoist.js'
|
|
33
18
|
import { checkLocalOverrides, createFreshnessCheck, readDirectoryPackage, readLinked } from './local.js'
|
|
34
19
|
import { createPatchedCheck, skippedSnapshots } from './install.js'
|
|
35
|
-
import {
|
|
20
|
+
import { checkDependencies, fetchPackage } from './package.js'
|
|
21
|
+
import { checkLinks, checkOptional } from './checks.js'
|
|
36
22
|
import { createHook } from './hook.js'
|
|
37
23
|
import { listOverrides } from './overrides.js'
|
|
38
24
|
import { checkHost, inputsOf, manifestsOf, patchesOf, readLockfile } from './inputs.js'
|
|
39
|
-
import { checkProject } from './project.js'
|
|
40
25
|
import { checkProjects, pinsPnpm, workspaceNames } from './projects.js'
|
|
41
26
|
import { readSettings } from './settings.js'
|
|
42
27
|
import { checkUpToDate } from './uptodate.js'
|
|
43
28
|
import { checkWorkspace } from './workspace.js'
|
|
44
29
|
|
|
45
|
-
//
|
|
46
|
-
|
|
30
|
+
// A project inside a node_modules would be inside the tree; on macOS, a
|
|
31
|
+
// node_modules in any case is one.
|
|
32
|
+
function checkProjectsOutside(ids, folded) {
|
|
33
|
+
for (const id of ids) {
|
|
34
|
+
if (id.split('/').some((name) => name === 'node_modules' || (folded && fold(name) === 'node_modules'))) throw new DeptreeError('a project inside node_modules would be inside the tree', `importers[${quote(id)}]`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function checkLockfile(lockfile, folded) {
|
|
47
39
|
if (lockfile.settings.excludeLinksFromLockfile) throw new DeptreeError('links left out of the lockfile would be left out of the tree', 'settings.excludeLinksFromLockfile')
|
|
48
40
|
if (lockfile.settings.injectWorkspacePackages) throw new DeptreeError('injected workspace packages are not supported', 'settings.injectWorkspacePackages')
|
|
49
41
|
if (lockfile.pnpmfileChecksum !== undefined) throw new DeptreeError('a pnpmfile\'s hooks are not run here', 'pnpmfileChecksum')
|
|
42
|
+
checkProjectsOutside(Object.keys(lockfile.importers), folded)
|
|
50
43
|
for (const [id, importer] of Object.entries(lockfile.importers)) {
|
|
51
44
|
if (id === '..' || id.startsWith('../')) throw new DeptreeError('a project outside the lockfile\'s directory is not supported', `importers[${quote(id)}]`)
|
|
52
|
-
if (id.split('/').includes('node_modules')) throw new DeptreeError('a project inside node_modules would be inside the tree', `importers[${quote(id)}]`)
|
|
53
45
|
for (const [name, meta] of Object.entries(importer.dependenciesMeta)) {
|
|
54
46
|
if (meta.injected) throw new DeptreeError('an injected dependency is not supported', `importers[${quote(id)}].dependenciesMeta[${quote(name)}]`)
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
//
|
|
60
|
-
// fetches it: its key is its name and version, and its resolution a
|
|
61
|
-
// tarball there with a sha512. One pnpm installs from a directory is one
|
|
62
|
-
// a `file:` override names, in `installed`, as local.js reads it, and is
|
|
63
|
-
// not patched: pnpm installs its files by hardlinks, so a patch would be
|
|
64
|
-
// applied to the directory's own.
|
|
51
|
+
// The lockfile reader holds a directory's key to it.
|
|
65
52
|
function checkSource(node, installed) {
|
|
66
53
|
const { key, pkg } = node
|
|
67
54
|
const { resolution } = pkg
|
|
68
55
|
if (resolution.type === 'directory') {
|
|
69
|
-
if (
|
|
56
|
+
if (!installed.has(resolution.directory)) throw new DeptreeError('a dependency on a local directory is supported only where a file: override names it', quote(key))
|
|
70
57
|
if (pkg.patchHash !== undefined) throw new DeptreeError('a patch to a package pnpm installs from a directory is not supported: it would be applied to the directory\'s own files, which pnpm hardlinks', quote(key))
|
|
71
58
|
return
|
|
72
59
|
}
|
|
@@ -76,91 +63,54 @@ function checkSource(node, installed) {
|
|
|
76
63
|
if (!resolution.integrity?.startsWith('sha512-')) throw new DeptreeError('expected a sha512 integrity', quote(key))
|
|
77
64
|
}
|
|
78
65
|
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Each package's files and package.json, by its name and version: a
|
|
84
|
-
// package is fetched once however many snapshots it has, a few at a time.
|
|
85
|
-
// One installed from a directory is read from `project`, as npm-packlist
|
|
86
|
-
// picks its files.
|
|
87
|
-
async function fetchAll(nodes, project, major) {
|
|
88
|
-
const packages = new Map()
|
|
89
|
-
for (const { key, pkg } of nodes.values()) {
|
|
90
|
-
const id = packageKeyOf(key)
|
|
91
|
-
if (!packages.has(id)) packages.set(id, pkg)
|
|
92
|
-
else if (packageFields(packages.get(id)) !== packageFields(pkg)) throw new DeptreeError(`its snapshots differ on what the package is: ${PACKAGE_FIELDS.join(', ')}`, quote(id))
|
|
93
|
-
}
|
|
66
|
+
// By name@version, as the lockfile reader gives a package's snapshots one
|
|
67
|
+
// resolution and manifest.
|
|
68
|
+
async function fetchAll(nodes, project, host) {
|
|
69
|
+
const packages = new Map([...nodes.values()].map(({ key, pkg }) => [packageKeyOf(key), pkg]))
|
|
94
70
|
const fetched = new Map()
|
|
95
71
|
await eachConcurrently(packages, async ([id, pkg]) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const got = readDirectoryPackage(project, pkg, quote(id), major)
|
|
99
|
-
checkManifest(got.manifest, pkg, quote(id), major)
|
|
100
|
-
fetched.set(id, { ...got, local: true })
|
|
101
|
-
} else fetched.set(id, await fetchPackage(pkg, quote(id), major))
|
|
102
|
-
} catch (error) {
|
|
103
|
-
throw error instanceof DeptreeError ? error : new DeptreeError(error.message, quote(id), { cause: error })
|
|
104
|
-
}
|
|
105
|
-
})
|
|
72
|
+
fetched.set(id, pkg.resolution.type === 'directory' ? readDirectoryPackage(project, pkg, quote(id), host) : await fetchPackage(pkg, quote(id), host.major))
|
|
73
|
+
}, ([id]) => quote(id))
|
|
106
74
|
return fetched
|
|
107
75
|
}
|
|
108
76
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
async function fetchNodes(nodes, hook, project, major, fresh) {
|
|
113
|
-
const fetched = await fetchAll(nodes, project, major)
|
|
77
|
+
async function fetchNodes(nodes, lockfile, hook, project, host) {
|
|
78
|
+
const fetched = await fetchAll(nodes, project, host)
|
|
79
|
+
const fresh = createFreshnessCheck(lockfile, host.major)
|
|
114
80
|
const byDir = new Map()
|
|
115
81
|
for (const node of nodes.values()) {
|
|
116
82
|
const id = packageKeyOf(node.key)
|
|
117
83
|
const got = fetched.get(id)
|
|
118
84
|
got.read ??= hook(got.manifest, `${quote(id)}: package.json`)
|
|
119
|
-
checkDependencies(got.manifest, got.read, node.pkg, quote(node.key))
|
|
85
|
+
checkDependencies(got.manifest, got.read, node.pkg, lockfile.packages, quote(node.key))
|
|
120
86
|
fresh?.(node, got.read)
|
|
121
87
|
byDir.set(node.dir, { ...node, files: got.files, manifest: got.manifest })
|
|
122
88
|
}
|
|
123
89
|
return { byDir, tarballs: [...fetched.values()].filter((got) => !got.local).length }
|
|
124
90
|
}
|
|
125
91
|
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
// copy instead where pnpm builds the package, or, with pnpm 11 and 12,
|
|
131
|
-
// where packageImportMethod is other than auto or hardlink. By
|
|
132
|
-
// directory, the files a snapshot has made executable by another's:
|
|
133
|
-
// `targets` is binTargets's.
|
|
92
|
+
// pnpm hardlinks a directory package's files into each of its snapshots, so a
|
|
93
|
+
// file fixBin makes executable in one is so in all (a CRLF `#!` it rewrites
|
|
94
|
+
// stays that snapshot's own), but where pnpm builds the package or, with
|
|
95
|
+
// pnpm 11 and 12, packageImportMethod is neither auto nor hardlink.
|
|
134
96
|
function executableElsewhere(byDir, targets, packageImportMethod, major) {
|
|
135
|
-
|
|
136
|
-
const shared = [...byDir.values()].filter((node) =>
|
|
137
|
-
const byPackage =
|
|
138
|
-
|
|
139
|
-
const id = packageKeyOf(node.key)
|
|
140
|
-
if (!byPackage.has(id)) byPackage.set(id, new Set())
|
|
141
|
-
for (const path of targets.get(node.dir) ?? []) byPackage.get(id).add(path)
|
|
142
|
-
}
|
|
143
|
-
const executable = new Map()
|
|
144
|
-
for (const node of shared) {
|
|
97
|
+
if (major >= 11 && packageImportMethod !== 'auto' && packageImportMethod !== 'hardlink') return new Map()
|
|
98
|
+
const shared = [...byDir.values()].filter((node) => node.pkg.resolution.type === 'directory' && !requiresBuild(node.manifest, node.files, major))
|
|
99
|
+
const byPackage = Map.groupBy(shared, (node) => packageKeyOf(node.key))
|
|
100
|
+
return new Map(shared.map((node) => {
|
|
145
101
|
const own = targets.get(node.dir) ?? new Set()
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
102
|
+
const all = byPackage.get(packageKeyOf(node.key)).flatMap((other) => [...targets.get(other.dir) ?? []])
|
|
103
|
+
return [node.dir, new Set(all.filter((path) => !own.has(path)))]
|
|
104
|
+
}))
|
|
149
105
|
}
|
|
150
106
|
|
|
151
|
-
// A snapshot's files as pnpm leaves them: its package's, the patch the
|
|
152
|
-
// snapshot names applied, and what linking bins does to them: fixBin run
|
|
153
|
-
// on `targets`, and `executable` made so. `checkPatched` is
|
|
154
|
-
// createPatchedCheck's.
|
|
155
107
|
function compose(node, patches, { targets, executable }, { major, checkPatched }) {
|
|
156
108
|
const where = quote(node.key)
|
|
157
109
|
let files = node.files
|
|
158
110
|
const { patchHash } = node.pkg
|
|
159
111
|
if (patchHash !== undefined) {
|
|
160
|
-
if (!patches.has(patchHash)) throw new DeptreeError(`the patch ${patchHash} is not given`, where)
|
|
161
112
|
const patch = patches.get(patchHash)
|
|
162
113
|
patch.parsed ??= parsePatch(patch.text, patch.path)
|
|
163
|
-
// Once for each package, whatever its snapshots.
|
|
164
114
|
patch.applied ??= new WeakMap()
|
|
165
115
|
if (!patch.applied.has(files)) patch.applied.set(files, applyPatch(files, patch.parsed, { createdMode: major >= 12 ? 0o644 : undefined }))
|
|
166
116
|
files = patch.applied.get(files)
|
|
@@ -174,36 +124,76 @@ function compose(node, patches, { targets, executable }, { major, checkPatched }
|
|
|
174
124
|
return files
|
|
175
125
|
}
|
|
176
126
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
127
|
+
function addMade(made, dir) {
|
|
128
|
+
for (let at = dir; !made.has(at) && at !== '/'; at = dirname(at)) made.add(at)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Only this node writes under `dir`, and the tree holds no links yet, so `made`
|
|
132
|
+
// knows every directory there and no write needs a look first, which costs a
|
|
133
|
+
// thrown error where nothing is.
|
|
134
|
+
function writeNode(vfs, dir, files, stats) {
|
|
135
|
+
const root = `/${dir}`
|
|
136
|
+
if (typeOf(vfs, root, false) !== undefined) throw new DeptreeError('would be written over with something else', quote(dir))
|
|
137
|
+
const real = new Set()
|
|
138
|
+
makeDirs(vfs, dir, real)
|
|
139
|
+
const made = new Set([root])
|
|
140
|
+
for (const [path, file] of files) {
|
|
141
|
+
const at = `${root}/${path}`
|
|
142
|
+
if (file.directory) {
|
|
143
|
+
if (!isInside(path)) throw new DeptreeError('is not a path within the package', quote(at.slice(1)))
|
|
144
|
+
makeDirs(vfs, at.slice(1), real)
|
|
145
|
+
addMade(made, at)
|
|
146
|
+
continue
|
|
147
|
+
}
|
|
148
|
+
if (made.has(at)) throw new DeptreeError('would be written over with something else', quote(at.slice(1)))
|
|
149
|
+
const parent = dirname(at)
|
|
150
|
+
if (!made.has(parent)) {
|
|
151
|
+
makeDirs(vfs, parent.slice(1), real)
|
|
152
|
+
addMade(made, parent)
|
|
153
|
+
}
|
|
154
|
+
vfs.writeFile(checkWrite(vfs, dir, path, real), file.data, { mode: file.mode })
|
|
155
|
+
stats.files++
|
|
156
|
+
stats.bytes += file.data.length
|
|
188
157
|
}
|
|
189
|
-
if (there.type === 'file' && there.mode === mode && sameBytes(vfs.readFile(path), data)) return false
|
|
190
|
-
throw new DeptreeError('would be written over with something else', quote(path.slice(1)))
|
|
191
158
|
}
|
|
192
159
|
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
// read under as many directories as it climbs.
|
|
160
|
+
// As pnpm's symlink-dir spells it. A target may climb out of the tree, so both
|
|
161
|
+
// are resolved under as many dummy directories as it climbs.
|
|
196
162
|
function linkTarget(path, target) {
|
|
197
163
|
const climbs = target.split('/').filter((segment) => segment === '..').length
|
|
198
164
|
const root = '/_'.repeat(climbs)
|
|
199
165
|
return relative(`${root}/${dirname(path)}`, `${root}/${target}`) || '.'
|
|
200
166
|
}
|
|
201
167
|
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
168
|
+
// What no project's dependencies or optionalDependencies reach is dev-only.
|
|
169
|
+
function reachedInProd(importers, nodes, byDir) {
|
|
170
|
+
const reached = new Set(Object.values(importers)
|
|
171
|
+
.flatMap(({ dependencies, optionalDependencies }) => [...Object.values(dependencies), ...Object.values(optionalDependencies)])
|
|
172
|
+
.map((target) => nodes.get(target)?.dir)
|
|
173
|
+
.filter((dir) => byDir.has(dir)))
|
|
174
|
+
for (const dir of reached) {
|
|
175
|
+
for (const child of byDir.get(dir).children.values()) if (byDir.has(child)) reached.add(child)
|
|
176
|
+
}
|
|
177
|
+
return reached
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function installedOf(node, dev, patches) {
|
|
181
|
+
const { key, name, dir, pkg: { version, resolution, optional, patchHash } } = node
|
|
182
|
+
return {
|
|
183
|
+
path: dir,
|
|
184
|
+
key,
|
|
185
|
+
name,
|
|
186
|
+
version,
|
|
187
|
+
integrity: resolution.integrity,
|
|
188
|
+
directory: resolution.directory,
|
|
189
|
+
dev,
|
|
190
|
+
optional,
|
|
191
|
+
patch: patchHash === undefined ? undefined : { hash: patchHash, path: patches.get(patchHash).path },
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Later links win: each node's children, then what is hoisted, then each
|
|
196
|
+
// project's direct dependencies.
|
|
207
197
|
function linksOf(byDir, direct, settings, projects, major, hoisting) {
|
|
208
198
|
const links = new Map()
|
|
209
199
|
for (const node of byDir.values()) {
|
|
@@ -230,29 +220,34 @@ export async function buildPnpmTree(options) {
|
|
|
230
220
|
const { lockfile, env } = readLockfile(inputs.lockfile)
|
|
231
221
|
if (!('.' in lockfile.importers)) throw new DeptreeError('expected the root project, whose package.json holds settings', 'importers')
|
|
232
222
|
// Before the project is read for any importer: none leads out of it.
|
|
233
|
-
checkLockfile(lockfile)
|
|
223
|
+
checkLockfile(lockfile, folded)
|
|
234
224
|
const { manifests, pnpm, major, workspace } = manifestsOf(inputs, lockfile, given.pnpm)
|
|
225
|
+
// Again with the projects given that the lockfile has no importer for.
|
|
226
|
+
checkProjectsOutside(Object.keys(lockfile.importers), folded)
|
|
235
227
|
const host = { pnpm, major, ...machine }
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
if (env !== undefined &&
|
|
228
|
+
// The env document locks config dependencies, refused, and the pnpm a project
|
|
229
|
+
// pins, which leaves the tree as it is.
|
|
230
|
+
if (env !== undefined && major < 11) throw new DeptreeError('the env document pnpm 11 writes is not supported', 'env')
|
|
239
231
|
if (env !== undefined && Object.keys(env.importers['.'].configDependencies).length > 0) throw new DeptreeError('config dependencies are not supported', 'env.importers["."].configDependencies')
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
232
|
+
// As pnpm 9, 10 and 11 write the lockfile's own directory.
|
|
233
|
+
const empty = major >= 12 ? Object.keys(lockfile.packages).find((key) => packageKeyOf(key).endsWith('@file:')) : undefined
|
|
234
|
+
if (empty !== undefined) throw new DeptreeError('pnpm 12 refuses as broken a lockfile with `file:` and an empty path', quote(empty))
|
|
235
|
+
const settings = readSettings({ workspace, npmrc: inputs.npmrc, manifest: manifests.get('.'), major, pinned: pinsPnpm(manifests.get('.'), host.pnpm) })
|
|
236
|
+
checkWorkspace(Object.keys(lockfile.importers), settings.packages, major)
|
|
237
|
+
const overrides = listOverrides(settings.overrides, settings.catalogs, major)
|
|
243
238
|
const installed = checkLocalOverrides(overrides, project)
|
|
244
239
|
const patches = patchesOf(inputs, settings.patchedDependencies)
|
|
245
|
-
const patched = await checkUpToDate(lockfile, settings, overrides, patches,
|
|
246
|
-
const hook = createHook({ overrides, ignored: settings.ignoredOptionalDependencies, major
|
|
240
|
+
const patched = await checkUpToDate(lockfile, settings, overrides, patches, major)
|
|
241
|
+
const hook = createHook({ overrides, ignored: settings.ignoredOptionalDependencies, major })
|
|
247
242
|
checkProjects(lockfile, manifests, { hook, host, settings, env })
|
|
248
243
|
checkOptional(lockfile)
|
|
249
244
|
const projects = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
|
|
250
245
|
const { skipped, incompatible } = skippedSnapshots(lockfile, { host, settings })
|
|
251
|
-
const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength,
|
|
246
|
+
const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength, major)
|
|
252
247
|
for (const node of nodes.values()) checkSource(node, installed)
|
|
253
248
|
|
|
254
|
-
const { byDir, tarballs } = await fetchNodes(nodes, hook, project, host
|
|
255
|
-
const links = linksOf(byDir, direct, settings, projects,
|
|
249
|
+
const { byDir, tarballs } = await fetchNodes(nodes, lockfile, hook, project, host)
|
|
250
|
+
const links = linksOf(byDir, direct, settings, projects, major, hoisting)
|
|
256
251
|
const linked = readLinked(links, byDir, manifests, project)
|
|
257
252
|
const targets = binTargets({
|
|
258
253
|
nodes: byDir,
|
|
@@ -262,43 +257,33 @@ export async function buildPnpmTree(options) {
|
|
|
262
257
|
publicHoist: settings.publicHoistPattern?.length > 0,
|
|
263
258
|
building: Object.keys(settings.patchedDependencies ?? {}).length > 0,
|
|
264
259
|
peers: settings.autoInstallPeers,
|
|
265
|
-
major
|
|
260
|
+
major,
|
|
266
261
|
})
|
|
267
|
-
const executable = executableElsewhere(byDir, targets, settings.packageImportMethod,
|
|
262
|
+
const executable = executableElsewhere(byDir, targets, settings.packageImportMethod, major)
|
|
263
|
+
const prod = reachedInProd(lockfile.importers, nodes, byDir)
|
|
268
264
|
|
|
269
265
|
const vfs = new Vfs()
|
|
270
|
-
vfs
|
|
271
|
-
const stats = { projects: manifests.size, snapshots: Object.keys(lockfile.packages).length, installed: nodes.size, skipped: skipped.size, incompatible: incompatible.size, tarballs, patched:
|
|
272
|
-
const
|
|
266
|
+
makeDirs(vfs, 'node_modules/.pnpm')
|
|
267
|
+
const stats = { projects: manifests.size, snapshots: Object.keys(lockfile.packages).length, installed: nodes.size, skipped: skipped.size, incompatible: incompatible.size, tarballs, patched: [...nodes.values()].filter((node) => node.pkg.patchHash !== undefined).length, files: 0, bytes: 0, links: links.size }
|
|
268
|
+
const listed = []
|
|
269
|
+
const composing = { major, checkPatched: createPatchedCheck({ host, settings }) }
|
|
273
270
|
// Each node is let go once written, and a package's files with its last.
|
|
274
271
|
for (const node of byDir.values()) {
|
|
275
272
|
byDir.delete(node.dir)
|
|
276
|
-
if (node.pkg.patchHash !== undefined) stats.patched++
|
|
277
273
|
try {
|
|
278
|
-
vfs.
|
|
279
|
-
for (const [path, file] of compose(node, patched, { targets: targets.get(node.dir) ?? new Set(), executable: executable.get(node.dir) ?? new Set() }, composing)) {
|
|
280
|
-
if (file.directory) vfs.mkdir(`/${node.dir}/${path}`, { recursive: true })
|
|
281
|
-
else if (writeOnce(vfs, `/${node.dir}/${path}`, file)) {
|
|
282
|
-
stats.files++
|
|
283
|
-
stats.bytes += file.data.length
|
|
284
|
-
}
|
|
285
|
-
}
|
|
274
|
+
writeNode(vfs, node.dir, compose(node, patched, { targets: targets.get(node.dir) ?? new Set(), executable: executable.get(node.dir) ?? new Set() }, composing), stats)
|
|
286
275
|
} catch (error) {
|
|
287
|
-
|
|
288
|
-
throw new DeptreeError(error.message, quote(node.key), { cause: error })
|
|
276
|
+
throw refusalOf(error, quote(node.key))
|
|
289
277
|
}
|
|
278
|
+
listed.push(installedOf(node, !prod.has(node.dir), patched))
|
|
290
279
|
}
|
|
291
280
|
for (const [path, target] of links) {
|
|
292
281
|
try {
|
|
293
|
-
vfs
|
|
294
|
-
vfs.symlink(linkTarget(path, target), `/${path}`)
|
|
282
|
+
writeLink(vfs, path, linkTarget(path, target))
|
|
295
283
|
} catch (error) {
|
|
296
284
|
throw new DeptreeError(`cannot be linked: ${error.message}`, quote(path), { cause: error })
|
|
297
285
|
}
|
|
298
286
|
}
|
|
299
287
|
checkLinks(vfs, links)
|
|
300
|
-
|
|
301
|
-
if (into === undefined) return { vfs, stats }
|
|
302
|
-
mount(vfs, into, folded)
|
|
303
|
-
return { vfs: into, stats }
|
|
288
|
+
return { vfs: mount(vfs, into, folded), stats, installed: listed }
|
|
304
289
|
}
|
package/src/pnpm/uptodate.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// catalogs
|
|
5
|
-
// dependencies left out, the patches, and a few of its own settings. Where
|
|
6
|
-
// one differs, `--frozen-lockfile` refuses to install, and so does this,
|
|
7
|
-
// naming the setting as pnpm names it. An install here is always frozen.
|
|
8
|
-
// pnpm 11 takes two git specifiers of one commit in a catalog alike, and
|
|
9
|
-
// holds the patch hashes in the peers of a key to the patches too.
|
|
10
|
-
//
|
|
11
|
-
// The patches are hashed here, all of them, as pnpm reads every one it is
|
|
12
|
-
// configured with, whether or not a package installed uses it; each has to
|
|
13
|
-
// be given, by the path the settings name it by, and nothing else may be.
|
|
14
|
-
// Only one a package installed uses is read as a patch, where it is
|
|
15
|
-
// applied, as pnpm reads it.
|
|
1
|
+
// Refuses a lockfile a frozen install would refuse as out of date with the
|
|
2
|
+
// settings (@pnpm/lockfile.settings-checker's getOutdatedLockfileSetting),
|
|
3
|
+
// naming the setting as pnpm names it. pnpm 9 holds the lockfile to neither the
|
|
4
|
+
// catalogs nor dedupePeers.
|
|
16
5
|
|
|
17
6
|
import { normalize } from '@preventive/vfs/path.js'
|
|
18
7
|
import { DeptreeError, difference, quote } from '../error.js'
|
|
19
|
-
import { sha256Hex } from '../hash.js'
|
|
8
|
+
import { md5Base32, sha256Hex } from '../hash.js'
|
|
20
9
|
import { sameSpecifier } from './frozen.js'
|
|
10
|
+
import { catalogEntry } from './overrides.js'
|
|
21
11
|
import { checkPatchUse, checkPeerPatches } from './patches.js'
|
|
22
12
|
|
|
23
13
|
const outdated = (name, detail) => new DeptreeError(`${detail}, which a frozen install refuses`, name)
|
|
24
14
|
|
|
25
15
|
const SIDES = ['the lockfile', 'the settings']
|
|
26
16
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
async function hashPatches(configured, given) {
|
|
17
|
+
// `hashes` is { hash, path } by selector, `byHash` { text, path } by hash.
|
|
18
|
+
async function hashPatches(configured, given, major) {
|
|
30
19
|
const texts = new Map()
|
|
31
20
|
for (const [key, text] of given) {
|
|
32
21
|
const path = normalize(key)
|
|
@@ -41,7 +30,9 @@ async function hashPatches(configured, given) {
|
|
|
41
30
|
named.add(path)
|
|
42
31
|
if (!texts.has(path)) throw new DeptreeError(`the patch ${quote(path)} is not given, and pnpm reads every patch it is configured with`, `patchedDependencies[${quote(selector)}]`)
|
|
43
32
|
const text = texts.get(path)
|
|
44
|
-
const
|
|
33
|
+
const normalized = text.replaceAll('\r\n', '\n')
|
|
34
|
+
const where = `patches[${quote(path)}]`
|
|
35
|
+
const hash = major < 10 ? md5Base32(normalized, where) : await sha256Hex(normalized, where)
|
|
45
36
|
hashes[selector] = { hash, path }
|
|
46
37
|
if (!byHash.has(hash)) byHash.set(hash, { text, path })
|
|
47
38
|
}
|
|
@@ -58,14 +49,11 @@ function checkPatches(locked, hashes, major) {
|
|
|
58
49
|
if (detail !== undefined) throw outdated('patchedDependencies', `the patches differ: ${detail}`)
|
|
59
50
|
}
|
|
60
51
|
|
|
61
|
-
// Throws where pnpm would not install the lockfile as it is; hands back the
|
|
62
|
-
// patches by hash, their text and path, to apply where a snapshot names one.
|
|
63
|
-
// `overrides` is listOverrides's.
|
|
64
52
|
export async function checkUpToDate(lockfile, settings, overrides, given, major) {
|
|
65
|
-
const { hashes, byHash } = await hashPatches(settings.patchedDependencies, given)
|
|
66
|
-
for (const [name, catalog] of Object.entries(lockfile.catalogs)) {
|
|
53
|
+
const { hashes, byHash } = await hashPatches(settings.patchedDependencies, given, major)
|
|
54
|
+
for (const [name, catalog] of major < 10 ? [] : Object.entries(lockfile.catalogs)) {
|
|
67
55
|
for (const [alias, { specifier }] of Object.entries(catalog)) {
|
|
68
|
-
const configured = settings.catalogs
|
|
56
|
+
const configured = catalogEntry(settings.catalogs, name, alias)
|
|
69
57
|
if (!sameSpecifier(specifier, configured, major)) throw outdated('catalogs', `${quote(alias)} is ${quote(specifier)} in the lockfile's catalog ${quote(name)}, and ${configured === undefined ? 'nothing' : quote(configured)} in the settings`)
|
|
70
58
|
}
|
|
71
59
|
}
|
|
@@ -79,9 +67,9 @@ export async function checkUpToDate(lockfile, settings, overrides, given, major)
|
|
|
79
67
|
checkPatches(lockfile.patchedDependencies, hashes, major)
|
|
80
68
|
const locked = lockfile.settings
|
|
81
69
|
if (locked.autoInstallPeers !== undefined && locked.autoInstallPeers !== settings.autoInstallPeers) throw outdated('settings.autoInstallPeers', `autoInstallPeers is ${locked.autoInstallPeers} in the lockfile`)
|
|
82
|
-
if (Boolean(locked.dedupePeers) !== settings.dedupePeers) throw outdated('settings.dedupePeers', `dedupePeers is ${Boolean(locked.dedupePeers)} in the lockfile`)
|
|
70
|
+
if (major >= 10 && Boolean(locked.dedupePeers) !== settings.dedupePeers) throw outdated('settings.dedupePeers', `dedupePeers is ${Boolean(locked.dedupePeers)} in the lockfile`)
|
|
83
71
|
if ((locked.peersSuffixMaxLength ?? 1000) !== settings.peersSuffixMaxLength) throw outdated('settings.peersSuffixMaxLength', `peersSuffixMaxLength is ${locked.peersSuffixMaxLength ?? 'left at 1000'} in the lockfile`)
|
|
84
|
-
checkPatchUse(lockfile, hashes)
|
|
72
|
+
checkPatchUse(lockfile, hashes, major)
|
|
85
73
|
if (major >= 11) checkPeerPatches(lockfile, hashes)
|
|
86
74
|
return byHash
|
|
87
75
|
}
|