@preventive/deptree 1.0.0-alpha.7 → 1.0.0-alpha.9
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/npm.d.ts +7 -6
- package/package.json +4 -3
- package/pnpm.d.ts +17 -8
- package/soldeer.d.ts +74 -21
- package/src/mount.js +13 -2
- package/src/pnpm/local.js +15 -3
- package/src/pnpm/package.js +4 -2
- package/src/pnpm/readers.js +9 -1
- package/src/soldeer/git.js +52 -0
- package/src/soldeer/tree.js +35 -19
- package/src/soldeer/zip.js +4 -5
- package/src/tarball.js +47 -9
- package/src/yarn1/bins.js +1 -1
- package/src/yarn1/package.js +61 -9
- package/src/yarn1/requests.js +7 -5
- package/src/yarn1/resolve.js +62 -12
- package/src/yarn1/tree.js +29 -9
- package/yarn1.d.ts +58 -26
package/npm.d.ts
CHANGED
|
@@ -7,12 +7,13 @@ export { LockfileError } from '@preventive/lockfile/npm.js'
|
|
|
7
7
|
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
8
8
|
// Tarballs are fetched through it, and that is the one place anything here
|
|
9
9
|
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
10
|
-
// cache — under $npm_config_cache, or ~/.npm —
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
10
|
+
// cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
|
|
11
|
+
// from its own default cache directory or stasis's, where one there has the
|
|
12
|
+
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
13
|
+
// where one is set, which is where it writes each tarball it fetches:
|
|
14
|
+
// setCacheDir() sets the default one, and setCacheDir(false) unsets it.
|
|
15
|
+
// Unset, which it is until set, it writes nothing. The project is read
|
|
16
|
+
// only through the view given as `project`, and the tree built in a Vfs.
|
|
16
17
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
17
18
|
|
|
18
19
|
// The machine npm would install on, which a tree depends on. `npm` is the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/deptree",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "A dependency tree in memory, as a package manager would install it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"src/pnpm/workspace.js",
|
|
83
83
|
"src/project.js",
|
|
84
84
|
"src/soldeer/config.js",
|
|
85
|
+
"src/soldeer/git.js",
|
|
85
86
|
"src/soldeer/inputs.js",
|
|
86
87
|
"src/soldeer/tree.js",
|
|
87
88
|
"src/soldeer/zip.js",
|
|
@@ -126,8 +127,8 @@
|
|
|
126
127
|
"@chalker/queue": "^1.0.1",
|
|
127
128
|
"@preventive/archive": "1.0.0-beta.4",
|
|
128
129
|
"@preventive/diff": "^1.0.1",
|
|
129
|
-
"@preventive/lockfile": "1.0.0-alpha.
|
|
130
|
-
"@preventive/upstream": "1.0.0-alpha.
|
|
130
|
+
"@preventive/lockfile": "1.0.0-alpha.7",
|
|
131
|
+
"@preventive/upstream": "1.0.0-alpha.11",
|
|
131
132
|
"@preventive/vfs": "1.0.0-beta.4"
|
|
132
133
|
}
|
|
133
134
|
}
|
package/pnpm.d.ts
CHANGED
|
@@ -10,13 +10,15 @@ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
|
|
|
10
10
|
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
11
11
|
// Tarballs are fetched through it, and that is the one place anything here
|
|
12
12
|
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
13
|
-
// cache — under $npm_config_cache, or ~/.npm —
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
13
|
+
// cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
|
|
14
|
+
// from its own default cache directory or stasis's, where one there has the
|
|
15
|
+
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
16
|
+
// where one is set, which is where it writes each tarball it fetches:
|
|
17
|
+
// setCacheDir() sets the default one, and setCacheDir(false) unsets it.
|
|
18
|
+
// Unset, which it is until set, it writes nothing: a tarball in none of
|
|
19
|
+
// the others is fetched every time, each once for however many snapshots
|
|
20
|
+
// it has. The project is read only through the view given as `project`,
|
|
21
|
+
// and the tree built in a Vfs.
|
|
20
22
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
21
23
|
|
|
22
24
|
// The machine pnpm would install on, which a tree depends on: `pnpm` is
|
|
@@ -191,7 +193,14 @@ export interface PnpmProject {
|
|
|
191
193
|
// install reads, without `lockfile`; for the directories a `link:` or an
|
|
192
194
|
// override leads to. With it given, a directory the tree links to that is
|
|
193
195
|
// no project, and is under the lockfile's, has to be there with a
|
|
194
|
-
// package.json, whose bins are read as pnpm reads them
|
|
196
|
+
// package.json, whose bins are read as pnpm reads them; pnpm links to one
|
|
197
|
+
// that is not there all the same, warning only as pnpm 10 and 11 resolve,
|
|
198
|
+
// never as a frozen install. So it does for `npm:@scope/name@workspace:^`,
|
|
199
|
+
// as an override or a dependency, which it takes for a path for its `/`,
|
|
200
|
+
// and that link is refused with or without `project`, but where it holds
|
|
201
|
+
// a directory of that very name:
|
|
202
|
+
// `workspace:@scope/name@^` is the spec that links the workspace package
|
|
203
|
+
// by another name. Without it, or
|
|
195
204
|
// outside the lockfile's directory, such a directory's bins are not
|
|
196
205
|
// known, and neither are those of a project that has them by the files of
|
|
197
206
|
// its directories.bin: where one could win a command a package's file is
|
package/soldeer.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// Hand-written against soldeer.js; a change to either belongs with the other.
|
|
2
2
|
|
|
3
|
+
import type { Client } from '@preventive/upstream/github.js'
|
|
3
4
|
import type { NodeType, Vfs } from '@preventive/vfs'
|
|
4
5
|
|
|
5
6
|
export { LockfileError, TomlError } from '@preventive/lockfile/soldeer.js'
|
|
6
7
|
|
|
7
|
-
// Where @preventive/upstream caches what it fetches, zips
|
|
8
|
-
// are fetched through it, and that is the one
|
|
9
|
-
// a filesystem: from its cache, where one is
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
8
|
+
// Where @preventive/upstream caches what it fetches, zips and GitHub's
|
|
9
|
+
// tarballs among them. Both are fetched through it, and that is the one
|
|
10
|
+
// place anything here touches a filesystem: from its cache, where one is
|
|
11
|
+
// set, which is where it writes each it fetches — setCacheDir() sets the
|
|
12
|
+
// default one, and setCacheDir(false) unsets it; unset, which it is until
|
|
13
|
+
// set, it has none, and writes nothing. Soldeer's own folders are never
|
|
14
|
+
// read. The project is read only through the view given as `project`, and
|
|
15
|
+
// the tree built in a Vfs.
|
|
14
16
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
15
17
|
|
|
16
18
|
// The machine Soldeer would install on: `soldeer` is the version that
|
|
@@ -66,6 +68,11 @@ export interface SoldeerProject {
|
|
|
66
68
|
// made, and every file is written where nothing is. The tree is built, and
|
|
67
69
|
// held to every check below, before any of it is written, so a refusal
|
|
68
70
|
// leaves the Vfs as it was.
|
|
71
|
+
//
|
|
72
|
+
// `github` is the client from @preventive/upstream/github.js's createClient
|
|
73
|
+
// each git dependency is fetched through, with whatever token it was made
|
|
74
|
+
// with, or none. It is needed only where the lockfile has a git dependency,
|
|
75
|
+
// and there it is a TypeError to leave it out, before anything is fetched.
|
|
69
76
|
export type SoldeerTreeOptions = SoldeerTreeGiven | SoldeerTreeRead
|
|
70
77
|
|
|
71
78
|
export interface SoldeerTreeGiven {
|
|
@@ -75,6 +82,7 @@ export interface SoldeerTreeGiven {
|
|
|
75
82
|
project?: undefined
|
|
76
83
|
host: SoldeerHost
|
|
77
84
|
vfs?: Vfs
|
|
85
|
+
github?: Client
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
export interface SoldeerTreeRead {
|
|
@@ -84,27 +92,44 @@ export interface SoldeerTreeRead {
|
|
|
84
92
|
project: SoldeerProject
|
|
85
93
|
host: SoldeerHost
|
|
86
94
|
vfs?: Vfs
|
|
95
|
+
github?: Client
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
// What buildSoldeerTree counts, all of it plain numbers: `dependencies`
|
|
90
|
-
// those installed, each a zip fetched; `files` and `bytes`
|
|
99
|
+
// those installed, each a zip or a tarball fetched; `files` and `bytes`
|
|
100
|
+
// what is written, and `links` the symlinks, which git dependencies alone
|
|
101
|
+
// have, as a zip's are written as files.
|
|
91
102
|
export interface SoldeerTreeStats {
|
|
92
103
|
dependencies: number
|
|
93
104
|
files: number
|
|
94
105
|
bytes: number
|
|
106
|
+
links: number
|
|
95
107
|
}
|
|
96
108
|
|
|
97
109
|
// A dependency in the tree, as an SBOM would list it: `path` is its
|
|
98
110
|
// folder, from the project's root, which is `/` of the Vfs —
|
|
99
111
|
// dependencies/<name>-<version>; `name` and `version` the lockfile's, as
|
|
100
|
-
// the registry has them
|
|
101
|
-
|
|
112
|
+
// the registry has them, or for a git dependency, the config's. From the
|
|
113
|
+
// registry, `checksum` is the hex sha256 its zip is held to; from git,
|
|
114
|
+
// `git` is the repository's URL and `rev` the commit, as the lockfile has
|
|
115
|
+
// them.
|
|
116
|
+
export type SoldeerInstalled = SoldeerInstalledZip | SoldeerInstalledGit
|
|
117
|
+
|
|
118
|
+
export interface SoldeerInstalledZip {
|
|
102
119
|
path: string
|
|
103
120
|
name: string
|
|
104
121
|
version: string
|
|
105
122
|
checksum: string
|
|
106
123
|
}
|
|
107
124
|
|
|
125
|
+
export interface SoldeerInstalledGit {
|
|
126
|
+
path: string
|
|
127
|
+
name: string
|
|
128
|
+
version: string
|
|
129
|
+
git: string
|
|
130
|
+
rev: string
|
|
131
|
+
}
|
|
132
|
+
|
|
108
133
|
// `vfs` is the one given, the tree mounted into it, or a new one.
|
|
109
134
|
// `installed` is each dependency, in the lockfile's order.
|
|
110
135
|
export interface SoldeerTree {
|
|
@@ -121,9 +146,9 @@ export interface SoldeerTree {
|
|
|
121
146
|
// written, and where writing it fails after the install, as Soldeer may on
|
|
122
147
|
// a remappings.txt it does not read, that is not followed.
|
|
123
148
|
//
|
|
124
|
-
// Each dependency's zip is fetched from Soldeer's registry, as
|
|
125
|
-
// 0.12 asks
|
|
126
|
-
//
|
|
149
|
+
// Each registry dependency's zip is fetched from Soldeer's registry, as
|
|
150
|
+
// Soldeer 0.12 asks for it anew rather than taking the lockfile's URL,
|
|
151
|
+
// and held to the lockfile's checksum, its sha256. It is extracted as
|
|
127
152
|
// Soldeer extracts it, with the zip crate, into a folder of its own: no
|
|
128
153
|
// root folder taken off; of two entries of one name, the later alone,
|
|
129
154
|
// where the first was; anything under a `.git` passed over, as Windows
|
|
@@ -158,17 +183,45 @@ export interface SoldeerTree {
|
|
|
158
183
|
// or normalization are refused, as they would be one name there, and so
|
|
159
184
|
// is a folder that is one there with another dependency's zip.
|
|
160
185
|
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
186
|
+
// A git dependency Soldeer clones, `git clone` of the lockfile's `git`,
|
|
187
|
+
// then `git checkout` of its `rev`; here it is fetched from a GitHub
|
|
188
|
+
// repository alone, by `github`, as GitHub's tarball of the tree of that
|
|
189
|
+
// commit, which upstream holds to the tree GitHub names for the commit. It
|
|
190
|
+
// is written as a checkout with no git config and a umask of 0o022 writes
|
|
191
|
+
// it: each directory 0o755, each file 0o644, or 0o755 where git has it
|
|
192
|
+
// executable; each symlink a symlink to its target, as git has it; a
|
|
193
|
+
// submodule an empty directory, as Soldeer leaves it without
|
|
194
|
+
// recursive_deps; a file the tree's .gitattributes mark `eol=crlf` with
|
|
195
|
+
// CRLF, as upstream reads them. The .git a clone has is not written, so
|
|
196
|
+
// nothing of the repository's history is there; nor is what git config on
|
|
197
|
+
// the machine would change, `core.autocrlf` or a filter such as Git LFS's.
|
|
198
|
+
// Its folder is the config's name and version, which Soldeer's
|
|
199
|
+
// sanitize_filename has to leave as they are. The `git` is the
|
|
200
|
+
// repository's URL over https or ssh, as git takes it —
|
|
201
|
+
// `https://github.com/<owner>/<name>`,
|
|
202
|
+
// `ssh://git@github.com/<owner>/<name>` or
|
|
203
|
+
// `git@github.com:<owner>/<name>`, `.git` after or not; git's http and git
|
|
204
|
+
// protocols, which Soldeer has git refuse, are refused. GitHub's tarball
|
|
205
|
+
// is refused where upstream refuses it — a tree with files marked
|
|
206
|
+
// `export-ignore`, `ident` or `working-tree-encoding`, from a repo set to
|
|
207
|
+
// include Git LFS objects in archives — and where the tar reader of
|
|
208
|
+
// @preventive/archive/tar.js does, as for a symlink whose target climbs
|
|
209
|
+
// out of the tarball; so is a path with a `.git` in it, in any case, which
|
|
210
|
+
// git refuses to check out. That the repository's branches and tags still
|
|
211
|
+
// reach the commit, without which Soldeer's clone does not have it, is not
|
|
212
|
+
// checked: GitHub answers for any commit it has.
|
|
213
|
+
//
|
|
214
|
+
// Dependencies come from Soldeer's registry, each by a name and a version
|
|
215
|
+
// the registry takes, or from GitHub: one from another git host, from a
|
|
216
|
+
// URL the config gives, or one the registry keeps private, which it hands
|
|
217
|
+
// out to those signed in alone, is refused.
|
|
166
218
|
//
|
|
167
219
|
// Nothing is left to a guess: a lockfile the lockfile reader refuses, a
|
|
168
220
|
// config this does not read as Soldeer reads it, a dependency from
|
|
169
|
-
// anywhere but the registry, a check above that fails — each is
|
|
170
|
-
// with a DeptreeError, a LockfileError or a TomlError that says
|
|
171
|
-
// TypeError is thrown for options of the wrong type
|
|
221
|
+
// anywhere but the registry or GitHub, a check above that fails — each is
|
|
222
|
+
// refused with a DeptreeError, a LockfileError or a TomlError that says
|
|
223
|
+
// where. A TypeError is thrown for options of the wrong type, and for a
|
|
224
|
+
// git dependency without `github`.
|
|
172
225
|
export function buildSoldeerTree(options: SoldeerTreeOptions): Promise<SoldeerTree>
|
|
173
226
|
|
|
174
227
|
// `where` is what a refusal is about — `foundry.toml: profile.default`,
|
package/src/mount.js
CHANGED
|
@@ -92,8 +92,9 @@ export function writeLink(vfs, path, target) {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// `root` is the package's directory in the tree, without a leading
|
|
96
|
-
|
|
95
|
+
// `root` is the package's directory in the tree, without a leading `/`;
|
|
96
|
+
// `links` are symlinks within it, by path, to their targets as given.
|
|
97
|
+
export function writeFiles(vfs, root, { dirs, files, links = new Map() }, stats, skip = () => false) {
|
|
97
98
|
const real = new Set()
|
|
98
99
|
makeDirs(vfs, root, real)
|
|
99
100
|
for (const dir of dirs) {
|
|
@@ -112,6 +113,16 @@ export function writeFiles(vfs, root, { dirs, files }, stats, skip = () => false
|
|
|
112
113
|
stats.files++
|
|
113
114
|
stats.bytes += file.data.length
|
|
114
115
|
}
|
|
116
|
+
for (const [path, target] of links) {
|
|
117
|
+
if (skip(path)) continue
|
|
118
|
+
const at = checkWrite(vfs, root, path, real)
|
|
119
|
+
try {
|
|
120
|
+
vfs.symlink(target, at)
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw asRefusal(error, 'made', `${root}/${path}`)
|
|
123
|
+
}
|
|
124
|
+
stats.links++
|
|
125
|
+
}
|
|
115
126
|
}
|
|
116
127
|
|
|
117
128
|
// `target` with `tree` in it, or `tree` where there is none; on macOS, two
|
package/src/pnpm/local.js
CHANGED
|
@@ -13,7 +13,7 @@ import { packDirectory } from './packlist.js'
|
|
|
13
13
|
|
|
14
14
|
function manifestAt(project, dir, where) {
|
|
15
15
|
const text = readText(project, `/${dir}/package.json`, where)
|
|
16
|
-
if (text === undefined) throw new DeptreeError(`${quote(dir)} holds no package.json in the project given`, where)
|
|
16
|
+
if (text === undefined) throw new DeptreeError(`${quote(dir)} ${typeOf(project, `/${dir}`) === undefined ? 'is not in' : 'holds no package.json in'} the project given`, where)
|
|
17
17
|
return readManifest(text, where)
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -41,12 +41,24 @@ export function readDirectoryPackage(project, pkg, where, host) {
|
|
|
41
41
|
return { files, manifest, local: true }
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// pnpm takes `npm:@scope/name@workspace:<range>` for a path, for its `/`,
|
|
45
|
+
// which no other resolver takes, and links to a directory of that name.
|
|
46
|
+
const ALIASED = /(?:^|\/)(npm:(@[^/]+\/[^/]+)@(workspace:[^/]*))$/u
|
|
47
|
+
|
|
48
|
+
// pnpm links to a directory that is not there all the same: pnpm 10 and 11
|
|
49
|
+
// warn as they resolve, and none does as a frozen install. Refused, with the
|
|
50
|
+
// project given or, for the spec it takes for a path, without, but where the
|
|
51
|
+
// project holds a directory of that name.
|
|
44
52
|
export function readLinked(links, nodes, projects, project) {
|
|
45
53
|
const linked = new Map()
|
|
46
|
-
if (project === undefined) return linked
|
|
47
54
|
for (const [path, target] of links) {
|
|
48
55
|
if (nodes.has(target) || projects.has(target) || linked.has(target) || target === '..' || target.startsWith('../')) continue
|
|
49
|
-
|
|
56
|
+
const aliased = ALIASED.exec(target)
|
|
57
|
+
if (aliased !== null && (project === undefined || typeOf(project, `/${target}`) === undefined)) {
|
|
58
|
+
const [, spec, name, range] = aliased
|
|
59
|
+
throw new DeptreeError(`pnpm takes ${quote(spec)} for a path, for its "/", and links to ${quote(target)}${project === undefined ? '' : ', which is not there'}; ${quote(range.replace(':', `:${name}@`))} is the spec that links the workspace package`, quote(path))
|
|
60
|
+
}
|
|
61
|
+
if (project !== undefined) linked.set(target, manifestAt(project, target, quote(path)))
|
|
50
62
|
}
|
|
51
63
|
return linked
|
|
52
64
|
}
|
package/src/pnpm/package.js
CHANGED
|
@@ -85,8 +85,10 @@ export function checkManifest(manifest, pkg, where, major) {
|
|
|
85
85
|
|
|
86
86
|
const bundledOf = (manifest) => manifest.bundleDependencies ?? manifest.bundledDependencies
|
|
87
87
|
|
|
88
|
-
// pnpm 10 writes an empty list of bundled dependencies, pnpm 11 none
|
|
89
|
-
|
|
88
|
+
// pnpm 10 writes an empty list of bundled dependencies, pnpm 11 none; for a
|
|
89
|
+
// `false`, as react@16.14.0's package.json has, pnpm 10, 11 and 12 write none,
|
|
90
|
+
// and npm publishes none.
|
|
91
|
+
const listed = (bundled) => (bundled === false || (Array.isArray(bundled) && bundled.length === 0) ? undefined : bundled)
|
|
90
92
|
|
|
91
93
|
// `read` is the package.json as hook.js's hook has it, and `packages` the
|
|
92
94
|
// lockfile's, by which a `file:` target is the directory it resolves to.
|
package/src/pnpm/readers.js
CHANGED
|
@@ -42,6 +42,10 @@ export const readers = {
|
|
|
42
42
|
linkWorkspacePackages(value, where) {
|
|
43
43
|
return value === 'deep' ? true : readers.boolean(value, where)
|
|
44
44
|
},
|
|
45
|
+
// A path, or a list of them, which pnpm 12 takes too.
|
|
46
|
+
pnpmfile(value, where) {
|
|
47
|
+
return typeof value === 'string' ? value : readers.list(value, where, 'a string or a list of strings')
|
|
48
|
+
},
|
|
45
49
|
sideEffectsCache(value, where) {
|
|
46
50
|
if (typeof value === 'boolean') return value
|
|
47
51
|
if (readers.mapping(value, where).remote != null) never('what a build left in a remote cache is not restored here')(value.remote, `${where}.remote`)
|
|
@@ -100,6 +104,10 @@ export const READ = {
|
|
|
100
104
|
filterProd: { kind: 'texts', check: never('every project is installed') },
|
|
101
105
|
useNodeVersion: { kind: 'text', check: never('the Node a tree is built for is the host\'s, or nodeVersion') },
|
|
102
106
|
globalPnpmfile: { kind: 'text', check: never('a pnpmfile\'s hooks are not run here') },
|
|
107
|
+
// [] loads none, not even the default one. An .npmrc's is passed over: from
|
|
108
|
+
// a path that leads nowhere pnpm 9 loads none, and a pnpmfile with hooks
|
|
109
|
+
// puts its pnpmfileChecksum in the lockfile, which is refused (tree.js).
|
|
110
|
+
pnpmfile: { kind: 'pnpmfile', check: (value, where) => (Array.isArray(value) && value.length === 0) || never('a pnpmfile\'s hooks are not run here')(value, where), rc: false },
|
|
103
111
|
registry: { kind: 'text', check: checkRegistry },
|
|
104
112
|
virtualStoreDirMaxLength: { kind: 'count' },
|
|
105
113
|
hoist: { kind: 'boolean' },
|
|
@@ -215,7 +223,7 @@ export const MANIFEST_KEYS = [
|
|
|
215
223
|
const IGNORED = new Set([
|
|
216
224
|
// resolution, already in the lockfile
|
|
217
225
|
'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
|
|
218
|
-
'dedupeInjectedDeps', 'dedupePeerDependents', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
|
|
226
|
+
'dedupeInjectedDeps', 'dedupePeerDependents', 'ignoreCompatibilityDb', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
|
|
219
227
|
'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
|
|
220
228
|
'registrySupportsTimeField', 'resolutionMode', 'resolvePeersFromWorkspaceRoot', 'saveExact', 'savePrefix',
|
|
221
229
|
'saveWorkspaceProtocol', 'strictPeerDependencies',
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// A git dependency as Soldeer 0.12 installs it, `git clone` and then `git
|
|
2
|
+
// checkout` of the lockfile's rev, from GitHub's tarball of that commit's
|
|
3
|
+
// tree instead: the files a checkout writes, without the .git it clones.
|
|
4
|
+
|
|
5
|
+
import { decompress } from '@preventive/archive/compression.js'
|
|
6
|
+
import { ArchiveError, unpack } from '@preventive/archive/tar.js'
|
|
7
|
+
import { DeptreeError, quote } from '../error.js'
|
|
8
|
+
import { MAX_BYTES } from '../tarball.js'
|
|
9
|
+
import { isGit } from './zip.js'
|
|
10
|
+
|
|
11
|
+
// A GitHub repository as git takes its URL over the protocols Soldeer has
|
|
12
|
+
// it allow, https and ssh, `.git` after it or not, the scheme and host in
|
|
13
|
+
// any case: https://github.com/<repo>, ssh://git@github.com/<repo> and
|
|
14
|
+
// git@github.com:<repo>. The owner and name are as GitHub takes them.
|
|
15
|
+
const REPO = String.raw`(?<repo>(?=[\dA-Za-z-]{1,39}\/)[\dA-Za-z](?:-?[\dA-Za-z])*\/[\w.-]{1,100}?)(?:\.git)?`
|
|
16
|
+
const URL_FORM = new RegExp(String.raw`^(?:(?i:https):\/\/|(?i:ssh):\/\/git@)(?i:github\.com)\/${REPO}\/?$`, 'u')
|
|
17
|
+
const SCP_FORM = new RegExp(String.raw`^git@(?i:github\.com):${REPO}$`, 'u')
|
|
18
|
+
|
|
19
|
+
export function githubRepoOf(url) {
|
|
20
|
+
const repo = (URL_FORM.exec(url) ?? SCP_FORM.exec(url))?.groups.repo
|
|
21
|
+
return repo === undefined || /\/\.\.?$/u.test(repo) ? undefined : repo
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// GitHub's tarball, which upstream holds to the tree GitHub names for the
|
|
25
|
+
// commit, files, symlinks and the submodules it shows as empty directories
|
|
26
|
+
// alike. Unpacked as a checkout with umask 0o022 writes it: directories
|
|
27
|
+
// 0o755, files 0o644 or 0o755 by the bit git keeps, symlinks as symlinks.
|
|
28
|
+
export async function checkoutOf(github, repo, rev, where) {
|
|
29
|
+
const bytes = await github.getRepoTarball({ repo, sha: rev })
|
|
30
|
+
let entries
|
|
31
|
+
try {
|
|
32
|
+
entries = unpack(await decompress(bytes, 'gzip', { limit: MAX_BYTES }))
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof ArchiveError) throw new DeptreeError(`its tarball from GitHub cannot be read: ${error.message}`, where, { cause: error })
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
const top = entries[0]?.name.split('/')[0]
|
|
38
|
+
const dirs = new Set()
|
|
39
|
+
const files = new Map()
|
|
40
|
+
const links = new Map()
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
if (entry.name === top) continue
|
|
43
|
+
if (!entry.name.startsWith(`${top}/`)) throw new Error('unreachable: an entry outside the one top directory upstream holds the tarball to')
|
|
44
|
+
const path = entry.name.slice(top.length + 1)
|
|
45
|
+
if (path.split('/').some(isGit)) throw new DeptreeError('a path with a .git in it, which git refuses to check out', `${where}: ${quote(path)}`)
|
|
46
|
+
if (entry.type === 'directory') dirs.add(path)
|
|
47
|
+
else if (entry.type === 'symlink') links.set(path, entry.linkname)
|
|
48
|
+
else if (entry.type === 'file') files.set(path, { data: entry.data, mode: entry.mode & 0o100 ? 0o755 : 0o644 })
|
|
49
|
+
else throw new Error(`unreachable: a ${entry.type} in a tarball of a git tree`)
|
|
50
|
+
}
|
|
51
|
+
return { dirs, files, links }
|
|
52
|
+
}
|
package/src/soldeer/tree.js
CHANGED
|
@@ -7,6 +7,7 @@ import { eachConcurrently } from '../concurrent.js'
|
|
|
7
7
|
import { DeptreeError, quote } from '../error.js'
|
|
8
8
|
import { fold, makeDirs, mount, writeFiles } from '../mount.js'
|
|
9
9
|
import { configOf } from './config.js'
|
|
10
|
+
import { checkoutOf, githubRepoOf } from './git.js'
|
|
10
11
|
import { checkHost, inputsOf } from './inputs.js'
|
|
11
12
|
import { extractZip } from './zip.js'
|
|
12
13
|
|
|
@@ -14,6 +15,12 @@ import { extractZip } from './zip.js'
|
|
|
14
15
|
// and version, which Soldeer's sanitize_filename leaves as they are on Unix.
|
|
15
16
|
const NAME = /^(?=.{3,100}$)[@\da-z][\da-z-]*[\da-z]$/u
|
|
16
17
|
const VERSION = /^(?=.{1,128}$)[\dA-Za-z][\w.+-]*$/u
|
|
18
|
+
// A folder sanitize_filename leaves as it is on Unix: none of the characters
|
|
19
|
+
// it replaces, and at most 255 bytes, past which it cuts the name short.
|
|
20
|
+
const encoder = new TextEncoder()
|
|
21
|
+
const isKept = (folder) => !/[/?<>\\:*|"\p{Cc}]/u.test(folder) && encoder.encode(folder).length <= 255
|
|
22
|
+
|
|
23
|
+
const GITHUB = 'github must be a GitHub client from createClient, which a git dependency is fetched through'
|
|
17
24
|
|
|
18
25
|
function checkNoDependencies(vfs, folded) {
|
|
19
26
|
for (const name of vfs.readdir('/')) {
|
|
@@ -25,49 +32,58 @@ function checkNoDependencies(vfs, folded) {
|
|
|
25
32
|
|
|
26
33
|
const about = (name) => `dependencies[${quote(name)}]`
|
|
27
34
|
|
|
28
|
-
function
|
|
35
|
+
function checkDependency({ type, name, version, git, folder }, config) {
|
|
36
|
+
const where = about(name)
|
|
37
|
+
if (type === 'private') throw new DeptreeError('a private dependency, which the registry hands out to those signed in alone, is not supported', where)
|
|
38
|
+
if (type === 'git') {
|
|
39
|
+
if (githubRepoOf(git) === undefined) throw new DeptreeError(`a git dependency from ${quote(git)}, not a GitHub repository over https or ssh, is not supported`, where)
|
|
40
|
+
if (!isKept(folder)) throw new DeptreeError(`its folder, ${quote(folder)}, is one Soldeer names otherwise, which is not supported`, where)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (config.dependencies?.[name]?.url !== undefined) throw new DeptreeError('a dependency from a URL of its own, rather than the registry, is not supported', where)
|
|
44
|
+
if (!NAME.test(name)) throw new DeptreeError('a name the registry does not take', where)
|
|
45
|
+
if (!VERSION.test(version)) throw new DeptreeError(`${quote(version)} is a version the registry does not take`, where)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function dependenciesOf(lock, config, folded) {
|
|
29
49
|
const dependencies = Object.values(lock.dependencies).map((dependency) => ({ ...dependency, folder: `${dependency.name}-${dependency.version}` }))
|
|
50
|
+
for (const dependency of dependencies) checkDependency(dependency, config)
|
|
30
51
|
const key = (folder) => (folded ? fold(folder) : folder)
|
|
31
52
|
const folders = new Set(dependencies.map(({ folder }) => key(folder)))
|
|
32
|
-
for (const { type, name,
|
|
33
|
-
|
|
34
|
-
if (type === 'git') throw new DeptreeError('a git dependency, which Soldeer clones with its history, is not supported', where)
|
|
35
|
-
if (type === 'private') throw new DeptreeError('a private dependency, which the registry hands out to those signed in alone, is not supported', where)
|
|
36
|
-
if (config.dependencies?.[name]?.url !== undefined) throw new DeptreeError('a dependency from a URL of its own, rather than the registry, is not supported', where)
|
|
37
|
-
if (!NAME.test(name)) throw new DeptreeError('a name the registry does not take', where)
|
|
38
|
-
if (!VERSION.test(version)) throw new DeptreeError(`${quote(version)} is a version the registry does not take`, where)
|
|
39
|
-
}
|
|
40
|
-
for (const { name, folder } of dependencies) {
|
|
41
|
-
if (folders.has(key(`${folder}.zip`))) throw new DeptreeError(`its zip is downloaded as ${quote(`${folder}.zip`)}, a folder Soldeer installs another dependency in`, about(name))
|
|
53
|
+
for (const { type, name, folder } of dependencies) {
|
|
54
|
+
if (type === 'http' && folders.has(key(`${folder}.zip`))) throw new DeptreeError(`its zip is downloaded as ${quote(`${folder}.zip`)}, a folder Soldeer installs another dependency in`, about(name))
|
|
42
55
|
}
|
|
43
56
|
return dependencies
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
async function fetchAll(dependencies) {
|
|
59
|
+
async function fetchAll(dependencies, github) {
|
|
47
60
|
const extracted = new Map()
|
|
48
|
-
await eachConcurrently(dependencies, async ({ name, version, checksum, folder }) => {
|
|
49
|
-
|
|
61
|
+
await eachConcurrently(dependencies, async ({ type, name, version, checksum, git, rev, folder }) => {
|
|
62
|
+
const where = about(name)
|
|
63
|
+
extracted.set(folder, type === 'git' ? await checkoutOf(github, githubRepoOf(git), rev, where) : await extractZip(await getZip(name, version, checksum), checksum, where))
|
|
50
64
|
}, ({ name }) => about(name))
|
|
51
65
|
return extracted
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
export async function buildSoldeerTree(options) {
|
|
55
|
-
const { host: given, vfs: into } = options ?? {}
|
|
69
|
+
const { host: given, vfs: into, github } = options ?? {}
|
|
56
70
|
if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
|
|
71
|
+
if (github !== undefined && typeof github?.getRepoTarball !== 'function') throw new TypeError(GITHUB)
|
|
57
72
|
const inputs = inputsOf(options ?? {})
|
|
58
73
|
const folded = checkHost(given).os === 'darwin'
|
|
59
74
|
// Refused before anything is fetched; mount checks again.
|
|
60
75
|
if (into !== undefined) checkNoDependencies(into, folded)
|
|
61
76
|
const config = configOf(inputs)
|
|
62
|
-
const dependencies =
|
|
63
|
-
|
|
77
|
+
const dependencies = dependenciesOf(parseSoldeerLockfile(inputs.lockfile, { config }), config, folded)
|
|
78
|
+
if (github === undefined && dependencies.some(({ type }) => type === 'git')) throw new TypeError(GITHUB)
|
|
79
|
+
const extracted = await fetchAll(dependencies, github)
|
|
64
80
|
const vfs = new Vfs()
|
|
65
81
|
makeDirs(vfs, 'dependencies')
|
|
66
|
-
const stats = { dependencies: dependencies.length, files: 0, bytes: 0 }
|
|
82
|
+
const stats = { dependencies: dependencies.length, files: 0, bytes: 0, links: 0 }
|
|
67
83
|
// In the lockfile's order, whatever order the fetches finished in.
|
|
68
84
|
for (const { folder } of dependencies) {
|
|
69
85
|
writeFiles(vfs, `dependencies/${folder}`, extracted.get(folder), stats)
|
|
70
86
|
}
|
|
71
|
-
const installed = dependencies.map(({ name, version, checksum, folder }) => ({ path: `dependencies/${folder}`, name, version, checksum }))
|
|
87
|
+
const installed = dependencies.map(({ type, name, version, checksum, git, rev, folder }) => ({ path: `dependencies/${folder}`, name, version, ...(type === 'git' ? { git, rev } : { checksum }) }))
|
|
72
88
|
return { vfs: mount(vfs, into, folded, checkNoDependencies), stats, installed }
|
|
73
89
|
}
|
package/src/soldeer/zip.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { ArchiveError, unzip } from '@preventive/archive/zip.js'
|
|
8
8
|
import { DeptreeError, quote } from '../error.js'
|
|
9
9
|
import { bytesSha256Hex } from '../hash.js'
|
|
10
|
+
import { MAX_BYTES } from '../tarball.js'
|
|
10
11
|
|
|
11
12
|
const END = 0x06054b50
|
|
12
13
|
const CENTRAL = 0x02014b50
|
|
@@ -14,9 +15,6 @@ const UTF8 = 0x0800
|
|
|
14
15
|
const S_IFLNK = 0o120000
|
|
15
16
|
const [NTFS, TIMESTAMP, UNICODE_COMMENT, AES] = [0x000a, 0x5455, 0x6375, 0x9901]
|
|
16
17
|
|
|
17
|
-
// As in ../tarball.js: the archive reader makes room for what entries declare.
|
|
18
|
-
const MAX_BYTES = 512 * 1024 * 1024
|
|
19
|
-
|
|
20
18
|
// As the archive reader decodes a name: a leading U+FEFF is part of it.
|
|
21
19
|
const decoder = new TextDecoder('utf-8', { ignoreBOM: true })
|
|
22
20
|
const encoder = new TextEncoder()
|
|
@@ -74,8 +72,9 @@ function unixMode({ system, attributes }) {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
// What str::trim_end_matches(['.', ' ']) and eq_ignore_ascii_case make of
|
|
77
|
-
// a component Soldeer holds to `.git
|
|
78
|
-
|
|
75
|
+
// a component Soldeer holds to `.git`; git's verify_path refuses to check
|
|
76
|
+
// one out, with core.protectNTFS, on by default.
|
|
77
|
+
export const isGit = (component) => component.replace(/[. ]+$/u, '').replace(/[A-Z]/gu, (char) => char.toLowerCase()) === '.git'
|
|
79
78
|
|
|
80
79
|
// getZip has held the zip to its checksum; it is held to it again where it
|
|
81
80
|
// is unpacked.
|
package/src/tarball.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// A registry tarball, fetched through @preventive/upstream, which checks the
|
|
2
2
|
// integrity it is given, and checked again here, as that is the lockfile's.
|
|
3
3
|
|
|
4
|
-
import { decompress } from '@preventive/archive/compression.js'
|
|
4
|
+
import { CompressionError, decompress } from '@preventive/archive/compression.js'
|
|
5
5
|
import { unpack } from '@preventive/archive/tar.js'
|
|
6
|
-
import { getTarball } from '@preventive/upstream/npm.js'
|
|
6
|
+
import { getMeta, getTarball } from '@preventive/upstream/npm.js'
|
|
7
7
|
import { DeptreeError, quote } from './error.js'
|
|
8
8
|
import { matchesIntegrity } from './hash.js'
|
|
9
9
|
import { fold } from './mount.js'
|
|
10
10
|
import { decodeUtf8 } from './project.js'
|
|
11
11
|
|
|
12
|
-
// What a tarball may unpack to, as upstream bounds what it
|
|
13
|
-
|
|
12
|
+
// What a tarball or a zip may unpack to, as upstream bounds what it
|
|
13
|
+
// downloads: the archive reader makes room for what entries declare.
|
|
14
|
+
export const MAX_BYTES = 512 * 1024 * 1024
|
|
14
15
|
export const REGISTRY = 'https://registry.npmjs.org/'
|
|
15
16
|
|
|
16
17
|
// The registry's own URL for a version's tarball, as npm and pnpm spell it.
|
|
@@ -27,13 +28,15 @@ function checkId(name, version, where) {
|
|
|
27
28
|
if (!NAME.test(name) || !VERSION.test(version)) throw new DeptreeError(`${quote(`${name}@${version}`)} is no package the registry's URL names as it is`, where)
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
// The registry's own tarball, by its sha512 alone, as fetchTarball takes it
|
|
31
|
-
|
|
31
|
+
// The registry's own tarball, by its sha512 alone, as fetchTarball takes it;
|
|
32
|
+
// where `unpinned`, with none where the lockfile records none, for
|
|
33
|
+
// fetchTarball to take the registry's.
|
|
34
|
+
export function ownTarball(url, name, version, integrity, where, unpinned = false) {
|
|
32
35
|
checkId(name, version, where)
|
|
33
36
|
const expected = tarballUrl(name, version)
|
|
34
37
|
if (url !== expected) throw new DeptreeError(`only the registry's own tarball of ${name}@${version}, ${expected}, is supported`, where)
|
|
35
38
|
const sha512 = integrity?.split(' ').find((part) => part.startsWith('sha512-'))
|
|
36
|
-
if (sha512 === undefined) throw new DeptreeError('a tarball with no sha512 integrity is not supported', where)
|
|
39
|
+
if (sha512 === undefined && !(unpinned && integrity === undefined)) throw new DeptreeError('a tarball with no sha512 integrity is not supported', where)
|
|
37
40
|
return { name, version, integrity: sha512 }
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -76,12 +79,47 @@ export function withDirs(files, where, dirs = new Set()) {
|
|
|
76
79
|
return { files, dirs }
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
// Old tarballs, as npm 1.0 packed them through the system's tar, may run on
|
|
83
|
+
// in zeros past their gzip stream, to a whole 10240-byte record. Node's
|
|
84
|
+
// zlib, which npm, pnpm and yarn unpack through, stops at a zero byte after
|
|
85
|
+
// the stream; the platform's stream refuses anything there, so the zeros are
|
|
86
|
+
// cut off. The stream's last four bytes are the length its last member
|
|
87
|
+
// inflates to, under 2^32 as MAX_BYTES is, so it ends within three bytes
|
|
88
|
+
// past the last that is not zero; or, where that member is empty, as zlib
|
|
89
|
+
// writes one, `03 00` and eight zeros, within nine. It ends at the one place
|
|
90
|
+
// it decompresses whole. Each place tried inflates it all again, which only
|
|
91
|
+
// a padded tarball pays for.
|
|
92
|
+
async function gunzip(bytes) {
|
|
93
|
+
const inflate = (end) => decompress(bytes.subarray(0, end), 'gzip', { limit: MAX_BYTES })
|
|
94
|
+
try {
|
|
95
|
+
return await inflate(bytes.length)
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (!(error instanceof CompressionError) || error.limited || bytes.at(-1) !== 0) throw error
|
|
98
|
+
const last = bytes.findLastIndex((byte) => byte !== 0)
|
|
99
|
+
for (let end = last + 1; end <= Math.min(last + 10, bytes.length - 1); end++) {
|
|
100
|
+
try {
|
|
101
|
+
return await inflate(end)
|
|
102
|
+
} catch {
|
|
103
|
+
// Not where the stream ends: the next byte may be.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw error
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// The registry's sha512 of a version, for a tarball ownTarball let through
|
|
111
|
+
// unpinned.
|
|
112
|
+
export async function registryIntegrity(name, version, where) {
|
|
113
|
+
checkId(name, version, where)
|
|
114
|
+
return (await getMeta(name, version)).dist.integrity
|
|
115
|
+
}
|
|
116
|
+
|
|
79
117
|
export async function fetchTarball(name, version, integrity, where) {
|
|
80
118
|
checkId(name, version, where)
|
|
81
119
|
if (!/^sha512-[\d+/A-Za-z]{86}==$/u.test(integrity)) throw new DeptreeError('a tarball with no sha512 integrity is not supported', where)
|
|
82
120
|
const bytes = await getTarball(name, version, { tarball: tarballUrl(name, version), integrity })
|
|
83
121
|
if (!await matchesIntegrity(bytes, integrity)) throw new DeptreeError(`the tarball is not ${integrity}`, where)
|
|
84
122
|
if (bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the tarball is not gzipped', where)
|
|
85
|
-
const tar = await
|
|
86
|
-
return { bytes, entries: unpack(tar), inflated: tar.length }
|
|
123
|
+
const tar = await gunzip(bytes)
|
|
124
|
+
return { bytes, entries: unpack(tar), inflated: tar.length, integrity }
|
|
87
125
|
}
|
package/src/yarn1/bins.js
CHANGED
|
@@ -20,7 +20,7 @@ export function checkBinLinks({ placed, patterns, locations, realOf }) {
|
|
|
20
20
|
const realBinLoc = realOf(binLoc)
|
|
21
21
|
for (const pattern of info.ref.dependencies) {
|
|
22
22
|
const dep = patterns.get(pattern)
|
|
23
|
-
if (dep.kind
|
|
23
|
+
if (dep.kind === 'workspace' || !locations.has(dep) || !dep.hasBins) continue
|
|
24
24
|
const found = locations.get(dep).some((at) => finds(dep.name, at, binLoc) || finds(dep.name, at, realBinLoc))
|
|
25
25
|
if (!found) throw new DeptreeError(`yarn finds no copy of ${quote(dep.name)} to link the bins of`, quote(loc))
|
|
26
26
|
}
|
package/src/yarn1/package.js
CHANGED
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
// than yarn holds it to: what npm packs, every entry under one directory,
|
|
4
4
|
// none in its own node_modules (npm packs those only for bundled
|
|
5
5
|
// dependencies), and a package.json of the lockfile's name and version.
|
|
6
|
+
// And a directory by `file:`, as yarn's copy fetcher installs it.
|
|
6
7
|
|
|
7
8
|
import { normalize } from '@preventive/vfs/path.js'
|
|
8
9
|
import { DeptreeError, quote } from '../error.js'
|
|
9
10
|
import { sha1Hex } from '../hash.js'
|
|
10
11
|
import { readManifest } from '../manifest.js'
|
|
11
|
-
import {
|
|
12
|
+
import { decodeUtf8, readBytes, typeOf } from '../project.js'
|
|
13
|
+
import { fetchTarball, fromMirror, isModules, ownTarball, registryIntegrity, sameFile, withDirs } from '../tarball.js'
|
|
14
|
+
import { fixLists } from './manifest.js'
|
|
15
|
+
import { kindOf, splitPattern } from './resolve.js'
|
|
12
16
|
|
|
13
17
|
const UMASK = 0o022
|
|
14
18
|
|
|
@@ -40,18 +44,21 @@ function entriesOf(entries, where) {
|
|
|
40
44
|
|
|
41
45
|
const decoder = new TextDecoder('utf-8', { fatal: true })
|
|
42
46
|
|
|
43
|
-
// `name` is the one fetched, as an `npm:` alias asks for it.
|
|
47
|
+
// `name` is the one fetched, as an `npm:` alias asks for it. yarn writes no
|
|
48
|
+
// integrity for a pattern that names the tarball's URL, but the sha1 after
|
|
49
|
+
// its `#`: the tarball is held to that, and to the registry's sha512.
|
|
44
50
|
export function registryTarball(entry, name, where) {
|
|
45
51
|
const { resolution } = entry
|
|
46
52
|
if (resolution === undefined) throw new DeptreeError('a directory, by file: or link:, is not supported', where)
|
|
47
53
|
const url = resolution.type === 'tarball' ? fromMirror(resolution.tarball) : resolution.tarball
|
|
48
|
-
|
|
54
|
+
const byUrl = entry.patterns.some((pattern) => kindOf(splitPattern(pattern).range, where) === 'tarball')
|
|
55
|
+
return ownTarball(url, name, entry.version, resolution.integrity, where, byUrl && resolution.sha1 !== undefined)
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
export async function fetchYarnPackage({ name, version, integrity }, where) {
|
|
52
|
-
const
|
|
53
|
-
const sha1 = await sha1Hex(bytes)
|
|
54
|
-
const { files, dirs } = entriesOf(entries, where)
|
|
59
|
+
const fetched = await fetchTarball(name, version, integrity ?? await registryIntegrity(name, version, where), where)
|
|
60
|
+
const sha1 = await sha1Hex(fetched.bytes)
|
|
61
|
+
const { files, dirs } = entriesOf(fetched.entries, where)
|
|
55
62
|
const file = files.get('package.json')
|
|
56
63
|
if (file === undefined) throw new DeptreeError('the tarball has no package.json', where)
|
|
57
64
|
let text
|
|
@@ -62,8 +69,53 @@ export async function fetchYarnPackage({ name, version, integrity }, where) {
|
|
|
62
69
|
}
|
|
63
70
|
const manifest = readManifest(text, `${where}: package.json`)
|
|
64
71
|
if (manifest.name !== name || manifest.version !== version) throw new DeptreeError(`package.json is for ${quote(`${manifest.name}@${manifest.version}`)}`, where)
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
return { ...withBins({ files, dirs }, manifest, where), sha1, integrity: fetched.integrity }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// A directory by `file:`, as yarn's copy fetcher installs it: all in it, each
|
|
76
|
+
// file's mode as it is, but what yarn's copy passes over (tree.js); read from
|
|
77
|
+
// the project, as yarn reads it again at every install. Held to more than
|
|
78
|
+
// yarn holds it to: no link, device or node_modules of its own in it, and a
|
|
79
|
+
// package.json of the name, version and lists its lockfile entry has, which
|
|
80
|
+
// yarn reads anew, installing whatever they are.
|
|
81
|
+
export function readYarnDirectory(project, { name, version, entry, dir }, where) {
|
|
82
|
+
if (typeOf(project, `/${dir}`, false) !== 'directory') throw new DeptreeError(`${quote(dir)} is not a directory of the project`, where)
|
|
83
|
+
const files = new Map()
|
|
84
|
+
const dirs = new Set()
|
|
85
|
+
const walk = (at) => {
|
|
86
|
+
for (const base of project.readdir(`/${dir}${at && `/${at}`}`)) {
|
|
87
|
+
const path = at ? `${at}/${base}` : base
|
|
88
|
+
const { type, mode } = project.lstat(`/${dir}/${path}`)
|
|
89
|
+
if (at === '' && isModules(base)) throw new DeptreeError(`${quote(`${dir}/${path}`)} is its own node_modules, which yarn copies beside what it installs there, and which is not supported`, where)
|
|
90
|
+
if (type === 'directory') {
|
|
91
|
+
dirs.add(path)
|
|
92
|
+
walk(path)
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
if (type !== 'file') throw new DeptreeError(`${quote(`${dir}/${path}`)} is a ${type}, which is not supported`, where)
|
|
96
|
+
if (!Number.isInteger(mode)) throw new TypeError(`project.lstat must give a file's mode, and gives ${String(mode)} for ${quote(`/${dir}/${path}`)}`)
|
|
97
|
+
if ((mode & ~0o777) !== 0) throw new DeptreeError(`${quote(`${dir}/${path}`)} has the mode ${mode.toString(8)}, which is not supported`, where)
|
|
98
|
+
files.set(path, { data: readBytes(project, `/${dir}/${path}`), mode })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
walk('')
|
|
102
|
+
const file = files.get('package.json')
|
|
103
|
+
if (file === undefined) throw new DeptreeError(`${quote(dir)} has no package.json, where yarn makes one up`, where)
|
|
104
|
+
const manifest = readManifest(decodeUtf8(file.data, 'package.json is not UTF-8', where), `${where}: package.json`)
|
|
105
|
+
const why = 'which yarn reads anew, installing what it says'
|
|
106
|
+
if (manifest.name !== name || manifest.version !== version) throw new DeptreeError(`package.json is for ${quote(`${manifest.name}@${manifest.version}`)}, not the lockfile's ${quote(`${name}@${version}`)}, ${why}`, where)
|
|
107
|
+
const fixed = fixLists(manifest)
|
|
108
|
+
for (const kind of ['dependencies', 'optionalDependencies']) {
|
|
109
|
+
const listed = Object.entries(fixed[kind] ?? {}).map(([dep, range]) => `${dep}@${range}`).sort()
|
|
110
|
+
const locked = Object.values(entry[kind] ?? {}).sort()
|
|
111
|
+
if (listed.join('\n') !== locked.join('\n')) throw new DeptreeError(`package.json's ${kind} are not the lockfile's, ${why}`, where)
|
|
112
|
+
}
|
|
113
|
+
return withBins(withDirs(files, where, dirs), manifest, where)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// As yarn's fetcher leaves a package in its cache (base-fetcher.js): each
|
|
117
|
+
// bin's target chmod 755, and a .bin made for the links.
|
|
118
|
+
function withBins({ files, dirs }, manifest, where) {
|
|
67
119
|
const bins = binsOf(manifest, { files, dirs })
|
|
68
120
|
if (bins.size > 0 && files.has('.bin')) throw new DeptreeError('.bin is a file, where yarn fails to make a directory for the bins', where)
|
|
69
121
|
for (const target of bins.values()) {
|
|
@@ -71,7 +123,7 @@ export async function fetchYarnPackage({ name, version, integrity }, where) {
|
|
|
71
123
|
const script = files.get(target.replace(/\/$/u, ''))
|
|
72
124
|
if (script !== undefined) script.mode = 0o755
|
|
73
125
|
}
|
|
74
|
-
return { files, dirs, manifest,
|
|
126
|
+
return { files, dirs, manifest, hasBins: bins.size > 0 }
|
|
75
127
|
}
|
|
76
128
|
|
|
77
129
|
// Bins as yarn's normalize-manifest reads them, targets normalized as Node's
|
package/src/yarn1/requests.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// What yarn 1 asks for at the top (install.js's fetchRequestFromCwd).
|
|
2
2
|
|
|
3
|
-
import { clean
|
|
4
|
-
import {
|
|
3
|
+
import { clean } from '@preventive/upstream/semver.js'
|
|
4
|
+
import { quote } from '../error.js'
|
|
5
5
|
import { matchesGlob } from '../glob.js'
|
|
6
6
|
import { cleanDependencies, globsOf } from './manifest.js'
|
|
7
|
+
import { kindOf } from './resolve.js'
|
|
7
8
|
|
|
8
9
|
// yarn names the workspace aggregator at random; this stands for it, and
|
|
9
10
|
// sorts where a name starting so sorts.
|
|
@@ -38,13 +39,14 @@ export function aggregatorOf(root, workspaces) {
|
|
|
38
39
|
return { name: AGGREGATOR, dir: '.', version: '1.0.0', manifest: cleanDependencies(manifest), aggregator: true }
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
// The resolutions as resolution-map.js reads them
|
|
42
|
-
//
|
|
42
|
+
// The resolutions as resolution-map.js reads them: to a semver range, or to a
|
|
43
|
+
// source, as kindOf takes one. One to neither a range nor a source, which
|
|
44
|
+
// yarn passes over, the lockfile reader refuses.
|
|
43
45
|
export function rulesOf(root) {
|
|
44
46
|
const rules = Object.entries(root.resolutions ?? {}).map(([path, range]) => {
|
|
45
47
|
const names = path.match(/(?:@[^/]+\/)?[^/]+/gu) ?? [path]
|
|
46
48
|
const name = names.at(-1)
|
|
47
|
-
|
|
49
|
+
kindOf(range, `manifests["."].resolutions[${quote(path)}]`)
|
|
48
50
|
return { path, name, glob: names.length === 1 ? `**/${path}` : path, pattern: `${name}@${range}` }
|
|
49
51
|
})
|
|
50
52
|
return [...Map.groupBy(rules, ({ name }) => name).values()].flat()
|
package/src/yarn1/resolve.js
CHANGED
|
@@ -7,8 +7,12 @@ import { DeptreeError, quote } from '../error.js'
|
|
|
7
7
|
import { matchesGlob } from '../glob.js'
|
|
8
8
|
|
|
9
9
|
// Beneath a top-level request, all run at once, each taking these microtask
|
|
10
|
-
// turns, by its resolver, before it checks for a package of its version
|
|
11
|
-
|
|
10
|
+
// turns, by its resolver, before it checks for a package of its version: a
|
|
11
|
+
// tarball URL as many as the registry. A directory is read at the top level
|
|
12
|
+
// alone, where nothing runs beside it; beneath, only one read already is
|
|
13
|
+
// asked for again, which yarn reads once all else has run, and takes the
|
|
14
|
+
// first's package for.
|
|
15
|
+
const TURNS = { registry: 5, workspace: 3, directory: 1 }
|
|
12
16
|
|
|
13
17
|
// yarn's normalizePattern.
|
|
14
18
|
export function splitPattern(pattern) {
|
|
@@ -19,13 +23,37 @@ export function splitPattern(pattern) {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
// yarn's normalizeRange: any range but a semver range or one with a `:`,
|
|
22
|
-
// such as an `npm:` alias, is a tag.
|
|
26
|
+
// such as an `npm:` alias, is a tag. Of the sources getExoticResolver takes,
|
|
27
|
+
// in its order, a tarball first, where a path ends in .tgz: the registry's
|
|
28
|
+
// own tarball by its URL, on npm's registry or yarn's mirror; and a
|
|
29
|
+
// directory, by `file:` or a path.
|
|
23
30
|
const TAG = /^[\w~-][\w.~-]*$/u
|
|
24
|
-
|
|
31
|
+
const TARBALL = /^https?:\/\/|^[^@]*\.(?:tgz|tar\.gz)$/u
|
|
32
|
+
const REGISTRY_TARBALL = /^https:\/\/registry\.(?:npmjs\.org|yarnpkg\.com)\/[^#?]+\.tgz$/u
|
|
33
|
+
const DIRECTORY = /^(?:file:|\.{1,2}\/|\/)/u
|
|
34
|
+
export function kindOf(range, where) {
|
|
25
35
|
if (validRange(range)) return 'range'
|
|
26
36
|
if (range.startsWith('npm:')) return 'alias'
|
|
27
|
-
if (
|
|
28
|
-
|
|
37
|
+
if (TARBALL.test(range)) {
|
|
38
|
+
if (REGISTRY_TARBALL.test(range)) return 'tarball'
|
|
39
|
+
} else if (DIRECTORY.test(range)) return 'directory'
|
|
40
|
+
else if (TAG.test(range)) return 'tag'
|
|
41
|
+
throw new DeptreeError('only a semver range, an npm: alias, a tag, a file: directory or the registry\'s own tarball URL is supported', where)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The directory a `file:` range names, as yarn resolves it from the
|
|
45
|
+
// lockfile's: one within the project, which it is read from.
|
|
46
|
+
function directoryOf(range, where) {
|
|
47
|
+
const path = range.replace(/^file:/u, '')
|
|
48
|
+
const segments = []
|
|
49
|
+
for (const segment of path.split('/')) {
|
|
50
|
+
if (segment === '..') {
|
|
51
|
+
if (segments.pop() === undefined) throw new DeptreeError(`${quote(path)} is outside the project, which is not supported`, where)
|
|
52
|
+
} else if (segment !== '' && segment !== '.') segments.push(segment)
|
|
53
|
+
}
|
|
54
|
+
if (path.startsWith('/')) throw new DeptreeError(`${quote(path)} is an absolute path, which is not supported`, where)
|
|
55
|
+
if (segments.length === 0) throw new DeptreeError('the project\'s own directory is not supported', where)
|
|
56
|
+
return segments.join('/')
|
|
29
57
|
}
|
|
30
58
|
|
|
31
59
|
// What a package asks for, in yarn's order. A lockfile entry's are patterns;
|
|
@@ -43,8 +71,9 @@ function asked(info, where) {
|
|
|
43
71
|
// Where yarn's cache keeps a package (generateModuleCachePath), which is
|
|
44
72
|
// what its hoister tells two references apart by: two of one package, as
|
|
45
73
|
// a tag or an alias asked for twice makes, are one there.
|
|
46
|
-
function locOf({ kind, name, version, entry }) {
|
|
74
|
+
function locOf({ kind, name, version, entry, dir }) {
|
|
47
75
|
if (kind === 'workspace') return `workspace\n${name}`
|
|
76
|
+
if (kind === 'directory') return `copy\n${dir}`
|
|
48
77
|
const { uid } = entry
|
|
49
78
|
const { sha1, integrity } = entry.resolution ?? {}
|
|
50
79
|
return `npm\n${name}\n${version}\n${uid !== undefined && uid !== version ? uid : sha1 ?? ''}\n${integrity ? 'integrity' : ''}`
|
|
@@ -56,6 +85,7 @@ class Resolver {
|
|
|
56
85
|
this.patterns = new Map()
|
|
57
86
|
this.byName = new Map()
|
|
58
87
|
this.delayed = []
|
|
88
|
+
this.late = []
|
|
59
89
|
this.diverted = []
|
|
60
90
|
}
|
|
61
91
|
|
|
@@ -74,13 +104,23 @@ class Resolver {
|
|
|
74
104
|
const workspace = this.workspaces.get(name)
|
|
75
105
|
if (workspace !== undefined && satisfies(workspace.version, range, { loose: true })) return { kind: 'workspace', name: workspace.name, version: workspace.version, workspace }
|
|
76
106
|
const where = quote(request.pattern)
|
|
77
|
-
const
|
|
107
|
+
const kind = kindOf(range, where)
|
|
78
108
|
const entry = this.lockfile.packages[request.pattern]
|
|
79
109
|
if (entry === undefined) throw new DeptreeError('yarn would resolve this pattern anew: the lockfile has no entry for it', where)
|
|
80
110
|
if (hasVersion && validRange(range) && !satisfies(entry.version, range)) {
|
|
81
111
|
throw new DeptreeError(`yarn would resolve this pattern anew: the lockfile has ${entry.version}, which the range does not take`, where)
|
|
82
112
|
}
|
|
83
|
-
return { kind: 'registry', name, version: entry.version, entry, tag }
|
|
113
|
+
if (kind !== 'directory') return { kind: 'registry', name, version: entry.version, entry, tag: kind === 'tag' }
|
|
114
|
+
const dir = directoryOf(range, where)
|
|
115
|
+
if (request.parentNames !== undefined && this.copyOf(name, dir) === undefined) {
|
|
116
|
+
throw new DeptreeError('a file: directory asked for beneath the top level, and not by the root or a resolution first, is not supported', where)
|
|
117
|
+
}
|
|
118
|
+
return { kind, name, version: entry.version, entry, dir }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// exoticRangeMatch: the package of `name` copied from `dir` already.
|
|
122
|
+
copyOf(name, dir) {
|
|
123
|
+
return this.byName.get(name)?.map((pattern) => this.patterns.get(pattern)).find((ref) => ref.kind === 'directory' && ref.dir === dir)
|
|
84
124
|
}
|
|
85
125
|
|
|
86
126
|
// No resolution applies to a top-level request.
|
|
@@ -101,7 +141,8 @@ class Resolver {
|
|
|
101
141
|
// the last of which its pattern names.
|
|
102
142
|
check(request, info) {
|
|
103
143
|
const { name, range } = splitPattern(request.pattern)
|
|
104
|
-
|
|
144
|
+
const found = info.kind === 'directory' ? this.copyOf(name, info.dir) : this.exactMatch(name, validRange(range) ? info.version : range)
|
|
145
|
+
if (found !== undefined) {
|
|
105
146
|
this.delayed.push(request)
|
|
106
147
|
return []
|
|
107
148
|
}
|
|
@@ -112,6 +153,7 @@ class Resolver {
|
|
|
112
153
|
kind: info.kind,
|
|
113
154
|
entry: info.entry,
|
|
114
155
|
workspace: info.workspace,
|
|
156
|
+
dir: info.dir,
|
|
115
157
|
patterns: [],
|
|
116
158
|
requests: [request],
|
|
117
159
|
asked: asked(info, quote(request.pattern)),
|
|
@@ -138,11 +180,16 @@ class Resolver {
|
|
|
138
180
|
return undefined
|
|
139
181
|
}
|
|
140
182
|
const info = this.infoOf(request)
|
|
183
|
+
if (info.kind === 'directory' && request.parentNames !== undefined) {
|
|
184
|
+
this.late.push(request)
|
|
185
|
+
return undefined
|
|
186
|
+
}
|
|
141
187
|
return { request, info, left: info.tag ? Infinity : TURNS[info.kind] }
|
|
142
188
|
}
|
|
143
189
|
|
|
144
190
|
answer(waiting) {
|
|
145
|
-
|
|
191
|
+
const reading = [...waiting.map(({ request }) => request), ...this.late]
|
|
192
|
+
if (reading.length > 1) throw new DeptreeError(`yarn resolves these in the order the filesystem answers it, which is not set: ${reading.map(({ pattern }) => quote(pattern)).join(', ')}`)
|
|
146
193
|
const [strand] = waiting
|
|
147
194
|
const where = quote(strand.request.pattern)
|
|
148
195
|
const { range } = splitPattern(strand.request.pattern)
|
|
@@ -169,13 +216,16 @@ class Resolver {
|
|
|
169
216
|
if (strands.every((strand) => strand.left === Infinity)) strands = this.answer(strands)
|
|
170
217
|
strands = this.turn(strands)
|
|
171
218
|
}
|
|
219
|
+
this.delayed.push(...this.late)
|
|
220
|
+
this.late = []
|
|
172
221
|
}
|
|
173
222
|
|
|
174
223
|
// yarn's resolveToExistingVersion for the delayed, then the diverted.
|
|
175
224
|
settle() {
|
|
176
225
|
for (const request of this.delayed) {
|
|
177
226
|
const { name } = splitPattern(request.pattern)
|
|
178
|
-
const
|
|
227
|
+
const info = this.infoOf(request)
|
|
228
|
+
const ref = info.kind === 'directory' ? this.copyOf(name, info.dir) : this.exactMatch(name, info.version)
|
|
179
229
|
ref.requests.push(request)
|
|
180
230
|
this.addPattern(request.pattern, ref)
|
|
181
231
|
if (!request.optional) ref.optional = false
|
package/src/yarn1/tree.js
CHANGED
|
@@ -15,7 +15,7 @@ import { incompatibility } from './compat.js'
|
|
|
15
15
|
import { Hoister } from './hoist.js'
|
|
16
16
|
import { checkHost, inputsOf } from './inputs.js'
|
|
17
17
|
import { checkRoot, fixLists } from './manifest.js'
|
|
18
|
-
import { fetchYarnPackage, registryTarball } from './package.js'
|
|
18
|
+
import { fetchYarnPackage, readYarnDirectory, registryTarball } from './package.js'
|
|
19
19
|
import { resolvePeers } from './peers.js'
|
|
20
20
|
import { AGGREGATOR, aggregatorOf, rulesOf, topRequests, workspacesOf } from './requests.js'
|
|
21
21
|
import { resolve, splitPattern } from './resolve.js'
|
|
@@ -35,11 +35,25 @@ async function fetchAll(refs) {
|
|
|
35
35
|
const fetched = new Map()
|
|
36
36
|
const tarballs = refs.map((ref) => ({ ref, tarball: registryTarball(ref.entry, fetchedName(ref), whereOf(ref)) }))
|
|
37
37
|
await eachConcurrently(tarballs, async ({ ref, tarball }) => {
|
|
38
|
-
fetched.set(ref,
|
|
38
|
+
fetched.set(ref, await fetchYarnPackage(tarball, whereOf(ref)))
|
|
39
39
|
}, ({ ref }) => whereOf(ref))
|
|
40
40
|
return fetched
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// Each file: directory, read from the project. yarn copies one into a place
|
|
44
|
+
// of its cache of its own each time it is asked for, as another package.
|
|
45
|
+
function readDirectories(order, project, fetched) {
|
|
46
|
+
const read = new Set()
|
|
47
|
+
for (const ref of order) {
|
|
48
|
+
if (ref.kind !== 'directory') continue
|
|
49
|
+
if (project === undefined) throw new DeptreeError('a file: directory is read from the project, which is not given', whereOf(ref))
|
|
50
|
+
if (read.has(ref.dir)) throw new DeptreeError(`${quote(ref.dir)} is asked for by another pattern too, which yarn copies as another package, and which is not supported`, whereOf(ref))
|
|
51
|
+
read.add(ref.dir)
|
|
52
|
+
fetched.set(ref, readYarnDirectory(project, ref, whereOf(ref)))
|
|
53
|
+
}
|
|
54
|
+
return read.size
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
// Under the aggregator, a package goes in its workspace's node_modules.
|
|
44
58
|
function locationOf(names, workspaces) {
|
|
45
59
|
if (names[0] === AGGREGATOR) return `${workspaces.get(names[1]).dir}/node_modules/${names.slice(2).join('/node_modules/')}`
|
|
@@ -66,11 +80,12 @@ function resolveProject(inputs, host) {
|
|
|
66
80
|
// first is fetched; the rest keep their lockfile entry as package.json, with
|
|
67
81
|
// no peers, bins, platforms or engines, and the first's files, and their
|
|
68
82
|
// URL's sha1 is held to the first's tarball.
|
|
69
|
-
async function fetchChecked(resolved, host, settings) {
|
|
83
|
+
async function fetchChecked(resolved, host, settings, project) {
|
|
70
84
|
const order = [...new Set(resolved.patterns.values())]
|
|
71
85
|
const first = new Map()
|
|
72
86
|
for (const ref of order) if (ref.kind === 'registry' && !first.has(ref.loc)) first.set(ref.loc, ref)
|
|
73
87
|
const fetched = await fetchAll([...first.values()])
|
|
88
|
+
const directories = readDirectories(order, project, fetched)
|
|
74
89
|
const manifestOf = new Map()
|
|
75
90
|
for (const ref of order) {
|
|
76
91
|
let manifest = ref.workspace?.manifest
|
|
@@ -81,6 +96,9 @@ async function fetchChecked(resolved, host, settings) {
|
|
|
81
96
|
fetched.set(ref, fetched.get(head))
|
|
82
97
|
ref.hasBins = head === ref && fetched.get(ref).hasBins
|
|
83
98
|
manifest = head === ref ? fixLists(fetched.get(ref).manifest) : { name: ref.name, version: ref.version }
|
|
99
|
+
} else if (ref.kind === 'directory') {
|
|
100
|
+
ref.hasBins = fetched.get(ref).hasBins
|
|
101
|
+
manifest = fixLists(fetched.get(ref).manifest)
|
|
84
102
|
}
|
|
85
103
|
const bundled = manifest.bundleDependencies ?? manifest.bundledDependencies
|
|
86
104
|
if (bundled && !(Array.isArray(bundled) && bundled.length === 0)) throw new DeptreeError('a package with bundled dependencies is not supported', whereOf(ref))
|
|
@@ -92,7 +110,7 @@ async function fetchChecked(resolved, host, settings) {
|
|
|
92
110
|
if (!ref.optional) throw new DeptreeError(`${reason}, and it is not optional, which yarn fails on`, whereOf(ref))
|
|
93
111
|
ref.incompatible = true
|
|
94
112
|
}
|
|
95
|
-
return { packages: first.size, fetched, manifestOf }
|
|
113
|
+
return { packages: first.size + directories, fetched, manifestOf }
|
|
96
114
|
}
|
|
97
115
|
|
|
98
116
|
// Sorted as yarn's linker sorts its absolute paths, all under one directory,
|
|
@@ -124,7 +142,7 @@ function writeTree(placed, fetched) {
|
|
|
124
142
|
const copies = new Map()
|
|
125
143
|
const left = new Map()
|
|
126
144
|
for (const { info: { ref } } of placed) {
|
|
127
|
-
if (ref.kind
|
|
145
|
+
if (ref.kind !== 'workspace') left.set(fetched.get(ref), (left.get(fetched.get(ref)) ?? 0) + 1)
|
|
128
146
|
}
|
|
129
147
|
const letGo = (pkg) => Object.assign(pkg, { files: undefined, dirs: undefined })
|
|
130
148
|
for (const pkg of new Set(fetched.values())) if (!left.has(pkg)) letGo(pkg)
|
|
@@ -156,8 +174,10 @@ function listInstalled(copies, fetched, asked, hoister) {
|
|
|
156
174
|
const prod = hoister.reachedBut('dev', asked)
|
|
157
175
|
const required = hoister.reachedBut('optional', asked)
|
|
158
176
|
return [...copies].map(([path, places]) => {
|
|
159
|
-
const {
|
|
160
|
-
|
|
177
|
+
const { ref } = places[0]
|
|
178
|
+
const { manifest, integrity } = fetched.get(ref)
|
|
179
|
+
const from = ref.kind === 'directory' ? { directory: ref.dir } : { integrity }
|
|
180
|
+
return { path, name: manifest.name, version: manifest.version, ...from, dev: !places.some((info) => prod.has(info)), optional: !places.some((info) => required.has(info)) }
|
|
161
181
|
}).sort((a, b) => compareNames(a.path, b.path))
|
|
162
182
|
}
|
|
163
183
|
|
|
@@ -171,14 +191,14 @@ export async function buildYarn1Tree(options) {
|
|
|
171
191
|
if (into !== undefined) checkNoModules(into, folded)
|
|
172
192
|
checkRoot(inputs.manifests.get('.'))
|
|
173
193
|
const { workspaces, asked, resolved } = resolveProject(inputs, host)
|
|
174
|
-
const { packages, fetched, manifestOf } = await fetchChecked(resolved, host, inputs.settings)
|
|
194
|
+
const { packages, fetched, manifestOf } = await fetchChecked(resolved, host, inputs.settings, inputs.project)
|
|
175
195
|
const { placed, hoister } = layout({ resolved, manifestOf, asked, workspaces })
|
|
176
196
|
const { vfs, links, locations, copies, files, bytes } = writeTree(placed, fetched)
|
|
177
197
|
checkBinLinks({ placed, patterns: resolved.patterns, locations, realOf: (path) => realOf(links, path) })
|
|
178
198
|
const stats = {
|
|
179
199
|
packages,
|
|
180
200
|
skipped: [...manifestOf.keys()].filter((ref) => ref.incompatible).length,
|
|
181
|
-
installed: placed.filter(({ info }) => info.ref.kind
|
|
201
|
+
installed: placed.filter(({ info }) => info.ref.kind !== 'workspace').length,
|
|
182
202
|
files,
|
|
183
203
|
bytes,
|
|
184
204
|
links: links.size,
|
package/yarn1.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ export { LockfileError } from '@preventive/lockfile/yarn1.js'
|
|
|
7
7
|
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
8
8
|
// Tarballs are fetched through it, and that is the one place anything here
|
|
9
9
|
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
10
|
-
// cache — under $npm_config_cache, or ~/.npm —
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
10
|
+
// cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
|
|
11
|
+
// from its own default cache directory or stasis's, where one there has the
|
|
12
|
+
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
13
|
+
// where one is set, which is where it writes each tarball it fetches:
|
|
14
|
+
// setCacheDir() sets the default one, and setCacheDir(false) unsets it.
|
|
15
|
+
// Unset, which it is until set, it writes nothing. yarn's own cache is
|
|
16
|
+
// never read. The project is read only through the view given as
|
|
17
|
+
// `project`, and the tree built in a Vfs.
|
|
16
18
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
17
19
|
|
|
18
20
|
// The machine yarn would install on, which a tree depends on: `yarn` is
|
|
@@ -44,13 +46,13 @@ export interface Yarn1Host {
|
|
|
44
46
|
// A view of the lockfile's directory, by paths from `/`: a Vfs, or
|
|
45
47
|
// anything with its readdir, lstat, stat and readFile, such as one of a
|
|
46
48
|
// directory on disk, of which only this is read: the names in a
|
|
47
|
-
// directory; what a path is, `file`, `directory` or `symlink`,
|
|
48
|
-
// and what it leads to with stat; and a file's bytes.
|
|
49
|
-
// whose `code` is ENOENT, ENOTDIR or ELOOP for a path
|
|
50
|
-
// Nothing is written to it.
|
|
49
|
+
// directory; what a path is, `file`, `directory` or `symlink`, and its
|
|
50
|
+
// mode, with lstat, and what it leads to with stat; and a file's bytes.
|
|
51
|
+
// Each throws an error whose `code` is ENOENT, ENOTDIR or ELOOP for a path
|
|
52
|
+
// that leads nowhere. Nothing is written to it.
|
|
51
53
|
export interface Yarn1Project {
|
|
52
54
|
readdir(path: string): string[]
|
|
53
|
-
lstat(path: string): { type: NodeType }
|
|
55
|
+
lstat(path: string): { type: NodeType, mode: number }
|
|
54
56
|
stat(path: string): { type: NodeType }
|
|
55
57
|
readFile(path: string): Uint8Array
|
|
56
58
|
}
|
|
@@ -151,7 +153,8 @@ export interface Yarn1TreeRead {
|
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
// What buildYarn1Tree counts, all of it plain numbers: `packages` the
|
|
154
|
-
//
|
|
156
|
+
// packages yarn resolves, each fetched from the registry or read from a
|
|
157
|
+
// directory of the project; `skipped` the optional
|
|
155
158
|
// ones left out, as the host cannot run them; `installed` the copies of
|
|
156
159
|
// them in the tree; `files` and `bytes` what is written; `links` the
|
|
157
160
|
// workspaces linked.
|
|
@@ -164,12 +167,14 @@ export interface Yarn1TreeStats {
|
|
|
164
167
|
links: number
|
|
165
168
|
}
|
|
166
169
|
|
|
167
|
-
// A copy of a
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
170
|
+
// A copy of a package in the tree, as an SBOM would list it: `path` is
|
|
171
|
+
// where its files really are, from the lockfile's directory, which is `/`
|
|
172
|
+
// of the Vfs — node_modules/<alias>, or beneath a workspace, in that
|
|
173
|
+
// workspace's own node_modules. `name` and `version` are the package's
|
|
174
|
+
// own, which its package.json is held to, whatever alias it is installed
|
|
175
|
+
// as; `integrity` the sha512 its tarball is held to, for a registry
|
|
176
|
+
// package, and `directory` the directory of the project it is copied
|
|
177
|
+
// from, for one by `file:`, in place of an integrity. `dev` is
|
|
173
178
|
// whether dev dependencies alone reach this copy, the root's and the
|
|
174
179
|
// workspaces' devDependencies: nothing else does, each dependency, and
|
|
175
180
|
// each peer yarn finds, looked for from where what asks for it is, as Node
|
|
@@ -181,7 +186,8 @@ export interface Yarn1Installed {
|
|
|
181
186
|
path: string
|
|
182
187
|
name: string
|
|
183
188
|
version: string
|
|
184
|
-
integrity
|
|
189
|
+
integrity?: string
|
|
190
|
+
directory?: string
|
|
185
191
|
dev: boolean
|
|
186
192
|
optional: boolean
|
|
187
193
|
}
|
|
@@ -212,7 +218,9 @@ export interface Yarn1Tree {
|
|
|
212
218
|
// package's peers looked for along the shortest chain of names that asked
|
|
213
219
|
// for it, as yarn looks for them; and the tree laid out as yarn's hoister
|
|
214
220
|
// lays it out, quirks and all. A resolution applies to a dependency by its
|
|
215
|
-
// path, as yarn applies it, and not to one of the root's own
|
|
221
|
+
// path, as yarn applies it, and not to one of the root's own; it resolves
|
|
222
|
+
// to a semver range, or to the registry's own tarball or a directory of
|
|
223
|
+
// the project, as below.
|
|
216
224
|
//
|
|
217
225
|
// Scripts are always ignored, as `--ignore-scripts` has yarn ignore them,
|
|
218
226
|
// whatever the settings say. No .bin is written, nor yarn's own
|
|
@@ -246,10 +254,11 @@ export interface Yarn1Tree {
|
|
|
246
254
|
// directory that differ only in case or normalization are refused, as
|
|
247
255
|
// they would be one name there.
|
|
248
256
|
//
|
|
249
|
-
// Packages come from npm's registry
|
|
250
|
-
// `resolved` has to be the registry's own URL of its
|
|
251
|
-
// npm spells it,
|
|
252
|
-
// (a `#` and the
|
|
257
|
+
// Packages come from npm's registry, or from a directory of the project.
|
|
258
|
+
// A registry entry's `resolved` has to be the registry's own URL of its
|
|
259
|
+
// tarball, exactly as npm spells it,
|
|
260
|
+
// https://registry.npmjs.org/<name>/-/<base>-<version>.tgz (a `#` and the
|
|
261
|
+
// sha1 after it aside), or that same URL on yarn's mirror,
|
|
253
262
|
// https://registry.yarnpkg.com/, which is taken for npm's; it is fetched
|
|
254
263
|
// from npm's through @preventive/upstream. Each is asked for by a semver
|
|
255
264
|
// range, an `npm:` alias, or a tag — the last only where the project is
|
|
@@ -258,6 +267,29 @@ export interface Yarn1Tree {
|
|
|
258
267
|
// requests of tags wait on the filesystem at once, which it answers in no
|
|
259
268
|
// set order.
|
|
260
269
|
//
|
|
270
|
+
// Or by the registry's own tarball URL, either of those above (no `#`
|
|
271
|
+
// after it): the entry yarn writes for one has no integrity, so its
|
|
272
|
+
// tarball is held to the sha1 after the `#` of its `resolved` and to the
|
|
273
|
+
// registry's own sha512. Or, by the root or as what a resolution resolves
|
|
274
|
+
// to, by a directory of the project, `file:<path>` or a path starting
|
|
275
|
+
// `./`, within the project and not its root; beneath another package,
|
|
276
|
+
// where yarn reads it in an order not modelled here, only one read
|
|
277
|
+
// already, as the workspaces' aggregator asks for the root's again, which
|
|
278
|
+
// yarn takes the first's package for, but not where a tag waits on the
|
|
279
|
+
// filesystem beside it. yarn copies a
|
|
280
|
+
// directory whole, whatever package.json's `files` and an ignore file
|
|
281
|
+
// say, each file's mode as it is, each bin's target made executable, and
|
|
282
|
+
// the tree copies it so, read from `project`, which has to be given for
|
|
283
|
+
// it: all but each `.bin`, .yarn-metadata.json and .yarn-tarball.tgz in
|
|
284
|
+
// it, as yarn's copy passes them over, empty directories kept. yarn reads
|
|
285
|
+
// a directory's package.json anew at every install, frozen or not, and
|
|
286
|
+
// installs whatever its version and dependencies say; so it has to be of
|
|
287
|
+
// the name and version its lockfile entry has, with the dependencies and
|
|
288
|
+
// optionalDependencies the entry lists. Refused: a link, device or a
|
|
289
|
+
// node_modules of its own in it, a mode beyond 0o777, a directory two
|
|
290
|
+
// patterns ask for, which yarn copies as two packages, and a tarball on
|
|
291
|
+
// the project's disk, which yarn takes for any path ending in .tgz.
|
|
292
|
+
//
|
|
261
293
|
// Ranges and versions are read with npm's own semver, borrowed from the
|
|
262
294
|
// npm beside node as @preventive/upstream borrows it, or with its semver
|
|
263
295
|
// peer where there is no npm, without either of which this throws. yarn
|
|
@@ -266,8 +298,8 @@ export interface Yarn1Tree {
|
|
|
266
298
|
//
|
|
267
299
|
// Nothing is left to a guess: a lockfile the lockfile reader refuses, a
|
|
268
300
|
// setting this does not know or does not build for, a package from
|
|
269
|
-
// anywhere but
|
|
270
|
-
//
|
|
301
|
+
// anywhere but those above — git, another tarball URL, a tarball on disk,
|
|
302
|
+
// a directory by `link:` — a range that is none of those above, a package
|
|
271
303
|
// with bundled dependencies, another package manager, a check above that
|
|
272
304
|
// fails — each is refused with a DeptreeError or a LockfileError that says
|
|
273
305
|
// where. A TypeError is thrown for options of the wrong type.
|