@preventive/deptree 1.0.0-alpha.0 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +27 -6
- package/pnpm.d.ts +143 -39
- package/pnpm.js +5 -3
- package/src/hash.js +4 -0
- package/src/mount.js +14 -7
- package/src/pnpm/bins.js +14 -14
- package/src/pnpm/frozen.js +30 -20
- package/src/pnpm/hoist.js +5 -4
- package/src/pnpm/hook.js +13 -22
- package/src/pnpm/inputs.js +125 -0
- package/src/pnpm/install.js +40 -29
- package/src/pnpm/local.js +36 -28
- package/src/pnpm/overrides.js +12 -5
- package/src/pnpm/packlist.js +100 -0
- package/src/pnpm/patches.js +3 -3
- package/src/pnpm/project.js +97 -0
- package/src/pnpm/projects.js +31 -18
- package/src/pnpm/settings.js +34 -21
- package/src/pnpm/tree.js +103 -83
- package/src/pnpm/uptodate.js +1 -1
- package/src/pnpm/workspace.js +161 -38
- package/src/tarball.js +22 -10
- package/src/yarn1/bins.js +38 -0
- package/src/yarn1/compat.js +86 -0
- package/src/yarn1/glob.js +52 -0
- package/src/yarn1/hoist.js +264 -0
- package/src/yarn1/inputs.js +125 -0
- package/src/yarn1/manifest.js +79 -0
- package/src/yarn1/package.js +148 -0
- package/src/yarn1/peers.js +58 -0
- package/src/yarn1/requests.js +90 -0
- package/src/yarn1/resolve.js +269 -0
- package/src/yarn1/settings.js +123 -0
- package/src/yarn1/tree.js +220 -0
- package/yarn1.d.ts +267 -0
- package/yarn1.js +14 -0
package/src/pnpm/uptodate.js
CHANGED
|
@@ -61,7 +61,7 @@ function checkPatches(locked, hashes, major) {
|
|
|
61
61
|
// Throws where pnpm would not install the lockfile as it is; hands back the
|
|
62
62
|
// patches by hash, their text and path, to apply where a snapshot names one.
|
|
63
63
|
// `overrides` is listOverrides's.
|
|
64
|
-
export async function checkUpToDate(lockfile, settings, overrides, given, major
|
|
64
|
+
export async function checkUpToDate(lockfile, settings, overrides, given, major) {
|
|
65
65
|
const { hashes, byHash } = await hashPatches(settings.patchedDependencies, given)
|
|
66
66
|
for (const [name, catalog] of Object.entries(lockfile.catalogs)) {
|
|
67
67
|
for (const [alias, { specifier }] of Object.entries(catalog)) {
|
package/src/pnpm/workspace.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
// under one lockfile: the root, always, and each directory whose
|
|
3
3
|
// package.json a glob of pnpm-workspace.yaml's `packages` takes, as
|
|
4
4
|
// @pnpm/fs.find-packages globs for them with tinyglobby — `<glob>/
|
|
5
|
-
// package.json`, less anything under node_modules or
|
|
6
|
-
// Without `packages`, or without pnpm-workspace.yaml,
|
|
7
|
-
// project. pnpm finds them on disk
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// for one the lockfile has no importer for, and installs every one.
|
|
5
|
+
// package.{json,yaml,json5}`, less anything under node_modules or
|
|
6
|
+
// bower_components. Without `packages`, or without pnpm-workspace.yaml,
|
|
7
|
+
// the root is the only project. pnpm finds them on disk: findProjects
|
|
8
|
+
// finds them so in the directories it is given, and checkWorkspace holds
|
|
9
|
+
// the lockfile's importers to them.
|
|
11
10
|
//
|
|
12
11
|
// A glob is read as tinyglobby reads it, normalized as a path first, as
|
|
13
12
|
// far as `*` and `**` go: `*` any run of characters in one directory's
|
|
@@ -19,55 +18,179 @@
|
|
|
19
18
|
// pnpm 11 leaves out what a `!` glob takes with micromatch too, a name
|
|
20
19
|
// starting with a dot and all.
|
|
21
20
|
|
|
21
|
+
import { normalize } from '@preventive/vfs/path.js'
|
|
22
22
|
import { DeptreeError, quote } from '../error.js'
|
|
23
23
|
import { escape } from '../matcher.js'
|
|
24
|
+
import { typeOf } from './project.js'
|
|
24
25
|
|
|
25
26
|
const UNSUPPORTED = /[?[\]{}()\\]/u
|
|
26
27
|
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
const names = []
|
|
31
|
-
for (const name of glob.split('/')) {
|
|
32
|
-
if (name === '' || name === '.') continue
|
|
33
|
-
if (name !== '..') names.push(name)
|
|
34
|
-
else if (names.length === 0) throw new DeptreeError(`${quote(glob)} reaches outside the workspace's directory, which is not supported`, where)
|
|
35
|
-
else names.pop()
|
|
36
|
-
}
|
|
37
|
-
return names
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// A name's pattern: `*` any run of characters, but not a leading dot
|
|
41
|
-
// unless `dot`.
|
|
42
|
-
const NAME = (name, dot) => `${name.startsWith('*') && !dot ? '(?!\\.)' : ''}${name.split('*').map(escape).join('[^/]*')}`
|
|
43
|
-
// `**`: any number of names, none with a leading dot unless `dot`, each
|
|
44
|
-
// with its `/`.
|
|
45
|
-
const GLOBSTAR = (dot) => `(?:${dot ? '' : '(?!\\.)'}[^/]+/)*`
|
|
28
|
+
// A name's pattern: `*` any run of characters, line terminators among
|
|
29
|
+
// them, but not a leading dot unless `dot`.
|
|
30
|
+
const NAME = (name, dot) => new RegExp(`^${name.startsWith('*') && !dot ? '(?!\\.)' : ''}${name.split('*').map(escape).join('[^/]*')}$`, 'u')
|
|
46
31
|
|
|
32
|
+
// A glob as the names of the paths it takes, normalized as tinyglobby
|
|
33
|
+
// does: each `**`, or the pattern of one name; `dot` whether `**` takes a
|
|
34
|
+
// name with a leading dot.
|
|
47
35
|
function compile(glob, where, dot) {
|
|
48
|
-
const
|
|
36
|
+
const path = normalize(`./${glob}/package.json`)
|
|
37
|
+
if (path.startsWith('../')) throw new DeptreeError(`${quote(glob)} reaches outside the workspace's directory, which is not supported`, where)
|
|
38
|
+
const names = path.split('/')
|
|
49
39
|
if (glob === '' || glob.startsWith('/') || UNSUPPORTED.test(glob) || glob.includes('!') || names.some((name) => name !== '**' && name.includes('**'))) {
|
|
50
40
|
throw new DeptreeError(`${quote(glob)} is not supported: only \`*\`, \`**\` as a whole name and a leading \`!\` are`, where)
|
|
51
41
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
return { names: names.map((name) => (name === '**' ? name : NAME(name, dot))), dot }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Which places in a glob the path of `names` leads to: for each index,
|
|
46
|
+
// whether the glob's names before it take the path, a name at a time, in
|
|
47
|
+
// time the glob's length for each and with no recursion, however many
|
|
48
|
+
// `**` it has. A `**` may take no name, so reaching one reaches the next.
|
|
49
|
+
function reach({ names: glob, dot }, names) {
|
|
50
|
+
let here = Array.from({ length: glob.length + 1 }, (_, g) => g === 0)
|
|
51
|
+
let next = Array.from({ length: glob.length + 1 }, () => false)
|
|
52
|
+
const onward = (places) => {
|
|
53
|
+
for (let g = 0; g < glob.length; g++) if (places[g] && glob[g] === '**') places[g + 1] = true
|
|
54
|
+
}
|
|
55
|
+
onward(here)
|
|
56
|
+
for (const name of names) {
|
|
57
|
+
next.fill(false)
|
|
58
|
+
for (let g = 0; g < glob.length; g++) {
|
|
59
|
+
if (!here[g]) continue
|
|
60
|
+
if (glob[g] !== '**') next[g + 1] ||= glob[g].test(name)
|
|
61
|
+
else if (dot || !name.startsWith('.')) next[g] = true
|
|
62
|
+
}
|
|
63
|
+
onward(next)
|
|
64
|
+
;[here, next] = [next, here]
|
|
65
|
+
}
|
|
66
|
+
return here
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Whether a glob takes the path of `names`.
|
|
70
|
+
const takes = (glob, names) => reach(glob, names)[glob.names.length]
|
|
71
|
+
|
|
72
|
+
// Whether tinyglobby walks into the directory at `names` for a glob, as
|
|
73
|
+
// its partial matcher has it: name by name, each has to be taken by the
|
|
74
|
+
// glob's name in the same place, until a `**` there takes one, which
|
|
75
|
+
// takes whatever is below it. A `**` that takes none is not tried, so a
|
|
76
|
+
// name with a leading dot a `**` stands before is never walked into.
|
|
77
|
+
function enters({ names: glob, dot }, names) {
|
|
78
|
+
for (const [i, name] of names.entries()) {
|
|
79
|
+
if (i === glob.length) return false
|
|
80
|
+
if (glob[i] === '**') return dot || !name.startsWith('.')
|
|
81
|
+
if (!glob[i].test(name)) return false
|
|
82
|
+
}
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// `packages`, the globs or undefined, as the globs that take and those
|
|
87
|
+
// that leave out; `major` pnpm's major version.
|
|
88
|
+
function compileAll(packages, major) {
|
|
89
|
+
const globs = { include: [], exclude: [] }
|
|
90
|
+
for (const glob of packages ?? []) {
|
|
91
|
+
const exclude = glob.startsWith('!')
|
|
92
|
+
globs[exclude ? 'exclude' : 'include'].push(compile(exclude ? glob.slice(1) : glob, 'pnpm-workspace.yaml: packages', exclude && major >= 11))
|
|
93
|
+
}
|
|
94
|
+
return globs
|
|
55
95
|
}
|
|
56
96
|
|
|
97
|
+
// What find-packages leaves out, as tinyglobby reads it, which does not
|
|
98
|
+
// take a name with a leading dot for `**`: what is under node_modules or
|
|
99
|
+
// bower_components.
|
|
100
|
+
const IGNORED = ['node_modules', 'bower_components'].map((name) => ({ names: ['**', NAME(name, false), '**'], dot: false }))
|
|
101
|
+
const ignored = (names) => IGNORED.some((glob) => takes(glob, names))
|
|
102
|
+
|
|
103
|
+
// Whether the globs take the manifest at `names`. What find-packages
|
|
104
|
+
// ignores it is not ignored for, in a directory tinyglobby walks into.
|
|
105
|
+
const taken = ({ include, exclude }, names) => include.some((glob) => takes(glob, names)) && !exclude.some((glob) => takes(glob, names))
|
|
106
|
+
|
|
107
|
+
// Whether tinyglobby walks into the directory at `names`, which it does
|
|
108
|
+
// through a link to one too.
|
|
109
|
+
const walked = ({ include }, names) => include.some((glob) => enters(glob, names)) && !ignored(names)
|
|
110
|
+
|
|
57
111
|
// `ids` are the projects' directories, `.` the root; `packages` the globs,
|
|
58
|
-
// or undefined; `major` pnpm's major version.
|
|
112
|
+
// or undefined; `major` pnpm's major version. pnpm finds a project where
|
|
113
|
+
// tinyglobby walks into each directory down to it, and the globs take its
|
|
114
|
+
// manifest.
|
|
59
115
|
export function checkWorkspace(ids, packages, major = 10) {
|
|
60
|
-
const
|
|
61
|
-
const globs = (packages ?? []).map((glob) => {
|
|
62
|
-
const exclude = glob.startsWith('!')
|
|
63
|
-
return { exclude, regexp: compile(exclude ? glob.slice(1) : glob, where, exclude && major >= 11) }
|
|
64
|
-
})
|
|
116
|
+
const globs = compileAll(packages, major)
|
|
65
117
|
for (const id of ids) {
|
|
66
118
|
if (id === '.') continue
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
if (!taken || id.split('/').includes('bower_components')) {
|
|
119
|
+
const names = id.split('/')
|
|
120
|
+
if (!names.every((_, i) => walked(globs, names.slice(0, i + 1))) || !taken(globs, [...names, 'package.json'])) {
|
|
70
121
|
throw new DeptreeError(`pnpm-workspace.yaml's packages ${packages === undefined ? 'are not set' : 'do not take this directory'}, so pnpm would not install it as a project`, `importers[${quote(id)}]`)
|
|
71
122
|
}
|
|
72
123
|
}
|
|
73
124
|
}
|
|
125
|
+
|
|
126
|
+
// Of what @preventive/lockfile holds an importer's key to, what a project
|
|
127
|
+
// under the lockfile's directory has to be: its path from there, in normal
|
|
128
|
+
// form, with no drive letter, and no control, bidirectional or backslash
|
|
129
|
+
// character, which the lockfile could not name it by.
|
|
130
|
+
const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
|
|
131
|
+
export function checkProjectId(id, where) {
|
|
132
|
+
if (id.split('/').some((name) => name === '' || name === '.' || name === '..' || UNSAFE.test(name)) || /^[A-Za-z]:/u.test(id)) {
|
|
133
|
+
throw new DeptreeError('expected a directory under the lockfile\'s, by its path from there in normal form, as a lockfile can key an importer', where)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// A manifest pnpm would read through a link, the root's among them, is
|
|
138
|
+
// refused before it is read.
|
|
139
|
+
export const linkedManifest = (file) => new DeptreeError('a link pnpm would read a project\'s manifest through is not supported', quote(file))
|
|
140
|
+
|
|
141
|
+
// The names pnpm reads a project's manifest by, the first of them there
|
|
142
|
+
// winning.
|
|
143
|
+
const MANIFESTS = ['package.json', 'package.json5', 'package.yaml']
|
|
144
|
+
|
|
145
|
+
// The directories of the projects pnpm `major` finds by the globs of
|
|
146
|
+
// `packages` in `project` (project.js): `.`, the root, then the rest in
|
|
147
|
+
// order. Every directory tinyglobby walks into is read, and no other, a
|
|
148
|
+
// link to one followed as it follows it. A manifest is a file, or a link
|
|
149
|
+
// to one; a link that leads nowhere, or to a directory, is none.
|
|
150
|
+
// Refused, as not read here: a root with no manifest, which pnpm takes
|
|
151
|
+
// for no project; a project, the root among them, whose manifest is
|
|
152
|
+
// package.json5, package.yaml or a link; a project found
|
|
153
|
+
// through a link, and a link to a directory in one followed, which is not
|
|
154
|
+
// followed; a project in a directory a lockfile could not key its
|
|
155
|
+
// importer by; and a node_modules tinyglobby walks into, which it does
|
|
156
|
+
// only under a directory with a leading dot, as what is installed there
|
|
157
|
+
// is no project buildPnpmTree builds.
|
|
158
|
+
export function findProjects(project, packages, major = 10) {
|
|
159
|
+
const globs = compileAll(packages, major)
|
|
160
|
+
const ids = []
|
|
161
|
+
// The directories left to read, by their names, and the link each is
|
|
162
|
+
// reached through, if any: a stack, not recursion, however deep the tree.
|
|
163
|
+
const pending = [{ names: [] }]
|
|
164
|
+
while (pending.length > 0) {
|
|
165
|
+
const { names, link } = pending.pop()
|
|
166
|
+
const dir = names.join('/')
|
|
167
|
+
const entries = project.readdir(`/${dir}`)
|
|
168
|
+
const found = names.length === 0 || taken(globs, [...names, 'package.json'])
|
|
169
|
+
? MANIFESTS.find((name) => entries.includes(name) && typeOf(project, `/${[...names, name].join('/')}`) === 'file')
|
|
170
|
+
: undefined
|
|
171
|
+
if (names.length === 0 && found === undefined) throw new DeptreeError('pnpm takes a workspace with no manifest at its root for one with no root project, which is not supported', quote('package.json'))
|
|
172
|
+
if (found !== undefined) {
|
|
173
|
+
const file = [...names, found].join('/')
|
|
174
|
+
if (project.lstat(`/${file}`).type === 'symlink') throw linkedManifest(file)
|
|
175
|
+
if (found !== 'package.json') throw new DeptreeError(`pnpm reads this project's ${found}, which is not supported`, quote(file))
|
|
176
|
+
if (link !== undefined) throw new DeptreeError(`pnpm finds a project through this link, ${quote(dir)}, which is not supported`, quote(link))
|
|
177
|
+
if (names.length > 0) {
|
|
178
|
+
checkProjectId(dir, quote(dir))
|
|
179
|
+
ids.push(dir)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const entry of entries) {
|
|
183
|
+
const at = [...names, entry]
|
|
184
|
+
if (!walked(globs, at)) continue
|
|
185
|
+
const path = at.join('/')
|
|
186
|
+
const { type } = project.lstat(`/${path}`)
|
|
187
|
+
const linked = type === 'symlink' && typeOf(project, `/${path}`) === 'directory'
|
|
188
|
+
if (type !== 'directory' && !linked) continue
|
|
189
|
+
if (entry === 'node_modules') throw new DeptreeError('pnpm-workspace.yaml\'s packages walk into this node_modules, which is not supported', quote(path))
|
|
190
|
+
if (!linked) pending.push({ names: at, link })
|
|
191
|
+
else if (link === undefined) pending.push({ names: at, link: path })
|
|
192
|
+
else throw new DeptreeError(`a link to a directory in one tinyglobby follows, ${quote(path)}, is not supported`, quote(link))
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return ['.', ...ids.sort()]
|
|
196
|
+
}
|
package/src/tarball.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import { decompress } from '@preventive/archive/compression.js'
|
|
27
27
|
import { unpack } from '@preventive/archive/tar.js'
|
|
28
28
|
import { normalize } from '@preventive/vfs/path.js'
|
|
29
|
+
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
29
30
|
import { getTarball } from '@preventive/upstream/npm.js'
|
|
30
31
|
import { DeptreeError, quote } from './error.js'
|
|
31
32
|
import { localOf } from './pnpm/overrides.js'
|
|
@@ -47,10 +48,11 @@ function nameOf(stored) {
|
|
|
47
48
|
return name.replaceAll('//', '/')
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const
|
|
51
|
+
export const sameBytes = (a, b) => a.length === b.length && a.every((byte, i) => byte === b[i])
|
|
52
|
+
const sameFile = (a, b) => a.mode === b.mode && sameBytes(a.data, b.data)
|
|
51
53
|
|
|
52
54
|
// A Map of each file's path in the package to its bytes and mode.
|
|
53
|
-
|
|
55
|
+
function filesOf(entries, where) {
|
|
54
56
|
const files = new Map()
|
|
55
57
|
const tops = new Set()
|
|
56
58
|
for (const entry of entries) {
|
|
@@ -100,17 +102,21 @@ function readManifest(files, pkg, where) {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// What the lockfile recorded of the package against the package.json.
|
|
103
|
-
function checkManifest(manifest, pkg, where) {
|
|
105
|
+
export function checkManifest(manifest, pkg, where) {
|
|
104
106
|
for (const field of ['os', 'cpu', 'libc']) {
|
|
105
107
|
if (!same(manifest[field], pkg[field])) throw new DeptreeError(`package.json's ${field} is not the lockfile's`, where)
|
|
106
108
|
}
|
|
107
109
|
const has = hasBin(manifest)
|
|
108
110
|
if (has !== undefined && has !== pkg.hasBin) throw new DeptreeError(`package.json ${pkg.hasBin ? 'has no bins, and the lockfile says it has' : 'has bins, and the lockfile says it has none'}`, where)
|
|
109
|
-
if (!same(bundledOf(manifest), pkg.bundledDependencies)) throw new DeptreeError('package.json bundles other than the lockfile says', where)
|
|
111
|
+
if (!same(listed(bundledOf(manifest)), listed(pkg.bundledDependencies))) throw new DeptreeError('package.json bundles other than the lockfile says', where)
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
const bundledOf = (manifest) => manifest.bundleDependencies ?? manifest.bundledDependencies
|
|
113
115
|
|
|
116
|
+
// Bundled dependencies as the lockfile records them, where pnpm 10 writes
|
|
117
|
+
// an empty list and pnpm 11 leaves it out.
|
|
118
|
+
const listed = (bundled) => (Array.isArray(bundled) && bundled.length === 0 ? undefined : bundled)
|
|
119
|
+
|
|
114
120
|
// A snapshot's dependencies against the package.json of its package, as
|
|
115
121
|
// fetchPackage read it and `read` as hook.js's hook has it. One the
|
|
116
122
|
// package.json, as overridden, names a directory for is linked there,
|
|
@@ -126,7 +132,7 @@ export function checkDependencies(manifest, read, pkg, where) {
|
|
|
126
132
|
const target = pkg.dependencies[name] ?? pkg.optionalDependencies[name]
|
|
127
133
|
if (target === undefined) continue
|
|
128
134
|
const local = localOf(spec, `${where}: package.json`)
|
|
129
|
-
if (local === undefined || target === `link:${local.dir}`) continue
|
|
135
|
+
if (local === undefined || target === `link:${local.dir}` || (local.protocol === 'file:' && packageKeyOf(target).endsWith(`@file:${local.dir}`))) continue
|
|
130
136
|
throw new DeptreeError(`the lockfile gives it ${quote(name)} as ${quote(target)}, and its package.json, overridden, names ${quote(local.dir)}`, where)
|
|
131
137
|
}
|
|
132
138
|
// A peer resolved is filed as optional where it is optional; pnpm's
|
|
@@ -138,14 +144,20 @@ export function checkDependencies(manifest, read, pkg, where) {
|
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
|
|
147
|
+
// A version's tarball from the registry, through @preventive/upstream, held
|
|
148
|
+
// to `integrity` and to be gzipped: its bytes, and its entries unpacked.
|
|
149
|
+
export async function fetchTarball(name, version, integrity, where) {
|
|
150
|
+
const bytes = await getTarball(name, version, { tarball: tarballUrl(name, version), integrity })
|
|
151
|
+
if (!await matchesIntegrity(bytes, integrity)) throw new DeptreeError(`the tarball is not ${integrity}`, where)
|
|
152
|
+
if (bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the tarball is not gzipped', where)
|
|
153
|
+
return { bytes, entries: unpack(await decompress(bytes, 'gzip', { limit: MAX_BYTES })) }
|
|
154
|
+
}
|
|
155
|
+
|
|
141
156
|
// A package's files, and its package.json as parsed; the package has to be
|
|
142
157
|
// from the registry.
|
|
143
158
|
export async function fetchPackage(pkg, where) {
|
|
144
|
-
const {
|
|
145
|
-
const
|
|
146
|
-
if (!await matchesIntegrity(bytes, integrity)) throw new DeptreeError(`the tarball is not ${integrity}`, where)
|
|
147
|
-
if (bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the tarball is not gzipped', where)
|
|
148
|
-
const files = filesOf(unpack(await decompress(bytes, 'gzip', { limit: MAX_BYTES })), where)
|
|
159
|
+
const { entries } = await fetchTarball(pkg.name, pkg.version, pkg.resolution.integrity, where)
|
|
160
|
+
const files = filesOf(entries, where)
|
|
149
161
|
const manifest = readManifest(files, pkg, where)
|
|
150
162
|
checkManifest(manifest, pkg, where)
|
|
151
163
|
return { files, manifest }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Where yarn 1 fails as it links bins (package-linker.js): of each package
|
|
2
|
+
// in the tree, each dependency's bins are linked from its copy nearest the
|
|
3
|
+
// package's node_modules, as node would find it from there, and yarn fails
|
|
4
|
+
// where there is none. What linking does to the tree, each target made
|
|
5
|
+
// executable, yarn's fetcher has done already (package.js). A dependency
|
|
6
|
+
// with no copy of its own reference in the tree, as one deduplicated into
|
|
7
|
+
// another's has none, links none, as yarn has no location for it.
|
|
8
|
+
|
|
9
|
+
import { dirname, join } from '@preventive/vfs/path.js'
|
|
10
|
+
import { DeptreeError, quote } from '../error.js'
|
|
11
|
+
import { binsOf } from './package.js'
|
|
12
|
+
|
|
13
|
+
// Whether node finds the package at `loc` by its name from `dir`, a
|
|
14
|
+
// directory at a time up from it, as yarn's
|
|
15
|
+
// findNearestInstalledVersionOfPackage looks. Paths are from the
|
|
16
|
+
// lockfile's directory, `.` it.
|
|
17
|
+
function finds(name, loc, dir) {
|
|
18
|
+
for (;; dir = dirname(dir)) {
|
|
19
|
+
if (join(dir, name) === loc || join(dir, `node_modules/${name}`) === loc) return true
|
|
20
|
+
if (dir === '.') return false
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// `placed` the flat tree, tree.js's; `patterns` resolve.js's; `fetched`
|
|
25
|
+
// each registry package's files, and `manifestOf` its package.json, as
|
|
26
|
+
// yarn has them; `locations` each reference's copies, where they really
|
|
27
|
+
// are, and `realOf` where a path in the tree really is.
|
|
28
|
+
export function checkBinLinks({ placed, patterns, fetched, manifestOf, locations, realOf }) {
|
|
29
|
+
for (const { loc, info } of placed) {
|
|
30
|
+
const binLoc = `${loc}/node_modules`
|
|
31
|
+
for (const pattern of info.ref.dependencies) {
|
|
32
|
+
const dep = patterns.get(pattern)
|
|
33
|
+
if (dep.kind !== 'registry' || !locations.has(dep) || binsOf(manifestOf.get(dep), fetched.get(dep)).size === 0) continue
|
|
34
|
+
const found = locations.get(dep).some((at) => finds(dep.name, at, binLoc) || finds(dep.name, at, realOf(binLoc)))
|
|
35
|
+
if (!found) throw new DeptreeError(`yarn finds no copy of ${quote(dep.name)} to link the bins of`, quote(loc))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// yarn 1's package-compatibility.js: a package whose os, cpu or engines
|
|
2
|
+
// the host does not take is left out where it is optional, and fails the
|
|
3
|
+
// install otherwise; so does the root project, checked as yarn checks it
|
|
4
|
+
// before anything is resolved. Engines are checked against the Node yarn
|
|
5
|
+
// runs on and yarn itself; any other engine Node reports a version of in
|
|
6
|
+
// process.versions — v8, uv, openssl and the rest — would be checked
|
|
7
|
+
// against the Node that runs yarn, which is not known here, and is
|
|
8
|
+
// refused. One yarn knows of no version for is passed over, as yarn
|
|
9
|
+
// passes over it.
|
|
10
|
+
|
|
11
|
+
import { compareVersions, major, satisfies, valid } from '@preventive/upstream/semver.js'
|
|
12
|
+
import { DeptreeError, quote } from '../error.js'
|
|
13
|
+
import { satisfiesWithPrereleases } from './peers.js'
|
|
14
|
+
|
|
15
|
+
// What Node reports in process.versions, but `node`, in any release or
|
|
16
|
+
// build of it from 12 on (src/node_metadata.h).
|
|
17
|
+
const REPORTED = new Set([
|
|
18
|
+
'acorn', 'ada', 'amaro', 'ares', 'base64', 'brotli', 'cjs_module_lexer', 'cldr', 'http_parser', 'icu', 'libffi', 'lief',
|
|
19
|
+
'llhttp', 'merve', 'modules', 'napi', 'nbytes', 'ncrypto', 'nghttp2', 'nghttp3', 'ngtcp2', 'openssl', 'simdjson', 'simdutf',
|
|
20
|
+
'sqlite', 'tz', 'undici', 'unicode', 'uv', 'uvwasi', 'v8', 'zlib', 'zstd',
|
|
21
|
+
])
|
|
22
|
+
|
|
23
|
+
// yarn's isValid: an os or cpu list of names, `!` before one to exclude.
|
|
24
|
+
function isValid(items, actual) {
|
|
25
|
+
let isNotWhitelist = true
|
|
26
|
+
let isBlacklist = false
|
|
27
|
+
for (const item of items) {
|
|
28
|
+
if (item[0] === '!') {
|
|
29
|
+
isBlacklist = true
|
|
30
|
+
if (actual === item.slice(1)) return false
|
|
31
|
+
} else {
|
|
32
|
+
isNotWhitelist = false
|
|
33
|
+
if (item === actual) return true
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return isBlacklist && isNotWhitelist
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const LOOSE = { loose: true }
|
|
40
|
+
|
|
41
|
+
// yarn's testEngine: yarn's own version taken with its prereleases, and
|
|
42
|
+
// Node's versions before 1.0.0 taken for its majors.
|
|
43
|
+
function testEngine(name, range, versions) {
|
|
44
|
+
const actual = versions[name]
|
|
45
|
+
if (!actual || !valid(actual, LOOSE)) return false
|
|
46
|
+
if (satisfies(actual, range, LOOSE)) return true
|
|
47
|
+
if (name === 'yarn' && satisfiesWithPrereleases(actual, range, true)) return true
|
|
48
|
+
if (name === 'node' && compareVersions(actual, '1.0.0', LOOSE) > 0) {
|
|
49
|
+
const of = major(actual, LOOSE)
|
|
50
|
+
return [`0.10.${of}`, `0.11.${of}`, `0.12.${of}`, `0.13.${of}`].some((fake) => satisfies(fake, range, LOOSE))
|
|
51
|
+
}
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Why the host does not take `manifest`, or undefined where it does; its
|
|
56
|
+
// os and cpu not checked with ignorePlatform, and its engines not with
|
|
57
|
+
// ignoreEngines. A manifest's engines may be a list of `name range`
|
|
58
|
+
// strings, which yarn reads into a mapping first.
|
|
59
|
+
export function incompatibility(manifest, host, where, { ignoreEngines, ignorePlatform }) {
|
|
60
|
+
const { os, cpu } = manifest
|
|
61
|
+
let { engines } = manifest
|
|
62
|
+
if (!ignorePlatform && Array.isArray(os) && os.length > 0 && !isValid(os, host.os)) return `its os, ${JSON.stringify(os)}, does not take ${quote(host.os)}`
|
|
63
|
+
if (!ignorePlatform && Array.isArray(cpu) && cpu.length > 0 && !isValid(cpu, host.cpu)) return `its cpu, ${JSON.stringify(cpu)}, does not take ${quote(host.cpu)}`
|
|
64
|
+
if (ignoreEngines) return undefined
|
|
65
|
+
if (Array.isArray(engines)) {
|
|
66
|
+
const read = {}
|
|
67
|
+
for (const item of engines) {
|
|
68
|
+
if (typeof item !== 'string') continue
|
|
69
|
+
const [name, ...rest] = item.trim().split(/ +/gu)
|
|
70
|
+
read[name] = rest.join(' ')
|
|
71
|
+
}
|
|
72
|
+
engines = read
|
|
73
|
+
}
|
|
74
|
+
if (engines === null || typeof engines !== 'object') return undefined
|
|
75
|
+
const versions = { node: host.node, yarn: host.yarn }
|
|
76
|
+
for (let [name, range] of Object.entries(engines)) {
|
|
77
|
+
if (name === 'iojs') name = 'node'
|
|
78
|
+
if (typeof range !== 'string' && (Object.hasOwn(versions, name) || REPORTED.has(name))) throw new DeptreeError(`engines.${name} is not a string, which yarn fails on`, where)
|
|
79
|
+
if (Object.hasOwn(versions, name)) {
|
|
80
|
+
if (!testEngine(name, range, versions)) return `its engines.${name}, ${quote(String(range))}, does not take ${versions[name]}`
|
|
81
|
+
} else if (REPORTED.has(name)) {
|
|
82
|
+
throw new DeptreeError(`yarn checks engines.${name} against the Node it runs on, which is not known here`, where)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The globs yarn matches with minimatch's defaults, as far as the lockfile
|
|
2
|
+
// reader lets them through: a segment at a time, `**` as any number of
|
|
3
|
+
// whole segments, `*` and `?` within one, and no segment that starts with
|
|
4
|
+
// a dot taken by a wildcard.
|
|
5
|
+
|
|
6
|
+
import { escape } from '../matcher.js'
|
|
7
|
+
|
|
8
|
+
const compiled = new Map()
|
|
9
|
+
|
|
10
|
+
function compile(glob) {
|
|
11
|
+
return glob.split('/').map((segment) => {
|
|
12
|
+
if (segment === '**') return null
|
|
13
|
+
const dot = segment.startsWith('.') || !/[*?]/u.test(segment) ? '' : '(?!\\.)'
|
|
14
|
+
return new RegExp(`^${dot}${segment.split(/([*?])/u).map((part) => (part === '*' ? '[^/]*' : part === '?' ? '[^/]' : escape(part))).join('')}$`, 'u')
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The places in `glob` that `path` reaches, a name at a time, a `**`
|
|
19
|
+
// taking none or more, in time linear in both: a place is the index of the
|
|
20
|
+
// glob's next segment, its length where all are taken.
|
|
21
|
+
function placesOf(glob, path) {
|
|
22
|
+
if (!compiled.has(glob)) compiled.set(glob, compile(glob))
|
|
23
|
+
const tests = compiled.get(glob)
|
|
24
|
+
const close = (places) => {
|
|
25
|
+
for (let i = 0; i < tests.length; i++) if (places.has(i) && tests[i] === null) places.add(i + 1)
|
|
26
|
+
return places
|
|
27
|
+
}
|
|
28
|
+
let places = close(new Set([0]))
|
|
29
|
+
for (const segment of path === '' ? [] : path.split('/')) {
|
|
30
|
+
const next = new Set()
|
|
31
|
+
for (const i of places) {
|
|
32
|
+
if (i === tests.length) continue
|
|
33
|
+
if (tests[i] === null) {
|
|
34
|
+
if (!segment.startsWith('.')) next.add(i)
|
|
35
|
+
} else if (tests[i].test(segment)) next.add(i + 1)
|
|
36
|
+
}
|
|
37
|
+
places = close(next)
|
|
38
|
+
}
|
|
39
|
+
return { places, length: tests.length }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Whether `glob` takes `path`.
|
|
43
|
+
export function matchesGlob(glob, path) {
|
|
44
|
+
const { places, length } = placesOf(glob, path)
|
|
45
|
+
return places.has(length)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Whether `glob` may take a path below `dir`: some of it left to take.
|
|
49
|
+
export function reachesBelow(glob, dir) {
|
|
50
|
+
const { places, length } = placesOf(glob, dir)
|
|
51
|
+
return [...places].some((place) => place < length)
|
|
52
|
+
}
|