@preventive/deptree 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "In-memory dependency tree, as a package manager installs it",
5
5
  "type": "module",
6
6
  "exports": {
@@ -148,11 +148,11 @@
148
148
  "dependencies": {
149
149
  "@chalker/queue": "^1.0.1",
150
150
  "@exodus/bytes": "^1.16.0",
151
- "@preventive/archive": "^1.2.0",
151
+ "@preventive/archive": "^1.2.1",
152
152
  "@preventive/compare": "^1.2.11",
153
153
  "@preventive/diff": "^1.1.0",
154
154
  "@preventive/lockfile": "^1.2.0",
155
155
  "@preventive/upstream": "^1.3.0",
156
- "@preventive/vfs": "1.0.0-beta.4"
156
+ "@preventive/vfs": "^1.0.0"
157
157
  }
158
158
  }
package/src/npm/tree.js CHANGED
@@ -75,14 +75,17 @@ async function fetchAll(tarballs, host, fetching) {
75
75
  const pkg = { ...await fetch(tarball, where), integrity: tarball.integrity }
76
76
  for (const node of copies) fetched.set(node, pkg)
77
77
  }, ({ where }) => where)
78
- return { fetched, tarballs: tarballs.size }
78
+ return fetched
79
79
  }
80
80
 
81
81
  // npm 10 makes every package's directory before leaving out those the host
82
82
  // cannot run, or --omit=dev omits, and leaves the directories they were in.
83
83
  function residueOf(nodes, left) {
84
- const removed = [...left].map((node) => node.location)
85
- const inRemoved = (dir) => removed.some((location) => dir === location || dir.startsWith(`${location}/`))
84
+ const removed = new Set([...left].map((node) => node.location))
85
+ const inRemoved = (dir) => {
86
+ for (let at = dir; at !== '.'; at = dirname(at)) if (removed.has(at)) return true
87
+ return false
88
+ }
86
89
  const dirs = new Set()
87
90
  for (const location of removed) {
88
91
  for (let dir = dirname(location); dir !== '.' && !nodes.has(dir) && !inRemoved(dir); dir = dirname(dir)) dirs.add(dir)
@@ -90,6 +93,9 @@ function residueOf(nodes, left) {
90
93
  return dirs
91
94
  }
92
95
 
96
+ // A package's files with those `fixed` by linking its bins in their place.
97
+ const withFixed = (files, fixed) => (fixed === undefined || fixed.size === 0 ? files : new Map([...files].map(([path, file]) => [path, fixed.get(path) ?? file])))
98
+
93
99
  // With `sizeEstimateOnly`, each package's directory alone is made, and its
94
100
  // size counted; with `lazy`, its directory alone.
95
101
  function writeTree({ lockfile, kept, fetched, changed, residue, sizeEstimateOnly, lazy }) {
@@ -102,8 +108,7 @@ function writeTree({ lockfile, kept, fetched, changed, residue, sizeEstimateOnly
102
108
  continue
103
109
  }
104
110
  const { files, dirs } = fetched.get(node)
105
- const fixed = changed.get(node.location)
106
- writeFiles(vfs, node.location, { dirs, files: fixed === undefined ? files : new Map([...files].map(([path, file]) => [path, fixed.get(path) ?? file])) }, stats)
111
+ writeFiles(vfs, node.location, { dirs, files: withFixed(files, changed.get(node.location)) }, stats)
107
112
  }
108
113
  // checkLinks has each a workspace's, in the project.
109
114
  for (const [location, target] of Object.entries(lockfile.links)) {
@@ -145,7 +150,7 @@ function lazyUnpacker({ vfs, kept, tarballOf, settings, host, fetching, stats, f
145
150
  const written = { files: 0, bytes: 0, links: 0 }
146
151
  try {
147
152
  const fixed = claimed.has(node.location) ? fixClaimed(node.location, claimed.get(node.location), got) : new Map()
148
- writeFiles(tree, node.location, { dirs: got.dirs, files: fixed.size === 0 ? got.files : new Map([...got.files].map(([path, file]) => [path, fixed.get(path) ?? file])) }, written)
153
+ writeFiles(tree, node.location, { dirs: got.dirs, files: withFixed(got.files, fixed) }, written)
149
154
  writeInto(vfs, tree, folded)
150
155
  } catch (error) {
151
156
  throw refusalOf(error, whereOf(node))
@@ -170,9 +175,7 @@ function rootListsOf(text) {
170
175
  export async function buildNpmTree(options) {
171
176
  const { host: given, vfs: into } = options ?? {}
172
177
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
173
- const fetching = fetchingOf(options ?? {})
174
- if (fetching.sizeEstimateOnly && into !== undefined) throw new TypeError('vfs is not taken with sizeEstimateOnly, whose tree has no files to mount')
175
- if (fetching.lazy && into !== undefined) throw new TypeError('vfs is not taken with lazy, whose tree is unpacked a package at a time')
178
+ const fetching = fetchingOf(options ?? {}, into)
176
179
  const production = productionOf(options ?? {})
177
180
  const host = checkHost(given)
178
181
  const folded = host.os === 'darwin'
@@ -192,12 +195,12 @@ export async function buildNpmTree(options) {
192
195
  const skipped = skippedOf(nodes, host, settings, omitted)
193
196
  const kept = [...nodes.values()].filter((node) => node.kind === 'package' && !skipped.has(node) && !omitted.has(node))
194
197
  const tarballs = tarballsOf(kept)
195
- const { fetched, tarballs: count } = fetching.lazy ? { fetched: new Map(), tarballs: 0 } : await fetchAll(tarballs, host, fetching)
198
+ const fetched = fetching.lazy ? new Map() : await fetchAll(tarballs, host, fetching)
196
199
  const changed = settings.binLinks && !fetching.sizeEstimateOnly && !fetching.lazy ? fixBins(kept, fetched) : new Map()
197
200
  const residue = host.reuse ? residueOf(nodes, new Set([...skipped, ...omitted])) : new Set()
198
201
  const { vfs, stats: written } = writeTree({ lockfile, kept, fetched, changed, residue, sizeEstimateOnly: fetching.sizeEstimateOnly, lazy: fetching.lazy })
199
202
  const packages = Object.keys(lockfile.packages).length
200
- const stats = { packages, installed: kept.length, skipped: packages - kept.length - omitted.size, tarballs: count, ...written }
203
+ const stats = { packages, installed: kept.length, skipped: packages - kept.length - omitted.size, tarballs: fetching.lazy ? 0 : tarballs.size, ...written }
201
204
  const entryOf = (node, { integrity, about, size }) => {
202
205
  const { name, version, dev, optional, devOptional, peer } = node.pkg
203
206
  return { path: node.location, name, version, integrity, ...about, dev, optional, devOptional, peer, ...fetching.sizeEstimateOnly ? { size } : {} }
package/src/pnpm/bins.js CHANGED
@@ -84,11 +84,20 @@ function commandReader(nodes, projects, major) {
84
84
  }
85
85
  }
86
86
 
87
+ // The lockfile has no hasBin for a directory, whose bins pnpm 12 reads.
88
+ const mayHaveBinIn = (nodes) => (dir) => nodes.get(dir)?.pkg.hasBin === true || nodes.get(dir)?.pkg.resolution.type === 'directory'
89
+
90
+ // The names a project of `manifest` depends on itself.
91
+ const ownNames = (manifest) => new Set(Object.keys({ ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }))
92
+
93
+ // A package's link in the root's node_modules, where pnpm hoists publicly.
94
+ const PUBLIC = /^node_modules\/(?:@[^/]+\/)?[^/@.][^/]*$/u
95
+
87
96
  // pnpm's preferDirectCmds for a project of `manifest`: of the commands of
88
97
  // `entries`, [alias, directory], those of its own dependencies, then of the
89
98
  // others those whose names none of them has.
90
99
  function preferOwn(entries, manifest, commandsOfDir) {
91
- const own = new Set(Object.keys({ ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }))
100
+ const own = ownNames(manifest)
92
101
  const commands = entries.flatMap(([alias, dir]) => commandsOfDir(dir).map((command) => ({ ...command, direct: own.has(alias) })))
93
102
  const names = new Set(commands.filter((command) => command.direct).map(({ name }) => name))
94
103
  return [...commands.filter((command) => command.direct), ...commands.filter((command) => !names.has(command.name))]
@@ -98,8 +107,7 @@ function preferOwn(entries, manifest, commandsOfDir) {
98
107
  // `building` is whether any patch is configured, `peers` autoInstallPeers.
99
108
  export function binTargets({ nodes, projects, direct, links, publicHoist, building, peers, major }) {
100
109
  const commandsOfDir = commandReader(nodes, projects, major)
101
- // The lockfile has no hasBin for a directory, whose bins pnpm 12 reads.
102
- const mayHaveBin = (dir) => nodes.get(dir)?.pkg.hasBin === true || nodes.get(dir)?.pkg.resolution.type === 'directory'
110
+ const mayHaveBin = mayHaveBinIn(nodes)
103
111
 
104
112
  const { fixed, contested, link } = linker(major)
105
113
 
@@ -135,11 +143,10 @@ export function binTargets({ nodes, projects, direct, links, publicHoist, buildi
135
143
  let linked
136
144
  if (id === '.' && publicHoist) {
137
145
  const manifest = projects.get('.')
138
- const own = new Set(Object.keys({ ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }))
146
+ const own = ownNames(manifest)
139
147
  const isOwn = (path) => own.has(path.slice('node_modules/'.length))
140
148
  // pnpm 12 links what it hoists of the projects apart, before.
141
- const entries = [...links].filter(([path, dir]) => /^node_modules\/(?:@[^/]+\/)?[^/@.][^/]*$/u.test(path)
142
- && (major < 12 || isOwn(path) || mayHaveBin(dir)))
149
+ const entries = [...links].filter(([path, dir]) => PUBLIC.test(path) && (major < 12 || isOwn(path) || mayHaveBin(dir)))
143
150
  relink ||= major >= 12 && entries.some(([path, dir]) => !isOwn(path) && mayHaveBin(dir))
144
151
  linked = link(preferOwn(entries.map(([path, dir]) => [path.slice('node_modules/'.length), dir]), manifest, commandsOfDir), { ordered: false, where, fixNode: relink })
145
152
  } else {
@@ -163,7 +170,7 @@ export function binTargets({ nodes, projects, direct, links, publicHoist, buildi
163
170
  // again what their first link did, and fixes nothing of theirs. The others
164
171
  // are read as having no bins (lazy.js).
165
172
  export function binReads({ nodes, projects, direct, links, publicHoist, peers, major }) {
166
- const mayHaveBin = (dir) => nodes.get(dir)?.pkg.hasBin === true || nodes.get(dir)?.pkg.resolution.type === 'directory'
173
+ const mayHaveBin = mayHaveBinIn(nodes)
167
174
  const reads = new Set()
168
175
  for (const node of nodes.values()) {
169
176
  if (mayHaveBin(node.dir) || node.pkg.bundledDependencies !== undefined) reads.add(node.dir)
@@ -173,10 +180,9 @@ export function binReads({ nodes, projects, direct, links, publicHoist, peers, m
173
180
  for (const [id, children] of direct) {
174
181
  if (major >= 11 && peers) for (const dir of peersOf(children, nodes)) reads.add(dir)
175
182
  if (id === '.' && publicHoist) {
176
- const manifest = projects.get('.')
177
- const own = new Set(Object.keys({ ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }))
183
+ const own = ownNames(projects.get('.'))
178
184
  for (const [path, dir] of links) {
179
- if (/^node_modules\/(?:@[^/]+\/)?[^/@.][^/]*$/u.test(path) && (major < 12 || own.has(path.slice('node_modules/'.length)))) reads.add(dir)
185
+ if (PUBLIC.test(path) && (major < 12 || own.has(path.slice('node_modules/'.length)))) reads.add(dir)
180
186
  }
181
187
  } else if (major < 11) {
182
188
  for (const dir of children.values()) reads.add(dir)
@@ -213,8 +219,8 @@ function linkCopies(builds, phases, fixed, contested, { keepsModules, major }) {
213
219
  for (const [target, { owner, why }] of phaseContested) mark(target, owner, before, why)
214
220
  }
215
221
  for (const [build, marks] of groups) {
216
- for (const rel of new Set(marks.map((item) => item.rel))) {
217
- const mine = marks.filter((item) => item.rel === rel && (!item.before || build.candidates.includes(item.owner)))
222
+ for (const [rel, marked] of Map.groupBy(marks, (item) => item.rel)) {
223
+ const mine = marked.filter((item) => !item.before || build.candidates.includes(item.owner))
218
224
  const after = mine.filter((item) => !item.before)
219
225
  const before = mine.filter((item) => item.before)
220
226
  const beforeFixed = new Set(before.filter((item) => item.why === undefined).map(({ owner }) => owner))
@@ -296,14 +302,16 @@ export function hoistedBinTargets({ nodes, projects, modules, builds = [], hardl
296
302
  return fixedFiles(nodes, fixed, contested, major)
297
303
  }
298
304
 
305
+ // pnpm 9 and 12 read each linked file's `#!` line. '' is the package.
306
+ export function failsAsDirectory(node, path, major) {
307
+ if (major >= 10 && major < 12) return false
308
+ const prefix = `${path}/`
309
+ return path === '' || node.files.keys().some((name) => name.startsWith(prefix))
310
+ }
311
+
299
312
  function fixedFiles(nodes, fixed, contested, major) {
300
- // pnpm 9 and 12 read each linked file's `#!` line. '' is the package.
301
313
  const checkDirectory = (node, path) => {
302
- if (major >= 10 && major < 12) return
303
- const prefix = `${path}/`
304
- if (path === '' || node.files.keys().some((name) => name.startsWith(prefix))) {
305
- throw new DeptreeError(`its bin ${quote(path === '' ? '.' : path)} is a directory, which pnpm ${major} fails on`, quote(node.key))
306
- }
314
+ if (failsAsDirectory(node, path, major)) throw new DeptreeError(`its bin ${quote(path === '' ? '.' : path)} is a directory, which pnpm ${major} fails on`, quote(node.key))
307
315
  }
308
316
  for (const [target, { owner, why }] of contested) {
309
317
  const node = nodes.get(owner)
@@ -311,7 +319,7 @@ function fixedFiles(nodes, fixed, contested, major) {
311
319
  checkDirectory(node, path)
312
320
  const file = node.files.get(path)
313
321
  if (fixed.has(target) || file?.data === undefined) continue
314
- if (executableMode(file.mode, major) === file.mode && (major >= 12 || (crlfShebang(file.data) === -1 && node.pkg.patchHash === undefined))) continue
322
+ if (!fixChanges(file, major) && (major >= 12 || node.pkg.patchHash === undefined)) continue
315
323
  throw new DeptreeError(`whether pnpm makes ${quote(path)} executable turns on ${why}`, quote(node.key))
316
324
  }
317
325
  const byNode = new Map()
@@ -327,6 +335,9 @@ function fixedFiles(nodes, fixed, contested, major) {
327
335
 
328
336
  export const executableMode = (mode, major) => (major >= 11 ? mode | 0o111 : 0o755)
329
337
 
338
+ // Whether fixBin changes `file`.
339
+ export const fixChanges = (file, major) => executableMode(file.mode, major) !== file.mode || (major < 12 && crlfShebang(file.data) !== -1)
340
+
330
341
  // pnpm reads and writes the file as UTF-8, which changes one that is not.
331
342
  export function fixBin(file, where, major) {
332
343
  const mode = executableMode(file.mode, major)
@@ -166,11 +166,8 @@ export function workspaceHoists(placed, lockfile, { hoistPattern, publicHoistPat
166
166
  // of a patched one's patch; `pnpm` the version, for what is refused.
167
167
  export function hoistedBuilds(byDir, projects, builds, { hardlinks, keepsModules = false, idOf = (key) => key, changesOf, pnpm = '10' }) {
168
168
  const first = new Map()
169
- const placedIn = new Set()
170
- for (const node of byDir.values()) {
171
- if (!first.has(idOf(node.key))) first.set(idOf(node.key), node.dir)
172
- placedIn.add(node.modules)
173
- }
169
+ for (const node of byDir.values()) if (!first.has(idOf(node.key))) first.set(idOf(node.key), node.dir)
170
+ const dropping = mayDrop(byDir)
174
171
  const childrenOf = (node) => Object.entries({ ...node.pkg.dependencies, ...node.pkg.optionalDependencies }).map(([alias, key]) => [alias, first.get(idOf(key))]).filter(([, dir]) => dir !== undefined)
175
172
  const tops = [...byDir.values()].filter((node) => projects.has(node.modules)).map((node) => node.dir)
176
173
  const reached = reachable(tops, (dir) => childrenOf(byDir.get(dir)).map(([, child]) => child))
@@ -194,7 +191,7 @@ export function hoistedBuilds(byDir, projects, builds, { hardlinks, keepsModules
194
191
  } else if (copies.length > 1) {
195
192
  const own = node.files.keys().find((path) => path.split('/').includes('node_modules'))
196
193
  if (own !== undefined) throw new DeptreeError(`pnpm ${pnpm} builds one of its copies where any patch is configured, and makes the others hardlinks of it, with no ${quote(own)}, which is not supported`, quote(key))
197
- const nested = copies.find((copy) => placedIn.has(`${copy.dir}/node_modules`))
194
+ const nested = dropping.get(key)
198
195
  if (nested !== undefined) throw new DeptreeError(`pnpm ${pnpm} builds one of its copies where any patch is configured, and makes the others hardlinks of it, dropping their node_modules: ${quote(`${nested.dir}/node_modules`)} may be dropped, which is not supported`, quote(key))
199
196
  }
200
197
  built.push({ key, copies: copies.map((copy) => copy.dir), candidates, children: childrenOf(node) })
package/src/pnpm/lazy.js CHANGED
@@ -6,8 +6,8 @@ import { Vfs } from '@preventive/vfs'
6
6
  import { eachConcurrently, limited } from '../concurrent.js'
7
7
  import { quote, refusalOf } from '../error.js'
8
8
  import { unpacker, writeInto } from '../lazy.js'
9
- import { NO_ABOUT, crlfShebang } from '../tarball.js'
10
- import { executableMode } from './bins.js'
9
+ import { NO_ABOUT } from '../tarball.js'
10
+ import { failsAsDirectory, fixChanges } from './bins.js'
11
11
  import { binsOf } from './commands.js'
12
12
  import { checkFetched, fetchPackage } from './package.js'
13
13
  import { compose, writeNode } from './write.js'
@@ -21,7 +21,7 @@ import { compose, writeNode } from './write.js'
21
21
  // is a directory; or the package is patched, which is held to its bins as
22
22
  // linked; or its commands cannot be read alone. Else its files are as fetched
23
23
  // and patched, whatever pnpm links of its bins, and of anything else's.
24
- export function bound(node, major, builds) {
24
+ function bound(node, major, builds) {
25
25
  if (builds?.(node)) return true
26
26
  let bins
27
27
  try {
@@ -32,10 +32,10 @@ export function bound(node, major, builds) {
32
32
  if (bins.size === 0) return false
33
33
  if (node.pkg.patchHash !== undefined) return true
34
34
  for (const path of bins.keys()) {
35
- if ((major < 10 || major >= 12) && (path === '' || node.files.keys().some((name) => name.startsWith(`${path}/`)))) return true
35
+ if (failsAsDirectory(node, path, major)) return true
36
36
  const file = node.files.get(path)
37
37
  if (file?.data === undefined) continue
38
- if (executableMode(file.mode, major) !== file.mode || (major < 12 && crlfShebang(file.data) !== -1)) return true
38
+ if (fixChanges(file, major)) return true
39
39
  }
40
40
  return false
41
41
  }
@@ -134,7 +134,7 @@ export async function lazyUnpacker({ vfs, byDir, stats, fixes, reads, builds, ea
134
134
  await eachConcurrently(early.nodes, prepare, (node) => quote(node.key))
135
135
  early.check()
136
136
  }
137
- return unpacker(new Map([...byDir.values()].map((node) => [node.dir, node])), async (node) => {
137
+ return unpacker(byDir, async (node) => {
138
138
  await prepare(node)
139
139
  const { targets, executable } = bound(node, major, builds) ? await fixesFor(node) : { targets: new Map(), executable: new Map() }
140
140
  const tree = new Vfs()
@@ -6,6 +6,7 @@
6
6
  import { valid } from '@preventive/upstream/semver.js'
7
7
  import { join } from '@preventive/vfs/path.js'
8
8
  import { DeptreeError, quote } from '../error.js'
9
+ import { own } from '../manifest.js'
9
10
 
10
11
  // From validate-npm-package-name 5, by which pnpm reads a selector's name.
11
12
  const SCOPED = /^(?:@([^/]+?)\/)?([^/]+?)$/u
@@ -37,12 +38,12 @@ export function parseSelector(selector, where) {
37
38
 
38
39
  // A layer's overrides with each `$name` replaced from the root package.json.
39
40
  export function replaceReferences(overrides, manifest, where) {
40
- const own = { ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }
41
+ const deps = { ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }
41
42
  const replaced = Object.create(null)
42
43
  for (const [selector, spec] of Object.entries(overrides)) {
43
44
  if (typeof spec !== 'string') throw new DeptreeError(`expected a string for ${quote(selector)}`, where)
44
45
  if (!spec.startsWith('$')) { replaced[selector] = spec; continue }
45
- const found = Object.hasOwn(own, spec.slice(1)) ? own[spec.slice(1)] : undefined
46
+ const found = own(deps, spec.slice(1))
46
47
  if (typeof found !== 'string' || found === '') throw new DeptreeError(`${quote(spec)} names no dependency of the root package.json`, where)
47
48
  replaced[selector] = found
48
49
  }
@@ -53,7 +54,7 @@ const CATALOG = 'catalog:'
53
54
 
54
55
  export const catalogOf = (spec) => (spec.startsWith(CATALOG) ? spec.slice(CATALOG.length).trim() || 'default' : undefined)
55
56
 
56
- export const catalogEntry = (catalogs, catalog, name) => (Object.hasOwn(catalogs, catalog) && Object.hasOwn(catalogs[catalog], name) ? catalogs[catalog][name] : undefined)
57
+ export const catalogEntry = (catalogs, catalog, name) => own(own(catalogs, catalog), name)
57
58
 
58
59
  // @pnpm/catalogs.resolver's resolveFromCatalog.
59
60
  function fromCatalog(catalogs, spec, name, where, major) {
@@ -99,7 +99,7 @@ const listed = (bundled) => (bundled === false || (Array.isArray(bundled) && bun
99
99
 
100
100
  // `read` is the package.json as hook.js's hook has it, and `packages` the
101
101
  // lockfile's, by which a `file:` target is the directory it resolves to.
102
- export function checkDependencies(manifest, read, pkg, packages, where) {
102
+ function checkDependencies(manifest, read, pkg, packages, where) {
103
103
  const bundled = bundledOf(manifest)
104
104
  const given = new Set([...names(pkg.dependencies), ...names(pkg.optionalDependencies)])
105
105
  for (const name of [...names(read.dependencies), ...names(read.optionalDependencies)]) {
@@ -89,13 +89,13 @@ const checkGlobs12 = (lines, what, where) => {
89
89
  // pnpm 12's `files` allowlist: its matcher, or undefined where no entry is
90
90
  // one, and the files it names outright.
91
91
  function filesOf12(view, files, where) {
92
- checkGlobs12(files ?? [], 'its package.json has `files`', where)
92
+ checkGlobs12(files, 'its package.json has `files`', where)
93
93
  const globs = []
94
- for (const entry of files ?? []) {
94
+ for (const entry of files) {
95
95
  const path = fieldPath(entry)
96
96
  if (path !== '') globs.push(gitignoreGlob(path.startsWith('!') ? path : `/${path}`, `${where}: files[${quote(entry)}]`))
97
97
  }
98
- const named = new Set((files ?? []).filter((entry) => !entry.startsWith('!') && !entry.endsWith('/') && !/[*?[\]{}]/u.test(entry)).map(fieldPath).filter((path) => path !== '' && !path.split('/').includes('..') && view.type(path) === 'file'))
98
+ const named = new Set(files.filter((entry) => !entry.startsWith('!') && !entry.endsWith('/') && !/[*?[\]{}]/u.test(entry)).map(fieldPath).filter((path) => path !== '' && !path.split('/').includes('..') && view.type(path) === 'file'))
99
99
  return { globs: globs.length > 0 ? globs : undefined, named }
100
100
  }
101
101
 
@@ -141,7 +141,7 @@ function walk12(view, { globs }, where) {
141
141
  }
142
142
 
143
143
  function pack12(view, manifest, where) {
144
- const files = Array.isArray(manifest.files) ? filesOf12(view, manifest.files, where) : { named: new Set() }
144
+ const files = Array.isArray(manifest.files) ? filesOf12(view, manifest.files, where) : {}
145
145
  const main = typeof manifest.main === 'string' ? [manifest.main] : []
146
146
  const bins = typeof manifest.bin === 'string' ? [manifest.bin] : manifest.bin !== null && typeof manifest.bin === 'object' && !Array.isArray(manifest.bin) ? Object.values(manifest.bin).filter((bin) => typeof bin === 'string') : []
147
147
  const fields = [...main, ...bins].map(fieldPath)
@@ -26,6 +26,7 @@ function ruleOf(pnpm, major) {
26
26
  }
27
27
 
28
28
  const edgesOf = (deps) => Object.values(deps).filter((target) => !target.startsWith('link:'))
29
+ const prodEdgesOf = ({ dependencies, optionalDependencies }) => edgesOf({ ...dependencies, ...optionalDependencies })
29
30
 
30
31
  // The groups that end a key, each without its parentheses, the patch hash's
31
32
  // first where the key has one; a key the lockfile reader takes has them
@@ -89,7 +90,7 @@ function satisfactionEdges(lockfile, rule, fromRoot) {
89
90
  const importers = Object.values(lockfile.importers)
90
91
  const direct = importers.map((importer) => new Set(directOf(importer)))
91
92
  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 next = (key) => (key in lockfile.packages ? prodEdgesOf(lockfile.packages[key]) : [])
93
94
  const groups = Map.groupBy(entries, ({ target }) => (rootDev.has(target) ? '' : direct.flatMap((keys, i) => (keys.has(target) ? [] : [i])).join(',')))
94
95
  for (const [listing, group] of groups) {
95
96
  const seeds = listing === '' ? [] : listing.split(',').flatMap((i) => directOf(importers[Number(i)]))
@@ -124,8 +125,8 @@ export function productionLockfile(lockfile, { pnpm, major, resolvePeersFromWork
124
125
  const rule = ruleOf(pnpm, major)
125
126
  const edges = rule === undefined ? new Map() : satisfactionEdges(lockfile, rule, resolvePeersFromWorkspaceRoot)
126
127
  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 }))
128
+ const starts = Object.values(importers).flatMap(prodEdgesOf)
129
+ const picked = reachable(starts, (key) => prodEdgesOf(walked.packages[key]))
129
130
  const packages = Object.fromEntries(Object.entries(lockfile.packages).filter(([key]) => picked.has(key)))
130
131
  return { walked, installing: { ...lockfile, importers, packages: without(packages, edges, (target) => !picked.has(target)) } }
131
132
  }
package/src/pnpm/tree.js CHANGED
@@ -255,9 +255,7 @@ async function buildIsolated({ lockfile, checked, settings, host, project, hook,
255
255
  export async function buildPnpmTree(options) {
256
256
  const { project, host: given, vfs: into } = options ?? {}
257
257
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
258
- const fetching = fetchingOf(options ?? {})
259
- if (fetching.sizeEstimateOnly && into !== undefined) throw new TypeError('vfs is not taken with sizeEstimateOnly, whose tree has no files to mount')
260
- if (fetching.lazy && into !== undefined) throw new TypeError('vfs is not taken with lazy, whose tree is unpacked a package at a time')
258
+ const fetching = fetchingOf(options ?? {}, into)
261
259
  const production = productionOf(options ?? {})
262
260
  if (project !== undefined) checkProject(project)
263
261
  const machine = checkHost(given)
package/src/tarball.js CHANGED
@@ -94,7 +94,8 @@ export const NO_ABOUT = Object.freeze(aboutOf({}))
94
94
  // alone (fetchSize); and `lazy`, false unless given true, for nothing until a
95
95
  // package is unpacked, and then its tarball, as without it. The two are
96
96
  // refused together: a tree is laid out with sizes alone, or to be unpacked.
97
- export function fetchingOf({ metadata = true, cache, sizeEstimateOnly = false, lazy = false }) {
97
+ // Each is refused with `into`, a Vfs given to mount the tree's files into.
98
+ export function fetchingOf({ metadata = true, cache, sizeEstimateOnly = false, lazy = false }, into) {
98
99
  if (typeof metadata !== 'boolean') throw new TypeError('metadata must be a boolean, or left out')
99
100
  if (cache !== undefined && cache !== false && (typeof cache?.read !== 'function' || typeof cache?.write !== 'function')) {
100
101
  throw new TypeError('cache must be false, or a store with read and write, or left out')
@@ -102,6 +103,8 @@ export function fetchingOf({ metadata = true, cache, sizeEstimateOnly = false, l
102
103
  if (typeof sizeEstimateOnly !== 'boolean') throw new TypeError('sizeEstimateOnly must be a boolean, or left out')
103
104
  if (typeof lazy !== 'boolean') throw new TypeError('lazy must be a boolean, or left out')
104
105
  if (lazy && sizeEstimateOnly) throw new TypeError('lazy is not taken with sizeEstimateOnly, which fetches no tarball to unpack')
106
+ if (sizeEstimateOnly && into !== undefined) throw new TypeError('vfs is not taken with sizeEstimateOnly, whose tree has no files to mount')
107
+ if (lazy && into !== undefined) throw new TypeError('vfs is not taken with lazy, whose tree is unpacked a package at a time')
105
108
  return { metadata, cache, sizeEstimateOnly, lazy }
106
109
  }
107
110
 
@@ -53,7 +53,7 @@ const decoder = new TextDecoder('utf-8', { fatal: true })
53
53
  // 3.10.8, is the first it signed over one it made, and superstatic@6.0.0, at
54
54
  // 2018-08-03T20:22:28.120Z, the last over none. It has since made one for
55
55
  // every version published before too.
56
- export const SHA512_SINCE = '2018-08-05T14:58:16.253Z'
56
+ const SHA512_SINCE = '2018-08-05T14:58:16.253Z'
57
57
 
58
58
  // The hex of an integrity that is a sha1 alone.
59
59
  function sha1Of(integrity) {
package/src/yarn1/tree.js CHANGED
@@ -38,7 +38,7 @@ async function fetchAll(refs, first, fetching) {
38
38
  const fetched = new Map()
39
39
  const times = new Map()
40
40
  const tarballs = new Map(refs.map((ref) => [ref, registryTarball(ref.entry, fetchedName(ref), whereOf(ref))]))
41
- await eachConcurrently([...first.values()], async (ref) => {
41
+ await eachConcurrently(first.values(), async (ref) => {
42
42
  fetched.set(ref, await fetchYarnPackage(tarballs.get(ref), whereOf(ref), times, fetching))
43
43
  }, whereOf)
44
44
  for (const ref of refs) {