@preventive/deptree 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/deptree.js +2 -1
- package/cocoapods.d.ts +63 -15
- package/npm.d.ts +7 -7
- package/package.json +4 -1
- package/pnpm.d.ts +20 -9
- package/src/cocoapods/inputs.js +9 -0
- package/src/cocoapods/source.js +24 -26
- package/src/cocoapods/tree.js +38 -11
- package/src/npm/compat.js +1 -1
- package/src/npm/dev-engines.js +3 -1
- package/src/npm/inputs.js +3 -3
- package/src/pnpm/inputs.js +4 -7
- package/src/pnpm/install.js +2 -1
- package/src/pnpm/packlist.js +2 -0
- package/src/pnpm/production.js +40 -12
- package/src/pnpm/projects.js +1 -1
- package/src/pnpm/tree.js +2 -2
- package/src/project.js +7 -0
- package/src/yarn1/compat.js +4 -1
- package/src/yarn1/inputs.js +3 -3
- package/yarn1.d.ts +6 -3
package/bin/deptree.js
CHANGED
|
@@ -62,7 +62,8 @@ pod with GITHUB_TOKEN or GH_TOKEN, else anonymously.
|
|
|
62
62
|
out each it does not for where it is from -- a spec
|
|
63
63
|
repo but trunk, an external source but :path and
|
|
64
64
|
:podspec, a source but git by a commit and :http
|
|
65
|
-
from GitHub
|
|
65
|
+
from GitHub or Maven Central's com/facebook/, a
|
|
66
|
+
prepare_command -- and saying why
|
|
66
67
|
--node <version> the Node it installed with; by default this one
|
|
67
68
|
--production devDependencies were left out, as by pnpm install
|
|
68
69
|
--prod, npm ci --omit=dev or yarn install --production
|
package/cocoapods.d.ts
CHANGED
|
@@ -85,15 +85,23 @@ export interface CocoaPodsProject {
|
|
|
85
85
|
// lockfile or its podspec says, rather than refusing the call: one from a
|
|
86
86
|
// spec repo but trunk, or an external source but :path and :podspec; one by
|
|
87
87
|
// :podspec without its podspec, or with CHECKOUT OPTIONS; one with a
|
|
88
|
-
// prepare_command
|
|
89
|
-
// full commit, without its submodules, nor :http as
|
|
90
|
-
// among them. Nothing is written for it, and it is
|
|
91
|
-
// CocoaPods to download: with `manifest`, it
|
|
88
|
+
// prepare_command, without `prepare`; and one whose source is neither git
|
|
89
|
+
// from GitHub by a full commit, without its submodules, nor :http as
|
|
90
|
+
// below: one by a tag among them. Nothing is written for it, and it is
|
|
91
|
+
// listed in `skipped`, for CocoaPods to download: with `manifest`, it
|
|
92
|
+
// downloads those and no other.
|
|
92
93
|
// A podspec is held to the lockfile's checksum all the same, and an archive
|
|
93
94
|
// to its hash. Every other refusal stands. So everything written is held to
|
|
94
95
|
// a hash the lockfile holds, or that a podspec it holds does, whether
|
|
95
96
|
// `partial` is given or not.
|
|
96
97
|
//
|
|
98
|
+
// `only` names the pods to download, by the lockfile's names of them, each
|
|
99
|
+
// once: for a Pods/ that has the others already, as its Manifest.lock
|
|
100
|
+
// says. No other pod is looked at: its podspec is not fetched, nor its
|
|
101
|
+
// source, its prepare_command is not run, and it is neither written,
|
|
102
|
+
// refused nor listed in `skipped`. A name the lockfile has no pod of is
|
|
103
|
+
// refused. Left out, every pod CocoaPods downloads is downloaded.
|
|
104
|
+
//
|
|
97
105
|
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to be
|
|
98
106
|
// the project's -- it may be `project` too; without one, a new Vfs holds
|
|
99
107
|
// the tree alone. A Vfs that holds a `Pods` at its root, or on macOS a name
|
|
@@ -104,6 +112,16 @@ export interface CocoaPodsProject {
|
|
|
104
112
|
// to every check below, before any of it is written, so a refusal leaves
|
|
105
113
|
// the Vfs as it was.
|
|
106
114
|
//
|
|
115
|
+
// `prepare` runs a pod's prepare_command, the script CocoaPods runs with
|
|
116
|
+
// bash in its copy of the download before it cleans it, which nothing here
|
|
117
|
+
// runs: it is called for each pod downloaded whose podspec has one, with
|
|
118
|
+
// the pod's `name` and `version`, the `command` as the podspec gives it,
|
|
119
|
+
// and the download's `contents`, a copy -- and gives back, or comes to, the
|
|
120
|
+
// contents as they are after the command, which are cleaned then as the
|
|
121
|
+
// podspec has them. What the command makes of the download is the caller's
|
|
122
|
+
// to answer for: no hash holds it. Left out, a pod with a prepare_command
|
|
123
|
+
// is refused, or with `partial` skipped.
|
|
124
|
+
//
|
|
107
125
|
// `github` is the client from @preventive/upstream/github.js's createClient
|
|
108
126
|
// each pod is fetched through, with whatever token it was made with, or
|
|
109
127
|
// none. It is needed only where the lockfile has a pod CocoaPods
|
|
@@ -111,6 +129,22 @@ export interface CocoaPodsProject {
|
|
|
111
129
|
// is fetched.
|
|
112
130
|
export type CocoaPodsTreeOptions = CocoaPodsTreeGiven | CocoaPodsTreeRead
|
|
113
131
|
|
|
132
|
+
// A download, or what is left of one, by paths from the pod's directory:
|
|
133
|
+
// its directories, its files, each with its bytes and its mode, and its
|
|
134
|
+
// symlinks, each with its target.
|
|
135
|
+
export interface CocoaPodsContents {
|
|
136
|
+
dirs: Iterable<string>
|
|
137
|
+
files: Map<string, { data: Uint8Array, mode: number }>
|
|
138
|
+
links: Map<string, string>
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface CocoaPodsPrepare {
|
|
142
|
+
name: string
|
|
143
|
+
version: string
|
|
144
|
+
command: string
|
|
145
|
+
contents: CocoaPodsContents
|
|
146
|
+
}
|
|
147
|
+
|
|
114
148
|
export interface CocoaPodsTreeGiven {
|
|
115
149
|
lockfile: string
|
|
116
150
|
podfile?: string | Uint8Array
|
|
@@ -120,6 +154,8 @@ export interface CocoaPodsTreeGiven {
|
|
|
120
154
|
podspecs?: Record<string, string | Uint8Array>
|
|
121
155
|
manifest?: boolean
|
|
122
156
|
partial?: boolean
|
|
157
|
+
only?: string[]
|
|
158
|
+
prepare?: (pod: CocoaPodsPrepare) => CocoaPodsContents | Promise<CocoaPodsContents>
|
|
123
159
|
vfs?: Vfs
|
|
124
160
|
github?: Client
|
|
125
161
|
}
|
|
@@ -133,6 +169,8 @@ export interface CocoaPodsTreeRead {
|
|
|
133
169
|
podspecs?: Record<string, string | Uint8Array>
|
|
134
170
|
manifest?: boolean
|
|
135
171
|
partial?: boolean
|
|
172
|
+
only?: string[]
|
|
173
|
+
prepare?: (pod: CocoaPodsPrepare) => CocoaPodsContents | Promise<CocoaPodsContents>
|
|
136
174
|
vfs?: Vfs
|
|
137
175
|
github?: Client
|
|
138
176
|
}
|
|
@@ -223,8 +261,8 @@ export interface CocoaPodsTree {
|
|
|
223
261
|
// Each root's podspec is fetched from trunk and held to the lockfile's
|
|
224
262
|
// checksum, its sha1, with @preventive/upstream/cocoapods.js's getPodspec;
|
|
225
263
|
// that of a pod by :podspec is `podspecs`', held to it alike. Its `source`
|
|
226
|
-
// has to be a git repository on GitHub, by a full commit, or an archive
|
|
227
|
-
//
|
|
264
|
+
// has to be a git repository on GitHub, by a full commit, or an archive by
|
|
265
|
+
// :http, as below. A git source by a tag is refused: CocoaPods
|
|
228
266
|
// records no commit for one, and GitHub can move it, so nothing would hold
|
|
229
267
|
// what is downloaded to a hash. Of git, CocoaPods clones the repository and
|
|
230
268
|
// checks the commit out, and here GitHub's tarball of the commit's tree is
|
|
@@ -252,16 +290,26 @@ export interface CocoaPodsTree {
|
|
|
252
290
|
// An archive by :http has to be on GitHub, over https: its URL
|
|
253
291
|
// https://github.com/<owner>/<repo>/ and a path under it, such as GitHub's
|
|
254
292
|
// archive of a tag, `archive/refs/tags/<tag>.tar.gz` or `.zip`, or a
|
|
255
|
-
// release's asset
|
|
256
|
-
//
|
|
293
|
+
// release's asset; or in Meta's namespace on Maven Central, which React
|
|
294
|
+
// Native publishes its archives under: its URL
|
|
295
|
+
// https://repo1.maven.org/maven2/com/facebook/ and a path under it, such as
|
|
296
|
+
// `react/react-native-artifacts/<version>/<file>.tar.gz`, ending in
|
|
297
|
+
// `.tar.gz` or `.zip` alone, with no :type, or the tgz or the zip that
|
|
298
|
+
// names. Either as upstream's isPodArchiveUrl takes it: exactly as the URL
|
|
299
|
+
// parser writes it back out, so that no `..` takes it out from under the
|
|
300
|
+
// prefix it is written with, with no query, fragment, credentials or port,
|
|
301
|
+
// each segment of the path letters, digits, `_`, `.`, `~`, `@`, `-` or a
|
|
257
302
|
// %-escape in capitals. The podspec has to hold it to its :sha256, in
|
|
258
303
|
// lowercase hex, as RemoteFile checks one before a :sha1, and does: so the
|
|
259
304
|
// lockfile's checksum of the podspec is the archive's as well. One held to
|
|
260
|
-
// a :sha1 alone, which two archives can be made to share, is refused
|
|
261
|
-
//
|
|
262
|
-
// and
|
|
263
|
-
//
|
|
264
|
-
//
|
|
305
|
+
// a :sha1 alone, which two archives can be made to share, is refused, and
|
|
306
|
+
// so is one held to no hash, as React Native's own podspecs,
|
|
307
|
+
// hermes-engine's and ReactNativeDependencies', name theirs on Maven
|
|
308
|
+
// Central. It is fetched with upstream's getPodArchive, which follows
|
|
309
|
+
// GitHub's redirects, and Maven Central's to repo.reactnative.dev, and
|
|
310
|
+
// holds the bytes to that hash. Its type is RemoteFile's, by :type or else
|
|
311
|
+
// by the end of its URL's path: tgz, tar, tbz or txz, which it extracts
|
|
312
|
+
// with `tar xf`, or zip, with `unzip`; a dmg is refused.
|
|
265
313
|
//
|
|
266
314
|
// A tar is read by what it is, as `tar xf` reads it, gzipped or not, as GNU
|
|
267
315
|
// tar and bsdtar extract one for a user other than root, under a umask of
|
|
@@ -351,8 +399,8 @@ export interface CocoaPodsTree {
|
|
|
351
399
|
// repository of CocoaPods/Specs, by :podspec, or by :path: one from another
|
|
352
400
|
// spec repo, one from any other external source, one by :podspec that
|
|
353
401
|
// CHECKOUT OPTIONS has, which CocoaPods downloads by those, one with a
|
|
354
|
-
// prepare_command, which CocoaPods runs as a script in the download
|
|
355
|
-
// one whose source is neither git from GitHub, by a full commit and
|
|
402
|
+
// prepare_command, which CocoaPods runs as a script in the download and
|
|
403
|
+
// `prepare` is not given to run, and one whose source is neither git from GitHub, by a full commit and
|
|
356
404
|
// without its submodules, nor :http as above, is refused, or with `partial`
|
|
357
405
|
// skipped: one by a tag or a branch among them.
|
|
358
406
|
//
|
package/npm.d.ts
CHANGED
|
@@ -19,12 +19,12 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
19
19
|
// version that installs, exact: 10.9.3 to 10.9.9, or 11.11.1 to 11.21.0
|
|
20
20
|
// (10.9.0 to 10.9.2 escape a `#` in the project's path, which is not known
|
|
21
21
|
// here); npm reads no packageManager field, so the root package.json's is
|
|
22
|
-
// not read. `node` is
|
|
23
|
-
//
|
|
24
|
-
// them -- `linux`, `x64`; and `libc`
|
|
25
|
-
// `glibc` or `musl`, and left out
|
|
26
|
-
//
|
|
27
|
-
// junctions.
|
|
22
|
+
// not read. `node` is the Node npm runs on, an exact version, or left out
|
|
23
|
+
// for one unknown, which every engines.node and devEngines.runtime version
|
|
24
|
+
// takes; `os` and `cpu` as Node names them -- `linux`, `x64`; and `libc`
|
|
25
|
+
// the C library npm finds on Linux, `glibc` or `musl`, and left out
|
|
26
|
+
// elsewhere, where npm finds none. Windows is refused: npm links bins
|
|
27
|
+
// there with shims, and workspaces with junctions.
|
|
28
28
|
//
|
|
29
29
|
// A package whose os, cpu, libc or engines the host does not take is left
|
|
30
30
|
// out where npm takes it as optional, and with it what npm leaves out with
|
|
@@ -35,7 +35,7 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
35
35
|
// with none, whatever it names.
|
|
36
36
|
export interface NpmHost {
|
|
37
37
|
npm: string
|
|
38
|
-
node
|
|
38
|
+
node?: string
|
|
39
39
|
os: string
|
|
40
40
|
cpu: string
|
|
41
41
|
libc?: 'glibc' | 'musl'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/deptree",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "In-memory dependency tree, as a package manager installs it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"./cocoapods.js": {
|
|
28
28
|
"types": "./cocoapods.d.ts",
|
|
29
29
|
"default": "./cocoapods.js"
|
|
30
|
+
},
|
|
31
|
+
"./src/cocoapods/fnmatch.js": {
|
|
32
|
+
"default": "./src/cocoapods/fnmatch.js"
|
|
30
33
|
}
|
|
31
34
|
},
|
|
32
35
|
"bin": {
|
package/pnpm.d.ts
CHANGED
|
@@ -21,13 +21,19 @@ 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 10.x, an 11.x or a 12.x
|
|
25
|
-
//
|
|
26
|
-
//
|
|
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
|
|
27
31
|
// packageManager pins, which pnpm switches to, and has to be given where
|
|
28
|
-
// that pins none. `node` is the Node it runs on,
|
|
32
|
+
// that pins none. `node` is the Node it runs on, an exact version,
|
|
29
33
|
// unless the settings name a nodeVersion or, for pnpm 11, the root
|
|
30
|
-
// package.json's engines.runtime pins one;
|
|
34
|
+
// package.json's engines.runtime pins one; left out, with none of those,
|
|
35
|
+
// the Node is unknown, and every engines.node and range for Node takes it,
|
|
36
|
+
// so nothing is refused or left out for it; `os`, `cpu` and `libc` as Node
|
|
31
37
|
// and pnpm name them -- `linux`, `x64`, `glibc` -- with `unknown` for a libc
|
|
32
38
|
// outside Linux, as pnpm has it.
|
|
33
39
|
// Windows is refused: pnpm links there with junctions to absolute paths.
|
|
@@ -35,7 +41,7 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
35
41
|
// it out; supportedArchitectures in the settings widens what is taken.
|
|
36
42
|
export interface PnpmHost {
|
|
37
43
|
pnpm?: string
|
|
38
|
-
node
|
|
44
|
+
node?: string
|
|
39
45
|
os: string
|
|
40
46
|
cpu: string
|
|
41
47
|
libc: 'glibc' | 'musl' | 'unknown'
|
|
@@ -134,7 +140,8 @@ export interface PnpmProject {
|
|
|
134
140
|
// time linear in the path and the pattern. pnpm hardlinks those files from
|
|
135
141
|
// the directory into each snapshot of the package, in their modes, which
|
|
136
142
|
// are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
|
|
137
|
-
// 0o755 and 0o775
|
|
143
|
+
// 0o755 and 0o775, and, for pnpm 12.8.0, which installs each at 0o644, any
|
|
144
|
+
// but 0o644. So a file linking a bin makes executable -- 0o755 for
|
|
138
145
|
// pnpm 10, its mode with 0o111 added for 11 and 12 -- is made so in
|
|
139
146
|
// every snapshot and in the directory, which is not written here; a CRLF
|
|
140
147
|
// `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package -- an install script, a
|
|
@@ -317,7 +324,7 @@ export interface PnpmProject {
|
|
|
317
324
|
// host cannot run left out as pnpm walks them, hoisted, its bins linked --
|
|
318
325
|
// as without it. Nothing else is fetched,
|
|
319
326
|
// nor its files checked; all else is held to the whole lockfile, as
|
|
320
|
-
// without it. From pnpm 11.28.0
|
|
327
|
+
// without it. From pnpm 11.28.0 and 12.7.0, an edge to an optional
|
|
321
328
|
// peer, which the snapshot is linked to only as each project that reaches it
|
|
322
329
|
// lists the peer itself, or as the peer is among the root's devDependencies
|
|
323
330
|
// and resolvePeersFromWorkspaceRoot is set, is not walked, and is linked
|
|
@@ -327,7 +334,11 @@ export interface PnpmProject {
|
|
|
327
334
|
// of a key with a hash in place of its peers; before, any dependency by the
|
|
328
335
|
// name of one of the snapshot's optional peers, though the snapshot
|
|
329
336
|
// resolved it as its own and its package.json asks for it, as the lockfile
|
|
330
|
-
// pnpm 11.28.7 and 12.15.0 on write records.
|
|
337
|
+
// pnpm 11.28.7 and 12.15.0 on write records. pnpm 12 before 12.7.0 walks
|
|
338
|
+
// each such edge, as pnpm 11 before 11.28.0 does; a lockfile where walking
|
|
339
|
+
// those 12.15.0 does not walk installs otherwise, or leaves out otherwise
|
|
340
|
+
// what the host cannot run, is refused, and any other is laid out as both
|
|
341
|
+
// lay it out.
|
|
331
342
|
//
|
|
332
343
|
// The two ways the files come, one or the other: given, with `lockfile`
|
|
333
344
|
// and `manifests`, `project` read only for directories; or read, with
|
package/src/cocoapods/inputs.js
CHANGED
|
@@ -34,6 +34,15 @@ export function flagsOf({ manifest = false, partial = false }) {
|
|
|
34
34
|
return { manifest, partial }
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
// `only`, the names of the pods to download, each once; undefined for every
|
|
38
|
+
// pod there is.
|
|
39
|
+
const ONLY = 'only must be a list of the names of pods, each once, or left out'
|
|
40
|
+
export function onlyOf(only) {
|
|
41
|
+
if (only === undefined) return undefined
|
|
42
|
+
if (!Array.isArray(only) || only.some((name) => typeof name !== 'string') || new Set(only).size !== only.length) throw new TypeError(ONLY)
|
|
43
|
+
return new Set(only)
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
// The names CocoaPods reads a Podfile under, the first one there taken.
|
|
38
47
|
const PODFILES = ['CocoaPods.podfile.yaml', 'CocoaPods.podfile', 'Podfile', 'Podfile.rb']
|
|
39
48
|
|
package/src/cocoapods/source.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Where a pod is downloaded from: its podspec's `source`, as
|
|
2
2
|
// cocoapods-downloader takes it, held to what is fetched here alike.
|
|
3
3
|
|
|
4
|
+
import { isPodArchiveUrl } from '@preventive/upstream/cocoapods.js'
|
|
4
5
|
import { DeptreeError, quote } from '../error.js'
|
|
5
6
|
import { githubRepoOf } from '../github.js'
|
|
6
7
|
import { given, isObject } from './podspec.js'
|
|
@@ -23,18 +24,9 @@ const SHA256 = /^[\da-f]{64}$/u
|
|
|
23
24
|
const TARS = new Set(['tgz', 'tar', 'tbz', 'txz'])
|
|
24
25
|
const TYPES = new Set([...TARS, 'zip', 'dmg'])
|
|
25
26
|
const URL_TYPES = [[/\.zip$/u, 'zip'], [/\.(?:tgz|tar\.gz)$/u, 'tgz'], [/\.tar$/u, 'tar'], [/\.(?:tbz|tar\.bz2)$/u, 'tbz'], [/\.(?:txz|tar\.xz)$/u, 'txz'], [/\.dmg$/u, 'dmg']]
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
const LOGIN = /^(?=.{1,39}$)[a-z\d](?:-?[a-z\d])*$/iu
|
|
30
|
-
const REPO_NAME = /^(?!\.\.?$)[\w.-]{1,100}$/u
|
|
31
|
-
const SEGMENT = /^(?!\.\.?$)(?:[\w.~@-]|%[\dA-F]{2})+$/u
|
|
32
|
-
function isGitHubUrl(url) {
|
|
33
|
-
const parsed = URL.parse(url)
|
|
34
|
-
if (parsed?.href !== url || parsed.origin !== 'https://github.com' || parsed.username !== '' || parsed.password !== '' || parsed.search !== '' || parsed.hash !== '') return false
|
|
35
|
-
const segments = parsed.pathname.slice(1).split('/')
|
|
36
|
-
return segments.length >= 3 && LOGIN.test(segments[0]) && REPO_NAME.test(segments[1]) && segments.every((segment) => SEGMENT.test(segment))
|
|
37
|
-
}
|
|
27
|
+
// Meta's namespace on Maven Central, a .tar.gz or a .zip under which
|
|
28
|
+
// upstream's isPodArchiveUrl takes.
|
|
29
|
+
const MAVEN_FACEBOOK = 'https://repo1.maven.org/maven2/com/facebook/'
|
|
38
30
|
|
|
39
31
|
// A refusal of where a pod is downloaded from, which buildCocoaPodsTree's
|
|
40
32
|
// `partial` leaves the pod to CocoaPods for; a DeptreeError otherwise.
|
|
@@ -42,18 +34,20 @@ export class SourceRefusal extends DeptreeError {}
|
|
|
42
34
|
|
|
43
35
|
// The podspec's source: git, a GitHub repository by its URL and the full
|
|
44
36
|
// commit to check out of it; or :http, an archive on GitHub over https,
|
|
45
|
-
// `tar xf` or `unzip` extracts,
|
|
37
|
+
// `tar xf` or `unzip` extracts, or a .tar.gz or a .zip under Maven
|
|
38
|
+
// Central's com/facebook/, and the hash the podspec holds it to. A
|
|
46
39
|
// tag is refused, as the lockfile holds no commit for one and GitHub can
|
|
47
40
|
// move it. A prepare_command, a script CocoaPods runs in the download, is
|
|
48
|
-
// refused
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
// refused unless `prepares`, where the caller runs it, as is any other
|
|
42
|
+
// source, each with a SourceRefusal.
|
|
43
|
+
export function sourceOf(podspec, where, prepares = false) {
|
|
44
|
+
if (given(podspec.attributes.prepare_command) && !prepares) throw new SourceRefusal('a prepare_command, a script CocoaPods runs in the download, is not supported', where)
|
|
51
45
|
const source = podspec.attributes.source
|
|
52
46
|
if (!isObject(source)) throw new SourceRefusal('its podspec has no source to download it from', where)
|
|
53
47
|
const strategies = STRATEGIES.filter((strategy) => Object.hasOwn(source, strategy))
|
|
54
48
|
if (strategies.length !== 1) throw new SourceRefusal('its podspec\'s source names no one way to download it, which CocoaPods fails on', where)
|
|
55
49
|
if (strategies[0] === 'http') return httpSourceOf(source, where)
|
|
56
|
-
if (strategies[0] !== 'git') throw new SourceRefusal(`a source by :${strategies[0]} is not supported: only git from GitHub, and :http from GitHub
|
|
50
|
+
if (strategies[0] !== 'git') throw new SourceRefusal(`a source by :${strategies[0]} is not supported: only git from GitHub, and :http from GitHub or Maven Central's com/facebook/, are`, where)
|
|
57
51
|
const other = Object.keys(source).find((key) => !GIT_OPTIONS.has(key))
|
|
58
52
|
if (other !== undefined) throw new SourceRefusal(`its source has :${other}, which cocoapods-downloader refuses of git`, where)
|
|
59
53
|
const { git: url, tag, commit, branch, submodules } = source
|
|
@@ -67,20 +61,24 @@ export function sourceOf(podspec, where) {
|
|
|
67
61
|
return { type: 'git', url, repo, commit }
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
// An :http source: its URL,
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
64
|
+
// An :http source: its URL, one upstream's getPodArchive fetches, on GitHub
|
|
65
|
+
// or a .tar.gz or a .zip under Maven Central's com/facebook/, of the type
|
|
66
|
+
// its URL names, by :type too; what RemoteFile takes it to be, and so the
|
|
67
|
+
// name it downloads it under, `file.<type>`, in the directory it extracts
|
|
68
|
+
// it into; whether it flattens it, by :flatten where that is given, as Ruby
|
|
69
|
+
// reads a value, and else by its type, a tar and not a zip; and the sha256
|
|
70
|
+
// it checks it against. A download held to no hash, or to a sha1 alone, is
|
|
71
|
+
// refused, as is one with :headers, which curl would send.
|
|
77
72
|
function httpSourceOf(source, where) {
|
|
78
73
|
const other = Object.keys(source).find((key) => !HTTP_OPTIONS.has(key))
|
|
79
74
|
if (other !== undefined) throw new SourceRefusal(`its source has :${other}, which cocoapods-downloader refuses of :http`, where)
|
|
80
75
|
const { http: url, type: named, flatten, headers } = source
|
|
81
|
-
if (
|
|
76
|
+
if (!isPodArchiveUrl(url)) throw new SourceRefusal(`an :http source from ${typeof url === 'string' ? quote(url) : 'nowhere'}, not https://github.com/<owner>/<repo>/ and a path under it, or ${MAVEN_FACEBOOK} and one under it to a .tar.gz or a .zip, as the URL parser writes it back out and of letters, digits and \`_.~@-%\`, is not supported`, where)
|
|
82
77
|
if (given(headers)) throw new SourceRefusal('an :http source with :headers, which curl sends with the request, is not supported', where)
|
|
83
|
-
|
|
78
|
+
// isPodArchiveUrl's URL ends with its path, which RemoteFile reads a type off.
|
|
79
|
+
const byUrl = URL_TYPES.find(([pattern]) => pattern.test(url))?.[1]
|
|
80
|
+
if (url.startsWith(MAVEN_FACEBOOK) && given(named) && named !== byUrl) throw new SourceRefusal(`its :type ${quote(String(named))} is not the ${byUrl} its URL on Maven Central names, as only a .tar.gz and a .zip from there are supported`, where)
|
|
81
|
+
const type = given(named) ? named : byUrl
|
|
84
82
|
if (typeof type !== 'string' || !TYPES.has(type)) throw new SourceRefusal(`${given(named) ? `its :type ${quote(String(named))}` : 'its URL'} names no type of archive cocoapods-downloader extracts`, where)
|
|
85
83
|
if (type === 'dmg') throw new SourceRefusal('an :http source of a dmg, which hdiutil mounts, is not supported: only a zip, and tgz, tar, tbz and txz, which `tar xf` extracts, are', where)
|
|
86
84
|
if (!given(source.sha256)) throw new SourceRefusal(given(source.sha1) ? 'an :http source held to a :sha1 alone, which two archives can be made to share, is not supported: only one held to a :sha256 is' : 'an :http source with no :sha256 to hold the download to is not supported', where)
|
package/src/cocoapods/tree.js
CHANGED
|
@@ -10,9 +10,9 @@ import { checkCloned, checkoutOf } from '../github.js'
|
|
|
10
10
|
import { sha1Hex } from '../hash.js'
|
|
11
11
|
import { checkNoDir, fold, makeDirs, mount, writeFiles } from '../mount.js'
|
|
12
12
|
import { archiveOf } from './archive.js'
|
|
13
|
-
import { checkHost, flagsOf, inputsOf, platformsOf } from './inputs.js'
|
|
13
|
+
import { checkHost, flagsOf, inputsOf, onlyOf, platformsOf } from './inputs.js'
|
|
14
14
|
import { installPod, planPod } from './install.js'
|
|
15
|
-
import { readPodspec, specNamed } from './podspec.js'
|
|
15
|
+
import { given, readPodspec, specNamed } from './podspec.js'
|
|
16
16
|
import { SourceRefusal, sourceOf } from './source.js'
|
|
17
17
|
|
|
18
18
|
const GITHUB = 'github must be a GitHub client from createClient, which each pod is fetched through'
|
|
@@ -88,19 +88,21 @@ async function localPodspec(root, podspecs, where) {
|
|
|
88
88
|
// planPod's, all before any download, so that a pod refused fails the call
|
|
89
89
|
// before any tarball or archive is fetched. A pod skipped for its source
|
|
90
90
|
// has no plan, its podspec held to the lockfile all the same.
|
|
91
|
-
async function planAll(roots, { github, podspecs, platforms }, skipped) {
|
|
91
|
+
async function planAll(roots, { github, podspecs, platforms, prepare }, skipped) {
|
|
92
92
|
const plans = new Map()
|
|
93
93
|
await eachConcurrently(roots, async (root) => {
|
|
94
94
|
const where = about(root.name)
|
|
95
95
|
const bytes = root.external === undefined ? await getPodspec(root.name, root.version, root.checksum) : await unlessSkipped(() => localPodspec(root, podspecs, where), root, skipped)
|
|
96
96
|
if (bytes === undefined) return
|
|
97
97
|
const podspec = readPodspec(bytes, root.name, root.version, where)
|
|
98
|
-
const source = unlessSkipped(() => sourceOf(podspec, where), root, skipped)
|
|
98
|
+
const source = unlessSkipped(() => sourceOf(podspec, where, prepare !== undefined), root, skipped)
|
|
99
99
|
if (source === undefined) return
|
|
100
|
+
const command = given(podspec.attributes.prepare_command) ? podspec.attributes.prepare_command : undefined
|
|
101
|
+
if (command !== undefined && typeof command !== 'string') throw new DeptreeError('its prepare_command is not text, which CocoaPods fails on', where)
|
|
100
102
|
const specs = root.pods.map((name) => specNamed(podspec, name) ?? refuse(`its podspec has no ${quote(name)}, which the lockfile installs`, where))
|
|
101
103
|
const files = planPod(podspec, specs, platforms, where)
|
|
102
104
|
if (source.type === 'git') await checkCloned(github, source.repo, source.commit, where)
|
|
103
|
-
plans.set(root.name, { root, files, source })
|
|
105
|
+
plans.set(root.name, { root, files, source, command })
|
|
104
106
|
}, (root) => about(root.name))
|
|
105
107
|
return plans
|
|
106
108
|
}
|
|
@@ -115,16 +117,35 @@ async function contentsOf({ root, source }, github) {
|
|
|
115
117
|
return await archiveOf(await getPodArchive(source.url, source.sha256), source, where)
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
const PREPARED = 'prepare must give the download back as it is after the command: its dirs, a Map of its files, each with data and a mode, and a Map of its links'
|
|
121
|
+
|
|
122
|
+
// A download as `prepare` leaves it: the pod's prepare_command run in a
|
|
123
|
+
// copy of it, by the caller, which gives back what is there afterwards.
|
|
124
|
+
async function prepared(prepare, { root, command }, contents) {
|
|
125
|
+
const copy = { dirs: new Set(contents.dirs), files: new Map(contents.files), links: new Map(contents.links) }
|
|
126
|
+
const after = await prepare({ name: root.name, version: root.version, command, contents: copy })
|
|
127
|
+
const isFile = (file) => file !== null && typeof file === 'object' && file.data instanceof Uint8Array && Number.isInteger(file.mode)
|
|
128
|
+
const valid = after !== null && typeof after === 'object' && typeof after.dirs?.[Symbol.iterator] === 'function' && after.files instanceof Map && after.links instanceof Map
|
|
129
|
+
&& [...after.dirs, ...after.files.keys(), ...after.links.keys(), ...after.links.values()].every((path) => typeof path === 'string') && [...after.files.values()].every(isFile)
|
|
130
|
+
if (!valid) throw new TypeError(PREPARED)
|
|
131
|
+
return { dirs: new Set(after.dirs), files: after.files, links: after.links }
|
|
132
|
+
}
|
|
133
|
+
|
|
118
134
|
// What CocoaPods keeps of each pod's download, held only while the pods of
|
|
119
|
-
// it are installed.
|
|
120
|
-
|
|
135
|
+
// it are installed. A pod with a prepare_command is cleaned as that leaves
|
|
136
|
+
// its download: CocoaPods runs it in its copy of the download, before it
|
|
137
|
+
// cleans that.
|
|
138
|
+
async function installAll(plans, github, { prepare, ...options }) {
|
|
121
139
|
const byDownload = Map.groupBy(plans.values(), downloadOf)
|
|
122
140
|
const installed = new Map()
|
|
123
141
|
await eachConcurrently(byDownload.values(), async (group) => {
|
|
124
142
|
const contents = await contentsOf(group[0], github)
|
|
125
143
|
// An archive is no clone, with no .git for CocoaPods to copy.
|
|
126
144
|
const keepsGit = options.keepsGit && group[0].source.type === 'git'
|
|
127
|
-
for (const plan of group)
|
|
145
|
+
for (const plan of group) {
|
|
146
|
+
const download = plan.command === undefined ? contents : await prepared(prepare, plan, contents)
|
|
147
|
+
installed.set(plan.root.name, installPod(download, plan.files, { ...options, keepsGit, where: about(plan.root.name) }))
|
|
148
|
+
}
|
|
128
149
|
}, ([{ root }]) => about(root.name))
|
|
129
150
|
return installed
|
|
130
151
|
}
|
|
@@ -157,6 +178,7 @@ export async function buildCocoaPodsTree(options) {
|
|
|
157
178
|
const inputs = inputsOf(all)
|
|
158
179
|
const platforms = platformsOf(all.platforms)
|
|
159
180
|
const { manifest, partial } = flagsOf(all)
|
|
181
|
+
const only = onlyOf(all.only)
|
|
160
182
|
const host = checkHost(all.host)
|
|
161
183
|
const folded = host.os === 'darwin'
|
|
162
184
|
// 1.13 to 1.15 copy a download into their cache with FileUtils.cp_r,
|
|
@@ -166,11 +188,16 @@ export async function buildCocoaPodsTree(options) {
|
|
|
166
188
|
if (into !== undefined) checkNoPods(into, folded)
|
|
167
189
|
const lock = await parsePodfileLock(inputs.lockfile, inputs.podfile === undefined ? {} : { podfile: inputs.podfile })
|
|
168
190
|
const roots = Object.values(lock.roots)
|
|
191
|
+
const unknown = [...(only ?? [])].find((name) => !roots.some((root) => root.name === name))
|
|
192
|
+
if (unknown !== undefined) throw new DeptreeError('the lockfile has no pod of the name, which `only` has', about(unknown))
|
|
169
193
|
const skipped = partial ? new Map() : undefined
|
|
170
|
-
|
|
194
|
+
// A pod `only` leaves out is not looked at: not refused, skipped or fetched.
|
|
195
|
+
const fetched = roots.filter((root) => only?.has(root.name) !== false && unlessSkipped(() => isDownloaded(root, folded), root, skipped))
|
|
171
196
|
if (github === undefined && fetched.length > 0) throw new TypeError(GITHUB)
|
|
172
|
-
const
|
|
173
|
-
|
|
197
|
+
const { prepare } = all
|
|
198
|
+
if (prepare !== undefined && typeof prepare !== 'function') throw new TypeError('prepare must be a function that runs a prepare_command, or left out')
|
|
199
|
+
const plans = await planAll(fetched, { github, podspecs: inputs.podspecs, platforms, prepare }, skipped)
|
|
200
|
+
const contents = await installAll(plans, github, { folded, keepsGit, prepare })
|
|
174
201
|
// In the lockfile's order, whatever order the fetches finished in.
|
|
175
202
|
const downloaded = fetched.filter(({ name }) => plans.has(name))
|
|
176
203
|
const vfs = new Vfs()
|
package/src/npm/compat.js
CHANGED
|
@@ -32,7 +32,7 @@ function checkEngine(pkg, host) {
|
|
|
32
32
|
const { engines } = pkg
|
|
33
33
|
if (!engines) return undefined
|
|
34
34
|
const options = { includePrerelease: true }
|
|
35
|
-
if (engines.node && !satisfies(`v${host.node}`, engines.node, options)) return `its engines.node, ${quote(String(engines.node))}, does not take Node ${host.node}`
|
|
35
|
+
if (engines.node && host.node !== undefined && !satisfies(`v${host.node}`, engines.node, options)) return `its engines.node, ${quote(String(engines.node))}, does not take Node ${host.node}`
|
|
36
36
|
if (engines.npm && !satisfies(host.npm, engines.npm, options)) return `its engines.npm, ${quote(String(engines.npm))}, does not take npm ${host.npm}`
|
|
37
37
|
return undefined
|
|
38
38
|
}
|
package/src/npm/dev-engines.js
CHANGED
|
@@ -23,6 +23,7 @@ function matches(wanted, current, at) {
|
|
|
23
23
|
if (wanted.name !== current.name) return false
|
|
24
24
|
if (!('version' in wanted)) return true
|
|
25
25
|
if (typeof wanted.version !== 'string') fail('expected a version')
|
|
26
|
+
if (current.anyVersion) return true
|
|
26
27
|
if (current.version === undefined) {
|
|
27
28
|
if (at.endsWith('.os')) throw new DeptreeError('a version of the os, which npm takes from the kernel, is not known here', at)
|
|
28
29
|
fail('the host has no version of it')
|
|
@@ -38,7 +39,8 @@ export function checkDevEngines(devEngines, host, at) {
|
|
|
38
39
|
libc: { name: host.libc },
|
|
39
40
|
os: { name: host.os },
|
|
40
41
|
packageManager: { name: 'npm', version: host.npm },
|
|
41
|
-
|
|
42
|
+
// A Node unknown takes every version asked for.
|
|
43
|
+
runtime: host.node === undefined ? { name: 'node', anyVersion: true } : { name: 'node', version: `v${host.node}` },
|
|
42
44
|
}
|
|
43
45
|
for (const [engine, wanted] of Object.entries(devEngines)) {
|
|
44
46
|
if (!ENGINES.has(engine)) throw new DeptreeError(`${quote(engine)} is not an engine npm knows, which it fails on`, at)
|
package/src/npm/inputs.js
CHANGED
|
@@ -4,15 +4,15 @@ import { valid } from '@preventive/upstream/semver.js'
|
|
|
4
4
|
import { DeptreeError, quote } from '../error.js'
|
|
5
5
|
import { walkWorkspaces } from '../glob.js'
|
|
6
6
|
import { readManifest, readManifests } from '../manifest.js'
|
|
7
|
-
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, readText, typeOf } from '../project.js'
|
|
7
|
+
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, nodeGiven, readText, typeOf } from '../project.js'
|
|
8
8
|
import { readSettings } from './settings.js'
|
|
9
9
|
import { profileOf } from './versions.js'
|
|
10
10
|
|
|
11
11
|
const LIBCS = new Set(['glibc', 'musl'])
|
|
12
12
|
|
|
13
13
|
export function checkHost(host) {
|
|
14
|
-
checkHostKeys(host, ['npm', '
|
|
15
|
-
if (valid(host.node) !== host.node) throw new DeptreeError(`${quote(host.node)} is not an exact version`, 'host.node')
|
|
14
|
+
checkHostKeys(host, ['npm', 'os', 'cpu'], 'npm, os and cpu, node where it is known, and libc on Linux')
|
|
15
|
+
if (nodeGiven(host.node) && valid(host.node) !== host.node) throw new DeptreeError(`${quote(host.node)} is not an exact version`, 'host.node')
|
|
16
16
|
if (host.os === 'win32') throw new DeptreeError('Windows is not supported: npm links bins there with shims, and workspaces with junctions', 'host.os')
|
|
17
17
|
if (host.os === 'linux' ? !LIBCS.has(host.libc) : host.libc !== undefined) {
|
|
18
18
|
throw new TypeError(host.os === 'linux' ? 'host.libc must be glibc or musl on Linux' : 'host.libc must be left out but on Linux')
|
package/src/pnpm/inputs.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { LockfileError, YamlError, parsePnpmLockfile } from '@preventive/lockfile/pnpm.js'
|
|
5
5
|
import { parseYaml } from '@preventive/lockfile/yaml.js'
|
|
6
|
-
import {
|
|
6
|
+
import { valid } from '@preventive/upstream/semver.js'
|
|
7
7
|
import { normalize } from '@preventive/vfs/path.js'
|
|
8
8
|
import { DeptreeError, quote } from '../error.js'
|
|
9
9
|
import { readManifest } from '../manifest.js'
|
|
10
|
-
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, readText, typeOf } from '../project.js'
|
|
10
|
+
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, nodeGiven, readText, typeOf } from '../project.js'
|
|
11
11
|
import { pinnedPnpm, readManifests } from './projects.js'
|
|
12
12
|
import { readers } from './readers.js'
|
|
13
13
|
import { checkWorkspace, findProjects, linkedManifest } from './workspace.js'
|
|
@@ -36,12 +36,9 @@ function readPatches(project, configured) {
|
|
|
36
36
|
return texts
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// pnpm 12 before 12.8.1 installs otherwise in places, and is refused.
|
|
40
|
-
const SINCE = { 12: '12.8.1' }
|
|
41
39
|
function majorOf(pnpm) {
|
|
42
40
|
const major = Number(valid(pnpm)?.split('.')[0])
|
|
43
41
|
if (major < 10 || major > 12 || !Number.isInteger(major)) throw new DeptreeError(`pnpm ${quote(pnpm)} is not supported: only pnpm 10, 11 and 12 are`, 'host.pnpm')
|
|
44
|
-
if (major in SINCE && compareVersions(pnpm, SINCE[major]) < 0) throw new DeptreeError(`pnpm ${quote(pnpm)} is not supported: pnpm ${major} is from ${SINCE[major]} on`, 'host.pnpm')
|
|
45
42
|
return major
|
|
46
43
|
}
|
|
47
44
|
|
|
@@ -55,9 +52,9 @@ function pnpmOf(pnpm, root) {
|
|
|
55
52
|
|
|
56
53
|
// All of host but its pnpm, which pnpmOf reads.
|
|
57
54
|
export function checkHost(host) {
|
|
58
|
-
checkHostKeys(host, ['
|
|
55
|
+
checkHostKeys(host, ['os', 'cpu', 'libc'], 'os, cpu and libc, node where it is known, and pnpm where it is not pinned')
|
|
59
56
|
const { node, os, libc } = host
|
|
60
|
-
if (valid(node) === null) throw new DeptreeError(`${quote(node)} is not an exact version`, 'host.node')
|
|
57
|
+
if (nodeGiven(node) && valid(node) === null) throw new DeptreeError(`${quote(node)} is not an exact version`, 'host.node')
|
|
61
58
|
if (os === 'win32') throw new DeptreeError('Windows is not supported: pnpm links there with junctions to absolute paths', 'host.os')
|
|
62
59
|
if (!LIBC.has(libc)) throw new DeptreeError(`expected "glibc", "musl" or "unknown", found ${quote(libc)}`, 'host.libc')
|
|
63
60
|
return { node, os, cpu: host.cpu, libc }
|
package/src/pnpm/install.js
CHANGED
|
@@ -55,7 +55,8 @@ const current = (value, supported) => (supported ?? ['current']).map((item) => (
|
|
|
55
55
|
const takesPlatform = (pkg, host, supported) => ['os', 'cpu', 'libc'].every((key) => (key === 'libc' && host.libc === 'unknown')
|
|
56
56
|
|| checkList(current(host[key], supported?.[key]), pkg[key] ?? ['any'], host.major))
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// A Node unknown (host.node left out, and none in the settings) takes any.
|
|
59
|
+
const takesEngine = (engines, node) => !engines.node || node === undefined || satisfies(node, engines.node, { includePrerelease: true })
|
|
59
60
|
|
|
60
61
|
// pnpm 12 drops what of a range it cannot parse, where npm's semver takes
|
|
61
62
|
// none of it, and reads a `-` range with an `x` as taking nothing.
|
package/src/pnpm/packlist.js
CHANGED
|
@@ -187,6 +187,8 @@ export function packDirectory(project, dir, manifest, version, where) {
|
|
|
187
187
|
if (rel.split('/').some((part) => part === '' || part === '.')) throw new DeptreeError('pnpm keeps it as a pattern spells it, which is not supported', here)
|
|
188
188
|
const { mode } = view.lstat(rel)
|
|
189
189
|
if (!MODES.has(mode)) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644, 664, 755 or 775, which is not supported`, here)
|
|
190
|
+
// pnpm 12.8.0 installs each at 644, whatever its own mode, which 12.8.1 fixed.
|
|
191
|
+
if (pnpm === '12.8.0' && mode !== 0o644) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644, which pnpm 12.8.0 installs it at, and that is not supported`, here)
|
|
190
192
|
files.set(rel, { data: view.bytes(rel), mode })
|
|
191
193
|
}
|
|
192
194
|
return files
|
package/src/pnpm/production.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// optionalDependencies and `link:`s, which lead only to projects, all of them
|
|
6
6
|
// installed anyway.
|
|
7
7
|
//
|
|
8
|
-
// From pnpm 11.28 and 12.
|
|
8
|
+
// From pnpm 11.28 and 12.7.0 on (@pnpm/lockfile.peer-edges), an edge to an
|
|
9
9
|
// optional peer that a snapshot has only as the projects that reach it list
|
|
10
10
|
// the peer themselves is not walked, and is dropped from the snapshot where
|
|
11
11
|
// nothing else reaches the peer: a devDependency only there to satisfy an
|
|
@@ -13,15 +13,22 @@
|
|
|
13
13
|
// only an edge to a peer the snapshot's key binds is such an edge, or any of
|
|
14
14
|
// one whose key ends in a hash of its peers; before, any edge by the name of
|
|
15
15
|
// an optional peer was, though the snapshot resolved it as its own.
|
|
16
|
+
//
|
|
17
|
+
// pnpm 12 before 12.7.0 walks such an edge too, as pnpm 11 before 11.28
|
|
18
|
+
// does, which is pnpm's bug and not built for: a lockfile where walking the
|
|
19
|
+
// edges 12.15.0 does not walk installs otherwise is refused.
|
|
16
20
|
|
|
17
21
|
import { compareVersions } from '@preventive/upstream/semver.js'
|
|
18
22
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
23
|
+
import { DeptreeError, quote } from '../error.js'
|
|
19
24
|
import { reachable } from './nm-hoist.js'
|
|
20
25
|
|
|
21
|
-
// undefined where there is no such edge; else whether the key must bind it
|
|
26
|
+
// undefined where there is no such edge; else whether the key must bind it,
|
|
27
|
+
// and whether a lockfile that walking the edges installs otherwise is refused.
|
|
22
28
|
function ruleOf(pnpm, major) {
|
|
23
29
|
const since = (version) => compareVersions(pnpm, version) >= 0
|
|
24
30
|
if (major < 11 || (major === 11 && !since('11.28.0'))) return undefined
|
|
31
|
+
if (major === 12 && !since('12.7.0')) return { bound: true, refused: true }
|
|
25
32
|
return { bound: since(major === 11 ? '11.28.7' : '12.15.0') }
|
|
26
33
|
}
|
|
27
34
|
|
|
@@ -116,17 +123,38 @@ function without(packages, edges, drop) {
|
|
|
116
123
|
return kept
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
|
|
126
|
+
const same = (a, b) => a.size === b.size && [...a].every((key) => b.has(key))
|
|
127
|
+
|
|
128
|
+
// The edge to name in refusing: one to a snapshot `fixed` leaves out, else
|
|
129
|
+
// one of a snapshot walking them all reaches.
|
|
130
|
+
function refusalOf(edges, all, fixed, packages) {
|
|
131
|
+
const listed = [...edges].flatMap(([parent, aliases]) => [...aliases].map((alias) => ({ parent, alias, target: packages[parent].dependencies[alias] ?? packages[parent].optionalDependencies[alias] })))
|
|
132
|
+
const reached = listed.filter((edge) => all.picked.has(edge.parent))
|
|
133
|
+
const edge = reached.find(({ target }) => !fixed.picked.has(target)) ?? reached[0]
|
|
134
|
+
return new DeptreeError(`pnpm 12 before 12.7.0 walks its edge to its optional peer ${quote(edge.alias)}, which pnpm 12.7.0 on does not, and installs otherwise with devDependencies left out, which is not supported`, `snapshots[${quote(edge.parent)}]`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// `installing`, the lockfile the tree is laid out from: the snapshots
|
|
138
|
+
// reached, each but for the edges pnpm does not walk to a snapshot not
|
|
139
|
+
// reached; and what `skippedOf` makes of what pnpm walks to leave out what
|
|
140
|
+
// the host cannot run: every snapshot, but for those edges. Each importer's
|
|
141
|
+
// devDependencies are empty.
|
|
142
|
+
export function productionLockfile(lockfile, { pnpm, major, resolvePeersFromWorkspaceRoot }, skippedOf) {
|
|
124
143
|
const importers = Object.fromEntries(Object.entries(lockfile.importers).map(([id, importer]) => [id, { ...importer, devDependencies: {} }]))
|
|
144
|
+
const starts = Object.values(importers).flatMap(prodEdgesOf)
|
|
145
|
+
const filtered = (edges) => {
|
|
146
|
+
const walked = { ...lockfile, importers, packages: without(lockfile.packages, edges, () => true) }
|
|
147
|
+
const picked = reachable(starts, (key) => prodEdgesOf(walked.packages[key]))
|
|
148
|
+
const packages = Object.fromEntries(Object.entries(lockfile.packages).filter(([key]) => picked.has(key)))
|
|
149
|
+
return { picked, installing: { ...lockfile, importers, packages: without(packages, edges, (target) => !picked.has(target)) }, ...skippedOf(walked) }
|
|
150
|
+
}
|
|
125
151
|
const rule = ruleOf(pnpm, major)
|
|
126
152
|
const edges = rule === undefined ? new Map() : satisfactionEdges(lockfile, rule, resolvePeersFromWorkspaceRoot)
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
153
|
+
const fixed = filtered(edges)
|
|
154
|
+
if (!rule?.refused || edges.size === 0) return fixed
|
|
155
|
+
// Where walking every edge reaches the same snapshots and leaves out the
|
|
156
|
+
// same, it lays out the same tree.
|
|
157
|
+
const all = filtered(new Map())
|
|
158
|
+
if (!same(all.picked, fixed.picked) || !same(all.skipped, fixed.skipped) || !same(all.incompatible, fixed.incompatible)) throw refusalOf(edges, all, fixed, lockfile.packages)
|
|
159
|
+
return all
|
|
132
160
|
}
|
package/src/pnpm/projects.js
CHANGED
|
@@ -202,7 +202,7 @@ function checkRuntimes(manifest, where, { host, root, onFail }) {
|
|
|
202
202
|
if ((onFail ?? item.onFail) !== 'error') continue
|
|
203
203
|
if (item.name !== 'node') throw new DeptreeError(`the ${item.name} it runs on is checked by pnpm 11, and is not known here`, here)
|
|
204
204
|
if (!item.version || validRange(item.version) === null) throw new DeptreeError(`${quote(String(item.version))} is not a range for Node, which pnpm 11 refuses`, here)
|
|
205
|
-
if (!satisfies(host.node, item.version, { includePrerelease: true })) throw new DeptreeError(`Node ${host.node} is not in ${quote(item.version)}, which pnpm 11 refuses to install with`, here)
|
|
205
|
+
if (host.node !== undefined && !satisfies(host.node, item.version, { includePrerelease: true })) throw new DeptreeError(`Node ${host.node} is not in ${quote(item.version)}, which pnpm 11 refuses to install with`, here)
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
package/src/pnpm/tree.js
CHANGED
|
@@ -296,8 +296,8 @@ export async function buildPnpmTree(options) {
|
|
|
296
296
|
checkProjects(lockfile, manifests, { hook, extensions, host, settings, env, directories })
|
|
297
297
|
checkOptional(lockfile)
|
|
298
298
|
const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
|
|
299
|
-
const
|
|
300
|
-
const { skipped, incompatible } =
|
|
299
|
+
const skippedOf = (walked) => skippedSnapshots(walked, { host, settings })
|
|
300
|
+
const { installing, skipped, incompatible } = production ? productionLockfile(lockfile, { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }, skippedOf) : { installing: lockfile, ...skippedOf(lockfile) }
|
|
301
301
|
const hoisted = settings.nodeLinker === 'hoisted'
|
|
302
302
|
const checks = { lockfile, hook, fresh, drops }
|
|
303
303
|
const { byDir, links, fixes, reads, builds, early, tarballs, dev } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile: installing, checks, settings, host, project, installed, manifests, names, patched, skipped, fetching })
|
package/src/project.js
CHANGED
|
@@ -48,6 +48,13 @@ export function checkHostKeys(host, keys, wanted) {
|
|
|
48
48
|
if (host === null || typeof host !== 'object') throw new TypeError(`host must be an object with ${wanted}`)
|
|
49
49
|
for (const key of keys) if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
|
|
50
50
|
}
|
|
51
|
+
// Whether host.node is given, a non-empty string. Left out, the Node is
|
|
52
|
+
// unknown: every engines.node, and every range for Node, takes it.
|
|
53
|
+
export function nodeGiven(node) {
|
|
54
|
+
if (node === undefined) return false
|
|
55
|
+
if (typeof node !== 'string' || node === '') throw new TypeError('host.node must be a non-empty string, or left out')
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
51
58
|
// `production`, false unless given true, as each manager's builder takes it.
|
|
52
59
|
export function productionOf({ production = false }) {
|
|
53
60
|
if (typeof production !== 'boolean') throw new TypeError('production must be a boolean, or left out')
|
package/src/yarn1/compat.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// yarn 1's package-compatibility.js, engines checked against host.node and
|
|
2
|
-
// host.yarn; one yarn knows no version of is passed over, as yarn does.
|
|
2
|
+
// host.yarn; one yarn knows no version of is passed over, as yarn does. A
|
|
3
|
+
// Node unknown (host.node left out) takes every range of its own, and of
|
|
4
|
+
// what it reports in process.versions.
|
|
3
5
|
|
|
4
6
|
import { compareVersions, major, satisfies, valid } from '@preventive/upstream/semver.js'
|
|
5
7
|
import { DeptreeError, quote } from '../error.js'
|
|
@@ -60,6 +62,7 @@ export function incompatibility(manifest, host, where, { ignoreEngines, ignorePl
|
|
|
60
62
|
const known = Object.hasOwn(versions, name)
|
|
61
63
|
if (!known && !REPORTED.has(name)) continue
|
|
62
64
|
if (typeof range !== 'string') throw new DeptreeError(`engines.${name} is not a string, which yarn fails on`, where)
|
|
65
|
+
if (host.node === undefined && (name === 'node' || !known)) continue
|
|
63
66
|
if (!known) throw new DeptreeError(`yarn checks engines.${name} against the Node it runs on, which is not known here`, where)
|
|
64
67
|
if (!testEngine(name, range, versions)) return `its engines.${name}, ${quote(range)}, does not take ${versions[name]}`
|
|
65
68
|
}
|
package/src/yarn1/inputs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { valid } from '@preventive/upstream/semver.js'
|
|
4
4
|
import { DeptreeError, quote } from '../error.js'
|
|
5
5
|
import { readManifest, readManifests } from '../manifest.js'
|
|
6
|
-
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, readText, typeOf } from '../project.js'
|
|
6
|
+
import { checkHostKeys, checkLeftOut, checkProject, checkTexts, nodeGiven, readText, typeOf } from '../project.js'
|
|
7
7
|
import { walkWorkspaces } from '../glob.js'
|
|
8
8
|
import { globsOf } from './manifest.js'
|
|
9
9
|
import { readSettings } from './settings.js'
|
|
@@ -25,8 +25,8 @@ function yarnOf(yarn, root) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function checkHost(host, root) {
|
|
28
|
-
checkHostKeys(host, ['
|
|
29
|
-
if (valid(host.node) !== host.node) throw new DeptreeError(`${quote(host.node)} is not an exact version`, 'host.node')
|
|
28
|
+
checkHostKeys(host, ['os', 'cpu'], 'os and cpu, node where it is known, and yarn where it is not pinned')
|
|
29
|
+
if (nodeGiven(host.node) && valid(host.node) !== host.node) throw new DeptreeError(`${quote(host.node)} is not an exact version`, 'host.node')
|
|
30
30
|
if (host.os === 'win32') throw new DeptreeError('Windows is not supported: yarn links bins there with shims, and workspaces with junctions', 'host.os')
|
|
31
31
|
return { yarn: yarnOf(host.yarn, root), node: host.node, os: host.os, cpu: host.cpu }
|
|
32
32
|
}
|
package/yarn1.d.ts
CHANGED
|
@@ -20,7 +20,9 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
20
20
|
// the version that installs, and has to be a 1.22.x; left out, it is the
|
|
21
21
|
// one the root package.json's packageManager pins, which corepack runs,
|
|
22
22
|
// and has to be given where that pins none, and to be that one where it
|
|
23
|
-
// does. `node` is the Node yarn runs on, an exact version
|
|
23
|
+
// does. `node` is the Node yarn runs on, an exact version, or left out
|
|
24
|
+
// for one unknown, which every range for Node, and for what Node reports
|
|
25
|
+
// in process.versions, takes; `os` and `cpu`
|
|
24
26
|
// as Node names them -- `linux`, `x64`. Windows is refused: yarn links bins
|
|
25
27
|
// there with shims, and workspaces with junctions.
|
|
26
28
|
// A package whose os, cpu or engines the machine does not take is left
|
|
@@ -34,10 +36,11 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
34
36
|
// yarn takes for it) and `yarn` are checked as yarn checks them, and one
|
|
35
37
|
// yarn has no version for is passed over, as yarn passes over it; one any
|
|
36
38
|
// Node reports in process.versions, such as `v8` or `merve`, which yarn
|
|
37
|
-
// would check against the Node it runs on, is refused
|
|
39
|
+
// would check against the Node it runs on, is refused, but for a Node
|
|
40
|
+
// unknown.
|
|
38
41
|
export interface Yarn1Host {
|
|
39
42
|
yarn?: string
|
|
40
|
-
node
|
|
43
|
+
node?: string
|
|
41
44
|
os: string
|
|
42
45
|
cpu: string
|
|
43
46
|
}
|