@pnpm/fetching.tarball-fetcher 1003.0.0 → 1100.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/lib/gitHostedTarballFetcher.d.ts +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/remoteTarballFetcher.js +60 -26
- package/package.json +26 -26
|
@@ -2,7 +2,6 @@ import type { FetchFunction } from '@pnpm/fetching.fetcher-base';
|
|
|
2
2
|
import type { StoreIndex } from '@pnpm/store.index';
|
|
3
3
|
export interface CreateGitHostedTarballFetcher {
|
|
4
4
|
ignoreScripts?: boolean;
|
|
5
|
-
rawConfig: Record<string, unknown>;
|
|
6
5
|
storeIndex: StoreIndex;
|
|
7
6
|
unsafePerm?: boolean;
|
|
8
7
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export interface TarballFetchers {
|
|
|
14
14
|
gitHostedTarball: FetchFunction;
|
|
15
15
|
}
|
|
16
16
|
export declare function createTarballFetcher(fetchFromRegistry: FetchFromRegistry, getAuthHeader: GetAuthHeader, opts: {
|
|
17
|
-
rawConfig: Record<string, unknown>;
|
|
18
17
|
unsafePerm?: boolean;
|
|
19
18
|
ignoreScripts?: boolean;
|
|
20
19
|
storeIndex: StoreIndex;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
1
|
import util from 'node:util';
|
|
3
2
|
import { requestRetryLogger } from '@pnpm/core-loggers';
|
|
4
3
|
import { FetchError } from '@pnpm/error';
|
|
@@ -38,9 +37,25 @@ export function createDownloader(fetchFromRegistry, gotOpts) {
|
|
|
38
37
|
reject(op.mainError());
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
40
|
+
// Extract error properties into a plain object because Error properties
|
|
41
|
+
// are non-enumerable and don't serialize well through the logging system
|
|
42
|
+
const errorInfo = {
|
|
43
|
+
name: error.name,
|
|
44
|
+
message: error.message,
|
|
45
|
+
code: error.code,
|
|
46
|
+
errno: error.errno,
|
|
47
|
+
// For HTTP errors from our ResponseError class
|
|
48
|
+
status: error.status,
|
|
49
|
+
statusCode: error.statusCode,
|
|
50
|
+
// undici wraps the actual network error in a cause property
|
|
51
|
+
cause: error.cause ? {
|
|
52
|
+
code: error.cause.code,
|
|
53
|
+
errno: error.cause.errno,
|
|
54
|
+
} : undefined,
|
|
55
|
+
};
|
|
41
56
|
requestRetryLogger.debug({
|
|
42
57
|
attempt,
|
|
43
|
-
error,
|
|
58
|
+
error: errorInfo,
|
|
44
59
|
maxRetries: retryOpts.retries,
|
|
45
60
|
method: 'GET',
|
|
46
61
|
timeout,
|
|
@@ -66,9 +81,8 @@ export function createDownloader(fetchFromRegistry, gotOpts) {
|
|
|
66
81
|
throw new FetchError({ url, authHeaderValue }, res);
|
|
67
82
|
}
|
|
68
83
|
const contentLength = res.headers.has('content-length') && res.headers.get('content-length');
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
: null;
|
|
84
|
+
const parsedLength = typeof contentLength === 'string' ? parseInt(contentLength, 10) : NaN;
|
|
85
|
+
const size = Number.isFinite(parsedLength) && parsedLength >= 0 ? parsedLength : null;
|
|
72
86
|
if (opts.onStart != null) {
|
|
73
87
|
opts.onStart(size, currentAttempt);
|
|
74
88
|
}
|
|
@@ -78,19 +92,45 @@ export function createDownloader(fetchFromRegistry, gotOpts) {
|
|
|
78
92
|
: undefined;
|
|
79
93
|
const startTime = Date.now();
|
|
80
94
|
let downloaded = 0;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
if (size !== null) {
|
|
96
|
+
// Known size: pre-allocate and copy directly (avoids intermediate array + second copy pass)
|
|
97
|
+
data = Buffer.from(new SharedArrayBuffer(size));
|
|
98
|
+
for await (const chunk of res.body) {
|
|
99
|
+
const c = chunk;
|
|
100
|
+
const nextDownloaded = downloaded + c.byteLength;
|
|
101
|
+
if (nextDownloaded > size) {
|
|
102
|
+
throw new BadTarballError({
|
|
103
|
+
expectedSize: size,
|
|
104
|
+
receivedSize: nextDownloaded,
|
|
105
|
+
tarballUrl: url,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
data.set(c, downloaded);
|
|
109
|
+
downloaded = nextDownloaded;
|
|
110
|
+
onProgress?.(downloaded);
|
|
111
|
+
}
|
|
112
|
+
if (size !== downloaded) {
|
|
113
|
+
throw new BadTarballError({
|
|
114
|
+
expectedSize: size,
|
|
115
|
+
receivedSize: downloaded,
|
|
116
|
+
tarballUrl: url,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
87
119
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
120
|
+
else {
|
|
121
|
+
const chunks = [];
|
|
122
|
+
for await (const chunk of res.body) {
|
|
123
|
+
const c = chunk;
|
|
124
|
+
chunks.push(c);
|
|
125
|
+
downloaded += c.byteLength;
|
|
126
|
+
onProgress?.(downloaded);
|
|
127
|
+
}
|
|
128
|
+
data = Buffer.from(new SharedArrayBuffer(downloaded));
|
|
129
|
+
let offset = 0;
|
|
130
|
+
for (const chunk of chunks) {
|
|
131
|
+
data.set(chunk, offset);
|
|
132
|
+
offset += chunk.byteLength;
|
|
133
|
+
}
|
|
94
134
|
}
|
|
95
135
|
const elapsedSec = (Date.now() - startTime) / 1000;
|
|
96
136
|
const avgKiBps = Math.floor((downloaded / elapsedSec) / 1024);
|
|
@@ -98,20 +138,14 @@ export function createDownloader(fetchFromRegistry, gotOpts) {
|
|
|
98
138
|
const sizeKb = Math.floor(downloaded / 1024);
|
|
99
139
|
globalWarn(`Tarball download average speed ${avgKiBps} KiB/s (size ${sizeKb} KiB) is below ${fetchMinSpeedKiBps} KiB/s: ${url} (GET)`);
|
|
100
140
|
}
|
|
101
|
-
data = Buffer.from(new SharedArrayBuffer(downloaded));
|
|
102
|
-
let offset = 0;
|
|
103
|
-
for (const chunk of chunks) {
|
|
104
|
-
chunk.copy(data, offset);
|
|
105
|
-
offset += chunk.length;
|
|
106
|
-
}
|
|
107
141
|
}
|
|
108
142
|
catch (err) {
|
|
109
|
-
|
|
110
|
-
Object.assign(
|
|
143
|
+
const error = util.types.isNativeError(err) ? err : new Error(String(err), { cause: err });
|
|
144
|
+
Object.assign(error, {
|
|
111
145
|
attempts: currentAttempt,
|
|
112
146
|
resource: url,
|
|
113
147
|
});
|
|
114
|
-
throw
|
|
148
|
+
throw error;
|
|
115
149
|
}
|
|
116
150
|
return addFilesFromTarball({
|
|
117
151
|
buffer: data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/fetching.tarball-fetcher",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1100.0.1",
|
|
4
4
|
"description": "Fetcher for packages hosted as tarballs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -30,37 +30,37 @@
|
|
|
30
30
|
"lodash.throttle": "4.1.1",
|
|
31
31
|
"p-map-values": "^0.1.0",
|
|
32
32
|
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
33
|
-
"@pnpm/core-loggers": "
|
|
34
|
-
"@pnpm/
|
|
35
|
-
"@pnpm/
|
|
36
|
-
"@pnpm/
|
|
37
|
-
"@pnpm/
|
|
38
|
-
"@pnpm/
|
|
39
|
-
"@pnpm/
|
|
40
|
-
"@pnpm/types": "
|
|
41
|
-
"@pnpm/store.index": "
|
|
33
|
+
"@pnpm/core-loggers": "1100.0.1",
|
|
34
|
+
"@pnpm/exec.prepare-package": "1100.0.1",
|
|
35
|
+
"@pnpm/error": "1100.0.0",
|
|
36
|
+
"@pnpm/fetching.fetcher-base": "1100.0.1",
|
|
37
|
+
"@pnpm/fetching.types": "1100.0.0",
|
|
38
|
+
"@pnpm/fs.graceful-fs": "1100.0.0",
|
|
39
|
+
"@pnpm/fs.packlist": "1100.0.0",
|
|
40
|
+
"@pnpm/types": "1101.0.0",
|
|
41
|
+
"@pnpm/store.index": "1100.0.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@pnpm/logger": ">=1001.0.0 <1002.0.0",
|
|
45
|
-
"@pnpm/worker": "^
|
|
45
|
+
"@pnpm/worker": "^1100.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@jest/globals": "30.0
|
|
48
|
+
"@jest/globals": "30.3.0",
|
|
49
49
|
"@pnpm/util.lex-comparator": "^3.0.2",
|
|
50
|
-
"@types/lodash.throttle": "4.1.
|
|
51
|
-
"@types/ramda": "0.
|
|
50
|
+
"@types/lodash.throttle": "4.1.9",
|
|
51
|
+
"@types/ramda": "0.31.1",
|
|
52
52
|
"@types/retry": "^0.12.5",
|
|
53
53
|
"@types/ssri": "^7.1.5",
|
|
54
|
-
"
|
|
55
|
-
"ssri": "13.0.0",
|
|
54
|
+
"ssri": "13.0.1",
|
|
56
55
|
"tempy": "3.0.0",
|
|
57
|
-
"
|
|
58
|
-
"@pnpm/
|
|
59
|
-
"@pnpm/
|
|
60
|
-
"@pnpm/
|
|
61
|
-
"@pnpm/
|
|
62
|
-
"@pnpm/
|
|
63
|
-
"@pnpm/
|
|
56
|
+
"undici": "^7.2.0",
|
|
57
|
+
"@pnpm/fetching.tarball-fetcher": "1100.0.1",
|
|
58
|
+
"@pnpm/logger": "1100.0.0",
|
|
59
|
+
"@pnpm/network.fetch": "1100.0.1",
|
|
60
|
+
"@pnpm/store.cafs-types": "1100.0.0",
|
|
61
|
+
"@pnpm/store.create-cafs-store": "1100.0.1",
|
|
62
|
+
"@pnpm/test-fixtures": "1100.0.0",
|
|
63
|
+
"@pnpm/types": "1101.0.0"
|
|
64
64
|
},
|
|
65
65
|
"engines": {
|
|
66
66
|
"node": ">=22.13"
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
73
|
+
"test": "pn compile && pn .test",
|
|
74
|
+
"compile": "tsgo --build && pn lint --fix",
|
|
75
|
+
".test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest"
|
|
76
76
|
}
|
|
77
77
|
}
|