@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.11
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 +325 -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 +96 -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/projects.js
CHANGED
|
@@ -1,59 +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'
|
|
11
|
+
import { createMatcher } from '../matcher.js'
|
|
36
12
|
import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
|
|
37
13
|
import { checkProject } from './install.js'
|
|
38
14
|
import { validForOldPackages } from './overrides.js'
|
|
39
15
|
import { checkProjectId } from './workspace.js'
|
|
40
16
|
|
|
41
|
-
// A package.json as parsed, as pnpm reads one: a byte order mark dropped,
|
|
42
|
-
// and an object.
|
|
43
|
-
export function readManifest(text, where) {
|
|
44
|
-
if (typeof text !== 'string') throw new TypeError(`${where} must be the text of a package.json`)
|
|
45
|
-
let manifest
|
|
46
|
-
try {
|
|
47
|
-
manifest = JSON.parse(text.replace(/^/u, ''))
|
|
48
|
-
} catch (error) {
|
|
49
|
-
throw new DeptreeError(`not JSON: ${error.message}`, where, { cause: error })
|
|
50
|
-
}
|
|
51
|
-
if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) throw new DeptreeError('expected an object', where)
|
|
52
|
-
return manifest
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// The manifests by project, the root one among them, as given by the
|
|
56
|
-
// project's directory relative to the lockfile's.
|
|
57
17
|
export function readManifests(manifests, lockfile) {
|
|
58
18
|
if (manifests === null || typeof manifests !== 'object') throw new TypeError('manifests must map each project\'s directory to its package.json')
|
|
59
19
|
const read = new Map()
|
|
@@ -61,7 +21,7 @@ export function readManifests(manifests, lockfile) {
|
|
|
61
21
|
const where = `manifests[${quote(id)}]`
|
|
62
22
|
if (!(id in lockfile.importers)) {
|
|
63
23
|
checkProjectId(id, where)
|
|
64
|
-
lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true }
|
|
24
|
+
lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true, made: true }
|
|
65
25
|
}
|
|
66
26
|
read.set(id, readManifest(text, where))
|
|
67
27
|
}
|
|
@@ -73,10 +33,7 @@ export function readManifests(manifests, lockfile) {
|
|
|
73
33
|
|
|
74
34
|
const omit = (deps, names) => Object.fromEntries(Object.entries(deps).filter(([name]) => !names.has(name)))
|
|
75
35
|
|
|
76
|
-
// The
|
|
77
|
-
// autoInstallPeers, a peer it does not list elsewhere is a dependency; and
|
|
78
|
-
// those `unresolved` left out. The hook has held each of these fields to a
|
|
79
|
-
// mapping of strings.
|
|
36
|
+
// The hook has held each of these fields to a mapping of strings.
|
|
80
37
|
function wantedOf(manifest, autoInstallPeers, unresolved) {
|
|
81
38
|
const kinds = Object.fromEntries(KINDS.map((kind) => [kind, manifest[kind] ?? {}]))
|
|
82
39
|
let all = omit({ ...kinds.devDependencies, ...kinds.dependencies, ...kinds.optionalDependencies }, unresolved)
|
|
@@ -89,33 +46,32 @@ function wantedOf(manifest, autoInstallPeers, unresolved) {
|
|
|
89
46
|
return { kinds, all }
|
|
90
47
|
}
|
|
91
48
|
|
|
92
|
-
//
|
|
93
|
-
//
|
|
49
|
+
// As the lockfile reader hands dependenciesMeta back: `injected` false where
|
|
50
|
+
// it is not set.
|
|
94
51
|
const metaOf = (meta) => JSON.stringify(Object.entries(meta).map(([name, item]) => [name, item?.injected === true, item?.node]).sort())
|
|
95
52
|
|
|
53
|
+
// pnpm 9 does not hold what a dependency resolved to to its range.
|
|
96
54
|
function checkKind(importer, kinds, kind, unresolved, major) {
|
|
97
55
|
const locked = importer[kind]
|
|
98
56
|
const wanted = kind === 'devDependencies' ? kinds[kind] : omit(kinds[kind], unresolved)
|
|
99
57
|
const names = Object.keys(wanted).filter((name) => kind === 'optionalDependencies'
|
|
100
|
-
|| (!kinds.optionalDependencies
|
|
58
|
+
|| (!own(kinds.optionalDependencies, name) && (kind === 'dependencies' || !own(kinds.dependencies, name))))
|
|
101
59
|
const unlinked = Object.values(locked).filter((target) => !target.includes('link:') && !target.includes('file:')).length
|
|
102
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`
|
|
103
61
|
for (const name of names) {
|
|
104
62
|
if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
|
|
105
63
|
const spec = importer.specifiers[name]
|
|
106
|
-
if (validRange(spec) === null) continue
|
|
64
|
+
if (major < 10 || validRange(spec) === null) continue
|
|
107
65
|
const version = resolvedOf(name, locked[name])
|
|
108
66
|
if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
|
|
109
67
|
}
|
|
110
68
|
return undefined
|
|
111
69
|
}
|
|
112
70
|
|
|
113
|
-
// Why pnpm
|
|
114
|
-
//
|
|
115
|
-
// pnpm's diffFlatRecords finds.
|
|
71
|
+
// Why pnpm finds `importer` out of date: of the specifiers, the first
|
|
72
|
+
// difference, as pnpm's diffFlatRecords finds.
|
|
116
73
|
function mismatch(importer, manifest, autoInstallPeers, major, where) {
|
|
117
|
-
const
|
|
118
|
-
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) : [])
|
|
119
75
|
const { kinds, all } = wantedOf(manifest, autoInstallPeers, unresolved)
|
|
120
76
|
const specified = difference(importer.specifiers, all, ['the lockfile', 'package.json'], (a, b) => sameSpecifier(a, b, major))
|
|
121
77
|
if (specified !== undefined) return `the specifiers differ: ${specified}`
|
|
@@ -133,8 +89,7 @@ function mismatch(importer, manifest, autoInstallPeers, major, where) {
|
|
|
133
89
|
return undefined
|
|
134
90
|
}
|
|
135
91
|
|
|
136
|
-
// devEngines.packageManager as pnpm 11 reads it
|
|
137
|
-
// else its first, and what to do where it does not match.
|
|
92
|
+
// devEngines.packageManager as pnpm 11 reads it.
|
|
138
93
|
function devEnginesPackageManager(devEngines, where) {
|
|
139
94
|
const engines = devEngines?.packageManager
|
|
140
95
|
if (!engines) return undefined
|
|
@@ -150,13 +105,93 @@ function devEnginesPackageManager(devEngines, where) {
|
|
|
150
105
|
return { name: engine.name, onFail }
|
|
151
106
|
}
|
|
152
107
|
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
108
|
+
// The exact pnpm version packageManager names, per pnpm's parsePackageManager.
|
|
109
|
+
export function pinnedPnpm(packageManager) {
|
|
110
|
+
const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
|
|
111
|
+
return isExactVersion(version) ? version : undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The root's pin, as pnpm 12's wanted_package_manager reads it.
|
|
115
|
+
function wantedPackageManager(manifest) {
|
|
116
|
+
const declared = manifest.devEngines?.packageManager
|
|
117
|
+
const list = Array.isArray(declared) ? declared : declared == null ? [] : [declared]
|
|
118
|
+
const index = Array.isArray(declared) ? Math.max(list.findIndex((entry) => entry?.name === 'pnpm'), 0) : 0
|
|
119
|
+
const entry = list[index]
|
|
120
|
+
if (typeof entry?.name === 'string') {
|
|
121
|
+
const onFail = typeof entry.onFail === 'string' ? entry.onFail : Array.isArray(declared) ? (index === list.length - 1 ? 'error' : 'ignore') : undefined
|
|
122
|
+
const version = typeof entry.version === 'string' && validRange(entry.version) !== null ? entry.version : undefined
|
|
123
|
+
return { name: entry.name, version, devEngines: true, onFail }
|
|
124
|
+
}
|
|
125
|
+
if (typeof manifest.packageManager !== 'string') return undefined
|
|
126
|
+
const [, name, version] = /^(@?[^@]*)(?:@(.*))?$/u.exec(manifest.packageManager)
|
|
127
|
+
const exact = version === undefined ? undefined : version.replace(/\+.*$/u, '')
|
|
128
|
+
return { name, version: isExactVersion(exact) && valid(exact) === exact ? exact : undefined, devEngines: false, onFail: undefined }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Whether the root package.json pins a pnpm that `pnpm` is, which makes
|
|
132
|
+
// pnpm 12 fail on a setting it does not know.
|
|
133
|
+
export function pinsPnpm(manifest, pnpm) {
|
|
134
|
+
const wanted = wantedPackageManager(manifest)
|
|
135
|
+
return wanted?.name === 'pnpm' && wanted.version !== undefined && satisfies(pnpm, wanted.version, { includePrerelease: true })
|
|
136
|
+
}
|
|
137
|
+
|
|
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.
|
|
141
|
+
function checkPackageManager12(manifest, host, pmOnFail, env) {
|
|
142
|
+
const wanted = wantedPackageManager(manifest)
|
|
143
|
+
if (wanted === undefined) return
|
|
144
|
+
const where = `manifests["."].${wanted.devEngines ? 'devEngines.packageManager' : 'packageManager'}`
|
|
145
|
+
const onFail = pmOnFail ?? wanted.onFail ?? 'download'
|
|
146
|
+
if (onFail === 'ignore' || (onFail === 'warn' && wanted.name !== 'pnpm')) return
|
|
147
|
+
if (wanted.name !== 'pnpm') throw new DeptreeError(`the project is installed by ${quote(wanted.name)}, which pnpm 12 refuses`, where)
|
|
148
|
+
if (wanted.version === undefined) throw new DeptreeError('it names no version of pnpm, or none pnpm takes, which is not supported', where)
|
|
149
|
+
const running = satisfies(host.pnpm, wanted.version, { includePrerelease: true })
|
|
150
|
+
if (!running && onFail !== 'warn') throw new DeptreeError(`pnpm ${host.pnpm} is not in ${quote(wanted.version)}, which pnpm 12 switches from or refuses`, where)
|
|
151
|
+
if (!wanted.devEngines && Number(wanted.version.split('.')[0]) < 12) return
|
|
152
|
+
const version = isExactVersion(wanted.version) ? wanted.version : running ? host.pnpm : undefined
|
|
153
|
+
if (version === undefined) return
|
|
154
|
+
const recorded = env?.importers['.'].packageManagerDependencies ?? {}
|
|
155
|
+
const here = 'env.importers["."].packageManagerDependencies'
|
|
156
|
+
if (recorded.pnpm === undefined) throw new DeptreeError(`the lockfile records no pnpm for ${where}, which a frozen install of pnpm 12 fails on`, here)
|
|
157
|
+
for (const [name, key] of Object.entries(recorded)) {
|
|
158
|
+
if (key !== `${name}@${version}`) throw new DeptreeError(`${quote(key)} is not ${name} ${version}, which pnpm 12 would run or fail on`, `${here}.${name}`)
|
|
159
|
+
if (env.packages[key] === undefined) throw new DeptreeError(`the lockfile records no package ${quote(key)}, which a frozen install of pnpm 12 fails on`, `${here}.${name}`)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
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)
|
|
194
|
+
if (host.major >= 12) return checkPackageManager12(manifest, host, pmOnFail, env)
|
|
160
195
|
const { packageManager } = manifest
|
|
161
196
|
if (host.major >= 11) {
|
|
162
197
|
const where = 'manifests["."].devEngines.packageManager'
|
|
@@ -167,22 +202,22 @@ function checkPackageManager(manifest, host, pmOnFail) {
|
|
|
167
202
|
}
|
|
168
203
|
if (packageManager === undefined) return
|
|
169
204
|
const where = 'manifests["."].packageManager'
|
|
170
|
-
const version =
|
|
171
|
-
if (
|
|
205
|
+
const version = pinnedPnpm(packageManager)
|
|
206
|
+
if (version === undefined) throw new DeptreeError(`${quote(String(packageManager))} is not pnpm at an exact version`, where)
|
|
172
207
|
if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
|
|
173
208
|
}
|
|
174
209
|
|
|
175
|
-
// A runtime pnpm would download
|
|
176
|
-
//
|
|
177
|
-
// project, pnpm 11 takes runtimeOnFail for each one's onFail, and checks a
|
|
178
|
-
// 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.
|
|
179
212
|
const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
|
|
180
213
|
const RUNTIME_NAMES = ['node', 'deno', 'bun']
|
|
181
214
|
function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
215
|
+
// pnpm 9 knows no runtime.
|
|
216
|
+
if (host.major < 10) return
|
|
182
217
|
const checked = new Set()
|
|
183
218
|
for (const [field, kind] of RUNTIMES) {
|
|
184
219
|
const runtime = manifest[field]?.runtime
|
|
185
|
-
if (runtime
|
|
220
|
+
if (runtime == null) continue
|
|
186
221
|
const here = `${where}.${field}.runtime`
|
|
187
222
|
const runtimes = Array.isArray(runtime) ? runtime : [runtime]
|
|
188
223
|
for (const name of RUNTIME_NAMES) {
|
|
@@ -203,32 +238,40 @@ function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
|
203
238
|
}
|
|
204
239
|
}
|
|
205
240
|
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
241
|
+
// pnpm 12 counts no ignored optional dependency, nor any peer.
|
|
242
|
+
function dependsOn(manifest, ignored) {
|
|
243
|
+
const names = (deps) => (deps !== null && typeof deps === 'object' ? Object.keys(deps) : [])
|
|
244
|
+
const optional = new Set(names(manifest.optionalDependencies).filter((name) => ignored(name)))
|
|
245
|
+
return names(manifest.devDependencies).length > 0 || [...names(manifest.dependencies), ...names(manifest.optionalDependencies)].some((name) => !optional.has(name))
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function checkProjects(lockfile, manifests, { hook, host, settings, env }) {
|
|
249
|
+
checkPackageManager(manifests.get('.'), host, settings, env)
|
|
250
|
+
const ignored = createMatcher(settings.ignoredOptionalDependencies ?? [])
|
|
210
251
|
let index
|
|
211
252
|
for (const [id, manifest] of manifests) {
|
|
212
253
|
const where = `manifests[${quote(id)}]`
|
|
213
254
|
const root = id === '.'
|
|
214
|
-
checkProject(manifest, where, { host, settings })
|
|
255
|
+
checkProject(manifest, where, { host, settings, root })
|
|
215
256
|
checkRuntimes(manifest, where, { host, root, onFail: root ? settings.runtimeOnFail : undefined })
|
|
216
|
-
const hooked = hook(manifest, where, { dir: id })
|
|
217
257
|
const importer = lockfile.importers[id]
|
|
258
|
+
if (host.major >= 12 && importer.made) {
|
|
259
|
+
if (dependsOn(manifest, ignored)) throw new DeptreeError('the lockfile has no importer for this project, which has dependencies, and pnpm 12 refuses it', where)
|
|
260
|
+
continue
|
|
261
|
+
}
|
|
262
|
+
const hooked = hook(manifest, where, { dir: id })
|
|
218
263
|
const reason = mismatch(importer, hooked, settings.autoInstallPeers, host.major, where)
|
|
219
264
|
if (reason !== undefined) throw new DeptreeError(`the lockfile is not up to date with this package.json, which a frozen install refuses: ${reason}`, where)
|
|
220
265
|
checkLinkTargets({ id, manifest: hooked, importer }, where)
|
|
221
|
-
if (host.major
|
|
266
|
+
if (host.major !== 11) continue
|
|
222
267
|
checkCatalogResolutions(importer, lockfile.catalogs, where)
|
|
223
268
|
index ??= indexProjects(manifests)
|
|
224
269
|
checkLinkedPackages({ manifest: hooked, importer, index, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
|
|
225
270
|
}
|
|
226
271
|
}
|
|
227
272
|
|
|
228
|
-
// The
|
|
229
|
-
//
|
|
230
|
-
// Two of one name would leave which is hoisted to the order pnpm finds
|
|
231
|
-
// 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.
|
|
232
275
|
export function workspaceNames(manifests) {
|
|
233
276
|
const names = new Map()
|
|
234
277
|
const taken = new Set()
|
package/src/pnpm/readers.js
CHANGED
|
@@ -1,64 +1,57 @@
|
|
|
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'
|
|
8
8
|
import { REGISTRY } from '../tarball.js'
|
|
9
9
|
|
|
10
|
+
const ON_FAIL = new Set(['download', 'error', 'warn', 'ignore'])
|
|
11
|
+
const IMPORT_METHODS = new Set(['auto', 'hardlink', 'copy', 'clone', 'clone-or-copy'])
|
|
12
|
+
|
|
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
|
+
|
|
15
|
+
// `read` where `ok`, or else `value` refused as not `what`.
|
|
16
|
+
function checked(ok, value, what, where, read = value) {
|
|
17
|
+
if (ok) return read
|
|
18
|
+
throw new DeptreeError(`expected ${what}, found ${show(value)}`, where)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const oneOf = (allowed) => (value, where) => checked(allowed.has(value), value, `one of ${[...allowed].join(', ')}`, where)
|
|
22
|
+
|
|
10
23
|
export const readers = {
|
|
11
24
|
boolean(value, where) {
|
|
12
|
-
|
|
13
|
-
if (value === 'true' || value === 'false') return value === 'true'
|
|
14
|
-
throw new DeptreeError(`expected true or false, found ${show(value)}`, where)
|
|
25
|
+
return value === 'true' || value === 'false' ? value === 'true' : checked(typeof value === 'boolean', value, 'true or false', where)
|
|
15
26
|
},
|
|
16
27
|
count(value, where) {
|
|
17
28
|
const number = typeof value === 'string' && /^\d{1,9}$/u.test(value) ? Number(value) : value
|
|
18
|
-
|
|
19
|
-
throw new DeptreeError(`expected a positive integer, found ${show(value)}`, where)
|
|
29
|
+
return checked(Number.isSafeInteger(number) && number > 0, value, 'a positive integer', where, number)
|
|
20
30
|
},
|
|
21
|
-
text(value, where)
|
|
22
|
-
|
|
23
|
-
throw new DeptreeError(`expected a string, found ${show(value)}`, where)
|
|
24
|
-
},
|
|
25
|
-
// A list: a string alone is a list of it, as pnpm reads a hoist pattern.
|
|
31
|
+
text: (value, where) => checked(typeof value === 'string', value, 'a string', where),
|
|
32
|
+
// A string alone is a list of it, as pnpm reads a hoist pattern.
|
|
26
33
|
texts(value, where) {
|
|
27
34
|
return readers.list(typeof value === 'string' ? [value] : value, where, 'a string or a list of strings')
|
|
28
35
|
},
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// pnpm-workspace.yaml's `packages`, which pnpm holds to a list of
|
|
36
|
-
// non-empty strings.
|
|
37
|
-
globs(value, where) {
|
|
38
|
-
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)
|
|
39
|
-
return [...value]
|
|
40
|
-
},
|
|
41
|
-
mapping(value, where) {
|
|
42
|
-
if (value !== null && typeof value === 'object' && !Array.isArray(value)) return value
|
|
43
|
-
throw new DeptreeError(`expected a mapping, found ${show(value)}`, where)
|
|
44
|
-
},
|
|
45
|
-
onFail(value, where) {
|
|
46
|
-
if (ON_FAIL.has(value)) return value
|
|
47
|
-
throw new DeptreeError(`expected one of ${[...ON_FAIL].join(', ')}, found ${show(value)}`, where)
|
|
48
|
-
},
|
|
36
|
+
// Only a list: pnpm fails on a string alone where it sorts or maps it.
|
|
37
|
+
list: (value, where, expected = 'a list of strings') => [...checked(Array.isArray(value) && value.every((item) => typeof item === 'string'), value, expected, where)],
|
|
38
|
+
globs: (value, where) => [...checked(Array.isArray(value) && value.every((item) => typeof item === 'string' && item !== ''), value, 'a list of non-empty strings', where)],
|
|
39
|
+
mapping: (value, where) => checked(value !== null && typeof value === 'object' && !Array.isArray(value), value, 'a mapping', where),
|
|
40
|
+
importMethod: oneOf(IMPORT_METHODS),
|
|
41
|
+
onFail: oneOf(ON_FAIL),
|
|
49
42
|
linkWorkspacePackages(value, where) {
|
|
50
43
|
return value === 'deep' ? true : readers.boolean(value, where)
|
|
51
44
|
},
|
|
52
|
-
//
|
|
53
|
-
|
|
45
|
+
// A path, or a list of them, which pnpm 12 takes too.
|
|
46
|
+
pnpmfile(value, where) {
|
|
47
|
+
return typeof value === 'string' ? value : readers.list(value, where, 'a string or a list of strings')
|
|
48
|
+
},
|
|
54
49
|
sideEffectsCache(value, where) {
|
|
55
50
|
if (typeof value === 'boolean') return value
|
|
56
51
|
if (readers.mapping(value, where).remote != null) never('what a build left in a remote cache is not restored here')(value.remote, `${where}.remote`)
|
|
57
52
|
return value
|
|
58
53
|
},
|
|
59
|
-
//
|
|
60
|
-
// pnpm 11 takes for a project that pnpm 10 took from its own .npmrc. Of
|
|
61
|
-
// those, where to save and how is all that leaves the tree as it is.
|
|
54
|
+
// pnpm 11's per-project settings: by project name, or a list with `match`.
|
|
62
55
|
packageConfigs(value, where) {
|
|
63
56
|
const configs = Array.isArray(value) ? value.map((item, i) => [i, item]) : Object.entries(readers.mapping(value, where))
|
|
64
57
|
for (const [key, config] of configs) {
|
|
@@ -72,23 +65,16 @@ export const readers = {
|
|
|
72
65
|
},
|
|
73
66
|
}
|
|
74
67
|
|
|
75
|
-
const
|
|
68
|
+
const only = (kind, wanted, why) => ({ kind, check: (value, where) => value === wanted || never(why)(value, where) })
|
|
76
69
|
|
|
77
|
-
const show = (value) => (typeof value === 'string' ? quote(value) : Array.isArray(value) ? 'a list' : value === null ? 'null' : typeof value === 'object' ? 'a mapping' : String(value))
|
|
78
|
-
|
|
79
|
-
// Read, and held to one value: the default, or the only one built for.
|
|
80
|
-
const only = (kind, wanted, why) => ({ kind, check: (value, where) => {
|
|
81
|
-
if (value !== wanted) throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
|
|
82
|
-
} })
|
|
83
|
-
|
|
84
|
-
// Read, and refused whatever it is.
|
|
85
70
|
const never = (why) => (value, where) => {
|
|
86
71
|
throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
|
|
87
72
|
}
|
|
88
73
|
|
|
89
74
|
export const READ = {
|
|
90
75
|
__proto__: null,
|
|
91
|
-
|
|
76
|
+
// pnpm 10's hoisted layout too (hoisted.js).
|
|
77
|
+
nodeLinker: { kind: 'text', check: (value, where) => value === 'hoisted' || value === 'isolated' || never('only the isolated and hoisted node_modules layouts are built')(value, where) },
|
|
92
78
|
symlink: only('boolean', true, 'a tree without its links is not built'),
|
|
93
79
|
enableModulesDir: only('boolean', true, 'a tree without node_modules is not built'),
|
|
94
80
|
modulesDir: only('text', 'node_modules', 'the modules directory is always node_modules'),
|
|
@@ -118,6 +104,10 @@ export const READ = {
|
|
|
118
104
|
filterProd: { kind: 'texts', check: never('every project is installed') },
|
|
119
105
|
useNodeVersion: { kind: 'text', check: never('the Node a tree is built for is the host\'s, or nodeVersion') },
|
|
120
106
|
globalPnpmfile: { kind: 'text', check: never('a pnpmfile\'s hooks are not run here') },
|
|
107
|
+
// [] loads none, not even the default one. An .npmrc's is passed over: from
|
|
108
|
+
// a path that leads nowhere pnpm 9 loads none, and a pnpmfile with hooks
|
|
109
|
+
// puts its pnpmfileChecksum in the lockfile, which is refused (tree.js).
|
|
110
|
+
pnpmfile: { kind: 'pnpmfile', check: (value, where) => (Array.isArray(value) && value.length === 0) || never('a pnpmfile\'s hooks are not run here')(value, where), rc: false },
|
|
121
111
|
registry: { kind: 'text', check: checkRegistry },
|
|
122
112
|
virtualStoreDirMaxLength: { kind: 'count' },
|
|
123
113
|
hoist: { kind: 'boolean' },
|
|
@@ -130,6 +120,8 @@ export const READ = {
|
|
|
130
120
|
autoInstallPeers: { kind: 'boolean' },
|
|
131
121
|
dedupePeers: { kind: 'boolean' },
|
|
132
122
|
peersSuffixMaxLength: { kind: 'count' },
|
|
123
|
+
// Whether a directory package's snapshots share hardlinked files (tree.js).
|
|
124
|
+
packageImportMethod: { kind: 'importMethod' },
|
|
133
125
|
// Neither pnpm's .npmrc nor ours has these.
|
|
134
126
|
supportedArchitectures: { kind: 'mapping', check: checkArchitectures, rc: false },
|
|
135
127
|
patchedDependencies: { kind: 'mapping', check: checkPatches, rc: false },
|
|
@@ -157,11 +149,8 @@ const READ_11 = {
|
|
|
157
149
|
linkWorkspacePackages: { kind: 'linkWorkspacePackages' },
|
|
158
150
|
}
|
|
159
151
|
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
// rest of what pnpm 11 checks the lockfile against the registry by before
|
|
163
|
-
// it installs — each package's publish time, its tarball URL, its trust —
|
|
164
|
-
// are passed over.
|
|
152
|
+
// The tree follows the lockfile, as pnpm 11's and 12's do with trustLockfile,
|
|
153
|
+
// so what pnpm 11 checks the lockfile against the registry by is passed over.
|
|
165
154
|
const IGNORED_11 = new Set([
|
|
166
155
|
'minimumReleaseAgeIgnoreMissingTime', 'minimumReleaseAgeStrict', 'minimumReleaseAgeExcludePrune', 'trustLockfile',
|
|
167
156
|
'trustPolicy', 'trustPolicyExclude', 'trustPolicyExcludePrune', 'trustPolicyIgnoreAfter', 'pnprServer',
|
|
@@ -178,8 +167,50 @@ const IGNORED_11 = new Set([
|
|
|
178
167
|
'nodeVersionFromEnginesRuntime', 'cliOptions', 'explicitlySetKeys', 'packageManager', 'wantedPackageManager',
|
|
179
168
|
])
|
|
180
169
|
|
|
181
|
-
//
|
|
182
|
-
|
|
170
|
+
// What pnpm 12 adds that leaves an isolated tree as it is.
|
|
171
|
+
const IGNORED_12 = new Set([
|
|
172
|
+
'autoDedupe', 'autoInstallPeersFromHighestMatch', 'externalDependencies', 'hoistingLimits', 'globalShims',
|
|
173
|
+
'concurrencyGroups', 'pipelines', 'pipelineBase', 'publishWaitTimeout', 'saveTypes', 'tools', 'macosBackup',
|
|
174
|
+
])
|
|
175
|
+
const notEnabled = (value, where) => {
|
|
176
|
+
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`)
|
|
177
|
+
}
|
|
178
|
+
const READ_12 = {
|
|
179
|
+
__proto__: null,
|
|
180
|
+
nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 12'),
|
|
181
|
+
cargo: { kind: 'mapping', check: notEnabled },
|
|
182
|
+
python: { kind: 'mapping', check: notEnabled },
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const UNRECOGNIZED_12 = new Set([
|
|
186
|
+
'allowNonAppliedPatches', 'alwaysAuth', 'email', 'enginePinManifest', 'ignoreDepScripts', 'ignorePatchFailures',
|
|
187
|
+
'lockfileDirectory', 'managePackageManagerVersions', 'nodeVersionFromEnginesRuntime', 'packageManagerStrict',
|
|
188
|
+
'packageManagerStrictVersion', 'shamefullyFlatten', 'useNodeVersion',
|
|
189
|
+
])
|
|
190
|
+
|
|
191
|
+
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)
|
|
192
|
+
|
|
193
|
+
// What pnpm 9 reads that pnpm 10 passes over: how it holds the root
|
|
194
|
+
// package.json's packageManager to the pnpm that runs (projects.js).
|
|
195
|
+
const READ_9 = {
|
|
196
|
+
__proto__: null,
|
|
197
|
+
nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 9'),
|
|
198
|
+
managePackageManagerVersions: { kind: 'boolean' },
|
|
199
|
+
packageManagerStrict: { kind: 'boolean' },
|
|
200
|
+
packageManagerStrictVersion: { kind: 'boolean' },
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// What pnpm 10 reads that pnpm 9 has no setting for, and passes over.
|
|
204
|
+
const NOT_9 = new Set(['dedupePeers', 'enableGlobalVirtualStore', 'injectWorkspacePackages'])
|
|
205
|
+
|
|
206
|
+
// The keys of package.json's `pnpm` pnpm 9 reads, passing over any other.
|
|
207
|
+
export const MANIFEST_KEYS_9 = [
|
|
208
|
+
'allowNonAppliedPatches', 'allowedDeprecatedVersions', 'ignoredOptionalDependencies', 'neverBuiltDependencies',
|
|
209
|
+
'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'overrides', 'packageExtensions', 'patchedDependencies',
|
|
210
|
+
'peerDependencyRules', 'supportedArchitectures',
|
|
211
|
+
]
|
|
212
|
+
|
|
213
|
+
// The keys of package.json's `pnpm` pnpm 10 reads, passing over any other.
|
|
183
214
|
export const MANIFEST_KEYS = [
|
|
184
215
|
'allowBuilds', 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'auditConfig',
|
|
185
216
|
'configDependencies', 'executionEnv', 'ignorePatchFailures', 'ignoredBuiltDependencies', 'ignoredOptionalDependencies',
|
|
@@ -187,26 +218,21 @@ export const MANIFEST_KEYS = [
|
|
|
187
218
|
'patchedDependencies', 'peerDependencyRules', 'requiredScripts', 'supportedArchitectures', 'updateConfig',
|
|
188
219
|
]
|
|
189
220
|
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
// registry alone, through @preventive/upstream, so the network and its
|
|
194
|
-
// credentials are its own; the store, caches and state live outside
|
|
195
|
-
// node_modules; bins are never written here, and scripts never run, as
|
|
196
|
-
// with --ignore-scripts, whatever a setting would allow to build.
|
|
197
|
-
export const IGNORED = new Set([
|
|
221
|
+
// A frozen install holds the lockfile to none of the resolution settings
|
|
222
|
+
// here (uptodate.js has those it does).
|
|
223
|
+
const IGNORED = new Set([
|
|
198
224
|
// resolution, already in the lockfile
|
|
199
225
|
'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
|
|
200
|
-
'dedupeInjectedDeps', 'dedupePeerDependents', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
|
|
226
|
+
'dedupeInjectedDeps', 'dedupePeerDependents', 'ignoreCompatibilityDb', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
|
|
201
227
|
'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
|
|
202
228
|
'registrySupportsTimeField', 'resolutionMode', 'resolvePeersFromWorkspaceRoot', 'saveExact', 'savePrefix',
|
|
203
229
|
'saveWorkspaceProtocol', 'strictPeerDependencies',
|
|
204
|
-
// the network
|
|
230
|
+
// the network and its credentials, which @preventive/upstream handles
|
|
205
231
|
'alwaysAuth', 'ca', 'cafile', 'cert', 'email', 'fetchRetries', 'fetchRetryFactor', 'fetchRetryMaxtimeout',
|
|
206
232
|
'fetchRetryMintimeout', 'fetchTimeout', 'httpProxy', 'httpsProxy', 'key', 'localAddress', 'maxsockets',
|
|
207
233
|
'networkConcurrency', 'noProxy', 'noproxy', 'offline', 'preferOffline', 'proxy', 'strictSsl', 'userAgent',
|
|
208
234
|
// the store, caches and state, none of it in node_modules
|
|
209
|
-
'cacheDir', 'modulesCacheMaxAge', '
|
|
235
|
+
'cacheDir', 'modulesCacheMaxAge', 'sideEffectsCache', 'sideEffectsCacheReadonly',
|
|
210
236
|
'stateDir', 'storeDir', 'strictStorePkgContentCheck', 'verifyStoreIntegrity',
|
|
211
237
|
// scripts, which are not run, and bins, which are not written
|
|
212
238
|
'allowBuilds', 'childConcurrency', 'dangerouslyAllowAllBuilds', 'enablePrePostScripts', 'extendNodePath',
|
|
@@ -226,7 +252,6 @@ export function checkRegistry(value, where) {
|
|
|
226
252
|
if ((value.endsWith('/') ? value : `${value}/`) !== REGISTRY) throw new DeptreeError(`${quote(value)} is not supported: packages are fetched from ${REGISTRY} alone`, where)
|
|
227
253
|
}
|
|
228
254
|
|
|
229
|
-
// pnpm 11's registries: by scope, or `default`, the registry's URL.
|
|
230
255
|
function checkRegistries(value, where) {
|
|
231
256
|
for (const [scope, url] of Object.entries(value)) checkRegistry(readers.text(url, `${where}.${scope}`), `${where}.${scope}`)
|
|
232
257
|
}
|
|
@@ -243,7 +268,6 @@ function checkArchitectures(value, where) {
|
|
|
243
268
|
}
|
|
244
269
|
}
|
|
245
270
|
|
|
246
|
-
// A catalog: by name, the specifier it gives the package.
|
|
247
271
|
function checkCatalog(value, where) {
|
|
248
272
|
for (const [name, spec] of Object.entries(value)) readers.text(spec, `${where}.${name}`)
|
|
249
273
|
}
|
|
@@ -252,16 +276,37 @@ function checkCatalogs(value, where) {
|
|
|
252
276
|
for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
|
|
253
277
|
}
|
|
254
278
|
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
if (major
|
|
259
|
-
if (
|
|
260
|
-
if (
|
|
261
|
-
return
|
|
279
|
+
// `{}` where a setting leaves the tree as it is or pnpm 9 has no such setting,
|
|
280
|
+
// undefined where not known here. pnpm 12 takes a pattern only as a list.
|
|
281
|
+
function lookup(name, major) {
|
|
282
|
+
if (major < 10 && name in READ_9) return { read: READ_9[name] }
|
|
283
|
+
if (major < 10 && NOT_9.has(name)) return {}
|
|
284
|
+
if (major >= 12 && UNRECOGNIZED_12.has(name)) return { unrecognized: true }
|
|
285
|
+
if (major >= 12 && name in READ_12) return { read: READ_12[name] }
|
|
286
|
+
if (major >= 11 && name in READ_11) return { read: READ_11[name] }
|
|
287
|
+
if (IGNORED.has(name) || (major >= 11 && IGNORED_11.has(name)) || (major >= 12 && IGNORED_12.has(name))) return {}
|
|
288
|
+
if (!(name in READ)) return undefined
|
|
289
|
+
return { read: major >= 12 && READ[name].kind === 'texts' ? { ...READ[name], kind: 'list' } : READ[name] }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// An .npmrc setting pnpm passes over is undefined.
|
|
293
|
+
export function npmrcReader(name, major) {
|
|
294
|
+
const read = lookup(name, major)?.read
|
|
295
|
+
return read?.rc === false ? undefined : read
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function readerOf(name, where, major, pinned = false) {
|
|
299
|
+
const found = lookup(name, major)
|
|
300
|
+
if (found === undefined) throw new DeptreeError('unsupported setting', where)
|
|
301
|
+
if (found.unrecognized && pinned) throw unrecognized12(where)
|
|
302
|
+
return found.read
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function known12(name) {
|
|
306
|
+
const found = lookup(name, 12)
|
|
307
|
+
return found !== undefined && !found.unrecognized
|
|
262
308
|
}
|
|
263
309
|
|
|
264
|
-
// By selector, the patch file, relative to the workspace's directory.
|
|
265
310
|
function checkPatches(value, where) {
|
|
266
311
|
for (const [selector, path] of Object.entries(value)) {
|
|
267
312
|
const here = `${where}[${quote(selector)}]`
|