@preventive/deptree 1.0.0-alpha.5 → 1.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/npm.d.ts +288 -0
- package/npm.js +7 -0
- package/package.json +41 -12
- package/pnpm.d.ts +158 -25
- package/pnpm.js +2 -10
- package/soldeer.d.ts +13 -0
- package/soldeer.js +1 -7
- package/src/concurrent.js +16 -17
- package/src/error.js +5 -9
- package/src/glob.js +55 -0
- package/src/hash.js +60 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +104 -44
- 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 +57 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +136 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +22 -41
- package/src/pnpm/bins.js +152 -131
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +53 -96
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +29 -75
- package/src/pnpm/gitignore.js +139 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +68 -61
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +73 -56
- package/src/pnpm/install.js +85 -131
- package/src/pnpm/local.js +21 -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 +121 -0
- package/src/pnpm/packlist.js +169 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +63 -83
- package/src/pnpm/settings.js +64 -100
- package/src/pnpm/tree.js +197 -169
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +124 -133
- package/src/project.js +57 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +5 -15
- package/src/soldeer/tree.js +22 -60
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +55 -140
- package/src/yarn1/bins.js +9 -19
- package/src/yarn1/compat.js +9 -28
- package/src/yarn1/hoist.js +53 -68
- package/src/yarn1/inputs.js +19 -61
- package/src/yarn1/manifest.js +8 -23
- package/src/yarn1/package.js +24 -63
- package/src/yarn1/peers.js +8 -15
- package/src/yarn1/requests.js +19 -37
- package/src/yarn1/resolve.js +36 -113
- package/src/yarn1/settings.js +15 -43
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +34 -5
- package/yarn1.js +1 -8
- package/src/pnpm/npmrc.js +0 -31
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/settings.js
CHANGED
|
@@ -1,56 +1,17 @@
|
|
|
1
|
-
// The settings
|
|
2
|
-
//
|
|
3
|
-
// each over the one before
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// things (readers.js): a setting read here, and held to the values this
|
|
8
|
-
// package builds a tree for; a setting that leaves the tree as it is,
|
|
9
|
-
// whether because a frozen lockfile already says what it would have
|
|
10
|
-
// changed, because it is about the network, the store, a cache, a script
|
|
11
|
-
// or a bin — no script is ever run, whatever a setting allows — or because
|
|
12
|
-
// it is a credential; or anything else, which is refused by name, as is a
|
|
13
|
-
// value read here that this package does not build for.
|
|
14
|
-
//
|
|
15
|
-
// An .npmrc is read as pnpm reads one: by the kebab-case names of its
|
|
16
|
-
// settings alone, and of those only the ones it has types for, which are
|
|
17
|
-
// npm's and its own. Every one of those that can change the tree is read
|
|
18
|
-
// here as above; anything else in the file — npm's settings pnpm has no
|
|
19
|
-
// use for, publishing's, credentials, any other spelling — pnpm passes
|
|
20
|
-
// over for an install, and so does this. A value pnpm would take from the
|
|
21
|
-
// environment is not known here: pnpm drops the whole file where one such
|
|
22
|
-
// variable is unset, so one in a line passed over is taken only where the
|
|
23
|
-
// file sets nothing that dropping it would change.
|
|
24
|
-
//
|
|
25
|
-
// Only these files are read. Settings from anywhere else pnpm looks — a
|
|
26
|
-
// user or global .npmrc, `npm_config_*` in the environment, the command
|
|
27
|
-
// line — are not seen, and a tree built here is the one those leave at
|
|
28
|
-
// their defaults. Of the package.json, pnpm 10 reads only the keys of
|
|
29
|
-
// `pnpm` below (MANIFEST_KEYS) and Yarn's `resolutions`, and so does this.
|
|
30
|
-
//
|
|
31
|
-
// pnpm 11 reads its settings from pnpm-workspace.yaml alone: an .npmrc
|
|
32
|
-
// for credentials and registries, and the package.json for none but the
|
|
33
|
-
// Node its engines.runtime pins, runtimeNodeVersion, which it takes where
|
|
34
|
-
// nodeVersion is not set. Of the
|
|
35
|
-
// yaml it passes over a key not in camelCase, and one about the machine,
|
|
36
|
-
// the run or a login; it has settings pnpm 10 has not (READ_11, IGNORED_11),
|
|
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.
|
|
1
|
+
// The settings an install reads. pnpm 10 reads the .npmrc beside the
|
|
2
|
+
// lockfile, pnpm-workspace.yaml and the root package.json's `pnpm` field,
|
|
3
|
+
// each over the one before; pnpm 9 reads only `packages` and the catalogs of
|
|
4
|
+
// pnpm-workspace.yaml, and pnpm 11 and 12 read pnpm-workspace.yaml alone.
|
|
5
|
+
// Settings from anywhere else (a user or global .npmrc, `npm_config_*`, the
|
|
6
|
+
// command line) are taken to be at their defaults.
|
|
44
7
|
|
|
45
8
|
import { valid, validRange } from '@preventive/upstream/semver.js'
|
|
46
9
|
import { DeptreeError, quote } from '../error.js'
|
|
47
|
-
import { parseNpmrc } from '
|
|
10
|
+
import { parseNpmrc } from '../npmrc.js'
|
|
48
11
|
import { replaceReferences } from './overrides.js'
|
|
49
|
-
import {
|
|
12
|
+
import { MANIFEST_KEYS, MANIFEST_KEYS_9, READ, checkRegistry, known12, npmrcReader, readerOf, readers, unrecognized12 } from './readers.js'
|
|
50
13
|
|
|
51
|
-
// An .npmrc value
|
|
52
|
-
// escaped, with no `;` or `#` that ini would cut it at. Neither file's
|
|
53
|
-
// value is read where pnpm would fill it in from the environment.
|
|
14
|
+
// An .npmrc value can mean one thing only with no quote, escape, `;` or `#`.
|
|
54
15
|
const PLAIN = /^[^"'`;#\\]*$/u
|
|
55
16
|
function plain(value, where) {
|
|
56
17
|
if (!PLAIN.test(value)) throw new DeptreeError(`${quote(value)} is quoted, escaped or commented, which is not read here`, where)
|
|
@@ -68,9 +29,8 @@ function noEnvironment(value, where) {
|
|
|
68
29
|
const KEBAB = /^[a-z][\da-z]*(?:-[\da-z]+)*$/u
|
|
69
30
|
const camelCase = (key) => key.replace(/-+([a-z\d])/gu, (_, char) => char.toUpperCase())
|
|
70
31
|
|
|
71
|
-
// pnpm 11 reads an .npmrc for credentials and registries alone
|
|
72
|
-
//
|
|
73
|
-
// names a variable is passed over.
|
|
32
|
+
// pnpm 11 reads an .npmrc for credentials and registries alone; a registry
|
|
33
|
+
// that names a variable is passed over.
|
|
74
34
|
function checkNpmrcRegistries(text) {
|
|
75
35
|
for (const { key, value, line } of parseNpmrc(text)) {
|
|
76
36
|
if ((key !== 'registry' && !/^@[^:]+:registry$/u.test(key)) || fromEnvironment(value)) continue
|
|
@@ -79,10 +39,11 @@ function checkNpmrcRegistries(text) {
|
|
|
79
39
|
}
|
|
80
40
|
}
|
|
81
41
|
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
42
|
+
// The registry's token as a project's .npmrc commonly gives it is taken to
|
|
43
|
+
// be set, as @preventive/upstream reads it too: pnpm reads the file then.
|
|
44
|
+
const isNpmToken = (key, value) => key === '//registry.npmjs.org/:_authToken' && value === '${NPM_TOKEN}'
|
|
45
|
+
|
|
46
|
+
function fromNpmrc(text, major) {
|
|
86
47
|
const settings = new Map()
|
|
87
48
|
let environment = false
|
|
88
49
|
for (const { key, value, list, line } of parseNpmrc(text)) {
|
|
@@ -92,46 +53,43 @@ function fromNpmrc(text) {
|
|
|
92
53
|
continue
|
|
93
54
|
}
|
|
94
55
|
const name = KEBAB.test(key) ? camelCase(key) : undefined
|
|
95
|
-
|
|
96
|
-
|
|
56
|
+
const read = name === undefined ? undefined : npmrcReader(name, major)
|
|
57
|
+
if (read === undefined) {
|
|
58
|
+
if (!isNpmToken(key, value)) environment ||= fromEnvironment(key) || fromEnvironment(value)
|
|
97
59
|
continue
|
|
98
60
|
}
|
|
99
61
|
noEnvironment(value, where)
|
|
100
62
|
const earlier = settings.get(name)
|
|
101
63
|
if (earlier !== undefined && !(list && earlier.list)) throw new DeptreeError('set more than once', where)
|
|
102
|
-
if (list &&
|
|
64
|
+
if (list && read.kind !== 'texts') throw new DeptreeError('not a list', where)
|
|
103
65
|
const next = list ? [...(earlier?.value ?? []), plain(value, where)] : plain(value, where)
|
|
104
|
-
settings.set(name, { value: next, list, where, read
|
|
66
|
+
settings.set(name, { value: next, list, where, read })
|
|
105
67
|
}
|
|
106
68
|
return { settings, environment }
|
|
107
69
|
}
|
|
108
70
|
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
// first.
|
|
112
|
-
function fromManifest(manifest) {
|
|
71
|
+
// pnpm 10 takes Yarn's `resolutions` as overrides, under `pnpm.overrides`.
|
|
72
|
+
function fromManifest(manifest, major) {
|
|
113
73
|
const pnpm = manifest.pnpm === undefined ? {} : readers.mapping(manifest.pnpm, 'package.json: pnpm')
|
|
114
74
|
const settings = new Map()
|
|
115
|
-
for (const name of MANIFEST_KEYS) {
|
|
75
|
+
for (const name of major < 10 ? MANIFEST_KEYS_9 : MANIFEST_KEYS) {
|
|
116
76
|
if (!Object.hasOwn(pnpm, name) || name === 'overrides') continue
|
|
117
77
|
const where = `package.json: pnpm.${name}`
|
|
118
78
|
noEnvironment(pnpm[name], where)
|
|
119
|
-
const read = readerOf(name, where,
|
|
79
|
+
const read = readerOf(name, where, major)
|
|
120
80
|
if (read !== undefined) settings.set(name, { value: pnpm[name], where, read })
|
|
121
81
|
}
|
|
122
82
|
const { resolutions } = manifest
|
|
123
83
|
if (resolutions !== undefined || Object.hasOwn(pnpm, 'overrides')) {
|
|
124
|
-
const where = 'package.json: resolutions and pnpm.overrides'
|
|
125
84
|
const value = { ...(resolutions === undefined ? {} : readers.mapping(resolutions, 'package.json: resolutions')), ...(Object.hasOwn(pnpm, 'overrides') ? readers.mapping(pnpm.overrides, 'package.json: pnpm.overrides') : {}) }
|
|
126
|
-
settings.set('overrides', { value, where, read: READ.overrides })
|
|
85
|
+
settings.set('overrides', { value, where: 'package.json: resolutions and pnpm.overrides', read: READ.overrides })
|
|
127
86
|
}
|
|
128
87
|
return settings
|
|
129
88
|
}
|
|
130
89
|
|
|
131
|
-
// pnpm 11 passes over a key not in camelCase.
|
|
132
90
|
const CAMEL = /^[a-z][\dA-Za-z]*$/u
|
|
133
91
|
|
|
134
|
-
// pnpm 12 passes over a key with no value.
|
|
92
|
+
// pnpm 12 passes over a key with no value.
|
|
135
93
|
function fromWorkspace(workspace, major, pinned) {
|
|
136
94
|
if (workspace === null || typeof workspace !== 'object' || Array.isArray(workspace)) throw new DeptreeError('expected a mapping', 'pnpm-workspace.yaml')
|
|
137
95
|
const settings = new Map()
|
|
@@ -149,14 +107,21 @@ function fromWorkspace(workspace, major, pinned) {
|
|
|
149
107
|
return settings
|
|
150
108
|
}
|
|
151
109
|
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
110
|
+
// pnpm 9 passes over the rest of pnpm-workspace.yaml unread, a catalog of null
|
|
111
|
+
// among it.
|
|
112
|
+
function fromWorkspace9(workspace) {
|
|
113
|
+
readers.mapping(workspace, 'pnpm-workspace.yaml')
|
|
114
|
+
const names = ['packages', 'catalog', 'catalogs'].filter((name) => workspace[name] != null)
|
|
115
|
+
return new Map(names.map((name) => [name, { value: workspace[name], where: `pnpm-workspace.yaml: ${name}`, read: READ[name] }]))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const PUBLIC_9 = ['*eslint*', '*prettier*']
|
|
119
|
+
|
|
120
|
+
// A hoist pattern left undefined is not hoisted to at all. Only on Windows,
|
|
121
|
+
// which checkHost refuses, is virtualStoreDirMaxLength 60 by default.
|
|
122
|
+
function derive(get, major) {
|
|
158
123
|
const shamefullyHoist = get('shamefullyHoist')
|
|
159
|
-
let publicHoistPattern = get('publicHoistPattern') ?? []
|
|
124
|
+
let publicHoistPattern = get('publicHoistPattern') ?? (major < 10 ? PUBLIC_9 : [])
|
|
160
125
|
if (shamefullyHoist === true) publicHoistPattern = ['*']
|
|
161
126
|
else if (shamefullyHoist === false || (publicHoistPattern.length === 1 && publicHoistPattern[0] === '')) publicHoistPattern = undefined
|
|
162
127
|
return {
|
|
@@ -181,11 +146,17 @@ function derive(get) {
|
|
|
181
146
|
pmOnFail: get('pmOnFail'),
|
|
182
147
|
runtimeOnFail: get('runtimeOnFail'),
|
|
183
148
|
packageImportMethod: get('packageImportMethod') ?? 'auto',
|
|
149
|
+
nodeLinker: get('nodeLinker') ?? 'isolated',
|
|
150
|
+
...major < 10 ? {
|
|
151
|
+
packageManagerChecks: {
|
|
152
|
+
manage: get('managePackageManagerVersions') ?? false,
|
|
153
|
+
strict: get('packageManagerStrict') ?? true,
|
|
154
|
+
strictVersion: get('packageManagerStrictVersion') ?? false,
|
|
155
|
+
},
|
|
156
|
+
} : {},
|
|
184
157
|
}
|
|
185
158
|
}
|
|
186
159
|
|
|
187
|
-
// The catalogs by name, `catalog` being `default`, as pnpm has them, which
|
|
188
|
-
// refuses the default one written both ways.
|
|
189
160
|
function catalogsOf(catalog, catalogs = {}) {
|
|
190
161
|
if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) {
|
|
191
162
|
throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
|
|
@@ -193,8 +164,7 @@ function catalogsOf(catalog, catalogs = {}) {
|
|
|
193
164
|
return Object.assign(Object.create(null), catalog === undefined ? {} : { default: catalog }, catalogs)
|
|
194
165
|
}
|
|
195
166
|
|
|
196
|
-
|
|
197
|
-
function settle(layers, manifest) {
|
|
167
|
+
function settle(layers, manifest, major) {
|
|
198
168
|
const values = new Map()
|
|
199
169
|
for (const layer of layers) {
|
|
200
170
|
for (const [name, { value, where, read: { kind, check } }] of layer) {
|
|
@@ -207,39 +177,33 @@ function settle(layers, manifest) {
|
|
|
207
177
|
values.set(name, read)
|
|
208
178
|
}
|
|
209
179
|
}
|
|
210
|
-
return derive((name) => values.get(name))
|
|
180
|
+
return derive((name) => values.get(name), major)
|
|
211
181
|
}
|
|
212
182
|
|
|
213
|
-
//
|
|
214
|
-
// .npmrc, either of which may be undefined; `manifest` the root
|
|
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
|
|
217
|
-
// those below them.
|
|
183
|
+
// Overrides that name nothing are none, and leave those below them.
|
|
218
184
|
export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
|
|
219
|
-
const fromYaml = () =>
|
|
220
|
-
|
|
221
|
-
|
|
185
|
+
const fromYaml = () => {
|
|
186
|
+
if (workspace === undefined) return new Map()
|
|
187
|
+
return major < 10 ? fromWorkspace9(workspace) : fromWorkspace(workspace, major, pinned)
|
|
188
|
+
}
|
|
222
189
|
if (major >= 11) {
|
|
223
190
|
if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
|
|
224
|
-
const settings = settle([fromYaml()], manifest)
|
|
191
|
+
const settings = settle([fromYaml()], manifest, major)
|
|
225
192
|
settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
|
|
226
193
|
return settings
|
|
227
194
|
}
|
|
228
|
-
const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc)
|
|
229
|
-
const rest = [fromYaml(), fromManifest(manifest)]
|
|
230
|
-
const settings = settle([rc.settings, ...rest], manifest)
|
|
231
|
-
if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest))) {
|
|
195
|
+
const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc, major)
|
|
196
|
+
const rest = [fromYaml(), fromManifest(manifest, major)]
|
|
197
|
+
const settings = settle([rc.settings, ...rest], manifest, major)
|
|
198
|
+
if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest, major))) {
|
|
232
199
|
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')
|
|
233
200
|
}
|
|
234
201
|
return settings
|
|
235
202
|
}
|
|
236
203
|
|
|
237
|
-
// The Node the root
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
// that names a range for Node decides, and gives its version where that is
|
|
241
|
-
// exact. One to download, which gives the range's lowest, is refused;
|
|
242
|
-
// runtimeOnFail stands for each one's onFail.
|
|
204
|
+
// The Node the root's runtime pins, for nodeVersion where none is set: the
|
|
205
|
+
// first naming a range for Node decides, with its version where exact. One
|
|
206
|
+
// to download, which gives the range's lowest, is refused.
|
|
243
207
|
function runtimeNode(manifest, onFail) {
|
|
244
208
|
for (const field of ['devEngines', 'engines']) {
|
|
245
209
|
const runtime = manifest[field]?.runtime
|