@preventive/deptree 1.2.0 → 1.3.0
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/bin/deptree.js +9 -3
- package/npm.d.ts +27 -10
- package/package.json +2 -1
- package/pnpm.d.ts +31 -7
- package/src/npm/compat.js +18 -5
- package/src/npm/tree.js +12 -9
- package/src/pnpm/local.js +1 -1
- package/src/pnpm/package.js +3 -2
- package/src/pnpm/production.js +131 -0
- package/src/pnpm/readers.js +5 -3
- package/src/pnpm/settings.js +1 -0
- package/src/pnpm/tree.js +19 -12
- package/src/project.js +5 -0
- package/src/yarn1/hoist.js +1 -1
- package/src/yarn1/resolve.js +7 -6
- package/src/yarn1/tree.js +14 -6
- package/yarn1.d.ts +24 -8
package/bin/deptree.js
CHANGED
|
@@ -47,6 +47,8 @@ GITHUB_TOKEN or GH_TOKEN, else anonymously.
|
|
|
47
47
|
packageManager pins, or Soldeer 0.12.0; npm's and
|
|
48
48
|
cargo's are needed
|
|
49
49
|
--node <version> the Node it installed with; by default this one
|
|
50
|
+
--production devDependencies were left out, as by pnpm install
|
|
51
|
+
--prod, npm ci --omit=dev or yarn install --production
|
|
50
52
|
--metadata fetch each package's version document from npm's
|
|
51
53
|
registry too, and hold its tarball's dist to it
|
|
52
54
|
--all list what is left out too
|
|
@@ -63,6 +65,7 @@ const OPTIONS = {
|
|
|
63
65
|
cargo: { type: 'string' },
|
|
64
66
|
node: { type: 'string' },
|
|
65
67
|
metadata: { type: 'boolean', default: false },
|
|
68
|
+
production: { type: 'boolean', default: false },
|
|
66
69
|
all: { type: 'boolean' },
|
|
67
70
|
diff: { type: 'boolean' },
|
|
68
71
|
help: { type: 'boolean', short: 'h' },
|
|
@@ -70,7 +73,8 @@ const OPTIONS = {
|
|
|
70
73
|
|
|
71
74
|
// Each package manager by its version flag: its lockfile, the folder it
|
|
72
75
|
// installs into in each project it finds, and the version where the flag is
|
|
73
|
-
// left out and nothing pins one, or, `unpinned`, that the flag is needed
|
|
76
|
+
// left out and nothing pins one, or, `unpinned`, that the flag is needed;
|
|
77
|
+
// `development`, that it installs every dependency, there being no other kind.
|
|
74
78
|
const MANAGERS = {
|
|
75
79
|
pnpm: { lockfile: 'pnpm-lock.yaml', folder: 'node_modules', projects: findPnpmProjects, build: buildPnpmTree },
|
|
76
80
|
yarn: { lockfile: 'yarn.lock', folder: 'node_modules', projects: findYarn1Workspaces, build: buildYarn1Tree },
|
|
@@ -79,10 +83,11 @@ const MANAGERS = {
|
|
|
79
83
|
lockfile: 'soldeer.lock',
|
|
80
84
|
folder: 'dependencies',
|
|
81
85
|
version: '0.12.0',
|
|
86
|
+
development: true,
|
|
82
87
|
projects: () => ['.'],
|
|
83
88
|
build: (options) => buildSoldeerTree({ ...options, github: createClient({ token: process.env.GITHUB_TOKEN || process.env.GH_TOKEN || null }) }),
|
|
84
89
|
},
|
|
85
|
-
cargo: { lockfile: 'Cargo.lock', folder: 'vendor', unpinned: true, projects: () => ['.'], build: buildCargoTree },
|
|
90
|
+
cargo: { lockfile: 'Cargo.lock', folder: 'vendor', unpinned: true, development: true, projects: () => ['.'], build: buildCargoTree },
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
async function main(argv) {
|
|
@@ -96,6 +101,7 @@ async function main(argv) {
|
|
|
96
101
|
const project = projectView(resolve(dir))
|
|
97
102
|
const name = managerOf(project, dir, values)
|
|
98
103
|
const manager = MANAGERS[name]
|
|
104
|
+
if (values.production && manager.development) fail(`deptree: ${manager.lockfile}: --production is not taken: ${name === 'cargo' ? 'cargo vendor vendors dev-dependencies too' : 'Soldeer has no devDependencies to leave out'}\n`)
|
|
99
105
|
if (defaultCacheDir !== undefined) setCacheDir()
|
|
100
106
|
// upstream reads it for each request, and sends it for a scoped package.
|
|
101
107
|
process.env.NPM_TOKEN ||= userToken() ?? ''
|
|
@@ -108,7 +114,7 @@ async function main(argv) {
|
|
|
108
114
|
const disk = readSide(project, dirs)
|
|
109
115
|
const files = [...disk.values()].filter((entry) => entry.type === 'file')
|
|
110
116
|
note(`${manager.folder} on disk: ${files.length} files, ${size(files.reduce((sum, file) => sum + file.data.length, 0))}`)
|
|
111
|
-
const tree = await manager.build({ project, host, metadata: values.metadata })
|
|
117
|
+
const tree = await manager.build({ project, host, metadata: values.metadata, ...values.production ? { production: true } : {} })
|
|
112
118
|
note(`${manager.lockfile}: ${tree.stats.files} files, ${size(tree.stats.bytes)} built`)
|
|
113
119
|
const built = readSide(tree.vfs, dirs)
|
|
114
120
|
const changes = difference(disk, built)
|
package/npm.d.ts
CHANGED
|
@@ -92,7 +92,8 @@ export interface NpmProject {
|
|
|
92
92
|
// otherwise. omit, include, production, dev, only, also, optional, os,
|
|
93
93
|
// cpu, libc, workspace, workspaces, location, umask, prefix, globalconfig,
|
|
94
94
|
// userconfig, allow-scripts and a credential not scoped to a registry are
|
|
95
|
-
// refused, whatever their value
|
|
95
|
+
// refused, whatever their value, which of the dependencies are installed
|
|
96
|
+
// being `production`'s to say; so are two settings npm takes as
|
|
96
97
|
// exclusive, set together, and a section. Any other setting is passed
|
|
97
98
|
// over: npm reads it for where it fetches from, how, what it prints, or
|
|
98
99
|
// another command, and the tree is held to the lockfile's integrities
|
|
@@ -152,6 +153,18 @@ export interface NpmProject {
|
|
|
152
153
|
// a lockfile one of those checks would refuse is laid out all the same, and
|
|
153
154
|
// refused where that package is unpacked. A `vfs` is not taken with it, nor
|
|
154
155
|
// `sizeEstimateOnly`.
|
|
156
|
+
//
|
|
157
|
+
// `production`, false unless given true, builds the tree `npm ci
|
|
158
|
+
// --omit=dev` makes: each package the lockfile's flags, as npm takes them,
|
|
159
|
+
// say dev dependencies alone reach is left out, as is what is beneath it,
|
|
160
|
+
// and its bins are linked by none of its names. npm 10 makes every
|
|
161
|
+
// package's directory before it leaves those out, and so leaves the
|
|
162
|
+
// directories they were in, a scope's or a workspace's node_modules, which
|
|
163
|
+
// the tree has too, empty; it holds each of them that is not optional to
|
|
164
|
+
// the host as without it, and leaves out nothing for one that is and that
|
|
165
|
+
// the host cannot run. npm 11 holds to the host none of them but those that
|
|
166
|
+
// are optional, each left out with its optionalSet where the host cannot
|
|
167
|
+
// run it, as without it. A workspace is linked all the same.
|
|
155
168
|
export type NpmTreeOptions = NpmTreeGiven | NpmTreeRead
|
|
156
169
|
|
|
157
170
|
export type NpmLayoutOptions = NpmTreeOptions & { sizeEstimateOnly: true, vfs?: undefined }
|
|
@@ -169,6 +182,7 @@ export interface NpmTreeGiven {
|
|
|
169
182
|
cache?: CacheOptions['cache']
|
|
170
183
|
sizeEstimateOnly?: boolean
|
|
171
184
|
lazy?: boolean
|
|
185
|
+
production?: boolean
|
|
172
186
|
}
|
|
173
187
|
|
|
174
188
|
export interface NpmTreeRead {
|
|
@@ -182,6 +196,7 @@ export interface NpmTreeRead {
|
|
|
182
196
|
cache?: CacheOptions['cache']
|
|
183
197
|
sizeEstimateOnly?: boolean
|
|
184
198
|
lazy?: boolean
|
|
199
|
+
production?: boolean
|
|
185
200
|
}
|
|
186
201
|
|
|
187
202
|
// What buildNpmTree counts, all of it plain numbers: `packages` the
|
|
@@ -193,7 +208,8 @@ export interface NpmTreeRead {
|
|
|
193
208
|
// is 0, as none is written, and `bytes` what the sizes of those installed
|
|
194
209
|
// add up to, each copy's, of those with one. With `lazy`, `tarballs`,
|
|
195
210
|
// `files` and `bytes` count what is unpacked, each 0 until `unpack` is
|
|
196
|
-
// asked, which adds to them.
|
|
211
|
+
// asked, which adds to them. With `production`, those it leaves out are
|
|
212
|
+
// counted in neither `installed` nor `skipped`.
|
|
197
213
|
export interface NpmTreeStats {
|
|
198
214
|
packages: number
|
|
199
215
|
installed: number
|
|
@@ -218,7 +234,8 @@ export interface NpmTreeStats {
|
|
|
218
234
|
// those
|
|
219
235
|
// npm installs by, the lockfile's as npm 10 takes them and as npm 11 works
|
|
220
236
|
// them out again: `dev` is whether dev dependencies alone reach it, which
|
|
221
|
-
// --omit=dev leaves out
|
|
237
|
+
// --omit=dev leaves out, and so none is with `production`; `optional`
|
|
238
|
+
// whether optional dependencies alone
|
|
222
239
|
// reach it, which --omit=optional leaves out; `devOptional` whether either
|
|
223
240
|
// is, or both together, which --omit=dev with --omit=optional leaves out;
|
|
224
241
|
// `peer` whether peer dependencies alone reach it, which --omit=peer
|
|
@@ -276,13 +293,13 @@ export interface NpmLazyTree extends NpmTree {
|
|
|
276
293
|
unpack(paths: Iterable<string>): Promise<NpmInstalled[]>
|
|
277
294
|
}
|
|
278
295
|
|
|
279
|
-
// The node_modules tree `npm ci --ignore-scripts` makes, with
|
|
280
|
-
// into a project with no node_modules yet:
|
|
281
|
-
// directory, each package's files unpacked where
|
|
282
|
-
// and each workspace linked as node_modules/<its
|
|
283
|
-
// to its directory, with what the lockfile puts
|
|
284
|
-
// directory's own node_modules. The tree holds
|
|
285
|
-
// else of the projects.
|
|
296
|
+
// The node_modules tree `npm ci --ignore-scripts` makes, with `production`
|
|
297
|
+
// --omit=dev too, with host.npm, into a project with no node_modules yet:
|
|
298
|
+
// rooted at the lockfile's directory, each package's files unpacked where
|
|
299
|
+
// the lockfile puts it, and each workspace linked as node_modules/<its
|
|
300
|
+
// name>, by a relative link to its directory, with what the lockfile puts
|
|
301
|
+
// beneath it in that directory's own node_modules. The tree holds
|
|
302
|
+
// node_modules and nothing else of the projects.
|
|
286
303
|
//
|
|
287
304
|
// Each package is unpacked as npm's tar unpacks it: the first segment of
|
|
288
305
|
// each name dropped; a file alone kept, so that a link, a device and a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/deptree",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "In-memory dependency tree, as a package manager installs it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"src/pnpm/package.js",
|
|
95
95
|
"src/pnpm/packlist.js",
|
|
96
96
|
"src/pnpm/patches.js",
|
|
97
|
+
"src/pnpm/production.js",
|
|
97
98
|
"src/pnpm/projects.js",
|
|
98
99
|
"src/pnpm/readers.js",
|
|
99
100
|
"src/pnpm/settings.js",
|
package/pnpm.d.ts
CHANGED
|
@@ -302,6 +302,27 @@ export interface PnpmProject {
|
|
|
302
302
|
// pnpm builds the package. A
|
|
303
303
|
// `vfs` is not taken with it, nor `sizeEstimateOnly`.
|
|
304
304
|
//
|
|
305
|
+
// `production`, false unless given true, builds the tree `pnpm install
|
|
306
|
+
// --prod` makes, from the lockfile pnpm leaves of it: each project's
|
|
307
|
+
// devDependencies dropped, a `link:` among them, and of the snapshots
|
|
308
|
+
// those the rest reach, through dependencies, optionalDependencies and the
|
|
309
|
+
// projects they link to. The tree is laid out of those alone -- what the
|
|
310
|
+
// host cannot run left out as pnpm walks them, hoisted, its bins linked --
|
|
311
|
+
// as without it, save that pnpm 9 keeps from hoisting each name the root's
|
|
312
|
+
// specifiers have, a devDependency's among them. Nothing else is fetched,
|
|
313
|
+
// nor its files checked; all else is held to the whole lockfile, as
|
|
314
|
+
// without it. From pnpm 11.28.0, and in pnpm 12, an edge to an optional
|
|
315
|
+
// peer, which the snapshot is linked to only as each project that reaches it
|
|
316
|
+
// lists the peer itself, or as the peer is among the root's devDependencies
|
|
317
|
+
// and resolvePeersFromWorkspaceRoot is set, is not walked, and is linked
|
|
318
|
+
// only where the rest reach the peer: a devDependency only there to satisfy
|
|
319
|
+
// an optional peer of a production dependency is left out. From 11.28.7 and
|
|
320
|
+
// 12.15.0, such an edge is one to a peer the snapshot's key binds, or to any
|
|
321
|
+
// of a key with a hash in place of its peers; before, any dependency by the
|
|
322
|
+
// name of one of the snapshot's optional peers, though the snapshot
|
|
323
|
+
// resolved it as its own and its package.json asks for it, as the lockfile
|
|
324
|
+
// pnpm 11.28.7 and 12.15.0 on write records.
|
|
325
|
+
//
|
|
305
326
|
// The two ways the files come, one or the other: given, with `lockfile`
|
|
306
327
|
// and `manifests`, `project` read only for directories; or read, with
|
|
307
328
|
// `project` and none of them.
|
|
@@ -324,6 +345,7 @@ export interface PnpmTreeGiven {
|
|
|
324
345
|
cache?: CacheOptions['cache']
|
|
325
346
|
sizeEstimateOnly?: boolean
|
|
326
347
|
lazy?: boolean
|
|
348
|
+
production?: boolean
|
|
327
349
|
}
|
|
328
350
|
|
|
329
351
|
export interface PnpmTreeRead {
|
|
@@ -339,6 +361,7 @@ export interface PnpmTreeRead {
|
|
|
339
361
|
cache?: CacheOptions['cache']
|
|
340
362
|
sizeEstimateOnly?: boolean
|
|
341
363
|
lazy?: boolean
|
|
364
|
+
production?: boolean
|
|
342
365
|
}
|
|
343
366
|
|
|
344
367
|
// What buildPnpmTree counts, all of it plain numbers: `projects` the
|
|
@@ -382,7 +405,8 @@ export interface PnpmTreeStats {
|
|
|
382
405
|
// to no repository.
|
|
383
406
|
// `dev` is whether devDependencies alone reach it: no project's
|
|
384
407
|
// dependencies or optionalDependencies do, through what is installed, so
|
|
385
|
-
// `pnpm install --prod` would leave it out
|
|
408
|
+
// `pnpm install --prod` would leave it out, and so none is with
|
|
409
|
+
// `production`. `optional` is whether optional
|
|
386
410
|
// dependencies alone reach it, as the lockfile records it. `patch` is the
|
|
387
411
|
// patch applied to it, by pnpm's hash of it and the path the settings name
|
|
388
412
|
// it by: of two patches of one text, the first they name.
|
|
@@ -442,12 +466,12 @@ export interface PnpmLazyTree extends PnpmTree {
|
|
|
442
466
|
unpack(paths: Iterable<string>): Promise<PnpmInstalled[]>
|
|
443
467
|
}
|
|
444
468
|
|
|
445
|
-
// The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts
|
|
446
|
-
// makes with the isolated linker of
|
|
447
|
-
// hoisted one of pnpm 10 or 11, and no
|
|
448
|
-
// settings say of frozen lockfiles, the install
|
|
449
|
-
// the only one that hoists by the lockfile's graph
|
|
450
|
-
// the lockfile's directory: each package's
|
|
469
|
+
// The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`,
|
|
470
|
+
// with `production` --prod too, makes with the isolated linker of
|
|
471
|
+
// host.pnpm, 9, 10, 11 or 12, or the hoisted one of pnpm 10 or 11, and no
|
|
472
|
+
// other install: whatever the settings say of frozen lockfiles, the install
|
|
473
|
+
// is frozen, which is also the only one that hoists by the lockfile's graph
|
|
474
|
+
// alone. It is rooted at the lockfile's directory: each package's
|
|
451
475
|
// files at node_modules/.pnpm/<dir>/node_modules/<name>, its dependencies
|
|
452
476
|
// linked beside it, the hoisted aliases, and each project's own
|
|
453
477
|
// node_modules of links. Links are relative; a `link:` dependency leads
|
package/src/npm/compat.js
CHANGED
|
@@ -75,16 +75,19 @@ const whereOf = (node) => `packages[${quote(node.location)}]`
|
|
|
75
75
|
|
|
76
76
|
// npm 11 checks optional packages in inventory order, passing over one an
|
|
77
77
|
// earlier set took; npm 10 checks them all as it extracts. What is in the
|
|
78
|
-
// node_modules of a node left out goes with it.
|
|
79
|
-
|
|
78
|
+
// node_modules of a node left out goes with it. Of those `omitted` leaves
|
|
79
|
+
// out, npm 10 checks only those that are not optional, before it extracts,
|
|
80
|
+
// and npm 11 only those that are.
|
|
81
|
+
export function skippedOf(nodes, host, settings, omitted = new Set()) {
|
|
80
82
|
const skipped = new Set()
|
|
81
83
|
for (const node of nodes.values()) {
|
|
82
84
|
if (node.kind !== 'package') continue
|
|
83
85
|
const where = whereOf(node)
|
|
84
86
|
if (!node.pkg.optional) {
|
|
85
|
-
checkRuns(node.manifest, host, where, settings.engineStrict, ', and it is not optional')
|
|
87
|
+
if (host.reuse || !omitted.has(node)) checkRuns(node.manifest, host, where, settings.engineStrict, ', and it is not optional')
|
|
86
88
|
continue
|
|
87
89
|
}
|
|
90
|
+
if (host.reuse && omitted.has(node)) continue
|
|
88
91
|
if (!host.reuse && skipped.has(node)) continue
|
|
89
92
|
if (checkEngine(node.manifest, host) === undefined && checkPlatform(node.manifest, host, where) === undefined) continue
|
|
90
93
|
for (const member of optionalSet(node, host, skipped)) skipped.add(member)
|
|
@@ -92,6 +95,16 @@ export function skippedOf(nodes, host, settings) {
|
|
|
92
95
|
for (const node of skipped) {
|
|
93
96
|
if (node.kind !== 'package') throw new DeptreeError('left out with an optional package the host cannot run, which is not supported', node.kind === 'link' ? whereOf(node) : `importers[${quote(node.location)}]`)
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
return new Set([...nodes.values()].filter((node) => skipped.has(node) || under(node)))
|
|
98
|
+
return withBeneath(nodes, skipped)
|
|
97
99
|
}
|
|
100
|
+
|
|
101
|
+
// `set`, and what is in the node_modules of each of its nodes.
|
|
102
|
+
function withBeneath(nodes, set) {
|
|
103
|
+
const under = (node) => node.parent !== undefined && (set.has(nodes.get(node.parent)) || under(nodes.get(node.parent)))
|
|
104
|
+
return new Set([...nodes.values()].filter((node) => set.has(node) || under(node)))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// What --omit=dev leaves out: each package the lockfile's flags say only dev
|
|
108
|
+
// dependencies reach, and so what is beneath it, as the lockfile reader holds
|
|
109
|
+
// the flags to what depends on each.
|
|
110
|
+
export const omittedOf = (nodes) => new Set([...nodes.values()].filter((node) => node.kind === 'package' && node.pkg.dev))
|
package/src/npm/tree.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// and links alone, each package's sized by its version document, of which
|
|
4
4
|
// nothing is fetched but those documents. With `lazy`, its directories and
|
|
5
5
|
// links alone too, fetching nothing, and each package unpacked into it as
|
|
6
|
-
// it is asked for (lazyUnpacker).
|
|
6
|
+
// it is asked for (lazyUnpacker). With `production`, as --omit=dev leaves it.
|
|
7
7
|
|
|
8
8
|
import { parseNpmLockfile } from '@preventive/lockfile/npm.js'
|
|
9
9
|
import { Vfs } from '@preventive/vfs'
|
|
@@ -13,9 +13,10 @@ import { eachConcurrently, limited } from '../concurrent.js'
|
|
|
13
13
|
import { DeptreeError, quote, refusalOf } from '../error.js'
|
|
14
14
|
import { unpacker, writeInto } from '../lazy.js'
|
|
15
15
|
import { checkNoModules, isInside, makeDirs, mount, writeFiles, writeLink } from '../mount.js'
|
|
16
|
+
import { productionOf } from '../project.js'
|
|
16
17
|
import { NO_ABOUT, fetchSize, fetchingOf } from '../tarball.js'
|
|
17
18
|
import { claimedBins, fixBins, fixClaimed } from './bins.js'
|
|
18
|
-
import { skippedOf } from './compat.js'
|
|
19
|
+
import { omittedOf, skippedOf } from './compat.js'
|
|
19
20
|
import { graphOf } from './graph.js'
|
|
20
21
|
import { checkHost, inputsOf } from './inputs.js'
|
|
21
22
|
import { checkManifests, recalculates, rootEdgesOf } from './manifests.js'
|
|
@@ -78,9 +79,9 @@ async function fetchAll(tarballs, host, fetching) {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
// npm 10 makes every package's directory before leaving out those the host
|
|
81
|
-
// cannot run, and leaves the directories they were in.
|
|
82
|
-
function residueOf(nodes,
|
|
83
|
-
const removed = [...
|
|
82
|
+
// cannot run, or --omit=dev omits, and leaves the directories they were in.
|
|
83
|
+
function residueOf(nodes, left) {
|
|
84
|
+
const removed = [...left].map((node) => node.location)
|
|
84
85
|
const inRemoved = (dir) => removed.some((location) => dir === location || dir.startsWith(`${location}/`))
|
|
85
86
|
const dirs = new Set()
|
|
86
87
|
for (const location of removed) {
|
|
@@ -172,6 +173,7 @@ export async function buildNpmTree(options) {
|
|
|
172
173
|
const fetching = fetchingOf(options ?? {})
|
|
173
174
|
if (fetching.sizeEstimateOnly && into !== undefined) throw new TypeError('vfs is not taken with sizeEstimateOnly, whose tree has no files to mount')
|
|
174
175
|
if (fetching.lazy && into !== undefined) throw new TypeError('vfs is not taken with lazy, whose tree is unpacked a package at a time')
|
|
176
|
+
const production = productionOf(options ?? {})
|
|
175
177
|
const host = checkHost(given)
|
|
176
178
|
const folded = host.os === 'darwin'
|
|
177
179
|
const inputs = inputsOf(options ?? {}, folded)
|
|
@@ -186,15 +188,16 @@ export async function buildNpmTree(options) {
|
|
|
186
188
|
checkLinks(lockfile)
|
|
187
189
|
checkSpecs(lockfile, host)
|
|
188
190
|
const nodes = graphOf(lockfile, manifests)
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
+
const omitted = production ? omittedOf(nodes) : new Set()
|
|
192
|
+
const skipped = skippedOf(nodes, host, settings, omitted)
|
|
193
|
+
const kept = [...nodes.values()].filter((node) => node.kind === 'package' && !skipped.has(node) && !omitted.has(node))
|
|
191
194
|
const tarballs = tarballsOf(kept)
|
|
192
195
|
const { fetched, tarballs: count } = fetching.lazy ? { fetched: new Map(), tarballs: 0 } : await fetchAll(tarballs, host, fetching)
|
|
193
196
|
const changed = settings.binLinks && !fetching.sizeEstimateOnly && !fetching.lazy ? fixBins(kept, fetched) : new Map()
|
|
194
|
-
const residue = host.reuse ? residueOf(nodes, skipped) : new Set()
|
|
197
|
+
const residue = host.reuse ? residueOf(nodes, new Set([...skipped, ...omitted])) : new Set()
|
|
195
198
|
const { vfs, stats: written } = writeTree({ lockfile, kept, fetched, changed, residue, sizeEstimateOnly: fetching.sizeEstimateOnly, lazy: fetching.lazy })
|
|
196
199
|
const packages = Object.keys(lockfile.packages).length
|
|
197
|
-
const stats = { packages, installed: kept.length, skipped: packages - kept.length, tarballs: count, ...written }
|
|
200
|
+
const stats = { packages, installed: kept.length, skipped: packages - kept.length - omitted.size, tarballs: count, ...written }
|
|
198
201
|
const entryOf = (node, { integrity, about, size }) => {
|
|
199
202
|
const { name, version, dev, optional, devOptional, peer } = node.pkg
|
|
200
203
|
return { path: node.location, name, version, integrity, ...about, dev, optional, devOptional, peer, ...fetching.sizeEstimateOnly ? { size } : {} }
|
package/src/pnpm/local.js
CHANGED
|
@@ -115,6 +115,6 @@ export function createFreshnessCheck(lockfile, major) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
return (node, read) => {
|
|
118
|
-
if (direct.has(node.key)) checkFresh(read, node.
|
|
118
|
+
if (direct.has(node.key)) checkFresh(read, lockfile.packages[node.key], lockfile.packages, quote(node.key))
|
|
119
119
|
}
|
|
120
120
|
}
|
package/src/pnpm/package.js
CHANGED
|
@@ -122,11 +122,12 @@ export function checkDependencies(manifest, read, pkg, packages, where) {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// What is held of a package's files once fetched, for one of its snapshots:
|
|
125
|
-
// its package.json, as the hook has it, asks for what the snapshot gives it
|
|
125
|
+
// its package.json, as the hook has it, asks for what the snapshot gives it,
|
|
126
|
+
// as `lockfile` has it, though the tree has fewer of its edges.
|
|
126
127
|
export function checkFetched(node, got, { lockfile, hook, fresh }) {
|
|
127
128
|
if (got.manifest === undefined) return
|
|
128
129
|
got.read ??= hook(got.manifest, `${quote(packageKeyOf(node.key))}: package.json`)
|
|
129
|
-
checkDependencies(got.manifest, got.read, node.
|
|
130
|
+
checkDependencies(got.manifest, got.read, lockfile.packages[node.key], lockfile.packages, quote(node.key))
|
|
130
131
|
fresh?.(node, got.read)
|
|
131
132
|
}
|
|
132
133
|
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// What `pnpm install --prod` installs of a lockfile, as
|
|
2
|
+
// @pnpm/lockfile.filtering's filterLockfileByImportersAndEngine filters it
|
|
3
|
+
// with devDependencies left out: every project's devDependencies dropped, and
|
|
4
|
+
// of the snapshots those the rest reach, through dependencies,
|
|
5
|
+
// optionalDependencies and `link:`s, which lead only to projects, all of them
|
|
6
|
+
// installed anyway. The root's specifiers stay, which pnpm 9 hoists by.
|
|
7
|
+
//
|
|
8
|
+
// From pnpm 11.28 and 12.8.1 on (@pnpm/lockfile.peer-edges), an edge to an
|
|
9
|
+
// optional peer that a snapshot has only as the projects that reach it list
|
|
10
|
+
// the peer themselves is not walked, and is dropped from the snapshot where
|
|
11
|
+
// nothing else reaches the peer: a devDependency only there to satisfy an
|
|
12
|
+
// optional peer of a production one is left out. From 11.28.7 and 12.15.0,
|
|
13
|
+
// only an edge to a peer the snapshot's key binds is such an edge, or any of
|
|
14
|
+
// one whose key ends in a hash of its peers; before, any edge by the name of
|
|
15
|
+
// an optional peer was, though the snapshot resolved it as its own.
|
|
16
|
+
|
|
17
|
+
import { compareVersions } from '@preventive/upstream/semver.js'
|
|
18
|
+
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
19
|
+
import { reachable } from './nm-hoist.js'
|
|
20
|
+
|
|
21
|
+
// undefined where there is no such edge; else whether the key must bind it.
|
|
22
|
+
function ruleOf(pnpm, major) {
|
|
23
|
+
const since = (version) => compareVersions(pnpm, version) >= 0
|
|
24
|
+
if (major < 11 || (major === 11 && !since('11.28.0'))) return undefined
|
|
25
|
+
return { bound: since(major === 11 ? '11.28.7' : '12.15.0') }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const edgesOf = (deps) => Object.values(deps).filter((target) => !target.startsWith('link:'))
|
|
29
|
+
|
|
30
|
+
// The groups that end a key, each without its parentheses, the patch hash's
|
|
31
|
+
// first where the key has one; a key the lockfile reader takes has them
|
|
32
|
+
// balanced.
|
|
33
|
+
function groupsOf(key) {
|
|
34
|
+
const groups = []
|
|
35
|
+
let open = 0
|
|
36
|
+
let start = 0
|
|
37
|
+
const suffix = key.slice(packageKeyOf(key).length)
|
|
38
|
+
for (let i = 0; i < suffix.length; i++) {
|
|
39
|
+
if (suffix[i] === '(' && open++ === 0) start = i + 1
|
|
40
|
+
else if (suffix[i] === ')' && --open === 0) groups.push(suffix.slice(start, i))
|
|
41
|
+
}
|
|
42
|
+
return groups
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const PATCH = 'patch_hash='
|
|
46
|
+
|
|
47
|
+
// pnpm's removePeersSuffix: a key with its patch hash and without its peers.
|
|
48
|
+
function withoutPeers(key) {
|
|
49
|
+
const [first] = groupsOf(key)
|
|
50
|
+
return packageKeyOf(key) + (first?.startsWith(PATCH) ? `(${first})` : '')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// pnpm's getBoundPeerProviders: null where the key has no peers, undefined
|
|
54
|
+
// where it has a hash in their place, else each peer it binds.
|
|
55
|
+
function boundOf(key) {
|
|
56
|
+
const peers = groupsOf(key).filter((group) => !group.startsWith(PATCH))
|
|
57
|
+
if (peers.length === 0) return null
|
|
58
|
+
if (peers.length === 1 && /^[\da-f]{32}$/u.test(peers[0])) return undefined
|
|
59
|
+
return new Set(peers.filter((peer) => peer.indexOf('@', 1) !== -1).map(withoutPeers))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Each snapshot's edges to its optional peers, `bound` holding them to the
|
|
63
|
+
// peers its key binds.
|
|
64
|
+
function optionalPeerEdges(packages, bound) {
|
|
65
|
+
const entries = []
|
|
66
|
+
for (const [parent, pkg] of Object.entries(packages)) {
|
|
67
|
+
const providers = bound ? boundOf(parent) : undefined
|
|
68
|
+
if (providers === null) continue
|
|
69
|
+
for (const deps of [pkg.dependencies, pkg.optionalDependencies]) {
|
|
70
|
+
for (const [alias, target] of Object.entries(deps)) {
|
|
71
|
+
if (target.startsWith('link:') || !Object.hasOwn(pkg.peerDependencies, alias) || pkg.peerDependenciesMeta[alias]?.optional !== true) continue
|
|
72
|
+
if (providers === undefined || providers.has(withoutPeers(target))) entries.push({ parent, alias, target })
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return entries
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const directOf = ({ dependencies, devDependencies, optionalDependencies }) => edgesOf({ ...dependencies, ...devDependencies, ...optionalDependencies })
|
|
80
|
+
|
|
81
|
+
// pnpm's collectPeerSatisfactionEdges: by each edge's target, the projects
|
|
82
|
+
// that do not list it among their own (none, where it is the root's
|
|
83
|
+
// devDependency and resolvePeersFromWorkspaceRoot is set); an edge is one to
|
|
84
|
+
// skip where nothing those projects list reaches its snapshot.
|
|
85
|
+
function satisfactionEdges(lockfile, rule, fromRoot) {
|
|
86
|
+
const entries = optionalPeerEdges(lockfile.packages, rule.bound)
|
|
87
|
+
const edges = new Map()
|
|
88
|
+
if (entries.length === 0) return edges
|
|
89
|
+
const importers = Object.values(lockfile.importers)
|
|
90
|
+
const direct = importers.map((importer) => new Set(directOf(importer)))
|
|
91
|
+
const rootDev = fromRoot && lockfile.importers['.'] !== undefined ? new Set(edgesOf(lockfile.importers['.'].devDependencies)) : new Set()
|
|
92
|
+
const next = (key) => (key in lockfile.packages ? edgesOf({ ...lockfile.packages[key].dependencies, ...lockfile.packages[key].optionalDependencies }) : [])
|
|
93
|
+
const groups = Map.groupBy(entries, ({ target }) => (rootDev.has(target) ? '' : direct.flatMap((keys, i) => (keys.has(target) ? [] : [i])).join(',')))
|
|
94
|
+
for (const [listing, group] of groups) {
|
|
95
|
+
const seeds = listing === '' ? [] : listing.split(',').flatMap((i) => directOf(importers[Number(i)]))
|
|
96
|
+
const reached = reachable(seeds, next)
|
|
97
|
+
for (const { parent, alias } of group) {
|
|
98
|
+
if (reached.has(parent)) continue
|
|
99
|
+
if (!edges.has(parent)) edges.set(parent, new Set())
|
|
100
|
+
edges.get(parent).add(alias)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return edges
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Each snapshot `edges` names, without those of its edges `drop` takes.
|
|
107
|
+
function without(packages, edges, drop) {
|
|
108
|
+
const kept = { ...packages }
|
|
109
|
+
for (const [parent, aliases] of edges) {
|
|
110
|
+
const pkg = packages[parent]
|
|
111
|
+
if (pkg === undefined) continue
|
|
112
|
+
const keep = (deps) => Object.fromEntries(Object.entries(deps).filter(([alias, target]) => !aliases.has(alias) || !drop(target)))
|
|
113
|
+
kept[parent] = { ...pkg, dependencies: keep(pkg.dependencies), optionalDependencies: keep(pkg.optionalDependencies) }
|
|
114
|
+
}
|
|
115
|
+
return kept
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// `walked`, what pnpm walks to leave out what the host cannot run: every
|
|
119
|
+
// snapshot, but for the edges it does not walk; `installing`, the lockfile
|
|
120
|
+
// the tree is laid out from: the snapshots reached, each but for those edges
|
|
121
|
+
// to a snapshot not reached. Each importer's devDependencies are empty.
|
|
122
|
+
export function productionLockfile(lockfile, { pnpm, major, resolvePeersFromWorkspaceRoot }) {
|
|
123
|
+
const importers = Object.fromEntries(Object.entries(lockfile.importers).map(([id, importer]) => [id, { ...importer, devDependencies: {} }]))
|
|
124
|
+
const rule = ruleOf(pnpm, major)
|
|
125
|
+
const edges = rule === undefined ? new Map() : satisfactionEdges(lockfile, rule, resolvePeersFromWorkspaceRoot)
|
|
126
|
+
const walked = { ...lockfile, importers, packages: without(lockfile.packages, edges, () => true) }
|
|
127
|
+
const starts = Object.values(importers).flatMap(({ dependencies, optionalDependencies }) => edgesOf({ ...dependencies, ...optionalDependencies }))
|
|
128
|
+
const picked = reachable(starts, (key) => edgesOf({ ...walked.packages[key].dependencies, ...walked.packages[key].optionalDependencies }))
|
|
129
|
+
const packages = Object.fromEntries(Object.entries(lockfile.packages).filter(([key]) => picked.has(key)))
|
|
130
|
+
return { walked, installing: { ...lockfile, importers, packages: without(packages, edges, (target) => !picked.has(target)) } }
|
|
131
|
+
}
|
package/src/pnpm/readers.js
CHANGED
|
@@ -87,7 +87,7 @@ export const READ = {
|
|
|
87
87
|
lockfile: only('boolean', true, 'the tree is the lockfile\'s'),
|
|
88
88
|
packageLock: only('boolean', true, 'the tree is the lockfile\'s'),
|
|
89
89
|
optional: only('boolean', true, 'optional dependencies are installed'),
|
|
90
|
-
production: only('boolean', false, 'devDependencies are installed'),
|
|
90
|
+
production: only('boolean', false, 'whether devDependencies are installed is for the production option to say'),
|
|
91
91
|
dev: only('boolean', false, 'dependencies are installed'),
|
|
92
92
|
ignorePatchFailures: { ...only('boolean', false, 'a patch that does not apply is an error'), rc: false },
|
|
93
93
|
force: only('boolean', false, 'optional packages the host cannot run are left out'),
|
|
@@ -99,7 +99,7 @@ export const READ = {
|
|
|
99
99
|
mergeGitBranchLockfilesBranchPattern: { kind: 'texts', check: never('the lockfile is the one given') },
|
|
100
100
|
lockfileDir: { kind: 'text', check: never('the lockfile is the one given, at the root of the tree') },
|
|
101
101
|
lockfileDirectory: { kind: 'text', check: never('the lockfile is the one given, at the root of the tree') },
|
|
102
|
-
only: { kind: 'text', check: never('dependencies and devDependencies are
|
|
102
|
+
only: { kind: 'text', check: never('which of dependencies and devDependencies are installed is for the production option to say') },
|
|
103
103
|
filter: { kind: 'texts', check: never('every project is installed') },
|
|
104
104
|
filterProd: { kind: 'texts', check: never('every project is installed') },
|
|
105
105
|
useNodeVersion: { kind: 'text', check: never('the Node a tree is built for is the host\'s, or nodeVersion') },
|
|
@@ -119,6 +119,8 @@ export const READ = {
|
|
|
119
119
|
nodeVersion: { kind: 'text', check: checkNodeVersion },
|
|
120
120
|
autoInstallPeers: { kind: 'boolean' },
|
|
121
121
|
dedupePeers: { kind: 'boolean' },
|
|
122
|
+
// Which edges to optional peers pnpm 11 and 12 leave out with --prod (production.js).
|
|
123
|
+
resolvePeersFromWorkspaceRoot: { kind: 'boolean' },
|
|
122
124
|
peersSuffixMaxLength: { kind: 'count' },
|
|
123
125
|
// Whether a directory package's snapshots share hardlinked files (tree.js).
|
|
124
126
|
packageImportMethod: { kind: 'importMethod' },
|
|
@@ -225,7 +227,7 @@ const IGNORED = new Set([
|
|
|
225
227
|
'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
|
|
226
228
|
'dedupeInjectedDeps', 'dedupePeerDependents', 'ignoreCompatibilityDb', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
|
|
227
229
|
'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
|
|
228
|
-
'registrySupportsTimeField', 'resolutionMode', '
|
|
230
|
+
'registrySupportsTimeField', 'resolutionMode', 'saveExact', 'savePrefix',
|
|
229
231
|
'saveWorkspaceProtocol', 'strictPeerDependencies',
|
|
230
232
|
// the network and its credentials, which @preventive/upstream handles
|
|
231
233
|
'alwaysAuth', 'ca', 'cafile', 'cert', 'email', 'fetchRetries', 'fetchRetryFactor', 'fetchRetryMaxtimeout',
|
package/src/pnpm/settings.js
CHANGED
|
@@ -139,6 +139,7 @@ function derive(get, major) {
|
|
|
139
139
|
packageExtensions: get('packageExtensions'),
|
|
140
140
|
ignoredOptionalDependencies: get('ignoredOptionalDependencies') ?? [],
|
|
141
141
|
autoInstallPeers: get('autoInstallPeers') ?? true,
|
|
142
|
+
resolvePeersFromWorkspaceRoot: get('resolvePeersFromWorkspaceRoot') ?? true,
|
|
142
143
|
dedupePeers: get('dedupePeers') ?? false,
|
|
143
144
|
peersSuffixMaxLength: get('peersSuffixMaxLength') ?? 1000,
|
|
144
145
|
packages: get('packages'),
|
package/src/pnpm/tree.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
// `sizeEstimateOnly`, its directories and links alone, each package's sized
|
|
6
6
|
// by its version document, of which nothing is fetched but those documents.
|
|
7
7
|
// With `lazy`, its directories and links alone too, fetching nothing, and
|
|
8
|
-
// each package unpacked into it as it is asked for (lazy.js).
|
|
8
|
+
// each package unpacked into it as it is asked for (lazy.js). With
|
|
9
|
+
// `production`, as --prod installs it (production.js): laid out from the
|
|
10
|
+
// lockfile it leaves, and held to the whole one.
|
|
9
11
|
|
|
10
12
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
11
13
|
import { compareVersions } from '@preventive/upstream/semver.js'
|
|
@@ -14,7 +16,7 @@ import { dirname, relative } from '@preventive/vfs/path.js'
|
|
|
14
16
|
import { eachConcurrently } from '../concurrent.js'
|
|
15
17
|
import { DeptreeError, quote, refusalOf } from '../error.js'
|
|
16
18
|
import { checkNoModules, fold, makeDirs, mount, writeLink } from '../mount.js'
|
|
17
|
-
import { checkProject } from '../project.js'
|
|
19
|
+
import { checkProject, productionOf } from '../project.js'
|
|
18
20
|
import { NO_ABOUT, REGISTRY, fetchSize, fetchingOf, tarballUrl } from '../tarball.js'
|
|
19
21
|
import { binReads, binTargets, hoistedBinReads, hoistedBinTargets, requiresBuild } from './bins.js'
|
|
20
22
|
import { buildGraph } from './graph.js'
|
|
@@ -26,6 +28,7 @@ import { lazyUnpacker } from './lazy.js'
|
|
|
26
28
|
import { checkFetched, fetchPackage } from './package.js'
|
|
27
29
|
import { checkLinks, checkOptional } from './checks.js'
|
|
28
30
|
import { createHook } from './hook.js'
|
|
31
|
+
import { productionLockfile } from './production.js'
|
|
29
32
|
import { listOverrides } from './overrides.js'
|
|
30
33
|
import { checkHost, inputsOf, manifestsOf, patchesOf, readLockfile } from './inputs.js'
|
|
31
34
|
import { checkProjects, pinsPnpm, workspaceNames } from './projects.js'
|
|
@@ -93,10 +96,11 @@ async function fetchAll(nodes, project, host, fetching) {
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
// With `lazy`, a registry package's snapshots have no files yet, and are held
|
|
96
|
-
// to them as each is unpacked; `checks` are what that takes
|
|
97
|
-
|
|
99
|
+
// to them as each is unpacked; `checks` are what that takes, of `checked`, the
|
|
100
|
+
// whole lockfile.
|
|
101
|
+
async function fetchNodes(nodes, checked, hook, project, host, fetching) {
|
|
98
102
|
const fetched = await fetchAll(nodes, project, host, fetching)
|
|
99
|
-
const checks = { lockfile, hook, fresh: createFreshnessCheck(
|
|
103
|
+
const checks = { lockfile: checked, hook, fresh: createFreshnessCheck(checked, host.major) }
|
|
100
104
|
const byDir = new Map()
|
|
101
105
|
for (const node of nodes.values()) {
|
|
102
106
|
const got = fetched.get(packageKeyOf(node.key))
|
|
@@ -183,8 +187,9 @@ const COPYING = new Set(['copy', 'clone', 'clone-or-copy'])
|
|
|
183
187
|
// every package's files are at hand; with `sizeEstimateOnly` they are not
|
|
184
188
|
// followed, nor with `lazy` but where a package unpacked needs them. `builds`
|
|
185
189
|
// tells, where any patch is configured, what the build pass builds; `reads`
|
|
186
|
-
// the packages the fixes read the files of (hoistedBinReads).
|
|
187
|
-
|
|
190
|
+
// the packages the fixes read the files of (hoistedBinReads). `lockfile` is
|
|
191
|
+
// the one the tree is laid out from, and `checked` the whole one.
|
|
192
|
+
async function buildHoisted({ lockfile, checked, settings, host, project, hook, installed, manifests, names, patched, skipped, fetching }) {
|
|
188
193
|
const { major } = host
|
|
189
194
|
const since = (version) => compareVersions(host.pnpm, version) >= 0
|
|
190
195
|
if (!COPYING.has(settings.packageImportMethod)) {
|
|
@@ -200,7 +205,7 @@ async function buildHoisted({ lockfile, settings, host, project, hook, installed
|
|
|
200
205
|
const keepsModules = since('11.25.0')
|
|
201
206
|
const dropping = building && hardlinks && !keepsModules ? mayDrop(placed) : new Map()
|
|
202
207
|
if (fetching.sizeEstimateOnly) checkNoneDropped(dropping, host.pnpm)
|
|
203
|
-
const { byDir, tarballs, checks } = await fetchNodes(placed,
|
|
208
|
+
const { byDir, tarballs, checks } = await fetchNodes(placed, checked, hook, project, host, fetching)
|
|
204
209
|
const linked = readLinked(links, byDir, manifests, project)
|
|
205
210
|
const prod = prodPackages(lockfile, skipped, directories)
|
|
206
211
|
const dev = (node) => !prod.has(packageIdOf(node.key, node.pkg, directories))
|
|
@@ -221,11 +226,11 @@ async function buildHoisted({ lockfile, settings, host, project, hook, installed
|
|
|
221
226
|
// The isolated layout: each package in node_modules/.pnpm, linked from what
|
|
222
227
|
// needs it and where it is hoisted; `fixes` as buildHoisted's, and `reads`
|
|
223
228
|
// the packages they read the files of (binReads).
|
|
224
|
-
async function buildIsolated({ lockfile, settings, host, project, hook, installed, manifests, names, skipped, fetching }) {
|
|
229
|
+
async function buildIsolated({ lockfile, checked, settings, host, project, hook, installed, manifests, names, skipped, fetching }) {
|
|
225
230
|
const { major } = host
|
|
226
231
|
const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength, major)
|
|
227
232
|
for (const node of nodes.values()) checkSource(node, installed)
|
|
228
|
-
const { byDir, tarballs, checks } = await fetchNodes(nodes,
|
|
233
|
+
const { byDir, tarballs, checks } = await fetchNodes(nodes, checked, hook, project, host, fetching)
|
|
229
234
|
const links = linksOf(byDir, direct, settings, names, major, hoisting)
|
|
230
235
|
const linked = readLinked(links, byDir, manifests, project)
|
|
231
236
|
const prod = reachedInProd(lockfile.importers, nodes, byDir)
|
|
@@ -253,6 +258,7 @@ export async function buildPnpmTree(options) {
|
|
|
253
258
|
const fetching = fetchingOf(options ?? {})
|
|
254
259
|
if (fetching.sizeEstimateOnly && into !== undefined) throw new TypeError('vfs is not taken with sizeEstimateOnly, whose tree has no files to mount')
|
|
255
260
|
if (fetching.lazy && into !== undefined) throw new TypeError('vfs is not taken with lazy, whose tree is unpacked a package at a time')
|
|
261
|
+
const production = productionOf(options ?? {})
|
|
256
262
|
if (project !== undefined) checkProject(project)
|
|
257
263
|
const machine = checkHost(given)
|
|
258
264
|
const folded = machine.os === 'darwin'
|
|
@@ -283,9 +289,10 @@ export async function buildPnpmTree(options) {
|
|
|
283
289
|
checkProjects(lockfile, manifests, { hook, host, settings, env })
|
|
284
290
|
checkOptional(lockfile)
|
|
285
291
|
const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
|
|
286
|
-
const {
|
|
292
|
+
const { walked, installing } = production ? productionLockfile(lockfile, { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }) : { walked: lockfile, installing: lockfile }
|
|
293
|
+
const { skipped, incompatible } = skippedSnapshots(walked, { host, settings })
|
|
287
294
|
const hoisted = settings.nodeLinker === 'hoisted'
|
|
288
|
-
const { byDir, links, fixes, reads, builds, early, tarballs, dev, checks } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile, settings, host, project, hook, installed, manifests, names, patched, skipped, fetching })
|
|
295
|
+
const { byDir, links, fixes, reads, builds, early, tarballs, dev, checks } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile: installing, checked: lockfile, settings, host, project, hook, installed, manifests, names, patched, skipped, fetching })
|
|
289
296
|
const laidOut = fetching.sizeEstimateOnly || fetching.lazy
|
|
290
297
|
const { targets, executable } = laidOut ? { targets: new Map(), executable: new Map() } : fixes()
|
|
291
298
|
|
package/src/project.js
CHANGED
|
@@ -48,6 +48,11 @@ export function checkHostKeys(host, keys, wanted) {
|
|
|
48
48
|
if (host === null || typeof host !== 'object') throw new TypeError(`host must be an object with ${wanted}`)
|
|
49
49
|
for (const key of keys) if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
|
|
50
50
|
}
|
|
51
|
+
// `production`, false unless given true, as each manager's builder takes it.
|
|
52
|
+
export function productionOf({ production = false }) {
|
|
53
|
+
if (typeof production !== 'boolean') throw new TypeError('production must be a boolean, or left out')
|
|
54
|
+
return production
|
|
55
|
+
}
|
|
51
56
|
export function checkLeftOut(values, all = 'both') {
|
|
52
57
|
for (const [name, value] of Object.entries(values)) if (value !== undefined) throw new TypeError(`${name} must be left out where lockfile is: ${all} are read from project`)
|
|
53
58
|
}
|
package/src/yarn1/hoist.js
CHANGED
|
@@ -78,7 +78,7 @@ export class Hoister {
|
|
|
78
78
|
const ref = this.resolved(pattern)
|
|
79
79
|
if (parent && !this.tree.get(parent.key)) return null
|
|
80
80
|
const isIncompatible = ref.incompatible === true
|
|
81
|
-
const isRequired = !isIncompatible && (isDirectRequire || parent?.isRequired === true)
|
|
81
|
+
const isRequired = !isIncompatible && ((isDirectRequire && !ref.ignore) || parent?.isRequired === true)
|
|
82
82
|
const parts = (parent?.parts ?? []).concat(ref.name)
|
|
83
83
|
const key = implode(parts)
|
|
84
84
|
const info = { key, parts, ref, isDirectRequire, isRequired, isIncompatible }
|
package/src/yarn1/resolve.js
CHANGED
|
@@ -57,11 +57,12 @@ function directoryOf(range, where) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// What a package asks for, in yarn's order. A lockfile entry's are patterns;
|
|
60
|
-
// one the lockfile reader links to a workspace has lost its range.
|
|
61
|
-
|
|
60
|
+
// one the lockfile reader links to a workspace has lost its range. A
|
|
61
|
+
// workspace's devDependencies are asked for, but with --production.
|
|
62
|
+
function asked(info, where, production) {
|
|
62
63
|
const workspace = info.kind === 'workspace'
|
|
63
64
|
const lists = workspace ? info.workspace.manifest : info.entry
|
|
64
|
-
const kinds = [['dependencies', false, false], ['optionalDependencies', true, false], ...workspace ? [['devDependencies', false, true]] : []]
|
|
65
|
+
const kinds = [['dependencies', false, false], ['optionalDependencies', true, false], ...workspace && !production ? [['devDependencies', false, true]] : []]
|
|
65
66
|
return kinds.flatMap(([kind, optional, dev]) => Object.entries(lists[kind] ?? {}).map(([name, value]) => {
|
|
66
67
|
if (!workspace && value.startsWith('link:')) throw new DeptreeError(`its dependency on ${quote(name)} is a workspace, which is not supported`, where)
|
|
67
68
|
return { pattern: workspace ? `${name}@${value}` : value, optional, dev }
|
|
@@ -80,8 +81,8 @@ function locOf({ kind, name, version, entry, dir }) {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
class Resolver {
|
|
83
|
-
constructor({ lockfile, workspaces, rules, isDirectory }) {
|
|
84
|
-
Object.assign(this, { lockfile, workspaces, rules, isDirectory })
|
|
84
|
+
constructor({ lockfile, workspaces, rules, isDirectory, production = false }) {
|
|
85
|
+
Object.assign(this, { lockfile, workspaces, rules, isDirectory, production })
|
|
85
86
|
this.patterns = new Map()
|
|
86
87
|
this.byName = new Map()
|
|
87
88
|
this.delayed = []
|
|
@@ -160,7 +161,7 @@ class Resolver {
|
|
|
160
161
|
dir: info.dir,
|
|
161
162
|
patterns: [],
|
|
162
163
|
requests: [request],
|
|
163
|
-
asked: asked(info, quote(request.pattern)),
|
|
164
|
+
asked: asked(info, quote(request.pattern), this.production),
|
|
164
165
|
optional: request.optional,
|
|
165
166
|
}
|
|
166
167
|
this.addPattern(request.pattern, ref)
|
package/src/yarn1/tree.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// A node_modules tree as `yarn install --frozen-lockfile --ignore-scripts`
|
|
2
|
-
// makes it in a directory with no node_modules yet
|
|
3
|
-
// node_modules/.bin, yarn's
|
|
2
|
+
// makes it in a directory with no node_modules yet, and with `production`, as
|
|
3
|
+
// --production does too. Not written: node_modules/.bin, yarn's
|
|
4
|
+
// .yarn-integrity, and anything a script builds.
|
|
4
5
|
|
|
5
6
|
import { parseYarn1Lockfile } from '@preventive/lockfile/yarn1.js'
|
|
6
7
|
import { Vfs } from '@preventive/vfs'
|
|
@@ -9,7 +10,7 @@ import { clean, satisfies, valid, validRange } from '@preventive/upstream/semver
|
|
|
9
10
|
import { eachConcurrently } from '../concurrent.js'
|
|
10
11
|
import { DeptreeError, quote } from '../error.js'
|
|
11
12
|
import { checkNoModules, isInside, makeDirs, mount, writeFiles, writeLink } from '../mount.js'
|
|
12
|
-
import { typeOf } from '../project.js'
|
|
13
|
+
import { productionOf, typeOf } from '../project.js'
|
|
13
14
|
import { fetchingOf } from '../tarball.js'
|
|
14
15
|
import { checkBinLinks } from './bins.js'
|
|
15
16
|
import { incompatibility } from './compat.js'
|
|
@@ -67,7 +68,11 @@ function locationOf(names, workspaces) {
|
|
|
67
68
|
return `node_modules/${names.join('/node_modules/')}`
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
// With --production yarn asks for the root's devDependencies all the same,
|
|
72
|
+
// fetches and checks them, and hoists them, but marks each as ignored
|
|
73
|
+
// (install.js's markIgnored): it is installed only where something else
|
|
74
|
+
// needs it.
|
|
75
|
+
function resolveProject(inputs, host, production) {
|
|
71
76
|
const lockfile = parseYarn1Lockfile(inputs.lockfile, { manifests: Object.fromEntries(inputs.manifests), semver: { clean, satisfies, valid, validRange } })
|
|
72
77
|
const manifests = new Map([...inputs.manifests].map(([dir, manifest]) => [dir, fixLists(manifest)]))
|
|
73
78
|
const root = manifests.get('.')
|
|
@@ -79,7 +84,9 @@ function resolveProject(inputs, host) {
|
|
|
79
84
|
if (reason !== undefined) throw new DeptreeError(reason, 'manifests["."]')
|
|
80
85
|
const { project } = inputs
|
|
81
86
|
const isDirectory = project === undefined ? () => undefined : (tag) => typeOf(project, `/${tag}/package.json`) !== undefined
|
|
82
|
-
|
|
87
|
+
const resolved = resolve({ lockfile, workspaces, rules, top: requests, isDirectory, production })
|
|
88
|
+
if (production) for (const { pattern, dev } of asked) if (dev) resolved.patterns.get(pattern).ignore = true
|
|
89
|
+
return { workspaces, asked, resolved }
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
// As in yarn, every package is fetched before any is checked, in the order
|
|
@@ -198,13 +205,14 @@ export async function buildYarn1Tree(options) {
|
|
|
198
205
|
for (const option of ['sizeEstimateOnly', 'lazy']) {
|
|
199
206
|
if (fetching[option]) throw new TypeError(`${option} is not taken for yarn 1, which hoists and leaves out packages by what their package.json says, which only their tarballs hold`)
|
|
200
207
|
}
|
|
208
|
+
const production = productionOf(options ?? {})
|
|
201
209
|
const inputs = inputsOf(options ?? {})
|
|
202
210
|
const host = checkHost(given, inputs.manifests.get('.'))
|
|
203
211
|
const folded = host.os === 'darwin'
|
|
204
212
|
// Refused before anything is fetched; mount checks again.
|
|
205
213
|
if (into !== undefined) checkNoModules(into, folded)
|
|
206
214
|
checkRoot(inputs.manifests.get('.'))
|
|
207
|
-
const { workspaces, asked, resolved } = resolveProject(inputs, host)
|
|
215
|
+
const { workspaces, asked, resolved } = resolveProject(inputs, host, production)
|
|
208
216
|
const { packages, fetched, manifestOf } = await fetchChecked(resolved, host, inputs.settings, inputs.project, fetching)
|
|
209
217
|
const { placed, hoister } = layout({ resolved, manifestOf, asked, workspaces })
|
|
210
218
|
const { vfs, links, locations, copies, files, bytes } = writeTree(placed, fetched)
|
package/yarn1.d.ts
CHANGED
|
@@ -149,6 +149,9 @@ export interface Yarn1Project {
|
|
|
149
149
|
// and leaves out packages by what their package.json says, which only their
|
|
150
150
|
// tarballs hold: a TypeError is thrown for either given true.
|
|
151
151
|
//
|
|
152
|
+
// `production`, false unless given true, builds the tree `yarn install
|
|
153
|
+
// --production` makes, as below.
|
|
154
|
+
//
|
|
152
155
|
// The two ways the files come, one or the other: given, with `lockfile`
|
|
153
156
|
// and `manifests`; or read, with `project` and none of them. `project`
|
|
154
157
|
// given with `lockfile` is read only to tell whether a tag a top-level
|
|
@@ -165,6 +168,7 @@ export interface Yarn1TreeGiven {
|
|
|
165
168
|
vfs?: Vfs
|
|
166
169
|
metadata?: boolean
|
|
167
170
|
cache?: CacheOptions['cache']
|
|
171
|
+
production?: boolean
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
export interface Yarn1TreeRead {
|
|
@@ -177,6 +181,7 @@ export interface Yarn1TreeRead {
|
|
|
177
181
|
vfs?: Vfs
|
|
178
182
|
metadata?: boolean
|
|
179
183
|
cache?: CacheOptions['cache']
|
|
184
|
+
production?: boolean
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
// What buildYarn1Tree counts, all of it plain numbers: `packages` the
|
|
@@ -213,8 +218,8 @@ export interface Yarn1TreeStats {
|
|
|
213
218
|
// each peer yarn finds, looked for from where what asks for it is, as Node
|
|
214
219
|
// finds it and yarn marks what an install requires, past what the host
|
|
215
220
|
// cannot run. Two copies of one package may differ: one beneath a
|
|
216
|
-
// devDependency that only it needs is dev. `
|
|
217
|
-
// dependencies alone reach this copy, so.
|
|
221
|
+
// devDependency that only it needs is dev. With `production`, none is.
|
|
222
|
+
// `optional` is whether optional dependencies alone reach this copy, so.
|
|
218
223
|
export interface Yarn1Installed {
|
|
219
224
|
path: string
|
|
220
225
|
name: string
|
|
@@ -240,12 +245,13 @@ export interface Yarn1Tree {
|
|
|
240
245
|
}
|
|
241
246
|
|
|
242
247
|
// The node_modules tree `yarn install --frozen-lockfile --ignore-scripts`
|
|
243
|
-
// makes, with host.yarn's node_modules
|
|
244
|
-
// node_modules yet: rooted at the lockfile's
|
|
245
|
-
// files copied where yarn hoists it, and each
|
|
246
|
-
// hoists it, by a relative link to its
|
|
247
|
-
// beneath it in that directory's own
|
|
248
|
-
// node_modules and nothing else of the
|
|
248
|
+
// makes, with `production` --production too, with host.yarn's node_modules
|
|
249
|
+
// linker, into a project with no node_modules yet: rooted at the lockfile's
|
|
250
|
+
// directory, each package's files copied where yarn hoists it, and each
|
|
251
|
+
// workspace linked where yarn hoists it, by a relative link to its
|
|
252
|
+
// directory, with what yarn hoists beneath it in that directory's own
|
|
253
|
+
// node_modules. The tree holds node_modules and nothing else of the
|
|
254
|
+
// projects.
|
|
249
255
|
//
|
|
250
256
|
// The lockfile is resolved as yarn resolves it, in yarn's order, which
|
|
251
257
|
// decides where a package goes: the resolutions' patterns, then the root's
|
|
@@ -259,6 +265,16 @@ export interface Yarn1Tree {
|
|
|
259
265
|
// to a semver range, or to the registry's own tarball or a directory of
|
|
260
266
|
// the project, as below.
|
|
261
267
|
//
|
|
268
|
+
// With `production`, as --production has yarn install it: no workspace's
|
|
269
|
+
// devDependencies are asked for, nor their entries read; the root's are
|
|
270
|
+
// asked for all the same, resolved, fetched, checked and hoisted as without
|
|
271
|
+
// it, but marked ignored, as yarn marks them, so each copy is installed only
|
|
272
|
+
// where something else needs it, with what it alone needs left out. So a
|
|
273
|
+
// devDependency of the root still takes the place it is hoisted to, which a
|
|
274
|
+
// version another package needs is kept from, as without it; and one the
|
|
275
|
+
// host cannot run fails as it does without it, though the tree leaves it
|
|
276
|
+
// out.
|
|
277
|
+
//
|
|
262
278
|
// Scripts are always ignored, as `--ignore-scripts` has yarn ignore them,
|
|
263
279
|
// whatever the settings say. No .bin is written, nor yarn's own
|
|
264
280
|
// .yarn-integrity; but each bin's target is made executable, chmod 755, in
|