@preventive/deptree 1.3.3 → 1.4.1

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 (67) hide show
  1. package/bin/compare.js +5 -2
  2. package/bin/deptree.js +66 -19
  3. package/cocoapods.d.ts +372 -0
  4. package/cocoapods.js +6 -0
  5. package/package.json +23 -5
  6. package/pnpm.d.ts +64 -78
  7. package/soldeer.d.ts +6 -3
  8. package/src/cargo/members.js +3 -2
  9. package/src/cargo/tree.js +2 -2
  10. package/src/cargo/workspace.js +3 -6
  11. package/src/cocoapods/archive.js +223 -0
  12. package/src/cocoapods/clean.js +186 -0
  13. package/src/cocoapods/fnmatch.js +198 -0
  14. package/src/cocoapods/inputs.js +80 -0
  15. package/src/cocoapods/install.js +61 -0
  16. package/src/cocoapods/podspec.js +203 -0
  17. package/src/cocoapods/podtree.js +131 -0
  18. package/src/cocoapods/source.js +90 -0
  19. package/src/cocoapods/tree.js +184 -0
  20. package/src/cocoapods/unicode.js +17 -0
  21. package/src/github.js +92 -0
  22. package/src/glob.js +2 -1
  23. package/src/hash.js +1 -34
  24. package/src/matcher.js +2 -4
  25. package/src/mount.js +2 -5
  26. package/src/npm/compat.js +3 -4
  27. package/src/npm/manifests.js +1 -1
  28. package/src/npm/tree.js +9 -8
  29. package/src/patch.js +9 -5
  30. package/src/pnpm/bins.js +12 -11
  31. package/src/pnpm/commands.js +5 -15
  32. package/src/pnpm/directories.js +250 -0
  33. package/src/pnpm/extensions.js +76 -0
  34. package/src/pnpm/filename.js +4 -4
  35. package/src/pnpm/frozen.js +3 -2
  36. package/src/pnpm/glob.js +1 -1
  37. package/src/pnpm/graph.js +7 -9
  38. package/src/pnpm/hoist.js +0 -36
  39. package/src/pnpm/hoisted.js +3 -3
  40. package/src/pnpm/hook.js +13 -21
  41. package/src/pnpm/inputs.js +6 -18
  42. package/src/pnpm/install.js +3 -4
  43. package/src/pnpm/lazy.js +18 -18
  44. package/src/pnpm/local.js +29 -15
  45. package/src/pnpm/minimatch.js +2 -2
  46. package/src/pnpm/nm-hoist.js +1 -1
  47. package/src/pnpm/npm-packlist.js +1 -1
  48. package/src/pnpm/overrides.js +3 -4
  49. package/src/pnpm/package.js +17 -9
  50. package/src/pnpm/packlist.js +3 -2
  51. package/src/pnpm/patches.js +15 -13
  52. package/src/pnpm/production.js +41 -13
  53. package/src/pnpm/projects.js +14 -40
  54. package/src/pnpm/readers.js +6 -29
  55. package/src/pnpm/settings.js +14 -37
  56. package/src/pnpm/tree.js +36 -26
  57. package/src/pnpm/uptodate.js +12 -13
  58. package/src/pnpm/workspace.js +8 -79
  59. package/src/soldeer/tree.js +2 -2
  60. package/src/soldeer/zip.js +11 -42
  61. package/src/tarball.js +1 -3
  62. package/src/yarn1/hoist.js +4 -2
  63. package/src/yarn1/manifest.js +3 -2
  64. package/src/yarn1/requests.js +1 -1
  65. package/src/yarn1/resolve.js +16 -6
  66. package/src/yarn1/tree.js +12 -8
  67. package/src/soldeer/git.js +0 -67
package/pnpm.d.ts CHANGED
@@ -21,10 +21,13 @@ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
21
21
  export { setCacheDir } from '@preventive/upstream/npm.js'
22
22
 
23
23
  // The machine pnpm would install on, which a tree depends on: `pnpm` is
24
- // the version that installs, and has to be a 9.x from 9.15.0 on, a 10.x,
25
- // an 11.x or a 12.x from 12.8.1 on, the four built for, each as it differs
26
- // from the others; an earlier 9.x or 12.x installs otherwise in places, and
27
- // is refused. Left out, it is the one the root package.json's
24
+ // the version that installs, and has to be a 10.x, an 11.x or a 12.x, the
25
+ // three built for, each as it differs from the others. pnpm 12 is checked
26
+ // against real installs from 12.8.1 on; an earlier one is taken but where
27
+ // its changelog says it installs otherwise, as its bug, which is not built
28
+ // for: a `file:` directory's file whose mode is not 0o644, for 12.8.0, and
29
+ // a production tree an edge to an optional peer changes, before 12.7.0.
30
+ // Left out, it is the one the root package.json's
28
31
  // packageManager pins, which pnpm switches to, and has to be given where
29
32
  // that pins none. `node` is the Node it runs on,
30
33
  // unless the settings name a nodeVersion or, for pnpm 11, the root
@@ -98,8 +101,9 @@ export interface PnpmProject {
98
101
  // Each project is held to its importer as --frozen-lockfile holds it: its
99
102
  // dependencies, devDependencies, optionalDependencies and, with
100
103
  // autoInstallPeers, the peers it lists nowhere else, have to be what the
101
- // importer records, and in the ranges they ask for. The projects' names
102
- // are what hoistWorkspacePackages hoists them by.
104
+ // importer records, and in the ranges they ask for, but `*`, which pnpm
105
+ // resolves to a prerelease `latest` too. The projects' names are what
106
+ // hoistWorkspacePackages hoists them by.
103
107
  //
104
108
  // Settings are read as `pnpm install` 10 reads them, each source over the
105
109
  // one before: the .npmrc, then pnpm-workspace.yaml, then what the
@@ -113,12 +117,12 @@ export interface PnpmProject {
113
117
  // is read only with `project` given, and only where the directory is
114
118
  // under the lockfile's and holds a package.json there. pnpm links to it by a
115
119
  // path alone or `link:`. By `file:` it installs it as a package, of the
116
- // files its packlist picks -- npm-packlist 5.1.3 for pnpm 9 and 10, 10.0.4
120
+ // files its packlist picks -- npm-packlist 5.1.3 for pnpm 10, 10.0.4
117
121
  // for pnpm 11, and pnpm 12's own port of it -- which each is followed here
118
122
  // as that version runs: by package.json's `files`, `main`, `bin` and, but
119
123
  // for pnpm 12, `browser`; by the .npmignore and .gitignore files where it
120
124
  // reads them; and by its own rules, case and all, odd steps among them,
121
- // such as pnpm 9 and 10 keeping what a `files` glob takes that their rules
125
+ // such as pnpm 10 keeping what a `files` glob takes that their rules
122
126
  // leave out, or the minimatch pnpm 10 bundles from 10.31 matching `**`
123
127
  // otherwise. Of glob syntax only `*`, `?` and `**` are followed, which all
124
128
  // read alike: a pattern with braces, a class, an extglob or a backslash is
@@ -126,16 +130,17 @@ export interface PnpmProject {
126
130
  // `files` that is not a list of strings, a file kept by a path a pattern
127
131
  // spells with a `.` part, and a package.json with a byte order mark for
128
132
  // pnpm 11 before 11.28, which fails on it. Refused too, where a pnpm may
129
- // make too large a regexp of it, failing for pnpm 9, 10 and 11 and dropping
133
+ // make too large a regexp of it, failing for pnpm 10 and 11 and dropping
130
134
  // it unread for 12, is a pattern of more than 4096 characters and, for pnpm
131
135
  // 12, an ignore file or `files` of more than 16 KiB; and so are a pattern
132
- // with more than 100 `**` parts for pnpm 9 and 10, and a directory nested
136
+ // with more than 100 `**` parts for pnpm 10, and a directory nested
133
137
  // more than 100 deep, for the time matching them takes. Matching takes
134
138
  // time linear in the path and the pattern. pnpm hardlinks those files from
135
139
  // the directory into each snapshot of the package, in their modes, which
136
140
  // are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
137
- // 0o755 and 0o775. So a file linking a bin makes executable -- 0o755 for
138
- // pnpm 9 and 10, its mode with 0o111 added for 11 and 12 -- is made so in
141
+ // 0o755 and 0o775, and, for pnpm 12.8.0, which installs each at 0o644, any
142
+ // but 0o644. So a file linking a bin makes executable -- 0o755 for
143
+ // pnpm 10, its mode with 0o111 added for 11 and 12 -- is made so in
139
144
  // every snapshot and in the directory, which is not written here; a CRLF
140
145
  // `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package -- an install script, a
141
146
  // binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
@@ -143,17 +148,24 @@ export interface PnpmProject {
143
148
  // other than auto or hardlink, each snapshot has a copy of its own
144
149
  // instead. One by `file:` to a tarball is refused, and so is a `file:`
145
150
  // dependency no override names. One to the lockfile's own directory that
146
- // the lockfile has as `file:` and an empty path, as pnpm 9, 10 and 11
151
+ // the lockfile has as `file:` and an empty path, as pnpm 10 and 11
147
152
  // write it, is refused for pnpm 12, which fails on that lockfile.
148
153
  //
149
- // pnpm 9 reads its settings as pnpm 10 does, but none of
150
- // pnpm-workspace.yaml: of that it reads the projects and the catalogs
151
- // alone, and fails on one that sets anything else but no `packages`, which
152
- // is refused; where one sets nothing, it finds projects everywhere, as `**`
153
- // does. Of the package.json's `pnpm` field it reads fewer keys, and what
154
- // pnpm 10 has that pnpm 9 has no setting for, such as dedupePeers or
155
- // enableGlobalVirtualStore, it passes over. It hoists `*eslint*` and
156
- // `*prettier*` publicly by default.
154
+ // Package extensions, `packageExtensions`, add to the package.json of each
155
+ // package a selector names, by its name and the versions in its range,
156
+ // before the overrides are read: the package.json's own entry in a field
157
+ // wins, and of two extensions the first. The lockfile is held to their
158
+ // checksum, as pnpm holds it: object-hash's sha256 of the setting, its
159
+ // names sorted by code point for pnpm 12. Only what pnpm 10, 11 and 12
160
+ // hash alike is taken: dependencies, optionalDependencies and
161
+ // peerDependencies of names to strings, and peerDependenciesMeta of names
162
+ // to `optional` alone. Refused too: a selector that names no package; an
163
+ // extension that names a project, whose package.json pnpm extends too;
164
+ // for pnpm 12, a range other than comparators and x-ranges joined by
165
+ // spaces and `||`, as it fails on some that npm's semver reads, and a name
166
+ // of digits alone, as it applies them in the order written; and, for pnpm
167
+ // 12 before 12.17.0, an extension of a directory a project depends on by
168
+ // `file:`, which that pnpm holds to its package.json without it.
157
169
  //
158
170
  // Of the .npmrc, only what pnpm reads for an install is read: its settings
159
171
  // by their kebab-case names, those that can change the tree held to what
@@ -217,7 +229,7 @@ export interface PnpmProject {
217
229
  // or is made, and every file and link is written where nothing is. The
218
230
  // tree is built, and held to every check below, before any of it is
219
231
  // written, so a refusal leaves the Vfs as it was. Nothing outside
220
- // node_modules is written, though pnpm 9 and 10 make the files a linked
232
+ // node_modules is written, though pnpm 10 makes the files a linked
221
233
  // directory's bins run executable too.
222
234
  //
223
235
  // `metadata`, true unless given false, has each registry package's version
@@ -272,7 +284,7 @@ export interface PnpmProject {
272
284
  // refused where that package is unpacked. Which of a package's bins pnpm
273
285
  // links turns on the others' bins, and is read only where it could change
274
286
  // the package's files: a bin pnpm would make executable, or whose CRLF `#!`
275
- // line it would make LF; one that is a directory, which pnpm 9 and 12 fail
287
+ // line it would make LF; one that is a directory, which pnpm 12 fails
276
288
  // on; or any bin of a patched package. With the hoisted linker where any
277
289
  // patch is configured, so does what pnpm's build pass does to a package it
278
290
  // builds, patched or with an install script, which is read for every such
@@ -280,9 +292,9 @@ export interface PnpmProject {
280
292
  // read from, but those unpacked already, which are read back from the
281
293
  // tree, and keeps them: with the isolated linker, those the lockfile says
282
294
  // have bins, those that bundle others, those whose bins pnpm reads whatever
283
- // the lockfile says (a project's dependencies with pnpm 9 and 10, their
295
+ // the lockfile says (a project's dependencies with pnpm 10, their
284
296
  // peers with pnpm 11 and 12, and those beside a dependency outside the tree
285
- // with pnpm 9 to 11), and directories, which are read with the tree; with
297
+ // with pnpm 10 and 11), and directories, which are read with the tree; with
286
298
  // the hoisted linker, those the lockfile says have bins, those that bundle
287
299
  // others, and directories, and where a patch is configured, those patched
288
300
  // and those that depend on one with bins, whose bins pnpm's build pass
@@ -308,10 +320,9 @@ export interface PnpmProject {
308
320
  // those the rest reach, through dependencies, optionalDependencies and the
309
321
  // projects they link to. The tree is laid out of those alone -- what the
310
322
  // host cannot run left out as pnpm walks them, hoisted, its bins linked --
311
- // as without it, save that pnpm 9 keeps from hoisting each name the root's
312
- // specifiers have, a devDependency's among them. Nothing else is fetched,
323
+ // as without it. Nothing else is fetched,
313
324
  // nor its files checked; all else is held to the whole lockfile, as
314
- // without it. From pnpm 11.28.0, and in pnpm 12, an edge to an optional
325
+ // without it. From pnpm 11.28.0 and 12.7.0, an edge to an optional
315
326
  // peer, which the snapshot is linked to only as each project that reaches it
316
327
  // lists the peer itself, or as the peer is among the root's devDependencies
317
328
  // and resolvePeersFromWorkspaceRoot is set, is not walked, and is linked
@@ -321,7 +332,11 @@ export interface PnpmProject {
321
332
  // of a key with a hash in place of its peers; before, any dependency by the
322
333
  // name of one of the snapshot's optional peers, though the snapshot
323
334
  // resolved it as its own and its package.json asks for it, as the lockfile
324
- // pnpm 11.28.7 and 12.15.0 on write records.
335
+ // pnpm 11.28.7 and 12.15.0 on write records. pnpm 12 before 12.7.0 walks
336
+ // each such edge, as pnpm 11 before 11.28.0 does; a lockfile where walking
337
+ // those 12.15.0 does not walk installs otherwise, or leaves out otherwise
338
+ // what the host cannot run, is refused, and any other is laid out as both
339
+ // lay it out.
325
340
  //
326
341
  // The two ways the files come, one or the other: given, with `lockfile`
327
342
  // and `manifests`, `project` read only for directories; or read, with
@@ -468,7 +483,7 @@ export interface PnpmLazyTree extends PnpmTree {
468
483
 
469
484
  // The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`,
470
485
  // with `production` --prod too, makes with the isolated linker of
471
- // host.pnpm, 9, 10, 11 or 12, or the hoisted one of pnpm 10 or 11, and no
486
+ // host.pnpm, 10, 11 or 12, or the hoisted one of pnpm 10 or 11, and no
472
487
  // other install: whatever the settings say of frozen lockfiles, the install
473
488
  // is frozen, which is also the only one that hoists by the lockfile's graph
474
489
  // alone. It is rooted at the lockfile's directory: each package's
@@ -487,19 +502,6 @@ export interface PnpmLazyTree extends PnpmTree {
487
502
  // and a write that would replace anything with something else is refused;
488
503
  // into a Vfs given, one that would replace anything at all.
489
504
  //
490
- // pnpm 9 makes its tree as pnpm 10 does but in places, each built as
491
- // pnpm 9 makes it. It ends the name of a directory under
492
- // node_modules/.pnpm it cuts short with 26 base32 characters of an MD5,
493
- // not 32 hex of a SHA-256, and leaves a `#` in it. It hoists from the
494
- // lockfile, not the graph: the snapshots of one depth in the order of
495
- // their keys, not their directories', and an alias taken by a child left
496
- // out, a `link:` or a project as well as by a snapshot hoisted, the root's
497
- // all taken from the start as its specifiers spell them. It takes a bin's
498
- // command by its name before it drops the scope, so links `@x/y z` as
499
- // `y z`, and links a `bin` string, or a directories.bin, where it leads
500
- // out of the package, which is refused; it fails on a bin that is a
501
- // directory, which is refused, where pnpm 10 passes over it.
502
- //
503
505
  // pnpm 11 links bins otherwise in places -- npm owns `npx` and pnpm its
504
506
  // aliases, a project's .bin takes the bins of the peers its dependencies
505
507
  // require -- and each is built as the one given links them.
@@ -574,7 +576,9 @@ export interface PnpmLazyTree extends PnpmTree {
574
576
  // dependency to the catalog's version, a workspace package linked exactly
575
577
  // where its version is in range, and a patch hash in a snapshot's peers to
576
578
  // the patch; it lets an optional dependency the importer has no specifier
577
- // for go unresolved, and takes two spellings of one git commit alike. A
579
+ // for go unresolved, and takes two spellings of one git commit alike. From
580
+ // 11.28.7 it holds each directory snapshot a project reaches by `file:` (from
581
+ // 11.28.10, through a registry package too) to the directory's package.json. A
578
582
  // devEngines.packageManager is refused unless its onFail, or pmOnFail, is
579
583
  // to warn or ignore, as pnpm 11 installs with the pnpm the lockfile pins
580
584
  // for it; and a root engines.runtime whose onFail is `error` has to take
@@ -590,25 +594,15 @@ export interface PnpmLazyTree extends PnpmTree {
590
594
  // or at host.pnpm for a range, with its package: pnpm 12 runs that one,
591
595
  // and fails a frozen install where it is not there.
592
596
  //
593
- // pnpm 9 holds a lockfile to less than pnpm 10: neither to the catalogs
594
- // nor to dedupePeers, nor a dependency's version to its range. It hashes a
595
- // patch with MD5, in base32, and picks one for a package by `name@version`
596
- // as spelled, else by `name`, never by a range. It overrides a peer in
597
- // place, whatever the override. Where the root package.json's
598
- // packageManager pins another pnpm, pnpm 9 installs with itself, unless
599
- // managePackageManagerVersions has it switch to that one, or
600
- // packageManagerStrict and packageManagerStrictVersion have it fail, each
601
- // refused; and it fails on another package manager with
602
- // packageManagerStrict, as it is by default, which is refused. It knows no
603
- // runtime, and holds a project's os, cpu and libc to the host's own,
604
- // whatever supportedArchitectures says.
605
- //
606
597
  // pnpm 12 makes none of pnpm 11's further checks of a lockfile, but holds
607
598
  // a directory a project depends on by `file:` to it: each dependency the
608
599
  // snapshot has is one its package.json, overridden, asks for, a peer among
609
- // them; each it asks for is resolved as it asks, an optional one there or
610
- // not; and its peers, and which are optional, are what the lockfile
611
- // records. A project the lockfile has no importer for is held to none
600
+ // them, an optional peer among its optional dependencies too; each it asks
601
+ // for is resolved as it asks, an optional one there or not, and one in both
602
+ // lists as optional at the dependency's range; and its peers, one only in
603
+ // peerDependenciesMeta at `*`, and which are optional, are what the lockfile
604
+ // records, but one that is a dependency too and that pnpm does not install
605
+ // itself. A project the lockfile has no importer for is held to none
612
606
  // where it has no dependencies but peers, and refused otherwise. It checks
613
607
  // of the projects only the root's engines.node, with engineStrict, and
614
608
  // with engineStrict refuses whatever it installs that the host cannot run,
@@ -629,9 +623,13 @@ export interface PnpmLazyTree extends PnpmTree {
629
623
  // gzipped, every file under one directory, no link or device in it, and
630
624
  // a package.json for exactly its name and version, whose os, cpu, libc,
631
625
  // bins and bundled dependencies are what the lockfile recorded and whose
632
- // every dependency the snapshot has. On macOS, two names in one directory
633
- // that differ only in case or normalization are refused, as they would be
634
- // one name there.
626
+ // every dependency the snapshot has, those package extensions add among
627
+ // them, but one its package.json also has as an optional peer where pnpm
628
+ // may leave that out: before 11.28.0 with autoInstallPeers, and in some
629
+ // graphs until 11.28.6 and 12.14.0; and, for any pnpm, each directory snapshot
630
+ // held so by every path, as no lockfile pnpm writes fails. On macOS, two names
631
+ // in one directory that differ only in case or normalization are refused, as
632
+ // they would be one name there.
635
633
  //
636
634
  // Packages come from https://registry.npmjs.org/ alone, fetched through
637
635
  // @preventive/upstream, and each tarball is held to the lockfile's
@@ -642,7 +640,7 @@ export interface PnpmLazyTree extends PnpmTree {
642
640
  // one of the env document pnpm 11 writes alone before anything is
643
641
  // installed, a setting this does not know or does not build for, overrides
644
642
  // pnpm cannot read, a lockfile not resolved with these settings, a package
645
- // from anywhere but the registry, a pnpmfile, package extensions, an
643
+ // from anywhere but the registry, a pnpmfile, some package extensions, an
646
644
  // injected dependency, a lockfile not up to date with a package.json,
647
645
  // another package manager, a runtime to download, two projects of one
648
646
  // name, a patch that does not hash or apply, a check above that fails,
@@ -679,17 +677,6 @@ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
679
677
  // file, which is refused; and the projects come in the order of their
680
678
  // paths by name, `a/b` before `a-b`.
681
679
  //
682
- // pnpm 9 finds them with fast-glob, otherwise again: past the names before
683
- // a glob's first `**` it walks into every directory, one with a leading
684
- // dot among them, though no `*` or `**` takes a project there; it walks
685
- // from the top for every glob where one has a `*` in its first name; and
686
- // it leaves out what a `!` glob takes, leading dots and all. It reads
687
- // every manifest a project has, not the first, and fails on a glob that
688
- // leads through a file, both refused. Where pnpm-workspace.yaml sets
689
- // nothing, it finds projects everywhere, as `**` does; where it sets
690
- // anything but no `packages`, it fails, which is refused; and it refuses
691
- // no name for it but pnpm-workspace.yml.
692
- //
693
680
  // Refused: a root with no manifest, which pnpm takes for no project; a
694
681
  // project, the root among them, whose manifest is package.json5 or
695
682
  // package.yaml, which pnpm reads where there is no package.json, or is a
@@ -698,9 +685,8 @@ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
698
685
  // project in a directory a lockfile could not key its importer by, with a
699
686
  // control, bidirectional or backslash character in its path, or a drive
700
687
  // letter; a node_modules pnpm walks into, which it does only under a
701
- // directory with a leading dot, one a glob spells or, for pnpm 9, one
702
- // past a `**`; a glob buildPnpmTree refuses, or a pnpm not 9.x, 10.x, 11.x
703
- // or 12.x; and a pnpm-workspace.yaml that is not YAML, is not a mapping,
688
+ // directory with a leading dot, or one a glob spells; a glob
689
+ // buildPnpmTree refuses, or a pnpm not 10.x, 11.x or 12.x; and a pnpm-workspace.yaml that is not YAML, is not a mapping,
704
690
  // is not UTF-8, or is under another name pnpm refuses.
705
691
  export interface PnpmProjectsOptions {
706
692
  project: PnpmProject
package/soldeer.d.ts CHANGED
@@ -186,7 +186,9 @@ export interface SoldeerTree {
186
186
  // A git dependency Soldeer clones, `git clone` of the lockfile's `git`,
187
187
  // then `git checkout` of its `rev`; here it is fetched from a GitHub
188
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. A
189
+ // commit: the tree read off the commit's own object, which upstream's
190
+ // getCommitTree fetches from github.com as git fetches it and holds to the
191
+ // commit's id, and the tarball, which getRepoTreeTarball holds to it. A
190
192
  // repository renamed or transferred since, which GitHub answers with a
191
193
  // redirect that git's clone follows, is fetched by the name GitHub gives
192
194
  // it now, as upstream's getRepo follows that redirect with
@@ -209,8 +211,9 @@ export interface SoldeerTree {
209
211
  // `export-ignore`, `ident` or `working-tree-encoding`, from a repo set to
210
212
  // include Git LFS objects in archives -- and where the tar reader of
211
213
  // @preventive/archive/tar.js does, as for a symlink whose target climbs
212
- // out of the tarball; so is a path with a `.git` in it, in any case, which
213
- // git refuses to check out. That the repository's branches and tags still
214
+ // out of the tarball; so is a path git refuses to check out, with a `.git`
215
+ // in it, or its short name `git~1`, in any case, dots and spaces after it,
216
+ // or a `:` after that. That the repository's branches and tags still
214
217
  // reach the commit, without which Soldeer's clone does not have it, is not
215
218
  // checked: GitHub answers for any commit it has.
216
219
  //
@@ -21,8 +21,9 @@ export function checkLists(workspace) {
21
21
  for (const [index, entry] of (workspace[key] ?? []).entries()) {
22
22
  const where = `Cargo.toml: workspace.${key === 'defaultMembers' ? 'default-members' : key}[${index}]`
23
23
  if (entry.startsWith('/') || UNSAFE.test(entry)) throw new DeptreeError(`${quote(entry)} is not a relative path within the project, which is all that is read`, where)
24
- if (key !== 'exclude' && parts(entry).includes('..')) throw new DeptreeError(`${quote(entry)} leads out of the root, which is not read`, where)
25
- if (key !== 'exclude' && /\*\*|\[/u.test(entry)) throw new DeptreeError(`${quote(entry)} has a \`**\` or a \`[\`, which is not supported`, where)
24
+ if (key === 'exclude') continue
25
+ if (parts(entry).includes('..')) throw new DeptreeError(`${quote(entry)} leads out of the root, which is not read`, where)
26
+ if (/\*\*|\[/u.test(entry)) throw new DeptreeError(`${quote(entry)} has a \`**\` or a \`[\`, which is not supported`, where)
26
27
  }
27
28
  }
28
29
  }
package/src/cargo/tree.js CHANGED
@@ -78,11 +78,11 @@ function checkLock(lock, inputs, crates, vendored) {
78
78
  for (const [dir, key] of keys) if (key in lock.packages) manifests[key] = inputs.packages.get(dir).manifest
79
79
  const texts = new Map(crates.map((crate) => [crate.key, manifestOf(crate, vendored.get(crate.key))]))
80
80
  for (const [key, { manifest }] of texts) manifests[key] = manifest
81
- const members = [...inputs.packages].filter(([dir, { member }]) => member && keys.has(dir)).map(([dir]) => keys.get(dir))
81
+ const members = inputs.packages.entries().filter(([dir, { member }]) => member && keys.has(dir)).map(([dir]) => keys.get(dir)).toArray()
82
82
  checkPaths(linkCargo(lock, manifests, { workspace: inputs.root, members, config: inputs.config }), inputs.packages, keys)
83
83
  const read = readCargoVendor(lock, Object.fromEntries(crates.map((crate) => [crate.directory, { manifest: texts.get(crate.key).text, checksum: vendored.get(crate.key).checksumText }])))
84
84
  for (const crate of crates) if (read[crate.key].directory !== crate.directory) throw new Error(`unreachable: ${crate.key} read back from ${read[crate.key].directory}`)
85
- return new Map([...texts].map(([key, { links }]) => [key, links]))
85
+ return new Map(texts.entries().map(([key, { links }]) => [key, links]))
86
86
  }
87
87
 
88
88
  // Each crate's bytes are let go once its files are written, which copies them.
@@ -147,14 +147,11 @@ function loadMembers(context) {
147
147
  // Each [patch] from a path, the root's from the root and the config's from
148
148
  // the directory its .cargo is in, which is the root too.
149
149
  function patchesOf(root, config) {
150
- const tables = [
151
- ...Object.entries(root.patch).map(([table, specs]) => ({ table, specs, file: 'Cargo.toml' })),
152
- ...Object.entries(config.patch).map(([table, specs]) => ({ table, specs, file: config.file })),
153
- ]
154
- return tables.flatMap(({ table, specs, file }) => Object.entries(specs).filter(([, spec]) => spec.source.type === 'path').map(([name, spec]) => {
150
+ const files = [[root.patch, 'Cargo.toml'], [config.patch, config.file]]
151
+ return files.flatMap(([patch, file]) => Object.entries(patch).flatMap(([table, specs]) => Object.entries(specs).filter(([, spec]) => spec.source.type === 'path').map(([name, spec]) => {
155
152
  const where = `${file}: patch.${quote(table)}.${name}`
156
153
  return { dir: resolvePath('.', spec.source.path, where), name: spec.package, where }
157
- }))
154
+ })))
158
155
  }
159
156
 
160
157
  // `config` is what parseCargoConfig gives, with the `file` it was read from.
@@ -0,0 +1,223 @@
1
+ // An archive by :http as RemoteFile leaves it: saved as `file.<type>` in a
2
+ // directory, extracted there by `tar xf` or `unzip -d` under a umask of
3
+ // 0o022, then flattened where that is asked and it holds one directory.
4
+
5
+ import { decompress } from '@preventive/archive/compression.js'
6
+ import { ArchiveError, unpack } from '@preventive/archive/tar.js'
7
+ import { unzip } from '@preventive/archive/zip.js'
8
+ import { DeptreeError, quote } from '../error.js'
9
+ import { isGit } from '../soldeer/zip.js'
10
+ import { MAX_BYTES } from '../tarball.js'
11
+
12
+ const startsWith = (bytes, magic) => magic.every((byte, i) => bytes[i] === byte)
13
+ const GZIP = [0x1f, 0x8b]
14
+ // A zip, with an entry or empty.
15
+ const ZIPS = [[0x50, 0x4b, 0x03, 0x04], [0x50, 0x4b, 0x05, 0x06]]
16
+ // What `tar xf` decompresses by its magic too, and is not read here.
17
+ const OTHERS = [
18
+ ['bzip2', [0x42, 0x5a, 0x68]], ['xz', [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00]], ['zstd', [0x28, 0xb5, 0x2f, 0xfd]],
19
+ ['compress', [0x1f, 0x9d]], ['lzip', [0x4c, 0x5a, 0x49, 0x50]], ['lzma', [0x5d, 0x00, 0x00]],
20
+ ]
21
+
22
+ // The setuid, setgid and sticky bits.
23
+ const SPECIAL = 0o7000
24
+ const UMASK = 0o022
25
+
26
+ // The names at the archive's root, a directory's that only paths under it
27
+ // name among them.
28
+ const topsOf = ({ dirs, files, links }) => new Set([...dirs, ...files.keys(), ...links.keys()].map((path) => path.split('/')[0]))
29
+
30
+ const gitRefusal = (at) => new DeptreeError('a path with a .git in it, which CocoaPods 1.16 leaves out of its cache and those before keep', at)
31
+ const dirRefusal = (mode, at) => new DeptreeError(`a directory of mode ${mode.toString(8)}, which its owner cannot list and write in, as CocoaPods' cleaner has to`, at)
32
+ const fileRefusal = (mode, at) => new DeptreeError(`a file of mode ${mode.toString(8)}, which its owner cannot read, as CocoaPods' copy has to`, at)
33
+
34
+ async function tarOf(bytes, where) {
35
+ if (startsWith(bytes, GZIP)) return await decompress(bytes, 'gzip', { limit: MAX_BYTES })
36
+ if (ZIPS.some((magic) => startsWith(bytes, magic))) throw new DeptreeError('its archive is a zip, which bsdtar extracts for `tar xf` and GNU tar does not', where)
37
+ const other = OTHERS.find(([, magic]) => startsWith(bytes, magic))
38
+ if (other !== undefined) throw new DeptreeError(`its archive is compressed with ${other[0]}, which is not read here: only gzip is`, where)
39
+ return bytes
40
+ }
41
+
42
+ // Each entry as tar writes it out: a directory, a file with its bytes and
43
+ // its mode under the umask, a link to its target as stored. A hard link is
44
+ // a second name for what it links to, and is copied as rsync -a, which
45
+ // CocoaPods copies the download into its cache with, and FileUtils.cp_r
46
+ // copy one: a file of the same bytes and mode, or a link to the same
47
+ // target. What tar would make otherwise on one machine than on another is
48
+ // refused: a special bit; a directory its owner cannot list and write in,
49
+ // which the cleaner would leave files in; a file its owner cannot read,
50
+ // which the copy fails on; a name starting with `._`, which bsdtar on macOS
51
+ // makes an extended attribute of; a `.git`, which the copy into the cache
52
+ // leaves out from CocoaPods 1.16; a FIFO or a device.
53
+ function entriesOf(entries, where) {
54
+ const dirs = new Set()
55
+ const files = new Map()
56
+ const links = new Map()
57
+ for (const entry of entries) {
58
+ const { name, type } = entry
59
+ if (name === '.' || dirs.has(name) || files.has(name) || links.has(name)) continue
60
+ const at = `${where}: ${quote(name)}`
61
+ const segments = name.split('/')
62
+ if (segments.some(isGit)) throw gitRefusal(at)
63
+ if (segments.some((segment) => segment.startsWith('._'))) throw new DeptreeError('a name starting with `._`, which bsdtar on macOS reads as the extended attributes of another', at)
64
+ const mode = type === 'hardlink' ? undefined : entry.mode
65
+ if (mode !== undefined && type !== 'symlink' && (mode & SPECIAL) !== 0) throw new DeptreeError(`a mode of ${mode.toString(8)}, with a bit tar sets or drops by who extracts it`, at)
66
+ if (type === 'directory') {
67
+ if ((mode & 0o700) !== 0o700) throw dirRefusal(mode, at)
68
+ dirs.add(name)
69
+ } else if (type === 'file' || type === 'contiguous-file') {
70
+ if ((mode & 0o400) === 0) throw fileRefusal(mode, at)
71
+ files.set(name, { data: entry.data, mode: mode & 0o777 & ~UMASK })
72
+ } else if (type === 'symlink') {
73
+ links.set(name, entry.linkname)
74
+ } else if (type === 'hardlink') {
75
+ // The archive reader holds a hard link to an earlier entry.
76
+ if (files.has(entry.linkname)) files.set(name, { ...files.get(entry.linkname) })
77
+ else if (links.has(entry.linkname)) links.set(name, links.get(entry.linkname))
78
+ else throw new DeptreeError(`a hard link to ${quote(entry.linkname)}, which is no file or link`, at)
79
+ } else {
80
+ throw new DeptreeError(`a ${type}, which a pod's download cannot hold`, at)
81
+ }
82
+ }
83
+ return { dirs, files, links }
84
+ }
85
+
86
+ async function untarred(bytes, where) {
87
+ try {
88
+ return entriesOf(unpack(await tarOf(bytes, where), { trailingGlobal: true }), where)
89
+ } catch (error) {
90
+ if (error instanceof ArchiveError) throw new DeptreeError(`its archive cannot be read: ${error.message}`, where, { cause: error })
91
+ throw error
92
+ }
93
+ }
94
+
95
+ // What unzip 6.0 stops to ask about, which fails `pod install` with nothing
96
+ // on stdin.
97
+ const PKZIP_VERSION = 45
98
+ const VMS = 2
99
+
100
+ function checkVersion({ version }, at) {
101
+ const needed = version & 0xff
102
+ if (needed > PKZIP_VERSION) throw new DeptreeError(`needs PKZIP ${(needed / 10).toFixed(1)} to extract, past the 4.5 an unzip built without bzip2 takes`, at)
103
+ if (version >> 8 === VMS) throw new DeptreeError('marked as stored in VMS format, which unzip asks before extracting', at)
104
+ }
105
+
106
+ // A mode as unzip's mapattr() makes one: a Unix maker's as stored, any
107
+ // other's from the DOS bits under the umask, unless the Unix mode it stored
108
+ // agrees with them, as PKZip for Unix writes one; filtattr() then drops the
109
+ // special bits. A symlink is one by its mode, from a maker known to make them.
110
+ const UNIX_HOSTS = new Set([2, 3, 5, 12, 13, 16, 17, 30])
111
+ const SYMLINK_HOSTS = new Set([2, 3, 5, 16, 30])
112
+ const LABEL_HOSTS = new Set([0, 5, 6, 11])
113
+ const MODE_EXTRAS = new Set([0x756e, 0x000c]) // ASI Unix and PKWARE VMS, read where the attributes hold no mode
114
+ const S_IFMT = 0o170000
115
+ const S_IFLNK = 0o120000
116
+ const DOS_READONLY = 1
117
+ const DOS_LABEL = 8
118
+ const DOS_DIRECTORY = 0x10
119
+ const CONTROL_FIELDS = 4 // of the internal attributes: the external ones are then their low byte alone
120
+
121
+ function unzipAttributes({ system, internalAttributes, attributes, extra, storedName }, at) {
122
+ const host = Math.min(system, 31)
123
+ if (host === 1 || host === 18) throw new DeptreeError('made on Amiga or THEOS, whose attributes unzip reads by that system', at)
124
+ const external = internalAttributes & CONTROL_FIELDS ? attributes & 0xff : attributes
125
+ if ((external & DOS_LABEL) !== 0 && LABEL_HOSTS.has(host)) return { label: true }
126
+ let unix = 0
127
+ if (UNIX_HOSTS.has(host)) {
128
+ unix = external >>> 16
129
+ if (unix === 0 && extra.some(({ id }) => MODE_EXTRAS.has(id))) throw new DeptreeError('attributes with no mode, and an extra field unzip reads one from', at)
130
+ return { mode: unix, symlink: (unix & S_IFMT) === S_IFLNK && SYMLINK_HOSTS.has(host) }
131
+ }
132
+ if (host === 0) unix = external >>> 16
133
+ const dos = ((external & DOS_READONLY) === 0 ? 2 : 0) | ((external & DOS_DIRECTORY) !== 0 || storedName.endsWith('/') ? 1 : 0)
134
+ if ((unix & 0o700) === (0o400 | (dos << 6))) return { mode: unix, symlink: (unix & S_IFMT) === S_IFLNK && host === 0 }
135
+ return { mode: (0o444 | (dos << 6) | (dos << 3) | dos) & ~UMASK, symlink: false }
136
+ }
137
+
138
+ // What unzip's mapname() writes otherwise than the reader reads it.
139
+ const NON_ASCII = /[^\u0020-\u007E]/u
140
+ const VMS_VERSION = /;\d*$/u
141
+
142
+ function checkName({ storedName, type }, at) {
143
+ if (NON_ASCII.test(storedName)) throw new DeptreeError('a name with a character outside ASCII, which unzip writes by the machine\'s locale and its own build', at)
144
+ if (type === 'directory') return
145
+ const last = storedName.split('/').at(-1)
146
+ if (last === '.') throw new DeptreeError('a name ending in a `.` segment, which unzip writes as `_`', at)
147
+ if (VMS_VERSION.test(last)) throw new DeptreeError('a name ending in `;` and digits, which unzip takes for a VMS version and drops', at)
148
+ }
149
+
150
+ // Each entry as unzip writes it out, in the central directory's order: a
151
+ // volume label skipped, a directory entry's mode counted only where unzip
152
+ // makes the directory for it.
153
+ async function unzipped(bytes, where) {
154
+ let entries
155
+ try {
156
+ entries = await unzip(bytes, { limit: MAX_BYTES })
157
+ } catch (error) {
158
+ if (error instanceof ArchiveError) throw new DeptreeError(`its archive cannot be read: ${error.message}`, where, { cause: error })
159
+ throw error
160
+ }
161
+ if (entries.length === 0) throw new DeptreeError('an empty archive, which unzip warns of, and CocoaPods fails on the warning', where)
162
+ const dirs = new Set()
163
+ const files = new Map()
164
+ const links = new Map()
165
+ const made = new Set()
166
+ for (const entry of entries) {
167
+ const { name, type } = entry
168
+ if (name === '.') continue
169
+ const at = `${where}: ${quote(entry.storedName)}`
170
+ checkVersion(entry, at)
171
+ const { label, mode, symlink } = unzipAttributes(entry, at)
172
+ if (label) continue
173
+ checkName(entry, at)
174
+ const segments = name.split('/')
175
+ if (segments.some(isGit)) throw gitRefusal(at)
176
+ if (files.has(name) || links.has(name)) throw new DeptreeError('a name again, which unzip asks whether to replace', at)
177
+ if (symlink !== (type === 'symlink')) throw new DeptreeError('a symlink by the attributes of a maker that is not Unix, which unzip makes a link of', at)
178
+ const perms = mode & 0o777
179
+ for (let i = 1; i < segments.length; i++) made.add(segments.slice(0, i).join('/'))
180
+ if (type === 'directory') {
181
+ if (!made.has(name)) {
182
+ if ((perms & 0o700) !== 0o700) throw dirRefusal(perms, at)
183
+ made.add(name)
184
+ }
185
+ dirs.add(name)
186
+ } else if (type === 'symlink') {
187
+ links.set(name, entry.linkname)
188
+ } else {
189
+ if ((perms & 0o400) === 0) throw fileRefusal(perms, at)
190
+ files.set(name, { data: entry.data, mode: perms })
191
+ }
192
+ }
193
+ return { dirs, files, links }
194
+ }
195
+
196
+ // RemoteFile#extract_with_type's flattening: where the directory holds one
197
+ // thing beside the download, and that is a directory, its contents moved
198
+ // up, by a move of it to its name and `.tmp` first. A link there, which
199
+ // Pathname#directory? would follow, is refused, and so is a name the moves
200
+ // would meet: a name ending in `.`, which Pathname#sub_ext reads otherwise
201
+ // than it ends, or something in it of the name it is moved to.
202
+ function flattened(contents, where) {
203
+ const tops = topsOf(contents)
204
+ if (tops.size !== 1) return contents
205
+ const [top] = tops
206
+ if (contents.files.has(top)) return contents
207
+ const at = `${where}: ${quote(top)}`
208
+ if (contents.links.has(top)) throw new DeptreeError('the one thing in the archive is a link, which flattening it would follow', at)
209
+ if (top.endsWith('.')) throw new DeptreeError('the one directory in the archive has a name ending in `.`, which flattening it reads otherwise', at)
210
+ const strip = (path) => path.slice(top.length + 1)
211
+ const inside = (path) => path.startsWith(`${top}/`)
212
+ const stripped = (map) => new Map([...map].map(([path, value]) => [strip(path), value]))
213
+ const moved = { dirs: new Set([...contents.dirs].filter(inside).map(strip)), files: stripped(contents.files), links: stripped(contents.links) }
214
+ if (topsOf(moved).has(`${top}.tmp`)) throw new DeptreeError(`the one directory in the archive holds ${quote(`${top}.tmp`)}, the name it is moved to while it is flattened`, at)
215
+ return moved
216
+ }
217
+
218
+ // `source` is sourceOf's of :http; the contents are as writeFiles takes them.
219
+ export async function archiveOf(bytes, source, where) {
220
+ const contents = source.archive === 'zip' ? await unzipped(bytes, where) : await untarred(bytes, where)
221
+ if (topsOf(contents).has(source.file)) throw new DeptreeError(`the archive holds ${quote(source.file)}, the name RemoteFile downloads it under where it extracts it`, where)
222
+ return source.flatten ? flattened(contents, where) : contents
223
+ }