@preventive/deptree 1.0.0-alpha.2 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.0.0-alpha.2",
4
- "description": "A node_modules tree in memory, as a package manager would install it: pnpm 10 or 11, or yarn 1.22, from its lockfile, tarballs fetched and checked, patches applied",
3
+ "version": "1.0.0-alpha.3",
4
+ "description": "A dependency tree in memory, as a package manager would install it: pnpm 10, 11 or 12, or yarn 1.22, from its lockfile, tarballs fetched and checked, patches applied; or Soldeer 0.12, its zips fetched, checked and extracted",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./pnpm.js": {
@@ -11,13 +11,20 @@
11
11
  "./yarn1.js": {
12
12
  "types": "./yarn1.d.ts",
13
13
  "default": "./yarn1.js"
14
+ },
15
+ "./soldeer.js": {
16
+ "types": "./soldeer.d.ts",
17
+ "default": "./soldeer.js"
14
18
  }
15
19
  },
16
20
  "files": [
17
21
  "pnpm.d.ts",
18
22
  "pnpm.js",
23
+ "soldeer.d.ts",
24
+ "soldeer.js",
19
25
  "yarn1.d.ts",
20
26
  "yarn1.js",
27
+ "src/concurrent.js",
21
28
  "src/error.js",
22
29
  "src/hash.js",
23
30
  "src/matcher.js",
@@ -25,6 +32,7 @@
25
32
  "src/patch.js",
26
33
  "src/pnpm/bins.js",
27
34
  "src/pnpm/checks.js",
35
+ "src/pnpm/commands.js",
28
36
  "src/pnpm/filename.js",
29
37
  "src/pnpm/frozen.js",
30
38
  "src/pnpm/graph.js",
@@ -44,6 +52,10 @@
44
52
  "src/pnpm/tree.js",
45
53
  "src/pnpm/uptodate.js",
46
54
  "src/pnpm/workspace.js",
55
+ "src/soldeer/config.js",
56
+ "src/soldeer/inputs.js",
57
+ "src/soldeer/tree.js",
58
+ "src/soldeer/zip.js",
47
59
  "src/tarball.js",
48
60
  "src/yarn1/bins.js",
49
61
  "src/yarn1/compat.js",
package/pnpm.d.ts CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  import type { NodeType, Vfs } from '@preventive/vfs'
4
4
 
5
+ // What the lockfile reader and the YAML parser refuse with: the cause of
6
+ // the DeptreeError that names the file they refused, pnpm-lock.yaml or
7
+ // pnpm-workspace.yaml.
5
8
  export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
6
9
 
7
10
  // Where @preventive/upstream caches what it fetches, tarballs among them.
@@ -17,8 +20,10 @@ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
17
20
  export { setCacheDir } from '@preventive/upstream/npm.js'
18
21
 
19
22
  // The machine pnpm would install on, which a tree depends on: `pnpm` is
20
- // the version that installs, and has to be a 10.x or an 11.x, the two
21
- // built for, each as it differs from the other; left out, it is the one
23
+ // the version that installs, and has to be a 10.x, an 11.x or a 12.x from
24
+ // 12.8.1 on, the three built for, each as it differs from the others; an
25
+ // earlier 12.x installs otherwise in places, and is refused. Left out, it
26
+ // is the one
22
27
  // the root package.json's packageManager pins, which pnpm switches to, and
23
28
  // has to be given where that pins none. `node` is the Node it runs on,
24
29
  // unless the settings name a nodeVersion or, for pnpm 11, the root
@@ -72,7 +77,9 @@ export interface PnpmProject {
72
77
  // `manifests["packages/x"]`, `patches["patches/p.patch"]`.
73
78
  //
74
79
  // Settings from anywhere else — another .npmrc, the environment, the
75
- // command line — are not read, and are taken to be at their defaults.
80
+ // command line — are not read, and are taken to be at their defaults; so
81
+ // is pnpm taken to run as itself, not under corepack, and free to switch
82
+ // to the version a project pins.
76
83
  //
77
84
  // A workspace is one lockfile for several projects, each a package.json:
78
85
  // the root, and every directory pnpm-workspace.yaml's `packages` globs
@@ -105,14 +112,19 @@ export interface PnpmProject {
105
112
  // is read only with `project` given, and only where the directory is
106
113
  // under the lockfile's and holds a package.json there. pnpm links to it by a
107
114
  // path alone or `link:`. By `file:` it installs it as a package, of the
108
- // files npm-packlist's built-in rules keep, which are followed here alone:
109
- // a directory with a .npmignore or .gitignore, a package.json with `files`
110
- // or bundled dependencies, or a link in it, is refused. pnpm hardlinks
111
- // those files from the directory into each snapshot of the package, so a
112
- // file linking a bin makes executable is made so in every snapshot and in
113
- // the directory, which is not written here; a CRLF `#!` line it rewrites
114
- // is rewritten as a file of that snapshot's own. One by `file:` to a
115
- // tarball is refused, and so is a `file:` dependency no override names.
115
+ // files npm-packlist's built-in rules keep — with pnpm 12, its own port's
116
+ // — which are followed here alone: a directory with a .npmignore or
117
+ // .gitignore, a package.json with `files` or bundled dependencies, or a
118
+ // link in it, is refused. pnpm hardlinks those files from the directory
119
+ // into each snapshot of the package, so a file linking a bin makes
120
+ // executable is made so in every snapshot and in the directory, which is
121
+ // not written here; a CRLF `#!` line it rewrites is rewritten as a file of
122
+ // that snapshot's own. Where it builds the package — an install script, a
123
+ // binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
124
+ // .hooks directory — or, with pnpm 11 and 12, where packageImportMethod is
125
+ // other than auto or hardlink, each snapshot has a copy of its own
126
+ // instead. One by `file:` to a tarball is refused, and so is a `file:`
127
+ // dependency no override names.
116
128
  //
117
129
  // Of the .npmrc, only what pnpm reads for an install is read: its settings
118
130
  // by their kebab-case names, those that can change the tree held to what
@@ -133,6 +145,19 @@ export interface PnpmProject {
133
145
  // lockfile against the registry by before it installs — each package's
134
146
  // publish time, its tarball URL, its trust — are passed over.
135
147
  //
148
+ // pnpm 12 reads them so too. Where the root package.json pins a pnpm that
149
+ // host.pnpm is, it fails on a key of pnpm-workspace.yaml it does not know,
150
+ // one of pnpm 11's such as alwaysAuth among them, which is refused; it
151
+ // drops one otherwise, and passes over one not in camelCase it knows. It
152
+ // takes hoistPattern and publicHoistPattern only as lists, and passes over
153
+ // what it has that pnpm 11 has not but `cargo` or `python` enabled, which
154
+ // is refused. It parses every key of pnpm-workspace.yaml into a type of
155
+ // its own, and fails on a value that does not parse, or a `tasks` entry it
156
+ // holds to be wrong: that is not checked here of a key that leaves the
157
+ // tree as it is. Where there is no pnpm-workspace.yaml, it writes one of
158
+ // the root package.json's `workspaces` list, its strings but empty ones,
159
+ // and installs by it, as this does for it.
160
+ //
136
161
  // `project` is read only where it is said to be here: for the files an
137
162
  // install reads, without `lockfile`; for the directories a `link:` or an
138
163
  // override leads to. With it given, a directory the tree links to that is
@@ -212,7 +237,7 @@ export interface PnpmTree {
212
237
  }
213
238
 
214
239
  // The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`
215
- // makes with the isolated linker of host.pnpm, 10 or 11, and no other
240
+ // makes with the isolated linker of host.pnpm, 10, 11 or 12, and no other
216
241
  // install: whatever the
217
242
  // settings say of frozen lockfiles, the install is frozen, which is also
218
243
  // the only one that hoists by the lockfile's graph alone. It is rooted at
@@ -235,6 +260,26 @@ export interface PnpmTree {
235
260
  // aliases, a project's .bin takes the bins of the peers its dependencies
236
261
  // require — and each is built as the one given links them.
237
262
  //
263
+ // pnpm 12, a rewrite of pnpm, makes its tree otherwise again, and it is
264
+ // built as pnpm 12 makes it. It links each package's own bins into its own
265
+ // node_modules/.bin, beside its dependencies', and of two of one name
266
+ // keeps the one of the package whose name sorts first by its bytes; makes
267
+ // a file a bin runs executable without rewriting a CRLF `#!` line, and
268
+ // fails on a bin that is a directory, which is refused; reads `bin` and
269
+ // directories.bin otherwise, dotfiles among them, and a package's null
270
+ // `bin` beside a directories.bin as its store has the package or not,
271
+ // which is refused. It links no package to
272
+ // a dependency of its own name, and writes a file a patch makes as
273
+ // 0o644, whatever mode the patch gives it. It hoists from a graph of every
274
+ // snapshot, those left out walked through but not hoisted, keeps from
275
+ // hoisting the root project's aliases but its `link:`s, those left out
276
+ // among them, and takes the snapshots of one depth in the order of their
277
+ // directories' names. It names a directory under node_modules/.pnpm by the
278
+ // UTF-8 bytes of its key, which only a key that is not ASCII tells. It
279
+ // shares pnpm 11's store, and takes what pnpm 11 left there, such as a
280
+ // patched package as pnpm 11 built it, which is not followed here: the
281
+ // tree is the one a store of pnpm 12's own gives.
282
+ //
238
283
  // The lockfile is held to what a frozen install holds it to, and refused
239
284
  // where pnpm would refuse it: the settings that shaped its resolution —
240
285
  // catalogs, overrides, package extensions, optional dependencies left out,
@@ -257,6 +302,33 @@ export interface PnpmTree {
257
302
  // for it; and a root engines.runtime whose onFail is `error` has to take
258
303
  // host.node.
259
304
  //
305
+ // pnpm 12 reads devEngines.packageManager over packageManager, as pnpm 11
306
+ // does but for the onFail of a list with no pnpm in it, which is its first
307
+ // entry's own. Unless what to do on a mismatch, or pmOnFail, is to ignore,
308
+ // host.pnpm has to be in the pnpm it pins, or the mismatch only to warn,
309
+ // and another package manager is refused unless it is only to warn; and a
310
+ // pin of devEngines, or of a pnpm 12 by packageManager, has to be recorded
311
+ // in the lockfile's env document, of `pnpm` alone at the version pinned,
312
+ // or at host.pnpm for a range, with its package: pnpm 12 runs that one,
313
+ // and fails a frozen install where it is not there.
314
+ //
315
+ // pnpm 12 makes none of pnpm 11's further checks of a lockfile, but holds
316
+ // a directory a project depends on by `file:` to it: each dependency the
317
+ // snapshot has is one its package.json, overridden, asks for, a peer among
318
+ // them; each it asks for is resolved as it asks, an optional one there or
319
+ // not; and its peers, and which are optional, are what the lockfile
320
+ // records. A project the lockfile has no importer for is held to none
321
+ // where it has no dependencies but peers, and refused otherwise. It checks
322
+ // of the projects only the root's engines.node, with engineStrict, and
323
+ // with engineStrict refuses whatever it installs that the host cannot run,
324
+ // though the lockfile mark it optional. An os, cpu or libc list is read
325
+ // by its first entry that names the host's. A patched package's
326
+ // engines.node is held to nodeVersion, or the host's Node, whatever the
327
+ // root's engines.runtime pins. An engines.node npm's semver does not read,
328
+ // or a range of a `-` with an `x`, pnpm 12 reads otherwise, which is
329
+ // refused where it would decide what is installed. host.node is, for pnpm
330
+ // 12, the `node` it finds on the PATH.
331
+ //
260
332
  // And to more than pnpm holds it to, where a lockfile pnpm writes, or a
261
333
  // package the registry serves, always holds: each dependency linked where
262
334
  // the package.json names a directory for it, a path alone among them; each
@@ -275,18 +347,21 @@ export interface PnpmTree {
275
347
  // integrity; each patch to the lockfile's hash of it, and applied only
276
348
  // where every hunk matches exactly where it says.
277
349
  //
278
- // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
279
- // setting this does not know or does not build for, overrides pnpm cannot
280
- // read, a lockfile not resolved with these settings, a package from
281
- // anywhere but the registry, a pnpmfile, package extensions, an injected
282
- // dependency, a lockfile not up to date with a package.json, another
283
- // package manager, a runtime to download, two projects of one name, a
284
- // patch that does not hash or apply, a check above that fails, text
285
- // that is not well-formed where it is hashed, a patch that would change a
286
- // bin's file between two times pnpm links it, a file whose mode would turn
287
- // on the order a directory is read in — each is refused with a
288
- // DeptreeError, a LockfileError or a YamlError that says where. A
289
- // TypeError is thrown for options of the wrong type.
350
+ // Nothing is left to a guess: a lockfile the lockfile reader refuses, or
351
+ // one of the env document pnpm 11 writes alone before anything is
352
+ // installed, a setting this does not know or does not build for, overrides
353
+ // pnpm cannot read, a lockfile not resolved with these settings, a package
354
+ // from anywhere but the registry, a pnpmfile, package extensions, an
355
+ // injected dependency, a lockfile not up to date with a package.json,
356
+ // another package manager, a runtime to download, two projects of one
357
+ // name, a patch that does not hash or apply, a check above that fails,
358
+ // text that is not well-formed where it is hashed, a patch that would
359
+ // change a bin's file between two times pnpm links it, a file whose mode
360
+ // would turn on the order a directory is read in — each is refused with a
361
+ // DeptreeError that says where: where the lockfile reader or the YAML
362
+ // parser refused pnpm-lock.yaml or pnpm-workspace.yaml, it names the file,
363
+ // and its cause is their LockfileError or YamlError. A TypeError is thrown
364
+ // for options of the wrong type.
290
365
  export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
291
366
 
292
367
  // The directories of the projects pnpm finds in `project`, by which
@@ -295,7 +370,8 @@ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
295
370
  // pnpm-workspace.yaml's `packages` takes, as pnpm `host.pnpm` finds them.
296
371
  // pnpm-workspace.yaml is read from `project`, as buildPnpmTree reads it;
297
372
  // so is the root package.json, where host.pnpm is left out, for the pnpm
298
- // its packageManager pins.
373
+ // its packageManager pins, or, for pnpm 12, where there is no
374
+ // pnpm-workspace.yaml, for its `workspaces`.
299
375
  //
300
376
  // Of `project`, besides those, only the directories pnpm walks into are
301
377
  // read: none under node_modules or bower_components, and none whose name
@@ -303,6 +379,13 @@ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
303
379
  // or a link to one; a link that leads nowhere, or to a directory, is none,
304
380
  // as pnpm has it.
305
381
  //
382
+ // pnpm 12 finds them otherwise in places: a `**` may take no directory
383
+ // before one a glob spells with a leading dot; it walks into no
384
+ // node_modules or bower_components, wherever they are; it fails where a
385
+ // glob with a `*` takes a directory whose first manifest there is not a
386
+ // file, which is refused; and the projects come in the order of their
387
+ // paths by name, `a/b` before `a-b`.
388
+ //
306
389
  // Refused: a root with no manifest, which pnpm takes for no project; a
307
390
  // project, the root among them, whose manifest is package.json5 or
308
391
  // package.yaml, which pnpm reads where there is no package.json, or is a
@@ -312,8 +395,9 @@ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
312
395
  // control, bidirectional or backslash character in its path, or a drive
313
396
  // letter; a node_modules pnpm walks into, which it does only under a
314
397
  // directory with a leading dot that a glob spells; a glob buildPnpmTree
315
- // refuses, or a pnpm not 10.x or 11.x; and a pnpm-workspace.yaml that is
316
- // not a mapping, is not UTF-8, or is under another name pnpm refuses.
398
+ // refuses, or a pnpm not 10.x, 11.x or 12.x; and a pnpm-workspace.yaml
399
+ // that is not YAML, is not a mapping, is not UTF-8, or is under another
400
+ // name pnpm refuses.
317
401
  export interface PnpmProjectsOptions {
318
402
  project: PnpmProject
319
403
  host?: Pick<PnpmHost, 'pnpm'>
@@ -322,9 +406,10 @@ export interface PnpmProjectsOptions {
322
406
  export function findPnpmProjects(options: PnpmProjectsOptions): string[]
323
407
 
324
408
  // `where` is what a refusal is about — `pnpm-workspace.yaml: nodeLinker`,
325
- // `.npmrc:3: node-linker`, a package's key — or undefined for the call as
326
- // a whole; the message leads with it. `cause` is what a package beneath
327
- // refused with, where one did.
409
+ // `.npmrc:3: node-linker`, `pnpm-lock.yaml`, a package's key — or
410
+ // undefined for the call as a whole; the message leads with it. `cause` is
411
+ // what a package beneath refused with, where one did: the lockfile
412
+ // reader's LockfileError, its YamlError, a fetch's failure.
328
413
  export class DeptreeError extends Error {
329
414
  constructor(detail: string, where?: string, options?: { cause?: unknown })
330
415
  where: string | undefined
package/pnpm.js CHANGED
@@ -9,6 +9,7 @@ export { DeptreeError } from './src/error.js'
9
9
  // Where @preventive/upstream caches what it fetches, tarballs among it;
10
10
  // unset, it keeps no cache of its own, and writes nothing.
11
11
  export { setCacheDir } from '@preventive/upstream/npm.js'
12
- // What the inputs beneath are refused with: the lockfile, and the YAML of
13
- // it and of pnpm-workspace.yaml.
12
+ // What the readers beneath refuse the lockfile with, and the YAML of it
13
+ // and of pnpm-workspace.yaml: the cause of a DeptreeError that names the
14
+ // file.
14
15
  export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
package/soldeer.d.ts ADDED
@@ -0,0 +1,168 @@
1
+ // Hand-written against soldeer.js; a change to either belongs with the other.
2
+
3
+ import type { NodeType, Vfs } from '@preventive/vfs'
4
+
5
+ export { LockfileError, TomlError } from '@preventive/lockfile/soldeer.js'
6
+
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.
14
+ export { setCacheDir } from '@preventive/upstream/npm.js'
15
+
16
+ // The machine Soldeer would install on: `soldeer` is the version that
17
+ // installs, on its own or as `forge soldeer`, and has to be 0.12.0, which
18
+ // extracts zips otherwise than 0.11 and older; `os` as Node names it —
19
+ // `linux`, `darwin`. Windows is refused: Soldeer names folders and reads
20
+ // paths in zips otherwise there.
21
+ export interface SoldeerHost {
22
+ soldeer: string
23
+ os: string
24
+ }
25
+
26
+ // A view of the project's root, by paths from `/`: a Vfs, or anything
27
+ // with its readdir, lstat, stat and readFile, such as one of a directory
28
+ // on disk, of which only soldeer.lock, foundry.toml and, where there is
29
+ // no foundry.toml, soldeer.toml are read there, as Soldeer reads them,
30
+ // each as UTF-8, and refused where it is not. Nothing is written to it.
31
+ export interface SoldeerProject {
32
+ readdir(path: string): string[]
33
+ lstat(path: string): { type: NodeType }
34
+ stat(path: string): { type: NodeType }
35
+ readFile(path: string): Uint8Array
36
+ }
37
+
38
+ // The files an install reads at the project's root: soldeer.lock, and
39
+ // foundry.toml and soldeer.toml, where they are.
40
+ //
41
+ // Of the two, the config is the one Soldeer reads: foundry.toml, where it
42
+ // has a [dependencies] table, written as one rather than inline; else
43
+ // soldeer.toml, where there is no foundry.toml. Where neither holds, which
44
+ // is so of a foundry.toml with no such table, whatever soldeer.toml there
45
+ // is, Soldeer asks which file to make its config, and that is refused. Of
46
+ // foundry.toml, what Soldeer fails on as it adds `dependencies` to the
47
+ // default profile's libs is refused: a profile or profile.default that is
48
+ // not a table, or written inline, and libs that are not an array. Of the
49
+ // config's [soldeer] settings, a value of a type Soldeer fails on is
50
+ // refused, and so is recursive_deps = true, which has Soldeer install what
51
+ // each dependency depends on too; the others change nothing beneath
52
+ // dependencies/, and any other key is passed over, as Soldeer passes it
53
+ // over. A config whose `dependencies` is inline, which Soldeer reads none
54
+ // from, is refused.
55
+ //
56
+ // The two ways the files come, one or the other: given, with `lockfile`
57
+ // and, where they are, `foundry` and `soldeer`; or read, with `project`
58
+ // and none of them.
59
+ //
60
+ // `vfs` is a Vfs to mount the tree into, at its root, which is taken to be
61
+ // the project's — it may be `project` too; without one, a new Vfs holds
62
+ // the tree alone. A Vfs that holds a `dependencies` at its root, or on
63
+ // macOS a name that is one there, is refused before anything is fetched,
64
+ // as Soldeer would keep or remove what is in it by what it holds. Nothing
65
+ // there is written over: each directory the tree has is one there or is
66
+ // made, and every file is written where nothing is. The tree is built, and
67
+ // held to every check below, before any of it is written, so a refusal
68
+ // leaves the Vfs as it was.
69
+ export type SoldeerTreeOptions = SoldeerTreeGiven | SoldeerTreeRead
70
+
71
+ export interface SoldeerTreeGiven {
72
+ lockfile: string
73
+ foundry?: string
74
+ soldeer?: string
75
+ project?: undefined
76
+ host: SoldeerHost
77
+ vfs?: Vfs
78
+ }
79
+
80
+ export interface SoldeerTreeRead {
81
+ lockfile?: undefined
82
+ foundry?: undefined
83
+ soldeer?: undefined
84
+ project: SoldeerProject
85
+ host: SoldeerHost
86
+ vfs?: Vfs
87
+ }
88
+
89
+ // What buildSoldeerTree counts, all of it plain numbers: `dependencies`
90
+ // those installed, each a zip fetched; `files` and `bytes` what is written.
91
+ export interface SoldeerTreeStats {
92
+ dependencies: number
93
+ files: number
94
+ bytes: number
95
+ }
96
+
97
+ // `vfs` is the one given, the tree mounted into it, or a new one.
98
+ export interface SoldeerTree {
99
+ vfs: Vfs
100
+ stats: SoldeerTreeStats
101
+ }
102
+
103
+ // The dependencies folder `soldeer install` makes from the lockfile, with
104
+ // host.soldeer, in a project with no dependencies folder yet: rooted at
105
+ // the project's root, it holds `dependencies/<name>-<version>` for each
106
+ // dependency, and nothing else of the project. What Soldeer writes beside
107
+ // it — the lockfile again, remappings, foundry.toml's libs — is not
108
+ // written, and where writing it fails after the install, as Soldeer may on
109
+ // a remappings.txt it does not read, that is not followed.
110
+ //
111
+ // Each dependency's zip is fetched from Soldeer's registry, as Soldeer
112
+ // 0.12 asks the registry for it again rather than taking the lockfile's
113
+ // URL, and held to the lockfile's checksum, its sha256. It is extracted as
114
+ // Soldeer extracts it, with the zip crate, into a folder of its own: no
115
+ // root folder taken off; of two entries of one name, the later alone,
116
+ // where the first was; anything under a `.git` passed over, as Windows
117
+ // reads the name — trailing dots and spaces dropped, ASCII letters in
118
+ // either case; each symlink written as a file holding its target. Each
119
+ // directory is 0o755; each file's mode is its Unix mode as the zip crate
120
+ // reads it — from the upper half of its external attributes, by whatever
121
+ // system made it, or none at all for Unix where that is 0, else for MS-DOS
122
+ // from its read-only bit — without the
123
+ // type, setuid, setgid, sticky and group and other write bits; or 0o644,
124
+ // where the zip crate reads none, or for a symlink, or for a file written
125
+ // again by a name the zip crate reads no mode of, the mode it had. Both
126
+ // are as a umask of 0o022 leaves them. The lockfile's integrity, which
127
+ // Soldeer records anew as it installs and does not check, is not checked.
128
+ //
129
+ // The lockfile is held to what the lockfile reader holds it to, with the
130
+ // config: each dependency has its entry, which Soldeer installs it from,
131
+ // and each entry a dependency. And to more than Soldeer holds it to: a zip
132
+ // is read with @preventive/archive/zip.js, which refuses what it does not
133
+ // read — a `..`, absolute or backslashed name, one starting with a drive
134
+ // letter, zip64, encryption, an entry inside one that is not a directory,
135
+ // two entries of one name that differ, a directory by its name or its
136
+ // attributes and not by the other, entries that come to more than 512
137
+ // MiB — where Soldeer would take some of it;
138
+ // and what the zip crate reads otherwise than the archive reader is
139
+ // refused: a name with a byte past ASCII that is not flagged UTF-8, which
140
+ // it reads as CP437, and an AES or a Unicode comment extra field. What
141
+ // Soldeer fails on is refused: a name with a `:` in it, an NTFS extra
142
+ // field or an extended timestamp the zip crate does not read. A folder
143
+ // Soldeer downloads another dependency's zip into, `<folder>.zip`, is
144
+ // refused. On macOS, two names in one directory that differ only in case
145
+ // or normalization are refused, as they would be one name there, and so
146
+ // is a folder that is one there with another dependency's zip.
147
+ //
148
+ // Dependencies come from Soldeer's registry alone, each by a name and a
149
+ // version the registry takes: a dependency from a git repository, which
150
+ // Soldeer clones with its history, from a URL the config gives, or one the
151
+ // registry keeps private, which it hands out to those signed in alone, is
152
+ // refused.
153
+ //
154
+ // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
155
+ // config this does not read as Soldeer reads it, a dependency from
156
+ // anywhere but the registry, a check above that fails — each is refused
157
+ // with a DeptreeError, a LockfileError or a TomlError that says where. A
158
+ // TypeError is thrown for options of the wrong type.
159
+ export function buildSoldeerTree(options: SoldeerTreeOptions): Promise<SoldeerTree>
160
+
161
+ // `where` is what a refusal is about — `foundry.toml: profile.default`,
162
+ // `dependencies["forge-std"]`, an entry of a zip — or undefined for the
163
+ // call as a whole; the message leads with it. `cause` is what a package
164
+ // beneath refused with, where one did.
165
+ export class DeptreeError extends Error {
166
+ constructor(detail: string, where?: string, options?: { cause?: unknown })
167
+ where: string | undefined
168
+ }
package/soldeer.js ADDED
@@ -0,0 +1,12 @@
1
+ // The dependencies folder built in memory from a soldeer.lock, as Soldeer
2
+ // 0.12 installs it: soldeer.d.ts says what it takes and what comes back.
3
+ // The project is read through the view given, and the tree built in a Vfs;
4
+ // the one filesystem touched is that of the cache @preventive/upstream
5
+ // reads, and writes where it keeps one.
6
+ export { buildSoldeerTree } from './src/soldeer/tree.js'
7
+ export { DeptreeError } from './src/error.js'
8
+ // Where @preventive/upstream caches what it fetches, zips among it; unset,
9
+ // it keeps no cache of its own, and writes nothing.
10
+ export { setCacheDir } from '@preventive/upstream/npm.js'
11
+ // What the lockfile, and the config read with it, are refused with.
12
+ export { LockfileError, TomlError } from '@preventive/lockfile/soldeer.js'
@@ -0,0 +1,24 @@
1
+ // The packages a tree is built of are fetched and unpacked a few at a
2
+ // time, so that a large lockfile does not start a request for each at
3
+ // once.
4
+
5
+ const CONCURRENCY = 8
6
+
7
+ // Runs `job` on each of `items`, a few at a time. The first failure stops
8
+ // the rest from starting, and is thrown once every job started has ended,
9
+ // so that none goes on, fetching or writing a cache, after the call has.
10
+ export async function eachConcurrently(items, job) {
11
+ const queue = [...items]
12
+ let failure
13
+ const worker = async () => {
14
+ while (queue.length > 0 && failure === undefined) {
15
+ try {
16
+ await job(queue.shift())
17
+ } catch (error) {
18
+ failure ??= { error }
19
+ }
20
+ }
21
+ }
22
+ await Promise.all(Array.from({ length: Math.min(CONCURRENCY, queue.length) }, worker))
23
+ if (failure !== undefined) throw failure.error
24
+ }
package/src/mount.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // A tree built on its own, mounted into a Vfs the caller already has, at
2
2
  // its root: the lockfile's directory. Nothing there is written over or
3
- // removed. A node_modules there already, anywhere, is refused: kept beside
4
- // the tree, Node would read it as the tree's, and removed, it would be the
5
- // caller's lost; neither is safe. Everything is checked before anything
6
- // is written, so a refusal leaves the Vfs as it was.
3
+ // removed. A node_modules there already, anywhere, is refused, or for
4
+ // another tree what its `check` refuses: kept beside the tree, Node would
5
+ // read it as the tree's, and removed, it would be the caller's lost;
6
+ // neither is safe. Everything is checked before anything is written, so a
7
+ // refusal leaves the Vfs as it was.
7
8
 
8
9
  import { basename, dirname } from '@preventive/vfs/path.js'
9
10
  import { DeptreeError, quote } from './error.js'
@@ -37,8 +38,8 @@ function typeAt(vfs, path) {
37
38
  // already or is made, and each file and link is written where nothing is,
38
39
  // and where names are `folded`, none beside a name it would be one with.
39
40
  // Each file is taken out of `tree` as it is written.
40
- export function mount(tree, target, folded) {
41
- checkNoModules(target, folded)
41
+ export function mount(tree, target, folded, check = checkNoModules) {
42
+ check(target, folded)
42
43
  // The tree's entries, parents first, each with what is there already;
43
44
  // under a directory that is not there, nothing is.
44
45
  const absent = new Set()
package/src/patch.js CHANGED
@@ -124,16 +124,17 @@ const parentsOf = (path) => path.split('/').slice(0, -1).map((_, index, names) =
124
124
  // Applies a parsed patch to a package's files: a Map of each path in the
125
125
  // package to a file, `{ data, mode }`, or to `{ directory: true }` for a
126
126
  // directory. A changed file keeps its mode, and a deleted one leaves its
127
- // directory, empty or not, as pnpm leaves them. Hands back a new Map; the
128
- // one given is left as it is.
129
- export function applyPatch(files, patch) {
127
+ // directory, empty or not, as pnpm leaves them. A file made has the mode
128
+ // its header gives, or `createdMode` where given, as pnpm 12 writes one
129
+ // plain. Hands back a new Map; the one given is left as it is.
130
+ export function applyPatch(files, patch, { createdMode } = {}) {
130
131
  const next = new Map(files)
131
132
  for (const file of patch) {
132
133
  const current = next.get(file.path)
133
134
  if (file.change === 'create') {
134
135
  const taken = current !== undefined || [...next.keys()].some((path) => path.startsWith(`${file.path}/`)) || parentsOf(file.path).some((dir) => next.get(dir)?.data !== undefined)
135
136
  if (taken) throw new DeptreeError('creates a file that is there', file.where)
136
- next.set(file.path, { data: bytesOf(applyTo('', file), file.where), mode: file.mode })
137
+ next.set(file.path, { data: bytesOf(applyTo('', file), file.where), mode: createdMode ?? file.mode })
137
138
  continue
138
139
  }
139
140
  if (current?.data === undefined) throw new DeptreeError('changes a file that is not there', file.where)