@preventive/deptree 1.0.0-alpha.0 → 1.0.0-alpha.1
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 +2 -1
- package/pnpm.d.ts +48 -6
- package/pnpm.js +1 -1
- package/src/mount.js +14 -7
- package/src/pnpm/bins.js +14 -14
- package/src/pnpm/frozen.js +30 -20
- package/src/pnpm/hoist.js +5 -4
- package/src/pnpm/hook.js +13 -22
- package/src/pnpm/install.js +40 -29
- package/src/pnpm/local.js +27 -11
- package/src/pnpm/overrides.js +12 -5
- package/src/pnpm/packlist.js +99 -0
- package/src/pnpm/patches.js +3 -3
- package/src/pnpm/projects.js +23 -17
- package/src/pnpm/settings.js +34 -21
- package/src/pnpm/tree.js +111 -44
- package/src/pnpm/uptodate.js +1 -1
- package/src/pnpm/workspace.js +169 -38
- package/src/tarball.js +11 -5
package/src/pnpm/local.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
// Directories outside node_modules the tree links to
|
|
2
|
-
// given as `vfs` where there is one: those local
|
|
3
|
-
// every other a `link:` leads to that is no project
|
|
4
|
-
// lockfile's directory. Each has to hold a package.json
|
|
5
|
-
// take their names as pnpm links them. An override to a
|
|
6
|
-
// read only from a Vfs given
|
|
7
|
-
//
|
|
8
|
-
//
|
|
1
|
+
// Directories outside node_modules the tree links to or installs,
|
|
2
|
+
// read from the Vfs given as `vfs` where there is one: those local
|
|
3
|
+
// overrides name, and every other a `link:` leads to that is no project
|
|
4
|
+
// and is under the lockfile's directory. Each has to hold a package.json
|
|
5
|
+
// there, whose bins take their names as pnpm links them. An override to a
|
|
6
|
+
// directory is read only from a Vfs given. One by `file:` has pnpm install
|
|
7
|
+
// the directory as a package, of the files npm-packlist picks
|
|
8
|
+
// (packlist.js); one to a tarball is refused.
|
|
9
9
|
|
|
10
10
|
import { DeptreeError, quote } from '../error.js'
|
|
11
|
+
import { packDirectory } from './packlist.js'
|
|
11
12
|
import { readManifest } from './projects.js'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
// readManifest drops a byte order mark, as pnpm does one.
|
|
15
|
+
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
|
|
14
16
|
|
|
15
17
|
function manifestAt(vfs, dir, where) {
|
|
16
18
|
const path = `/${dir}/package.json`
|
|
@@ -24,15 +26,29 @@ function manifestAt(vfs, dir, where) {
|
|
|
24
26
|
return readManifest(text, where)
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
// `overrides` is listOverrides's.
|
|
29
|
+
// `overrides` is listOverrides's. It gives back the directories `file:`
|
|
30
|
+
// overrides have pnpm install.
|
|
28
31
|
export function checkLocalOverrides(overrides, vfs) {
|
|
32
|
+
const installed = new Set()
|
|
29
33
|
for (const { selector, local } of overrides) {
|
|
30
34
|
if (local === undefined) continue
|
|
31
35
|
const where = `overrides[${quote(selector)}]`
|
|
32
|
-
if (local.protocol === 'file:') throw new DeptreeError('an override to a copy of a directory, as file: has pnpm install it, is not supported: pnpm picks the files it copies with npm-packlist', where)
|
|
33
36
|
if (vfs === undefined) throw new DeptreeError(`an override to a directory, ${quote(local.dir)}, is read only from a Vfs given as vfs`, where)
|
|
37
|
+
if (local.protocol === 'file:' && vfs.isFile(`/${local.dir}`)) throw new DeptreeError(`${quote(local.dir)} is a file in the Vfs given, and an override to a tarball is not supported`, where)
|
|
34
38
|
manifestAt(vfs, local.dir, where)
|
|
39
|
+
if (local.protocol === 'file:') installed.add(local.dir)
|
|
35
40
|
}
|
|
41
|
+
return installed
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The package at the directory a `file:` dependency names, from `vfs`:
|
|
45
|
+
// its files as npm-packlist picks them, and its package.json, which has
|
|
46
|
+
// to be for the name the lockfile has; the lockfile has no version.
|
|
47
|
+
export function readDirectoryPackage(vfs, pkg, where, major) {
|
|
48
|
+
const { directory } = pkg.resolution
|
|
49
|
+
const manifest = manifestAt(vfs, directory, where)
|
|
50
|
+
if (manifest.name !== pkg.name) throw new DeptreeError(`its package.json is for ${quote(String(manifest.name))}`, where)
|
|
51
|
+
return { files: packDirectory(vfs, directory, manifest, major, where), manifest }
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
// By directory, the package.json of each directory the tree links to that
|
package/src/pnpm/overrides.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// with a parent and an empty range, and one whose version is not exact.
|
|
31
31
|
|
|
32
32
|
import { valid } from '@preventive/upstream/semver.js'
|
|
33
|
-
import { join
|
|
33
|
+
import { join } from '@preventive/vfs/path.js'
|
|
34
34
|
import { DeptreeError, quote } from '../error.js'
|
|
35
35
|
|
|
36
36
|
// validate-npm-package-name 5's validForOldPackages, which pnpm reads a
|
|
@@ -82,12 +82,19 @@ export function replaceReferences(overrides, manifest, where) {
|
|
|
82
82
|
|
|
83
83
|
const CATALOG = 'catalog:'
|
|
84
84
|
|
|
85
|
+
// The catalog a `catalog:` specifier names, `default` where it names none,
|
|
86
|
+
// or undefined for another specifier.
|
|
87
|
+
export const catalogOf = (spec) => (spec.startsWith(CATALOG) ? spec.slice(CATALOG.length).trim() || 'default' : undefined)
|
|
88
|
+
|
|
89
|
+
// The entry catalog `catalog` of `catalogs` has for `name`, if any.
|
|
90
|
+
export const catalogEntry = (catalogs, catalog, name) => (Object.hasOwn(catalogs, catalog) && Object.hasOwn(catalogs[catalog], name) ? catalogs[catalog][name] : undefined)
|
|
91
|
+
|
|
85
92
|
// @pnpm/catalogs.resolver's resolveFromCatalog: the specifier a catalog
|
|
86
93
|
// gives `name`, where `spec` asks for one.
|
|
87
94
|
function fromCatalog(catalogs, spec, name, where, major) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const found =
|
|
95
|
+
const catalog = catalogOf(spec)
|
|
96
|
+
if (catalog === undefined) return spec
|
|
97
|
+
const found = catalogEntry(catalogs, catalog, name)
|
|
91
98
|
const refused = found === undefined ? `catalog ${quote(catalog)} has no entry for ${quote(name)}`
|
|
92
99
|
: found.startsWith(CATALOG) ? `the entry for ${quote(name)} in catalog ${quote(catalog)} is itself a catalog reference`
|
|
93
100
|
: ['link', 'file', ...(major >= 11 ? [] : ['workspace'])].includes(found.split(':')[0]) ? `the entry for ${quote(name)} in catalog ${quote(catalog)} uses a protocol pnpm refuses in a catalog`
|
|
@@ -102,7 +109,7 @@ export function localOf(spec, where) {
|
|
|
102
109
|
const protocol = ['file:', 'link:'].find((prefix) => spec.startsWith(prefix)) ?? (/^(?:[./]|~\/)/u.test(spec) ? '' : undefined)
|
|
103
110
|
if (protocol === undefined) return undefined
|
|
104
111
|
const path = spec.slice(protocol.length).replace(/\/+$/u, '')
|
|
105
|
-
const dir = /^(?:[/\\]|~[/\\]|[A-Za-z]:)/u.test(path) || path.includes('\\') ? '..' :
|
|
112
|
+
const dir = /^(?:[/\\]|~[/\\]|[A-Za-z]:)/u.test(path) || path.includes('\\') ? '..' : join('.', path)
|
|
106
113
|
if (dir === '..' || dir.startsWith('../')) throw new DeptreeError(`${quote(spec)} is not a directory under the lockfile's, which is not supported`, where)
|
|
107
114
|
return { protocol, dir }
|
|
108
115
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// The files pnpm installs of a directory a `file:` dependency names: its
|
|
2
|
+
// directory fetcher picks them with npm-packlist — 5.1.3 for pnpm 10,
|
|
3
|
+
// 10.0.4 for pnpm 11 — and hardlinks them into the tree. Only
|
|
4
|
+
// npm-packlist's built-in rules are followed here, which leave out, by
|
|
5
|
+
// name and whatever its case:
|
|
6
|
+
//
|
|
7
|
+
// - anywhere, `.git`, `.svn`, `.hg`, `CVS`, `.npmrc`, `.DS_Store`,
|
|
8
|
+
// `npm-debug.log`, `.npmignore`, `.gitignore`, and a name starting
|
|
9
|
+
// with `._`, or `.` and ending in `.swp`, or ending in `.orig`, with
|
|
10
|
+
// everything in it;
|
|
11
|
+
// - at the top, and with pnpm 11 in every directory, `.lock-wscript`,
|
|
12
|
+
// `.wafpickle-*`, `build/config.gypi` and what is in
|
|
13
|
+
// `archived-packages`;
|
|
14
|
+
// - at the top, `node_modules` and the lockfiles `package-lock.json`,
|
|
15
|
+
// `yarn.lock`, `pnpm-lock.yaml` and, with pnpm 11, `bun.lockb`;
|
|
16
|
+
//
|
|
17
|
+
// and every name with a `*` in it. A directory those do not describe is
|
|
18
|
+
// refused: one with a .npmignore or .gitignore in it, or a package.json
|
|
19
|
+
// with `files` or bundled dependencies, whose rules are not followed
|
|
20
|
+
// here; one with a link in it, which the two pass over differently; and
|
|
21
|
+
// one where a file those leave out is one npm-packlist would keep, a
|
|
22
|
+
// readme, copying, license or licence file, or one `main`, `browser` or
|
|
23
|
+
// `bin` names, as the two keep them differently. So is a file whose mode
|
|
24
|
+
// is not 0o644 or 0o755, which linking a bin would change otherwise than
|
|
25
|
+
// fixBin has it.
|
|
26
|
+
|
|
27
|
+
import { join } from '@preventive/vfs/path.js'
|
|
28
|
+
import { DeptreeError, quote } from '../error.js'
|
|
29
|
+
|
|
30
|
+
// The rules each name is held to, folded, wherever it is.
|
|
31
|
+
const ANYWHERE = /^(?:\.git|\.svn|\.hg|cvs|\.npmrc|\.ds_store|npm-debug\.log|\.npmignore|\.gitignore|\._.*|\..*\.swp|.*\.orig)$/u
|
|
32
|
+
|
|
33
|
+
// The rules held to the path, by its names folded, from the directory they
|
|
34
|
+
// are read in: the top for npm-packlist 5, and every directory for
|
|
35
|
+
// npm-packlist 10, which reads them again in each.
|
|
36
|
+
const anchored = (names, directory) => (names.length === 1 && (names[0] === '.lock-wscript' || names[0].startsWith('.wafpickle-') || (directory && names[0] === 'archived-packages')))
|
|
37
|
+
|| (names.length === 2 && names[0] === 'build' && names[1] === 'config.gypi')
|
|
38
|
+
|
|
39
|
+
// The names left out at the top alone.
|
|
40
|
+
const TOP = ['node_modules', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml']
|
|
41
|
+
const TOP_11 = [...TOP, 'bun.lockb']
|
|
42
|
+
|
|
43
|
+
// Whether the built-in rules leave out the entry at `names`, its path from
|
|
44
|
+
// the package's directory by name, which is a directory where `directory`.
|
|
45
|
+
function leftOut(names, directory, major) {
|
|
46
|
+
const folded = names.map((name) => name.toLowerCase())
|
|
47
|
+
const readIn = major >= 11 ? folded.map((_, i) => folded.slice(i)) : [folded]
|
|
48
|
+
return ANYWHERE.test(folded.at(-1)) || readIn.some((path) => anchored(path, directory))
|
|
49
|
+
|| (folded.length === 1 && (major >= 11 ? TOP_11 : TOP).includes(folded[0]))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// npm-packlist's names it keeps, whatever else says.
|
|
53
|
+
const MUST_HAVE = /^(?:readme|copying|license|licence)(?:\..*[^~$])?$/iu
|
|
54
|
+
|
|
55
|
+
// The paths a package.json's main, browser and bin name, from its
|
|
56
|
+
// directory, whatever their case.
|
|
57
|
+
function namedByManifest(manifest) {
|
|
58
|
+
const { main, browser, bin } = manifest
|
|
59
|
+
const paths = [main, browser, ...typeof bin === 'string' ? [bin] : Object.values(bin ?? {})]
|
|
60
|
+
return paths.filter((path) => typeof path === 'string').map((path) => join('.', path).toLowerCase())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Whether a package.json's list of bundled dependencies may name any: an
|
|
64
|
+
// empty one bundles none, with either npm-packlist.
|
|
65
|
+
const bundles = (list) => Boolean(list) && !(Array.isArray(list) && list.length === 0)
|
|
66
|
+
|
|
67
|
+
// The files of the package at `dir` of `vfs` npm-packlist picks, with
|
|
68
|
+
// their data and modes, by their paths from it; `manifest` is its
|
|
69
|
+
// package.json as parsed.
|
|
70
|
+
export function packDirectory(vfs, dir, manifest, major, where) {
|
|
71
|
+
if (manifest.files !== undefined) throw new DeptreeError('its package.json has `files`, which npm-packlist picks the files pnpm installs by, and which is not followed here', where)
|
|
72
|
+
if (bundles(manifest.bundleDependencies) || bundles(manifest.bundledDependencies)) throw new DeptreeError('a directory with bundled dependencies is not supported', where)
|
|
73
|
+
const named = namedByManifest(manifest)
|
|
74
|
+
const files = new Map()
|
|
75
|
+
const visit = (names) => {
|
|
76
|
+
for (const entry of vfs.readdir(['', dir, ...names].join('/'))) {
|
|
77
|
+
const at = [...names, entry]
|
|
78
|
+
const rel = at.join('/')
|
|
79
|
+
const here = `${where}: ${quote(rel)}`
|
|
80
|
+
const { type, mode } = vfs.lstat(`/${dir}/${rel}`)
|
|
81
|
+
if (type === 'symlink') throw new DeptreeError('a link in a directory pnpm installs a copy of is not supported', here)
|
|
82
|
+
if (entry === '.npmignore' || entry === '.gitignore') throw new DeptreeError(`${entry}'s rules, which npm-packlist picks the files pnpm installs by, are not followed here`, here)
|
|
83
|
+
if (names.length === 0 && entry !== 'node_modules' && entry.toLowerCase() === 'node_modules') throw new DeptreeError('a name that is node_modules but for its case is kept by pnpm 10 and left out by pnpm 11', here)
|
|
84
|
+
if (entry.includes('*')) continue
|
|
85
|
+
if (leftOut(at, type === 'directory', major)) {
|
|
86
|
+
const folded = rel.toLowerCase()
|
|
87
|
+
if (MUST_HAVE.test(entry) || named.some((kept) => kept === folded || kept.startsWith(`${folded}/`))) {
|
|
88
|
+
throw new DeptreeError('whether pnpm installs it turns on rules of npm-packlist not followed here', here)
|
|
89
|
+
}
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
if (type === 'directory') visit(at)
|
|
93
|
+
else if (mode !== 0o644 && mode !== 0o755) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644 or 755, which is not supported`, here)
|
|
94
|
+
else files.set(rel, { data: vfs.readFile(`/${dir}/${rel}`), mode })
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
visit([])
|
|
98
|
+
return files
|
|
99
|
+
}
|
package/src/pnpm/patches.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// some snapshot.
|
|
10
10
|
|
|
11
11
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
12
|
-
import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
12
|
+
import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
13
13
|
import { DeptreeError, quote } from '../error.js'
|
|
14
14
|
|
|
15
15
|
// dependency-path's parse of a selector: a name and an exact version, a
|
|
@@ -19,7 +19,7 @@ function parseSelector(selector) {
|
|
|
19
19
|
const rest = at === -1 ? '' : packageKeyOf(selector).slice(at + 1)
|
|
20
20
|
if (rest === '') return {}
|
|
21
21
|
const name = selector.slice(0, at)
|
|
22
|
-
return
|
|
22
|
+
return isExactVersion(rest) ? { name, version: rest } : { name, range: rest }
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// groupPatchedDependencies: by package name, the selectors that can pick
|
|
@@ -117,7 +117,7 @@ export function checkPeerPatches(lockfile, hashes) {
|
|
|
117
117
|
const known = lockfile.packages[key]?.version ?? version
|
|
118
118
|
const found = groups.get(name)
|
|
119
119
|
if (known === undefined && found !== undefined && (found.exact.size > 0 || found.ranges.length > 0)) throw uncheckable(key, where)
|
|
120
|
-
const selector =
|
|
120
|
+
const selector = pick(groups, name, known ?? '', where)
|
|
121
121
|
if ((selector === undefined ? undefined : hashes[selector].hash) !== hash) {
|
|
122
122
|
throw new DeptreeError(`the patch hash ${quote(key)} names is not the one of the patch pnpm picks for it, which pnpm 11 refuses a frozen install for`, where)
|
|
123
123
|
}
|
package/src/pnpm/projects.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
// (@pnpm/lockfile.verification's satisfiesPackageManifest): where one is
|
|
4
4
|
// not, pnpm refuses the lockfile as not up to date with that package.json,
|
|
5
5
|
// and resolves anew without --frozen-lockfile, so it is refused here too.
|
|
6
|
-
// Every
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// Every importer has to be a project: the projects pnpm finds are what it
|
|
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.
|
|
9
10
|
//
|
|
10
11
|
// A project's specifiers are its dependencies, devDependencies and
|
|
11
12
|
// optionalDependencies, and, with autoInstallPeers, the peerDependencies
|
|
@@ -30,14 +31,12 @@
|
|
|
30
31
|
// --frozen-lockfile, that workspace packages are linked exactly where
|
|
31
32
|
// their version is in range, are not made; pnpm 11 makes them frozen too.
|
|
32
33
|
|
|
33
|
-
import {
|
|
34
|
-
import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
34
|
+
import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
35
35
|
import { DeptreeError, difference, quote } from '../error.js'
|
|
36
|
-
import { checkCatalogResolutions, checkLinkTargets, checkLinkedPackages,
|
|
36
|
+
import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
|
|
37
37
|
import { checkProject } from './install.js'
|
|
38
38
|
import { validForOldPackages } from './overrides.js'
|
|
39
|
-
|
|
40
|
-
const KINDS = ['optionalDependencies', 'dependencies', 'devDependencies']
|
|
39
|
+
import { checkProjectId } from './workspace.js'
|
|
41
40
|
|
|
42
41
|
// A package.json as parsed, as pnpm reads one: a byte order mark dropped,
|
|
43
42
|
// and an object.
|
|
@@ -60,7 +59,10 @@ export function readManifests(manifests, lockfile) {
|
|
|
60
59
|
const read = new Map()
|
|
61
60
|
for (const [id, text] of manifests instanceof Map ? manifests : Object.entries(manifests)) {
|
|
62
61
|
const where = `manifests[${quote(id)}]`
|
|
63
|
-
if (!(id in lockfile.importers))
|
|
62
|
+
if (!(id in lockfile.importers)) {
|
|
63
|
+
checkProjectId(id, where)
|
|
64
|
+
lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true }
|
|
65
|
+
}
|
|
64
66
|
read.set(id, readManifest(text, where))
|
|
65
67
|
}
|
|
66
68
|
for (const id of Object.keys(lockfile.importers)) {
|
|
@@ -102,7 +104,7 @@ function checkKind(importer, kinds, kind, unresolved, major) {
|
|
|
102
104
|
if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
|
|
103
105
|
const spec = importer.specifiers[name]
|
|
104
106
|
if (validRange(spec) === null) continue
|
|
105
|
-
const version =
|
|
107
|
+
const version = resolvedOf(name, locked[name])
|
|
106
108
|
if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
|
|
107
109
|
}
|
|
108
110
|
return undefined
|
|
@@ -166,7 +168,7 @@ function checkPackageManager(manifest, host, pmOnFail) {
|
|
|
166
168
|
if (packageManager === undefined) return
|
|
167
169
|
const where = 'manifests["."].packageManager'
|
|
168
170
|
const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
|
|
169
|
-
if (
|
|
171
|
+
if (!isExactVersion(version)) throw new DeptreeError(`${quote(String(packageManager))} is not pnpm at an exact version`, where)
|
|
170
172
|
if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
|
|
171
173
|
}
|
|
172
174
|
|
|
@@ -175,22 +177,23 @@ function checkPackageManager(manifest, host, pmOnFail) {
|
|
|
175
177
|
// project, pnpm 11 takes runtimeOnFail for each one's onFail, and checks a
|
|
176
178
|
// runtime whose onFail is `error` against the host's before it installs.
|
|
177
179
|
const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
|
|
178
|
-
|
|
180
|
+
const RUNTIME_NAMES = ['node', 'deno', 'bun']
|
|
181
|
+
function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
179
182
|
const checked = new Set()
|
|
180
183
|
for (const [field, kind] of RUNTIMES) {
|
|
181
184
|
const runtime = manifest[field]?.runtime
|
|
182
185
|
if (runtime === undefined || runtime === null) continue
|
|
183
186
|
const here = `${where}.${field}.runtime`
|
|
184
187
|
const runtimes = Array.isArray(runtime) ? runtime : [runtime]
|
|
185
|
-
for (const name of
|
|
188
|
+
for (const name of RUNTIME_NAMES) {
|
|
186
189
|
if (manifest[kind]?.[name]) continue
|
|
187
190
|
const item = runtimes.find((each) => each?.name === name)
|
|
188
191
|
if (item !== undefined && (onFail ?? item.onFail) === 'download') throw new DeptreeError(`a ${name} runtime to download is not supported`, here)
|
|
189
192
|
}
|
|
190
|
-
if (host.major < 11 ||
|
|
193
|
+
if (host.major < 11 || !root) continue
|
|
191
194
|
if (runtimes.some((item) => item === null || typeof item !== 'object')) throw new DeptreeError('expected a mapping or a list of mappings, which pnpm 11 fails on otherwise', here)
|
|
192
195
|
for (const item of runtimes) {
|
|
193
|
-
if (!
|
|
196
|
+
if (!RUNTIME_NAMES.includes(item.name) || checked.has(item.name)) continue
|
|
194
197
|
checked.add(item.name)
|
|
195
198
|
if ((onFail ?? item.onFail) !== 'error') continue
|
|
196
199
|
if (item.name !== 'node') throw new DeptreeError(`the ${item.name} it runs on is checked by pnpm 11, and is not known here`, here)
|
|
@@ -204,10 +207,12 @@ function checkRuntimes(manifest, where, { host, onFail }) {
|
|
|
204
207
|
// and `settings` what its engines are held to.
|
|
205
208
|
export function checkProjects(lockfile, manifests, { hook, host, settings }) {
|
|
206
209
|
checkPackageManager(manifests.get('.'), host, settings.pmOnFail)
|
|
210
|
+
let index
|
|
207
211
|
for (const [id, manifest] of manifests) {
|
|
208
212
|
const where = `manifests[${quote(id)}]`
|
|
213
|
+
const root = id === '.'
|
|
209
214
|
checkProject(manifest, where, { host, settings })
|
|
210
|
-
checkRuntimes(manifest, where, { host, onFail:
|
|
215
|
+
checkRuntimes(manifest, where, { host, root, onFail: root ? settings.runtimeOnFail : undefined })
|
|
211
216
|
const hooked = hook(manifest, where, { dir: id })
|
|
212
217
|
const importer = lockfile.importers[id]
|
|
213
218
|
const reason = mismatch(importer, hooked, settings.autoInstallPeers, host.major, where)
|
|
@@ -215,7 +220,8 @@ export function checkProjects(lockfile, manifests, { hook, host, settings }) {
|
|
|
215
220
|
checkLinkTargets({ id, manifest: hooked, importer }, where)
|
|
216
221
|
if (host.major < 11) continue
|
|
217
222
|
checkCatalogResolutions(importer, lockfile.catalogs, where)
|
|
218
|
-
|
|
223
|
+
index ??= indexProjects(manifests)
|
|
224
|
+
checkLinkedPackages({ manifest: hooked, importer, index, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
|
|
219
225
|
}
|
|
220
226
|
}
|
|
221
227
|
|
package/src/pnpm/settings.js
CHANGED
|
@@ -61,20 +61,25 @@ function noEnvironment(value, where) {
|
|
|
61
61
|
const KEBAB = /^[a-z][\da-z]*(?:-[\da-z]+)*$/u
|
|
62
62
|
const camelCase = (key) => key.replace(/-+([a-z\d])/gu, (_, char) => char.toUpperCase())
|
|
63
63
|
|
|
64
|
+
// pnpm 11 reads an .npmrc for credentials and registries alone: each
|
|
65
|
+
// registry has to be the public one, but one of a project's .npmrc that
|
|
66
|
+
// names a variable is passed over.
|
|
67
|
+
function checkNpmrcRegistries(text) {
|
|
68
|
+
for (const { key, value, line } of parseNpmrc(text)) {
|
|
69
|
+
if ((key !== 'registry' && !/^@[^:]+:registry$/u.test(key)) || fromEnvironment(value)) continue
|
|
70
|
+
const where = `.npmrc:${line}: ${key}`
|
|
71
|
+
checkRegistry(plain(value, where), where)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
// An .npmrc's settings by name, each written once, or once with `[]` each
|
|
65
76
|
// time, and whether any line takes something from the environment. A
|
|
66
77
|
// registry for a scope has to be the public one.
|
|
67
|
-
|
|
68
|
-
// over a registry of a project's .npmrc that names a variable.
|
|
69
|
-
function fromNpmrc(text, major) {
|
|
78
|
+
function fromNpmrc(text) {
|
|
70
79
|
const settings = new Map()
|
|
71
80
|
let environment = false
|
|
72
81
|
for (const { key, value, list, line } of parseNpmrc(text)) {
|
|
73
82
|
const where = `.npmrc:${line}: ${key}`
|
|
74
|
-
if (major >= 11) {
|
|
75
|
-
if ((key === 'registry' || /^@[^:]+:registry$/u.test(key)) && !fromEnvironment(value)) checkRegistry(plain(value, where), where)
|
|
76
|
-
continue
|
|
77
|
-
}
|
|
78
83
|
if (/^@[^:]+:registry$/u.test(key)) {
|
|
79
84
|
checkRegistry(plain(noEnvironment(value, where), where), where)
|
|
80
85
|
continue
|
|
@@ -136,14 +141,15 @@ function fromWorkspace(workspace, major) {
|
|
|
136
141
|
// The settings as pnpm 10 derives what it installs by: `hoist: false`
|
|
137
142
|
// drops the private pattern, `shamefullyHoist` sets or drops the public
|
|
138
143
|
// one, and an empty public pattern is none. A pattern left undefined is
|
|
139
|
-
// not hoisted to at all.
|
|
140
|
-
|
|
144
|
+
// not hoisted to at all. virtualStoreDirMaxLength is 60 by default on
|
|
145
|
+
// Windows alone, which is refused (tree.js's checkHost).
|
|
146
|
+
function derive(get) {
|
|
141
147
|
const shamefullyHoist = get('shamefullyHoist')
|
|
142
148
|
let publicHoistPattern = get('publicHoistPattern') ?? []
|
|
143
149
|
if (shamefullyHoist === true) publicHoistPattern = ['*']
|
|
144
150
|
else if (shamefullyHoist === false || (publicHoistPattern.length === 1 && publicHoistPattern[0] === '')) publicHoistPattern = undefined
|
|
145
151
|
return {
|
|
146
|
-
virtualStoreDirMaxLength: get('virtualStoreDirMaxLength') ??
|
|
152
|
+
virtualStoreDirMaxLength: get('virtualStoreDirMaxLength') ?? 120,
|
|
147
153
|
hoistPattern: get('hoist') === false ? undefined : get('hoistPattern') ?? ['*'],
|
|
148
154
|
publicHoistPattern,
|
|
149
155
|
hoistWorkspacePackages: get('hoistWorkspacePackages') ?? true,
|
|
@@ -175,7 +181,7 @@ function catalogsOf(catalog, catalogs = {}) {
|
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
// Each layer over the one before, as `derive` has them.
|
|
178
|
-
function settle(layers, manifest
|
|
184
|
+
function settle(layers, manifest) {
|
|
179
185
|
const values = new Map()
|
|
180
186
|
for (const layer of layers) {
|
|
181
187
|
for (const [name, { value, where, read: { kind, check } }] of layer) {
|
|
@@ -188,22 +194,29 @@ function settle(layers, manifest, os) {
|
|
|
188
194
|
values.set(name, read)
|
|
189
195
|
}
|
|
190
196
|
}
|
|
191
|
-
return derive((name) => values.get(name)
|
|
197
|
+
return derive((name) => values.get(name))
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
// `workspace` is pnpm-workspace.yaml as parsed and `npmrc` the text of the
|
|
195
201
|
// .npmrc, either of which may be undefined; `manifest` the root
|
|
196
|
-
// package.json as parsed.
|
|
197
|
-
//
|
|
198
|
-
export function readSettings({ workspace, npmrc, manifest,
|
|
199
|
-
const
|
|
200
|
-
// pnpm 11 reads
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
// package.json as parsed. Overrides that name nothing are none, and leave
|
|
203
|
+
// those below them.
|
|
204
|
+
export function readSettings({ workspace, npmrc, manifest, major = 10 }) {
|
|
205
|
+
const fromYaml = () => (workspace === undefined ? new Map() : fromWorkspace(workspace, major))
|
|
206
|
+
// pnpm 11 reads its settings from pnpm-workspace.yaml alone, and none
|
|
207
|
+
// from the package.json, its `resolutions` none.
|
|
208
|
+
if (major >= 11) {
|
|
209
|
+
if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
|
|
210
|
+
const settings = settle([fromYaml()], manifest)
|
|
211
|
+
settings.nodeVersion ??= runtimeNode(manifest, settings.runtimeOnFail)
|
|
212
|
+
return settings
|
|
213
|
+
}
|
|
214
|
+
const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc)
|
|
215
|
+
const rest = [fromYaml(), fromManifest(manifest)]
|
|
216
|
+
const settings = settle([rc.settings, ...rest], manifest)
|
|
217
|
+
if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest))) {
|
|
204
218
|
throw new DeptreeError('a line takes a value from the environment, which pnpm drops the whole file for where it is unset, and the file sets what would change the tree', '.npmrc')
|
|
205
219
|
}
|
|
206
|
-
if (major >= 11) settings.nodeVersion ??= runtimeNode(manifest, settings.runtimeOnFail)
|
|
207
220
|
return settings
|
|
208
221
|
}
|
|
209
222
|
|