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

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 (75) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/npm.d.ts +288 -0
  3. package/npm.js +7 -0
  4. package/package.json +36 -10
  5. package/pnpm.d.ts +116 -22
  6. package/pnpm.js +2 -10
  7. package/soldeer.d.ts +13 -0
  8. package/soldeer.js +1 -7
  9. package/src/concurrent.js +16 -17
  10. package/src/error.js +5 -9
  11. package/src/glob.js +55 -0
  12. package/src/hash.js +64 -13
  13. package/src/manifest.js +52 -0
  14. package/src/matcher.js +59 -10
  15. package/src/mount.js +95 -44
  16. package/src/npm/bins.js +71 -0
  17. package/src/npm/compat.js +92 -0
  18. package/src/npm/dev-engines.js +52 -0
  19. package/src/npm/graph.js +68 -0
  20. package/src/npm/inputs.js +80 -0
  21. package/src/npm/manifests.js +138 -0
  22. package/src/npm/package.js +57 -0
  23. package/src/npm/ratio.js +34 -0
  24. package/src/npm/settings.js +67 -0
  25. package/src/npm/tree.js +136 -0
  26. package/src/npm/versions.js +20 -0
  27. package/src/{pnpm/npmrc.js → npmrc.js} +5 -11
  28. package/src/patch.js +21 -31
  29. package/src/pnpm/bins.js +32 -103
  30. package/src/pnpm/checks.js +8 -35
  31. package/src/pnpm/commands.js +49 -86
  32. package/src/pnpm/filename.js +10 -21
  33. package/src/pnpm/frozen.js +27 -70
  34. package/src/pnpm/gitignore.js +137 -0
  35. package/src/pnpm/glob.js +65 -0
  36. package/src/pnpm/graph.js +15 -43
  37. package/src/pnpm/hoist.js +65 -55
  38. package/src/pnpm/hook.js +26 -31
  39. package/src/pnpm/inputs.js +67 -40
  40. package/src/pnpm/install.js +72 -115
  41. package/src/pnpm/local.js +21 -40
  42. package/src/pnpm/minimatch.js +328 -0
  43. package/src/pnpm/npm-packlist.js +221 -0
  44. package/src/pnpm/overrides.js +10 -49
  45. package/src/pnpm/package.js +120 -0
  46. package/src/pnpm/packlist.js +168 -109
  47. package/src/pnpm/patches.js +18 -25
  48. package/src/pnpm/projects.js +63 -107
  49. package/src/pnpm/readers.js +46 -55
  50. package/src/pnpm/settings.js +60 -97
  51. package/src/pnpm/tree.js +134 -149
  52. package/src/pnpm/uptodate.js +16 -28
  53. package/src/pnpm/workspace.js +122 -131
  54. package/src/project.js +41 -0
  55. package/src/soldeer/config.js +8 -24
  56. package/src/soldeer/inputs.js +2 -5
  57. package/src/soldeer/tree.js +20 -56
  58. package/src/soldeer/zip.js +17 -36
  59. package/src/tarball.js +38 -142
  60. package/src/yarn1/bins.js +9 -19
  61. package/src/yarn1/compat.js +9 -28
  62. package/src/yarn1/hoist.js +53 -68
  63. package/src/yarn1/inputs.js +16 -51
  64. package/src/yarn1/manifest.js +8 -23
  65. package/src/yarn1/package.js +24 -63
  66. package/src/yarn1/peers.js +8 -15
  67. package/src/yarn1/requests.js +19 -37
  68. package/src/yarn1/resolve.js +35 -111
  69. package/src/yarn1/settings.js +14 -41
  70. package/src/yarn1/tree.js +67 -91
  71. package/yarn1.d.ts +30 -2
  72. package/yarn1.js +1 -8
  73. package/src/pnpm/project.js +0 -97
  74. package/src/yarn1/glob.js +0 -52
  75. /package/{LICENSE → LICENSE-MIT} +0 -0
package/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/npm.d.ts ADDED
@@ -0,0 +1,288 @@
1
+ // Hand-written against npm.js; a change to either belongs with the other.
2
+
3
+ import type { NodeType, Vfs } from '@preventive/vfs'
4
+
5
+ export { LockfileError } from '@preventive/lockfile/npm.js'
6
+
7
+ // Where @preventive/upstream caches what it fetches, tarballs among them.
8
+ // Tarballs are fetched through it, and that is the one place anything here
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.
16
+ export { setCacheDir } from '@preventive/upstream/npm.js'
17
+
18
+ // The machine npm would install on, which a tree depends on. `npm` is the
19
+ // version that installs, exact: 10.9.3 to 10.9.9, or 11.11.1 to 11.21.0
20
+ // (10.9.0 to 10.9.2 escape a `#` in the project's path, which is not known
21
+ // here); npm reads no packageManager field, so the root package.json's is
22
+ // not read. `node` is
23
+ // the Node npm runs on, an exact version; `os` and `cpu` as Node names
24
+ // them — `linux`, `x64`; and `libc` the C library npm finds on Linux,
25
+ // `glibc` or `musl`, and left out elsewhere, where npm finds none. Windows
26
+ // is refused: npm links bins there with shims, and workspaces with
27
+ // junctions.
28
+ //
29
+ // A package whose os, cpu, libc or engines the host does not take is left
30
+ // out where npm takes it as optional, and with it what npm leaves out with
31
+ // it; one that is not optional is refused where its platform is not the
32
+ // host's, as npm fails on it, and installed where its engines are not, as
33
+ // npm warns of them, unless engine-strict is set. So for the root and each
34
+ // workspace, by their package.json. A libc a package names fails a host
35
+ // with none, whatever it names.
36
+ export interface NpmHost {
37
+ npm: string
38
+ node: string
39
+ os: string
40
+ cpu: string
41
+ libc?: 'glibc' | 'musl'
42
+ }
43
+
44
+ // A view of the lockfile's directory, by paths from `/`: a Vfs, or
45
+ // anything with its readdir, lstat, stat and readFile, such as one of a
46
+ // directory on disk, of which only this is read: the names in a
47
+ // directory; what a path is, `file`, `directory` or `symlink`, with lstat,
48
+ // and what it leads to with stat; and a file's bytes. Each throws an error
49
+ // whose `code` is ENOENT, ENOTDIR or ELOOP for a path that leads nowhere.
50
+ // Nothing is written to it.
51
+ export interface NpmProject {
52
+ readdir(path: string): string[]
53
+ lstat(path: string): { type: NodeType }
54
+ stat(path: string): { type: NodeType }
55
+ readFile(path: string): Uint8Array
56
+ }
57
+
58
+ // The files `npm ci` reads: package-lock.json; the package.json of the
59
+ // root and of every workspace; and the .npmrc, where there is one.
60
+ //
61
+ // With `lockfile`, they are given as text: `manifests` by the project's
62
+ // directory relative to the lockfile's (`.` for the root, then each
63
+ // workspace's, as findNpmWorkspaces lists them: a directory under the
64
+ // lockfile's, with no `.`, `..` or empty segment). Every workspace npm would
65
+ // find has to be given, and none else: the lockfile's have to be those.
66
+ //
67
+ // Without it, they are read from `project`, as npm reads them there, and
68
+ // none of them may be given: package-lock.json, which has to be there; the
69
+ // root package.json, which has to be there too; the package.json of every
70
+ // directory the root's `workspaces` globs take, as npm globs for them,
71
+ // outside node_modules, on macOS whatever the case; and the .npmrc. Each
72
+ // is read as UTF-8, and refused where it is not. A refusal names each as
73
+ // it would given: `manifests["packages/x"]`. Refused there: an
74
+ // npm-shrinkwrap.json, which npm reads in the lockfile's stead; and a link
75
+ // anywhere the globs reach, which glob follows or not by where it is.
76
+ //
77
+ // Settings from anywhere else — an .npmrc in the home directory or npm's
78
+ // own, the environment, NODE_ENV among it, the command line — are not
79
+ // read, and are taken to be at their defaults; so is the directory npm is
80
+ // run in, taken to be the lockfile's, with no workspace above it.
81
+ //
82
+ // Of the .npmrc, as npm reads it: npm hands the install each setting as
83
+ // ini reads it, before it checks it, so `bin-links=0` links bins, "0" being
84
+ // a truthy string. A setting that can change what npm installs is read
85
+ // only in a form with one reading, a key and a value neither quoted,
86
+ // escaped, cut at a `;` or `#`, nor filled in from the environment, and
87
+ // refused in any other. Three are followed: legacy-peer-deps, engine-strict
88
+ // and bin-links, each true or false. install-strategy is taken as hoisted,
89
+ // lockfile-version as 1, 2 or 3, allow-git, allow-directory, allow-file
90
+ // and allow-remote as all, and install-links, force, dry-run, global,
91
+ // package-lock-only, usage and include-workspace-root as false, and refused
92
+ // otherwise. omit, include, production, dev, only, also, optional, os,
93
+ // cpu, libc, workspace, workspaces, location, umask, prefix, globalconfig,
94
+ // userconfig, allow-scripts and a credential not scoped to a registry are
95
+ // refused, whatever their value; so are two settings npm takes as
96
+ // exclusive, set together, and a section. Any other setting is passed
97
+ // over: npm reads it for where it fetches from, how, what it prints, or
98
+ // another command, and the tree is held to the lockfile's integrities
99
+ // whatever serves it.
100
+ //
101
+ // `vfs` is a Vfs to mount the tree into, at its root, which is taken to
102
+ // be the lockfile's directory, beside whatever it holds, such as the
103
+ // projects themselves — it may be `project` too; without one, a new Vfs
104
+ // holds the tree alone. Nothing the tree is built from is read from it. A
105
+ // Vfs that holds a node_modules anywhere, or on macOS a name that is one
106
+ // there, is refused before anything is fetched: kept beside the tree, Node
107
+ // would read it as the tree's, and removed, it would be the caller's lost.
108
+ // Nothing there is written over: each directory the tree has is one there
109
+ // or is made, and every file and link is written where nothing is. The
110
+ // tree is built, and held to every check below, before any of it is
111
+ // written, so a refusal leaves the Vfs as it was.
112
+ export type NpmTreeOptions = NpmTreeGiven | NpmTreeRead
113
+
114
+ export interface NpmTreeGiven {
115
+ lockfile: string
116
+ manifests: Record<string, string> | Map<string, string>
117
+ npmrc?: string
118
+ project?: undefined
119
+ host: NpmHost
120
+ vfs?: Vfs
121
+ }
122
+
123
+ export interface NpmTreeRead {
124
+ lockfile?: undefined
125
+ manifests?: undefined
126
+ npmrc?: undefined
127
+ project: NpmProject
128
+ host: NpmHost
129
+ vfs?: Vfs
130
+ }
131
+
132
+ // What buildNpmTree counts, all of it plain numbers: `packages` the
133
+ // lockfile's, each a copy in a node_modules; `installed` those in the
134
+ // tree; `skipped` those left out, as the host cannot run them or only such
135
+ // need them; `tarballs` those fetched, each once; `files` and `bytes` what
136
+ // is written; `links` the workspaces linked.
137
+ export interface NpmTreeStats {
138
+ packages: number
139
+ installed: number
140
+ skipped: number
141
+ tarballs: number
142
+ files: number
143
+ bytes: number
144
+ links: number
145
+ }
146
+
147
+ // A package in the tree, as an SBOM would list it: `path` is where its
148
+ // files are, the lockfile's key of it, from the lockfile's directory,
149
+ // which is `/` of the Vfs — node_modules/<name>, beneath another package's
150
+ // node_modules, or beneath a workspace's. `name` and `version` are the
151
+ // package's own, whatever alias it is installed as, as the lockfile has
152
+ // them; `integrity` the sha512 its tarball is held to. The flags are those
153
+ // npm installs by, the lockfile's as npm 10 takes them and as npm 11 works
154
+ // them out again: `dev` is whether dev dependencies alone reach it, which
155
+ // --omit=dev leaves out; `optional` whether optional dependencies alone
156
+ // reach it, which --omit=optional leaves out; `devOptional` whether either
157
+ // is, or both together, which --omit=dev with --omit=optional leaves out;
158
+ // `peer` whether peer dependencies alone reach it, which --omit=peer
159
+ // leaves out.
160
+ export interface NpmInstalled {
161
+ path: string
162
+ name: string
163
+ version: string
164
+ integrity: string
165
+ dev: boolean
166
+ optional: boolean
167
+ devOptional: boolean
168
+ peer: boolean
169
+ }
170
+
171
+ // `vfs` is the one given, the tree mounted into it, or a new one.
172
+ // `installed` is each package in the tree, in the lockfile's order; a
173
+ // workspace, whose files the tree does not hold, is not among them.
174
+ export interface NpmTree {
175
+ vfs: Vfs
176
+ stats: NpmTreeStats
177
+ installed: NpmInstalled[]
178
+ }
179
+
180
+ // The node_modules tree `npm ci --ignore-scripts` makes, with host.npm,
181
+ // into a project with no node_modules yet: rooted at the lockfile's
182
+ // directory, each package's files unpacked where the lockfile puts it,
183
+ // and each workspace linked as node_modules/<its name>, by a relative link
184
+ // to its directory, with what the lockfile puts beneath it in that
185
+ // directory's own node_modules. The tree holds node_modules and nothing
186
+ // else of the projects.
187
+ //
188
+ // Each package is unpacked as npm's tar unpacks it: the first segment of
189
+ // each name dropped; a file alone kept, so that a link, a device and a
190
+ // directory entry are passed over and no empty directory is made; each
191
+ // file's mode the tarball's with read and write for all added, and a umask
192
+ // of 0o022 then taken off, so that its execute bits stay; and a .gitignore
193
+ // renamed .npmignore, and dropped where a .npmignore came before it in its
194
+ // directory, or, where one comes after it, holding the second's bytes with
195
+ // the first's mode. Directories are 0o755.
196
+ //
197
+ // Scripts are always ignored, as `--ignore-scripts` has npm ignore them,
198
+ // whatever the settings say; npm 10 runs a workspace's prepare script all
199
+ // the same, and one with a prepare script is refused for it. No .bin is
200
+ // written, nor npm's own node_modules/.package-lock.json; but each bin's
201
+ // target is changed as linking it changes it, unless bin-links is false:
202
+ // of the bins the lockfile gives the packages of one node_modules, the
203
+ // first of each name, as npm sorts its packages by path, is linked, and its
204
+ // target, where the package has it, made 0o755, and the CR dropped from a
205
+ // first line in its first 2048 bytes that is a shebang ending in CRLF. A
206
+ // target that is a directory, runs through a file, or is in the package's
207
+ // own node_modules is refused, and one with such a line that is not UTF-8,
208
+ // which npm rewrites with replacement characters. A workspace's bins are
209
+ // its own files, which the tree does not hold; one in the workspace's own
210
+ // node_modules, or by directories.bin, is refused. So is the root's
211
+ // allowScripts, which npm 11.16 and later read for whose bins to link.
212
+ //
213
+ // npm 10 leaves out an optional package the host cannot run only once it
214
+ // has made directories for every package, and so leaves the directories
215
+ // it was in, a scope's or another package's node_modules, which the tree
216
+ // has too, empty. Of what only such a package needs, npm 11.13 and later
217
+ // leave out too what another left out needs as well. The tar of npm 10.9.9
218
+ // and 11.18 on gives up on a tarball that inflates more than 1000 times
219
+ // what it has read at any point, which is refused where it may, with a
220
+ // margin, as where it checks depends on how the bytes come.
221
+ //
222
+ // The lockfile is held to what the lockfile reader holds it to, with the
223
+ // flags npm installs by: npm 11 works them out again at every install, and
224
+ // npm 10 takes them as written, unless the root package.json asks for
225
+ // other than the lockfile's entry of it to the letter, as one asking for a
226
+ // name in two lists, or for a workspace by name too, does. Each project's
227
+ // package.json is held to the lockfile's entry of its directory: the same
228
+ // names asked for, in the same lists, by the same specs, as npm ci would
229
+ // otherwise resolve them anew or refuse; and each workspace to the name
230
+ // and version the lockfile gives it. The root's devEngines are checked as
231
+ // npm checks them, against the host, which has no os version to check.
232
+ // Refused too, as npm's releases read them otherwise: a range with a
233
+ // wildcard before a number, `1.x.0`, and for npm 10 an optional peer the
234
+ // lockfile does not meet by a range, which it resolves again.
235
+ //
236
+ // And to more than npm holds it to, where a lockfile npm writes, or a
237
+ // package the registry serves, always holds: each tarball gzipped, every
238
+ // entry under one directory, named as tar reads it, with no `\` and no
239
+ // more than 1024 segments, none in the package's own node_modules, where
240
+ // npm installs its dependencies, no setuid, setgid or sticky bit, no link
241
+ // name on a file, no global pax header nor a pax size, which tar's releases
242
+ // read otherwise; each with the sha512 integrity the lockfile records. On
243
+ // macOS, two names in one directory that differ only in case or
244
+ // normalization are refused, as they would be one name there.
245
+ //
246
+ // Packages come from npm's registry alone: each lockfile entry's
247
+ // `resolved` has to be the registry's own URL of its tarball,
248
+ // https://registry.npmjs.org/<name>/-/<base>-<version>.tgz, a scope's `/`
249
+ // as `%2f` or not, or that same URL on yarn's mirror,
250
+ // https://registry.yarnpkg.com/, which is taken for npm's; it is fetched
251
+ // from npm's through @preventive/upstream.
252
+ //
253
+ // 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.
256
+ //
257
+ // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
258
+ // setting this does not know or does not build for, a package from
259
+ // anywhere but the registry — git, a tarball's URL or one on disk, a
260
+ // directory by `file:` — or with no resolved URL, which npm fetches by the
261
+ // registry's packument, a package bundled in another, a link but to a
262
+ // workspace, overrides, acceptDependencies, a check above that fails —
263
+ // each is refused with a DeptreeError or a LockfileError that says where.
264
+ // A TypeError is thrown for options of the wrong type.
265
+ export function buildNpmTree(options: NpmTreeOptions): Promise<NpmTree>
266
+
267
+ // The directories of the projects npm finds in `project`, by which
268
+ // buildNpmTree takes their package.json given: `.`, the root, first, then
269
+ // each directory with a package.json that a glob of the root's
270
+ // `workspaces` takes, outside node_modules, as npm finds them, and as
271
+ // buildNpmTree reads them from a project; with `os` darwin, whatever the
272
+ // case, as npm's glob matches on macOS. Refused as buildNpmTree refuses
273
+ // it: a link where the globs reach; and a root with no package.json.
274
+ export interface NpmWorkspacesOptions {
275
+ project: NpmProject
276
+ os?: string
277
+ }
278
+
279
+ export function findNpmWorkspaces(options: NpmWorkspacesOptions): string[]
280
+
281
+ // `where` is what a refusal is about — `.npmrc:3`, `manifests["."]`, a
282
+ // lockfile entry, `packages["node_modules/a"]` — or undefined for the call
283
+ // as a whole; the message leads with it. `cause` is what a package beneath
284
+ // refused with, where one did.
285
+ export class DeptreeError extends Error {
286
+ constructor(detail: string, where?: string, options?: { cause?: unknown })
287
+ where: string | undefined
288
+ }
package/npm.js ADDED
@@ -0,0 +1,7 @@
1
+ // A node_modules tree built in memory from a package-lock.json, as npm 10
2
+ // or 11 installs it with `npm ci`; see npm.d.ts.
3
+ export { buildNpmTree } from './src/npm/tree.js'
4
+ export { findNpmWorkspaces } from './src/npm/inputs.js'
5
+ export { DeptreeError } from './src/error.js'
6
+ export { setCacheDir } from '@preventive/upstream/npm.js'
7
+ export { LockfileError } from '@preventive/lockfile/npm.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.0.0-alpha.4",
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",
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",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./pnpm.js": {
@@ -12,12 +12,20 @@
12
12
  "types": "./yarn1.d.ts",
13
13
  "default": "./yarn1.js"
14
14
  },
15
+ "./npm.js": {
16
+ "types": "./npm.d.ts",
17
+ "default": "./npm.js"
18
+ },
15
19
  "./soldeer.js": {
16
20
  "types": "./soldeer.d.ts",
17
21
  "default": "./soldeer.js"
18
22
  }
19
23
  },
20
24
  "files": [
25
+ "LICENSE-APACHE",
26
+ "LICENSE-MIT",
27
+ "npm.d.ts",
28
+ "npm.js",
21
29
  "pnpm.d.ts",
22
30
  "pnpm.js",
23
31
  "soldeer.d.ts",
@@ -26,32 +34,50 @@
26
34
  "yarn1.js",
27
35
  "src/concurrent.js",
28
36
  "src/error.js",
37
+ "src/glob.js",
29
38
  "src/hash.js",
39
+ "src/manifest.js",
30
40
  "src/matcher.js",
31
41
  "src/mount.js",
42
+ "src/npm/bins.js",
43
+ "src/npm/compat.js",
44
+ "src/npm/dev-engines.js",
45
+ "src/npm/graph.js",
46
+ "src/npm/inputs.js",
47
+ "src/npm/manifests.js",
48
+ "src/npm/package.js",
49
+ "src/npm/ratio.js",
50
+ "src/npm/settings.js",
51
+ "src/npm/tree.js",
52
+ "src/npm/versions.js",
53
+ "src/npmrc.js",
32
54
  "src/patch.js",
33
55
  "src/pnpm/bins.js",
34
56
  "src/pnpm/checks.js",
35
57
  "src/pnpm/commands.js",
36
58
  "src/pnpm/filename.js",
37
59
  "src/pnpm/frozen.js",
60
+ "src/pnpm/gitignore.js",
61
+ "src/pnpm/glob.js",
38
62
  "src/pnpm/graph.js",
39
- "src/pnpm/hook.js",
40
63
  "src/pnpm/hoist.js",
64
+ "src/pnpm/hook.js",
41
65
  "src/pnpm/inputs.js",
42
66
  "src/pnpm/install.js",
43
67
  "src/pnpm/local.js",
44
- "src/pnpm/npmrc.js",
68
+ "src/pnpm/minimatch.js",
69
+ "src/pnpm/npm-packlist.js",
45
70
  "src/pnpm/overrides.js",
71
+ "src/pnpm/package.js",
46
72
  "src/pnpm/packlist.js",
47
73
  "src/pnpm/patches.js",
48
- "src/pnpm/project.js",
49
74
  "src/pnpm/projects.js",
50
75
  "src/pnpm/readers.js",
51
76
  "src/pnpm/settings.js",
52
77
  "src/pnpm/tree.js",
53
78
  "src/pnpm/uptodate.js",
54
79
  "src/pnpm/workspace.js",
80
+ "src/project.js",
55
81
  "src/soldeer/config.js",
56
82
  "src/soldeer/inputs.js",
57
83
  "src/soldeer/tree.js",
@@ -59,7 +85,6 @@
59
85
  "src/tarball.js",
60
86
  "src/yarn1/bins.js",
61
87
  "src/yarn1/compat.js",
62
- "src/yarn1/glob.js",
63
88
  "src/yarn1/hoist.js",
64
89
  "src/yarn1/inputs.js",
65
90
  "src/yarn1/manifest.js",
@@ -76,7 +101,7 @@
76
101
  "scripts": {
77
102
  "test": "node --test ./tests/*.test.js"
78
103
  },
79
- "license": "MIT",
104
+ "license": "MIT OR Apache-2.0",
80
105
  "author": {
81
106
  "name": "Nikita Skovoroda",
82
107
  "email": "chalkerx@gmail.com",
@@ -95,10 +120,11 @@
95
120
  "access": "public"
96
121
  },
97
122
  "dependencies": {
123
+ "@chalker/queue": "^1.0.1",
98
124
  "@preventive/archive": "1.0.0-beta.3",
99
125
  "@preventive/diff": "^1.0.0",
100
- "@preventive/lockfile": "1.0.0-alpha.4",
101
- "@preventive/upstream": "1.0.0-alpha.2",
102
- "@preventive/vfs": "1.0.0-beta.2"
126
+ "@preventive/lockfile": "1.0.0-alpha.5",
127
+ "@preventive/upstream": "1.0.0-alpha.4",
128
+ "@preventive/vfs": "1.0.0-beta.3"
103
129
  }
104
130
  }