@preventive/deptree 1.0.0-alpha.6 → 1.0.0-alpha.8

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 (48) hide show
  1. package/npm.d.ts +9 -8
  2. package/package.json +11 -7
  3. package/pnpm.d.ts +66 -18
  4. package/soldeer.d.ts +74 -21
  5. package/src/hash.js +2 -6
  6. package/src/matcher.js +3 -2
  7. package/src/mount.js +22 -2
  8. package/src/npm/bins.js +2 -19
  9. package/src/npm/compat.js +11 -6
  10. package/src/npm/inputs.js +4 -9
  11. package/src/npm/manifests.js +4 -12
  12. package/src/npmrc.js +1 -2
  13. package/src/patch.js +4 -13
  14. package/src/pnpm/bins.js +129 -37
  15. package/src/pnpm/commands.js +4 -10
  16. package/src/pnpm/frozen.js +3 -6
  17. package/src/pnpm/gitignore.js +3 -1
  18. package/src/pnpm/glob.js +3 -3
  19. package/src/pnpm/hoist.js +3 -6
  20. package/src/pnpm/hoisted.js +234 -0
  21. package/src/pnpm/inputs.js +24 -34
  22. package/src/pnpm/install.js +17 -20
  23. package/src/pnpm/local.js +15 -3
  24. package/src/pnpm/minimatch.js +6 -15
  25. package/src/pnpm/nm-hoist-graph.js +299 -0
  26. package/src/pnpm/nm-hoist.js +149 -0
  27. package/src/pnpm/npm-packlist.js +7 -11
  28. package/src/pnpm/overrides.js +1 -2
  29. package/src/pnpm/package.js +6 -3
  30. package/src/pnpm/packlist.js +5 -4
  31. package/src/pnpm/readers.js +26 -29
  32. package/src/pnpm/settings.js +9 -8
  33. package/src/pnpm/tree.js +73 -30
  34. package/src/pnpm/workspace.js +2 -2
  35. package/src/project.js +22 -6
  36. package/src/soldeer/git.js +52 -0
  37. package/src/soldeer/inputs.js +4 -11
  38. package/src/soldeer/tree.js +36 -22
  39. package/src/soldeer/zip.js +4 -5
  40. package/src/tarball.js +68 -11
  41. package/src/yarn1/bins.js +1 -1
  42. package/src/yarn1/inputs.js +4 -11
  43. package/src/yarn1/package.js +61 -9
  44. package/src/yarn1/requests.js +7 -5
  45. package/src/yarn1/resolve.js +62 -13
  46. package/src/yarn1/settings.js +1 -2
  47. package/src/yarn1/tree.js +29 -9
  48. package/yarn1.d.ts +62 -29
package/npm.d.ts CHANGED
@@ -7,12 +7,13 @@ export { LockfileError } from '@preventive/lockfile/npm.js'
7
7
  // Where @preventive/upstream caches what it fetches, tarballs among them.
8
8
  // Tarballs are fetched through it, and that is the one place anything here
9
9
  // touches a filesystem. Before the network, it takes a tarball from npm's
10
- // cache — under $npm_config_cache, or ~/.npm — or from ~/.audit/cache/tgz,
11
- // where one there has the lockfile's integrity, and writes neither; then
12
- // from its own cache, where one is set, which is where it writes each
13
- // tarball it fetches. Unset, which it is by default, it has none, and
14
- // writes nothing. The project is read only through the view given as
15
- // `project`, and the tree built in a Vfs.
10
+ // cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
11
+ // from its own default cache directory or stasis's, where one there has the
12
+ // lockfile's integrity, and writes none of them; then from its own cache,
13
+ // where one is set, which is where it writes each tarball it fetches:
14
+ // setCacheDir() sets the default one, and setCacheDir(false) unsets it.
15
+ // Unset, which it is until set, it writes nothing. The project is read
16
+ // only through the view given as `project`, and the tree built in a Vfs.
16
17
  export { setCacheDir } from '@preventive/upstream/npm.js'
17
18
 
18
19
  // The machine npm would install on, which a tree depends on. `npm` is the
@@ -251,8 +252,8 @@ export interface NpmTree {
251
252
  // from npm's through @preventive/upstream.
252
253
  //
253
254
  // Ranges and versions are read with npm's own semver, borrowed from the
254
- // npm beside node as @preventive/upstream borrows it, without which this
255
- // throws.
255
+ // npm beside node as @preventive/upstream borrows it, or with its semver
256
+ // peer where there is no npm, without either of which this throws.
256
257
  //
257
258
  // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
258
259
  // setting this does not know or does not build for, a package from
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.0.0-alpha.6",
4
- "description": "A dependency tree in memory, as a package manager would install it: pnpm 9, 10, 11 or 12, yarn 1.22, or npm 10 or 11, from its lockfile, tarballs fetched and checked, patches applied; or Soldeer 0.12, its zips fetched, checked and extracted",
3
+ "version": "1.0.0-alpha.8",
4
+ "description": "A dependency tree in memory, as a package manager would install it",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./pnpm.js": {
@@ -61,11 +61,14 @@
61
61
  "src/pnpm/glob.js",
62
62
  "src/pnpm/graph.js",
63
63
  "src/pnpm/hoist.js",
64
+ "src/pnpm/hoisted.js",
64
65
  "src/pnpm/hook.js",
65
66
  "src/pnpm/inputs.js",
66
67
  "src/pnpm/install.js",
67
68
  "src/pnpm/local.js",
68
69
  "src/pnpm/minimatch.js",
70
+ "src/pnpm/nm-hoist-graph.js",
71
+ "src/pnpm/nm-hoist.js",
69
72
  "src/pnpm/npm-packlist.js",
70
73
  "src/pnpm/overrides.js",
71
74
  "src/pnpm/package.js",
@@ -79,6 +82,7 @@
79
82
  "src/pnpm/workspace.js",
80
83
  "src/project.js",
81
84
  "src/soldeer/config.js",
85
+ "src/soldeer/git.js",
82
86
  "src/soldeer/inputs.js",
83
87
  "src/soldeer/tree.js",
84
88
  "src/soldeer/zip.js",
@@ -121,10 +125,10 @@
121
125
  },
122
126
  "dependencies": {
123
127
  "@chalker/queue": "^1.0.1",
124
- "@preventive/archive": "1.0.0-beta.3",
125
- "@preventive/diff": "^1.0.0",
126
- "@preventive/lockfile": "1.0.0-alpha.5",
127
- "@preventive/upstream": "1.0.0-alpha.4",
128
- "@preventive/vfs": "1.0.0-beta.3"
128
+ "@preventive/archive": "1.0.0-beta.4",
129
+ "@preventive/diff": "^1.0.1",
130
+ "@preventive/lockfile": "1.0.0-alpha.7",
131
+ "@preventive/upstream": "1.0.0-alpha.10",
132
+ "@preventive/vfs": "1.0.0-beta.4"
129
133
  }
130
134
  }
package/pnpm.d.ts CHANGED
@@ -10,13 +10,15 @@ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
10
10
  // Where @preventive/upstream caches what it fetches, tarballs among them.
11
11
  // Tarballs are fetched through it, and that is the one place anything here
12
12
  // touches a filesystem. Before the network, it takes a tarball from npm's
13
- // cache — under $npm_config_cache, or ~/.npm — or from ~/.audit/cache/tgz,
14
- // where one there has the lockfile's integrity, and writes neither; then
15
- // from its own cache, where one is set, which is where it writes each
16
- // tarball it fetches. Unset, which it is by default, it has none, and
17
- // writes nothing: a tarball in neither of the others is fetched every
18
- // time, each once for however many snapshots it has. The project is read
19
- // only through the view given as `project`, and the tree built in a Vfs.
13
+ // cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
14
+ // from its own default cache directory or stasis's, where one there has the
15
+ // lockfile's integrity, and writes none of them; then from its own cache,
16
+ // where one is set, which is where it writes each tarball it fetches:
17
+ // setCacheDir() sets the default one, and setCacheDir(false) unsets it.
18
+ // Unset, which it is until set, it writes nothing: a tarball in none of
19
+ // the others is fetched every time, each once for however many snapshots
20
+ // it has. The project is read only through the view given as `project`,
21
+ // and the tree built in a Vfs.
20
22
  export { setCacheDir } from '@preventive/upstream/npm.js'
21
23
 
22
24
  // The machine pnpm would install on, which a tree depends on: `pnpm` is
@@ -131,10 +133,12 @@ export interface PnpmProject {
131
133
  // with more than 100 `**` parts for pnpm 9 and 10, and a directory nested
132
134
  // more than 100 deep, for the time matching them takes. Matching takes
133
135
  // time linear in the path and the pattern. pnpm hardlinks those files from
134
- // the directory into each snapshot of the package, so a file linking a bin
135
- // makes executable is made so in every snapshot and in the directory, which
136
- // is not written here; a CRLF `#!` line it rewrites is rewritten as a file
137
- // of that snapshot's own. Where it builds the package — an install script, a
136
+ // the directory into each snapshot of the package, in their modes, which
137
+ // are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
138
+ // 0o755 and 0o775. So a file linking a bin makes executable — 0o755 for
139
+ // pnpm 9 and 10, its mode with 0o111 added for 11 and 12 — is made so in
140
+ // every snapshot and in the directory, which is not written here; a CRLF
141
+ // `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package — an install script, a
138
142
  // binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
139
143
  // .hooks directory — or, with pnpm 11 and 12, where packageImportMethod is
140
144
  // other than auto or hardlink, each snapshot has a copy of its own
@@ -156,9 +160,10 @@ export interface PnpmProject {
156
160
  // by their kebab-case names, those that can change the tree held to what
157
161
  // is built here, and all else — npm's own settings, publishing's,
158
162
  // credentials, other names — passed over. A `${VAR}` pnpm would fill in is
159
- // taken in a line passed over, such as `//registry.npmjs.org/:_authToken`,
160
- // where the rest of the file would not change the tree: pnpm drops the
161
- // whole file where the variable is unset.
163
+ // taken in a line passed over where the rest of the file would not change
164
+ // the tree, as pnpm drops the whole file where the variable is unset; but
165
+ // `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`, the registry's token as
166
+ // a project commonly gives it, is taken to be set, and the rest read.
162
167
  //
163
168
  // pnpm 11 reads its settings from pnpm-workspace.yaml alone, as this does
164
169
  // for it: of the .npmrc only its registries, and of the package.json no
@@ -188,7 +193,14 @@ export interface PnpmProject {
188
193
  // install reads, without `lockfile`; for the directories a `link:` or an
189
194
  // override leads to. With it given, a directory the tree links to that is
190
195
  // no project, and is under the lockfile's, has to be there with a
191
- // package.json, whose bins are read as pnpm reads them. Without it, or
196
+ // package.json, whose bins are read as pnpm reads them; pnpm links to one
197
+ // that is not there all the same, warning only as pnpm 10 and 11 resolve,
198
+ // never as a frozen install. So it does for `npm:@scope/name@workspace:^`,
199
+ // as an override or a dependency, which it takes for a path for its `/`,
200
+ // and that link is refused with or without `project`, but where it holds
201
+ // a directory of that very name:
202
+ // `workspace:@scope/name@^` is the spec that links the workspace package
203
+ // by another name. Without it, or
192
204
  // outside the lockfile's directory, such a directory's bins are not
193
205
  // known, and neither are those of a project that has them by the files of
194
206
  // its directories.bin: where one could win a command a package's file is
@@ -285,7 +297,9 @@ export interface PnpmInstalled {
285
297
 
286
298
  // `vfs` is the one given, the tree mounted into it, or a new one.
287
299
  // `installed` is each snapshot in the tree, one for each `stats.installed`
288
- // counts, in the lockfile's order.
300
+ // counts, in the lockfile's order; with the hoisted linker, each copy, at
301
+ // node_modules/<alias> under where it landed, in the order pnpm makes them,
302
+ // each with the snapshot copied there.
289
303
  export interface PnpmTree {
290
304
  vfs: Vfs
291
305
  stats: PnpmTreeStats
@@ -293,8 +307,8 @@ export interface PnpmTree {
293
307
  }
294
308
 
295
309
  // The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`
296
- // makes with the isolated linker of host.pnpm, 9, 10, 11 or 12, and no
297
- // other install: whatever the
310
+ // makes with the isolated linker of host.pnpm, 9, 10, 11 or 12, or the
311
+ // hoisted one of pnpm 10 or 11, and no other install: whatever the
298
312
  // settings say of frozen lockfiles, the install is frozen, which is also
299
313
  // the only one that hoists by the lockfile's graph alone. It is rooted at
300
314
  // the lockfile's directory: each package's
@@ -350,6 +364,40 @@ export interface PnpmTree {
350
364
  // patched package as pnpm 11 built it, which is not followed here: the
351
365
  // tree is the one a store of pnpm 12's own gives.
352
366
  //
367
+ // With nodeLinker: hoisted, for pnpm 10 and 11, the tree is the one the
368
+ // hoisted linker makes: each package copied to node_modules/<alias> as near
369
+ // the root as @yarnpkg/nm's hoist takes it, under what needs it where the
370
+ // name there is another's, and each project's dependencies the root has
371
+ // another of in its own node_modules; a project's `link:` dependencies
372
+ // linked there, and a package's refused, which pnpm links nowhere; and no
373
+ // node_modules/.pnpm, where pnpm keeps only its state. pnpm takes every
374
+ // snapshot of one name and version for the first it comes to, and every
375
+ // directory of one name for one, as is followed here; from pnpm 11.24, each
376
+ // snapshot of a directory for its own. From pnpm 11.28 it also links each
377
+ // named project into the root's node_modules by its name, as
378
+ // hoistWorkspacePackages has it, where a hoist pattern matches it and the
379
+ // root depends on nothing of that name and no package landed there by it,
380
+ // their case folded; and from 11.28.1 does not hoist a project's `link:`
381
+ // into itself (`link:<root>/`). Every copy has to be its own, so
382
+ // packageImportMethod has to be copy, clone or clone-or-copy: any other
383
+ // hardlinks from pnpm's store. Bins are fixed as pnpm links them: in each
384
+ // node_modules as it fills it, then in each project's again with its links
385
+ // in, a command of the project's own dependencies over another's. Where any
386
+ // patch is configured, pnpm builds each package patched or with an install
387
+ // script in one of its copies, which it finds through the dependencies of
388
+ // each, by snapshot or from pnpm 11.23 by package, linking its
389
+ // dependencies' bins and its own, and links that copy's files into the
390
+ // others: before pnpm 10.21 in place, which leaves the others unpatched;
391
+ // from 10.21 a copy of hardlinks put in place of each, with no
392
+ // node_modules, which drops the copy's own; and from 11.25 each file but
393
+ // those under a node_modules in place of the copy's own, keeping its
394
+ // node_modules and what the built copy has not, which leaves a file the
395
+ // patch deletes in the others. These are refused where they would change a
396
+ // copy, and so is a patched package no copy of which the build reaches,
397
+ // which pnpm leaves unpatched; which copy pnpm builds is not followed, and
398
+ // refused where it would change a bin. Hoisting is refused past 50,000,000
399
+ // steps, weighted by the work each does, or a tree of 100,000 packages.
400
+ //
353
401
  // The lockfile is held to what a frozen install holds it to, and refused
354
402
  // where pnpm would refuse it: the settings that shaped its resolution —
355
403
  // catalogs, overrides, package extensions, optional dependencies left out,
package/soldeer.d.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  // Hand-written against soldeer.js; a change to either belongs with the other.
2
2
 
3
+ import type { Client } from '@preventive/upstream/github.js'
3
4
  import type { NodeType, Vfs } from '@preventive/vfs'
4
5
 
5
6
  export { LockfileError, TomlError } from '@preventive/lockfile/soldeer.js'
6
7
 
7
- // Where @preventive/upstream caches what it fetches, zips among them. Zips
8
- // are fetched through it, and that is the one place anything here touches
9
- // a filesystem: from its cache, where one is set, which is where it writes
10
- // each zip it fetches; unset, which it is by default, it has none, and
11
- // writes nothing. Soldeer's own folders are never read. The project is
12
- // read only through the view given as `project`, and the tree built in a
13
- // Vfs.
8
+ // Where @preventive/upstream caches what it fetches, zips and GitHub's
9
+ // tarballs among them. Both are fetched through it, and that is the one
10
+ // place anything here touches a filesystem: from its cache, where one is
11
+ // set, which is where it writes each it fetches — setCacheDir() sets the
12
+ // default one, and setCacheDir(false) unsets it; unset, which it is until
13
+ // set, it has none, and writes nothing. Soldeer's own folders are never
14
+ // read. The project is read only through the view given as `project`, and
15
+ // the tree built in a Vfs.
14
16
  export { setCacheDir } from '@preventive/upstream/npm.js'
15
17
 
16
18
  // The machine Soldeer would install on: `soldeer` is the version that
@@ -66,6 +68,11 @@ export interface SoldeerProject {
66
68
  // made, and every file is written where nothing is. The tree is built, and
67
69
  // held to every check below, before any of it is written, so a refusal
68
70
  // leaves the Vfs as it was.
71
+ //
72
+ // `github` is the client from @preventive/upstream/github.js's createClient
73
+ // each git dependency is fetched through, with whatever token it was made
74
+ // with, or none. It is needed only where the lockfile has a git dependency,
75
+ // and there it is a TypeError to leave it out, before anything is fetched.
69
76
  export type SoldeerTreeOptions = SoldeerTreeGiven | SoldeerTreeRead
70
77
 
71
78
  export interface SoldeerTreeGiven {
@@ -75,6 +82,7 @@ export interface SoldeerTreeGiven {
75
82
  project?: undefined
76
83
  host: SoldeerHost
77
84
  vfs?: Vfs
85
+ github?: Client
78
86
  }
79
87
 
80
88
  export interface SoldeerTreeRead {
@@ -84,27 +92,44 @@ export interface SoldeerTreeRead {
84
92
  project: SoldeerProject
85
93
  host: SoldeerHost
86
94
  vfs?: Vfs
95
+ github?: Client
87
96
  }
88
97
 
89
98
  // What buildSoldeerTree counts, all of it plain numbers: `dependencies`
90
- // those installed, each a zip fetched; `files` and `bytes` what is written.
99
+ // those installed, each a zip or a tarball fetched; `files` and `bytes`
100
+ // what is written, and `links` the symlinks, which git dependencies alone
101
+ // have, as a zip's are written as files.
91
102
  export interface SoldeerTreeStats {
92
103
  dependencies: number
93
104
  files: number
94
105
  bytes: number
106
+ links: number
95
107
  }
96
108
 
97
109
  // A dependency in the tree, as an SBOM would list it: `path` is its
98
110
  // folder, from the project's root, which is `/` of the Vfs —
99
111
  // dependencies/<name>-<version>; `name` and `version` the lockfile's, as
100
- // the registry has them; `checksum` the hex sha256 its zip is held to.
101
- export interface SoldeerInstalled {
112
+ // the registry has them, or for a git dependency, the config's. From the
113
+ // registry, `checksum` is the hex sha256 its zip is held to; from git,
114
+ // `git` is the repository's URL and `rev` the commit, as the lockfile has
115
+ // them.
116
+ export type SoldeerInstalled = SoldeerInstalledZip | SoldeerInstalledGit
117
+
118
+ export interface SoldeerInstalledZip {
102
119
  path: string
103
120
  name: string
104
121
  version: string
105
122
  checksum: string
106
123
  }
107
124
 
125
+ export interface SoldeerInstalledGit {
126
+ path: string
127
+ name: string
128
+ version: string
129
+ git: string
130
+ rev: string
131
+ }
132
+
108
133
  // `vfs` is the one given, the tree mounted into it, or a new one.
109
134
  // `installed` is each dependency, in the lockfile's order.
110
135
  export interface SoldeerTree {
@@ -121,9 +146,9 @@ export interface SoldeerTree {
121
146
  // written, and where writing it fails after the install, as Soldeer may on
122
147
  // a remappings.txt it does not read, that is not followed.
123
148
  //
124
- // Each dependency's zip is fetched from Soldeer's registry, as Soldeer
125
- // 0.12 asks the registry for it again rather than taking the lockfile's
126
- // URL, and held to the lockfile's checksum, its sha256. It is extracted as
149
+ // Each registry dependency's zip is fetched from Soldeer's registry, as
150
+ // Soldeer 0.12 asks for it anew rather than taking the lockfile's URL,
151
+ // and held to the lockfile's checksum, its sha256. It is extracted as
127
152
  // Soldeer extracts it, with the zip crate, into a folder of its own: no
128
153
  // root folder taken off; of two entries of one name, the later alone,
129
154
  // where the first was; anything under a `.git` passed over, as Windows
@@ -158,17 +183,45 @@ export interface SoldeerTree {
158
183
  // or normalization are refused, as they would be one name there, and so
159
184
  // is a folder that is one there with another dependency's zip.
160
185
  //
161
- // Dependencies come from Soldeer's registry alone, each by a name and a
162
- // version the registry takes: a dependency from a git repository, which
163
- // Soldeer clones with its history, from a URL the config gives, or one the
164
- // registry keeps private, which it hands out to those signed in alone, is
165
- // refused.
186
+ // A git dependency Soldeer clones, `git clone` of the lockfile's `git`,
187
+ // then `git checkout` of its `rev`; here it is fetched from a GitHub
188
+ // repository alone, by `github`, as GitHub's tarball of the tree of that
189
+ // commit, which upstream holds to the tree GitHub names for the commit. It
190
+ // is written as a checkout with no git config and a umask of 0o022 writes
191
+ // it: each directory 0o755, each file 0o644, or 0o755 where git has it
192
+ // executable; each symlink a symlink to its target, as git has it; a
193
+ // submodule an empty directory, as Soldeer leaves it without
194
+ // recursive_deps; a file the tree's .gitattributes mark `eol=crlf` with
195
+ // CRLF, as upstream reads them. The .git a clone has is not written, so
196
+ // nothing of the repository's history is there; nor is what git config on
197
+ // the machine would change, `core.autocrlf` or a filter such as Git LFS's.
198
+ // Its folder is the config's name and version, which Soldeer's
199
+ // sanitize_filename has to leave as they are. The `git` is the
200
+ // repository's URL over https or ssh, as git takes it —
201
+ // `https://github.com/<owner>/<name>`,
202
+ // `ssh://git@github.com/<owner>/<name>` or
203
+ // `git@github.com:<owner>/<name>`, `.git` after or not; git's http and git
204
+ // protocols, which Soldeer has git refuse, are refused. GitHub's tarball
205
+ // is refused where upstream refuses it — a tree with files marked
206
+ // `export-ignore`, `ident` or `working-tree-encoding`, from a repo set to
207
+ // include Git LFS objects in archives — and where the tar reader of
208
+ // @preventive/archive/tar.js does, as for a symlink whose target climbs
209
+ // out of the tarball; so is a path with a `.git` in it, in any case, which
210
+ // git refuses to check out. That the repository's branches and tags still
211
+ // reach the commit, without which Soldeer's clone does not have it, is not
212
+ // checked: GitHub answers for any commit it has.
213
+ //
214
+ // Dependencies come from Soldeer's registry, each by a name and a version
215
+ // the registry takes, or from GitHub: one from another git host, from a
216
+ // URL the config gives, or one the registry keeps private, which it hands
217
+ // out to those signed in alone, is refused.
166
218
  //
167
219
  // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
168
220
  // config this does not read as Soldeer reads it, a dependency from
169
- // anywhere but the registry, a check above that fails — each is refused
170
- // with a DeptreeError, a LockfileError or a TomlError that says where. A
171
- // TypeError is thrown for options of the wrong type.
221
+ // anywhere but the registry or GitHub, a check above that fails — each is
222
+ // refused with a DeptreeError, a LockfileError or a TomlError that says
223
+ // where. A TypeError is thrown for options of the wrong type, and for a
224
+ // git dependency without `github`.
172
225
  export function buildSoldeerTree(options: SoldeerTreeOptions): Promise<SoldeerTree>
173
226
 
174
227
  // `where` is what a refusal is about — `foundry.toml: profile.default`,
package/src/hash.js CHANGED
@@ -19,8 +19,7 @@ export const sha256Hex = async (text, where) => hex(await digest('SHA-256', utf8
19
19
  const SHIFTS = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21]
20
20
  const SINES = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32) >>> 0)
21
21
  function md5(input) {
22
- const blocks = Math.ceil((input.length + 9) / 64)
23
- const padded = new Uint8Array(blocks * 64)
22
+ const padded = new Uint8Array(Math.ceil((input.length + 9) / 64) * 64)
24
23
  padded.set(input)
25
24
  padded[input.length] = 0x80
26
25
  const view = new DataView(padded.buffer)
@@ -38,10 +37,7 @@ function md5(input) {
38
37
  ;[a, d, c] = [d, c, b]
39
38
  b = (b + ((sum << shift) | (sum >>> (32 - shift)))) >>> 0
40
39
  }
41
- state[0] = (state[0] + a) >>> 0
42
- state[1] = (state[1] + b) >>> 0
43
- state[2] = (state[2] + c) >>> 0
44
- state[3] = (state[3] + d) >>> 0
40
+ for (const [i, word] of [a, b, c, d].entries()) state[i] = (state[i] + word) >>> 0
45
41
  }
46
42
  const bytes = new Uint8Array(16)
47
43
  const out = new DataView(bytes.buffer)
package/src/matcher.js CHANGED
@@ -13,9 +13,10 @@ export function wildcard(pattern, { one = false, any = () => true } = {}) {
13
13
  const onward = (places) => {
14
14
  for (let i = 0; i < end; i++) if (places[i] === 1 && parts[i] === '*') places[i + 1] = 1
15
15
  }
16
+ let here = new Uint8Array(end + 1)
17
+ let next = new Uint8Array(end + 1)
16
18
  return (text) => {
17
- let here = new Uint8Array(end + 1)
18
- let next = new Uint8Array(end + 1)
19
+ here.fill(0)
19
20
  here[0] = 1
20
21
  onward(here)
21
22
  for (const char of text) {
package/src/mount.js CHANGED
@@ -29,6 +29,15 @@ function checkCollisions(vfs) {
29
29
  // A path within a directory: no segment of it empty, `.` or `..`.
30
30
  export const isInside = (path) => path !== '' && path.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..')
31
31
 
32
+ // Whether `child` is `parent` or under it, both paths from one directory in
33
+ // normal form, `.` being that one.
34
+ export const within = (parent, child) => child === parent || (parent === '.' ? child !== '..' && !child.startsWith('../') : child.startsWith(`${parent}/`))
35
+
36
+ // What the lockfile reader refuses in a path: a backslash, a separator on
37
+ // Windows, and what reads otherwise than it is written (a control character,
38
+ // a line or paragraph separator, a bidirectional control).
39
+ export const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
40
+
32
41
  const asRefusal = (error, what, path) => {
33
42
  if (error instanceof VfsError) return new DeptreeError(`cannot be ${what}: ${error.message}`, quote(path), { cause: error })
34
43
  return error
@@ -83,8 +92,9 @@ export function writeLink(vfs, path, target) {
83
92
  }
84
93
  }
85
94
 
86
- // `root` is the package's directory in the tree, without a leading `/`.
87
- export function writeFiles(vfs, root, { dirs, files }, stats, skip = () => false) {
95
+ // `root` is the package's directory in the tree, without a leading `/`;
96
+ // `links` are symlinks within it, by path, to their targets as given.
97
+ export function writeFiles(vfs, root, { dirs, files, links = new Map() }, stats, skip = () => false) {
88
98
  const real = new Set()
89
99
  makeDirs(vfs, root, real)
90
100
  for (const dir of dirs) {
@@ -103,6 +113,16 @@ export function writeFiles(vfs, root, { dirs, files }, stats, skip = () => false
103
113
  stats.files++
104
114
  stats.bytes += file.data.length
105
115
  }
116
+ for (const [path, target] of links) {
117
+ if (skip(path)) continue
118
+ const at = checkWrite(vfs, root, path, real)
119
+ try {
120
+ vfs.symlink(target, at)
121
+ } catch (error) {
122
+ throw asRefusal(error, 'made', `${root}/${path}`)
123
+ }
124
+ stats.links++
125
+ }
106
126
  }
107
127
 
108
128
  // `target` with `tree` in it, or `tree` where there is none; on macOS, two
package/src/npm/bins.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { basename, dirname, join } from '@preventive/vfs/path.js'
8
8
  import { DeptreeError, quote } from '../error.js'
9
- import { isModules } from '../tarball.js'
9
+ import { fixShebang, isModules } from '../tarball.js'
10
10
 
11
11
  const collator = new Intl.Collator('en')
12
12
 
@@ -26,23 +26,6 @@ function modulesOf(location) {
26
26
  return basename(parent) === 'node_modules' ? parent : dirname(parent)
27
27
  }
28
28
 
29
- const decoder = new TextDecoder('utf-8', { fatal: true })
30
-
31
- // bin-links rewrites the file as UTF-8, which it has to be here.
32
- function fixed({ data }, where) {
33
- const newline = data.subarray(0, 2048).indexOf(0x0a)
34
- if (data[0] !== 0x23 || data[1] !== 0x21 || newline < 4 || data[newline - 1] !== 0x0d) return { data, mode: 0o755 }
35
- try {
36
- decoder.decode(data)
37
- } catch {
38
- throw new DeptreeError('a bin with a CRLF shebang that is not UTF-8, which npm rewrites with replacement characters, is not supported', where)
39
- }
40
- const unix = new Uint8Array(data.length - 1)
41
- unix.set(data.subarray(0, newline - 1))
42
- unix.set(data.subarray(newline), newline - 1)
43
- return { data: unix, mode: 0o755 }
44
- }
45
-
46
29
  // The files linking changes, by each package's location.
47
30
  export function fixBins(nodes, fetched) {
48
31
  const seen = new Set()
@@ -64,7 +47,7 @@ export function fixBins(nodes, fetched) {
64
47
  throw new DeptreeError(`${quote(path)} is a directory, which is not supported`, where)
65
48
  }
66
49
  if (!changed.has(location)) changed.set(location, new Map())
67
- changed.get(location).set(path, fixed(file, where))
50
+ changed.get(location).set(path, { data: fixShebang(file.data, 'a bin with a CRLF shebang that is not UTF-8, which npm rewrites with replacement characters, is not supported', where), mode: 0o755 })
68
51
  }
69
52
  }
70
53
  return changed
package/src/npm/compat.js CHANGED
@@ -20,7 +20,7 @@ function listOf(pkg, key, at) {
20
20
  }
21
21
 
22
22
  // A libc fails a host with none, whatever it names.
23
- export function checkPlatform(pkg, host, at) {
23
+ function checkPlatform(pkg, host, at) {
24
24
  for (const key of ['os', 'cpu', 'libc']) {
25
25
  const list = listOf(pkg, key, at)
26
26
  if (list !== undefined && (host[key] === undefined || !takes(host[key], list))) return `its ${key}, ${quote(JSON.stringify(list))}, is not the host's`
@@ -28,7 +28,7 @@ export function checkPlatform(pkg, host, at) {
28
28
  return undefined
29
29
  }
30
30
 
31
- export function checkEngine(pkg, host) {
31
+ function checkEngine(pkg, host) {
32
32
  const { engines } = pkg
33
33
  if (!engines) return undefined
34
34
  const options = { includePrerelease: true }
@@ -37,6 +37,14 @@ export function checkEngine(pkg, host) {
37
37
  return undefined
38
38
  }
39
39
 
40
+ // What npm fails on of a package it does not leave out, `and` said of it.
41
+ export function checkRuns(manifest, host, where, engineStrict, and = '') {
42
+ const platform = checkPlatform(manifest, host, where)
43
+ if (platform !== undefined) throw new DeptreeError(`${platform}${and}, which npm fails on`, where)
44
+ const engine = engineStrict ? checkEngine(manifest, host) : undefined
45
+ if (engine !== undefined) throw new DeptreeError(`${engine}${and}, which npm fails on with engine-strict`, where)
46
+ }
47
+
40
48
  // Arborist's gatherDepSet.
41
49
  function gatherDepSet(set, follow) {
42
50
  const deps = new Set(set)
@@ -74,10 +82,7 @@ export function skippedOf(nodes, host, settings) {
74
82
  if (node.kind !== 'package') continue
75
83
  const where = whereOf(node)
76
84
  if (!node.pkg.optional) {
77
- const platform = checkPlatform(node.manifest, host, where)
78
- if (platform !== undefined) throw new DeptreeError(`${platform}, and it is not optional, which npm fails on`, where)
79
- const engine = settings.engineStrict ? checkEngine(node.manifest, host) : undefined
80
- if (engine !== undefined) throw new DeptreeError(`${engine}, and it is not optional, which npm fails on with engine-strict`, where)
85
+ checkRuns(node.manifest, host, where, settings.engineStrict, ', and it is not optional')
81
86
  continue
82
87
  }
83
88
  if (!host.reuse && skipped.has(node)) continue
package/src/npm/inputs.js CHANGED
@@ -4,17 +4,14 @@ import { valid } from '@preventive/upstream/semver.js'
4
4
  import { DeptreeError, quote } from '../error.js'
5
5
  import { walkWorkspaces } from '../glob.js'
6
6
  import { readManifest, readManifests } from '../manifest.js'
7
- import { checkProject, readText, typeOf } from '../project.js'
7
+ import { checkHostKeys, checkLeftOut, checkProject, checkTexts, readText, typeOf } from '../project.js'
8
8
  import { readSettings } from './settings.js'
9
9
  import { profileOf } from './versions.js'
10
10
 
11
11
  const LIBCS = new Set(['glibc', 'musl'])
12
12
 
13
13
  export function checkHost(host) {
14
- if (host === null || typeof host !== 'object') throw new TypeError('host must be an object with npm, node, os and cpu, and libc on Linux')
15
- for (const key of ['npm', 'node', 'os', 'cpu']) {
16
- if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
17
- }
14
+ checkHostKeys(host, ['npm', 'node', 'os', 'cpu'], 'npm, node, os and cpu, and libc on Linux')
18
15
  if (valid(host.node) !== host.node) throw new DeptreeError(`${quote(host.node)} is not an exact version`, 'host.node')
19
16
  if (host.os === 'win32') throw new DeptreeError('Windows is not supported: npm links bins there with shims, and workspaces with junctions', 'host.os')
20
17
  if (host.os === 'linux' ? !LIBCS.has(host.libc) : host.libc !== undefined) {
@@ -67,14 +64,12 @@ export function inputsOf(options, nocase) {
67
64
  if (lockfile === undefined) {
68
65
  if (project === undefined) throw new TypeError(LOCKFILE)
69
66
  checkProject(project)
70
- for (const [name, value] of Object.entries({ manifests, npmrc })) {
71
- if (value !== undefined) throw new TypeError(`${name} must be left out where lockfile is: both are read from project`)
72
- }
67
+ checkLeftOut({ manifests, npmrc })
73
68
  return readProject(project, nocase)
74
69
  }
75
70
  if (project !== undefined) throw new TypeError('project must be left out where lockfile is given')
76
71
  if (typeof lockfile !== 'string') throw new TypeError(LOCKFILE)
77
72
  if (manifests === null || typeof manifests !== 'object') throw new TypeError('manifests must map each project\'s directory to its package.json')
78
- if (npmrc !== undefined && typeof npmrc !== 'string') throw new TypeError('npmrc must be a string, or left out')
73
+ checkTexts({ npmrc })
79
74
  return { lockfile, manifests: readManifests(manifests), settings: readSettings(npmrc) }
80
75
  }
@@ -4,7 +4,7 @@
4
4
  import { join } from '@preventive/vfs/path.js'
5
5
  import { DeptreeError, quote } from '../error.js'
6
6
  import { own } from '../manifest.js'
7
- import { checkEngine, checkPlatform } from './compat.js'
7
+ import { checkRuns } from './compat.js'
8
8
  import { checkDevEngines } from './dev-engines.js'
9
9
 
10
10
  const where = (dir) => `manifests[${quote(dir)}]`
@@ -102,16 +102,6 @@ function checkWorkspace(dir, manifest, importer) {
102
102
  }
103
103
  }
104
104
 
105
- // The root and workspaces are never left out; npm skips the root's engines
106
- // where it has devEngines.
107
- function checkHostOf(dir, manifest, host, settings) {
108
- const reason = checkPlatform(manifest, host, where(dir))
109
- if (reason !== undefined) throw new DeptreeError(`${reason}, which npm fails on`, where(dir))
110
- if (!settings.engineStrict || (dir === '.' && manifest.devEngines)) return
111
- const engine = checkEngine(manifest, host)
112
- if (engine !== undefined) throw new DeptreeError(`${engine}, which npm fails on with engine-strict`, where(dir))
113
- }
114
-
115
105
  export function checkManifests({ lockfile, manifests, settings, host, rootEdges }) {
116
106
  const root = manifests.get('.')
117
107
  if (root.overrides != null && (typeof root.overrides !== 'object' || Object.keys(root.overrides).length > 0)) {
@@ -133,6 +123,8 @@ export function checkManifests({ lockfile, manifests, settings, host, rootEdges
133
123
  }
134
124
  compareEdges(dir === '.' ? rootEdges : edgesOf(manifest, where(dir), [], settings.legacyPeerDeps), importer, where(dir))
135
125
  if (host.reuse && dir !== '.' && manifest.scripts?.prepare) throw new DeptreeError('a workspace with a prepare script, which npm 10 runs even with --ignore-scripts, is not supported', `${where(dir)}.scripts.prepare`)
136
- checkHostOf(dir, manifest, host, settings)
126
+ // The root and workspaces are never left out; npm skips the root's engines
127
+ // where it has devEngines.
128
+ checkRuns(manifest, host, where(dir), settings.engineStrict && !(dir === '.' && manifest.devEngines))
137
129
  }
138
130
  }
package/src/npmrc.js CHANGED
@@ -7,8 +7,7 @@ import { DeptreeError } from './error.js'
7
7
 
8
8
  export function parseNpmrc(text) {
9
9
  const settings = []
10
- const lines = text.split(/\r\n|\r|\n/u)
11
- for (const [index, raw] of lines.entries()) {
10
+ for (const [index, raw] of text.split(/\r\n|\r|\n/u).entries()) {
12
11
  const line = raw.trim()
13
12
  const where = `.npmrc:${index + 1}`
14
13
  if (line === '' || line.startsWith('#') || line.startsWith(';')) continue