@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.3
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/package.json +38 -6
- package/pnpm.d.ts +224 -77
- package/pnpm.js +9 -6
- package/soldeer.d.ts +168 -0
- package/soldeer.js +12 -0
- package/src/concurrent.js +24 -0
- package/src/hash.js +4 -0
- package/src/mount.js +7 -6
- package/src/patch.js +5 -4
- package/src/pnpm/bins.js +105 -246
- package/src/pnpm/commands.js +273 -0
- package/src/pnpm/filename.js +16 -2
- package/src/pnpm/frozen.js +4 -2
- package/src/pnpm/graph.js +36 -16
- package/src/pnpm/hoist.js +41 -11
- package/src/pnpm/inputs.js +160 -0
- package/src/pnpm/install.js +65 -20
- package/src/pnpm/local.js +95 -33
- package/src/pnpm/packlist.js +64 -29
- package/src/pnpm/project.js +97 -0
- package/src/pnpm/projects.js +97 -10
- package/src/pnpm/readers.js +73 -16
- package/src/pnpm/settings.js +25 -10
- package/src/pnpm/tree.js +68 -119
- package/src/pnpm/workspace.js +70 -35
- package/src/soldeer/config.js +79 -0
- package/src/soldeer/inputs.js +40 -0
- package/src/soldeer/tree.js +111 -0
- package/src/soldeer/zip.js +142 -0
- package/src/tarball.js +26 -12
- package/src/yarn1/bins.js +38 -0
- package/src/yarn1/compat.js +86 -0
- package/src/yarn1/glob.js +52 -0
- package/src/yarn1/hoist.js +264 -0
- package/src/yarn1/inputs.js +125 -0
- package/src/yarn1/manifest.js +79 -0
- package/src/yarn1/package.js +148 -0
- package/src/yarn1/peers.js +58 -0
- package/src/yarn1/requests.js +90 -0
- package/src/yarn1/resolve.js +269 -0
- package/src/yarn1/settings.js +123 -0
- package/src/yarn1/tree.js +212 -0
- package/yarn1.d.ts +267 -0
- package/yarn1.js +14 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The project a tree is built for: a view of the lockfile's directory, by
|
|
2
|
+
// paths from `/` — a Vfs, or anything with its readdir, lstat, stat and
|
|
3
|
+
// readFile, such as one of a directory on disk. It is only read, and only
|
|
4
|
+
// where these say: the files pnpm reads at the root for an install, the
|
|
5
|
+
// package.json of each project and the patches the settings name, where
|
|
6
|
+
// buildPnpmTree is not handed them; the directories findProjects walks;
|
|
7
|
+
// and those a `link:` or `file:` leads to (local.js).
|
|
8
|
+
|
|
9
|
+
import { normalize } from '@preventive/vfs/path.js'
|
|
10
|
+
import { DeptreeError, quote } from '../error.js'
|
|
11
|
+
|
|
12
|
+
export function checkProject(project) {
|
|
13
|
+
if (['readdir', 'lstat', 'stat', 'readFile'].some((name) => typeof project?.[name] !== 'function')) {
|
|
14
|
+
throw new TypeError('project must be a Vfs, or have its readdir, lstat, stat and readFile')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// What `path` leads to, links followed, or where `follow` is false, what
|
|
19
|
+
// it is; nothing, where it leads nowhere: to no entry, through a file, or
|
|
20
|
+
// round a loop of links. Any other failure is thrown.
|
|
21
|
+
const NOWHERE = new Set(['ENOENT', 'ENOTDIR', 'ELOOP'])
|
|
22
|
+
export function typeOf(project, path, follow = true) {
|
|
23
|
+
try {
|
|
24
|
+
return (follow ? project.stat(path) : project.lstat(path)).type
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (NOWHERE.has(error?.code)) return undefined
|
|
27
|
+
throw error
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// As text handed in would be: a byte order mark kept, for what reads it
|
|
32
|
+
// to drop as pnpm does.
|
|
33
|
+
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
|
|
34
|
+
|
|
35
|
+
// The bytes of the file at `path`, as a Vfs gives them back.
|
|
36
|
+
export function readBytes(project, path) {
|
|
37
|
+
const bytes = project.readFile(path)
|
|
38
|
+
if (!(bytes instanceof Uint8Array)) throw new TypeError('project.readFile must give back bytes')
|
|
39
|
+
return bytes
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The text of the file at `path`, or undefined where nothing is.
|
|
43
|
+
export function readText(project, path, where) {
|
|
44
|
+
const type = typeOf(project, path)
|
|
45
|
+
if (type === undefined) return undefined
|
|
46
|
+
if (type !== 'file') throw new DeptreeError(`${quote(path.slice(1))} is a ${type}, not a file`, where)
|
|
47
|
+
const bytes = readBytes(project, path)
|
|
48
|
+
try {
|
|
49
|
+
return decoder.decode(bytes)
|
|
50
|
+
} catch {
|
|
51
|
+
throw new DeptreeError(`${quote(path.slice(1))} is not UTF-8`, where)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// pnpm-workspace.yaml, where it is. pnpm looks for it under other names
|
|
56
|
+
// too, and refuses one it finds so.
|
|
57
|
+
const MISNAMED = ['pnpm-workspaces.yaml', 'pnpm-workspaces.yml', 'pnpm-workspace.yml', '.pnpm-workspace.yaml', '.pnpm-workspace.yml', '.pnpm-workspaces.yaml', '.pnpm-workspaces.yml']
|
|
58
|
+
export function readWorkspaceText(project) {
|
|
59
|
+
const text = readText(project, '/pnpm-workspace.yaml')
|
|
60
|
+
const misnamed = text === undefined ? MISNAMED.find((name) => typeOf(project, `/${name}`) === 'file') : undefined
|
|
61
|
+
if (misnamed !== undefined) throw new DeptreeError('pnpm refuses a workspace manifest not named pnpm-workspace.yaml', quote(misnamed))
|
|
62
|
+
return text
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// What pnpm reads at the root for an install besides the package.json:
|
|
66
|
+
// pnpm-lock.yaml, which a frozen install cannot do without, and
|
|
67
|
+
// pnpm-workspace.yaml and the .npmrc, where they are.
|
|
68
|
+
export function readRootFiles(project) {
|
|
69
|
+
const lockfile = readText(project, '/pnpm-lock.yaml')
|
|
70
|
+
if (lockfile === undefined) throw new DeptreeError('the project has no pnpm-lock.yaml, which a frozen install cannot do without')
|
|
71
|
+
return { lockfile, workspace: readWorkspaceText(project), npmrc: readText(project, '/.npmrc') }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The text of the package.json of each of `ids`, the projects'
|
|
75
|
+
// directories, by directory.
|
|
76
|
+
export function readManifestTexts(project, ids) {
|
|
77
|
+
const texts = new Map()
|
|
78
|
+
for (const id of ids) {
|
|
79
|
+
texts.set(id, readText(project, id === '.' ? '/package.json' : `/${id}/package.json`, `manifests[${quote(id)}]`))
|
|
80
|
+
}
|
|
81
|
+
return texts
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The text of each patch `configured`, patchedDependencies, names, by its
|
|
85
|
+
// path from the lockfile's directory; one that is not there left out.
|
|
86
|
+
// One outside that directory, or absolute, is not in the project, and is
|
|
87
|
+
// refused.
|
|
88
|
+
export function readPatches(project, configured) {
|
|
89
|
+
const texts = new Map()
|
|
90
|
+
for (const [selector, spec] of Object.entries(configured ?? {})) {
|
|
91
|
+
const path = normalize(spec)
|
|
92
|
+
if (path === '..' || path.startsWith('../') || path.startsWith('/')) throw new DeptreeError(`the patch ${quote(spec)} is not in the project: it is outside the lockfile's directory`, `patchedDependencies[${quote(selector)}]`)
|
|
93
|
+
const text = readText(project, `/${path}`, `patches[${quote(path)}]`)
|
|
94
|
+
if (text !== undefined) texts.set(path, text)
|
|
95
|
+
}
|
|
96
|
+
return texts
|
|
97
|
+
}
|
package/src/pnpm/projects.js
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
35
35
|
import { DeptreeError, difference, quote } from '../error.js'
|
|
36
|
+
import { createMatcher } from '../matcher.js'
|
|
36
37
|
import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
|
|
37
38
|
import { checkProject } from './install.js'
|
|
38
39
|
import { validForOldPackages } from './overrides.js'
|
|
@@ -61,7 +62,8 @@ export function readManifests(manifests, lockfile) {
|
|
|
61
62
|
const where = `manifests[${quote(id)}]`
|
|
62
63
|
if (!(id in lockfile.importers)) {
|
|
63
64
|
checkProjectId(id, where)
|
|
64
|
-
|
|
65
|
+
// `made`, as the lockfile has no importer for the project.
|
|
66
|
+
lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true, made: true }
|
|
65
67
|
}
|
|
66
68
|
read.set(id, readManifest(text, where))
|
|
67
69
|
}
|
|
@@ -150,13 +152,80 @@ function devEnginesPackageManager(devEngines, where) {
|
|
|
150
152
|
return { name: engine.name, onFail }
|
|
151
153
|
}
|
|
152
154
|
|
|
155
|
+
// The version of pnpm packageManager names, as pnpm's parsePackageManager
|
|
156
|
+
// reads it, where it names pnpm at an exact version.
|
|
157
|
+
export function pinnedPnpm(packageManager) {
|
|
158
|
+
const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
|
|
159
|
+
return isExactVersion(version) ? version : undefined
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// The package manager the root package.json pins as pnpm 12 reads it
|
|
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.
|
|
167
|
+
function wantedPackageManager(manifest) {
|
|
168
|
+
const declared = manifest.devEngines?.packageManager
|
|
169
|
+
const list = Array.isArray(declared) ? declared : declared === undefined || declared === null ? [] : [declared]
|
|
170
|
+
const index = Array.isArray(declared) ? Math.max(list.findIndex((entry) => entry?.name === 'pnpm'), 0) : 0
|
|
171
|
+
const entry = list[index]
|
|
172
|
+
if (typeof entry?.name === 'string') {
|
|
173
|
+
const onFail = typeof entry.onFail === 'string' ? entry.onFail : Array.isArray(declared) ? (index === list.length - 1 ? 'error' : 'ignore') : undefined
|
|
174
|
+
const version = typeof entry.version === 'string' && validRange(entry.version) !== null ? entry.version : undefined
|
|
175
|
+
return { name: entry.name, version, devEngines: true, onFail }
|
|
176
|
+
}
|
|
177
|
+
if (typeof manifest.packageManager !== 'string') return undefined
|
|
178
|
+
const [, name, version] = /^(@?[^@]*)(?:@(.*))?$/u.exec(manifest.packageManager)
|
|
179
|
+
const exact = version === undefined ? undefined : version.replace(/\+.*$/u, '')
|
|
180
|
+
return { name, version: isExactVersion(exact) && valid(exact) === exact ? exact : undefined, devEngines: false, onFail: undefined }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Whether the root package.json pins a pnpm that `pnpm` is, which makes
|
|
184
|
+
// pnpm 12 fail on a setting it does not know.
|
|
185
|
+
export function pinsPnpm(manifest, pnpm) {
|
|
186
|
+
const wanted = wantedPackageManager(manifest)
|
|
187
|
+
return wanted?.name === 'pnpm' && wanted.version !== undefined && satisfies(pnpm, wanted.version, { includePrerelease: true })
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// pnpm 12 runs, of a pin that is not to be ignored, the pnpm the lockfile's
|
|
191
|
+
// env document records for it; it records a devEngines one, or a
|
|
192
|
+
// packageManager one of 12 or later, and a frozen install fails where it
|
|
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.
|
|
198
|
+
function checkPackageManager12(manifest, host, pmOnFail, env) {
|
|
199
|
+
const wanted = wantedPackageManager(manifest)
|
|
200
|
+
if (wanted === undefined) return
|
|
201
|
+
const where = `manifests["."].${wanted.devEngines ? 'devEngines.packageManager' : 'packageManager'}`
|
|
202
|
+
const onFail = pmOnFail ?? wanted.onFail ?? 'download'
|
|
203
|
+
if (onFail === 'ignore' || (onFail === 'warn' && wanted.name !== 'pnpm')) return
|
|
204
|
+
if (wanted.name !== 'pnpm') throw new DeptreeError(`the project is installed by ${quote(wanted.name)}, which pnpm 12 refuses`, where)
|
|
205
|
+
if (wanted.version === undefined) throw new DeptreeError('it names no version of pnpm, or none pnpm takes, which is not supported', where)
|
|
206
|
+
const running = satisfies(host.pnpm, wanted.version, { includePrerelease: true })
|
|
207
|
+
if (!running && onFail !== 'warn') throw new DeptreeError(`pnpm ${host.pnpm} is not in ${quote(wanted.version)}, which pnpm 12 switches from or refuses`, where)
|
|
208
|
+
if (!wanted.devEngines && Number(wanted.version.split('.')[0]) < 12) return
|
|
209
|
+
const version = isExactVersion(wanted.version) ? wanted.version : running ? host.pnpm : undefined
|
|
210
|
+
if (version === undefined) return
|
|
211
|
+
const recorded = env?.importers['.'].packageManagerDependencies ?? {}
|
|
212
|
+
const here = 'env.importers["."].packageManagerDependencies'
|
|
213
|
+
if (recorded.pnpm === undefined) throw new DeptreeError(`the lockfile records no pnpm for ${where}, which a frozen install of pnpm 12 fails on`, here)
|
|
214
|
+
for (const [name, key] of Object.entries(recorded)) {
|
|
215
|
+
if (key !== `${name}@${version}`) throw new DeptreeError(`${quote(key)} is not ${name} ${version}, which pnpm 12 would run or fail on`, `${here}.${name}`)
|
|
216
|
+
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}`)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
153
220
|
// packageManager as pnpm's parsePackageManager reads it, held to be this
|
|
154
221
|
// pnpm, exactly: pnpm switches to the version it names, and one it cannot
|
|
155
222
|
// switch to, or another package manager, is refused rather than run over.
|
|
156
223
|
// pnpm 11 reads devEngines.packageManager over it, and switches to the
|
|
157
224
|
// pnpm the lockfile pins for that, which is refused; either is passed
|
|
158
225
|
// over where what to do on a mismatch, or pmOnFail, is to warn or ignore.
|
|
159
|
-
|
|
226
|
+
// pnpm 12's are checkPackageManager12's.
|
|
227
|
+
function checkPackageManager(manifest, host, pmOnFail, env) {
|
|
228
|
+
if (host.major >= 12) return checkPackageManager12(manifest, host, pmOnFail, env)
|
|
160
229
|
const { packageManager } = manifest
|
|
161
230
|
if (host.major >= 11) {
|
|
162
231
|
const where = 'manifests["."].devEngines.packageManager'
|
|
@@ -167,8 +236,8 @@ function checkPackageManager(manifest, host, pmOnFail) {
|
|
|
167
236
|
}
|
|
168
237
|
if (packageManager === undefined) return
|
|
169
238
|
const where = 'manifests["."].packageManager'
|
|
170
|
-
const version =
|
|
171
|
-
if (
|
|
239
|
+
const version = pinnedPnpm(packageManager)
|
|
240
|
+
if (version === undefined) throw new DeptreeError(`${quote(String(packageManager))} is not pnpm at an exact version`, where)
|
|
172
241
|
if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
|
|
173
242
|
}
|
|
174
243
|
|
|
@@ -203,22 +272,40 @@ function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
|
203
272
|
}
|
|
204
273
|
}
|
|
205
274
|
|
|
275
|
+
// Whether pnpm 12 takes a project to have dependencies, where the lockfile
|
|
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.
|
|
279
|
+
function dependsOn(manifest, ignored) {
|
|
280
|
+
const names = (deps) => (deps !== null && typeof deps === 'object' ? Object.keys(deps) : [])
|
|
281
|
+
const optional = new Set(names(manifest.optionalDependencies).filter((name) => ignored(name)))
|
|
282
|
+
return names(manifest.devDependencies).length > 0 || [...names(manifest.dependencies), ...names(manifest.optionalDependencies)].some((name) => !optional.has(name))
|
|
283
|
+
}
|
|
284
|
+
|
|
206
285
|
// `hook` is hook.js's, which each package.json is read through; `host`
|
|
207
|
-
// and `settings` what its engines are held to
|
|
208
|
-
|
|
209
|
-
|
|
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
|
+
export function checkProjects(lockfile, manifests, { hook, host, settings, env }) {
|
|
291
|
+
checkPackageManager(manifests.get('.'), host, settings.pmOnFail, env)
|
|
292
|
+
const ignored = createMatcher(settings.ignoredOptionalDependencies ?? [])
|
|
210
293
|
let index
|
|
211
294
|
for (const [id, manifest] of manifests) {
|
|
212
295
|
const where = `manifests[${quote(id)}]`
|
|
213
296
|
const root = id === '.'
|
|
214
|
-
checkProject(manifest, where, { host, settings })
|
|
297
|
+
checkProject(manifest, where, { host, settings, root })
|
|
215
298
|
checkRuntimes(manifest, where, { host, root, onFail: root ? settings.runtimeOnFail : undefined })
|
|
216
|
-
const hooked = hook(manifest, where, { dir: id })
|
|
217
299
|
const importer = lockfile.importers[id]
|
|
300
|
+
if (host.major >= 12 && importer.made) {
|
|
301
|
+
if (dependsOn(manifest, ignored)) throw new DeptreeError('the lockfile has no importer for this project, which has dependencies, and pnpm 12 refuses it', where)
|
|
302
|
+
continue
|
|
303
|
+
}
|
|
304
|
+
const hooked = hook(manifest, where, { dir: id })
|
|
218
305
|
const reason = mismatch(importer, hooked, settings.autoInstallPeers, host.major, where)
|
|
219
306
|
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
307
|
checkLinkTargets({ id, manifest: hooked, importer }, where)
|
|
221
|
-
if (host.major
|
|
308
|
+
if (host.major !== 11) continue
|
|
222
309
|
checkCatalogResolutions(importer, lockfile.catalogs, where)
|
|
223
310
|
index ??= indexProjects(manifests)
|
|
224
311
|
checkLinkedPackages({ manifest: hooked, importer, index, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
|
package/src/pnpm/readers.js
CHANGED
|
@@ -7,6 +7,17 @@ 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
|
+
// A reader of one of the values of `allowed`.
|
|
16
|
+
const oneOf = (allowed) => (value, where) => {
|
|
17
|
+
if (allowed.has(value)) return value
|
|
18
|
+
throw new DeptreeError(`expected one of ${[...allowed].join(', ')}, found ${show(value)}`, where)
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
export const readers = {
|
|
11
22
|
boolean(value, where) {
|
|
12
23
|
if (typeof value === 'boolean') return value
|
|
@@ -42,10 +53,8 @@ export const readers = {
|
|
|
42
53
|
if (value !== null && typeof value === 'object' && !Array.isArray(value)) return value
|
|
43
54
|
throw new DeptreeError(`expected a mapping, found ${show(value)}`, where)
|
|
44
55
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw new DeptreeError(`expected one of ${[...ON_FAIL].join(', ')}, found ${show(value)}`, where)
|
|
48
|
-
},
|
|
56
|
+
importMethod: oneOf(IMPORT_METHODS),
|
|
57
|
+
onFail: oneOf(ON_FAIL),
|
|
49
58
|
linkWorkspacePackages(value, where) {
|
|
50
59
|
return value === 'deep' ? true : readers.boolean(value, where)
|
|
51
60
|
},
|
|
@@ -72,10 +81,6 @@ export const readers = {
|
|
|
72
81
|
},
|
|
73
82
|
}
|
|
74
83
|
|
|
75
|
-
const ON_FAIL = new Set(['download', 'error', 'warn', 'ignore'])
|
|
76
|
-
|
|
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
84
|
// Read, and held to one value: the default, or the only one built for.
|
|
80
85
|
const only = (kind, wanted, why) => ({ kind, check: (value, where) => {
|
|
81
86
|
if (value !== wanted) throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
|
|
@@ -130,6 +135,9 @@ export const READ = {
|
|
|
130
135
|
autoInstallPeers: { kind: 'boolean' },
|
|
131
136
|
dedupePeers: { kind: 'boolean' },
|
|
132
137
|
peersSuffixMaxLength: { kind: 'count' },
|
|
138
|
+
// Whether a package installed from a directory has the files of each of
|
|
139
|
+
// its snapshots as one, hardlinked, or each as its own (tree.js).
|
|
140
|
+
packageImportMethod: { kind: 'importMethod' },
|
|
133
141
|
// Neither pnpm's .npmrc nor ours has these.
|
|
134
142
|
supportedArchitectures: { kind: 'mapping', check: checkArchitectures, rc: false },
|
|
135
143
|
patchedDependencies: { kind: 'mapping', check: checkPatches, rc: false },
|
|
@@ -158,7 +166,7 @@ const READ_11 = {
|
|
|
158
166
|
}
|
|
159
167
|
|
|
160
168
|
// What pnpm 11 has that leaves the tree as it is. The tree follows the
|
|
161
|
-
// lockfile, as pnpm 11's
|
|
169
|
+
// lockfile, as pnpm 11's and 12's do with trustLockfile: minimumReleaseAge and the
|
|
162
170
|
// rest of what pnpm 11 checks the lockfile against the registry by before
|
|
163
171
|
// it installs — each package's publish time, its tarball URL, its trust —
|
|
164
172
|
// are passed over.
|
|
@@ -178,6 +186,34 @@ const IGNORED_11 = new Set([
|
|
|
178
186
|
'nodeVersionFromEnginesRuntime', 'cliOptions', 'explicitlySetKeys', 'packageManager', 'wantedPackageManager',
|
|
179
187
|
])
|
|
180
188
|
|
|
189
|
+
// What pnpm 12 has that pnpm 11 has not: those that leave an isolated
|
|
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.
|
|
193
|
+
const IGNORED_12 = new Set([
|
|
194
|
+
'autoDedupe', 'autoInstallPeersFromHighestMatch', 'externalDependencies', 'hoistingLimits', 'globalShims',
|
|
195
|
+
'concurrencyGroups', 'pipelines', 'pipelineBase', 'publishWaitTimeout', 'saveTypes', 'tools', 'macosBackup',
|
|
196
|
+
])
|
|
197
|
+
const notEnabled = (value, where) => {
|
|
198
|
+
if (value.enabled !== undefined && 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
|
+
}
|
|
200
|
+
const READ_12 = {
|
|
201
|
+
__proto__: null,
|
|
202
|
+
cargo: { kind: 'mapping', check: notEnabled },
|
|
203
|
+
python: { kind: 'mapping', check: notEnabled },
|
|
204
|
+
}
|
|
205
|
+
|
|
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
|
+
const UNRECOGNIZED_12 = new Set([
|
|
210
|
+
'allowNonAppliedPatches', 'alwaysAuth', 'email', 'enginePinManifest', 'ignoreDepScripts', 'ignorePatchFailures',
|
|
211
|
+
'lockfileDirectory', 'managePackageManagerVersions', 'nodeVersionFromEnginesRuntime', 'packageManagerStrict',
|
|
212
|
+
'packageManagerStrictVersion', 'shamefullyFlatten', 'useNodeVersion',
|
|
213
|
+
])
|
|
214
|
+
|
|
215
|
+
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
|
+
|
|
181
217
|
// The keys of the root package.json's `pnpm` field pnpm 10 reads; it
|
|
182
218
|
// passes over any other there.
|
|
183
219
|
export const MANIFEST_KEYS = [
|
|
@@ -206,7 +242,7 @@ export const IGNORED = new Set([
|
|
|
206
242
|
'fetchRetryMintimeout', 'fetchTimeout', 'httpProxy', 'httpsProxy', 'key', 'localAddress', 'maxsockets',
|
|
207
243
|
'networkConcurrency', 'noProxy', 'noproxy', 'offline', 'preferOffline', 'proxy', 'strictSsl', 'userAgent',
|
|
208
244
|
// the store, caches and state, none of it in node_modules
|
|
209
|
-
'cacheDir', 'modulesCacheMaxAge', '
|
|
245
|
+
'cacheDir', 'modulesCacheMaxAge', 'sideEffectsCache', 'sideEffectsCacheReadonly',
|
|
210
246
|
'stateDir', 'storeDir', 'strictStorePkgContentCheck', 'verifyStoreIntegrity',
|
|
211
247
|
// scripts, which are not run, and bins, which are not written
|
|
212
248
|
'allowBuilds', 'childConcurrency', 'dangerouslyAllowAllBuilds', 'enablePrePostScripts', 'extendNodePath',
|
|
@@ -252,13 +288,34 @@ function checkCatalogs(value, where) {
|
|
|
252
288
|
for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
|
|
253
289
|
}
|
|
254
290
|
|
|
291
|
+
// What pnpm of `major` does with a setting, as far as is known here: reads
|
|
292
|
+
// it, with `read`; leaves the tree as it is, with none; or for pnpm 12,
|
|
293
|
+
// does not recognize it. Undefined for one not known. pnpm 12 takes a
|
|
294
|
+
// pattern only as a list.
|
|
295
|
+
function lookup(name, major) {
|
|
296
|
+
if (major >= 12 && UNRECOGNIZED_12.has(name)) return { unrecognized: true }
|
|
297
|
+
if (major >= 12 && name in READ_12) return { read: READ_12[name] }
|
|
298
|
+
if (major >= 11 && name in READ_11) return { read: READ_11[name] }
|
|
299
|
+
if (IGNORED.has(name) || (major >= 11 && IGNORED_11.has(name)) || (major >= 12 && IGNORED_12.has(name))) return {}
|
|
300
|
+
if (!(name in READ)) return undefined
|
|
301
|
+
return { read: major >= 12 && READ[name].kind === 'texts' ? { ...READ[name], kind: 'list' } : READ[name] }
|
|
302
|
+
}
|
|
303
|
+
|
|
255
304
|
// What reads a setting for pnpm of `major`, or undefined for one that
|
|
256
|
-
// leaves the tree as it is; one
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (
|
|
261
|
-
|
|
305
|
+
// leaves the tree as it is; one not known is refused. `pinned` is whether
|
|
306
|
+
// pnpm 12 fails on one it does not recognize.
|
|
307
|
+
export function readerOf(name, where, major, pinned = false) {
|
|
308
|
+
const found = lookup(name, major)
|
|
309
|
+
if (found === undefined) throw new DeptreeError('unsupported setting', where)
|
|
310
|
+
if (found.unrecognized && pinned) throw unrecognized12(where)
|
|
311
|
+
return found.read
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Whether pnpm 12 knows a setting, read or passed over, as far as is known
|
|
315
|
+
// here.
|
|
316
|
+
export function known12(name) {
|
|
317
|
+
const found = lookup(name, 12)
|
|
318
|
+
return found !== undefined && !found.unrecognized
|
|
262
319
|
}
|
|
263
320
|
|
|
264
321
|
// By selector, the patch file, relative to the workspace's directory.
|
package/src/pnpm/settings.js
CHANGED
|
@@ -30,16 +30,23 @@
|
|
|
30
30
|
//
|
|
31
31
|
// pnpm 11 reads its settings from pnpm-workspace.yaml alone: an .npmrc
|
|
32
32
|
// for credentials and registries, and the package.json for none but the
|
|
33
|
-
// Node its engines.runtime pins, which it takes
|
|
33
|
+
// Node its engines.runtime pins, runtimeNodeVersion, which it takes where
|
|
34
|
+
// nodeVersion is not set. Of the
|
|
34
35
|
// yaml it passes over a key not in camelCase, and one about the machine,
|
|
35
36
|
// the run or a login; it has settings pnpm 10 has not (READ_11, IGNORED_11),
|
|
36
37
|
// and reads linkWorkspacePackages for a frozen install too.
|
|
38
|
+
//
|
|
39
|
+
// pnpm 12 reads them as pnpm 11 does, and has settings of its own (READ_12,
|
|
40
|
+
// IGNORED_12); where the root package.json pins the pnpm that runs, it
|
|
41
|
+
// fails on a key of pnpm-workspace.yaml with a value it does not know,
|
|
42
|
+
// pnpm 11's that it has not among them (UNRECOGNIZED_12), which it drops
|
|
43
|
+
// otherwise.
|
|
37
44
|
|
|
38
45
|
import { valid, validRange } from '@preventive/upstream/semver.js'
|
|
39
46
|
import { DeptreeError, quote } from '../error.js'
|
|
40
47
|
import { parseNpmrc } from './npmrc.js'
|
|
41
48
|
import { replaceReferences } from './overrides.js'
|
|
42
|
-
import { IGNORED, MANIFEST_KEYS, READ, checkRegistry, readerOf, readers } from './readers.js'
|
|
49
|
+
import { IGNORED, MANIFEST_KEYS, READ, checkRegistry, known12, readerOf, readers, unrecognized12 } from './readers.js'
|
|
43
50
|
|
|
44
51
|
// An .npmrc value read only where it can mean one thing: not quoted, not
|
|
45
52
|
// escaped, with no `;` or `#` that ini would cut it at. Neither file's
|
|
@@ -124,15 +131,19 @@ function fromManifest(manifest) {
|
|
|
124
131
|
// pnpm 11 passes over a key not in camelCase.
|
|
125
132
|
const CAMEL = /^[a-z][\dA-Za-z]*$/u
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
// pnpm 12 passes over a key with no value. `pinned` is readerOf's.
|
|
135
|
+
function fromWorkspace(workspace, major, pinned) {
|
|
128
136
|
if (workspace === null || typeof workspace !== 'object' || Array.isArray(workspace)) throw new DeptreeError('expected a mapping', 'pnpm-workspace.yaml')
|
|
129
137
|
const settings = new Map()
|
|
130
138
|
for (const [name, value] of Object.entries(workspace)) {
|
|
131
139
|
const where = `pnpm-workspace.yaml: ${name}`
|
|
132
140
|
noEnvironment(name, where)
|
|
133
141
|
noEnvironment(value, where)
|
|
134
|
-
if (major >= 11 && !CAMEL.test(name))
|
|
135
|
-
|
|
142
|
+
if (major >= 11 && !CAMEL.test(name)) {
|
|
143
|
+
if (major >= 12 && pinned && value !== null && !known12(camelCase(name))) throw unrecognized12(where)
|
|
144
|
+
continue
|
|
145
|
+
}
|
|
146
|
+
const read = readerOf(name, where, major, pinned && value !== null)
|
|
136
147
|
if (read !== undefined) settings.set(name, { value, where, read })
|
|
137
148
|
}
|
|
138
149
|
return settings
|
|
@@ -155,6 +166,7 @@ function derive(get) {
|
|
|
155
166
|
hoistWorkspacePackages: get('hoistWorkspacePackages') ?? true,
|
|
156
167
|
engineStrict: get('engineStrict') ?? false,
|
|
157
168
|
nodeVersion: get('nodeVersion'),
|
|
169
|
+
runtimeNodeVersion: undefined,
|
|
158
170
|
supportedArchitectures: get('supportedArchitectures'),
|
|
159
171
|
patchedDependencies: get('patchedDependencies'),
|
|
160
172
|
overrides: get('overrides'),
|
|
@@ -168,6 +180,7 @@ function derive(get) {
|
|
|
168
180
|
linkWorkspacePackages: get('linkWorkspacePackages') ?? false,
|
|
169
181
|
pmOnFail: get('pmOnFail'),
|
|
170
182
|
runtimeOnFail: get('runtimeOnFail'),
|
|
183
|
+
packageImportMethod: get('packageImportMethod') ?? 'auto',
|
|
171
184
|
}
|
|
172
185
|
}
|
|
173
186
|
|
|
@@ -199,16 +212,17 @@ function settle(layers, manifest) {
|
|
|
199
212
|
|
|
200
213
|
// `workspace` is pnpm-workspace.yaml as parsed and `npmrc` the text of the
|
|
201
214
|
// .npmrc, either of which may be undefined; `manifest` the root
|
|
202
|
-
// package.json as parsed
|
|
215
|
+
// package.json as parsed; `pinned` whether it pins the pnpm that runs,
|
|
216
|
+
// which pnpm 12 holds pnpm-workspace.yaml's keys to. Overrides that name nothing are none, and leave
|
|
203
217
|
// those below them.
|
|
204
|
-
export function readSettings({ workspace, npmrc, manifest, major = 10 }) {
|
|
205
|
-
const fromYaml = () => (workspace === undefined ? new Map() : fromWorkspace(workspace, major))
|
|
218
|
+
export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
|
|
219
|
+
const fromYaml = () => (workspace === undefined ? new Map() : fromWorkspace(workspace, major, pinned))
|
|
206
220
|
// pnpm 11 reads its settings from pnpm-workspace.yaml alone, and none
|
|
207
221
|
// from the package.json, its `resolutions` none.
|
|
208
222
|
if (major >= 11) {
|
|
209
223
|
if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
|
|
210
224
|
const settings = settle([fromYaml()], manifest)
|
|
211
|
-
settings.
|
|
225
|
+
settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
|
|
212
226
|
return settings
|
|
213
227
|
}
|
|
214
228
|
const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc)
|
|
@@ -221,7 +235,8 @@ export function readSettings({ workspace, npmrc, manifest, major = 10 }) {
|
|
|
221
235
|
}
|
|
222
236
|
|
|
223
237
|
// The Node the root package.json's devEngines.runtime or engines.runtime
|
|
224
|
-
// pins, which pnpm 11 takes for nodeVersion where none is set
|
|
238
|
+
// pins, which pnpm 11 takes for nodeVersion where none is set, and so does
|
|
239
|
+
// pnpm 12 but for a patched package's engines (install.js): the first
|
|
225
240
|
// that names a range for Node decides, and gives its version where that is
|
|
226
241
|
// exact. One to download, which gives the range's lowest, is refused;
|
|
227
242
|
// runtimeOnFail stands for each one's onFail.
|