@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.
@@ -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 size = typeof contentLength === 'string'
70
- ? parseInt(contentLength, 10)
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
- const chunks = [];
82
- // This will handle the 'data', 'error', and 'end' events.
83
- for await (const chunk of res.body) {
84
- chunks.push(chunk);
85
- downloaded += chunk.length;
86
- onProgress?.(downloaded);
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
- if (size !== null && size !== downloaded) {
89
- throw new BadTarballError({
90
- expectedSize: size,
91
- receivedSize: downloaded,
92
- tarballUrl: url,
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
- assert(util.types.isNativeError(err));
110
- Object.assign(err, {
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 err;
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": "1003.0.0",
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": "1001.0.4",
34
- "@pnpm/error": "1000.0.5",
35
- "@pnpm/fetching.fetcher-base": "1001.0.2",
36
- "@pnpm/fs.graceful-fs": "1000.0.1",
37
- "@pnpm/fs.packlist": "1000.0.0",
38
- "@pnpm/fetching.types": "1000.2.0",
39
- "@pnpm/exec.prepare-package": "1000.0.26",
40
- "@pnpm/types": "1000.9.0",
41
- "@pnpm/store.index": "1000.0.0-0"
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": "^1000.3.0"
45
+ "@pnpm/worker": "^1100.0.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@jest/globals": "30.0.5",
48
+ "@jest/globals": "30.3.0",
49
49
  "@pnpm/util.lex-comparator": "^3.0.2",
50
- "@types/lodash.throttle": "4.1.7",
51
- "@types/ramda": "0.29.12",
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
- "nock": "13.3.4",
55
- "ssri": "13.0.0",
54
+ "ssri": "13.0.1",
56
55
  "tempy": "3.0.0",
57
- "@pnpm/fetching.tarball-fetcher": "1003.0.0",
58
- "@pnpm/network.fetch": "1000.2.6",
59
- "@pnpm/store.cafs-types": "1000.0.0",
60
- "@pnpm/store.create-cafs-store": "1000.0.20",
61
- "@pnpm/logger": "1001.0.1",
62
- "@pnpm/test-fixtures": "1000.0.0",
63
- "@pnpm/types": "1000.9.0"
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
- "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
74
- "test": "pnpm run compile && pnpm run _test",
75
- "compile": "tsgo --build && pnpm run lint --fix"
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
  }