@preventive/deptree 1.3.2 → 1.4.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.
Files changed (68) hide show
  1. package/bin/compare.js +5 -2
  2. package/bin/deptree.js +66 -19
  3. package/cocoapods.d.ts +372 -0
  4. package/cocoapods.js +6 -0
  5. package/package.json +24 -6
  6. package/pnpm.d.ts +52 -75
  7. package/soldeer.d.ts +6 -3
  8. package/src/cargo/members.js +3 -2
  9. package/src/cargo/tree.js +2 -2
  10. package/src/cargo/workspace.js +3 -6
  11. package/src/cocoapods/archive.js +223 -0
  12. package/src/cocoapods/clean.js +186 -0
  13. package/src/cocoapods/fnmatch.js +198 -0
  14. package/src/cocoapods/inputs.js +80 -0
  15. package/src/cocoapods/install.js +61 -0
  16. package/src/cocoapods/podspec.js +203 -0
  17. package/src/cocoapods/podtree.js +131 -0
  18. package/src/cocoapods/source.js +90 -0
  19. package/src/cocoapods/tree.js +184 -0
  20. package/src/cocoapods/unicode.js +17 -0
  21. package/src/github.js +92 -0
  22. package/src/glob.js +2 -1
  23. package/src/hash.js +1 -34
  24. package/src/matcher.js +2 -4
  25. package/src/mount.js +3 -6
  26. package/src/npm/compat.js +3 -4
  27. package/src/npm/manifests.js +1 -1
  28. package/src/npm/tree.js +9 -8
  29. package/src/patch.js +9 -5
  30. package/src/pnpm/bins.js +12 -11
  31. package/src/pnpm/commands.js +5 -15
  32. package/src/pnpm/directories.js +250 -0
  33. package/src/pnpm/extensions.js +76 -0
  34. package/src/pnpm/filename.js +4 -4
  35. package/src/pnpm/frozen.js +3 -2
  36. package/src/pnpm/glob.js +1 -1
  37. package/src/pnpm/graph.js +7 -9
  38. package/src/pnpm/hoist.js +0 -36
  39. package/src/pnpm/hoisted.js +3 -3
  40. package/src/pnpm/hook.js +13 -21
  41. package/src/pnpm/inputs.js +7 -16
  42. package/src/pnpm/install.js +3 -4
  43. package/src/pnpm/lazy.js +18 -18
  44. package/src/pnpm/local.js +29 -15
  45. package/src/pnpm/minimatch.js +2 -2
  46. package/src/pnpm/nm-hoist.js +1 -1
  47. package/src/pnpm/npm-packlist.js +1 -1
  48. package/src/pnpm/overrides.js +3 -4
  49. package/src/pnpm/package.js +17 -9
  50. package/src/pnpm/packlist.js +1 -2
  51. package/src/pnpm/patches.js +15 -13
  52. package/src/pnpm/production.js +1 -1
  53. package/src/pnpm/projects.js +14 -40
  54. package/src/pnpm/readers.js +6 -29
  55. package/src/pnpm/settings.js +14 -37
  56. package/src/pnpm/tree.js +34 -24
  57. package/src/pnpm/uptodate.js +12 -13
  58. package/src/pnpm/workspace.js +8 -79
  59. package/src/pnpm/write.js +2 -1
  60. package/src/soldeer/tree.js +2 -2
  61. package/src/soldeer/zip.js +11 -42
  62. package/src/tarball.js +1 -3
  63. package/src/yarn1/hoist.js +4 -2
  64. package/src/yarn1/manifest.js +3 -2
  65. package/src/yarn1/requests.js +1 -1
  66. package/src/yarn1/resolve.js +16 -6
  67. package/src/yarn1/tree.js +12 -8
  68. package/src/soldeer/git.js +0 -67
@@ -1,7 +1,6 @@
1
1
  // The settings an install reads. pnpm 10 reads the .npmrc beside the
2
2
  // lockfile, pnpm-workspace.yaml and the root package.json's `pnpm` field,
3
- // each over the one before; pnpm 9 reads only `packages` and the catalogs of
4
- // pnpm-workspace.yaml, and pnpm 11 and 12 read pnpm-workspace.yaml alone.
3
+ // each over the one before; pnpm 11 and 12 read pnpm-workspace.yaml alone.
5
4
  // Settings from anywhere else (a user or global .npmrc, `npm_config_*`, the
6
5
  // command line) are taken to be at their defaults.
7
6
 
@@ -9,7 +8,7 @@ import { valid, validRange } from '@preventive/upstream/semver.js'
9
8
  import { DeptreeError, quote } from '../error.js'
10
9
  import { parseNpmrc } from '../npmrc.js'
11
10
  import { replaceReferences } from './overrides.js'
12
- import { MANIFEST_KEYS, MANIFEST_KEYS_9, READ, checkRegistry, known12, npmrcReader, readerOf, readers, unrecognized12 } from './readers.js'
11
+ import { MANIFEST_KEYS, READ, checkRegistry, known12, npmrcReader, readerOf, readers, unrecognized12 } from './readers.js'
13
12
 
14
13
  // An .npmrc value can mean one thing only with no quote, escape, `;` or `#`.
15
14
  const PLAIN = /^[^"'`;#\\]*$/u
@@ -62,8 +61,8 @@ function fromNpmrc(text, major) {
62
61
  const earlier = settings.get(name)
63
62
  if (earlier !== undefined && !(list && earlier.list)) throw new DeptreeError('set more than once', where)
64
63
  if (list && read.kind !== 'texts') throw new DeptreeError('not a list', where)
65
- const next = list ? [...(earlier?.value ?? []), plain(value, where)] : plain(value, where)
66
- settings.set(name, { value: next, list, where, read })
64
+ const given = plain(value, where)
65
+ settings.set(name, { value: list ? [...(earlier?.value ?? []), given] : given, list, where, read })
67
66
  }
68
67
  return { settings, environment }
69
68
  }
@@ -72,7 +71,7 @@ function fromNpmrc(text, major) {
72
71
  function fromManifest(manifest, major) {
73
72
  const pnpm = manifest.pnpm === undefined ? {} : readers.mapping(manifest.pnpm, 'package.json: pnpm')
74
73
  const settings = new Map()
75
- for (const name of major < 10 ? MANIFEST_KEYS_9 : MANIFEST_KEYS) {
74
+ for (const name of MANIFEST_KEYS) {
76
75
  if (!Object.hasOwn(pnpm, name) || name === 'overrides') continue
77
76
  const where = `package.json: pnpm.${name}`
78
77
  noEnvironment(pnpm[name], where)
@@ -107,21 +106,11 @@ function fromWorkspace(workspace, major, pinned) {
107
106
  return settings
108
107
  }
109
108
 
110
- // pnpm 9 passes over the rest of pnpm-workspace.yaml unread, a catalog of null
111
- // among it.
112
- function fromWorkspace9(workspace) {
113
- readers.mapping(workspace, 'pnpm-workspace.yaml')
114
- const names = ['packages', 'catalog', 'catalogs'].filter((name) => workspace[name] != null)
115
- return new Map(names.map((name) => [name, { value: workspace[name], where: `pnpm-workspace.yaml: ${name}`, read: READ[name] }]))
116
- }
117
-
118
- const PUBLIC_9 = ['*eslint*', '*prettier*']
119
-
120
109
  // A hoist pattern left undefined is not hoisted to at all. Only on Windows,
121
110
  // which checkHost refuses, is virtualStoreDirMaxLength 60 by default.
122
- function derive(get, major) {
111
+ function derive(get) {
123
112
  const shamefullyHoist = get('shamefullyHoist')
124
- let publicHoistPattern = get('publicHoistPattern') ?? (major < 10 ? PUBLIC_9 : [])
113
+ let publicHoistPattern = get('publicHoistPattern') ?? []
125
114
  if (shamefullyHoist === true) publicHoistPattern = ['*']
126
115
  else if (shamefullyHoist === false || (publicHoistPattern.length === 1 && publicHoistPattern[0] === '')) publicHoistPattern = undefined
127
116
  return {
@@ -148,24 +137,15 @@ function derive(get, major) {
148
137
  runtimeOnFail: get('runtimeOnFail'),
149
138
  packageImportMethod: get('packageImportMethod') ?? 'auto',
150
139
  nodeLinker: get('nodeLinker') ?? 'isolated',
151
- ...major < 10 ? {
152
- packageManagerChecks: {
153
- manage: get('managePackageManagerVersions') ?? false,
154
- strict: get('packageManagerStrict') ?? true,
155
- strictVersion: get('packageManagerStrictVersion') ?? false,
156
- },
157
- } : {},
158
140
  }
159
141
  }
160
142
 
161
143
  function catalogsOf(catalog, catalogs = {}) {
162
- if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) {
163
- throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
164
- }
144
+ if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
165
145
  return Object.assign(Object.create(null), catalog === undefined ? {} : { default: catalog }, catalogs)
166
146
  }
167
147
 
168
- function settle(layers, manifest, major) {
148
+ function settle(layers, manifest) {
169
149
  const values = new Map()
170
150
  for (const layer of layers) {
171
151
  for (const [name, { value, where, read: { kind, check } }] of layer) {
@@ -178,25 +158,22 @@ function settle(layers, manifest, major) {
178
158
  values.set(name, read)
179
159
  }
180
160
  }
181
- return derive((name) => values.get(name), major)
161
+ return derive((name) => values.get(name))
182
162
  }
183
163
 
184
164
  // Overrides that name nothing are none, and leave those below them.
185
165
  export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
186
- const fromYaml = () => {
187
- if (workspace === undefined) return new Map()
188
- return major < 10 ? fromWorkspace9(workspace) : fromWorkspace(workspace, major, pinned)
189
- }
166
+ const fromYaml = () => (workspace === undefined ? new Map() : fromWorkspace(workspace, major, pinned))
190
167
  if (major >= 11) {
191
168
  if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
192
- const settings = settle([fromYaml()], manifest, major)
169
+ const settings = settle([fromYaml()], manifest)
193
170
  settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
194
171
  return settings
195
172
  }
196
173
  const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc, major)
197
174
  const rest = [fromYaml(), fromManifest(manifest, major)]
198
- const settings = settle([rc.settings, ...rest], manifest, major)
199
- if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest, major))) {
175
+ const settings = settle([rc.settings, ...rest], manifest)
176
+ if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest))) {
200
177
  throw new DeptreeError('a line takes a value from the environment, which pnpm drops the whole file for where it is unset, and the file sets what would change the tree', '.npmrc')
201
178
  }
202
179
  return settings
package/src/pnpm/tree.js CHANGED
@@ -1,4 +1,4 @@
1
- // The node_modules tree pnpm 9, 10, 11 or 12 installs from a frozen lockfile
1
+ // The node_modules tree pnpm 10, 11 or 12 installs from a frozen lockfile
2
2
  // with the isolated linker and --ignore-scripts, in a Vfs rooted at the
3
3
  // lockfile's directory; patched still, as pnpm patches before scripts. Bins are
4
4
  // not linked, though what linking does to their files is (bins.js). With
@@ -25,8 +25,10 @@ import { checkNoneDropped, hoistedBuilds, hoistedLayout, hoistedModules, mayDrop
25
25
  import { checkLocalOverrides, createFreshnessCheck, readDirectoryPackage, readLinked } from './local.js'
26
26
  import { createPatchedCheck, skippedSnapshots } from './install.js'
27
27
  import { lazyUnpacker } from './lazy.js'
28
- import { checkFetched, fetchPackage } from './package.js'
28
+ import { checkFetched, createPeerDrop, fetchPackage } from './package.js'
29
29
  import { checkLinks, checkOptional } from './checks.js'
30
+ import { createDirectoryCheck } from './directories.js'
31
+ import { listExtensions } from './extensions.js'
30
32
  import { createHook } from './hook.js'
31
33
  import { productionLockfile } from './production.js'
32
34
  import { listOverrides } from './overrides.js'
@@ -89,25 +91,27 @@ async function fetchAll(nodes, project, host, fetching) {
89
91
  return fetching.sizeEstimateOnly ? { ...got, size: bytesOf(got.files) } : got
90
92
  }
91
93
  await eachConcurrently(packages, async ([id, pkg]) => {
92
- if (pkg.resolution.type === 'directory') fetched.set(id, read(pkg, quote(id)))
93
- else if (!fetching.lazy) fetched.set(id, await fetch(pkg, quote(id)))
94
+ if (pkg.resolution.type === 'directory') {
95
+ fetched.set(id, read(pkg, quote(id)))
96
+ } else if (!fetching.lazy) {
97
+ fetched.set(id, await fetch(pkg, quote(id)))
98
+ }
94
99
  }, ([id]) => quote(id))
95
100
  return fetched
96
101
  }
97
102
 
98
103
  // With `lazy`, a registry package's snapshots have no files yet, and are held
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) {
104
+ // to them as each is unpacked; `checks` are what that takes, of the whole
105
+ // lockfile.
106
+ async function fetchNodes(nodes, checks, project, host, fetching) {
102
107
  const fetched = await fetchAll(nodes, project, host, fetching)
103
- const checks = { lockfile: checked, hook, fresh: createFreshnessCheck(checked, host.major) }
104
108
  const byDir = new Map()
105
109
  for (const node of nodes.values()) {
106
110
  const got = fetched.get(packageKeyOf(node.key))
107
111
  if (got !== undefined) checkFetched(node, got, checks)
108
112
  byDir.set(node.dir, { ...node, files: got?.files, manifest: got?.manifest, about: got?.about ?? NO_ABOUT, size: got?.size })
109
113
  }
110
- return { byDir, tarballs: [...fetched.values()].filter((got) => !got.local).length, checks }
114
+ return { byDir, tarballs: [...fetched.values()].filter((got) => !got.local).length }
111
115
  }
112
116
 
113
117
  // pnpm hardlinks a directory package's files into each of its snapshots, so a
@@ -188,8 +192,8 @@ const COPYING = new Set(['copy', 'clone', 'clone-or-copy'])
188
192
  // followed, nor with `lazy` but where a package unpacked needs them. `builds`
189
193
  // tells, where any patch is configured, what the build pass builds; `reads`
190
194
  // 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 }) {
195
+ // the one the tree is laid out from, and `checks` hold it to the whole one.
196
+ async function buildHoisted({ lockfile, checks, settings, host, project, installed, manifests, names, patched, skipped, fetching }) {
193
197
  const { major } = host
194
198
  const since = (version) => compareVersions(host.pnpm, version) >= 0
195
199
  if (!COPYING.has(settings.packageImportMethod)) {
@@ -205,7 +209,7 @@ async function buildHoisted({ lockfile, checked, settings, host, project, hook,
205
209
  const keepsModules = since('11.25.0')
206
210
  const dropping = building && hardlinks && !keepsModules ? mayDrop(placed) : new Map()
207
211
  if (fetching.sizeEstimateOnly) checkNoneDropped(dropping, host.pnpm)
208
- const { byDir, tarballs, checks } = await fetchNodes(placed, checked, hook, project, host, fetching)
212
+ const { byDir, tarballs } = await fetchNodes(placed, checks, project, host, fetching)
209
213
  const linked = readLinked(links, byDir, manifests, project)
210
214
  const prod = prodPackages(lockfile, skipped, directories)
211
215
  const dev = (node) => !prod.has(packageIdOf(node.key, node.pkg, directories))
@@ -220,17 +224,17 @@ async function buildHoisted({ lockfile, checked, settings, host, project, hook,
220
224
  }
221
225
  // With lazy, those that may drop a node_modules are fetched with the tree.
222
226
  const early = dropping.size === 0 ? undefined : { nodes: [...byDir.values()].filter((node) => dropping.has(node.key)), check: () => builtOf((node) => dropping.has(node.key) && builds(node)) }
223
- return { byDir, links, fixes, reads: () => hoistedBinReads({ nodes: byDir, building, packages: lockfile.packages }), builds, early, tarballs, dev, checks }
227
+ return { byDir, links, fixes, reads: () => hoistedBinReads({ nodes: byDir, building, packages: lockfile.packages }), builds, early, tarballs, dev }
224
228
  }
225
229
 
226
230
  // The isolated layout: each package in node_modules/.pnpm, linked from what
227
231
  // needs it and where it is hoisted; `fixes` as buildHoisted's, and `reads`
228
232
  // the packages they read the files of (binReads).
229
- async function buildIsolated({ lockfile, checked, settings, host, project, hook, installed, manifests, names, skipped, fetching }) {
233
+ async function buildIsolated({ lockfile, checks, settings, host, project, installed, manifests, names, skipped, fetching }) {
230
234
  const { major } = host
231
235
  const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength, major)
232
236
  for (const node of nodes.values()) checkSource(node, installed)
233
- const { byDir, tarballs, checks } = await fetchNodes(nodes, checked, hook, project, host, fetching)
237
+ const { byDir, tarballs } = await fetchNodes(nodes, checks, project, host, fetching)
234
238
  const links = linksOf(byDir, direct, settings, names, major, hoisting)
235
239
  const linked = readLinked(links, byDir, manifests, project)
236
240
  const prod = reachedInProd(lockfile.importers, nodes, byDir)
@@ -249,14 +253,15 @@ async function buildIsolated({ lockfile, checked, settings, host, project, hook,
249
253
  const targets = binTargets(linking)
250
254
  return { targets, executable: executableElsewhere(byDir, targets, settings.packageImportMethod, major) }
251
255
  }
252
- return { byDir, links, fixes, reads: () => binReads(linking), tarballs, dev, checks }
256
+ return { byDir, links, fixes, reads: () => binReads(linking), tarballs, dev }
253
257
  }
254
258
 
255
259
  export async function buildPnpmTree(options) {
256
- const { project, host: given, vfs: into } = options ?? {}
260
+ const opts = options ?? {}
261
+ const { project, host: given, vfs: into } = opts
257
262
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
258
- const fetching = fetchingOf(options ?? {}, into)
259
- const production = productionOf(options ?? {})
263
+ const fetching = fetchingOf(opts, into)
264
+ const production = productionOf(opts)
260
265
  if (project !== undefined) checkProject(project)
261
266
  const machine = checkHost(given)
262
267
  const folded = machine.os === 'darwin'
@@ -275,22 +280,27 @@ export async function buildPnpmTree(options) {
275
280
  // pins, which leaves the tree as it is.
276
281
  if (env !== undefined && major < 11) throw new DeptreeError('the env document pnpm 11 writes is not supported', 'env')
277
282
  if (env !== undefined && Object.keys(env.importers['.'].configDependencies).length > 0) throw new DeptreeError('config dependencies are not supported', 'env.importers["."].configDependencies')
278
- // As pnpm 9, 10 and 11 write the lockfile's own directory.
283
+ // As pnpm 10 and 11 write the lockfile's own directory.
279
284
  const empty = major >= 12 ? Object.keys(lockfile.packages).find((key) => packageKeyOf(key).endsWith('@file:')) : undefined
280
285
  if (empty !== undefined) throw new DeptreeError('pnpm 12 refuses as broken a lockfile with `file:` and an empty path', quote(empty))
281
286
  const settings = readSettings({ workspace, npmrc: inputs.npmrc, manifest: manifests.get('.'), major, pinned: pinsPnpm(manifests.get('.'), host.pnpm) })
282
287
  checkWorkspace(Object.keys(lockfile.importers), settings.packages, major)
283
288
  const overrides = listOverrides(settings.overrides, settings.catalogs, major)
289
+ const extensions = listExtensions(settings.packageExtensions, major)
284
290
  const installed = checkLocalOverrides(overrides, project)
285
- const patched = await checkUpToDate(lockfile, settings, overrides, patchesOf(inputs, settings.patchedDependencies), major)
286
- const hook = createHook({ overrides, ignored: settings.ignoredOptionalDependencies, major })
287
- checkProjects(lockfile, manifests, { hook, host, settings, env })
291
+ const patched = await checkUpToDate(lockfile, settings, { overrides, extensions }, patchesOf(inputs, settings.patchedDependencies), major)
292
+ const hook = createHook({ overrides, extensions, ignored: settings.ignoredOptionalDependencies, major })
293
+ const fresh = createFreshnessCheck(lockfile, host, extensions, settings.autoInstallPeers)
294
+ const drops = createPeerDrop(host, settings.autoInstallPeers)
295
+ const directories = createDirectoryCheck(lockfile, { host, hook, project, installed, settings, fresh, drops })
296
+ checkProjects(lockfile, manifests, { hook, extensions, host, settings, env, directories })
288
297
  checkOptional(lockfile)
289
298
  const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
290
299
  const { walked, installing } = production ? productionLockfile(lockfile, { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }) : { walked: lockfile, installing: lockfile }
291
300
  const { skipped, incompatible } = skippedSnapshots(walked, { host, settings })
292
301
  const hoisted = settings.nodeLinker === 'hoisted'
293
- 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 })
302
+ const checks = { lockfile, hook, fresh, drops }
303
+ 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 })
294
304
  const laidOut = fetching.sizeEstimateOnly || fetching.lazy
295
305
  const { targets, executable } = laidOut ? { targets: new Map(), executable: new Map() } : fixes()
296
306
 
@@ -1,11 +1,11 @@
1
1
  // Refuses a lockfile a frozen install would refuse as out of date with the
2
2
  // settings (@pnpm/lockfile.settings-checker's getOutdatedLockfileSetting),
3
- // naming the setting as pnpm names it. pnpm 9 holds the lockfile to neither the
4
- // catalogs nor dedupePeers.
3
+ // naming the setting as pnpm names it.
5
4
 
6
5
  import { normalize } from '@preventive/vfs/path.js'
7
6
  import { DeptreeError, difference, quote } from '../error.js'
8
- import { md5Base32, sha256Hex } from '../hash.js'
7
+ import { sha256Hex } from '../hash.js'
8
+ import { extensionsChecksum } from './extensions.js'
9
9
  import { sameSpecifier } from './frozen.js'
10
10
  import { catalogEntry } from './overrides.js'
11
11
  import { checkPatchUse, checkPeerPatches } from './patches.js'
@@ -15,7 +15,7 @@ const outdated = (name, detail) => new DeptreeError(`${detail}, which a frozen i
15
15
  const SIDES = ['the lockfile', 'the settings']
16
16
 
17
17
  // `hashes` is { hash, path } by selector, `byHash` { text, path } by hash.
18
- async function hashPatches(configured, given, major) {
18
+ async function hashPatches(configured, given) {
19
19
  const texts = new Map()
20
20
  for (const [key, text] of given) {
21
21
  const path = normalize(key)
@@ -32,7 +32,7 @@ async function hashPatches(configured, given, major) {
32
32
  const text = texts.get(path)
33
33
  const normalized = text.replaceAll('\r\n', '\n')
34
34
  const where = `patches[${quote(path)}]`
35
- const hash = major < 10 ? md5Base32(normalized, where) : await sha256Hex(normalized, where)
35
+ const hash = await sha256Hex(normalized, where)
36
36
  hashes[selector] = { hash, path }
37
37
  if (!byHash.has(hash)) byHash.set(hash, { text, path })
38
38
  }
@@ -49,9 +49,9 @@ function checkPatches(locked, hashes, major) {
49
49
  if (detail !== undefined) throw outdated('patchedDependencies', `the patches differ: ${detail}`)
50
50
  }
51
51
 
52
- export async function checkUpToDate(lockfile, settings, overrides, given, major) {
53
- const { hashes, byHash } = await hashPatches(settings.patchedDependencies, given, major)
54
- for (const [name, catalog] of major < 10 ? [] : Object.entries(lockfile.catalogs)) {
52
+ export async function checkUpToDate(lockfile, settings, { overrides, extensions }, given, major) {
53
+ const { hashes, byHash } = await hashPatches(settings.patchedDependencies, given)
54
+ for (const [name, catalog] of Object.entries(lockfile.catalogs)) {
55
55
  for (const [alias, { specifier }] of Object.entries(catalog)) {
56
56
  const configured = catalogEntry(settings.catalogs, name, alias)
57
57
  if (!sameSpecifier(specifier, configured, major)) throw outdated('catalogs', `${quote(alias)} is ${quote(specifier)} in the lockfile's catalog ${quote(name)}, and ${configured === undefined ? 'nothing' : quote(configured)} in the settings`)
@@ -59,17 +59,16 @@ export async function checkUpToDate(lockfile, settings, overrides, given, major)
59
59
  }
60
60
  const overridden = difference(lockfile.overrides, Object.fromEntries(overrides.map(({ selector, spec }) => [selector, spec])), SIDES)
61
61
  if (overridden !== undefined) throw outdated('overrides', `the overrides differ: ${overridden}`)
62
- // pnpm checksums them with object-hash, which is not reproduced here.
63
- if (settings.packageExtensions !== undefined && Object.keys(settings.packageExtensions).length > 0) throw new DeptreeError('package extensions are not supported: their checksum cannot be checked against the lockfile\'s here', 'packageExtensions')
64
- if (lockfile.packageExtensionsChecksum !== undefined) throw outdated('packageExtensionsChecksum', 'the lockfile was resolved with package extensions, and the settings have none')
62
+ const extended = await extensionsChecksum(extensions, major)
63
+ if (lockfile.packageExtensionsChecksum !== extended) throw outdated('packageExtensionsChecksum', extended === undefined ? 'the lockfile was resolved with package extensions, and the settings have none' : 'the package extensions in the settings are not those the lockfile was resolved with')
65
64
  const ignored = (list) => JSON.stringify([...list].sort())
66
65
  if (ignored(lockfile.ignoredOptionalDependencies) !== ignored(settings.ignoredOptionalDependencies)) throw outdated('ignoredOptionalDependencies', 'the optional dependencies left out differ')
67
66
  checkPatches(lockfile.patchedDependencies, hashes, major)
68
67
  const locked = lockfile.settings
69
68
  if (locked.autoInstallPeers !== undefined && locked.autoInstallPeers !== settings.autoInstallPeers) throw outdated('settings.autoInstallPeers', `autoInstallPeers is ${locked.autoInstallPeers} in the lockfile`)
70
- if (major >= 10 && Boolean(locked.dedupePeers) !== settings.dedupePeers) throw outdated('settings.dedupePeers', `dedupePeers is ${Boolean(locked.dedupePeers)} in the lockfile`)
69
+ if (Boolean(locked.dedupePeers) !== settings.dedupePeers) throw outdated('settings.dedupePeers', `dedupePeers is ${Boolean(locked.dedupePeers)} in the lockfile`)
71
70
  if ((locked.peersSuffixMaxLength ?? 1000) !== settings.peersSuffixMaxLength) throw outdated('settings.peersSuffixMaxLength', `peersSuffixMaxLength is ${locked.peersSuffixMaxLength ?? 'left at 1000'} in the lockfile`)
72
- checkPatchUse(lockfile, hashes, major)
71
+ checkPatchUse(lockfile, hashes)
73
72
  if (major >= 11) checkPeerPatches(lockfile, hashes)
74
73
  return byHash
75
74
  }
@@ -1,6 +1,6 @@
1
1
  // The directories pnpm takes for a workspace's projects: the root, and each
2
2
  // whose package.json a glob of pnpm-workspace.yaml's `packages` takes, as
3
- // @pnpm/fs.find-packages globs for them with tinyglobby (pnpm 9: fast-glob), or
3
+ // @pnpm/fs.find-packages globs for them with tinyglobby, or
4
4
  // as pnpm 12 walks (wax). pnpm 11 matches `!` globs with micromatch, dotted
5
5
  // names and all.
6
6
 
@@ -47,7 +47,6 @@ function enters({ names: glob, dot }, names) {
47
47
  // find-packages ignores; pnpm 12 drops it whatever the globs say. `wild` is
48
48
  // whether a glob with a `*` takes it (manifestOf).
49
49
  function compileAll(packages, major) {
50
- if (major < 10) return compile9(packages)
51
50
  const twelve = major >= 12
52
51
  const [enters_, ignored_, dropped] = twelve ? [enters12, underLeftOut, underLeftOut] : [enters, ignored, () => false]
53
52
  const include = []
@@ -61,78 +60,15 @@ function compileAll(packages, major) {
61
60
  walked: (names) => include.some((glob) => enters_(glob, names)) && !ignored_(names),
62
61
  taken: takenBy(include, exclude, dropped),
63
62
  wild: (names) => include.some((glob) => glob.wild && takes(glob, names)),
64
- manifests: MANIFESTS,
65
- through: [],
66
63
  }
67
64
  }
68
65
 
69
66
  const takenBy = (include, exclude, dropped) => (names) => include.some((glob) => takes(glob, names)) && !exclude.some((glob) => takes(glob, names)) && !dropped(names)
70
67
 
71
- const startsWith = (names, start) => start.length <= names.length && start.every((name, i) => names[i] === name)
72
-
73
- // fast-glob's partial matcher: past the names before its first `**`, any.
74
- function partial({ names: glob, raw }, names) {
75
- const star = raw.indexOf('**')
76
- if (star === -1 && glob.length <= names.length) return false
77
- if (star !== -1 && names.length > star) return true
78
- return names.every((name, i) => glob[i].test(name))
79
- }
80
-
81
- const isDynamic = (glob) => glob.raw.some((name) => name.includes('*'))
82
-
83
- // pnpm 9 globs with fast-glob 3: a glob with no `*` it looks up where it
84
- // leads, and one with a `*` it walks for from the names before that
85
- // (`base`), from the top for all of them where one has none there. Under
86
- // a base it walks into every directory its globs may reach (`partial`),
87
- // those with a leading dot among them, but where the ignore globs take it
88
- // with `**` taking no leading dot, or where a `!` glob takes it whole;
89
- // and takes a manifest a glob takes and no `!` glob, nor an ignore glob,
90
- // with `**` and `*` taking leading dots. It reads every manifest a
91
- // directory has, so one but package.json is the one refused (MANIFESTS_9),
92
- // and fails on a glob that leads through a file (`through`).
93
- function compile9(packages) {
94
- const where = 'pnpm-workspace.yaml: packages'
95
- const include = []
96
- const exclude = []
97
- const excludeWhole = []
98
- for (const glob of packages ?? []) {
99
- if (glob.startsWith('!')) {
100
- exclude.push(compile(glob.slice(1), where, true))
101
- excludeWhole.push(compile(glob.slice(1), where, false))
102
- } else include.push(compile(glob, where, false))
103
- }
104
- const dynamic = include.filter(isDynamic)
105
- const baseOf = (glob) => glob.raw.slice(0, glob.raw.findIndex((name) => name.includes('*')))
106
- const groups = Map.groupBy(dynamic, (glob) => baseOf(glob).join('/'))
107
- const tasks = groups.has('') ? [{ base: [], globs: dynamic }] : [...groups.values()].map((globs) => ({ base: baseOf(globs[0]), globs }))
108
- const skipped = (names) => ignored(names) || (MANIFESTS.includes(names.at(-1)) && excludeWhole.some((glob) => takes(glob, [...names.slice(0, -1), 'package.json'])))
109
- // A task walks into a directory only where it walked into its parent; each
110
- // answer is kept for the walk.
111
- const reacher = ({ base, globs }) => {
112
- const known = new Map()
113
- const reaches = (names) => {
114
- if (names.length <= base.length) return names.length === base.length && startsWith(names, base)
115
- const key = names.join('/')
116
- if (!known.has(key)) known.set(key, reaches(names.slice(0, -1)) && globs.some((glob) => partial(glob, names)) && !skipped(names))
117
- return known.get(key)
118
- }
119
- return reaches
120
- }
121
- const reachers = tasks.map(reacher)
122
- const through = [...tasks.map((task) => task.base), ...include.filter((glob) => !isDynamic(glob)).map((glob) => glob.raw.slice(0, -1))]
123
- return {
124
- walked: (names) => through.some((path) => startsWith(path, names)) || reachers.some((reaches) => reaches(names)),
125
- taken: takenBy(include, exclude, underLeftOut),
126
- wild: () => false,
127
- manifests: MANIFESTS_9,
128
- through,
129
- }
130
- }
131
-
132
- // The first of `globs.manifests` that is a file; pnpm 12 reads the first there
68
+ // The first of MANIFESTS that is a file; pnpm 12 reads the first there
133
69
  // where a `wild` glob takes the directory, failing where it is not a file.
134
70
  function manifestOf(project, globs, names, entries) {
135
- for (const name of globs.manifests) {
71
+ for (const name of MANIFESTS) {
136
72
  if (!entries.includes(name)) continue
137
73
  const type = typeOf(project, `/${[...names, name].join('/')}`)
138
74
  if (type === 'file') return name
@@ -150,8 +86,8 @@ function byNames(a, b) {
150
86
  }
151
87
 
152
88
  // find-packages leaves out what is under these, by globs whose `**`, as
153
- // tinyglobby reads them, takes no name with a leading dot; as fast-glob
154
- // reads them for a manifest, any (underLeftOut).
89
+ // tinyglobby reads them, takes no name with a leading dot; pnpm 12 drops
90
+ // whatever is under them (underLeftOut).
155
91
  const LEFT_OUT = ['node_modules', 'bower_components']
156
92
  const IGNORED = LEFT_OUT.map((name) => ({ names: ['**', compileName(name, false), '**'], dot: false }))
157
93
  const ignored = (names) => IGNORED.some((glob) => takes(glob, names))
@@ -181,20 +117,14 @@ export function checkProjectId(id, where) {
181
117
 
182
118
  export const linkedManifest = (file) => new DeptreeError('a link pnpm would read a project\'s manifest through is not supported', quote(file))
183
119
 
184
- // pnpm reads the first of these a project has; pnpm 9 each, so one but
185
- // package.json is named first.
120
+ // pnpm reads the first of these a project has.
186
121
  const MANIFESTS = ['package.json', 'package.json5', 'package.yaml']
187
- const MANIFESTS_9 = ['package.json5', 'package.yaml', 'package.json']
188
122
 
189
123
  // Every directory tinyglobby walks into is read, and no other. It walks into
190
124
  // a node_modules only under a directory with a leading dot, which is
191
125
  // refused, as what is installed there is no project buildPnpmTree builds.
192
126
  export function findProjects(project, packages, major = 10) {
193
127
  const globs = compileAll(packages, major)
194
- for (const path of globs.through) {
195
- const end = path.findIndex((_, i) => typeOf(project, `/${path.slice(0, i + 1).join('/')}`) === 'file')
196
- if (end !== -1) throw new DeptreeError('a glob leads through this file, which pnpm 9 fails on', quote(path.slice(0, end + 1).join('/')))
197
- }
198
128
  const ids = []
199
129
  const pending = [{ names: [] }]
200
130
  while (pending.length > 0) {
@@ -221,9 +151,8 @@ export function findProjects(project, packages, major = 10) {
221
151
  const linked = type === 'symlink' && typeOf(project, `/${path}`) === 'directory'
222
152
  if (type !== 'directory' && !linked) continue
223
153
  if (entry === 'node_modules') throw new DeptreeError('pnpm-workspace.yaml\'s packages walk into this node_modules, which is not supported', quote(path))
224
- if (!linked) pending.push({ names: at, link })
225
- else if (link === undefined) pending.push({ names: at, link: path })
226
- else throw new DeptreeError(`a link to a directory in one tinyglobby follows, ${quote(path)}, is not supported`, quote(link))
154
+ if (linked && link !== undefined) throw new DeptreeError(`a link to a directory in one tinyglobby follows, ${quote(path)}, is not supported`, quote(link))
155
+ pending.push({ names: at, link: linked ? path : link })
227
156
  }
228
157
  }
229
158
  return ['.', ...major >= 12 ? ids.sort(byNames) : ids.sort()]
package/src/pnpm/write.js CHANGED
@@ -62,7 +62,8 @@ export function writeNode(vfs, dir, files, stats) {
62
62
  makeDirs(vfs, parent.slice(1), real)
63
63
  addMade(made, parent)
64
64
  }
65
- vfs.writeFile(checkWrite(vfs, dir, path, real), file.data, { mode: file.mode })
65
+ // A package's bytes are handed over, not copied: nothing writes into them after (vfs's `adopt`).
66
+ vfs.writeFile(checkWrite(vfs, dir, path, real), file.data, { mode: file.mode, adopt: true })
66
67
  stats.files++
67
68
  stats.bytes += file.data.length
68
69
  }
@@ -8,7 +8,7 @@ import { eachConcurrently } from '../concurrent.js'
8
8
  import { DeptreeError, quote } from '../error.js'
9
9
  import { checkNoDir, fold, makeDirs, mount, writeFiles } from '../mount.js'
10
10
  import { configOf } from './config.js'
11
- import { checkoutOf, githubRepoOf } from './git.js'
11
+ import { checkoutOf, githubRepoOf } from '../github.js'
12
12
  import { checkHost, inputsOf } from './inputs.js'
13
13
  import { extractZip } from './zip.js'
14
14
 
@@ -62,7 +62,7 @@ async function fetchAll(dependencies, github) {
62
62
  export async function buildSoldeerTree(options) {
63
63
  const { host: given, vfs: into, github } = options ?? {}
64
64
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
65
- if (github !== undefined && (typeof github?.getRepoTarball !== 'function' || typeof github.getRepo !== 'function')) throw new TypeError(GITHUB)
65
+ if (github !== undefined && ['getCommitTree', 'getRepoTreeTarball', 'getRepo'].some((method) => typeof github?.[method] !== 'function')) throw new TypeError(GITHUB)
66
66
  const inputs = inputsOf(options ?? {})
67
67
  const folded = checkHost(given).os === 'darwin'
68
68
  // Refused before anything is fetched; mount checks again.
@@ -4,61 +4,32 @@
4
4
  // every directory is 0o755, and a file's mode its Unix mode as the zip crate
5
5
  // reads it, or 0o644 where it reads none; a symlink is a file of its target.
6
6
 
7
- import { utf8fromStringLoose, utf8toStringLoose } from '@exodus/bytes/utf8.js'
7
+ import { utf8fromStringLoose } from '@exodus/bytes/utf8.js'
8
8
  import { ArchiveError, unzip } from '@preventive/archive/zip.js'
9
9
  import { DeptreeError, quote } from '../error.js'
10
10
  import { bytesSha256Hex } from '../hash.js'
11
11
  import { MAX_BYTES } from '../tarball.js'
12
12
 
13
- const END = 0x06054b50
14
- const CENTRAL = 0x02014b50
15
13
  const UTF8 = 0x0800
14
+ const NON_ASCII = /[^\u0020-\u007E]/u
16
15
  const S_IFLNK = 0o120000
17
16
  const [NTFS, TIMESTAMP, UNICODE_COMMENT, AES] = [0x000a, 0x5455, 0x6375, 0x9901]
18
17
 
19
- // As the archive reader decodes a name: a leading U+FEFF is part of it.
20
-
21
18
  const ones = (byte) => [...byte.toString(2)].filter((bit) => bit === '1').length
22
19
 
23
20
  // Why the zip crate would fail on an entry's extra fields, or undefined; an
24
21
  // AES or a Unicode comment field is refused here.
25
- function extraRefusal(view, at, length) {
26
- for (let pos = at; pos < at + length;) {
27
- const id = view.getUint16(pos, true)
28
- const size = view.getUint16(pos + 2, true)
29
- const body = pos + 4
30
- if (id === NTFS && (size !== 32 || view.getUint16(body + 4, true) !== 1 || view.getUint16(body + 6, true) !== 24)) return 'an NTFS extra field the zip crate does not read'
31
- if (id === TIMESTAMP && (size === 0 || (size !== 5 && size !== 1 + 4 * ones(view.getUint8(body))))) return 'an extended timestamp the zip crate does not read'
22
+ function extraRefusal(extra) {
23
+ for (const { id, data } of extra) {
24
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength)
25
+ if (id === NTFS && (data.length !== 32 || view.getUint16(4, true) !== 1 || view.getUint16(6, true) !== 24)) return 'an NTFS extra field the zip crate does not read'
26
+ if (id === TIMESTAMP && (data.length === 0 || (data.length !== 5 && data.length !== 1 + 4 * ones(data[0])))) return 'an extended timestamp the zip crate does not read'
32
27
  if (id === AES) return 'an AES extra field, which has the zip crate decrypt the entry'
33
28
  if (id === UNICODE_COMMENT) return 'a Unicode comment extra field, which the zip crate checks'
34
- pos = body + size
35
29
  }
36
30
  return undefined
37
31
  }
38
32
 
39
- // What the zip crate reads of each entry that unzip does not hand out. unzip
40
- // has checked the layout whole, so each record is where it says.
41
- function centralRecords(bytes) {
42
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
43
- let end = bytes.length - 22
44
- while (view.getUint32(end, true) !== END || end + 22 + view.getUint16(end + 20, true) !== bytes.length) end--
45
- const records = []
46
- let at = view.getUint32(end + 16, true)
47
- for (let i = 0; i < view.getUint16(end + 10, true); i++) {
48
- if (view.getUint32(at, true) !== CENTRAL) throw new Error('unreachable: a central record where unzip found none')
49
- const [nameLength, extraLength, commentLength] = [at + 28, at + 30, at + 32].map((field) => view.getUint16(field, true))
50
- records.push({
51
- system: view.getUint8(at + 5),
52
- flags: view.getUint16(at + 8, true),
53
- attributes: view.getUint32(at + 38, true),
54
- name: bytes.subarray(at + 46, at + 46 + nameLength),
55
- extra: extraRefusal(view, at + 46 + nameLength, extraLength),
56
- })
57
- at += 46 + nameLength + extraLength + commentLength
58
- }
59
- return records
60
- }
61
-
62
33
  // The zip crate's ZipFileData::unix_mode; system 0 is MS-DOS, and 3 Unix.
63
34
  function unixMode({ system, attributes }) {
64
35
  if (attributes === 0) return undefined
@@ -86,16 +57,14 @@ export async function extractZip(bytes, checksum, where) {
86
57
  if (error instanceof ArchiveError) throw new DeptreeError(`its zip cannot be read: ${error.message}`, where, { cause: error })
87
58
  throw error
88
59
  }
89
- const records = centralRecords(bytes)
90
60
  // The zip crate keys entries by their names' bytes, here the stored names:
91
61
  // of two of one name, the later is extracted where the first was.
92
62
  const last = new Map()
93
63
  for (const [index, entry] of entries.entries()) {
94
- const record = records[index]
95
- if (utf8toStringLoose(record.name) !== entry.storedName) throw new Error('unreachable: unzip lists entries out of the central directory\'s order')
96
64
  const here = `${where}: ${quote(entry.storedName)}`
97
- if (record.extra !== undefined) throw new DeptreeError(`${record.extra}, which Soldeer fails on`, here)
98
- if (!(record.flags & UTF8) && record.name.some((byte) => byte >= 0x80)) throw new DeptreeError('a name not flagged UTF-8, which Soldeer reads as CP437, is not supported', here)
65
+ const refusal = extraRefusal(entry.extra)
66
+ if (refusal !== undefined) throw new DeptreeError(`${refusal}, which Soldeer fails on`, here)
67
+ if (!(entry.flags & UTF8) && NON_ASCII.test(entry.storedName)) throw new DeptreeError('a name not flagged UTF-8, which Soldeer reads as CP437, is not supported', here)
99
68
  last.set(entry.storedName, index)
100
69
  }
101
70
  const dirs = new Set()
@@ -111,7 +80,7 @@ export async function extractZip(bytes, checksum, where) {
111
80
  dirs.add(entry.name)
112
81
  continue
113
82
  }
114
- const mode = unixMode(records[index])
83
+ const mode = unixMode(entry)
115
84
  const data = entry.type === 'symlink' ? utf8fromStringLoose(entry.linkname) : entry.data
116
85
  // A file written again keeps its mode where the zip crate reads none.
117
86
  const kept = mode === undefined || (mode & S_IFLNK) === S_IFLNK ? files.get(entry.name)?.mode ?? 0o644 : mode & 0o777 & ~0o022
package/src/tarball.js CHANGED
@@ -123,9 +123,7 @@ export async function fetchTarball(name, version, given, where, { metadata, cach
123
123
  const integrity = given ?? meta.dist.integrity
124
124
  if (!SHA512.test(integrity)) throw new DeptreeError('a tarball with no sha512 integrity is not supported', where)
125
125
  const dist = { tarball: tarballUrl(name, version), integrity }
126
- let about = NO_ABOUT
127
- if (meta !== undefined) about = aboutOf(meta)
128
- else if (metadata) about = getMeta(name, version, { dist, cache }).then(aboutOf)
126
+ const about = meta === undefined ? (metadata ? getMeta(name, version, { dist, cache }).then(aboutOf) : NO_ABOUT) : aboutOf(meta)
129
127
  const [bytes, said] = await settled([getTarball(name, version, dist, { cache }), about])
130
128
  if (!await matchesIntegrity(bytes, integrity)) throw new DeptreeError(`the tarball is not ${integrity}`, where)
131
129
  if (bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the tarball is not gzipped', where)
@@ -63,7 +63,9 @@ export class Hoister {
63
63
  sorted.push(item)
64
64
  available.add(pattern)
65
65
  changed = true
66
- } else queue.push(item)
66
+ } else {
67
+ queue.push(item)
68
+ }
67
69
  }
68
70
  }
69
71
  for (const [pattern, parent] of sorted.concat(queue)) {
@@ -89,7 +91,7 @@ export class Hoister {
89
91
  }
90
92
 
91
93
  propagateRequired() {
92
- const toVisit = [...this.tree.values()].filter((info) => info.isRequired)
94
+ const toVisit = this.tree.values().filter((info) => info.isRequired).toArray()
93
95
  // In yarn's order, but by index, as shift() copies a long array.
94
96
  for (let i = 0; i < toVisit.length; i++) {
95
97
  const info = toVisit[i]