@preventive/deptree 1.0.0-alpha.4 → 1.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/npm.d.ts +288 -0
- package/npm.js +7 -0
- package/package.json +36 -10
- package/pnpm.d.ts +116 -22
- package/pnpm.js +2 -10
- package/soldeer.d.ts +13 -0
- package/soldeer.js +1 -7
- package/src/concurrent.js +16 -17
- package/src/error.js +5 -9
- package/src/glob.js +55 -0
- package/src/hash.js +64 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +59 -10
- package/src/mount.js +95 -44
- package/src/npm/bins.js +71 -0
- package/src/npm/compat.js +92 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +80 -0
- package/src/npm/manifests.js +138 -0
- package/src/npm/package.js +57 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +136 -0
- package/src/npm/versions.js +20 -0
- package/src/{pnpm/npmrc.js → npmrc.js} +5 -11
- package/src/patch.js +21 -31
- package/src/pnpm/bins.js +32 -103
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +49 -86
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +27 -70
- package/src/pnpm/gitignore.js +137 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +65 -55
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +67 -40
- package/src/pnpm/install.js +72 -115
- package/src/pnpm/local.js +21 -40
- package/src/pnpm/minimatch.js +328 -0
- package/src/pnpm/npm-packlist.js +221 -0
- package/src/pnpm/overrides.js +10 -49
- package/src/pnpm/package.js +120 -0
- package/src/pnpm/packlist.js +168 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +46 -55
- package/src/pnpm/settings.js +60 -97
- package/src/pnpm/tree.js +134 -149
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +122 -131
- package/src/project.js +41 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +2 -5
- package/src/soldeer/tree.js +20 -56
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +38 -142
- package/src/yarn1/bins.js +9 -19
- package/src/yarn1/compat.js +9 -28
- package/src/yarn1/hoist.js +53 -68
- package/src/yarn1/inputs.js +16 -51
- package/src/yarn1/manifest.js +8 -23
- package/src/yarn1/package.js +24 -63
- package/src/yarn1/peers.js +8 -15
- package/src/yarn1/requests.js +19 -37
- package/src/yarn1/resolve.js +35 -111
- package/src/yarn1/settings.js +14 -41
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +30 -2
- package/yarn1.js +1 -8
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/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,7 @@ function checkNpmrcRegistries(text) {
|
|
|
79
39
|
}
|
|
80
40
|
}
|
|
81
41
|
|
|
82
|
-
|
|
83
|
-
// time, and whether any line takes something from the environment. A
|
|
84
|
-
// registry for a scope has to be the public one.
|
|
85
|
-
function fromNpmrc(text) {
|
|
42
|
+
function fromNpmrc(text, major) {
|
|
86
43
|
const settings = new Map()
|
|
87
44
|
let environment = false
|
|
88
45
|
for (const { key, value, list, line } of parseNpmrc(text)) {
|
|
@@ -92,31 +49,30 @@ function fromNpmrc(text) {
|
|
|
92
49
|
continue
|
|
93
50
|
}
|
|
94
51
|
const name = KEBAB.test(key) ? camelCase(key) : undefined
|
|
95
|
-
|
|
52
|
+
const read = name === undefined ? undefined : npmrcReader(name, major)
|
|
53
|
+
if (read === undefined) {
|
|
96
54
|
environment ||= fromEnvironment(key) || fromEnvironment(value)
|
|
97
55
|
continue
|
|
98
56
|
}
|
|
99
57
|
noEnvironment(value, where)
|
|
100
58
|
const earlier = settings.get(name)
|
|
101
59
|
if (earlier !== undefined && !(list && earlier.list)) throw new DeptreeError('set more than once', where)
|
|
102
|
-
if (list &&
|
|
60
|
+
if (list && read.kind !== 'texts') throw new DeptreeError('not a list', where)
|
|
103
61
|
const next = list ? [...(earlier?.value ?? []), plain(value, where)] : plain(value, where)
|
|
104
|
-
settings.set(name, { value: next, list, where, read
|
|
62
|
+
settings.set(name, { value: next, list, where, read })
|
|
105
63
|
}
|
|
106
64
|
return { settings, environment }
|
|
107
65
|
}
|
|
108
66
|
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
// first.
|
|
112
|
-
function fromManifest(manifest) {
|
|
67
|
+
// pnpm 10 takes Yarn's `resolutions` as overrides, under `pnpm.overrides`.
|
|
68
|
+
function fromManifest(manifest, major) {
|
|
113
69
|
const pnpm = manifest.pnpm === undefined ? {} : readers.mapping(manifest.pnpm, 'package.json: pnpm')
|
|
114
70
|
const settings = new Map()
|
|
115
|
-
for (const name of MANIFEST_KEYS) {
|
|
71
|
+
for (const name of major < 10 ? MANIFEST_KEYS_9 : MANIFEST_KEYS) {
|
|
116
72
|
if (!Object.hasOwn(pnpm, name) || name === 'overrides') continue
|
|
117
73
|
const where = `package.json: pnpm.${name}`
|
|
118
74
|
noEnvironment(pnpm[name], where)
|
|
119
|
-
const read = readerOf(name, where,
|
|
75
|
+
const read = readerOf(name, where, major)
|
|
120
76
|
if (read !== undefined) settings.set(name, { value: pnpm[name], where, read })
|
|
121
77
|
}
|
|
122
78
|
const { resolutions } = manifest
|
|
@@ -128,10 +84,9 @@ function fromManifest(manifest) {
|
|
|
128
84
|
return settings
|
|
129
85
|
}
|
|
130
86
|
|
|
131
|
-
// pnpm 11 passes over a key not in camelCase.
|
|
132
87
|
const CAMEL = /^[a-z][\dA-Za-z]*$/u
|
|
133
88
|
|
|
134
|
-
// pnpm 12 passes over a key with no value.
|
|
89
|
+
// pnpm 12 passes over a key with no value.
|
|
135
90
|
function fromWorkspace(workspace, major, pinned) {
|
|
136
91
|
if (workspace === null || typeof workspace !== 'object' || Array.isArray(workspace)) throw new DeptreeError('expected a mapping', 'pnpm-workspace.yaml')
|
|
137
92
|
const settings = new Map()
|
|
@@ -149,14 +104,24 @@ function fromWorkspace(workspace, major, pinned) {
|
|
|
149
104
|
return settings
|
|
150
105
|
}
|
|
151
106
|
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
107
|
+
// pnpm 9 passes over the rest of pnpm-workspace.yaml unread, a catalog of null
|
|
108
|
+
// among it.
|
|
109
|
+
function fromWorkspace9(workspace) {
|
|
110
|
+
readers.mapping(workspace, 'pnpm-workspace.yaml')
|
|
111
|
+
const settings = new Map()
|
|
112
|
+
for (const name of ['packages', 'catalog', 'catalogs']) {
|
|
113
|
+
if (workspace[name] != null) settings.set(name, { value: workspace[name], where: `pnpm-workspace.yaml: ${name}`, read: READ[name] })
|
|
114
|
+
}
|
|
115
|
+
return settings
|
|
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,16 @@ function derive(get) {
|
|
|
181
146
|
pmOnFail: get('pmOnFail'),
|
|
182
147
|
runtimeOnFail: get('runtimeOnFail'),
|
|
183
148
|
packageImportMethod: get('packageImportMethod') ?? 'auto',
|
|
149
|
+
...major < 10 ? {
|
|
150
|
+
packageManagerChecks: {
|
|
151
|
+
manage: get('managePackageManagerVersions') ?? false,
|
|
152
|
+
strict: get('packageManagerStrict') ?? true,
|
|
153
|
+
strictVersion: get('packageManagerStrictVersion') ?? false,
|
|
154
|
+
},
|
|
155
|
+
} : {},
|
|
184
156
|
}
|
|
185
157
|
}
|
|
186
158
|
|
|
187
|
-
// The catalogs by name, `catalog` being `default`, as pnpm has them, which
|
|
188
|
-
// refuses the default one written both ways.
|
|
189
159
|
function catalogsOf(catalog, catalogs = {}) {
|
|
190
160
|
if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) {
|
|
191
161
|
throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
|
|
@@ -193,8 +163,7 @@ function catalogsOf(catalog, catalogs = {}) {
|
|
|
193
163
|
return Object.assign(Object.create(null), catalog === undefined ? {} : { default: catalog }, catalogs)
|
|
194
164
|
}
|
|
195
165
|
|
|
196
|
-
|
|
197
|
-
function settle(layers, manifest) {
|
|
166
|
+
function settle(layers, manifest, major) {
|
|
198
167
|
const values = new Map()
|
|
199
168
|
for (const layer of layers) {
|
|
200
169
|
for (const [name, { value, where, read: { kind, check } }] of layer) {
|
|
@@ -207,39 +176,33 @@ function settle(layers, manifest) {
|
|
|
207
176
|
values.set(name, read)
|
|
208
177
|
}
|
|
209
178
|
}
|
|
210
|
-
return derive((name) => values.get(name))
|
|
179
|
+
return derive((name) => values.get(name), major)
|
|
211
180
|
}
|
|
212
181
|
|
|
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.
|
|
182
|
+
// Overrides that name nothing are none, and leave those below them.
|
|
218
183
|
export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
|
|
219
|
-
const fromYaml = () =>
|
|
220
|
-
|
|
221
|
-
|
|
184
|
+
const fromYaml = () => {
|
|
185
|
+
if (workspace === undefined) return new Map()
|
|
186
|
+
return major < 10 ? fromWorkspace9(workspace) : fromWorkspace(workspace, major, pinned)
|
|
187
|
+
}
|
|
222
188
|
if (major >= 11) {
|
|
223
189
|
if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
|
|
224
|
-
const settings = settle([fromYaml()], manifest)
|
|
190
|
+
const settings = settle([fromYaml()], manifest, major)
|
|
225
191
|
settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
|
|
226
192
|
return settings
|
|
227
193
|
}
|
|
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))) {
|
|
194
|
+
const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc, major)
|
|
195
|
+
const rest = [fromYaml(), fromManifest(manifest, major)]
|
|
196
|
+
const settings = settle([rc.settings, ...rest], manifest, major)
|
|
197
|
+
if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest, major))) {
|
|
232
198
|
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
199
|
}
|
|
234
200
|
return settings
|
|
235
201
|
}
|
|
236
202
|
|
|
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.
|
|
203
|
+
// The Node the root's runtime pins, for nodeVersion where none is set: the
|
|
204
|
+
// first naming a range for Node decides, with its version where exact. One
|
|
205
|
+
// to download, which gives the range's lowest, is refused.
|
|
243
206
|
function runtimeNode(manifest, onFail) {
|
|
244
207
|
for (const field of ['devEngines', 'engines']) {
|
|
245
208
|
const runtime = manifest[field]?.runtime
|