@pnpm/fetching.binary-fetcher 1005.0.4 → 1100.0.0
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/lib/index.d.ts +4 -3
- package/lib/index.js +30 -35
- package/package.json +19 -18
- package/lib/index.js.map +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { BinaryFetcher, FetchFunction } from '@pnpm/fetching.fetcher-base';
|
|
2
|
+
import type { FetchFromRegistry } from '@pnpm/fetching.types';
|
|
3
|
+
import type { StoreIndex } from '@pnpm/store.index';
|
|
3
4
|
export declare function createBinaryFetcher(ctx: {
|
|
4
5
|
fetch: FetchFromRegistry;
|
|
5
6
|
fetchFromRemoteTarball: FetchFunction;
|
|
6
|
-
|
|
7
|
+
storeIndex: StoreIndex;
|
|
7
8
|
offline?: boolean;
|
|
8
9
|
}): {
|
|
9
10
|
binary: BinaryFetcher;
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const worker_1 = require("@pnpm/worker");
|
|
12
|
-
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
13
|
-
const is_subdir_1 = __importDefault(require("is-subdir"));
|
|
14
|
-
const rename_overwrite_1 = __importDefault(require("rename-overwrite"));
|
|
15
|
-
const tempy_1 = __importDefault(require("tempy"));
|
|
16
|
-
const ssri_1 = __importDefault(require("ssri"));
|
|
17
|
-
function createBinaryFetcher(ctx) {
|
|
1
|
+
import fsPromises from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { PnpmError } from '@pnpm/error';
|
|
4
|
+
import { addFilesFromDir } from '@pnpm/worker';
|
|
5
|
+
import AdmZip from 'adm-zip';
|
|
6
|
+
import { isSubdir } from 'is-subdir';
|
|
7
|
+
import { renameOverwrite } from 'rename-overwrite';
|
|
8
|
+
import ssri from 'ssri';
|
|
9
|
+
import { temporaryDirectory } from 'tempy';
|
|
10
|
+
export function createBinaryFetcher(ctx) {
|
|
18
11
|
const fetchBinary = async (cafs, resolution, opts) => {
|
|
19
12
|
if (ctx.offline) {
|
|
20
|
-
throw new
|
|
13
|
+
throw new PnpmError('CANNOT_DOWNLOAD_BINARY_OFFLINE', `Cannot download binary "${resolution.url}" because offline mode is enabled.`);
|
|
21
14
|
}
|
|
22
15
|
const manifest = {
|
|
23
16
|
name: opts.pkg.name,
|
|
@@ -43,17 +36,19 @@ function createBinaryFetcher(ctx) {
|
|
|
43
36
|
integrity: resolution.integrity,
|
|
44
37
|
basename: resolution.prefix ?? '',
|
|
45
38
|
}, tempLocation);
|
|
46
|
-
fetchResult = await
|
|
39
|
+
fetchResult = await addFilesFromDir({
|
|
47
40
|
storeDir: cafs.storeDir,
|
|
41
|
+
storeIndex: ctx.storeIndex,
|
|
48
42
|
dir: tempLocation,
|
|
49
43
|
filesIndexFile: opts.filesIndexFile,
|
|
50
44
|
readManifest: false,
|
|
51
45
|
appendManifest: manifest,
|
|
46
|
+
includeNodeModules: true,
|
|
52
47
|
});
|
|
53
48
|
break;
|
|
54
49
|
}
|
|
55
50
|
default: {
|
|
56
|
-
throw new
|
|
51
|
+
throw new PnpmError('NOT_SUPPORTED_ARCHIVE', `The binary fetcher doesn't support archive type ${resolution.archive}`);
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
54
|
return {
|
|
@@ -73,8 +68,8 @@ function createBinaryFetcher(ctx) {
|
|
|
73
68
|
* @param targetDir - Directory where the binary asset should be installed
|
|
74
69
|
* @throws {PnpmError} When integrity verification fails or extraction fails
|
|
75
70
|
*/
|
|
76
|
-
async function downloadAndUnpackZip(fetchFromRegistry, assetInfo, targetDir) {
|
|
77
|
-
const tmp =
|
|
71
|
+
export async function downloadAndUnpackZip(fetchFromRegistry, assetInfo, targetDir) {
|
|
72
|
+
const tmp = path.join(temporaryDirectory(), 'pnpm.zip');
|
|
78
73
|
try {
|
|
79
74
|
await downloadWithIntegrityCheck(fetchFromRegistry, assetInfo, tmp);
|
|
80
75
|
await extractZipToTarget(tmp, assetInfo.basename, targetDir);
|
|
@@ -82,7 +77,7 @@ async function downloadAndUnpackZip(fetchFromRegistry, assetInfo, targetDir) {
|
|
|
82
77
|
finally {
|
|
83
78
|
// Clean up temporary file
|
|
84
79
|
try {
|
|
85
|
-
await
|
|
80
|
+
await fsPromises.unlink(tmp);
|
|
86
81
|
}
|
|
87
82
|
catch {
|
|
88
83
|
// Ignore cleanup errors
|
|
@@ -102,16 +97,16 @@ async function downloadWithIntegrityCheck(fetchFromRegistry, { url, integrity },
|
|
|
102
97
|
const data = Buffer.concat(chunks);
|
|
103
98
|
try {
|
|
104
99
|
// Verify integrity if provided
|
|
105
|
-
|
|
100
|
+
ssri.checkData(data, integrity, { error: true });
|
|
106
101
|
}
|
|
107
102
|
catch (err) {
|
|
108
103
|
if (!(err instanceof Error) || !('expected' in err) || !('found' in err)) {
|
|
109
104
|
throw err;
|
|
110
105
|
}
|
|
111
|
-
throw new
|
|
106
|
+
throw new PnpmError('TARBALL_INTEGRITY', `Got unexpected checksum for "${url}". Wanted "${err.expected}". Got "${err.found}".`);
|
|
112
107
|
}
|
|
113
108
|
// Write the verified data to file
|
|
114
|
-
await
|
|
109
|
+
await fsPromises.writeFile(tmpPath, data);
|
|
115
110
|
}
|
|
116
111
|
/**
|
|
117
112
|
* Extracts a zip file to the target directory.
|
|
@@ -122,8 +117,8 @@ async function downloadWithIntegrityCheck(fetchFromRegistry, { url, integrity },
|
|
|
122
117
|
* @throws {PnpmError} When extraction fails or path traversal is detected
|
|
123
118
|
*/
|
|
124
119
|
async function extractZipToTarget(zipPath, basename, targetDir) {
|
|
125
|
-
const zip = new
|
|
126
|
-
const nodeDir = basename === '' ? targetDir :
|
|
120
|
+
const zip = new AdmZip(zipPath);
|
|
121
|
+
const nodeDir = basename === '' ? targetDir : path.dirname(targetDir);
|
|
127
122
|
// Validate basename/prefix doesn't escape the target directory
|
|
128
123
|
if (basename !== '') {
|
|
129
124
|
validatePathSecurity(nodeDir, basename);
|
|
@@ -134,8 +129,8 @@ async function extractZipToTarget(zipPath, basename, targetDir) {
|
|
|
134
129
|
validatePathSecurity(nodeDir, entryPath);
|
|
135
130
|
zip.extractEntryTo(entry, nodeDir, true, true);
|
|
136
131
|
}
|
|
137
|
-
const extractedDir =
|
|
138
|
-
await (
|
|
132
|
+
const extractedDir = path.join(nodeDir, basename);
|
|
133
|
+
await renameOverwrite(extractedDir, targetDir);
|
|
139
134
|
}
|
|
140
135
|
/**
|
|
141
136
|
* Validates that a path does not escape the base directory via path traversal.
|
|
@@ -146,12 +141,12 @@ async function extractZipToTarget(zipPath, basename, targetDir) {
|
|
|
146
141
|
*/
|
|
147
142
|
function validatePathSecurity(basePath, targetPath) {
|
|
148
143
|
// Explicitly reject absolute paths - they should never be allowed as prefixes or entry names
|
|
149
|
-
if (
|
|
150
|
-
throw new
|
|
144
|
+
if (path.isAbsolute(targetPath)) {
|
|
145
|
+
throw new PnpmError('PATH_TRAVERSAL', `Refusing to extract path "${targetPath}" - absolute paths are not allowed`);
|
|
151
146
|
}
|
|
152
|
-
const normalizedTarget =
|
|
153
|
-
if (!(
|
|
154
|
-
throw new
|
|
147
|
+
const normalizedTarget = path.resolve(basePath, targetPath);
|
|
148
|
+
if (!isSubdir(basePath, normalizedTarget) && normalizedTarget !== basePath) {
|
|
149
|
+
throw new PnpmError('PATH_TRAVERSAL', `Refusing to extract path "${targetPath}" outside of target directory`);
|
|
155
150
|
}
|
|
156
151
|
}
|
|
157
152
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/fetching.binary-fetcher",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1100.0.0",
|
|
4
4
|
"description": "A fetcher for binary archives",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
7
|
-
"
|
|
7
|
+
"pnpm11"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"funding": "https://opencollective.com/pnpm",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/pnpm/pnpm/issues"
|
|
15
15
|
},
|
|
16
|
-
"type": "
|
|
16
|
+
"type": "module",
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"types": "lib/index.d.ts",
|
|
19
19
|
"exports": {
|
|
@@ -25,34 +25,35 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"adm-zip": "^0.5.16",
|
|
28
|
-
"is-subdir": "^
|
|
29
|
-
"rename-overwrite": "^
|
|
30
|
-
"ssri": "
|
|
31
|
-
"tempy": "
|
|
32
|
-
"@pnpm/error": "
|
|
33
|
-
"@pnpm/fetching-
|
|
34
|
-
"@pnpm/
|
|
28
|
+
"is-subdir": "^2.0.0",
|
|
29
|
+
"rename-overwrite": "^7.0.1",
|
|
30
|
+
"ssri": "13.0.1",
|
|
31
|
+
"tempy": "3.0.0",
|
|
32
|
+
"@pnpm/error": "1100.0.0",
|
|
33
|
+
"@pnpm/fetching.fetcher-base": "1100.0.0",
|
|
34
|
+
"@pnpm/fetching.types": "1100.0.0",
|
|
35
|
+
"@pnpm/store.index": "1100.0.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"@pnpm/worker": "^
|
|
38
|
+
"@pnpm/worker": "^1100.0.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@jest/globals": "
|
|
41
|
+
"@jest/globals": "30.3.0",
|
|
41
42
|
"@types/adm-zip": "^0.5.7",
|
|
42
43
|
"@types/ssri": "^7.1.5",
|
|
43
|
-
"tempy": "
|
|
44
|
-
"@pnpm/fetching.binary-fetcher": "
|
|
44
|
+
"tempy": "3.0.0",
|
|
45
|
+
"@pnpm/fetching.binary-fetcher": "1100.0.0"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
48
|
+
"node": ">=22.13"
|
|
48
49
|
},
|
|
49
50
|
"jest": {
|
|
50
51
|
"preset": "@pnpm/jest-config"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
|
-
"
|
|
54
|
-
"test": "pnpm run compile && pnpm run _test",
|
|
54
|
+
"test": "pn compile && pn .test",
|
|
55
55
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
56
|
-
"compile": "
|
|
56
|
+
"compile": "tsgo --build && pn lint --fix",
|
|
57
|
+
".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest"
|
|
57
58
|
}
|
|
58
59
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAYA,kDAyDC;AAgBD,oDAkBC;AAvGD,gDAAuB;AACvB,2DAAoC;AACpC,uCAAuC;AAGvC,yCAA8C;AAC9C,sDAA4B;AAC5B,0DAAgC;AAChC,wEAA8C;AAC9C,kDAAyB;AACzB,gDAAuB;AAEvB,SAAgB,mBAAmB,CAAE,GAKpC;IACC,MAAM,WAAW,GAAkB,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE;QAClE,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAS,CAAC,gCAAgC,EAAE,2BAA2B,UAAU,CAAC,GAAG,oCAAoC,CAAC,CAAA;QACtI,CAAC;QAED,MAAM,QAAQ,GAAG;YACf,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAK;YACpB,O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