@preventive/deptree 1.0.0 → 1.0.1
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 +3 -3
- package/src/npm/package.js +8 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/deptree",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "In-memory dependency tree, as a package manager installs it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -144,11 +144,11 @@
|
|
|
144
144
|
"dependencies": {
|
|
145
145
|
"@chalker/queue": "^1.0.1",
|
|
146
146
|
"@exodus/bytes": "^1.16.0",
|
|
147
|
-
"@preventive/archive": "1.
|
|
147
|
+
"@preventive/archive": "^1.2.0",
|
|
148
148
|
"@preventive/compare": "^1.2.11",
|
|
149
149
|
"@preventive/diff": "^1.1.0",
|
|
150
150
|
"@preventive/lockfile": "^1.2.0",
|
|
151
|
-
"@preventive/upstream": "^1.
|
|
151
|
+
"@preventive/upstream": "^1.3.0",
|
|
152
152
|
"@preventive/vfs": "1.0.0-beta.4"
|
|
153
153
|
}
|
|
154
154
|
}
|
package/src/npm/package.js
CHANGED
|
@@ -22,42 +22,18 @@ export function registryTarball({ name, version, resolution }, where) {
|
|
|
22
22
|
|
|
23
23
|
const FILES = new Set(['file', 'contiguous-file'])
|
|
24
24
|
|
|
25
|
-
// The headers that stand ahead of an entry: pax, global, long name, long link.
|
|
26
|
-
const EXTENDED = new Set([0x78, 0x67, 0x4c, 0x4b])
|
|
27
|
-
const PAX = 0x78
|
|
28
|
-
const BLOCK = 512
|
|
29
|
-
const blocks = (size) => BLOCK * Math.ceil(size / BLOCK)
|
|
30
|
-
|
|
31
|
-
// An extended header's size as the archive reader read it, which held it to
|
|
32
|
-
// 1 MiB: base 256, or octal digits to a NUL, a blank field 0.
|
|
33
|
-
function extendedSize(tar, at) {
|
|
34
|
-
const field = tar.subarray(at + 124, at + 136)
|
|
35
|
-
if (field[0] === 0x80 || field[0] === 0xff) return field.subarray(1).reduce((size, byte) => size * 256 + byte, 0)
|
|
36
|
-
const digits = /^ *([0-7]*)/u.exec(String.fromCodePoint(...field).split('\0')[0])[1]
|
|
37
|
-
return digits === '' ? 0 : Number.parseInt(digits, 8)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
25
|
// Every tar release takes a pax size over the header's. Up to 7.5.15, as
|
|
41
26
|
// npm 10.9.8 and 11.16 and before bundle it, tar reads it into each header
|
|
42
27
|
// after the pax one up to its entry too, so a long name, a long link or a
|
|
43
28
|
// global header between them is read by it, and all that follows otherwise
|
|
44
|
-
// than later releases read it. The archive reader
|
|
45
|
-
//
|
|
46
|
-
function checkPaxSizes(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let afterPax = false
|
|
51
|
-
let between = false
|
|
52
|
-
for (let flag = tar[at + 156]; EXTENDED.has(flag); flag = tar[at + 156]) {
|
|
53
|
-
between ||= afterPax
|
|
54
|
-
afterPax ||= flag === PAX
|
|
55
|
-
at += BLOCK + blocks(extendedSize(tar, at))
|
|
29
|
+
// than later releases read it. The archive reader lists the extended headers
|
|
30
|
+
// ahead of each entry, in their order.
|
|
31
|
+
function checkPaxSizes(entries, where) {
|
|
32
|
+
for (const { storedName, pax, extended } of entries) {
|
|
33
|
+
if (pax.has('size') && extended.findIndex(({ kind }) => kind === 'pax') < extended.length - 1) {
|
|
34
|
+
throw new DeptreeError(`${quote(storedName)} has a pax size ahead of another extended header, which tar's releases read otherwise`, where)
|
|
56
35
|
}
|
|
57
|
-
if (between && pax.has('size')) throw new DeptreeError(`${quote(storedName)} has a pax size ahead of another extended header, which tar's releases read otherwise`, where)
|
|
58
|
-
at += BLOCK + blocks(data.length)
|
|
59
36
|
}
|
|
60
|
-
if (tar.length < at + 2 * BLOCK || tar.subarray(at, at + 2 * BLOCK).some((byte) => byte !== 0)) throw new Error('unreachable: no end of the archive where the archive reader found one')
|
|
61
37
|
}
|
|
62
38
|
|
|
63
39
|
function unpack(entries, where) {
|
|
@@ -89,8 +65,8 @@ function unpack(entries, where) {
|
|
|
89
65
|
}
|
|
90
66
|
|
|
91
67
|
export async function fetchNpmPackage({ name, version, integrity }, where, check, fetching) {
|
|
92
|
-
const { bytes,
|
|
68
|
+
const { bytes, entries, inflated, about } = await fetchTarball(name, version, integrity, where, fetching)
|
|
93
69
|
await check?.(bytes, inflated, where)
|
|
94
|
-
checkPaxSizes(
|
|
70
|
+
checkPaxSizes(entries, where)
|
|
95
71
|
return { ...unpack(entries, where), about }
|
|
96
72
|
}
|