@preventive/deptree 1.0.0-alpha.4 → 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/patches.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// held to have the patch hash that pick has, so the patch applied here by
|
|
7
|
-
// the key is the one pnpm applies; and, stricter than pnpm, which checks
|
|
8
|
-
// this only when it resolves, every patch configured has to be the pick of
|
|
9
|
-
// some snapshot.
|
|
1
|
+
// pnpm 10 applies the patch patchedDependencies picks for a package's name and
|
|
2
|
+
// version (@pnpm/patching.config's getPatchInfo), not the one its snapshot key
|
|
3
|
+
// names, so every snapshot must name that pick's hash. Every patch must be some
|
|
4
|
+
// snapshot's, which pnpm checks only when resolving. pnpm 9 picks by the
|
|
5
|
+
// selector `name@version` as spelled, else `name`, and takes no range.
|
|
10
6
|
|
|
11
7
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
12
8
|
import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
13
9
|
import { DeptreeError, quote } from '../error.js'
|
|
14
10
|
|
|
15
|
-
// dependency-path's parse of a selector
|
|
16
|
-
// name and anything else after its `@`, or neither.
|
|
11
|
+
// dependency-path's parse of a selector.
|
|
17
12
|
function parseSelector(selector) {
|
|
18
13
|
const at = selector.indexOf('@', 1)
|
|
19
14
|
const rest = at === -1 ? '' : packageKeyOf(selector).slice(at + 1)
|
|
@@ -22,8 +17,7 @@ function parseSelector(selector) {
|
|
|
22
17
|
return isExactVersion(rest) ? { name, version: rest } : { name, range: rest }
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
// groupPatchedDependencies:
|
|
26
|
-
// it; a later one of a kind over an earlier, as pnpm assigns them.
|
|
20
|
+
// groupPatchedDependencies: a later selector of a kind wins, as pnpm assigns.
|
|
27
21
|
function group(selectors) {
|
|
28
22
|
const groups = new Map()
|
|
29
23
|
const of = (name) => {
|
|
@@ -50,12 +44,14 @@ function pick(groups, name, version, where) {
|
|
|
50
44
|
return taking[0]?.selector ?? found.all
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
// pnpm 9's getPatchInfo.
|
|
48
|
+
const pick9 = (hashes, name, version) => [`${name}@${version}`, name].find((selector) => Object.hasOwn(hashes, selector))
|
|
49
|
+
|
|
50
|
+
export function checkPatchUse(lockfile, hashes, major = 10) {
|
|
51
|
+
const groups = major < 10 ? undefined : group(Object.keys(hashes))
|
|
56
52
|
const used = new Set()
|
|
57
53
|
for (const [key, pkg] of Object.entries(lockfile.packages)) {
|
|
58
|
-
const selector = pick(groups, pkg.name, pkg.version, quote(key))
|
|
54
|
+
const selector = major < 10 ? pick9(hashes, pkg.name, pkg.version) : pick(groups, pkg.name, pkg.version, quote(key))
|
|
59
55
|
const wanted = selector === undefined ? undefined : hashes[selector].hash
|
|
60
56
|
if (wanted !== pkg.patchHash) {
|
|
61
57
|
throw new DeptreeError(`pnpm applies ${selector === undefined ? 'no patch' : `the patch of ${quote(selector)}`} to it, and the lockfile names ${pkg.patchHash === undefined ? 'none' : `the patch ${pkg.patchHash}`}`, quote(key))
|
|
@@ -69,7 +65,7 @@ export function checkPatchUse(lockfile, hashes) {
|
|
|
69
65
|
|
|
70
66
|
const PATCH = '(patch_hash='
|
|
71
67
|
|
|
72
|
-
// A key's
|
|
68
|
+
// A key's trailing parenthesized groups, each on its own, and what is
|
|
73
69
|
// before them; undefined where they do not balance.
|
|
74
70
|
function splitSuffix(key) {
|
|
75
71
|
const segments = []
|
|
@@ -88,8 +84,7 @@ function splitSuffix(key) {
|
|
|
88
84
|
return { locator: key.slice(0, end), segments }
|
|
89
85
|
}
|
|
90
86
|
|
|
91
|
-
// dependency-path's parse, of
|
|
92
|
-
// where it is SemVer, and the patch hash.
|
|
87
|
+
// dependency-path's parse, of the name, a SemVer version and the patch hash.
|
|
93
88
|
function parseKey(key) {
|
|
94
89
|
const at = key.indexOf('@', 1)
|
|
95
90
|
if (at === -1 || at === key.length - 1) return {}
|
|
@@ -99,11 +94,9 @@ function parseKey(key) {
|
|
|
99
94
|
return { name: key.slice(0, at), version: valid(base) === null ? undefined : base, hash }
|
|
100
95
|
}
|
|
101
96
|
|
|
102
|
-
// pnpm 11
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
// them out, one of a version of a patched package, has to name the hash of
|
|
106
|
-
// the patch picked for it. One whose hash cannot be told is refused too.
|
|
97
|
+
// pnpm 11's checkPatchedDepPaths (@pnpm/lockfile.fs) checks hashes down through
|
|
98
|
+
// a key's peers too: a peer that names one, or, unless dedupePeers leaves
|
|
99
|
+
// versions out, a version of a patched package.
|
|
107
100
|
export function checkPeerPatches(lockfile, hashes) {
|
|
108
101
|
const groups = group(Object.keys(hashes))
|
|
109
102
|
const carried = lockfile.settings.dedupePeers !== true
|
package/src/pnpm/projects.js
CHANGED
|
@@ -1,60 +1,19 @@
|
|
|
1
|
-
//
|
|
2
|
-
// importer as
|
|
3
|
-
// (@pnpm/lockfile.verification's satisfiesPackageManifest)
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// installs, and an importer none of them is would be left out. A project
|
|
8
|
-
// the lockfile has no importer for pnpm gives an empty one, which it is
|
|
9
|
-
// then held to: one with dependencies is refused as not up to date.
|
|
10
|
-
//
|
|
11
|
-
// A project's specifiers are its dependencies, devDependencies and
|
|
12
|
-
// optionalDependencies, and, with autoInstallPeers, the peerDependencies
|
|
13
|
-
// it does not also list otherwise, which pnpm installs as dependencies;
|
|
14
|
-
// each has to be what the importer records, under the kind pnpm files it
|
|
15
|
-
// under, and a version the importer resolved has to be in its range. Its
|
|
16
|
-
// publishConfig.directory and dependenciesMeta have to be the importer's.
|
|
17
|
-
//
|
|
18
|
-
// Each package.json is read as pnpm reads it before that: through its
|
|
19
|
-
// read-package hook (hook.js), so a direct dependency overridden or an
|
|
20
|
-
// optional one ignored is held to the importer as overridden or left out;
|
|
21
|
-
// and held to the host by its engines (install.js's checkProject). The
|
|
22
|
-
// root one's packageManager, where it names one, has to be the pnpm the
|
|
23
|
-
// tree is built for: pnpm 10 would run that one instead.
|
|
24
|
-
//
|
|
25
|
-
// pnpm 11 lets an optional dependency the importer has no specifier for
|
|
26
|
-
// go unresolved, takes git specifiers of one commit to be the same however
|
|
27
|
-
// spelled, holds publishConfig.linkDirectory to the importer too, and
|
|
28
|
-
// makes frozen.js's further checks.
|
|
29
|
-
//
|
|
30
|
-
// Installs are frozen, always: pnpm 10's further checks without
|
|
31
|
-
// --frozen-lockfile, that workspace packages are linked exactly where
|
|
32
|
-
// their version is in range, are not made; pnpm 11 makes them frozen too.
|
|
1
|
+
// Each project's package.json, read through its read-package hook (hook.js),
|
|
2
|
+
// held to its importer as a frozen install holds it
|
|
3
|
+
// (@pnpm/lockfile.verification's satisfiesPackageManifest). Every importer
|
|
4
|
+
// has to be a project, or pnpm would leave it out. The check pnpm 10 makes
|
|
5
|
+
// only when not frozen, that workspace packages are linked exactly where
|
|
6
|
+
// their version is in range, is not made.
|
|
33
7
|
|
|
34
8
|
import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
35
9
|
import { DeptreeError, difference, quote } from '../error.js'
|
|
10
|
+
import { own, readManifest } from '../manifest.js'
|
|
36
11
|
import { createMatcher } from '../matcher.js'
|
|
37
12
|
import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
|
|
38
13
|
import { checkProject } from './install.js'
|
|
39
14
|
import { validForOldPackages } from './overrides.js'
|
|
40
15
|
import { checkProjectId } from './workspace.js'
|
|
41
16
|
|
|
42
|
-
// A package.json as parsed, as pnpm reads one: a byte order mark dropped,
|
|
43
|
-
// and an object.
|
|
44
|
-
export function readManifest(text, where) {
|
|
45
|
-
if (typeof text !== 'string') throw new TypeError(`${where} must be the text of a package.json`)
|
|
46
|
-
let manifest
|
|
47
|
-
try {
|
|
48
|
-
manifest = JSON.parse(text.replace(/^/u, ''))
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw new DeptreeError(`not JSON: ${error.message}`, where, { cause: error })
|
|
51
|
-
}
|
|
52
|
-
if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) throw new DeptreeError('expected an object', where)
|
|
53
|
-
return manifest
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// The manifests by project, the root one among them, as given by the
|
|
57
|
-
// project's directory relative to the lockfile's.
|
|
58
17
|
export function readManifests(manifests, lockfile) {
|
|
59
18
|
if (manifests === null || typeof manifests !== 'object') throw new TypeError('manifests must map each project\'s directory to its package.json')
|
|
60
19
|
const read = new Map()
|
|
@@ -62,7 +21,6 @@ export function readManifests(manifests, lockfile) {
|
|
|
62
21
|
const where = `manifests[${quote(id)}]`
|
|
63
22
|
if (!(id in lockfile.importers)) {
|
|
64
23
|
checkProjectId(id, where)
|
|
65
|
-
// `made`, as the lockfile has no importer for the project.
|
|
66
24
|
lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true, made: true }
|
|
67
25
|
}
|
|
68
26
|
read.set(id, readManifest(text, where))
|
|
@@ -75,10 +33,7 @@ export function readManifests(manifests, lockfile) {
|
|
|
75
33
|
|
|
76
34
|
const omit = (deps, names) => Object.fromEntries(Object.entries(deps).filter(([name]) => !names.has(name)))
|
|
77
35
|
|
|
78
|
-
// The
|
|
79
|
-
// autoInstallPeers, a peer it does not list elsewhere is a dependency; and
|
|
80
|
-
// those `unresolved` left out. The hook has held each of these fields to a
|
|
81
|
-
// mapping of strings.
|
|
36
|
+
// The hook has held each of these fields to a mapping of strings.
|
|
82
37
|
function wantedOf(manifest, autoInstallPeers, unresolved) {
|
|
83
38
|
const kinds = Object.fromEntries(KINDS.map((kind) => [kind, manifest[kind] ?? {}]))
|
|
84
39
|
let all = omit({ ...kinds.devDependencies, ...kinds.dependencies, ...kinds.optionalDependencies }, unresolved)
|
|
@@ -91,33 +46,32 @@ function wantedOf(manifest, autoInstallPeers, unresolved) {
|
|
|
91
46
|
return { kinds, all }
|
|
92
47
|
}
|
|
93
48
|
|
|
94
|
-
//
|
|
95
|
-
//
|
|
49
|
+
// As the lockfile reader hands dependenciesMeta back: `injected` false where
|
|
50
|
+
// it is not set.
|
|
96
51
|
const metaOf = (meta) => JSON.stringify(Object.entries(meta).map(([name, item]) => [name, item?.injected === true, item?.node]).sort())
|
|
97
52
|
|
|
53
|
+
// pnpm 9 does not hold what a dependency resolved to to its range.
|
|
98
54
|
function checkKind(importer, kinds, kind, unresolved, major) {
|
|
99
55
|
const locked = importer[kind]
|
|
100
56
|
const wanted = kind === 'devDependencies' ? kinds[kind] : omit(kinds[kind], unresolved)
|
|
101
57
|
const names = Object.keys(wanted).filter((name) => kind === 'optionalDependencies'
|
|
102
|
-
|| (!kinds.optionalDependencies
|
|
58
|
+
|| (!own(kinds.optionalDependencies, name) && (kind === 'dependencies' || !own(kinds.dependencies, name))))
|
|
103
59
|
const unlinked = Object.values(locked).filter((target) => !target.includes('link:') && !target.includes('file:')).length
|
|
104
60
|
if (names.length !== Object.keys(locked).length && names.length !== unlinked) return `${kind} in the lockfile do not match the same field in package.json`
|
|
105
61
|
for (const name of names) {
|
|
106
62
|
if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
|
|
107
63
|
const spec = importer.specifiers[name]
|
|
108
|
-
if (validRange(spec) === null) continue
|
|
64
|
+
if (major < 10 || validRange(spec) === null) continue
|
|
109
65
|
const version = resolvedOf(name, locked[name])
|
|
110
66
|
if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
|
|
111
67
|
}
|
|
112
68
|
return undefined
|
|
113
69
|
}
|
|
114
70
|
|
|
115
|
-
// Why pnpm
|
|
116
|
-
//
|
|
117
|
-
// pnpm's diffFlatRecords finds.
|
|
71
|
+
// Why pnpm finds `importer` out of date: of the specifiers, the first
|
|
72
|
+
// difference, as pnpm's diffFlatRecords finds.
|
|
118
73
|
function mismatch(importer, manifest, autoInstallPeers, major, where) {
|
|
119
|
-
const
|
|
120
|
-
const unresolved = new Set(major >= 11 ? Object.keys(optional).filter((name) => importer.specifiers[name] === undefined) : [])
|
|
74
|
+
const unresolved = new Set(major >= 11 ? Object.keys(manifest.optionalDependencies ?? {}).filter((name) => importer.specifiers[name] === undefined) : [])
|
|
121
75
|
const { kinds, all } = wantedOf(manifest, autoInstallPeers, unresolved)
|
|
122
76
|
const specified = difference(importer.specifiers, all, ['the lockfile', 'package.json'], (a, b) => sameSpecifier(a, b, major))
|
|
123
77
|
if (specified !== undefined) return `the specifiers differ: ${specified}`
|
|
@@ -135,8 +89,7 @@ function mismatch(importer, manifest, autoInstallPeers, major, where) {
|
|
|
135
89
|
return undefined
|
|
136
90
|
}
|
|
137
91
|
|
|
138
|
-
// devEngines.packageManager as pnpm 11 reads it
|
|
139
|
-
// else its first, and what to do where it does not match.
|
|
92
|
+
// devEngines.packageManager as pnpm 11 reads it.
|
|
140
93
|
function devEnginesPackageManager(devEngines, where) {
|
|
141
94
|
const engines = devEngines?.packageManager
|
|
142
95
|
if (!engines) return undefined
|
|
@@ -152,21 +105,16 @@ function devEnginesPackageManager(devEngines, where) {
|
|
|
152
105
|
return { name: engine.name, onFail }
|
|
153
106
|
}
|
|
154
107
|
|
|
155
|
-
// The
|
|
156
|
-
// reads it, where it names pnpm at an exact version.
|
|
108
|
+
// The exact pnpm version packageManager names, per pnpm's parsePackageManager.
|
|
157
109
|
export function pinnedPnpm(packageManager) {
|
|
158
110
|
const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
|
|
159
111
|
return isExactVersion(version) ? version : undefined
|
|
160
112
|
}
|
|
161
113
|
|
|
162
|
-
// The
|
|
163
|
-
// (wanted_package_manager): devEngines.packageManager over packageManager,
|
|
164
|
-
// the pnpm one of a list, else its first, whose own onFail it takes, else
|
|
165
|
-
// `error` for the last of a list and `ignore` for another; a version that
|
|
166
|
-
// is not a range is none, and packageManager's has to be exact.
|
|
114
|
+
// The root's pin, as pnpm 12's wanted_package_manager reads it.
|
|
167
115
|
function wantedPackageManager(manifest) {
|
|
168
116
|
const declared = manifest.devEngines?.packageManager
|
|
169
|
-
const list = Array.isArray(declared) ? declared : declared
|
|
117
|
+
const list = Array.isArray(declared) ? declared : declared == null ? [] : [declared]
|
|
170
118
|
const index = Array.isArray(declared) ? Math.max(list.findIndex((entry) => entry?.name === 'pnpm'), 0) : 0
|
|
171
119
|
const entry = list[index]
|
|
172
120
|
if (typeof entry?.name === 'string') {
|
|
@@ -187,14 +135,9 @@ export function pinsPnpm(manifest, pnpm) {
|
|
|
187
135
|
return wanted?.name === 'pnpm' && wanted.version !== undefined && satisfies(pnpm, wanted.version, { includePrerelease: true })
|
|
188
136
|
}
|
|
189
137
|
|
|
190
|
-
// pnpm 12 runs
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
// has none: there has to be one, of `pnpm` alone at the pinned version, or
|
|
194
|
-
// at the running one for a range it is in, and its package. The pnpm that
|
|
195
|
-
// runs has to be in the pin, which it would be switched from or refused
|
|
196
|
-
// by, unless it is only to warn. Another package manager fails it unless
|
|
197
|
-
// it is only to warn.
|
|
138
|
+
// pnpm 12 runs the pnpm the lockfile's env document records for a pin. It
|
|
139
|
+
// records one for a devEngines pin, or a packageManager one of 12 or later,
|
|
140
|
+
// at the pinned version or, for a range, the running one.
|
|
198
141
|
function checkPackageManager12(manifest, host, pmOnFail, env) {
|
|
199
142
|
const wanted = wantedPackageManager(manifest)
|
|
200
143
|
if (wanted === undefined) return
|
|
@@ -217,14 +160,37 @@ function checkPackageManager12(manifest, host, pmOnFail, env) {
|
|
|
217
160
|
}
|
|
218
161
|
}
|
|
219
162
|
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
163
|
+
// pnpm 9's parsePackageManager.
|
|
164
|
+
function parsePackageManager(packageManager) {
|
|
165
|
+
if (!packageManager.includes('@')) return { name: packageManager, version: undefined }
|
|
166
|
+
const [name, reference] = packageManager.split('@')
|
|
167
|
+
return { name, version: reference.includes(':') ? undefined : reference.split('+')[0] }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// pnpm 9 switches to the pnpm packageManager pins only with
|
|
171
|
+
// managePackageManagerVersions; otherwise it refuses another package
|
|
172
|
+
// manager with packageManagerStrict, and another pnpm with that and
|
|
173
|
+
// packageManagerStrictVersion, and installs with itself. 9.15.0 switches
|
|
174
|
+
// to a version semver reads but spells otherwise, and later 9.15s do not.
|
|
175
|
+
function checkPackageManager9(manifest, host, { manage, strict, strictVersion }) {
|
|
176
|
+
const { packageManager } = manifest
|
|
177
|
+
if (!packageManager) return
|
|
178
|
+
const where = 'manifests["."].packageManager'
|
|
179
|
+
if (typeof packageManager !== 'string') throw new DeptreeError('expected a string, which pnpm 9 fails on otherwise', where)
|
|
180
|
+
const { name, version } = parsePackageManager(packageManager)
|
|
181
|
+
if (manage && name === 'pnpm') {
|
|
182
|
+
const exact = version === undefined ? null : valid(version)
|
|
183
|
+
if (version === undefined || version === host.pnpm || exact === null) return
|
|
184
|
+
if (exact !== version.trim()) throw new DeptreeError(`pnpm ${quote(version)} is one pnpm 9.15.0 switches to and a later 9.15 does not, which is not supported`, where)
|
|
185
|
+
throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm 9 switches to with managePackageManagerVersions, not ${host.pnpm}`, where)
|
|
186
|
+
}
|
|
187
|
+
if (name && name !== 'pnpm' && strict) throw new DeptreeError(`the project is installed by ${quote(name)}, which pnpm 9 refuses with packageManagerStrict`, where)
|
|
188
|
+
if (name === 'pnpm' && strict && strictVersion && version && version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, not ${host.pnpm}, which pnpm 9 refuses with packageManagerStrict and packageManagerStrictVersion`, where)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function checkPackageManager(manifest, host, settings, env) {
|
|
192
|
+
const { pmOnFail } = settings
|
|
193
|
+
if (host.major < 10) return checkPackageManager9(manifest, host, settings.packageManagerChecks)
|
|
228
194
|
if (host.major >= 12) return checkPackageManager12(manifest, host, pmOnFail, env)
|
|
229
195
|
const { packageManager } = manifest
|
|
230
196
|
if (host.major >= 11) {
|
|
@@ -241,17 +207,17 @@ function checkPackageManager(manifest, host, pmOnFail, env) {
|
|
|
241
207
|
if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
|
|
242
208
|
}
|
|
243
209
|
|
|
244
|
-
// A runtime pnpm would download
|
|
245
|
-
//
|
|
246
|
-
// project, pnpm 11 takes runtimeOnFail for each one's onFail, and checks a
|
|
247
|
-
// runtime whose onFail is `error` against the host's before it installs.
|
|
210
|
+
// A runtime pnpm would download as a dependency is refused, as the lockfile
|
|
211
|
+
// reader refuses a `runtime:` one.
|
|
248
212
|
const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
|
|
249
213
|
const RUNTIME_NAMES = ['node', 'deno', 'bun']
|
|
250
214
|
function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
215
|
+
// pnpm 9 knows no runtime.
|
|
216
|
+
if (host.major < 10) return
|
|
251
217
|
const checked = new Set()
|
|
252
218
|
for (const [field, kind] of RUNTIMES) {
|
|
253
219
|
const runtime = manifest[field]?.runtime
|
|
254
|
-
if (runtime
|
|
220
|
+
if (runtime == null) continue
|
|
255
221
|
const here = `${where}.${field}.runtime`
|
|
256
222
|
const runtimes = Array.isArray(runtime) ? runtime : [runtime]
|
|
257
223
|
for (const name of RUNTIME_NAMES) {
|
|
@@ -272,23 +238,15 @@ function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
|
272
238
|
}
|
|
273
239
|
}
|
|
274
240
|
|
|
275
|
-
//
|
|
276
|
-
// has no importer for it: any of its devDependencies, or of its
|
|
277
|
-
// dependencies and optionalDependencies, but optional ones it ignores, as
|
|
278
|
-
// its package.json has them; its peers are none.
|
|
241
|
+
// pnpm 12 counts no ignored optional dependency, nor any peer.
|
|
279
242
|
function dependsOn(manifest, ignored) {
|
|
280
243
|
const names = (deps) => (deps !== null && typeof deps === 'object' ? Object.keys(deps) : [])
|
|
281
244
|
const optional = new Set(names(manifest.optionalDependencies).filter((name) => ignored(name)))
|
|
282
245
|
return names(manifest.devDependencies).length > 0 || [...names(manifest.dependencies), ...names(manifest.optionalDependencies)].some((name) => !optional.has(name))
|
|
283
246
|
}
|
|
284
247
|
|
|
285
|
-
// `hook` is hook.js's, which each package.json is read through; `host`
|
|
286
|
-
// and `settings` what its engines are held to; `env` the lockfile's env
|
|
287
|
-
// document, where it has one. pnpm 12 holds a project the lockfile has no
|
|
288
|
-
// importer for to none, if it has no dependencies, and refuses it
|
|
289
|
-
// otherwise; and makes none of pnpm 11's further checks.
|
|
290
248
|
export function checkProjects(lockfile, manifests, { hook, host, settings, env }) {
|
|
291
|
-
checkPackageManager(manifests.get('.'), host, settings
|
|
249
|
+
checkPackageManager(manifests.get('.'), host, settings, env)
|
|
292
250
|
const ignored = createMatcher(settings.ignoredOptionalDependencies ?? [])
|
|
293
251
|
let index
|
|
294
252
|
for (const [id, manifest] of manifests) {
|
|
@@ -312,10 +270,8 @@ export function checkProjects(lockfile, manifests, { hook, host, settings, env }
|
|
|
312
270
|
}
|
|
313
271
|
}
|
|
314
272
|
|
|
315
|
-
// The
|
|
316
|
-
//
|
|
317
|
-
// Two of one name would leave which is hoisted to the order pnpm finds
|
|
318
|
-
// them in, and are refused.
|
|
273
|
+
// The names hoistWorkspacePackages links projects by. Two of one name are
|
|
274
|
+
// refused, as which is hoisted would turn on the order pnpm finds them in.
|
|
319
275
|
export function workspaceNames(manifests) {
|
|
320
276
|
const names = new Map()
|
|
321
277
|
const taken = new Set()
|
package/src/pnpm/readers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Each setting pnpm reads, by its pnpm-workspace.yaml name, is either read
|
|
2
|
+
// and checked (READ, READ_9, READ_11, READ_12) or passed over as leaving
|
|
3
|
+
// the tree as it is (IGNORED, NOT_9, IGNORED_11, IGNORED_12); any other is
|
|
4
|
+
// refused.
|
|
5
5
|
|
|
6
6
|
import { valid } from '@preventive/upstream/semver.js'
|
|
7
7
|
import { DeptreeError, quote } from '../error.js'
|
|
@@ -12,7 +12,6 @@ const IMPORT_METHODS = new Set(['auto', 'hardlink', 'copy', 'clone', 'clone-or-c
|
|
|
12
12
|
|
|
13
13
|
const show = (value) => (typeof value === 'string' ? quote(value) : Array.isArray(value) ? 'a list' : value === null ? 'null' : typeof value === 'object' ? 'a mapping' : String(value))
|
|
14
14
|
|
|
15
|
-
// A reader of one of the values of `allowed`.
|
|
16
15
|
const oneOf = (allowed) => (value, where) => {
|
|
17
16
|
if (allowed.has(value)) return value
|
|
18
17
|
throw new DeptreeError(`expected one of ${[...allowed].join(', ')}, found ${show(value)}`, where)
|
|
@@ -33,18 +32,15 @@ export const readers = {
|
|
|
33
32
|
if (typeof value === 'string') return value
|
|
34
33
|
throw new DeptreeError(`expected a string, found ${show(value)}`, where)
|
|
35
34
|
},
|
|
36
|
-
// A
|
|
35
|
+
// A string alone is a list of it, as pnpm reads a hoist pattern.
|
|
37
36
|
texts(value, where) {
|
|
38
37
|
return readers.list(typeof value === 'string' ? [value] : value, where, 'a string or a list of strings')
|
|
39
38
|
},
|
|
40
|
-
//
|
|
41
|
-
// maps the value.
|
|
39
|
+
// Only a list: pnpm fails on a string alone where it sorts or maps it.
|
|
42
40
|
list(value, where, expected = 'a list of strings') {
|
|
43
41
|
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) throw new DeptreeError(`expected ${expected}, found ${show(value)}`, where)
|
|
44
42
|
return [...value]
|
|
45
43
|
},
|
|
46
|
-
// pnpm-workspace.yaml's `packages`, which pnpm holds to a list of
|
|
47
|
-
// non-empty strings.
|
|
48
44
|
globs(value, where) {
|
|
49
45
|
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || item === '')) throw new DeptreeError(`expected a list of non-empty strings, found ${show(value)}`, where)
|
|
50
46
|
return [...value]
|
|
@@ -58,16 +54,12 @@ export const readers = {
|
|
|
58
54
|
linkWorkspacePackages(value, where) {
|
|
59
55
|
return value === 'deep' ? true : readers.boolean(value, where)
|
|
60
56
|
},
|
|
61
|
-
// true or false, or what to read and write, and a remote cache, which is
|
|
62
|
-
// refused.
|
|
63
57
|
sideEffectsCache(value, where) {
|
|
64
58
|
if (typeof value === 'boolean') return value
|
|
65
59
|
if (readers.mapping(value, where).remote != null) never('what a build left in a remote cache is not restored here')(value.remote, `${where}.remote`)
|
|
66
60
|
return value
|
|
67
61
|
},
|
|
68
|
-
//
|
|
69
|
-
// pnpm 11 takes for a project that pnpm 10 took from its own .npmrc. Of
|
|
70
|
-
// those, where to save and how is all that leaves the tree as it is.
|
|
62
|
+
// pnpm 11's per-project settings: by project name, or a list with `match`.
|
|
71
63
|
packageConfigs(value, where) {
|
|
72
64
|
const configs = Array.isArray(value) ? value.map((item, i) => [i, item]) : Object.entries(readers.mapping(value, where))
|
|
73
65
|
for (const [key, config] of configs) {
|
|
@@ -81,12 +73,10 @@ export const readers = {
|
|
|
81
73
|
},
|
|
82
74
|
}
|
|
83
75
|
|
|
84
|
-
// Read, and held to one value: the default, or the only one built for.
|
|
85
76
|
const only = (kind, wanted, why) => ({ kind, check: (value, where) => {
|
|
86
77
|
if (value !== wanted) throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
|
|
87
78
|
} })
|
|
88
79
|
|
|
89
|
-
// Read, and refused whatever it is.
|
|
90
80
|
const never = (why) => (value, where) => {
|
|
91
81
|
throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
|
|
92
82
|
}
|
|
@@ -135,8 +125,7 @@ export const READ = {
|
|
|
135
125
|
autoInstallPeers: { kind: 'boolean' },
|
|
136
126
|
dedupePeers: { kind: 'boolean' },
|
|
137
127
|
peersSuffixMaxLength: { kind: 'count' },
|
|
138
|
-
// Whether a package
|
|
139
|
-
// its snapshots as one, hardlinked, or each as its own (tree.js).
|
|
128
|
+
// Whether a directory package's snapshots share hardlinked files (tree.js).
|
|
140
129
|
packageImportMethod: { kind: 'importMethod' },
|
|
141
130
|
// Neither pnpm's .npmrc nor ours has these.
|
|
142
131
|
supportedArchitectures: { kind: 'mapping', check: checkArchitectures, rc: false },
|
|
@@ -165,11 +154,8 @@ const READ_11 = {
|
|
|
165
154
|
linkWorkspacePackages: { kind: 'linkWorkspacePackages' },
|
|
166
155
|
}
|
|
167
156
|
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
// rest of what pnpm 11 checks the lockfile against the registry by before
|
|
171
|
-
// it installs — each package's publish time, its tarball URL, its trust —
|
|
172
|
-
// are passed over.
|
|
157
|
+
// The tree follows the lockfile, as pnpm 11's and 12's do with trustLockfile,
|
|
158
|
+
// so what pnpm 11 checks the lockfile against the registry by is passed over.
|
|
173
159
|
const IGNORED_11 = new Set([
|
|
174
160
|
'minimumReleaseAgeIgnoreMissingTime', 'minimumReleaseAgeStrict', 'minimumReleaseAgeExcludePrune', 'trustLockfile',
|
|
175
161
|
'trustPolicy', 'trustPolicyExclude', 'trustPolicyExcludePrune', 'trustPolicyIgnoreAfter', 'pnprServer',
|
|
@@ -186,16 +172,13 @@ const IGNORED_11 = new Set([
|
|
|
186
172
|
'nodeVersionFromEnginesRuntime', 'cliOptions', 'explicitlySetKeys', 'packageManager', 'wantedPackageManager',
|
|
187
173
|
])
|
|
188
174
|
|
|
189
|
-
// What pnpm 12
|
|
190
|
-
// tree as it is — resolution's, the hoisted linker's, the tasks of
|
|
191
|
-
// `pnpm run`, the global install's — and a Cargo or Python install beside
|
|
192
|
-
// the tree's, which is refused where it is enabled.
|
|
175
|
+
// What pnpm 12 adds that leaves an isolated tree as it is.
|
|
193
176
|
const IGNORED_12 = new Set([
|
|
194
177
|
'autoDedupe', 'autoInstallPeersFromHighestMatch', 'externalDependencies', 'hoistingLimits', 'globalShims',
|
|
195
178
|
'concurrencyGroups', 'pipelines', 'pipelineBase', 'publishWaitTimeout', 'saveTypes', 'tools', 'macosBackup',
|
|
196
179
|
])
|
|
197
180
|
const notEnabled = (value, where) => {
|
|
198
|
-
if (value.enabled
|
|
181
|
+
if (value.enabled != null && value.enabled !== false) never('an install of Cargo or Python packages beside the tree is not supported')(value.enabled, `${where}.enabled`)
|
|
199
182
|
}
|
|
200
183
|
const READ_12 = {
|
|
201
184
|
__proto__: null,
|
|
@@ -203,9 +186,6 @@ const READ_12 = {
|
|
|
203
186
|
python: { kind: 'mapping', check: notEnabled },
|
|
204
187
|
}
|
|
205
188
|
|
|
206
|
-
// What pnpm 11 reads or passes over that pnpm 12 does not know: it drops
|
|
207
|
-
// each, and fails on one where the root package.json pins the pnpm that
|
|
208
|
-
// runs.
|
|
209
189
|
const UNRECOGNIZED_12 = new Set([
|
|
210
190
|
'allowNonAppliedPatches', 'alwaysAuth', 'email', 'enginePinManifest', 'ignoreDepScripts', 'ignorePatchFailures',
|
|
211
191
|
'lockfileDirectory', 'managePackageManagerVersions', 'nodeVersionFromEnginesRuntime', 'packageManagerStrict',
|
|
@@ -214,8 +194,26 @@ const UNRECOGNIZED_12 = new Set([
|
|
|
214
194
|
|
|
215
195
|
export const unrecognized12 = (where) => new DeptreeError('pnpm 12 does not know it, and fails on it where the root package.json pins the pnpm that runs', where)
|
|
216
196
|
|
|
217
|
-
//
|
|
218
|
-
//
|
|
197
|
+
// What pnpm 9 reads that pnpm 10 passes over: how it holds the root
|
|
198
|
+
// package.json's packageManager to the pnpm that runs (projects.js).
|
|
199
|
+
const READ_9 = {
|
|
200
|
+
__proto__: null,
|
|
201
|
+
managePackageManagerVersions: { kind: 'boolean' },
|
|
202
|
+
packageManagerStrict: { kind: 'boolean' },
|
|
203
|
+
packageManagerStrictVersion: { kind: 'boolean' },
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// What pnpm 10 reads that pnpm 9 has no setting for, and passes over.
|
|
207
|
+
const NOT_9 = new Set(['dedupePeers', 'enableGlobalVirtualStore', 'injectWorkspacePackages'])
|
|
208
|
+
|
|
209
|
+
// The keys of package.json's `pnpm` pnpm 9 reads, passing over any other.
|
|
210
|
+
export const MANIFEST_KEYS_9 = [
|
|
211
|
+
'allowNonAppliedPatches', 'allowedDeprecatedVersions', 'ignoredOptionalDependencies', 'neverBuiltDependencies',
|
|
212
|
+
'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'overrides', 'packageExtensions', 'patchedDependencies',
|
|
213
|
+
'peerDependencyRules', 'supportedArchitectures',
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
// The keys of package.json's `pnpm` pnpm 10 reads, passing over any other.
|
|
219
217
|
export const MANIFEST_KEYS = [
|
|
220
218
|
'allowBuilds', 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'auditConfig',
|
|
221
219
|
'configDependencies', 'executionEnv', 'ignorePatchFailures', 'ignoredBuiltDependencies', 'ignoredOptionalDependencies',
|
|
@@ -223,21 +221,16 @@ export const MANIFEST_KEYS = [
|
|
|
223
221
|
'patchedDependencies', 'peerDependencyRules', 'requiredScripts', 'supportedArchitectures', 'updateConfig',
|
|
224
222
|
]
|
|
225
223
|
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
// registry alone, through @preventive/upstream, so the network and its
|
|
230
|
-
// credentials are its own; the store, caches and state live outside
|
|
231
|
-
// node_modules; bins are never written here, and scripts never run, as
|
|
232
|
-
// with --ignore-scripts, whatever a setting would allow to build.
|
|
233
|
-
export const IGNORED = new Set([
|
|
224
|
+
// A frozen install holds the lockfile to none of the resolution settings
|
|
225
|
+
// here (uptodate.js has those it does).
|
|
226
|
+
const IGNORED = new Set([
|
|
234
227
|
// resolution, already in the lockfile
|
|
235
228
|
'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
|
|
236
229
|
'dedupeInjectedDeps', 'dedupePeerDependents', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
|
|
237
230
|
'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
|
|
238
231
|
'registrySupportsTimeField', 'resolutionMode', 'resolvePeersFromWorkspaceRoot', 'saveExact', 'savePrefix',
|
|
239
232
|
'saveWorkspaceProtocol', 'strictPeerDependencies',
|
|
240
|
-
// the network
|
|
233
|
+
// the network and its credentials, which @preventive/upstream handles
|
|
241
234
|
'alwaysAuth', 'ca', 'cafile', 'cert', 'email', 'fetchRetries', 'fetchRetryFactor', 'fetchRetryMaxtimeout',
|
|
242
235
|
'fetchRetryMintimeout', 'fetchTimeout', 'httpProxy', 'httpsProxy', 'key', 'localAddress', 'maxsockets',
|
|
243
236
|
'networkConcurrency', 'noProxy', 'noproxy', 'offline', 'preferOffline', 'proxy', 'strictSsl', 'userAgent',
|
|
@@ -262,7 +255,6 @@ export function checkRegistry(value, where) {
|
|
|
262
255
|
if ((value.endsWith('/') ? value : `${value}/`) !== REGISTRY) throw new DeptreeError(`${quote(value)} is not supported: packages are fetched from ${REGISTRY} alone`, where)
|
|
263
256
|
}
|
|
264
257
|
|
|
265
|
-
// pnpm 11's registries: by scope, or `default`, the registry's URL.
|
|
266
258
|
function checkRegistries(value, where) {
|
|
267
259
|
for (const [scope, url] of Object.entries(value)) checkRegistry(readers.text(url, `${where}.${scope}`), `${where}.${scope}`)
|
|
268
260
|
}
|
|
@@ -279,7 +271,6 @@ function checkArchitectures(value, where) {
|
|
|
279
271
|
}
|
|
280
272
|
}
|
|
281
273
|
|
|
282
|
-
// A catalog: by name, the specifier it gives the package.
|
|
283
274
|
function checkCatalog(value, where) {
|
|
284
275
|
for (const [name, spec] of Object.entries(value)) readers.text(spec, `${where}.${name}`)
|
|
285
276
|
}
|
|
@@ -288,11 +279,11 @@ function checkCatalogs(value, where) {
|
|
|
288
279
|
for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
|
|
289
280
|
}
|
|
290
281
|
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
// does not recognize it. Undefined for one not known. pnpm 12 takes a
|
|
294
|
-
// pattern only as a list.
|
|
282
|
+
// `{}` where a setting leaves the tree as it is or pnpm 9 has no such setting,
|
|
283
|
+
// undefined where not known here. pnpm 12 takes a pattern only as a list.
|
|
295
284
|
function lookup(name, major) {
|
|
285
|
+
if (major < 10 && name in READ_9) return { read: READ_9[name] }
|
|
286
|
+
if (major < 10 && NOT_9.has(name)) return {}
|
|
296
287
|
if (major >= 12 && UNRECOGNIZED_12.has(name)) return { unrecognized: true }
|
|
297
288
|
if (major >= 12 && name in READ_12) return { read: READ_12[name] }
|
|
298
289
|
if (major >= 11 && name in READ_11) return { read: READ_11[name] }
|
|
@@ -301,9 +292,12 @@ function lookup(name, major) {
|
|
|
301
292
|
return { read: major >= 12 && READ[name].kind === 'texts' ? { ...READ[name], kind: 'list' } : READ[name] }
|
|
302
293
|
}
|
|
303
294
|
|
|
304
|
-
//
|
|
305
|
-
|
|
306
|
-
|
|
295
|
+
// An .npmrc setting pnpm passes over is undefined.
|
|
296
|
+
export function npmrcReader(name, major) {
|
|
297
|
+
const read = lookup(name, major)?.read
|
|
298
|
+
return read?.rc === false ? undefined : read
|
|
299
|
+
}
|
|
300
|
+
|
|
307
301
|
export function readerOf(name, where, major, pinned = false) {
|
|
308
302
|
const found = lookup(name, major)
|
|
309
303
|
if (found === undefined) throw new DeptreeError('unsupported setting', where)
|
|
@@ -311,14 +305,11 @@ export function readerOf(name, where, major, pinned = false) {
|
|
|
311
305
|
return found.read
|
|
312
306
|
}
|
|
313
307
|
|
|
314
|
-
// Whether pnpm 12 knows a setting, read or passed over, as far as is known
|
|
315
|
-
// here.
|
|
316
308
|
export function known12(name) {
|
|
317
309
|
const found = lookup(name, 12)
|
|
318
310
|
return found !== undefined && !found.unrecognized
|
|
319
311
|
}
|
|
320
312
|
|
|
321
|
-
// By selector, the patch file, relative to the workspace's directory.
|
|
322
313
|
function checkPatches(value, where) {
|
|
323
314
|
for (const [selector, path] of Object.entries(value)) {
|
|
324
315
|
const here = `${where}[${quote(selector)}]`
|