@preventive/deptree 1.0.0-alpha.2 → 1.0.0-alpha.4
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 +15 -3
- package/pnpm.d.ts +115 -30
- package/pnpm.js +3 -2
- package/soldeer.d.ts +168 -0
- package/soldeer.js +12 -0
- package/src/concurrent.js +24 -0
- package/src/mount.js +7 -6
- package/src/patch.js +5 -4
- package/src/pnpm/bins.js +105 -246
- package/src/pnpm/commands.js +273 -0
- package/src/pnpm/filename.js +16 -2
- package/src/pnpm/frozen.js +4 -2
- package/src/pnpm/graph.js +36 -16
- package/src/pnpm/hoist.js +41 -11
- package/src/pnpm/inputs.js +51 -16
- package/src/pnpm/install.js +65 -20
- package/src/pnpm/local.js +72 -2
- package/src/pnpm/packlist.js +58 -24
- package/src/pnpm/projects.js +88 -8
- package/src/pnpm/readers.js +73 -16
- package/src/pnpm/settings.js +25 -10
- package/src/pnpm/tree.js +50 -54
- package/src/pnpm/workspace.js +56 -13
- package/src/soldeer/config.js +79 -0
- package/src/soldeer/inputs.js +40 -0
- package/src/soldeer/tree.js +111 -0
- package/src/soldeer/zip.js +142 -0
- package/src/tarball.js +16 -8
- package/src/yarn1/tree.js +9 -17
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The config `soldeer install` reads, as Soldeer 0.12 finds and reads it:
|
|
2
|
+
// foundry.toml where it has a [dependencies] table; else soldeer.toml,
|
|
3
|
+
// where there is no foundry.toml. Where neither holds, Soldeer asks which
|
|
4
|
+
// one to make its config, which is refused. Of foundry.toml, what Soldeer
|
|
5
|
+
// would fail on as it adds `dependencies` to the default profile's libs is
|
|
6
|
+
// refused; of the config, its [soldeer] settings where Soldeer would fail
|
|
7
|
+
// on them, and recursive_deps.
|
|
8
|
+
|
|
9
|
+
import { TomlError, isInlineTable, parseToml } from '@preventive/lockfile/toml.js'
|
|
10
|
+
import { DeptreeError } from '../error.js'
|
|
11
|
+
|
|
12
|
+
const isTable = (value) => typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === null
|
|
13
|
+
// A table toml_edit gives as one, as a header or a dotted key makes it:
|
|
14
|
+
// one written inline it gives as a value, which Soldeer reads no
|
|
15
|
+
// dependencies from, and fails on for a profile.
|
|
16
|
+
const isTableItem = (value) => isTable(value) && !isInlineTable(value)
|
|
17
|
+
|
|
18
|
+
function parse(text, file) {
|
|
19
|
+
try {
|
|
20
|
+
return parseToml(text)
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof TomlError) throw new DeptreeError(`not TOML read here: ${error.message}`, file, { cause: error })
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// update_config_libs, which expects each of these to be what it adds where
|
|
28
|
+
// it is not there, and panics on another.
|
|
29
|
+
function checkLibs(doc) {
|
|
30
|
+
const { profile } = doc
|
|
31
|
+
if (profile === undefined) return
|
|
32
|
+
if (!isTableItem(profile)) throw new DeptreeError('not a table, which Soldeer fails on', 'foundry.toml: profile')
|
|
33
|
+
const defaults = profile.default
|
|
34
|
+
if (defaults === undefined) return
|
|
35
|
+
if (!isTableItem(defaults)) throw new DeptreeError('not a table, which Soldeer fails on', 'foundry.toml: profile.default')
|
|
36
|
+
const { libs } = defaults
|
|
37
|
+
if (libs !== undefined && (!Array.isArray(libs) || isTableItem(libs[0]))) throw new DeptreeError('not an array, which Soldeer fails on', 'foundry.toml: profile.default.libs')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function checkDependencies(doc, file) {
|
|
41
|
+
if (doc.dependencies !== undefined && !isTableItem(doc.dependencies)) {
|
|
42
|
+
throw new DeptreeError('not a table, which Soldeer reads no dependencies from, is not supported', `${file}: dependencies`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const BOOLEANS = ['remappings_generate', 'remappings_regenerate', 'remappings_version', 'recursive_deps']
|
|
47
|
+
|
|
48
|
+
// read_soldeer_config's SoldeerConfig, by serde: each field of its type,
|
|
49
|
+
// any other passed over.
|
|
50
|
+
function checkSettings(settings, file) {
|
|
51
|
+
if (settings === undefined) return
|
|
52
|
+
const where = `${file}: soldeer`
|
|
53
|
+
if (!isTable(settings)) throw new DeptreeError('not a table, which Soldeer fails on', where)
|
|
54
|
+
for (const key of BOOLEANS) {
|
|
55
|
+
if (settings[key] !== undefined && typeof settings[key] !== 'boolean') throw new DeptreeError('not true or false, which Soldeer fails on', `${where}.${key}`)
|
|
56
|
+
}
|
|
57
|
+
if (settings.remappings_prefix !== undefined && typeof settings.remappings_prefix !== 'string') throw new DeptreeError('not a string, which Soldeer fails on', `${where}.remappings_prefix`)
|
|
58
|
+
if (settings.remappings_location !== undefined && settings.remappings_location !== 'txt' && settings.remappings_location !== 'config') {
|
|
59
|
+
throw new DeptreeError('not "txt" or "config", which Soldeer fails on', `${where}.remappings_location`)
|
|
60
|
+
}
|
|
61
|
+
if (settings.recursive_deps === true) throw new DeptreeError('has Soldeer install what each dependency depends on too, which is not supported', `${where}.recursive_deps`)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ASKS = 'Soldeer asks which file to make its config, which is not supported'
|
|
65
|
+
|
|
66
|
+
// The file Soldeer reads its config from, and that config, parsed.
|
|
67
|
+
export function configOf({ foundry, soldeer }) {
|
|
68
|
+
if (foundry === undefined && soldeer === undefined) throw new DeptreeError(`neither foundry.toml nor soldeer.toml is there, so ${ASKS}`)
|
|
69
|
+
const file = foundry === undefined ? 'soldeer.toml' : 'foundry.toml'
|
|
70
|
+
const config = parse(foundry ?? soldeer, file)
|
|
71
|
+
if (foundry === undefined) {
|
|
72
|
+
checkDependencies(config, file)
|
|
73
|
+
} else {
|
|
74
|
+
if (!isTableItem(config.dependencies)) throw new DeptreeError(`no [dependencies] table, so ${ASKS}`, file)
|
|
75
|
+
checkLibs(config)
|
|
76
|
+
}
|
|
77
|
+
checkSettings(config.soldeer, file)
|
|
78
|
+
return { file, config }
|
|
79
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// What buildSoldeerTree takes, checked: the host Soldeer runs on, and the
|
|
2
|
+
// files `soldeer install` reads — given as text, or read from the project
|
|
3
|
+
// (../pnpm/project.js) as Soldeer reads them at the project's root.
|
|
4
|
+
|
|
5
|
+
import { DeptreeError, quote } from '../error.js'
|
|
6
|
+
import { checkProject, readText } from '../pnpm/project.js'
|
|
7
|
+
|
|
8
|
+
export function checkHost(host) {
|
|
9
|
+
if (host === null || typeof host !== 'object') throw new TypeError('host must be an object with soldeer and os')
|
|
10
|
+
for (const key of ['soldeer', 'os']) {
|
|
11
|
+
if (typeof host[key] !== 'string' || host[key] === '') throw new TypeError(`host.${key} must be a non-empty string`)
|
|
12
|
+
}
|
|
13
|
+
if (host.soldeer !== '0.12.0') throw new DeptreeError(`Soldeer ${quote(host.soldeer)} is not supported: only Soldeer 0.12.0 is`, 'host.soldeer')
|
|
14
|
+
if (host.os === 'win32') throw new DeptreeError('Windows is not supported: Soldeer names folders otherwise there', 'host.os')
|
|
15
|
+
return { soldeer: host.soldeer, os: host.os }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const LOCKFILE = 'lockfile must be the soldeer.lock text, or left out where project is given'
|
|
19
|
+
|
|
20
|
+
export function inputsOf(options) {
|
|
21
|
+
const { lockfile, foundry, soldeer, project } = options
|
|
22
|
+
if (lockfile === undefined) {
|
|
23
|
+
if (project === undefined) throw new TypeError(LOCKFILE)
|
|
24
|
+
checkProject(project)
|
|
25
|
+
for (const [name, value] of Object.entries({ foundry, soldeer })) {
|
|
26
|
+
if (value !== undefined) throw new TypeError(`${name} must be left out where lockfile is: all are read from project`)
|
|
27
|
+
}
|
|
28
|
+
const lock = readText(project, '/soldeer.lock', 'soldeer.lock')
|
|
29
|
+
if (lock === undefined) throw new DeptreeError('the project has no soldeer.lock, without which Soldeer resolves each dependency anew')
|
|
30
|
+
// Soldeer reads soldeer.toml only where it cannot read foundry.toml.
|
|
31
|
+
const foundryText = readText(project, '/foundry.toml', 'foundry.toml')
|
|
32
|
+
return { lockfile: lock, foundry: foundryText, soldeer: foundryText === undefined ? readText(project, '/soldeer.toml', 'soldeer.toml') : undefined }
|
|
33
|
+
}
|
|
34
|
+
if (typeof lockfile !== 'string') throw new TypeError(LOCKFILE)
|
|
35
|
+
if (project !== undefined) throw new TypeError('project must be left out where lockfile is given')
|
|
36
|
+
for (const [name, value] of Object.entries({ foundry, soldeer })) {
|
|
37
|
+
if (value !== undefined && typeof value !== 'string') throw new TypeError(`${name} must be a string, or left out`)
|
|
38
|
+
}
|
|
39
|
+
return { lockfile, foundry, soldeer }
|
|
40
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The dependencies folder `soldeer install` makes from a soldeer.lock: each
|
|
2
|
+
// registry dependency's zip fetched, held to the lockfile's checksum, and
|
|
3
|
+
// extracted in a folder of its own (zip.js).
|
|
4
|
+
|
|
5
|
+
import { parseSoldeerLockfile } from '@preventive/lockfile/soldeer.js'
|
|
6
|
+
import { getZip } from '@preventive/upstream/soldeer.js'
|
|
7
|
+
import { Vfs, VfsError } from '@preventive/vfs'
|
|
8
|
+
import { eachConcurrently } from '../concurrent.js'
|
|
9
|
+
import { DeptreeError, quote } from '../error.js'
|
|
10
|
+
import { fold, mount } from '../mount.js'
|
|
11
|
+
import { checkCollisions } from '../pnpm/checks.js'
|
|
12
|
+
import { configOf } from './config.js'
|
|
13
|
+
import { checkHost, inputsOf } from './inputs.js'
|
|
14
|
+
import { extractZip } from './zip.js'
|
|
15
|
+
|
|
16
|
+
// What the registry takes, as @preventive/upstream/soldeer.js holds a name
|
|
17
|
+
// and a version to: of these, Soldeer's sanitize_filename leaves a folder
|
|
18
|
+
// `<name>-<version>` as it is on Unix.
|
|
19
|
+
const NAME = /^(?=.{3,100}$)[@\da-z][\da-z-]*[\da-z]$/u
|
|
20
|
+
const VERSION = /^(?=.{1,128}$)[\dA-Za-z][\w.+-]*$/u
|
|
21
|
+
|
|
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
|
+
function checkNoDependencies(vfs, folded) {
|
|
25
|
+
for (const name of vfs.readdir('/')) {
|
|
26
|
+
if (name === 'dependencies' || (folded && fold(name) === 'dependencies')) {
|
|
27
|
+
throw new DeptreeError('a dependencies folder is there already, which is neither kept beside the tree nor removed', `vfs[${quote(`/${name}`)}]`)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The registry dependencies, each with the folder Soldeer installs it in;
|
|
33
|
+
// any other kind is refused. Where names are `folded`, a folder is one
|
|
34
|
+
// with another that differs from it only in case or normalization.
|
|
35
|
+
function registryDependencies(lock, config, folded) {
|
|
36
|
+
const dependencies = Object.values(lock.dependencies).map((dependency) => ({ ...dependency, folder: `${dependency.name}-${dependency.version}` }))
|
|
37
|
+
const key = (folder) => (folded ? fold(folder) : folder)
|
|
38
|
+
const folders = new Set(dependencies.map(({ folder }) => key(folder)))
|
|
39
|
+
for (const { type, name, version } of dependencies) {
|
|
40
|
+
const where = `dependencies[${quote(name)}]`
|
|
41
|
+
if (type === 'git') throw new DeptreeError('a git dependency, which Soldeer clones with its history, is not supported', where)
|
|
42
|
+
if (type === 'private') throw new DeptreeError('a private dependency, which the registry hands out to those signed in alone, is not supported', where)
|
|
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
|
+
// Soldeer downloads each zip beside the folders, as `<folder>.zip`.
|
|
48
|
+
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`, `dependencies[${quote(name)}]`)
|
|
50
|
+
}
|
|
51
|
+
return dependencies
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Each dependency's zip, fetched and extracted a few at a time, by its
|
|
55
|
+
// folder.
|
|
56
|
+
async function fetchAll(dependencies) {
|
|
57
|
+
const extracted = new Map()
|
|
58
|
+
await eachConcurrently(dependencies, async ({ name, version, checksum, folder }) => {
|
|
59
|
+
const where = `dependencies[${quote(name)}]`
|
|
60
|
+
try {
|
|
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
|
+
})
|
|
66
|
+
return extracted
|
|
67
|
+
}
|
|
68
|
+
|
|
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
|
+
export async function buildSoldeerTree(options) {
|
|
93
|
+
const { host: given, vfs: into } = options ?? {}
|
|
94
|
+
if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
|
|
95
|
+
const inputs = inputsOf(options ?? {})
|
|
96
|
+
const host = checkHost(given)
|
|
97
|
+
const folded = host.os === 'darwin'
|
|
98
|
+
// Refused before anything is fetched; mount checks again.
|
|
99
|
+
if (into !== undefined) checkNoDependencies(into, folded)
|
|
100
|
+
const { config } = configOf(inputs)
|
|
101
|
+
const lock = parseSoldeerLockfile(inputs.lockfile, { config })
|
|
102
|
+
const dependencies = registryDependencies(lock, config, folded)
|
|
103
|
+
const extracted = await fetchAll(dependencies)
|
|
104
|
+
// In the lockfile's order, whatever order the fetches finished in.
|
|
105
|
+
const { vfs, files, bytes } = writeTree(dependencies.map(({ folder }) => [folder, extracted.get(folder)]))
|
|
106
|
+
if (folded) checkCollisions(vfs)
|
|
107
|
+
const stats = { dependencies: dependencies.length, files, bytes }
|
|
108
|
+
if (into === undefined) return { vfs, stats }
|
|
109
|
+
mount(vfs, into, folded, checkNoDependencies)
|
|
110
|
+
return { vfs: into, stats }
|
|
111
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// A registry zip as Soldeer 0.12 extracts it (download.rs's
|
|
2
|
+
// extract_dependency_archive, over the zip crate 8.6): every entry in the
|
|
3
|
+
// order the central directory lists them, read with
|
|
4
|
+
// @preventive/archive/zip.js, which refuses what it does not read — `..`,
|
|
5
|
+
// absolute and backslashed names, zip64, encryption, two different entries
|
|
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.
|
|
18
|
+
|
|
19
|
+
import { ArchiveError, unzip } from '@preventive/archive/zip.js'
|
|
20
|
+
import { DeptreeError, quote } from '../error.js'
|
|
21
|
+
|
|
22
|
+
const END = 0x06054b50
|
|
23
|
+
const CENTRAL = 0x02014b50
|
|
24
|
+
const UTF8 = 0x0800
|
|
25
|
+
const S_IFLNK = 0o120000
|
|
26
|
+
const [NTFS, TIMESTAMP, UNICODE_COMMENT, AES] = [0x000a, 0x5455, 0x6375, 0x9901]
|
|
27
|
+
|
|
28
|
+
// What a zip may extract to, as a tarball may unpack to (../tarball.js):
|
|
29
|
+
// the archive reader makes room for what each entry declares.
|
|
30
|
+
const MAX_BYTES = 512 * 1024 * 1024
|
|
31
|
+
|
|
32
|
+
// As the archive reader decodes a name: a leading U+FEFF is part of it.
|
|
33
|
+
const decoder = new TextDecoder('utf-8', { ignoreBOM: true })
|
|
34
|
+
const encoder = new TextEncoder()
|
|
35
|
+
|
|
36
|
+
const ones = (byte) => [...byte.toString(2)].filter((bit) => bit === '1').length
|
|
37
|
+
|
|
38
|
+
// Why the zip crate would fail on an entry's extra fields, which it reads
|
|
39
|
+
// from the central directory, or undefined: an NTFS field, or an extended
|
|
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.
|
|
42
|
+
function extraRefusal(view, at, length) {
|
|
43
|
+
for (let pos = at; pos < at + length;) {
|
|
44
|
+
const id = view.getUint16(pos, true)
|
|
45
|
+
const size = view.getUint16(pos + 2, true)
|
|
46
|
+
const body = pos + 4
|
|
47
|
+
if (id === NTFS && (size !== 32 || view.getUint16(body + 4, true) !== 1 || view.getUint16(body + 6, true) !== 24)) return 'an NTFS extra field the zip crate does not read'
|
|
48
|
+
if (id === TIMESTAMP && (size === 0 || (size !== 5 && size !== 1 + 4 * ones(view.getUint8(body))))) return 'an extended timestamp the zip crate does not read'
|
|
49
|
+
if (id === AES) return 'an AES extra field, which has the zip crate decrypt the entry'
|
|
50
|
+
if (id === UNICODE_COMMENT) return 'a Unicode comment extra field, which the zip crate checks'
|
|
51
|
+
pos = body + size
|
|
52
|
+
}
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// What the zip crate reads of each entry that the archive reader does not
|
|
57
|
+
// hand out, in the central directory's order: the system that made it, its
|
|
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.
|
|
60
|
+
function centralRecords(bytes) {
|
|
61
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
62
|
+
let end = bytes.length - 22
|
|
63
|
+
while (view.getUint32(end, true) !== END || end + 22 + view.getUint16(end + 20, true) !== bytes.length) end--
|
|
64
|
+
const records = []
|
|
65
|
+
let at = view.getUint32(end + 16, true)
|
|
66
|
+
for (let i = 0; i < view.getUint16(end + 10, true); i++) {
|
|
67
|
+
if (view.getUint32(at, true) !== CENTRAL) throw new Error('unreachable: a central record where unzip found none')
|
|
68
|
+
const [nameLength, extraLength, commentLength] = [at + 28, at + 30, at + 32].map((field) => view.getUint16(field, true))
|
|
69
|
+
records.push({
|
|
70
|
+
system: view.getUint8(at + 5),
|
|
71
|
+
flags: view.getUint16(at + 8, true),
|
|
72
|
+
attributes: view.getUint32(at + 38, true),
|
|
73
|
+
name: bytes.subarray(at + 46, at + 46 + nameLength),
|
|
74
|
+
extra: extraRefusal(view, at + 46 + nameLength, extraLength),
|
|
75
|
+
})
|
|
76
|
+
at += 46 + nameLength + extraLength + commentLength
|
|
77
|
+
}
|
|
78
|
+
return records
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// The zip crate's ZipFileData::unix_mode: the upper half of the external
|
|
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.
|
|
84
|
+
function unixMode({ system, attributes }) {
|
|
85
|
+
if (attributes === 0) return undefined
|
|
86
|
+
const upper = attributes >>> 16
|
|
87
|
+
if (upper !== 0) return upper
|
|
88
|
+
if (system === 3) return 0
|
|
89
|
+
if (system !== 0) return undefined
|
|
90
|
+
const mode = attributes & 0x10 ? 0o040775 : 0o100664
|
|
91
|
+
return attributes & 0x01 ? mode & ~0o222 : mode
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// What str::trim_end_matches(['.', ' ']) and eq_ignore_ascii_case make of
|
|
95
|
+
// a component Soldeer holds to `.git`.
|
|
96
|
+
const isGit = (component) => component.replace(/[. ]+$/u, '').replace(/[A-Z]/gu, (char) => char.toLowerCase()) === '.git'
|
|
97
|
+
|
|
98
|
+
// The directories and files of the zip, by their paths under the folder
|
|
99
|
+
// Soldeer extracts it in, files with their bytes and modes.
|
|
100
|
+
export async function extractZip(bytes, where) {
|
|
101
|
+
let entries
|
|
102
|
+
try {
|
|
103
|
+
entries = await unzip(bytes, { limit: MAX_BYTES })
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error instanceof ArchiveError) throw new DeptreeError(`its zip cannot be read: ${error.message}`, where, { cause: error })
|
|
106
|
+
throw error
|
|
107
|
+
}
|
|
108
|
+
const records = centralRecords(bytes)
|
|
109
|
+
// The zip crate keys entries by their names' bytes, which unzip has read
|
|
110
|
+
// as UTF-8, so by their stored names: of two of one name, the later is
|
|
111
|
+
// extracted, where the first was.
|
|
112
|
+
const last = new Map()
|
|
113
|
+
for (const [index, entry] of entries.entries()) {
|
|
114
|
+
const record = records[index]
|
|
115
|
+
if (decoder.decode(record.name) !== entry.storedName) throw new Error('unreachable: unzip lists entries out of the central directory\'s order')
|
|
116
|
+
const here = `${where}: ${quote(entry.storedName)}`
|
|
117
|
+
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
|
+
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
|
+
last.set(entry.storedName, index)
|
|
121
|
+
}
|
|
122
|
+
const dirs = new Set()
|
|
123
|
+
const files = new Map()
|
|
124
|
+
for (const index of last.values()) {
|
|
125
|
+
const entry = entries[index]
|
|
126
|
+
if (entry.name === '.') continue
|
|
127
|
+
const components = entry.name.split('/')
|
|
128
|
+
if (components.some((component) => component.includes(':'))) throw new DeptreeError('a name with a ":" in it, which Soldeer fails on', `${where}: ${quote(entry.storedName)}`)
|
|
129
|
+
if (components.some(isGit)) continue
|
|
130
|
+
for (let i = 1; i < components.length; i++) dirs.add(components.slice(0, i).join('/'))
|
|
131
|
+
if (entry.type === 'directory') {
|
|
132
|
+
dirs.add(entry.name)
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
const mode = unixMode(records[index])
|
|
136
|
+
const data = entry.type === 'symlink' ? encoder.encode(entry.linkname) : entry.data
|
|
137
|
+
// A file written again keeps its mode where the zip crate reads none.
|
|
138
|
+
const kept = mode === undefined || (mode & S_IFLNK) === S_IFLNK ? files.get(entry.name)?.mode ?? 0o644 : mode & 0o777 & ~0o022
|
|
139
|
+
files.set(entry.name, { data, mode: kept })
|
|
140
|
+
}
|
|
141
|
+
return { dirs, files }
|
|
142
|
+
}
|
package/src/tarball.js
CHANGED
|
@@ -51,11 +51,13 @@ function nameOf(stored) {
|
|
|
51
51
|
export const sameBytes = (a, b) => a.length === b.length && a.every((byte, i) => byte === b[i])
|
|
52
52
|
const sameFile = (a, b) => a.mode === b.mode && sameBytes(a.data, b.data)
|
|
53
53
|
|
|
54
|
-
// A Map of each file's path in the package to its bytes and mode.
|
|
55
|
-
|
|
54
|
+
// A Map of each file's path in the package to its bytes and mode. pnpm 12
|
|
55
|
+
// takes a backslash in a name for a separator, which is not supported.
|
|
56
|
+
function filesOf(entries, where, major) {
|
|
56
57
|
const files = new Map()
|
|
57
58
|
const tops = new Set()
|
|
58
59
|
for (const entry of entries) {
|
|
60
|
+
if (major >= 12 && entry.storedName.includes('\\')) throw new DeptreeError(`${quote(entry.storedName)} has a backslash, which pnpm 12 takes for a separator, and that is not supported`, where)
|
|
59
61
|
if (entry.type === 'directory') continue
|
|
60
62
|
if (entry.type !== 'file') throw new DeptreeError(`${quote(entry.name)} is a ${entry.type}, which is not supported`, where)
|
|
61
63
|
tops.add(entry.storedName.slice(0, Math.max(entry.storedName.indexOf('/'), 0)))
|
|
@@ -81,7 +83,13 @@ const names = (value) => Object.keys(value ?? {})
|
|
|
81
83
|
// `bin` is there and names none, and there is a directories.bin, pnpm
|
|
82
84
|
// resolves it as having none and pnpm 11 rewrites a snapshot as having
|
|
83
85
|
// some, so that is undefined: bins are linked as the lockfile has it.
|
|
84
|
-
|
|
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
|
+
}
|
|
85
93
|
if (bin === undefined || bin === null) return Boolean(directories?.bin)
|
|
86
94
|
if (bin && Object.keys(bin).length > 0) return true
|
|
87
95
|
return directories?.bin ? undefined : false
|
|
@@ -102,11 +110,11 @@ function readManifest(files, pkg, where) {
|
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
// What the lockfile recorded of the package against the package.json.
|
|
105
|
-
export function checkManifest(manifest, pkg, where) {
|
|
113
|
+
export function checkManifest(manifest, pkg, where, major) {
|
|
106
114
|
for (const field of ['os', 'cpu', 'libc']) {
|
|
107
115
|
if (!same(manifest[field], pkg[field])) throw new DeptreeError(`package.json's ${field} is not the lockfile's`, where)
|
|
108
116
|
}
|
|
109
|
-
const has = hasBin(manifest)
|
|
117
|
+
const has = hasBin(manifest, major)
|
|
110
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)
|
|
111
119
|
if (!same(listed(bundledOf(manifest)), listed(pkg.bundledDependencies))) throw new DeptreeError('package.json bundles other than the lockfile says', where)
|
|
112
120
|
}
|
|
@@ -155,10 +163,10 @@ export async function fetchTarball(name, version, integrity, where) {
|
|
|
155
163
|
|
|
156
164
|
// A package's files, and its package.json as parsed; the package has to be
|
|
157
165
|
// from the registry.
|
|
158
|
-
export async function fetchPackage(pkg, where) {
|
|
166
|
+
export async function fetchPackage(pkg, where, major) {
|
|
159
167
|
const { entries } = await fetchTarball(pkg.name, pkg.version, pkg.resolution.integrity, where)
|
|
160
|
-
const files = filesOf(entries, where)
|
|
168
|
+
const files = filesOf(entries, where, major)
|
|
161
169
|
const manifest = readManifest(files, pkg, where)
|
|
162
|
-
checkManifest(manifest, pkg, where)
|
|
170
|
+
checkManifest(manifest, pkg, where, major)
|
|
163
171
|
return { files, manifest }
|
|
164
172
|
}
|
package/src/yarn1/tree.js
CHANGED
|
@@ -15,6 +15,7 @@ import { parseYarn1Lockfile } from '@preventive/lockfile/yarn1.js'
|
|
|
15
15
|
import { Vfs, VfsError } from '@preventive/vfs'
|
|
16
16
|
import { dirname, relative } from '@preventive/vfs/path.js'
|
|
17
17
|
import { clean, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
18
|
+
import { eachConcurrently } from '../concurrent.js'
|
|
18
19
|
import { DeptreeError, quote } from '../error.js'
|
|
19
20
|
import { checkNoModules, mount } from '../mount.js'
|
|
20
21
|
import { checkCollisions } from '../pnpm/checks.js'
|
|
@@ -29,8 +30,6 @@ import { resolvePeers } from './peers.js'
|
|
|
29
30
|
import { AGGREGATOR, aggregatorOf, rulesOf, topRequests, workspacesOf } from './requests.js'
|
|
30
31
|
import { resolve, splitPattern } from './resolve.js'
|
|
31
32
|
|
|
32
|
-
const CONCURRENCY = 8
|
|
33
|
-
|
|
34
33
|
// What a refusal of a reference is about: the first pattern of it.
|
|
35
34
|
const whereOf = (ref) => quote(ref.patterns[0])
|
|
36
35
|
|
|
@@ -47,27 +46,20 @@ function fetchedName(ref) {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
// Each registry reference's files and package.json, a few at a time,
|
|
50
|
-
// every tarball's URL checked before any is fetched
|
|
51
|
-
// stops the rest from starting.
|
|
49
|
+
// every tarball's URL checked before any is fetched.
|
|
52
50
|
async function fetchAll(refs) {
|
|
53
51
|
const fetched = new Map()
|
|
54
|
-
const
|
|
52
|
+
const tarballs = refs.map((ref) => {
|
|
55
53
|
const where = whereOf(ref)
|
|
56
54
|
return { ref, where, tarball: registryTarball(ref.entry, fetchedName(ref), where) }
|
|
57
55
|
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
fetched.set(ref, await fetchYarnPackage(tarball, where))
|
|
64
|
-
} catch (error) {
|
|
65
|
-
failed = true
|
|
66
|
-
throw error instanceof DeptreeError ? error : new DeptreeError(error.message, where, { cause: error })
|
|
67
|
-
}
|
|
56
|
+
await eachConcurrently(tarballs, async ({ ref, where, tarball }) => {
|
|
57
|
+
try {
|
|
58
|
+
fetched.set(ref, await fetchYarnPackage(tarball, where))
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw error instanceof DeptreeError ? error : new DeptreeError(error.message, where, { cause: error })
|
|
68
61
|
}
|
|
69
|
-
}
|
|
70
|
-
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, queue.length) }, worker))
|
|
62
|
+
})
|
|
71
63
|
return fetched
|
|
72
64
|
}
|
|
73
65
|
|