@preventive/deptree 1.5.3 → 1.5.5

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/npm.d.ts CHANGED
@@ -252,8 +252,8 @@ export interface NpmLazyTree extends NpmTree {
252
252
  *
253
253
  * And held to what npm's lockfiles and the registry always hold: each tarball gzipped, under one directory,
254
254
  * named as tar reads it (no `\`, at most 1024 segments), with nothing in its own node_modules, no setuid,
255
- * setgid or sticky bit, no link name on a file, no global pax header or pax size ahead of another extended
256
- * header, and the lockfile's sha512. On macOS, two names in a directory differing only in case or
255
+ * setgid or sticky bit, no link name on a file, no global pax header but one of a comment alone (as git
256
+ * archive writes its commit), no pax size ahead of another extended header, and the lockfile's sha512. On macOS, two names in a directory differing only in case or
257
257
  * normalization are refused. Each package's `resolved` has to be the registry's own tarball URL, a scope's
258
258
  * `/` as `%2f` or not, or that on yarn's mirror. Ranges are read with the semver of the npm beside node.
259
259
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "In-memory dependency tree, as a package manager installs it",
5
5
  "type": "module",
6
6
  "exports": {
@@ -172,7 +172,7 @@
172
172
  "@preventive/archive": "^1.4.0",
173
173
  "@preventive/compare": "^1.2.11",
174
174
  "@preventive/diff": "^1.1.1",
175
- "@preventive/lockfile": "^1.3.0",
175
+ "@preventive/lockfile": "^1.3.1",
176
176
  "@preventive/upstream": "^1.8.0",
177
177
  "@preventive/vfs": "^1.1.0"
178
178
  }
package/pnpm.d.ts CHANGED
@@ -194,7 +194,7 @@ export interface PnpmInstalled {
194
194
  repository: string | PackageRepository | undefined;
195
195
  homepage: string | undefined;
196
196
  bugs: string | PackageBugs | undefined;
197
- /** Whether devDependencies alone reach it, so `--prod` would leave it out */
197
+ /** Whether `--prod` would leave it out; hoisted, by name and version */
198
198
  dev: boolean;
199
199
  /** Whether optional dependencies alone reach it, as the lockfile records */
200
200
  optional: boolean;
@@ -19,6 +19,11 @@ export function registryTarball({ name, version, resolution }, where) {
19
19
 
20
20
  const FILES = new Set(['file', 'contiguous-file'])
21
21
 
22
+ // One global header of a `comment` alone, as git archive writes its commit: tar's releases keep it on each entry
23
+ // and extract by nothing of it. They split a value at a newline into records, and merge a global header into the
24
+ // one before, which the archive reader replaces, so a second ahead of one entry would hide what the first sets.
25
+ const isCommentOnly = (globalPax, extended) => extended.filter(({ kind }) => kind === 'global').length <= 1 && globalPax.entries().every(([key, value]) => key === 'comment' && !value.includes('\n'))
26
+
22
27
  // tar up to 7.5.15 (npm 10.9.8, 11.16 and before) reads a pax size into each header after the pax one up
23
28
  // to its entry, so a long name, long link or global header between them, and all after, reads otherwise
24
29
  function checkPaxSizes(entries, where) {
@@ -33,12 +38,12 @@ function unpack(entries, where) {
33
38
  const files = new Map()
34
39
  const ignores = new Set()
35
40
  let top
36
- for (const { storedName, storedLinkname, type, mode, data, globalPax } of entries) {
41
+ for (const { storedName, storedLinkname, type, mode, data, globalPax, extended } of entries) {
37
42
  const segments = storedName.replace(/(?<=.)\/$/u, '').split('/')
38
43
  if (segments.length > 1024 || /[\\\0]/u.test(storedName) || segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
39
44
  throw new DeptreeError(`${quote(storedName)} is a name tar reads otherwise`, where)
40
45
  }
41
- if (globalPax.size > 0) throw new DeptreeError(`${quote(storedName)} has a pax header tar's releases read otherwise`, where)
46
+ if (!isCommentOnly(globalPax, extended)) throw new DeptreeError(`${quote(storedName)} has a pax header tar's releases read otherwise`, where)
42
47
  if (top !== undefined && segments[0] !== top) throw new DeptreeError('the tarball has entries under more than one directory', where)
43
48
  top = segments[0]
44
49
  if (!FILES.has(type)) continue
@@ -219,9 +219,9 @@ export function hoistedModules(byDir, links, projects, manifests, lockfile) {
219
219
  }
220
220
 
221
221
  // The snapshots `pnpm install --prod` would install, by pnpm's name@version.
222
- export function prodPackages(lockfile, skipped, directories) {
223
- const edges = ({ dependencies, optionalDependencies }) => [...Object.values(dependencies), ...Object.values(optionalDependencies)]
224
- const reached = reachable(Object.values(lockfile.importers).flatMap(edges), (key) => edges(lockfile.packages[key]), (key) => key.startsWith('link:') || skipped.has(key))
222
+ export function prodPackages(lockfile, skipped, directories, unwalked = new Map()) {
223
+ const edges = ({ dependencies, optionalDependencies }, aliases) => [...Object.entries(dependencies), ...Object.entries(optionalDependencies)].flatMap(([alias, target]) => (aliases?.has(alias) ? [] : [target]))
224
+ const reached = reachable(Object.values(lockfile.importers).flatMap((importer) => edges(importer)), (key) => edges(lockfile.packages[key], unwalked.get(key)), (key) => key.startsWith('link:') || skipped.has(key))
225
225
  return new Set(reached.values().map((key) => packageIdOf(key, lockfile.packages[key], directories)))
226
226
  }
227
227
 
@@ -94,6 +94,12 @@ function satisfactionEdges(lockfile, rule, fromRoot) {
94
94
  return edges
95
95
  }
96
96
 
97
+ // By snapshot, the aliases --prod does not walk; pnpm 12 before 12.7.0 walks them all.
98
+ export function unwalkedEdges(lockfile, { pnpm, major, resolvePeersFromWorkspaceRoot }) {
99
+ const rule = ruleOf(pnpm, major)
100
+ return rule === undefined || rule.refused ? new Map() : satisfactionEdges(lockfile, rule, resolvePeersFromWorkspaceRoot)
101
+ }
102
+
97
103
  // Each snapshot `edges` names, without those of its edges `drop` takes.
98
104
  function without(packages, edges, drop) {
99
105
  const kept = { ...packages }
package/src/pnpm/tree.js CHANGED
@@ -23,7 +23,7 @@ import { checkLinks, checkOptional } from './checks.js'
23
23
  import { createDirectoryCheck } from './directories.js'
24
24
  import { listExtensions } from './extensions.js'
25
25
  import { createHook } from './hook.js'
26
- import { productionLockfile } from './production.js'
26
+ import { productionLockfile, unwalkedEdges } from './production.js'
27
27
  import { listOverrides } from './overrides.js'
28
28
  import { checkHost, inputsOf, manifestsOf, patchesOf, readLockfile } from './inputs.js'
29
29
  import { checkProjects, pinsPnpm, workspaceNames } from './projects.js'
@@ -122,14 +122,16 @@ function linkTarget(path, target) {
122
122
  return relative(`${root}/${dirname(path)}`, `${root}/${target}`) || '.'
123
123
  }
124
124
 
125
- // What no project's dependencies or optionalDependencies reach is dev-only.
126
- function reachedInProd(importers, nodes, byDir) {
125
+ // What no project's dependencies or optionalDependencies reach, by the edges --prod walks, is dev-only.
126
+ function reachedInProd(importers, nodes, byDir, unwalked) {
127
127
  const reached = new Set(Object.values(importers)
128
128
  .flatMap(({ dependencies, optionalDependencies }) => [...Object.values(dependencies), ...Object.values(optionalDependencies)])
129
129
  .map((target) => nodes.get(target)?.dir)
130
130
  .filter((dir) => byDir.has(dir)))
131
131
  for (const dir of reached) {
132
- for (const child of byDir.get(dir).children.values()) if (byDir.has(child)) reached.add(child)
132
+ const { key, children } = byDir.get(dir)
133
+ const aliases = unwalked.get(key)
134
+ for (const [alias, child] of children) if (byDir.has(child) && !aliases?.has(alias)) reached.add(child)
133
135
  }
134
136
  return reached
135
137
  }
@@ -173,7 +175,7 @@ const COPYING = new Set(['copy', 'clone', 'clone-or-copy'])
173
175
  // The hoisted layout of pnpm 10 and 11 (hoisted.js), each copy a parent before what lands in its
174
176
  // node_modules. `fixes` are what linking bins and the build pass do to the files, read once every
175
177
  // package's are at hand; `builds` what the build pass builds; `checks` hold the lockfile to the whole one.
176
- async function buildHoisted({ lockfile, checks, settings, host, project, installed, manifests, names, patched, skipped, fetching }) {
178
+ async function buildHoisted({ lockfile, checks, settings, host, project, installed, manifests, names, patched, skipped, unwalked, fetching }) {
177
179
  const { major } = host
178
180
  const since = (version) => compareVersions(host.pnpm, version) >= 0
179
181
  if (!COPYING.has(settings.packageImportMethod)) {
@@ -191,7 +193,7 @@ async function buildHoisted({ lockfile, checks, settings, host, project, install
191
193
  if (fetching.sizeEstimateOnly) checkNoneDropped(dropping, host.pnpm)
192
194
  const { byDir, tarballs } = await fetchNodes(placed, checks, project, host, fetching)
193
195
  const linked = readLinked(links, byDir, manifests, project)
194
- const prod = prodPackages(lockfile, skipped, directories)
196
+ const prod = prodPackages(lockfile, skipped, directories, unwalked)
195
197
  const dev = (node) => !prod.has(packageIdOf(node.key, node.pkg, directories))
196
198
  const builds = building ? (node) => node.pkg.patchHash !== undefined || requiresBuild(node.manifest, node.files, major) : undefined
197
199
  const idOf = since('11.23.0') ? (key) => packageIdOf(key, lockfile.packages[key], directories) : (key) => key
@@ -209,14 +211,14 @@ async function buildHoisted({ lockfile, checks, settings, host, project, install
209
211
 
210
212
  // The isolated layout: each package in node_modules/.pnpm, linked from what needs it and where it is
211
213
  // hoisted; `reads` are the packages `fixes` read the files of (binReads)
212
- async function buildIsolated({ lockfile, checks, settings, host, project, installed, manifests, names, skipped, fetching }) {
214
+ async function buildIsolated({ lockfile, checks, settings, host, project, installed, manifests, names, skipped, unwalked, fetching }) {
213
215
  const { major } = host
214
216
  const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength, major)
215
217
  for (const node of nodes.values()) checkSource(node, installed)
216
218
  const { byDir, tarballs } = await fetchNodes(nodes, checks, project, host, fetching)
217
219
  const links = linksOf(byDir, direct, settings, names, major, hoisting)
218
220
  const linked = readLinked(links, byDir, manifests, project)
219
- const prod = reachedInProd(lockfile.importers, nodes, byDir)
221
+ const prod = reachedInProd(lockfile.importers, nodes, byDir, unwalked)
220
222
  const dev = (node) => !prod.has(node.dir)
221
223
  const linking = {
222
224
  nodes: byDir,
@@ -276,10 +278,12 @@ export async function buildPnpmTree(options) {
276
278
  checkOptional(lockfile)
277
279
  const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
278
280
  const skippedOf = (walked) => skippedSnapshots(walked, { host, settings })
279
- const { installing, skipped, incompatible } = production ? productionLockfile(lockfile, { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }, skippedOf) : { installing: lockfile, ...skippedOf(lockfile) }
281
+ const peers = { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }
282
+ const { installing, skipped, incompatible } = production ? productionLockfile(lockfile, peers, skippedOf) : { installing: lockfile, ...skippedOf(lockfile) }
283
+ const unwalked = production ? new Map() : unwalkedEdges(lockfile, peers)
280
284
  const hoisted = settings.nodeLinker === 'hoisted'
281
285
  const checks = { lockfile, hook, fresh, drops }
282
- const { byDir, links, fixes, reads, builds, early, tarballs, dev } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile: installing, checks, settings, host, project, installed, manifests, names, patched, skipped, fetching })
286
+ const { byDir, links, fixes, reads, builds, early, tarballs, dev } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile: installing, checks, settings, host, project, installed, manifests, names, patched, skipped, unwalked, fetching })
283
287
  const laidOut = fetching.sizeEstimateOnly || fetching.lazy
284
288
  const { targets, executable } = laidOut ? { targets: new Map(), executable: new Map() } : fixes()
285
289