@pnpm/fetching.tarball-fetcher 1003.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/LICENSE +22 -0
- package/README.md +15 -0
- package/lib/errorTypes/BadTarballError.d.ts +11 -0
- package/lib/errorTypes/BadTarballError.js +14 -0
- package/lib/errorTypes/index.d.ts +1 -0
- package/lib/errorTypes/index.js +2 -0
- package/lib/gitHostedTarballFetcher.d.ts +9 -0
- package/lib/gitHostedTarballFetcher.js +89 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +48 -0
- package/lib/localTarballFetcher.d.ts +3 -0
- package/lib/localTarballFetcher.js +28 -0
- package/lib/remoteTarballFetcher.d.ts +36 -0
- package/lib/remoteTarballFetcher.js +130 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
|
4
|
+
Copyright (c) 2016-2026 Zoltan Kochan and other contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @pnpm/tarball-fetcher
|
|
2
|
+
|
|
3
|
+
> Fetcher for packages hosted as tarballs
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@pnpm/tarball-fetcher)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pnpm add @pnpm/tarball-fetcher
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PnpmError } from '@pnpm/error';
|
|
2
|
+
export declare class BadTarballError extends PnpmError {
|
|
3
|
+
expectedSize: number;
|
|
4
|
+
receivedSize: number;
|
|
5
|
+
constructor(opts: {
|
|
6
|
+
attempts?: number;
|
|
7
|
+
expectedSize: number;
|
|
8
|
+
receivedSize: number;
|
|
9
|
+
tarballUrl: string;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PnpmError } from '@pnpm/error';
|
|
2
|
+
export class BadTarballError extends PnpmError {
|
|
3
|
+
expectedSize;
|
|
4
|
+
receivedSize;
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
const message = `Actual size (${opts.receivedSize}) of tarball (${opts.tarballUrl}) did not match the one specified in 'Content-Length' header (${opts.expectedSize})`;
|
|
7
|
+
super('BAD_TARBALL_SIZE', message, {
|
|
8
|
+
attempts: opts?.attempts,
|
|
9
|
+
});
|
|
10
|
+
this.expectedSize = opts.expectedSize;
|
|
11
|
+
this.receivedSize = opts.receivedSize;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=BadTarballError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BadTarballError } from './BadTarballError.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FetchFunction } from '@pnpm/fetching.fetcher-base';
|
|
2
|
+
import type { StoreIndex } from '@pnpm/store.index';
|
|
3
|
+
export interface CreateGitHostedTarballFetcher {
|
|
4
|
+
ignoreScripts?: boolean;
|
|
5
|
+
rawConfig: Record<string, unknown>;
|
|
6
|
+
storeIndex: StoreIndex;
|
|
7
|
+
unsafePerm?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createGitHostedTarballFetcher(fetchRemoteTarball: FetchFunction, fetcherOpts: CreateGitHostedTarballFetcher): FetchFunction;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import util from 'node:util';
|
|
3
|
+
import { preparePackage } from '@pnpm/exec.prepare-package';
|
|
4
|
+
import { packlist } from '@pnpm/fs.packlist';
|
|
5
|
+
import { globalWarn } from '@pnpm/logger';
|
|
6
|
+
import { addFilesFromDir } from '@pnpm/worker';
|
|
7
|
+
export function createGitHostedTarballFetcher(fetchRemoteTarball, fetcherOpts) {
|
|
8
|
+
const fetch = async (cafs, resolution, opts) => {
|
|
9
|
+
const rawFilesIndexFile = `${opts.filesIndexFile}\traw`;
|
|
10
|
+
const { filesMap, manifest, requiresBuild } = await fetchRemoteTarball(cafs, resolution, {
|
|
11
|
+
...opts,
|
|
12
|
+
filesIndexFile: rawFilesIndexFile,
|
|
13
|
+
});
|
|
14
|
+
// Flush any queued store index writes so that the raw files index entry
|
|
15
|
+
// written during tarball extraction is visible to subsequent reads.
|
|
16
|
+
fetcherOpts.storeIndex.flush();
|
|
17
|
+
try {
|
|
18
|
+
const prepareResult = await prepareGitHostedPkg(filesMap, cafs, rawFilesIndexFile, opts.filesIndexFile, fetcherOpts, opts, resolution);
|
|
19
|
+
if (prepareResult.ignoredBuild) {
|
|
20
|
+
globalWarn(`The git-hosted package fetched from "${resolution.tarball}" has to be built but the build scripts were ignored.`);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
filesMap: prepareResult.filesMap,
|
|
24
|
+
manifest: prepareResult.manifest ?? manifest,
|
|
25
|
+
requiresBuild,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
assert(util.types.isNativeError(err));
|
|
30
|
+
err.message = `Failed to prepare git-hosted package fetched from "${resolution.tarball}": ${err.message}`;
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return fetch;
|
|
35
|
+
}
|
|
36
|
+
async function prepareGitHostedPkg(filesMap, cafs, rawFilesIndexFile, filesIndexFile, opts, fetcherOpts, resolution) {
|
|
37
|
+
const tempLocation = await cafs.tempDir();
|
|
38
|
+
cafs.importPackage(tempLocation, {
|
|
39
|
+
filesResponse: {
|
|
40
|
+
filesMap,
|
|
41
|
+
resolvedFrom: 'remote',
|
|
42
|
+
requiresBuild: false,
|
|
43
|
+
},
|
|
44
|
+
force: true,
|
|
45
|
+
});
|
|
46
|
+
const { shouldBeBuilt, pkgDir } = await preparePackage({
|
|
47
|
+
...opts,
|
|
48
|
+
allowBuild: fetcherOpts.allowBuild,
|
|
49
|
+
}, tempLocation, resolution.path ?? '');
|
|
50
|
+
const files = await packlist(pkgDir);
|
|
51
|
+
const { storeIndex } = opts;
|
|
52
|
+
if (!resolution.path && files.length === filesMap.size) {
|
|
53
|
+
if (!shouldBeBuilt) {
|
|
54
|
+
const data = storeIndex.get(rawFilesIndexFile);
|
|
55
|
+
if (data) {
|
|
56
|
+
storeIndex.set(filesIndexFile, data);
|
|
57
|
+
storeIndex.delete(rawFilesIndexFile);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
filesMap,
|
|
61
|
+
ignoredBuild: false,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (opts.ignoreScripts) {
|
|
65
|
+
storeIndex.delete(rawFilesIndexFile);
|
|
66
|
+
return {
|
|
67
|
+
filesMap,
|
|
68
|
+
ignoredBuild: true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
storeIndex.delete(rawFilesIndexFile);
|
|
73
|
+
// Important! We cannot remove the temp location at this stage.
|
|
74
|
+
// Even though we have the index of the package,
|
|
75
|
+
// the linking of files to the store is in progress.
|
|
76
|
+
return {
|
|
77
|
+
...await addFilesFromDir({
|
|
78
|
+
storeDir: cafs.storeDir,
|
|
79
|
+
storeIndex: opts.storeIndex,
|
|
80
|
+
dir: pkgDir,
|
|
81
|
+
files,
|
|
82
|
+
filesIndexFile,
|
|
83
|
+
pkg: fetcherOpts.pkg,
|
|
84
|
+
readManifest: fetcherOpts.readManifest,
|
|
85
|
+
}),
|
|
86
|
+
ignoredBuild: Boolean(opts.ignoreScripts),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=gitHostedTarballFetcher.js.map
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FetchFunction } from '@pnpm/fetching.fetcher-base';
|
|
2
|
+
import type { FetchFromRegistry, GetAuthHeader, RetryTimeoutOptions } from '@pnpm/fetching.types';
|
|
3
|
+
import type { StoreIndex } from '@pnpm/store.index';
|
|
4
|
+
import { TarballIntegrityError } from '@pnpm/worker';
|
|
5
|
+
import { type CreateDownloaderOptions } from './remoteTarballFetcher.js';
|
|
6
|
+
export { BadTarballError } from './errorTypes/index.js';
|
|
7
|
+
export { TarballIntegrityError };
|
|
8
|
+
export { createGitHostedTarballFetcher } from './gitHostedTarballFetcher.js';
|
|
9
|
+
export { createLocalTarballFetcher } from './localTarballFetcher.js';
|
|
10
|
+
export { createDownloader, type CreateDownloaderOptions, type DownloadFunction } from './remoteTarballFetcher.js';
|
|
11
|
+
export interface TarballFetchers {
|
|
12
|
+
localTarball: FetchFunction;
|
|
13
|
+
remoteTarball: FetchFunction;
|
|
14
|
+
gitHostedTarball: FetchFunction;
|
|
15
|
+
}
|
|
16
|
+
export declare function createTarballFetcher(fetchFromRegistry: FetchFromRegistry, getAuthHeader: GetAuthHeader, opts: {
|
|
17
|
+
rawConfig: Record<string, unknown>;
|
|
18
|
+
unsafePerm?: boolean;
|
|
19
|
+
ignoreScripts?: boolean;
|
|
20
|
+
storeIndex: StoreIndex;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
retry?: RetryTimeoutOptions;
|
|
23
|
+
offline?: boolean;
|
|
24
|
+
} & Pick<CreateDownloaderOptions, 'fetchMinSpeedKiBps'>): TarballFetchers;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PnpmError } from '@pnpm/error';
|
|
2
|
+
import { TarballIntegrityError } from '@pnpm/worker';
|
|
3
|
+
import { createGitHostedTarballFetcher } from './gitHostedTarballFetcher.js';
|
|
4
|
+
import { createLocalTarballFetcher } from './localTarballFetcher.js';
|
|
5
|
+
import { createDownloader, } from './remoteTarballFetcher.js';
|
|
6
|
+
export { BadTarballError } from './errorTypes/index.js';
|
|
7
|
+
export { TarballIntegrityError };
|
|
8
|
+
// Export individual fetcher factories for custom fetcher authors
|
|
9
|
+
export { createGitHostedTarballFetcher } from './gitHostedTarballFetcher.js';
|
|
10
|
+
export { createLocalTarballFetcher } from './localTarballFetcher.js';
|
|
11
|
+
export { createDownloader } from './remoteTarballFetcher.js';
|
|
12
|
+
export function createTarballFetcher(fetchFromRegistry, getAuthHeader, opts) {
|
|
13
|
+
const download = createDownloader(fetchFromRegistry, {
|
|
14
|
+
retry: opts.retry,
|
|
15
|
+
timeout: opts.timeout,
|
|
16
|
+
fetchMinSpeedKiBps: opts.fetchMinSpeedKiBps,
|
|
17
|
+
});
|
|
18
|
+
const remoteTarballFetcher = fetchFromTarball.bind(null, {
|
|
19
|
+
download,
|
|
20
|
+
getAuthHeaderByURI: getAuthHeader,
|
|
21
|
+
offline: opts.offline,
|
|
22
|
+
storeIndex: opts.storeIndex,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
localTarball: createLocalTarballFetcher(opts.storeIndex),
|
|
26
|
+
remoteTarball: remoteTarballFetcher,
|
|
27
|
+
gitHostedTarball: createGitHostedTarballFetcher(remoteTarballFetcher, opts),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function fetchFromTarball(ctx, cafs, resolution, opts) {
|
|
31
|
+
if (ctx.offline) {
|
|
32
|
+
throw new PnpmError('NO_OFFLINE_TARBALL', `A package is missing from the store but cannot download it in offline mode. The missing package may be downloaded from ${resolution.tarball}.`);
|
|
33
|
+
}
|
|
34
|
+
return ctx.download(resolution.tarball, {
|
|
35
|
+
getAuthHeaderByURI: ctx.getAuthHeaderByURI,
|
|
36
|
+
cafs,
|
|
37
|
+
storeIndex: ctx.storeIndex,
|
|
38
|
+
integrity: resolution.integrity,
|
|
39
|
+
readManifest: opts.readManifest,
|
|
40
|
+
onProgress: opts.onProgress,
|
|
41
|
+
onStart: opts.onStart,
|
|
42
|
+
registry: resolution.registry,
|
|
43
|
+
filesIndexFile: opts.filesIndexFile,
|
|
44
|
+
pkg: opts.pkg,
|
|
45
|
+
appendManifest: opts.appendManifest,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import gfs from '@pnpm/fs.graceful-fs';
|
|
3
|
+
import { addFilesFromTarball } from '@pnpm/worker';
|
|
4
|
+
const isAbsolutePath = /^\/|^[A-Z]:/i;
|
|
5
|
+
export function createLocalTarballFetcher(storeIndex) {
|
|
6
|
+
const fetch = (cafs, resolution, opts) => {
|
|
7
|
+
const tarball = resolvePath(opts.lockfileDir, resolution.tarball.slice(5));
|
|
8
|
+
const buffer = gfs.readFileSync(tarball);
|
|
9
|
+
return addFilesFromTarball({
|
|
10
|
+
storeDir: cafs.storeDir,
|
|
11
|
+
storeIndex,
|
|
12
|
+
buffer,
|
|
13
|
+
filesIndexFile: opts.filesIndexFile,
|
|
14
|
+
integrity: resolution.integrity,
|
|
15
|
+
readManifest: opts.readManifest,
|
|
16
|
+
url: tarball,
|
|
17
|
+
pkg: opts.pkg,
|
|
18
|
+
appendManifest: opts.appendManifest,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
return fetch;
|
|
22
|
+
}
|
|
23
|
+
function resolvePath(where, spec) {
|
|
24
|
+
if (isAbsolutePath.test(spec))
|
|
25
|
+
return spec;
|
|
26
|
+
return path.resolve(where, spec);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=localTarballFetcher.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import type { FetchOptions, FetchResult } from '@pnpm/fetching.fetcher-base';
|
|
3
|
+
import type { FetchFromRegistry } from '@pnpm/fetching.types';
|
|
4
|
+
import type { Cafs } from '@pnpm/store.cafs-types';
|
|
5
|
+
import type { StoreIndex } from '@pnpm/store.index';
|
|
6
|
+
export interface HttpResponse {
|
|
7
|
+
body: string;
|
|
8
|
+
}
|
|
9
|
+
export type DownloadOptions = {
|
|
10
|
+
getAuthHeaderByURI: (registry: string) => string | undefined;
|
|
11
|
+
cafs: Cafs;
|
|
12
|
+
registry?: string;
|
|
13
|
+
onStart?: (totalSize: number | null, attempt: number) => void;
|
|
14
|
+
onProgress?: (downloaded: number) => void;
|
|
15
|
+
integrity?: string;
|
|
16
|
+
storeIndex: StoreIndex;
|
|
17
|
+
} & Pick<FetchOptions, 'pkg' | 'appendManifest' | 'readManifest' | 'filesIndexFile'>;
|
|
18
|
+
export type DownloadFunction = (url: string, opts: DownloadOptions) => Promise<FetchResult>;
|
|
19
|
+
export interface NpmRegistryClient {
|
|
20
|
+
get: (url: string, getOpts: object, cb: (err: Error, data: object, raw: object, res: HttpResponse) => void) => void;
|
|
21
|
+
fetch: (url: string, opts: {
|
|
22
|
+
auth?: object;
|
|
23
|
+
}, cb: (err: Error, res: IncomingMessage) => void) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateDownloaderOptions {
|
|
26
|
+
retry?: {
|
|
27
|
+
retries?: number;
|
|
28
|
+
factor?: number;
|
|
29
|
+
minTimeout?: number;
|
|
30
|
+
maxTimeout?: number;
|
|
31
|
+
randomize?: boolean;
|
|
32
|
+
};
|
|
33
|
+
timeout?: number;
|
|
34
|
+
fetchMinSpeedKiBps?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare function createDownloader(fetchFromRegistry: FetchFromRegistry, gotOpts: CreateDownloaderOptions): DownloadFunction;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import util from 'node:util';
|
|
3
|
+
import { requestRetryLogger } from '@pnpm/core-loggers';
|
|
4
|
+
import { FetchError } from '@pnpm/error';
|
|
5
|
+
import { globalWarn } from '@pnpm/logger';
|
|
6
|
+
import { addFilesFromTarball } from '@pnpm/worker';
|
|
7
|
+
import * as retry from '@zkochan/retry';
|
|
8
|
+
import throttle from 'lodash.throttle';
|
|
9
|
+
import { BadTarballError } from './errorTypes/index.js';
|
|
10
|
+
const BIG_TARBALL_SIZE = 1024 * 1024 * 5; // 5 MB
|
|
11
|
+
export function createDownloader(fetchFromRegistry, gotOpts) {
|
|
12
|
+
const retryOpts = {
|
|
13
|
+
factor: 10,
|
|
14
|
+
maxTimeout: 6e4, // 1 minute
|
|
15
|
+
minTimeout: 1e4, // 10 seconds
|
|
16
|
+
retries: 2,
|
|
17
|
+
...gotOpts.retry,
|
|
18
|
+
};
|
|
19
|
+
const fetchMinSpeedKiBps = gotOpts.fetchMinSpeedKiBps ?? 50; // 50 KiB/s
|
|
20
|
+
return async function download(url, opts) {
|
|
21
|
+
const authHeaderValue = opts.getAuthHeaderByURI(url);
|
|
22
|
+
const op = retry.operation(retryOpts);
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
op.attempt(async (attempt) => {
|
|
25
|
+
try {
|
|
26
|
+
resolve(await fetch(attempt));
|
|
27
|
+
}
|
|
28
|
+
catch (error) { // eslint-disable-line
|
|
29
|
+
if (error.response?.status === 401 ||
|
|
30
|
+
error.response?.status === 403 ||
|
|
31
|
+
error.response?.status === 404 ||
|
|
32
|
+
error.code === 'ERR_PNPM_PREPARE_PKG_FAILURE') {
|
|
33
|
+
reject(error);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const timeout = op.retry(error);
|
|
37
|
+
if (timeout === false) {
|
|
38
|
+
reject(op.mainError());
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
requestRetryLogger.debug({
|
|
42
|
+
attempt,
|
|
43
|
+
error,
|
|
44
|
+
maxRetries: retryOpts.retries,
|
|
45
|
+
method: 'GET',
|
|
46
|
+
timeout,
|
|
47
|
+
url,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
async function fetch(currentAttempt) {
|
|
53
|
+
let data;
|
|
54
|
+
try {
|
|
55
|
+
const res = await fetchFromRegistry(url, {
|
|
56
|
+
authHeaderValue,
|
|
57
|
+
// The fetch library can retry requests on bad HTTP responses.
|
|
58
|
+
// However, it is not enough to retry on bad HTTP responses only.
|
|
59
|
+
// Requests should also be retried when the tarball's integrity check fails.
|
|
60
|
+
// Hence, we tell fetch to not retry,
|
|
61
|
+
// and we perform the retries from this function instead.
|
|
62
|
+
retry: { retries: 0 },
|
|
63
|
+
timeout: gotOpts.timeout,
|
|
64
|
+
});
|
|
65
|
+
if (res.status !== 200) {
|
|
66
|
+
throw new FetchError({ url, authHeaderValue }, res);
|
|
67
|
+
}
|
|
68
|
+
const contentLength = res.headers.has('content-length') && res.headers.get('content-length');
|
|
69
|
+
const size = typeof contentLength === 'string'
|
|
70
|
+
? parseInt(contentLength, 10)
|
|
71
|
+
: null;
|
|
72
|
+
if (opts.onStart != null) {
|
|
73
|
+
opts.onStart(size, currentAttempt);
|
|
74
|
+
}
|
|
75
|
+
// In order to reduce the amount of logs, we only report the download progress of big tarballs
|
|
76
|
+
const onProgress = (size != null && size >= BIG_TARBALL_SIZE && opts.onProgress)
|
|
77
|
+
? throttle(opts.onProgress, 500)
|
|
78
|
+
: undefined;
|
|
79
|
+
const startTime = Date.now();
|
|
80
|
+
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);
|
|
87
|
+
}
|
|
88
|
+
if (size !== null && size !== downloaded) {
|
|
89
|
+
throw new BadTarballError({
|
|
90
|
+
expectedSize: size,
|
|
91
|
+
receivedSize: downloaded,
|
|
92
|
+
tarballUrl: url,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const elapsedSec = (Date.now() - startTime) / 1000;
|
|
96
|
+
const avgKiBps = Math.floor((downloaded / elapsedSec) / 1024);
|
|
97
|
+
if (downloaded > 0 && elapsedSec > 1 && avgKiBps < fetchMinSpeedKiBps) {
|
|
98
|
+
const sizeKb = Math.floor(downloaded / 1024);
|
|
99
|
+
globalWarn(`Tarball download average speed ${avgKiBps} KiB/s (size ${sizeKb} KiB) is below ${fetchMinSpeedKiBps} KiB/s: ${url} (GET)`);
|
|
100
|
+
}
|
|
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
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
assert(util.types.isNativeError(err));
|
|
110
|
+
Object.assign(err, {
|
|
111
|
+
attempts: currentAttempt,
|
|
112
|
+
resource: url,
|
|
113
|
+
});
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
return addFilesFromTarball({
|
|
117
|
+
buffer: data,
|
|
118
|
+
storeDir: opts.cafs.storeDir,
|
|
119
|
+
storeIndex: opts.storeIndex,
|
|
120
|
+
readManifest: opts.readManifest,
|
|
121
|
+
integrity: opts.integrity,
|
|
122
|
+
filesIndexFile: opts.filesIndexFile,
|
|
123
|
+
url,
|
|
124
|
+
pkg: opts.pkg,
|
|
125
|
+
appendManifest: opts.appendManifest,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=remoteTarballFetcher.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/fetching.tarball-fetcher",
|
|
3
|
+
"version": "1003.0.0",
|
|
4
|
+
"description": "Fetcher for packages hosted as tarballs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11",
|
|
8
|
+
"fetcher",
|
|
9
|
+
"tarball"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"funding": "https://opencollective.com/pnpm",
|
|
13
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/fetching/tarball-fetcher",
|
|
14
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/fetching/tarball-fetcher#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "lib/index.js",
|
|
20
|
+
"types": "lib/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./lib/index.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib",
|
|
26
|
+
"!*.map"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@zkochan/retry": "^0.2.0",
|
|
30
|
+
"lodash.throttle": "4.1.1",
|
|
31
|
+
"p-map-values": "^0.1.0",
|
|
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"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@pnpm/logger": ">=1001.0.0 <1002.0.0",
|
|
45
|
+
"@pnpm/worker": "^1000.3.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@jest/globals": "30.0.5",
|
|
49
|
+
"@pnpm/util.lex-comparator": "^3.0.2",
|
|
50
|
+
"@types/lodash.throttle": "4.1.7",
|
|
51
|
+
"@types/ramda": "0.29.12",
|
|
52
|
+
"@types/retry": "^0.12.5",
|
|
53
|
+
"@types/ssri": "^7.1.5",
|
|
54
|
+
"nock": "13.3.4",
|
|
55
|
+
"ssri": "13.0.0",
|
|
56
|
+
"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"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=22.13"
|
|
67
|
+
},
|
|
68
|
+
"jest": {
|
|
69
|
+
"preset": "@pnpm/jest-config"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
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"
|
|
76
|
+
}
|
|
77
|
+
}
|