@preventive/deptree 1.0.0-alpha.9 → 1.0.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.
@@ -5,12 +5,15 @@
5
5
  // dependencies), and a package.json of the lockfile's name and version.
6
6
  // And a directory by `file:`, as yarn's copy fetcher installs it.
7
7
 
8
+ import { fromBase64 } from '@exodus/bytes/base64.js'
9
+ import { toHex } from '@exodus/bytes/hex.js'
10
+ import { getPublishTimes } from '@preventive/upstream/npm.js'
8
11
  import { normalize } from '@preventive/vfs/path.js'
9
12
  import { DeptreeError, quote } from '../error.js'
10
13
  import { sha1Hex } from '../hash.js'
11
14
  import { readManifest } from '../manifest.js'
12
15
  import { decodeUtf8, readBytes, typeOf } from '../project.js'
13
- import { fetchTarball, fromMirror, isModules, ownTarball, registryIntegrity, sameFile, withDirs } from '../tarball.js'
16
+ import { fetchTarball, fromMirror, isModules, ownTarball, sameFile, withDirs } from '../tarball.js'
14
17
  import { fixLists } from './manifest.js'
15
18
  import { kindOf, splitPattern } from './resolve.js'
16
19
 
@@ -44,20 +47,62 @@ function entriesOf(entries, where) {
44
47
 
45
48
  const decoder = new TextDecoder('utf-8', { fatal: true })
46
49
 
50
+ // yarn writes the registry's sha512 where it has one, and else a sha1 of its
51
+ // shasum. Since this time the registry has made one for every version as it
52
+ // was published, by any client: firebase-tools@4.0.3, published then by npm
53
+ // 3.10.8, is the first it signed over one it made, and superstatic@6.0.0, at
54
+ // 2018-08-03T20:22:28.120Z, the last over none. It has since made one for
55
+ // every version published before too.
56
+ export const SHA512_SINCE = '2018-08-05T14:58:16.253Z'
57
+
58
+ // The hex of an integrity that is a sha1 alone.
59
+ function sha1Of(integrity) {
60
+ if (integrity === undefined || !/^sha1-[\d+/A-Za-z]{26}[048AEIMQUYcgkosw]=$/u.test(integrity)) return undefined
61
+ return toHex(fromBase64(integrity.slice(5)))
62
+ }
63
+
47
64
  // `name` is the one fetched, as an `npm:` alias asks for it. yarn writes no
48
65
  // integrity for a pattern that names the tarball's URL, but the sha1 after
49
- // its `#`: the tarball is held to that, and to the registry's sha512.
66
+ // its `#`: the tarball is held to that, and to the registry's sha512. One
67
+ // with a sha1 integrity alone is held to it, and to the registry's sha512,
68
+ // where it was published before SHA512_SINCE.
50
69
  export function registryTarball(entry, name, where) {
51
70
  const { resolution } = entry
52
71
  if (resolution === undefined) throw new DeptreeError('a directory, by file: or link:, is not supported', where)
53
72
  const url = resolution.type === 'tarball' ? fromMirror(resolution.tarball) : resolution.tarball
54
73
  const byUrl = entry.patterns.some((pattern) => kindOf(splitPattern(pattern).range, where) === 'tarball')
55
- return ownTarball(url, name, entry.version, resolution.integrity, where, byUrl && resolution.sha1 !== undefined)
74
+ const sha1 = sha1Of(resolution.integrity)
75
+ if (sha1 === undefined) return ownTarball(url, name, entry.version, resolution.integrity, where, byUrl && resolution.sha1 !== undefined)
76
+ return { ...ownTarball(url, name, entry.version, undefined, where, true), sha1 }
77
+ }
78
+
79
+ // `times` keeps getPublishTimes' answer for each name, fetched once.
80
+ async function checkPublished({ name, version }, where, times) {
81
+ if (!times.has(name)) times.set(name, getPublishTimes(name))
82
+ const published = (await times.get(name)).get(version)
83
+ if (published === undefined) throw new DeptreeError(`a sha1 integrity alone, where the registry gives no time ${name}@${version} was published at`, where)
84
+ if (published >= SHA512_SINCE) throw new DeptreeError(`a sha1 integrity alone, which yarn does not write for ${name}@${version}, published at ${published}: the registry has given every version a sha512 since ${SHA512_SINCE}`, where)
85
+ }
86
+
87
+ export function checkSha1(pinned, sha1, where) {
88
+ if (pinned !== undefined && sha1 !== pinned) throw new DeptreeError(`the tarball's sha1 is not ${pinned}`, where)
89
+ }
90
+
91
+ // Another entry of a package yarn's cache keeps in one place, held to the
92
+ // first's, `head`, as fetchYarnPackage holds that one: yarn fetches it once.
93
+ export async function checkShared({ name, version, integrity, sha1: pinned }, head, where, times) {
94
+ if (pinned !== undefined) await checkPublished({ name, version }, where, times)
95
+ checkSha1(pinned, head.sha1, where)
96
+ if (integrity !== undefined && integrity !== head.integrity) throw new DeptreeError(`the tarball is not ${integrity}`, where)
56
97
  }
57
98
 
58
- export async function fetchYarnPackage({ name, version, integrity }, where) {
59
- const fetched = await fetchTarball(name, version, integrity ?? await registryIntegrity(name, version, where), where)
99
+ // One the lockfile gives no sha512 is fetched by the registry's, as
100
+ // fetchTarball takes it unpinned.
101
+ export async function fetchYarnPackage({ name, version, integrity, sha1: pinned }, where, times, fetching) {
102
+ if (pinned !== undefined) await checkPublished({ name, version }, where, times)
103
+ const fetched = await fetchTarball(name, version, integrity, where, fetching)
60
104
  const sha1 = await sha1Hex(fetched.bytes)
105
+ checkSha1(pinned, sha1, where)
61
106
  const { files, dirs } = entriesOf(fetched.entries, where)
62
107
  const file = files.get('package.json')
63
108
  if (file === undefined) throw new DeptreeError('the tarball has no package.json', where)
@@ -69,7 +114,7 @@ export async function fetchYarnPackage({ name, version, integrity }, where) {
69
114
  }
70
115
  const manifest = readManifest(text, `${where}: package.json`)
71
116
  if (manifest.name !== name || manifest.version !== version) throw new DeptreeError(`package.json is for ${quote(`${manifest.name}@${manifest.version}`)}`, where)
72
- return { ...withBins({ files, dirs }, manifest, where), sha1, integrity: fetched.integrity }
117
+ return { ...withBins({ files, dirs }, manifest, where), sha1, integrity: fetched.integrity, about: fetched.about }
73
118
  }
74
119
 
75
120
  // A directory by `file:`, as yarn's copy fetcher installs it: all in it, each
@@ -131,6 +131,11 @@ class Resolver {
131
131
  return this.rules.find((rule) => rule.name === name && matchesGlob(rule.glob, path))
132
132
  }
133
133
 
134
+ // The package a request of `name` and `range` finds resolved already.
135
+ resolvedOf(name, range, info) {
136
+ return info.kind === 'directory' ? this.copyOf(name, info.dir) : this.exactMatch(name, validRange(range) ? info.version : range)
137
+ }
138
+
134
139
  exactMatch(name, version) {
135
140
  return this.byName.get(name)?.map((pattern) => this.patterns.get(pattern)).find((ref) => ref.version === version)
136
141
  }
@@ -141,8 +146,7 @@ class Resolver {
141
146
  // the last of which its pattern names.
142
147
  check(request, info) {
143
148
  const { name, range } = splitPattern(request.pattern)
144
- const found = info.kind === 'directory' ? this.copyOf(name, info.dir) : this.exactMatch(name, validRange(range) ? info.version : range)
145
- if (found !== undefined) {
149
+ if (this.resolvedOf(name, range, info) !== undefined) {
146
150
  this.delayed.push(request)
147
151
  return []
148
152
  }
@@ -187,17 +191,60 @@ class Resolver {
187
191
  return { request, info, left: info.tag ? Infinity : TURNS[info.kind] }
188
192
  }
189
193
 
194
+ // The names a request would add a package or a pattern under, through all
195
+ // it would resolve that is not resolved already; undefined where a
196
+ // resolution or a directory may come in, or something is refused.
197
+ namesOf(request) {
198
+ const names = new Set()
199
+ const seen = new Set()
200
+ const queue = [request]
201
+ try {
202
+ while (queue.length > 0) {
203
+ const next = queue.pop()
204
+ if (seen.has(next.pattern)) continue
205
+ seen.add(next.pattern)
206
+ const { name, range } = splitPattern(next.pattern)
207
+ if (this.rules.some((rule) => rule.name === name)) return undefined
208
+ const info = this.infoOf(next)
209
+ const deps = asked(info, quote(next.pattern))
210
+ if (info.kind === 'directory') return undefined
211
+ names.add(name).add(info.name)
212
+ if (this.resolvedOf(name, range, info) === undefined) queue.push(...deps)
213
+ }
214
+ } catch (error) {
215
+ if (error instanceof DeptreeError) return undefined
216
+ throw error
217
+ }
218
+ return names
219
+ }
220
+
221
+ // A tag waits on the filesystem, and each it answers resolves all beneath
222
+ // it before the next: in an order not set, which changes nothing where no
223
+ // two would add under one name, and no resolution or directory comes in.
224
+ apart(waiting) {
225
+ if (this.late.length > 0) return false
226
+ const taken = new Set()
227
+ for (const { request } of waiting) {
228
+ const names = this.namesOf(request)
229
+ if (names === undefined || !names.isDisjointFrom(taken)) return false
230
+ for (const name of names) taken.add(name)
231
+ }
232
+ return true
233
+ }
234
+
235
+ // Where none is a directory of the project, the first goes on.
190
236
  answer(waiting) {
191
237
  const reading = [...waiting.map(({ request }) => request), ...this.late]
192
- if (reading.length > 1) throw new DeptreeError(`yarn resolves these in the order the filesystem answers it, which is not set: ${reading.map(({ pattern }) => quote(pattern)).join(', ')}`)
193
- const [strand] = waiting
194
- const where = quote(strand.request.pattern)
195
- const { range } = splitPattern(strand.request.pattern)
196
- const found = this.isDirectory(range)
197
- if (found === undefined) throw new DeptreeError(`yarn installs the directory ${quote(range)} for it where the project has one, which is known only with the project read`, where)
198
- if (found) throw new DeptreeError(`yarn installs the directory ${quote(range)} for it, which is not supported`, where)
199
- strand.left = 1
200
- return [strand]
238
+ if (reading.length > 1 && !this.apart(waiting)) throw new DeptreeError(`yarn resolves these in the order the filesystem answers it, which is not set: ${reading.map(({ pattern }) => quote(pattern)).join(', ')}`)
239
+ for (const { request } of waiting) {
240
+ const where = quote(request.pattern)
241
+ const { range } = splitPattern(request.pattern)
242
+ const found = this.isDirectory(range)
243
+ if (found === undefined) throw new DeptreeError(`yarn installs the directory ${quote(range)} for it where the project has one, which is known only with the project read`, where)
244
+ if (found) throw new DeptreeError(`yarn installs the directory ${quote(range)} for it, which is not supported`, where)
245
+ }
246
+ waiting[0].left = 1
247
+ return waiting
201
248
  }
202
249
 
203
250
  // A microtask turn: the requests a check makes start where it stood.
package/src/yarn1/tree.js CHANGED
@@ -10,12 +10,13 @@ import { eachConcurrently } from '../concurrent.js'
10
10
  import { DeptreeError, quote } from '../error.js'
11
11
  import { checkNoModules, isInside, makeDirs, mount, writeFiles, writeLink } from '../mount.js'
12
12
  import { typeOf } from '../project.js'
13
+ import { fetchingOf } from '../tarball.js'
13
14
  import { checkBinLinks } from './bins.js'
14
15
  import { incompatibility } from './compat.js'
15
16
  import { Hoister } from './hoist.js'
16
17
  import { checkHost, inputsOf } from './inputs.js'
17
18
  import { checkRoot, fixLists } from './manifest.js'
18
- import { fetchYarnPackage, readYarnDirectory, registryTarball } from './package.js'
19
+ import { checkSha1, checkShared, fetchYarnPackage, readYarnDirectory, registryTarball } from './package.js'
19
20
  import { resolvePeers } from './peers.js'
20
21
  import { AGGREGATOR, aggregatorOf, rulesOf, topRequests, workspacesOf } from './requests.js'
21
22
  import { resolve, splitPattern } from './resolve.js'
@@ -31,12 +32,18 @@ function fetchedName(ref) {
31
32
  return range.startsWith('npm:') ? splitPattern(range.slice(4)).name : ref.name
32
33
  }
33
34
 
34
- async function fetchAll(refs) {
35
+ // The first of each place in `first` is fetched, and every entry held to it.
36
+ async function fetchAll(refs, first, fetching) {
35
37
  const fetched = new Map()
36
- const tarballs = refs.map((ref) => ({ ref, tarball: registryTarball(ref.entry, fetchedName(ref), whereOf(ref)) }))
37
- await eachConcurrently(tarballs, async ({ ref, tarball }) => {
38
- fetched.set(ref, await fetchYarnPackage(tarball, whereOf(ref)))
39
- }, ({ ref }) => whereOf(ref))
38
+ const times = new Map()
39
+ const tarballs = new Map(refs.map((ref) => [ref, registryTarball(ref.entry, fetchedName(ref), whereOf(ref))]))
40
+ await eachConcurrently([...first.values()], async (ref) => {
41
+ fetched.set(ref, await fetchYarnPackage(tarballs.get(ref), whereOf(ref), times, fetching))
42
+ }, whereOf)
43
+ for (const ref of refs) {
44
+ const head = first.get(ref.loc)
45
+ if (head !== ref) await checkShared(tarballs.get(ref), fetched.get(head), whereOf(ref), times)
46
+ }
40
47
  return fetched
41
48
  }
42
49
 
@@ -79,20 +86,20 @@ function resolveProject(inputs, host) {
79
86
  // its resolver hands them over. Of two its cache keeps in one place, only the
80
87
  // first is fetched; the rest keep their lockfile entry as package.json, with
81
88
  // no peers, bins, platforms or engines, and the first's files, and their
82
- // URL's sha1 is held to the first's tarball.
83
- async function fetchChecked(resolved, host, settings, project) {
89
+ // hashes are held to the first's tarball.
90
+ async function fetchChecked(resolved, host, settings, project, fetching) {
84
91
  const order = [...new Set(resolved.patterns.values())]
92
+ const registry = order.filter((ref) => ref.kind === 'registry')
85
93
  const first = new Map()
86
- for (const ref of order) if (ref.kind === 'registry' && !first.has(ref.loc)) first.set(ref.loc, ref)
87
- const fetched = await fetchAll([...first.values()])
94
+ for (const ref of registry) if (!first.has(ref.loc)) first.set(ref.loc, ref)
95
+ const fetched = await fetchAll(registry, first, fetching)
88
96
  const directories = readDirectories(order, project, fetched)
89
97
  const manifestOf = new Map()
90
98
  for (const ref of order) {
91
99
  let manifest = ref.workspace?.manifest
92
100
  if (ref.kind === 'registry') {
93
101
  const head = first.get(ref.loc)
94
- const { sha1 } = ref.entry.resolution
95
- if (sha1 !== undefined && fetched.get(head).sha1 !== sha1) throw new DeptreeError(`the tarball's sha1 is not ${sha1}`, whereOf(ref))
102
+ checkSha1(ref.entry.resolution.sha1, fetched.get(head).sha1, whereOf(ref))
96
103
  fetched.set(ref, fetched.get(head))
97
104
  ref.hasBins = head === ref && fetched.get(ref).hasBins
98
105
  manifest = head === ref ? fixLists(fetched.get(ref).manifest) : { name: ref.name, version: ref.version }
@@ -170,13 +177,16 @@ function writeTree(placed, fetched) {
170
177
  return { vfs, links, locations, copies, ...counted }
171
178
  }
172
179
 
180
+ // What a version document says, but what it does not.
181
+ const said = (about) => Object.fromEntries(Object.entries(about).filter(([, value]) => value !== undefined))
182
+
173
183
  function listInstalled(copies, fetched, asked, hoister) {
174
184
  const prod = hoister.reachedBut('dev', asked)
175
185
  const required = hoister.reachedBut('optional', asked)
176
186
  return [...copies].map(([path, places]) => {
177
187
  const { ref } = places[0]
178
- const { manifest, integrity } = fetched.get(ref)
179
- const from = ref.kind === 'directory' ? { directory: ref.dir } : { integrity }
188
+ const { manifest, integrity, about } = fetched.get(ref)
189
+ const from = ref.kind === 'directory' ? { directory: ref.dir } : { integrity, ...said(about) }
180
190
  return { path, name: manifest.name, version: manifest.version, ...from, dev: !places.some((info) => prod.has(info)), optional: !places.some((info) => required.has(info)) }
181
191
  }).sort((a, b) => compareNames(a.path, b.path))
182
192
  }
@@ -184,6 +194,8 @@ function listInstalled(copies, fetched, asked, hoister) {
184
194
  export async function buildYarn1Tree(options) {
185
195
  const { host: given, vfs: into } = options ?? {}
186
196
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
197
+ const fetching = fetchingOf(options ?? {})
198
+ if (fetching.sizeEstimateOnly) throw new TypeError('sizeEstimateOnly is not taken for yarn 1, which hoists and leaves out packages by what their package.json says, which only their tarballs hold')
187
199
  const inputs = inputsOf(options ?? {})
188
200
  const host = checkHost(given, inputs.manifests.get('.'))
189
201
  const folded = host.os === 'darwin'
@@ -191,7 +203,7 @@ export async function buildYarn1Tree(options) {
191
203
  if (into !== undefined) checkNoModules(into, folded)
192
204
  checkRoot(inputs.manifests.get('.'))
193
205
  const { workspaces, asked, resolved } = resolveProject(inputs, host)
194
- const { packages, fetched, manifestOf } = await fetchChecked(resolved, host, inputs.settings, inputs.project)
206
+ const { packages, fetched, manifestOf } = await fetchChecked(resolved, host, inputs.settings, inputs.project, fetching)
195
207
  const { placed, hoister } = layout({ resolved, manifestOf, asked, workspaces })
196
208
  const { vfs, links, locations, copies, files, bytes } = writeTree(placed, fetched)
197
209
  checkBinLinks({ placed, patterns: resolved.patterns, locations, realOf: (path) => realOf(links, path) })
package/yarn1.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- // Hand-written against yarn1.js; a change to either belongs with the other.
2
-
1
+ import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js'
3
2
  import type { NodeType, Vfs } from '@preventive/vfs'
4
3
 
5
4
  export { LockfileError } from '@preventive/lockfile/yarn1.js'
@@ -7,7 +6,7 @@ export { LockfileError } from '@preventive/lockfile/yarn1.js'
7
6
  // Where @preventive/upstream caches what it fetches, tarballs among them.
8
7
  // Tarballs are fetched through it, and that is the one place anything here
9
8
  // touches a filesystem. Before the network, it takes a tarball from npm's
10
- // cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
9
+ // cache -- under $npm_config_cache, or ~/.npm -- from ~/.audit/cache/tgz, or
11
10
  // from its own default cache directory or stasis's, where one there has the
12
11
  // lockfile's integrity, and writes none of them; then from its own cache,
13
12
  // where one is set, which is where it writes each tarball it fetches:
@@ -22,7 +21,7 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
22
21
  // one the root package.json's packageManager pins, which corepack runs,
23
22
  // and has to be given where that pins none, and to be that one where it
24
23
  // does. `node` is the Node yarn runs on, an exact version; `os` and `cpu`
25
- // as Node names them — `linux`, `x64`. Windows is refused: yarn links bins
24
+ // as Node names them -- `linux`, `x64`. Windows is refused: yarn links bins
26
25
  // there with shims, and workspaces with junctions.
27
26
  // A package whose os, cpu or engines the machine does not take is left
28
27
  // out where it is optional, and refused where it is not, as yarn fails
@@ -82,8 +81,8 @@ export interface Yarn1Project {
82
81
  // reads as a manifest too; and a .yarnrc.yml, whose yarnPath yarn 1.22
83
82
  // runs in its stead.
84
83
  //
85
- // Settings from anywhere else — a .yarnrc or .npmrc above the project or
86
- // in the home directory, the environment, the command line — are not read,
84
+ // Settings from anywhere else -- a .yarnrc or .npmrc above the project or
85
+ // in the home directory, the environment, the command line -- are not read,
87
86
  // and are taken to be at their defaults.
88
87
  //
89
88
  // Of the .yarnrc and the .npmrc, as yarn 1.22 reads them: yarn reads an
@@ -91,18 +90,18 @@ export interface Yarn1Project {
91
90
  // a `--` line of the .yarnrc as a flag on its command line. Two settings
92
91
  // are followed as yarn follows them: ignore-engines, by the flag
93
92
  // `--ignore-engines true` or `--install.ignore-engines true`, or by the
94
- // option where it is truthy as yarn reads it — a quoted "false" is; and
93
+ // option where it is truthy as yarn reads it -- a quoted "false" is; and
95
94
  // ignore-platform, by its flag alone, as yarn does not act on the option.
96
- // Options yarn reads that change what it installs are refused —
95
+ // Options yarn reads that change what it installs are refused --
97
96
  // ignore-optional, production, bin-links, workspaces-experimental and the
98
- // like — and so is yarn-path, which has another yarn run, and
97
+ // like -- and so is yarn-path, which has another yarn run, and
99
98
  // global-folder, which, where it is the project's own directory, has yarn
100
99
  // read its package.json files otherwise; any other option
101
100
  // is passed over, as yarn reads it only for where it fetches from, how,
102
101
  // and what it keeps, which the tree is held to the lockfile's integrities
103
102
  // against whatever serves it, or for no install at all, as with most of
104
- // npm's own. A flag is passed over where it does not change the tree —
105
- // --registry, --frozen-lockfile, --network-timeout and the like — and
103
+ // npm's own. A flag is passed over where it does not change the tree --
104
+ // --registry, --frozen-lockfile, --network-timeout and the like -- and
106
105
  // refused where it may or is not known here: --production, --flat,
107
106
  // --modules-folder, --ignore-optional, --no-bin-links, --no-lockfile,
108
107
  // which has yarn read no yarn.lock, --global-folder, --cwd and the rest. A .yarnrc line indented under another, which yarn reads into it,
@@ -110,13 +109,13 @@ export interface Yarn1Project {
110
109
  // or false, or for the .yarnrc's option a quoted string.
111
110
  //
112
111
  // A workspace project is the root, marked private, and every directory its
113
- // `workspaces` globs take — `*`, `?` and `**`, as the lockfile reader takes
114
- // them — with a package.json that has a name and a version. `nohoist`,
112
+ // `workspaces` globs take -- `*`, `?` and `**`, as the lockfile reader takes
113
+ // them -- with a package.json that has a name and a version. `nohoist`,
115
114
  // Plug'n'Play, and a root package.json's `flat` are refused.
116
115
  //
117
116
  // `vfs` is a Vfs to mount the tree into, at its root, which is taken to
118
117
  // be the lockfile's directory, beside whatever it holds, such as the
119
- // projects themselves — it may be `project` too; without one, a new Vfs
118
+ // projects themselves -- it may be `project` too; without one, a new Vfs
120
119
  // holds the tree alone. Nothing the tree is built from is read from it. A
121
120
  // Vfs that holds a node_modules anywhere, or on macOS a name that is one
122
121
  // there, is refused before anything is fetched: kept beside the tree, Node
@@ -126,6 +125,30 @@ export interface Yarn1Project {
126
125
  // tree is built, and held to every check below, before any of it is
127
126
  // written, so a refusal leaves the Vfs as it was.
128
127
  //
128
+ // `metadata`, true unless given false, has each registry package's version
129
+ // document asked for beside its tarball, through getMeta of
130
+ // @preventive/upstream given the lockfile's dist: the one `cache` keeps,
131
+ // where its dist is that one, else the registry's, a request for each name
132
+ // and version. Its dist has to be the lockfile's, the tarball
133
+ // the registry's own URL and the integrity the lockfile's sha512, compared
134
+ // as text, with nothing hashed again, as the lockfile copies the
135
+ // registry's; and its gitHead, repository, homepage and bugs are the
136
+ // package's. False fetches none, and gives none of them, but for a package
137
+ // whose sha512 the lockfile does not record, whose document is fetched for
138
+ // the registry's either way, and gives them.
139
+ //
140
+ // `cache` is where each registry package's tarball and version document
141
+ // are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
142
+ // cache where it is left out; in a store of the caller's, with `read` and
143
+ // `write`, in place of it; or with false, nowhere, though setCacheDir's
144
+ // cache is read all the same. Other tools' caches are read for tarballs
145
+ // whatever it is. A TypeError is thrown for anything else.
146
+ //
147
+ // `sizeEstimateOnly`, which buildPnpmTree and buildNpmTree take for a tree's
148
+ // directories and links alone, is not taken, as yarn hoists and leaves out
149
+ // packages by what their package.json says, which only their tarballs
150
+ // hold: a TypeError is thrown for it given true.
151
+ //
129
152
  // The two ways the files come, one or the other: given, with `lockfile`
130
153
  // and `manifests`; or read, with `project` and none of them. `project`
131
154
  // given with `lockfile` is read only to tell whether a tag a top-level
@@ -140,6 +163,8 @@ export interface Yarn1TreeGiven {
140
163
  project?: Yarn1Project
141
164
  host: Yarn1Host
142
165
  vfs?: Vfs
166
+ metadata?: boolean
167
+ cache?: CacheOptions['cache']
143
168
  }
144
169
 
145
170
  export interface Yarn1TreeRead {
@@ -150,6 +175,8 @@ export interface Yarn1TreeRead {
150
175
  project: Yarn1Project
151
176
  host: Yarn1Host
152
177
  vfs?: Vfs
178
+ metadata?: boolean
179
+ cache?: CacheOptions['cache']
153
180
  }
154
181
 
155
182
  // What buildYarn1Tree counts, all of it plain numbers: `packages` the
@@ -169,12 +196,18 @@ export interface Yarn1TreeStats {
169
196
 
170
197
  // A copy of a package in the tree, as an SBOM would list it: `path` is
171
198
  // where its files really are, from the lockfile's directory, which is `/`
172
- // of the Vfs — node_modules/<alias>, or beneath a workspace, in that
199
+ // of the Vfs -- node_modules/<alias>, or beneath a workspace, in that
173
200
  // workspace's own node_modules. `name` and `version` are the package's
174
201
  // own, which its package.json is held to, whatever alias it is installed
175
202
  // as; `integrity` the sha512 its tarball is held to, for a registry
176
203
  // package, and `directory` the directory of the project it is copied
177
- // from, for one by `file:`, in place of an integrity. `dev` is
204
+ // from, for one by `file:`, in place of an integrity. For a registry
205
+ // package alone, where its version document is fetched: `commit` is its
206
+ // gitHead, where that is a full commit id, the commit npm read off the
207
+ // checkout it published from; `repository`, `homepage` and `bugs` the
208
+ // document's, as getMeta of @preventive/upstream reads them; each left out
209
+ // where there is none, and all of it the publisher's word, held to no
210
+ // repository. `dev` is
178
211
  // whether dev dependencies alone reach this copy, the root's and the
179
212
  // workspaces' devDependencies: nothing else does, each dependency, and
180
213
  // each peer yarn finds, looked for from where what asks for it is, as Node
@@ -188,6 +221,10 @@ export interface Yarn1Installed {
188
221
  version: string
189
222
  integrity?: string
190
223
  directory?: string
224
+ commit?: string
225
+ repository?: string | PackageRepository
226
+ homepage?: string
227
+ bugs?: string | PackageBugs
191
228
  dev: boolean
192
229
  optional: boolean
193
230
  }
@@ -250,7 +287,11 @@ export interface Yarn1Tree {
250
287
  // yarn installs its dependencies, no link or device in it, and a
251
288
  // package.json for exactly its name and version; each with the sha512
252
289
  // integrity the lockfile records, and the sha1 each of its entries does,
253
- // fetched or not. On macOS, two names in one
290
+ // fetched or not. yarn writes a sha1 integrity alone where the registry had
291
+ // no sha512 for the version: taken only for one the registry says was
292
+ // published before 2018-08-05T14:58:16.253Z, since when it has made one for
293
+ // every version as it was published, and held to that sha1 and to the
294
+ // registry's own sha512. On macOS, two names in one
254
295
  // directory that differ only in case or normalization are refused, as
255
296
  // they would be one name there.
256
297
  //
@@ -261,11 +302,13 @@ export interface Yarn1Tree {
261
302
  // sha1 after it aside), or that same URL on yarn's mirror,
262
303
  // https://registry.yarnpkg.com/, which is taken for npm's; it is fetched
263
304
  // from npm's through @preventive/upstream. Each is asked for by a semver
264
- // range, an `npm:` alias, or a tag — the last only where the project is
305
+ // range, an `npm:` alias, or a tag -- the last only where the project is
265
306
  // given, and a directory of the project of that name is not there, which
266
- // yarn would install instead, and only where yarn would not have two
267
- // requests of tags wait on the filesystem at once, which it answers in no
268
- // set order.
307
+ // yarn would install instead. A request of a tag waits on the filesystem,
308
+ // which answers in no set order, and each it answers resolves all beneath
309
+ // it before the next: where two or more wait at once, only where that
310
+ // order changes nothing, as no two would add a package or a pattern under
311
+ // one name, and no resolution applies or directory is read beneath them.
269
312
  //
270
313
  // Or by the registry's own tarball URL, either of those above (no `#`
271
314
  // after it): the entry yarn writes for one has no integrity, so its
@@ -298,10 +341,10 @@ export interface Yarn1Tree {
298
341
  //
299
342
  // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
300
343
  // setting this does not know or does not build for, a package from
301
- // anywhere but those above — git, another tarball URL, a tarball on disk,
302
- // a directory by `link:` — a range that is none of those above, a package
344
+ // anywhere but those above -- git, another tarball URL, a tarball on disk,
345
+ // a directory by `link:` -- a range that is none of those above, a package
303
346
  // with bundled dependencies, another package manager, a check above that
304
- // fails — each is refused with a DeptreeError or a LockfileError that says
347
+ // fails -- each is refused with a DeptreeError or a LockfileError that says
305
348
  // where. A TypeError is thrown for options of the wrong type.
306
349
  export function buildYarn1Tree(options: Yarn1TreeOptions): Promise<Yarn1Tree>
307
350
 
@@ -318,8 +361,8 @@ export interface Yarn1WorkspacesOptions {
318
361
 
319
362
  export function findYarn1Workspaces(options: Yarn1WorkspacesOptions): string[]
320
363
 
321
- // `where` is what a refusal is about — `.yarnrc:3`, `manifests["."]`, a
322
- // package's pattern — or undefined for the call as a whole; the message
364
+ // `where` is what a refusal is about -- `.yarnrc:3`, `manifests["."]`, a
365
+ // package's pattern -- or undefined for the call as a whole; the message
323
366
  // leads with it. `cause` is what a package beneath refused with, where one
324
367
  // did.
325
368
  export class DeptreeError extends Error {