@preventive/deptree 1.0.0-alpha.5 → 1.0.0-alpha.7
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/LICENSE-APACHE +202 -0
- package/npm.d.ts +288 -0
- package/npm.js +7 -0
- package/package.json +41 -12
- package/pnpm.d.ts +158 -25
- package/pnpm.js +2 -10
- package/soldeer.d.ts +13 -0
- package/soldeer.js +1 -7
- package/src/concurrent.js +16 -17
- package/src/error.js +5 -9
- package/src/glob.js +55 -0
- package/src/hash.js +60 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +104 -44
- package/src/npm/bins.js +54 -0
- package/src/npm/compat.js +97 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +75 -0
- package/src/npm/manifests.js +130 -0
- package/src/npm/package.js +57 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +136 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +22 -41
- package/src/pnpm/bins.js +152 -131
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +53 -96
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +29 -75
- package/src/pnpm/gitignore.js +139 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +68 -61
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +73 -56
- package/src/pnpm/install.js +85 -131
- package/src/pnpm/local.js +21 -40
- package/src/pnpm/minimatch.js +319 -0
- package/src/pnpm/nm-hoist-graph.js +299 -0
- package/src/pnpm/nm-hoist.js +149 -0
- package/src/pnpm/npm-packlist.js +217 -0
- package/src/pnpm/overrides.js +11 -51
- package/src/pnpm/package.js +121 -0
- package/src/pnpm/packlist.js +169 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +63 -83
- package/src/pnpm/settings.js +64 -100
- package/src/pnpm/tree.js +197 -169
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +124 -133
- package/src/project.js +57 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +5 -15
- package/src/soldeer/tree.js +22 -60
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +55 -140
- package/src/yarn1/bins.js +9 -19
- package/src/yarn1/compat.js +9 -28
- package/src/yarn1/hoist.js +53 -68
- package/src/yarn1/inputs.js +19 -61
- package/src/yarn1/manifest.js +8 -23
- package/src/yarn1/package.js +24 -63
- package/src/yarn1/peers.js +8 -15
- package/src/yarn1/requests.js +19 -37
- package/src/yarn1/resolve.js +36 -113
- package/src/yarn1/settings.js +15 -43
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +34 -5
- package/yarn1.js +1 -8
- package/src/pnpm/npmrc.js +0 -31
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/soldeer/tree.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
// The dependencies folder `soldeer install` makes from a soldeer.lock
|
|
2
|
-
// registry dependency's zip fetched, held to the lockfile's checksum, and
|
|
3
|
-
// extracted in a folder of its own (zip.js).
|
|
1
|
+
// The dependencies folder `soldeer install` makes from a soldeer.lock.
|
|
4
2
|
|
|
5
3
|
import { parseSoldeerLockfile } from '@preventive/lockfile/soldeer.js'
|
|
6
4
|
import { getZip } from '@preventive/upstream/soldeer.js'
|
|
7
|
-
import { Vfs
|
|
5
|
+
import { Vfs } from '@preventive/vfs'
|
|
8
6
|
import { eachConcurrently } from '../concurrent.js'
|
|
9
7
|
import { DeptreeError, quote } from '../error.js'
|
|
10
|
-
import { fold, mount } from '../mount.js'
|
|
11
|
-
import { checkCollisions } from '../pnpm/checks.js'
|
|
8
|
+
import { fold, makeDirs, mount, writeFiles } from '../mount.js'
|
|
12
9
|
import { configOf } from './config.js'
|
|
13
10
|
import { checkHost, inputsOf } from './inputs.js'
|
|
14
11
|
import { extractZip } from './zip.js'
|
|
15
12
|
|
|
16
|
-
// What the registry takes, as @preventive/upstream/soldeer.js
|
|
17
|
-
// and
|
|
18
|
-
// `<name>-<version>` as it is on Unix.
|
|
13
|
+
// What the registry takes, as @preventive/upstream/soldeer.js checks a name
|
|
14
|
+
// and version, which Soldeer's sanitize_filename leaves as they are on Unix.
|
|
19
15
|
const NAME = /^(?=.{3,100}$)[@\da-z][\da-z-]*[\da-z]$/u
|
|
20
16
|
const VERSION = /^(?=.{1,128}$)[\dA-Za-z][\w.+-]*$/u
|
|
21
17
|
|
|
22
|
-
// Refuses a Vfs that holds a dependencies folder at its root, or, where
|
|
23
|
-
// names are `folded`, a name that is one there.
|
|
24
18
|
function checkNoDependencies(vfs, folded) {
|
|
25
19
|
for (const name of vfs.readdir('/')) {
|
|
26
20
|
if (name === 'dependencies' || (folded && fold(name) === 'dependencies')) {
|
|
@@ -29,83 +23,51 @@ function checkNoDependencies(vfs, folded) {
|
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// with another that differs from it only in case or normalization.
|
|
26
|
+
const about = (name) => `dependencies[${quote(name)}]`
|
|
27
|
+
|
|
35
28
|
function registryDependencies(lock, config, folded) {
|
|
36
29
|
const dependencies = Object.values(lock.dependencies).map((dependency) => ({ ...dependency, folder: `${dependency.name}-${dependency.version}` }))
|
|
37
30
|
const key = (folder) => (folded ? fold(folder) : folder)
|
|
38
31
|
const folders = new Set(dependencies.map(({ folder }) => key(folder)))
|
|
39
32
|
for (const { type, name, version } of dependencies) {
|
|
40
|
-
const where =
|
|
33
|
+
const where = about(name)
|
|
41
34
|
if (type === 'git') throw new DeptreeError('a git dependency, which Soldeer clones with its history, is not supported', where)
|
|
42
35
|
if (type === 'private') throw new DeptreeError('a private dependency, which the registry hands out to those signed in alone, is not supported', where)
|
|
43
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)
|
|
44
37
|
if (!NAME.test(name)) throw new DeptreeError('a name the registry does not take', where)
|
|
45
38
|
if (!VERSION.test(version)) throw new DeptreeError(`${quote(version)} is a version the registry does not take`, where)
|
|
46
39
|
}
|
|
47
|
-
// Soldeer downloads each zip beside the folders, as `<folder>.zip`.
|
|
48
40
|
for (const { name, folder } of dependencies) {
|
|
49
|
-
if (folders.has(key(`${folder}.zip`))) throw new DeptreeError(`its zip is downloaded as ${quote(`${folder}.zip`)}, a folder Soldeer installs another dependency in`,
|
|
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))
|
|
50
42
|
}
|
|
51
43
|
return dependencies
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
// Each dependency's zip, fetched and extracted a few at a time, by its
|
|
55
|
-
// folder.
|
|
56
46
|
async function fetchAll(dependencies) {
|
|
57
47
|
const extracted = new Map()
|
|
58
48
|
await eachConcurrently(dependencies, async ({ name, version, checksum, folder }) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
extracted.set(folder, await extractZip(await getZip(name, version, checksum), where))
|
|
62
|
-
} catch (error) {
|
|
63
|
-
throw error instanceof DeptreeError ? error : new DeptreeError(error.message, where, { cause: error })
|
|
64
|
-
}
|
|
65
|
-
})
|
|
49
|
+
extracted.set(folder, await extractZip(await getZip(name, version, checksum), checksum, about(name)))
|
|
50
|
+
}, ({ name }) => about(name))
|
|
66
51
|
return extracted
|
|
67
52
|
}
|
|
68
53
|
|
|
69
|
-
function writeTree(extracted) {
|
|
70
|
-
const vfs = new Vfs()
|
|
71
|
-
vfs.mkdir('/dependencies')
|
|
72
|
-
let files = 0
|
|
73
|
-
let bytes = 0
|
|
74
|
-
for (const [folder, { dirs, files: written }] of extracted) {
|
|
75
|
-
const root = `/dependencies/${folder}`
|
|
76
|
-
vfs.mkdir(root)
|
|
77
|
-
for (const dir of dirs) vfs.mkdir(`${root}/${dir}`, { recursive: true })
|
|
78
|
-
for (const [path, file] of written) {
|
|
79
|
-
try {
|
|
80
|
-
vfs.writeFile(`${root}/${path}`, file.data, { mode: file.mode })
|
|
81
|
-
} catch (error) {
|
|
82
|
-
if (error instanceof VfsError) throw new DeptreeError(`cannot be written: ${error.message}`, quote(`dependencies/${folder}/${path}`), { cause: error })
|
|
83
|
-
throw error
|
|
84
|
-
}
|
|
85
|
-
files++
|
|
86
|
-
bytes += file.data.length
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return { vfs, files, bytes }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
54
|
export async function buildSoldeerTree(options) {
|
|
93
55
|
const { host: given, vfs: into } = options ?? {}
|
|
94
56
|
if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
|
|
95
57
|
const inputs = inputsOf(options ?? {})
|
|
96
|
-
const
|
|
97
|
-
const folded = host.os === 'darwin'
|
|
58
|
+
const folded = checkHost(given).os === 'darwin'
|
|
98
59
|
// Refused before anything is fetched; mount checks again.
|
|
99
60
|
if (into !== undefined) checkNoDependencies(into, folded)
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const dependencies = registryDependencies(lock, config, folded)
|
|
61
|
+
const config = configOf(inputs)
|
|
62
|
+
const dependencies = registryDependencies(parseSoldeerLockfile(inputs.lockfile, { config }), config, folded)
|
|
103
63
|
const extracted = await fetchAll(dependencies)
|
|
64
|
+
const vfs = new Vfs()
|
|
65
|
+
makeDirs(vfs, 'dependencies')
|
|
66
|
+
const stats = { dependencies: dependencies.length, files: 0, bytes: 0 }
|
|
104
67
|
// In the lockfile's order, whatever order the fetches finished in.
|
|
105
|
-
const {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
mount(vfs, into, folded, checkNoDependencies)
|
|
110
|
-
return { vfs: into, stats }
|
|
68
|
+
for (const { folder } of dependencies) {
|
|
69
|
+
writeFiles(vfs, `dependencies/${folder}`, extracted.get(folder), stats)
|
|
70
|
+
}
|
|
71
|
+
const installed = dependencies.map(({ name, version, checksum, folder }) => ({ path: `dependencies/${folder}`, name, version, checksum }))
|
|
72
|
+
return { vfs: mount(vfs, into, folded, checkNoDependencies), stats, installed }
|
|
111
73
|
}
|
package/src/soldeer/zip.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
// A registry zip as Soldeer 0.12 extracts it (download.rs's
|
|
2
|
-
// extract_dependency_archive,
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// of one name — where Soldeer would take some of it otherwise; what the two
|
|
7
|
-
// would read otherwise and the archive reader takes is refused here.
|
|
8
|
-
//
|
|
9
|
-
// A name a component of which is `.git`, as Windows reads one — trailing
|
|
10
|
-
// dots and spaces dropped, ASCII letters in either case — is passed over,
|
|
11
|
-
// with all beneath it; one with a `:` in it is refused, as Soldeer fails on
|
|
12
|
-
// it. A directory is made 0o755, whatever the archive says, and so is every
|
|
13
|
-
// directory on the way to an entry. A file's mode is its Unix mode as the
|
|
14
|
-
// zip crate reads it, without the type, setuid, setgid, sticky and group
|
|
15
|
-
// and other write bits, or 0o644 where it reads none; a symlink is a file,
|
|
16
|
-
// 0o644, holding its target. Both modes are as a umask of 0o022 leaves
|
|
17
|
-
// them.
|
|
2
|
+
// extract_dependency_archive, zip crate 8.6); what the archive reader takes
|
|
3
|
+
// and the two would read otherwise is refused. As a 0o022 umask leaves them,
|
|
4
|
+
// every directory is 0o755, and a file's mode its Unix mode as the zip crate
|
|
5
|
+
// reads it, or 0o644 where it reads none; a symlink is a file of its target.
|
|
18
6
|
|
|
19
7
|
import { ArchiveError, unzip } from '@preventive/archive/zip.js'
|
|
20
8
|
import { DeptreeError, quote } from '../error.js'
|
|
9
|
+
import { bytesSha256Hex } from '../hash.js'
|
|
21
10
|
|
|
22
11
|
const END = 0x06054b50
|
|
23
12
|
const CENTRAL = 0x02014b50
|
|
@@ -25,8 +14,7 @@ const UTF8 = 0x0800
|
|
|
25
14
|
const S_IFLNK = 0o120000
|
|
26
15
|
const [NTFS, TIMESTAMP, UNICODE_COMMENT, AES] = [0x000a, 0x5455, 0x6375, 0x9901]
|
|
27
16
|
|
|
28
|
-
//
|
|
29
|
-
// the archive reader makes room for what each entry declares.
|
|
17
|
+
// As in ../tarball.js: the archive reader makes room for what entries declare.
|
|
30
18
|
const MAX_BYTES = 512 * 1024 * 1024
|
|
31
19
|
|
|
32
20
|
// As the archive reader decodes a name: a leading U+FEFF is part of it.
|
|
@@ -35,10 +23,8 @@ const encoder = new TextEncoder()
|
|
|
35
23
|
|
|
36
24
|
const ones = (byte) => [...byte.toString(2)].filter((bit) => bit === '1').length
|
|
37
25
|
|
|
38
|
-
// Why the zip crate would fail on an entry's extra fields,
|
|
39
|
-
//
|
|
40
|
-
// timestamp, it does not read; or an AES field, which has it decrypt the
|
|
41
|
-
// entry, or a Unicode comment field, which it checks, both refused here.
|
|
26
|
+
// Why the zip crate would fail on an entry's extra fields, or undefined; an
|
|
27
|
+
// AES or a Unicode comment field is refused here.
|
|
42
28
|
function extraRefusal(view, at, length) {
|
|
43
29
|
for (let pos = at; pos < at + length;) {
|
|
44
30
|
const id = view.getUint16(pos, true)
|
|
@@ -53,10 +39,8 @@ function extraRefusal(view, at, length) {
|
|
|
53
39
|
return undefined
|
|
54
40
|
}
|
|
55
41
|
|
|
56
|
-
// What the zip crate reads of each entry that
|
|
57
|
-
//
|
|
58
|
-
// flags, its external attributes, its name's bytes. The layout has been
|
|
59
|
-
// checked whole by unzip, so each record is where it says.
|
|
42
|
+
// What the zip crate reads of each entry that unzip does not hand out. unzip
|
|
43
|
+
// has checked the layout whole, so each record is where it says.
|
|
60
44
|
function centralRecords(bytes) {
|
|
61
45
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
62
46
|
let end = bytes.length - 22
|
|
@@ -78,9 +62,7 @@ function centralRecords(bytes) {
|
|
|
78
62
|
return records
|
|
79
63
|
}
|
|
80
64
|
|
|
81
|
-
// The zip crate's ZipFileData::unix_mode
|
|
82
|
-
// attributes, by whatever system; else for MS-DOS its directory and
|
|
83
|
-
// read-only bits; else for Unix none at all, 0; else nothing.
|
|
65
|
+
// The zip crate's ZipFileData::unix_mode; system 0 is MS-DOS, and 3 Unix.
|
|
84
66
|
function unixMode({ system, attributes }) {
|
|
85
67
|
if (attributes === 0) return undefined
|
|
86
68
|
const upper = attributes >>> 16
|
|
@@ -95,9 +77,10 @@ function unixMode({ system, attributes }) {
|
|
|
95
77
|
// a component Soldeer holds to `.git`.
|
|
96
78
|
const isGit = (component) => component.replace(/[. ]+$/u, '').replace(/[A-Z]/gu, (char) => char.toLowerCase()) === '.git'
|
|
97
79
|
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
export async function extractZip(bytes, where) {
|
|
80
|
+
// getZip has held the zip to its checksum; it is held to it again where it
|
|
81
|
+
// is unpacked.
|
|
82
|
+
export async function extractZip(bytes, checksum, where) {
|
|
83
|
+
if (await bytesSha256Hex(bytes) !== checksum) throw new DeptreeError(`its zip's sha256 is not ${checksum}`, where)
|
|
101
84
|
let entries
|
|
102
85
|
try {
|
|
103
86
|
entries = await unzip(bytes, { limit: MAX_BYTES })
|
|
@@ -106,16 +89,14 @@ export async function extractZip(bytes, where) {
|
|
|
106
89
|
throw error
|
|
107
90
|
}
|
|
108
91
|
const records = centralRecords(bytes)
|
|
109
|
-
// The zip crate keys entries by their names' bytes,
|
|
110
|
-
//
|
|
111
|
-
// extracted, where the first was.
|
|
92
|
+
// The zip crate keys entries by their names' bytes, here the stored names:
|
|
93
|
+
// of two of one name, the later is extracted where the first was.
|
|
112
94
|
const last = new Map()
|
|
113
95
|
for (const [index, entry] of entries.entries()) {
|
|
114
96
|
const record = records[index]
|
|
115
97
|
if (decoder.decode(record.name) !== entry.storedName) throw new Error('unreachable: unzip lists entries out of the central directory\'s order')
|
|
116
98
|
const here = `${where}: ${quote(entry.storedName)}`
|
|
117
99
|
if (record.extra !== undefined) throw new DeptreeError(`${record.extra}, which Soldeer fails on`, here)
|
|
118
|
-
// The zip crate reads a name not flagged UTF-8 as CP437.
|
|
119
100
|
if (!(record.flags & UTF8) && record.name.some((byte) => byte >= 0x80)) throw new DeptreeError('a name not flagged UTF-8, which Soldeer reads as CP437, is not supported', here)
|
|
120
101
|
last.set(entry.storedName, index)
|
|
121
102
|
}
|
package/src/tarball.js
CHANGED
|
@@ -1,36 +1,13 @@
|
|
|
1
|
-
// A registry
|
|
2
|
-
//
|
|
3
|
-
// the registry and holds what it gets to the integrity it is given, then
|
|
4
|
-
// held to that integrity again here, since it is the lockfile's; gunzipped
|
|
5
|
-
// and unpacked by @preventive/archive, with every rule of a name that
|
|
6
|
-
// holds; and read into files the way pnpm reads them out of a tarball
|
|
7
|
-
// (@pnpm/store.cafs): the first segment of each name dropped, whatever it
|
|
8
|
-
// is, only files kept, as ones not executable or executable by anyone.
|
|
9
|
-
//
|
|
10
|
-
// Here it is held to more than pnpm holds it to, to what npm packs: a
|
|
11
|
-
// gzipped tarball, every file under one directory, no link of either kind
|
|
12
|
-
// or device, which pnpm would pass over or refuse, and no name twice as
|
|
13
|
-
// two different files, of which pnpm would keep the later. It has to have
|
|
14
|
-
// a package.json, for exactly the name and version the lockfile says, and
|
|
15
|
-
// that package.json has to agree with what the lockfile recorded of the
|
|
16
|
-
// package's: its os, cpu and libc, whether it has bins, what it bundles.
|
|
17
|
-
// And every dependency it asks for, read through pnpm's read-package hook
|
|
18
|
-
// as pnpm reads it (hook.js), has to be among each of its snapshots', bundled
|
|
19
|
-
// or optional ones aside: a lockfile that leaves one out would leave the
|
|
20
|
-
// package to find it wherever it is hoisted, if anywhere. A registry whose
|
|
21
|
-
// metadata says other than its tarball does is caught at the same time.
|
|
22
|
-
//
|
|
23
|
-
// A package is fetched and read once however many snapshots it has, one
|
|
24
|
-
// for each set of peers it is resolved with.
|
|
1
|
+
// A registry tarball, fetched through @preventive/upstream, which checks the
|
|
2
|
+
// integrity it is given, and checked again here, as that is the lockfile's.
|
|
25
3
|
|
|
26
4
|
import { decompress } from '@preventive/archive/compression.js'
|
|
27
5
|
import { unpack } from '@preventive/archive/tar.js'
|
|
28
|
-
import { normalize } from '@preventive/vfs/path.js'
|
|
29
|
-
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
30
6
|
import { getTarball } from '@preventive/upstream/npm.js'
|
|
31
7
|
import { DeptreeError, quote } from './error.js'
|
|
32
|
-
import { localOf } from './pnpm/overrides.js'
|
|
33
8
|
import { matchesIntegrity } from './hash.js'
|
|
9
|
+
import { fold } from './mount.js'
|
|
10
|
+
import { decodeUtf8 } from './project.js'
|
|
34
11
|
|
|
35
12
|
// What a tarball may unpack to, as upstream bounds what it downloads.
|
|
36
13
|
const MAX_BYTES = 512 * 1024 * 1024
|
|
@@ -39,134 +16,72 @@ export const REGISTRY = 'https://registry.npmjs.org/'
|
|
|
39
16
|
// The registry's own URL for a version's tarball, as npm and pnpm spell it.
|
|
40
17
|
export const tarballUrl = (name, version) => `${REGISTRY}${name}/-/${name.split('/').at(-1)}-${version}.tgz`
|
|
41
18
|
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return name.replaceAll('//', '/')
|
|
49
|
-
}
|
|
19
|
+
// A name and a version that URL holds as they are: ASCII a URL takes
|
|
20
|
+
// unescaped, no part of the name `.` or `..`, and nothing that would end the
|
|
21
|
+
// path. The lockfile reader holds both to more; the URL fetched is held to
|
|
22
|
+
// this whatever reached here.
|
|
23
|
+
const NAME = /^(?:@[\w~-][\w.~-]*\/)?[\w~-][\w.~-]*$/u
|
|
24
|
+
const VERSION = /^[\dA-Za-z][\dA-Za-z.+-]*$/u
|
|
50
25
|
|
|
51
|
-
|
|
52
|
-
|
|
26
|
+
function checkId(name, version, where) {
|
|
27
|
+
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
|
+
}
|
|
53
29
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (entry.type !== 'file') throw new DeptreeError(`${quote(entry.name)} is a ${entry.type}, which is not supported`, where)
|
|
63
|
-
tops.add(entry.storedName.slice(0, Math.max(entry.storedName.indexOf('/'), 0)))
|
|
64
|
-
if (tops.size > 1 || tops.has('')) throw new DeptreeError('the tarball has files under more than one directory, or at its top', where)
|
|
65
|
-
const name = nameOf(entry.storedName)
|
|
66
|
-
if (name === '' || name.split('/').some((segment) => segment === '' || segment === '.' || segment === '..')) {
|
|
67
|
-
throw new DeptreeError(`${quote(entry.storedName)} names no file in the package`, where)
|
|
68
|
-
}
|
|
69
|
-
const file = { data: entry.data, mode: (entry.mode & 0o111) === 0 ? 0o644 : 0o755 }
|
|
70
|
-
const earlier = files.get(name)
|
|
71
|
-
if (earlier !== undefined && !sameFile(earlier, file)) throw new DeptreeError(`${quote(name)} is in the tarball twice`, where)
|
|
72
|
-
files.set(name, file)
|
|
73
|
-
}
|
|
74
|
-
return files
|
|
30
|
+
// The registry's own tarball, by its sha512 alone, as fetchTarball takes it.
|
|
31
|
+
export function ownTarball(url, name, version, integrity, where) {
|
|
32
|
+
checkId(name, version, where)
|
|
33
|
+
const expected = tarballUrl(name, version)
|
|
34
|
+
if (url !== expected) throw new DeptreeError(`only the registry's own tarball of ${name}@${version}, ${expected}, is supported`, where)
|
|
35
|
+
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)
|
|
37
|
+
return { name, version, integrity: sha512 }
|
|
75
38
|
}
|
|
76
39
|
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
const
|
|
40
|
+
// yarn's mirror of npm's registry serves the same tarballs at the same paths.
|
|
41
|
+
const YARNPKG = 'https://registry.yarnpkg.com/'
|
|
42
|
+
export const fromMirror = (url) => (url.startsWith(YARNPKG) ? `${REGISTRY}${url.slice(YARNPKG.length)}` : url)
|
|
80
43
|
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
// resolves it as having none and pnpm 11 rewrites a snapshot as having
|
|
85
|
-
// some, so that is undefined: bins are linked as the lockfile has it.
|
|
86
|
-
// pnpm 12 records it for a `bin` that is a string or object not empty, or
|
|
87
|
-
// a directories.bin that is a string not empty.
|
|
88
|
-
function hasBin({ bin, directories }, major) {
|
|
89
|
-
if (major >= 12) {
|
|
90
|
-
const named = typeof bin === 'string' ? bin !== '' : bin !== null && typeof bin === 'object' && !Array.isArray(bin) && Object.keys(bin).length > 0
|
|
91
|
-
return named || (directories !== null && typeof directories === 'object' && !Array.isArray(directories) && typeof directories.bin === 'string' && directories.bin !== '')
|
|
92
|
-
}
|
|
93
|
-
if (bin === undefined || bin === null) return Boolean(directories?.bin)
|
|
94
|
-
if (bin && Object.keys(bin).length > 0) return true
|
|
95
|
-
return directories?.bin ? undefined : false
|
|
96
|
-
}
|
|
44
|
+
// The name of a package's own node_modules, where npm and yarn install its
|
|
45
|
+
// dependencies, in any case: macOS takes `Node_Modules` for it.
|
|
46
|
+
export const isModules = (name) => fold(name) === 'node_modules'
|
|
97
47
|
|
|
98
|
-
|
|
99
|
-
const file = files.get('package.json')
|
|
100
|
-
if (file === undefined) throw new DeptreeError('the tarball has no package.json', where)
|
|
101
|
-
let manifest
|
|
102
|
-
try {
|
|
103
|
-
manifest = JSON.parse(decoder.decode(file.data))
|
|
104
|
-
} catch {
|
|
105
|
-
throw new DeptreeError('package.json is not JSON', where)
|
|
106
|
-
}
|
|
107
|
-
if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) throw new DeptreeError('package.json is not an object', where)
|
|
108
|
-
if (manifest.name !== pkg.name || manifest.version !== pkg.version) throw new DeptreeError(`package.json is for ${quote(`${manifest.name}@${manifest.version}`)}`, where)
|
|
109
|
-
return manifest
|
|
110
|
-
}
|
|
48
|
+
export const sameFile = (a, b) => a.mode === b.mode && a.data.length === b.data.length && a.data.every((byte, i) => byte === b.data[i])
|
|
111
49
|
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
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)
|
|
119
|
-
if (!same(listed(bundledOf(manifest)), listed(pkg.bundledDependencies))) throw new DeptreeError('package.json bundles other than the lockfile says', where)
|
|
50
|
+
// Where a file's first line is a `#!` one ending in a CRLF within its first
|
|
51
|
+
// 2048 bytes, as bin-links' fixBin tells it, the index of its LF; else -1.
|
|
52
|
+
export function crlfShebang(data) {
|
|
53
|
+
if (data[0] !== 0x23 || data[1] !== 0x21) return -1
|
|
54
|
+
const newline = data.subarray(0, 2048).indexOf(0x0a)
|
|
55
|
+
return newline >= 4 && data[newline - 1] === 0x0d ? newline : -1
|
|
120
56
|
}
|
|
121
57
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
58
|
+
// `data` less such a line's CR; the file is rewritten as UTF-8, else refused with `detail`.
|
|
59
|
+
export function fixShebang(data, detail, where) {
|
|
60
|
+
const newline = crlfShebang(data)
|
|
61
|
+
if (newline === -1) return data
|
|
62
|
+
decodeUtf8(data, detail, where)
|
|
63
|
+
const copy = new Uint8Array(data.length - 1)
|
|
64
|
+
copy.set(data.subarray(0, newline - 1))
|
|
65
|
+
copy.set(data.subarray(newline), newline - 1)
|
|
66
|
+
return copy
|
|
67
|
+
}
|
|
127
68
|
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const bundled = bundledOf(manifest)
|
|
134
|
-
const given = new Set([...names(pkg.dependencies), ...names(pkg.optionalDependencies)])
|
|
135
|
-
for (const name of [...names(read.dependencies), ...names(read.optionalDependencies)]) {
|
|
136
|
-
if (bundled === true || (Array.isArray(bundled) && bundled.includes(name)) || given.has(name)) continue
|
|
137
|
-
throw new DeptreeError(`package.json asks for ${quote(name)}, which the lockfile does not give it`, where)
|
|
138
|
-
}
|
|
139
|
-
for (const [name, spec] of [...Object.entries(read.dependencies ?? {}), ...Object.entries(read.optionalDependencies ?? {})]) {
|
|
140
|
-
const target = pkg.dependencies[name] ?? pkg.optionalDependencies[name]
|
|
141
|
-
if (target === undefined) continue
|
|
142
|
-
const local = localOf(spec, `${where}: package.json`)
|
|
143
|
-
if (local === undefined || target === `link:${local.dir}` || (local.protocol === 'file:' && packageKeyOf(target).endsWith(`@file:${local.dir}`))) continue
|
|
144
|
-
throw new DeptreeError(`the lockfile gives it ${quote(name)} as ${quote(target)}, and its package.json, overridden, names ${quote(local.dir)}`, where)
|
|
145
|
-
}
|
|
146
|
-
// A peer resolved is filed as optional where it is optional; pnpm's
|
|
147
|
-
// compatibility database adds peers to a few packages, which the
|
|
148
|
-
// lockfile records among their peers and the package.json does not.
|
|
149
|
-
const optional = new Set([...names(read.optionalDependencies), ...names(manifest.peerDependencies), ...names(manifest.peerDependenciesMeta), ...names(pkg.peerDependencies), ...names(pkg.peerDependenciesMeta)])
|
|
150
|
-
for (const name of names(pkg.optionalDependencies)) {
|
|
151
|
-
if (!optional.has(name)) throw new DeptreeError(`the lockfile gives it ${quote(name)} as optional, which its package.json does not`, where)
|
|
69
|
+
// Adds to `dirs` each one `files` are in, refusing one that is a file too.
|
|
70
|
+
export function withDirs(files, where, dirs = new Set()) {
|
|
71
|
+
for (const path of files.keys()) {
|
|
72
|
+
const segments = path.split('/')
|
|
73
|
+
for (let i = 1; i < segments.length; i++) dirs.add(segments.slice(0, i).join('/'))
|
|
152
74
|
}
|
|
75
|
+
for (const dir of dirs) if (files.has(dir)) throw new DeptreeError(`${quote(dir)} is both a file and a directory in the tarball`, where)
|
|
76
|
+
return { files, dirs }
|
|
153
77
|
}
|
|
154
78
|
|
|
155
|
-
// A version's tarball from the registry, through @preventive/upstream, held
|
|
156
|
-
// to `integrity` and to be gzipped: its bytes, and its entries unpacked.
|
|
157
79
|
export async function fetchTarball(name, version, integrity, where) {
|
|
80
|
+
checkId(name, version, where)
|
|
81
|
+
if (!/^sha512-[\d+/A-Za-z]{86}==$/u.test(integrity)) throw new DeptreeError('a tarball with no sha512 integrity is not supported', where)
|
|
158
82
|
const bytes = await getTarball(name, version, { tarball: tarballUrl(name, version), integrity })
|
|
159
83
|
if (!await matchesIntegrity(bytes, integrity)) throw new DeptreeError(`the tarball is not ${integrity}`, where)
|
|
160
84
|
if (bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the tarball is not gzipped', where)
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// A package's files, and its package.json as parsed; the package has to be
|
|
165
|
-
// from the registry.
|
|
166
|
-
export async function fetchPackage(pkg, where, major) {
|
|
167
|
-
const { entries } = await fetchTarball(pkg.name, pkg.version, pkg.resolution.integrity, where)
|
|
168
|
-
const files = filesOf(entries, where, major)
|
|
169
|
-
const manifest = readManifest(files, pkg, where)
|
|
170
|
-
checkManifest(manifest, pkg, where, major)
|
|
171
|
-
return { files, manifest }
|
|
85
|
+
const tar = await decompress(bytes, 'gzip', { limit: MAX_BYTES })
|
|
86
|
+
return { bytes, entries: unpack(tar), inflated: tar.length }
|
|
172
87
|
}
|
package/src/yarn1/bins.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
// Where yarn 1 fails as it links bins (package-linker.js)
|
|
2
|
-
//
|
|
3
|
-
//
|
|
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.
|
|
1
|
+
// Where yarn 1 fails as it links bins (package-linker.js). The one change
|
|
2
|
+
// linking makes to the tree, each target made executable, package.js has
|
|
3
|
+
// made. A dependency deduplicated into another's reference links no bins.
|
|
8
4
|
|
|
9
5
|
import { dirname, join } from '@preventive/vfs/path.js'
|
|
10
6
|
import { DeptreeError, quote } from '../error.js'
|
|
11
|
-
import { binsOf } from './package.js'
|
|
12
7
|
|
|
13
|
-
//
|
|
14
|
-
// directory
|
|
15
|
-
// findNearestInstalledVersionOfPackage looks. Paths are from the
|
|
16
|
-
// lockfile's directory, `.` it.
|
|
8
|
+
// As yarn's findNearestInstalledVersionOfPackage looks; paths are from the
|
|
9
|
+
// lockfile's directory, `.`.
|
|
17
10
|
function finds(name, loc, dir) {
|
|
18
11
|
for (;; dir = dirname(dir)) {
|
|
19
12
|
if (join(dir, name) === loc || join(dir, `node_modules/${name}`) === loc) return true
|
|
@@ -21,17 +14,14 @@ function finds(name, loc, dir) {
|
|
|
21
14
|
}
|
|
22
15
|
}
|
|
23
16
|
|
|
24
|
-
|
|
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 }) {
|
|
17
|
+
export function checkBinLinks({ placed, patterns, locations, realOf }) {
|
|
29
18
|
for (const { loc, info } of placed) {
|
|
30
19
|
const binLoc = `${loc}/node_modules`
|
|
20
|
+
const realBinLoc = realOf(binLoc)
|
|
31
21
|
for (const pattern of info.ref.dependencies) {
|
|
32
22
|
const dep = patterns.get(pattern)
|
|
33
|
-
if (dep.kind !== 'registry' || !locations.has(dep) ||
|
|
34
|
-
const found = locations.get(dep).some((at) => finds(dep.name, at, binLoc) || finds(dep.name, at,
|
|
23
|
+
if (dep.kind !== 'registry' || !locations.has(dep) || !dep.hasBins) continue
|
|
24
|
+
const found = locations.get(dep).some((at) => finds(dep.name, at, binLoc) || finds(dep.name, at, realBinLoc))
|
|
35
25
|
if (!found) throw new DeptreeError(`yarn finds no copy of ${quote(dep.name)} to link the bins of`, quote(loc))
|
|
36
26
|
}
|
|
37
27
|
}
|
package/src/yarn1/compat.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
// yarn 1's package-compatibility.js
|
|
2
|
-
//
|
|
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.
|
|
1
|
+
// yarn 1's package-compatibility.js, engines checked against host.node and
|
|
2
|
+
// host.yarn; one yarn knows no version of is passed over, as yarn does.
|
|
10
3
|
|
|
11
4
|
import { compareVersions, major, satisfies, valid } from '@preventive/upstream/semver.js'
|
|
12
5
|
import { DeptreeError, quote } from '../error.js'
|
|
@@ -52,35 +45,23 @@ function testEngine(name, range, versions) {
|
|
|
52
45
|
return false
|
|
53
46
|
}
|
|
54
47
|
|
|
55
|
-
//
|
|
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.
|
|
48
|
+
// engines may be a list of `name range` strings, which yarn reads as a map.
|
|
59
49
|
export function incompatibility(manifest, host, where, { ignoreEngines, ignorePlatform }) {
|
|
60
50
|
const { os, cpu } = manifest
|
|
61
51
|
let { engines } = manifest
|
|
62
52
|
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
53
|
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
54
|
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
|
-
}
|
|
55
|
+
if (Array.isArray(engines)) engines = Object.fromEntries(engines.filter((item) => typeof item === 'string').map((item) => item.trim().split(/ +/gu)).map(([name, ...rest]) => [name, rest.join(' ')]))
|
|
74
56
|
if (engines === null || typeof engines !== 'object') return undefined
|
|
75
57
|
const versions = { node: host.node, yarn: host.yarn }
|
|
76
58
|
for (let [name, range] of Object.entries(engines)) {
|
|
77
59
|
if (name === 'iojs') name = 'node'
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
60
|
+
const known = Object.hasOwn(versions, name)
|
|
61
|
+
if (!known && !REPORTED.has(name)) continue
|
|
62
|
+
if (typeof range !== 'string') throw new DeptreeError(`engines.${name} is not a string, which yarn fails on`, where)
|
|
63
|
+
if (!known) throw new DeptreeError(`yarn checks engines.${name} against the Node it runs on, which is not known here`, where)
|
|
64
|
+
if (!testEngine(name, range, versions)) return `its engines.${name}, ${quote(range)}, does not take ${versions[name]}`
|
|
84
65
|
}
|
|
85
66
|
return undefined
|
|
86
67
|
}
|