@metamask-previews/foundryup 1.0.1-preview-8bfa290fb → 2.0.0-preview-97d6b86c0
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/CHANGELOG.md +12 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/{cli.mjs → cli.js} +2 -2
- package/dist/cli.js.map +1 -0
- package/dist/{download.d.cts → download.d.ts} +4 -9
- package/dist/download.d.ts.map +1 -0
- package/dist/{download.mjs → download.js} +5 -5
- package/dist/download.js.map +1 -0
- package/dist/{extract.d.cts → extract.d.ts} +2 -2
- package/dist/extract.d.ts.map +1 -0
- package/dist/{extract.mjs → extract.js} +15 -15
- package/dist/extract.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +4 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.mjs → index.js} +12 -12
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +71 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/{options.mjs → options.js} +6 -6
- package/dist/options.js.map +1 -0
- package/dist/{types.d.mts → types.d.ts} +4 -10
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/dist/{utils.d.cts → utils.d.ts} +3 -3
- package/dist/utils.d.ts.map +1 -0
- package/dist/{utils.mjs → utils.js} +4 -4
- package/dist/utils.js.map +1 -0
- package/package.json +11 -9
- package/dist/cli.cjs +0 -23
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -3
- package/dist/cli.d.cts.map +0 -1
- package/dist/cli.d.mts +0 -3
- package/dist/cli.d.mts.map +0 -1
- package/dist/cli.mjs.map +0 -1
- package/dist/download.cjs +0 -76
- package/dist/download.cjs.map +0 -1
- package/dist/download.d.cts.map +0 -1
- package/dist/download.d.mts +0 -30
- package/dist/download.d.mts.map +0 -1
- package/dist/download.mjs.map +0 -1
- package/dist/extract.cjs +0 -205
- package/dist/extract.cjs.map +0 -1
- package/dist/extract.d.cts.map +0 -1
- package/dist/extract.d.mts +0 -24
- package/dist/extract.d.mts.map +0 -1
- package/dist/extract.mjs.map +0 -1
- package/dist/index.cjs +0 -163
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -56
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/options.cjs +0 -157
- package/dist/options.cjs.map +0 -1
- package/dist/options.d.cts +0 -62
- package/dist/options.d.cts.map +0 -1
- package/dist/options.d.mts +0 -62
- package/dist/options.d.mts.map +0 -1
- package/dist/options.mjs.map +0 -1
- package/dist/types.cjs +0 -30
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -78
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/utils.cjs +0 -110
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts +0 -50
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs.map +0 -1
package/dist/cli.d.cts
DELETED
package/dist/cli.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.cts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.d.mts
DELETED
package/dist/cli.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.mts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,OAAO,EAAE,iCAAiC,EAAE,oBAAmB;AAE/D;;GAEG;AACH,iCAAiC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAClD;;;;OAIG;IACH,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * CLI entry point for Foundryup.\n *\n * This script downloads and installs Foundry binaries.\n * If an error occurs, it logs the error and exits with code 1.\n */\nimport { downloadAndInstallFoundryBinaries } from './index.js';\n\n/**\n * Run the main installation process and handle errors.\n */\ndownloadAndInstallFoundryBinaries().catch((error) => {\n /**\n * Log any error that occurs during installation and exit with code 1.\n *\n * @param error - The error thrown during installation.\n */\n console.error('Error:', error);\n process.exit(1);\n});\n"]}
|
package/dist/download.cjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startDownload = void 0;
|
|
4
|
-
const node_http_1 = require("node:http");
|
|
5
|
-
const node_https_1 = require("node:https");
|
|
6
|
-
const node_stream_1 = require("node:stream");
|
|
7
|
-
const promises_1 = require("node:stream/promises");
|
|
8
|
-
/**
|
|
9
|
-
* A PassThrough stream that emits a 'response' event when the HTTP(S) response is available.
|
|
10
|
-
*/
|
|
11
|
-
class DownloadStream extends node_stream_1.Stream.PassThrough {
|
|
12
|
-
/**
|
|
13
|
-
* Returns a promise that resolves with the HTTP(S) IncomingMessage response.
|
|
14
|
-
*
|
|
15
|
-
* @returns The HTTP(S) response stream.
|
|
16
|
-
*/
|
|
17
|
-
async response() {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
this.once('response', resolve);
|
|
20
|
-
this.once('error', reject);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Starts a download from the given URL.
|
|
26
|
-
*
|
|
27
|
-
* @param url - The URL to download from
|
|
28
|
-
* @param options - The download options
|
|
29
|
-
* @param redirects - The number of redirects that have occurred
|
|
30
|
-
* @returns A stream of the download
|
|
31
|
-
*/
|
|
32
|
-
function startDownload(url, options = {}, redirects = 0) {
|
|
33
|
-
const MAX_REDIRECTS = options.maxRedirects ?? 5;
|
|
34
|
-
const request = url.protocol === 'http:' ? node_http_1.request : node_https_1.request;
|
|
35
|
-
const stream = new DownloadStream();
|
|
36
|
-
request(url, options, (response) => {
|
|
37
|
-
stream.once('close', () => {
|
|
38
|
-
response.destroy();
|
|
39
|
-
});
|
|
40
|
-
const { statusCode, statusMessage, headers } = response;
|
|
41
|
-
// handle redirects
|
|
42
|
-
if (statusCode &&
|
|
43
|
-
statusCode >= 300 &&
|
|
44
|
-
statusCode < 400 &&
|
|
45
|
-
headers.location) {
|
|
46
|
-
if (redirects >= MAX_REDIRECTS) {
|
|
47
|
-
stream.emit('error', new Error('Too many redirects'));
|
|
48
|
-
response.destroy();
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// note: we don't emit a response until we're done redirecting, because
|
|
52
|
-
// handlers only expect it to be emitted once.
|
|
53
|
-
(0, promises_1.pipeline)(startDownload(new URL(headers.location, url), options, redirects + 1)
|
|
54
|
-
// emit the response event to the stream
|
|
55
|
-
.once('response', stream.emit.bind(stream, 'response')), stream).catch(stream.emit.bind(stream, 'error'));
|
|
56
|
-
response.destroy();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// check for HTTP errors
|
|
60
|
-
else if (!statusCode || statusCode < 200 || statusCode >= 300) {
|
|
61
|
-
stream.emit('error', new Error(`Request to ${url} failed. Status Code: ${statusCode} - ${statusMessage}`));
|
|
62
|
-
response.destroy();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// resolve with response stream
|
|
66
|
-
stream.emit('response', response);
|
|
67
|
-
response.once('error', stream.emit.bind(stream, 'error'));
|
|
68
|
-
(0, promises_1.pipeline)(response, stream).catch(stream.emit.bind(stream, 'error'));
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
.once('error', stream.emit.bind(stream, 'error'))
|
|
72
|
-
.end();
|
|
73
|
-
return stream;
|
|
74
|
-
}
|
|
75
|
-
exports.startDownload = startDownload;
|
|
76
|
-
//# sourceMappingURL=download.cjs.map
|
package/dist/download.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.cjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AAEnD,2CAAqD;AACrD,6CAAqC;AACrC,mDAAgD;AAIhD;;GAEG;AACH,MAAM,cAAe,SAAQ,oBAAM,CAAC,WAAW;IAC7C;;;;OAIG;IACH,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;;;;GAOG;AACH,SAAgB,aAAa,CAC3B,GAAQ,EACR,UAA2B,EAAE,EAC7B,YAAoB,CAAC;IAErB,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,mBAAW,CAAC,CAAC,CAAC,oBAAY,CAAC;IACtE,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;YACxB,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QACxD,mBAAmB;QAC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,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC,CAAC;SACC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SAChD,GAAG,EAAE,CAAC;IACT,OAAO,MAAM,CAAC;AAChB,CAAC;AAzDD,sCAyDC","sourcesContent":["import { request as httpRequest } from 'node:http';\nimport type { IncomingMessage } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { Stream } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { DownloadOptions } from './types.js';\n\n/**\n * A PassThrough stream that emits a 'response' event when the HTTP(S) response is available.\n */\nclass DownloadStream extends Stream.PassThrough {\n /**\n * Returns a promise that resolves with the HTTP(S) IncomingMessage response.\n *\n * @returns The HTTP(S) response stream.\n */\n async response(): Promise<IncomingMessage> {\n return new Promise((resolve, reject) => {\n this.once('response', resolve);\n this.once('error', reject);\n });\n }\n}\n\n/**\n * Starts a download from the given URL.\n *\n * @param url - The URL to download from\n * @param options - The download options\n * @param redirects - The number of redirects that have occurred\n * @returns A stream of the download\n */\nexport function startDownload(\n url: URL,\n options: DownloadOptions = {},\n redirects: number = 0,\n) {\n const MAX_REDIRECTS = options.maxRedirects ?? 5;\n const request = url.protocol === 'http:' ? httpRequest : httpsRequest;\n const stream = new DownloadStream();\n request(url, options, (response) => {\n stream.once('close', () => {\n response.destroy();\n });\n\n const { statusCode, statusMessage, headers } = response;\n // handle redirects\n if (\n statusCode &&\n statusCode >= 300 &&\n statusCode < 400 &&\n headers.location\n ) {\n if (redirects >= MAX_REDIRECTS) {\n stream.emit('error', new Error('Too many redirects'));\n response.destroy();\n } else {\n // note: we don't emit a response until we're done redirecting, because\n // handlers only expect it to be emitted once.\n pipeline(\n startDownload(new URL(headers.location, url), options, redirects + 1)\n // emit the response event to the stream\n .once('response', stream.emit.bind(stream, 'response')),\n stream,\n ).catch(stream.emit.bind(stream, 'error'));\n response.destroy();\n }\n }\n\n // check for HTTP errors\n else if (!statusCode || statusCode < 200 || statusCode >= 300) {\n stream.emit(\n 'error',\n new Error(\n `Request to ${url} failed. Status Code: ${statusCode} - ${statusMessage}`,\n ),\n );\n response.destroy();\n } else {\n // resolve with response stream\n stream.emit('response', response);\n\n response.once('error', stream.emit.bind(stream, 'error'));\n pipeline(response, stream).catch(stream.emit.bind(stream, 'error'));\n }\n })\n .once('error', stream.emit.bind(stream, 'error'))\n .end();\n return stream;\n}\n"]}
|
package/dist/download.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.cts","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;;;;AACA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB;AAEjD,OAAO,EAAE,MAAM,EAAE,oBAAoB;AAGrC,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAmB;AAElD;;GAEG;AACH,cAAM,cAAe,SAAQ,MAAM,CAAC,WAAW;IAC7C;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC;CAM3C;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,eAAoB,EAC7B,SAAS,GAAE,MAAU,kBAsDtB"}
|
package/dist/download.d.mts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node/http.js" />
|
|
3
|
-
/// <reference types="npm-which/node_modules/@types/node/http.js" />
|
|
4
|
-
/// <reference types="node/stream.js" />
|
|
5
|
-
/// <reference types="npm-which/node_modules/@types/node/stream.js" />
|
|
6
|
-
import type { IncomingMessage } from "node:http";
|
|
7
|
-
import { Stream } from "node:stream";
|
|
8
|
-
import type { DownloadOptions } from "./types.mjs";
|
|
9
|
-
/**
|
|
10
|
-
* A PassThrough stream that emits a 'response' event when the HTTP(S) response is available.
|
|
11
|
-
*/
|
|
12
|
-
declare class DownloadStream extends Stream.PassThrough {
|
|
13
|
-
/**
|
|
14
|
-
* Returns a promise that resolves with the HTTP(S) IncomingMessage response.
|
|
15
|
-
*
|
|
16
|
-
* @returns The HTTP(S) response stream.
|
|
17
|
-
*/
|
|
18
|
-
response(): Promise<IncomingMessage>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Starts a download from the given URL.
|
|
22
|
-
*
|
|
23
|
-
* @param url - The URL to download from
|
|
24
|
-
* @param options - The download options
|
|
25
|
-
* @param redirects - The number of redirects that have occurred
|
|
26
|
-
* @returns A stream of the download
|
|
27
|
-
*/
|
|
28
|
-
export declare function startDownload(url: URL, options?: DownloadOptions, redirects?: number): DownloadStream;
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=download.d.mts.map
|
package/dist/download.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.mts","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;;;;AACA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB;AAEjD,OAAO,EAAE,MAAM,EAAE,oBAAoB;AAGrC,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAmB;AAElD;;GAEG;AACH,cAAM,cAAe,SAAQ,MAAM,CAAC,WAAW;IAC7C;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC;CAM3C;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,eAAoB,EAC7B,SAAS,GAAE,MAAU,kBAsDtB"}
|
package/dist/download.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.mjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,W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CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SAChD,GAAG,EAAE,CAAC;IACT,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { request as httpRequest } from 'node:http';\nimport type { IncomingMessage } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { Stream } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { DownloadOptions } from './types.js';\n\n/**\n * A PassThrough stream that emits a 'response' event when the HTTP(S) response is available.\n */\nclass DownloadStream extends Stream.PassThrough {\n /**\n * Returns a promise that resolves with the HTTP(S) IncomingMessage response.\n *\n * @returns The HTTP(S) response stream.\n */\n async response(): Promise<IncomingMessage> {\n return new Promise((resolve, reject) => {\n this.once('response', resolve);\n this.once('error', reject);\n });\n }\n}\n\n/**\n * Starts a download from the given URL.\n *\n * @param url - The URL to download from\n * @param options - The download options\n * @param redirects - The number of redirects that have occurred\n * @returns A stream of the download\n */\nexport function startDownload(\n url: URL,\n options: DownloadOptions = {},\n redirects: number = 0,\n) {\n const MAX_REDIRECTS = options.maxRedirects ?? 5;\n const request = url.protocol === 'http:' ? httpRequest : httpsRequest;\n const stream = new DownloadStream();\n request(url, options, (response) => {\n stream.once('close', () => {\n response.destroy();\n });\n\n const { statusCode, statusMessage, headers } = response;\n // handle redirects\n if (\n statusCode &&\n statusCode >= 300 &&\n statusCode < 400 &&\n headers.location\n ) {\n if (redirects >= MAX_REDIRECTS) {\n stream.emit('error', new Error('Too many redirects'));\n response.destroy();\n } else {\n // note: we don't emit a response until we're done redirecting, because\n // handlers only expect it to be emitted once.\n pipeline(\n startDownload(new URL(headers.location, url), options, redirects + 1)\n // emit the response event to the stream\n .once('response', stream.emit.bind(stream, 'response')),\n stream,\n ).catch(stream.emit.bind(stream, 'error'));\n response.destroy();\n }\n }\n\n // check for HTTP errors\n else if (!statusCode || statusCode < 200 || statusCode >= 300) {\n stream.emit(\n 'error',\n new Error(\n `Request to ${url} failed. Status Code: ${statusCode} - ${statusMessage}`,\n ),\n );\n response.destroy();\n } else {\n // resolve with response stream\n stream.emit('response', response);\n\n response.once('error', stream.emit.bind(stream, 'error'));\n pipeline(response, stream).catch(stream.emit.bind(stream, 'error'));\n }\n })\n .once('error', stream.emit.bind(stream, 'error'))\n .end();\n return stream;\n}\n"]}
|
package/dist/extract.cjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractFrom = void 0;
|
|
4
|
-
const minipass_1 = require("minipass");
|
|
5
|
-
const strict_1 = require("node:assert/strict");
|
|
6
|
-
const node_crypto_1 = require("node:crypto");
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const promises_1 = require("node:fs/promises");
|
|
9
|
-
const node_http_1 = require("node:http");
|
|
10
|
-
const node_https_1 = require("node:https");
|
|
11
|
-
const node_path_1 = require("node:path");
|
|
12
|
-
const promises_2 = require("node:stream/promises");
|
|
13
|
-
const tar_1 = require("tar");
|
|
14
|
-
const unzipper_1 = require("unzipper");
|
|
15
|
-
const download_js_1 = require("./download.cjs");
|
|
16
|
-
const types_js_1 = require("./types.cjs");
|
|
17
|
-
const utils_js_1 = require("./utils.cjs");
|
|
18
|
-
/**
|
|
19
|
-
* Extracts the binaries from the given URL and writes them to the destination.
|
|
20
|
-
*
|
|
21
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
22
|
-
* @param binaries - The list of binaries to extract
|
|
23
|
-
* @param dir - The destination directory
|
|
24
|
-
* @param checksums - The checksums to verify the binaries against
|
|
25
|
-
* @returns The list of binaries extracted
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* Extracts the binaries from the given URL and writes them to the destination.
|
|
29
|
-
*
|
|
30
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
31
|
-
* @param binaries - The list of binaries to extract
|
|
32
|
-
* @param dir - The destination directory
|
|
33
|
-
* @param checksums - The checksums to verify the binaries against
|
|
34
|
-
* @returns The list of binaries extracted
|
|
35
|
-
*/
|
|
36
|
-
async function extractFrom(url, binaries, dir, checksums) {
|
|
37
|
-
const extract = url.pathname.toLowerCase().endsWith(types_js_1.Extension.Tar)
|
|
38
|
-
? extractFromTar
|
|
39
|
-
: extractFromZip;
|
|
40
|
-
// write all files to a temporary directory first, then rename to the final
|
|
41
|
-
// destination to avoid accidental partial extraction. We don't use
|
|
42
|
-
// `os.tmpdir` for this because `rename` will fail if the directories are on
|
|
43
|
-
// different file systems.
|
|
44
|
-
const tempDir = `${dir}.downloading`;
|
|
45
|
-
const rmOpts = { recursive: true, maxRetries: 3, force: true };
|
|
46
|
-
try {
|
|
47
|
-
// clean up any previous in-progress downloads
|
|
48
|
-
await (0, promises_1.rm)(tempDir, rmOpts);
|
|
49
|
-
// make the temporary directory to extract the binaries to
|
|
50
|
-
await (0, promises_1.mkdir)(tempDir, { recursive: true });
|
|
51
|
-
const downloads = await extract(url, binaries, tempDir, checksums?.algorithm);
|
|
52
|
-
(0, strict_1.ok)(downloads.length === binaries.length, 'Failed to extract all binaries');
|
|
53
|
-
const paths = [];
|
|
54
|
-
for (const { path, binary, checksum } of downloads) {
|
|
55
|
-
if (checksums) {
|
|
56
|
-
(0, utils_js_1.say)(`verifying checksum for ${binary}`);
|
|
57
|
-
const expected = checksums.binaries[binary];
|
|
58
|
-
if (checksum === expected) {
|
|
59
|
-
(0, utils_js_1.say)(`checksum verified for ${binary}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw new Error(`checksum mismatch for ${binary}, expected ${expected}, got ${checksum}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// add the *final* path to the list of binaries
|
|
66
|
-
paths.push((0, node_path_1.join)(dir, (0, node_path_1.relative)(tempDir, path)));
|
|
67
|
-
}
|
|
68
|
-
// this directory shouldn't exist, but if two simultaneous `yarn foundryup`
|
|
69
|
-
// processes are running, it might. Last process wins, so we remove other
|
|
70
|
-
// `dir`s just in case.
|
|
71
|
-
await (0, promises_1.rm)(dir, rmOpts);
|
|
72
|
-
// everything has been extracted; move the files to their final destination
|
|
73
|
-
await (0, promises_1.rename)(tempDir, dir);
|
|
74
|
-
// return the list of extracted binaries
|
|
75
|
-
return paths;
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
// if things fail for any reason try to clean up a bit. it is very important
|
|
79
|
-
// to not leave `dir` behind, as its existence is a signal that the binaries
|
|
80
|
-
// are installed.
|
|
81
|
-
const rmErrors = (await Promise.allSettled([(0, promises_1.rm)(tempDir, rmOpts), (0, promises_1.rm)(dir, rmOpts)]))
|
|
82
|
-
.filter((r) => r.status === 'rejected')
|
|
83
|
-
.map((r) => r.reason);
|
|
84
|
-
// if we failed to clean up, create an aggregate error message
|
|
85
|
-
if (rmErrors.length) {
|
|
86
|
-
throw new AggregateError([error, ...rmErrors], 'This is a bug; you should report it.');
|
|
87
|
-
}
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.extractFrom = extractFrom;
|
|
92
|
-
/**
|
|
93
|
-
* Extracts the binaries from a tar archive.
|
|
94
|
-
*
|
|
95
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
96
|
-
* @param binaries - The list of binaries to extract
|
|
97
|
-
* @param dir - The destination directory
|
|
98
|
-
* @param checksumAlgorithm - The checksum algorithm to use
|
|
99
|
-
* @returns The list of binaries extracted
|
|
100
|
-
*/
|
|
101
|
-
/**
|
|
102
|
-
* Extracts the binaries from a tar archive.
|
|
103
|
-
*
|
|
104
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
105
|
-
* @param binaries - The list of binaries to extract
|
|
106
|
-
* @param dir - The destination directory
|
|
107
|
-
* @param checksumAlgorithm - The checksum algorithm to use
|
|
108
|
-
* @returns The list of binaries extracted
|
|
109
|
-
*/
|
|
110
|
-
async function extractFromTar(url, binaries, dir, checksumAlgorithm) {
|
|
111
|
-
const downloads = [];
|
|
112
|
-
await (0, promises_2.pipeline)((0, download_js_1.startDownload)(url), (0, tar_1.extract)({
|
|
113
|
-
cwd: dir,
|
|
114
|
-
// @ts-expect-error: Types here broke in `tar@7.5.12`, but it appears to
|
|
115
|
-
// work fine as-is.
|
|
116
|
-
// See: https://github.com/isaacs/node-tar/issues/459
|
|
117
|
-
transform: (entry) => {
|
|
118
|
-
const absolutePath = entry.absolute;
|
|
119
|
-
if (!absolutePath) {
|
|
120
|
-
throw new Error('Missing absolute path for entry');
|
|
121
|
-
}
|
|
122
|
-
if (checksumAlgorithm) {
|
|
123
|
-
const hash = (0, node_crypto_1.createHash)(checksumAlgorithm);
|
|
124
|
-
const passThrough = new minipass_1.Minipass({ async: true });
|
|
125
|
-
passThrough.pipe(hash);
|
|
126
|
-
passThrough.on('end', () => {
|
|
127
|
-
downloads.push({
|
|
128
|
-
path: absolutePath,
|
|
129
|
-
binary: entry.path,
|
|
130
|
-
checksum: hash.digest('hex'),
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
return passThrough;
|
|
134
|
-
}
|
|
135
|
-
// When no checksum is needed, record the entry and return undefined
|
|
136
|
-
// to use the original stream without transformation
|
|
137
|
-
downloads.push({
|
|
138
|
-
path: absolutePath,
|
|
139
|
-
binary: entry.path,
|
|
140
|
-
});
|
|
141
|
-
return undefined;
|
|
142
|
-
},
|
|
143
|
-
}, binaries));
|
|
144
|
-
return downloads;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Extracts the binaries from a zip archive.
|
|
148
|
-
*
|
|
149
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
150
|
-
* @param binaries - The list of binaries to extract
|
|
151
|
-
* @param dir - The destination directory
|
|
152
|
-
* @param checksumAlgorithm - The checksum algorithm to use
|
|
153
|
-
* @returns The list of binaries extracted
|
|
154
|
-
*/
|
|
155
|
-
async function extractFromZip(url, binaries, dir, checksumAlgorithm) {
|
|
156
|
-
const agent = new (url.protocol === 'http:' ? node_http_1.Agent : node_https_1.Agent)({
|
|
157
|
-
keepAlive: true,
|
|
158
|
-
});
|
|
159
|
-
const source = {
|
|
160
|
-
async size() {
|
|
161
|
-
const download = (0, download_js_1.startDownload)(url, { agent, method: 'HEAD' });
|
|
162
|
-
const response = await download.response();
|
|
163
|
-
const contentLength = response.headers['content-length'];
|
|
164
|
-
return contentLength ? parseInt(contentLength, 10) : 0;
|
|
165
|
-
},
|
|
166
|
-
stream(offset, bytes) {
|
|
167
|
-
const options = {
|
|
168
|
-
agent,
|
|
169
|
-
headers: {
|
|
170
|
-
range: `bytes=${offset}-${bytes ? offset + bytes : ''}`,
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
return (0, download_js_1.startDownload)(url, options);
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
const { files } = await unzipper_1.Open.custom(source, {});
|
|
177
|
-
const filtered = files.filter(({ path }) => binaries.includes((0, node_path_1.basename)(path, (0, node_path_1.extname)(path))));
|
|
178
|
-
return await Promise.all(filtered.map(async ({ path, stream }) => {
|
|
179
|
-
const dest = (0, node_path_1.join)(dir, path);
|
|
180
|
-
const entry = stream();
|
|
181
|
-
const destStream = (0, node_fs_1.createWriteStream)(dest);
|
|
182
|
-
const binary = (0, node_path_1.basename)(path, (0, node_path_1.extname)(path));
|
|
183
|
-
if (checksumAlgorithm) {
|
|
184
|
-
const hash = (0, node_crypto_1.createHash)(checksumAlgorithm);
|
|
185
|
-
const hashStream = async function* (entryStream) {
|
|
186
|
-
for await (const chunk of entryStream) {
|
|
187
|
-
hash.update(chunk);
|
|
188
|
-
yield chunk;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
await (0, promises_2.pipeline)(entry, hashStream, destStream);
|
|
192
|
-
return {
|
|
193
|
-
path: dest,
|
|
194
|
-
binary,
|
|
195
|
-
checksum: hash.digest('hex'),
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
await (0, promises_2.pipeline)(entry, destStream);
|
|
199
|
-
return {
|
|
200
|
-
path: dest,
|
|
201
|
-
binary,
|
|
202
|
-
};
|
|
203
|
-
}));
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=extract.cjs.map
|
package/dist/extract.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.cjs","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,+CAAwC;AACxC,6CAAyC;AACzC,qCAA4C;AAC5C,+CAAqD;AACrD,yCAA+C;AAC/C,2CAAiD;AACjD,yCAA8D;AAC9D,mDAAgD;AAChD,6BAA4C;AAC5C,uCAAgC;AAGhC,gDAA8C;AAC9C,0CAAuC;AAEvC,0CAAiC;AAEjC;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACI,KAAK,UAAU,WAAW,CAC/B,GAAQ,EACR,QAAkB,EAClB,GAAW,EACX,SAAyE;IAEzE,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,oBAAS,CAAC,GAAG,CAAC;QAChE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,cAAc,CAAC;IACnB,2EAA2E;IAC3E,mEAAmE;IACnE,4EAA4E;IAC5E,0BAA0B;IAC1B,MAAM,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC;IACrC,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,CAAC;QACH,8CAA8C;QAC9C,MAAM,IAAA,aAAE,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,0DAA0D;QAC1D,MAAM,IAAA,gBAAK,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,MAAM,OAAO,CAC7B,GAAG,EACH,QAAQ,EACR,OAAO,EACP,SAAS,EAAE,SAAS,CACrB,C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AAE,UAAU,EAAE,UAAU,CAAC,CAAC;YAC9C,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,MAAM;gBACN,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;aAC7B,CAAC;QACJ,CAAC;QACD,MAAM,IAAA,mBAAQ,EAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,IAAI;YACV,MAAM;SACP,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { Minipass } from 'minipass';\nimport { ok } from 'node:assert/strict';\nimport { createHash } from 'node:crypto';\nimport { createWriteStream } from 'node:fs';\nimport { rename, mkdir, rm } from 'node:fs/promises';\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { join, basename, extname, relative } from 'node:path';\nimport { pipeline } from 'node:stream/promises';\nimport { extract as extractTar } from 'tar';\nimport { Open } from 'unzipper';\nimport type { Source, Entry } from 'unzipper';\n\nimport { startDownload } from './download.js';\nimport { Extension } from './types.js';\nimport type { Binary } from './types.js';\nimport { say } from './utils.js';\n\n/**\n * Extracts the binaries from the given URL and writes them to the destination.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksums - The checksums to verify the binaries against\n * @returns The list of binaries extracted\n */\n\n/**\n * Extracts the binaries from the given URL and writes them to the destination.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksums - The checksums to verify the binaries against\n * @returns The list of binaries extracted\n */\nexport async function extractFrom(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksums: { algorithm: string; binaries: Record<Binary, string> } | null,\n) {\n const extract = url.pathname.toLowerCase().endsWith(Extension.Tar)\n ? extractFromTar\n : extractFromZip;\n // write all files to a temporary directory first, then rename to the final\n // destination to avoid accidental partial extraction. We don't use\n // `os.tmpdir` for this because `rename` will fail if the directories are on\n // different file systems.\n const tempDir = `${dir}.downloading`;\n const rmOpts = { recursive: true, maxRetries: 3, force: true };\n try {\n // clean up any previous in-progress downloads\n await rm(tempDir, rmOpts);\n // make the temporary directory to extract the binaries to\n await mkdir(tempDir, { recursive: true });\n const downloads = await extract(\n url,\n binaries,\n tempDir,\n checksums?.algorithm,\n );\n ok(downloads.length === binaries.length, 'Failed to extract all binaries');\n\n const paths: string[] = [];\n for (const { path, binary, checksum } of downloads) {\n if (checksums) {\n say(`verifying checksum for ${binary}`);\n const expected = checksums.binaries[binary];\n if (checksum === expected) {\n say(`checksum verified for ${binary}`);\n } else {\n throw new Error(\n `checksum mismatch for ${binary}, expected ${expected}, got ${checksum}`,\n );\n }\n }\n // add the *final* path to the list of binaries\n paths.push(join(dir, relative(tempDir, path)));\n }\n\n // this directory shouldn't exist, but if two simultaneous `yarn foundryup`\n // processes are running, it might. Last process wins, so we remove other\n // `dir`s just in case.\n await rm(dir, rmOpts);\n // everything has been extracted; move the files to their final destination\n await rename(tempDir, dir);\n // return the list of extracted binaries\n return paths;\n } catch (error) {\n // if things fail for any reason try to clean up a bit. it is very important\n // to not leave `dir` behind, as its existence is a signal that the binaries\n // are installed.\n const rmErrors = (\n await Promise.allSettled([rm(tempDir, rmOpts), rm(dir, rmOpts)])\n )\n .filter((r) => r.status === 'rejected')\n .map((r) => (r as PromiseRejectedResult).reason);\n\n // if we failed to clean up, create an aggregate error message\n if (rmErrors.length) {\n throw new AggregateError(\n [error, ...rmErrors],\n 'This is a bug; you should report it.',\n );\n }\n throw error;\n }\n}\n/**\n * Extracts the binaries from a tar archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\n\n/**\n * Extracts the binaries from a tar archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\nasync function extractFromTar(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksumAlgorithm?: string,\n) {\n const downloads: {\n path: string;\n binary: Binary;\n checksum?: string;\n }[] = [];\n await pipeline(\n startDownload(url),\n extractTar(\n {\n cwd: dir,\n // @ts-expect-error: Types here broke in `tar@7.5.12`, but it appears to\n // work fine as-is.\n // See: https://github.com/isaacs/node-tar/issues/459\n transform: (entry) => {\n const absolutePath = entry.absolute;\n if (!absolutePath) {\n throw new Error('Missing absolute path for entry');\n }\n\n if (checksumAlgorithm) {\n const hash = createHash(checksumAlgorithm);\n const passThrough = new Minipass({ async: true });\n passThrough.pipe(hash);\n passThrough.on('end', () => {\n downloads.push({\n path: absolutePath,\n binary: entry.path as Binary,\n checksum: hash.digest('hex'),\n });\n });\n return passThrough;\n }\n\n // When no checksum is needed, record the entry and return undefined\n // to use the original stream without transformation\n downloads.push({\n path: absolutePath,\n binary: entry.path as Binary,\n });\n return undefined;\n },\n },\n binaries,\n ),\n );\n return downloads;\n}\n/**\n * Extracts the binaries from a zip archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\nasync function extractFromZip(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksumAlgorithm?: string,\n) {\n const agent = new (url.protocol === 'http:' ? HttpAgent : HttpsAgent)({\n keepAlive: true,\n });\n const source: Source = {\n async size() {\n const download = startDownload(url, { agent, method: 'HEAD' });\n const response = await download.response();\n const contentLength = response.headers['content-length'];\n return contentLength ? parseInt(contentLength, 10) : 0;\n },\n stream(offset: number, bytes: number) {\n const options = {\n agent,\n headers: {\n range: `bytes=${offset}-${bytes ? offset + bytes : ''}`,\n },\n };\n return startDownload(url, options);\n },\n };\n\n const { files } = await Open.custom(source, {});\n const filtered = files.filter(({ path }) =>\n binaries.includes(basename(path, extname(path)) as Binary),\n );\n return await Promise.all(\n filtered.map(async ({ path, stream }) => {\n const dest = join(dir, path);\n const entry = stream();\n const destStream = createWriteStream(dest);\n const binary = basename(path, extname(path)) as Binary;\n if (checksumAlgorithm) {\n const hash = createHash(checksumAlgorithm);\n const hashStream = async function* (entryStream: Entry) {\n for await (const chunk of entryStream) {\n hash.update(chunk);\n yield chunk;\n }\n };\n await pipeline(entry, hashStream, destStream);\n return {\n path: dest,\n binary,\n checksum: hash.digest('hex'),\n };\n }\n await pipeline(entry, destStream);\n return {\n path: dest,\n binary,\n };\n }),\n );\n}\n"]}
|
package/dist/extract.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.cts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAmB;AAGzC;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,IAAI,qBAoE1E"}
|
package/dist/extract.d.mts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Binary } from "./types.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* Extracts the binaries from the given URL and writes them to the destination.
|
|
4
|
-
*
|
|
5
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
6
|
-
* @param binaries - The list of binaries to extract
|
|
7
|
-
* @param dir - The destination directory
|
|
8
|
-
* @param checksums - The checksums to verify the binaries against
|
|
9
|
-
* @returns The list of binaries extracted
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Extracts the binaries from the given URL and writes them to the destination.
|
|
13
|
-
*
|
|
14
|
-
* @param url - The URL of the archive to extract the binaries from
|
|
15
|
-
* @param binaries - The list of binaries to extract
|
|
16
|
-
* @param dir - The destination directory
|
|
17
|
-
* @param checksums - The checksums to verify the binaries against
|
|
18
|
-
* @returns The list of binaries extracted
|
|
19
|
-
*/
|
|
20
|
-
export declare function extractFrom(url: URL, binaries: Binary[], dir: string, checksums: {
|
|
21
|
-
algorithm: string;
|
|
22
|
-
binaries: Record<Binary, string>;
|
|
23
|
-
} | null): Promise<string[]>;
|
|
24
|
-
//# sourceMappingURL=extract.d.mts.map
|
package/dist/extract.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.mts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAmB;AAGzC;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,IAAI,qBAoE1E"}
|
package/dist/extract.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.mjs","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB;AACpC,OAAO,EAAE,EAAE,EAAE,2BAA2B;AACxC,OAAO,EAAE,UAAU,EAAE,oBAAoB;AACzC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB;AAC5C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,yBAAyB;AACrD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,kBAAkB;AAC/C,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,mBAAmB;AACjD,OAAO,EA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AACJ,CAAC","sourcesContent":["import { Minipass } from 'minipass';\nimport { ok } from 'node:assert/strict';\nimport { createHash } from 'node:crypto';\nimport { createWriteStream } from 'node:fs';\nimport { rename, mkdir, rm } from 'node:fs/promises';\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { join, basename, extname, relative } from 'node:path';\nimport { pipeline } from 'node:stream/promises';\nimport { extract as extractTar } from 'tar';\nimport { Open } from 'unzipper';\nimport type { Source, Entry } from 'unzipper';\n\nimport { startDownload } from './download.js';\nimport { Extension } from './types.js';\nimport type { Binary } from './types.js';\nimport { say } from './utils.js';\n\n/**\n * Extracts the binaries from the given URL and writes them to the destination.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksums - The checksums to verify the binaries against\n * @returns The list of binaries extracted\n */\n\n/**\n * Extracts the binaries from the given URL and writes them to the destination.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksums - The checksums to verify the binaries against\n * @returns The list of binaries extracted\n */\nexport async function extractFrom(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksums: { algorithm: string; binaries: Record<Binary, string> } | null,\n) {\n const extract = url.pathname.toLowerCase().endsWith(Extension.Tar)\n ? extractFromTar\n : extractFromZip;\n // write all files to a temporary directory first, then rename to the final\n // destination to avoid accidental partial extraction. We don't use\n // `os.tmpdir` for this because `rename` will fail if the directories are on\n // different file systems.\n const tempDir = `${dir}.downloading`;\n const rmOpts = { recursive: true, maxRetries: 3, force: true };\n try {\n // clean up any previous in-progress downloads\n await rm(tempDir, rmOpts);\n // make the temporary directory to extract the binaries to\n await mkdir(tempDir, { recursive: true });\n const downloads = await extract(\n url,\n binaries,\n tempDir,\n checksums?.algorithm,\n );\n ok(downloads.length === binaries.length, 'Failed to extract all binaries');\n\n const paths: string[] = [];\n for (const { path, binary, checksum } of downloads) {\n if (checksums) {\n say(`verifying checksum for ${binary}`);\n const expected = checksums.binaries[binary];\n if (checksum === expected) {\n say(`checksum verified for ${binary}`);\n } else {\n throw new Error(\n `checksum mismatch for ${binary}, expected ${expected}, got ${checksum}`,\n );\n }\n }\n // add the *final* path to the list of binaries\n paths.push(join(dir, relative(tempDir, path)));\n }\n\n // this directory shouldn't exist, but if two simultaneous `yarn foundryup`\n // processes are running, it might. Last process wins, so we remove other\n // `dir`s just in case.\n await rm(dir, rmOpts);\n // everything has been extracted; move the files to their final destination\n await rename(tempDir, dir);\n // return the list of extracted binaries\n return paths;\n } catch (error) {\n // if things fail for any reason try to clean up a bit. it is very important\n // to not leave `dir` behind, as its existence is a signal that the binaries\n // are installed.\n const rmErrors = (\n await Promise.allSettled([rm(tempDir, rmOpts), rm(dir, rmOpts)])\n )\n .filter((r) => r.status === 'rejected')\n .map((r) => (r as PromiseRejectedResult).reason);\n\n // if we failed to clean up, create an aggregate error message\n if (rmErrors.length) {\n throw new AggregateError(\n [error, ...rmErrors],\n 'This is a bug; you should report it.',\n );\n }\n throw error;\n }\n}\n/**\n * Extracts the binaries from a tar archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\n\n/**\n * Extracts the binaries from a tar archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\nasync function extractFromTar(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksumAlgorithm?: string,\n) {\n const downloads: {\n path: string;\n binary: Binary;\n checksum?: string;\n }[] = [];\n await pipeline(\n startDownload(url),\n extractTar(\n {\n cwd: dir,\n // @ts-expect-error: Types here broke in `tar@7.5.12`, but it appears to\n // work fine as-is.\n // See: https://github.com/isaacs/node-tar/issues/459\n transform: (entry) => {\n const absolutePath = entry.absolute;\n if (!absolutePath) {\n throw new Error('Missing absolute path for entry');\n }\n\n if (checksumAlgorithm) {\n const hash = createHash(checksumAlgorithm);\n const passThrough = new Minipass({ async: true });\n passThrough.pipe(hash);\n passThrough.on('end', () => {\n downloads.push({\n path: absolutePath,\n binary: entry.path as Binary,\n checksum: hash.digest('hex'),\n });\n });\n return passThrough;\n }\n\n // When no checksum is needed, record the entry and return undefined\n // to use the original stream without transformation\n downloads.push({\n path: absolutePath,\n binary: entry.path as Binary,\n });\n return undefined;\n },\n },\n binaries,\n ),\n );\n return downloads;\n}\n/**\n * Extracts the binaries from a zip archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\nasync function extractFromZip(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksumAlgorithm?: string,\n) {\n const agent = new (url.protocol === 'http:' ? HttpAgent : HttpsAgent)({\n keepAlive: true,\n });\n const source: Source = {\n async size() {\n const download = startDownload(url, { agent, method: 'HEAD' });\n const response = await download.response();\n const contentLength = response.headers['content-length'];\n return contentLength ? parseInt(contentLength, 10) : 0;\n },\n stream(offset: number, bytes: number) {\n const options = {\n agent,\n headers: {\n range: `bytes=${offset}-${bytes ? offset + bytes : ''}`,\n },\n };\n return startDownload(url, options);\n },\n };\n\n const { files } = await Open.custom(source, {});\n const filtered = files.filter(({ path }) =>\n binaries.includes(basename(path, extname(path)) as Binary),\n );\n return await Promise.all(\n filtered.map(async ({ path, stream }) => {\n const dest = join(dir, path);\n const entry = stream();\n const destStream = createWriteStream(dest);\n const binary = basename(path, extname(path)) as Binary;\n if (checksumAlgorithm) {\n const hash = createHash(checksumAlgorithm);\n const hashStream = async function* (entryStream: Entry) {\n for await (const chunk of entryStream) {\n hash.update(chunk);\n yield chunk;\n }\n };\n await pipeline(entry, hashStream, destStream);\n return {\n path: dest,\n binary,\n checksum: hash.digest('hex'),\n };\n }\n await pipeline(entry, destStream);\n return {\n path: dest,\n binary,\n };\n }),\n );\n}\n"]}
|
package/dist/index.cjs
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.downloadAndInstallFoundryBinaries = exports.installBinaries = exports.checkAndDownloadBinaries = exports.getBinaryArchiveUrl = exports.getCacheDirectory = void 0;
|
|
5
|
-
const node_crypto_1 = require("node:crypto");
|
|
6
|
-
const node_fs_1 = require("node:fs");
|
|
7
|
-
const promises_1 = require("node:fs/promises");
|
|
8
|
-
const node_os_1 = require("node:os");
|
|
9
|
-
const node_path_1 = require("node:path");
|
|
10
|
-
const node_process_1 = require("node:process");
|
|
11
|
-
const yaml_1 = require("yaml");
|
|
12
|
-
const extract_js_1 = require("./extract.cjs");
|
|
13
|
-
const options_js_1 = require("./options.cjs");
|
|
14
|
-
const types_js_1 = require("./types.cjs");
|
|
15
|
-
const utils_js_1 = require("./utils.cjs");
|
|
16
|
-
/**
|
|
17
|
-
* Determines the cache directory based on the .yarnrc.yml configuration.
|
|
18
|
-
* If global cache is enabled, returns a path in the user's home directory.
|
|
19
|
-
* Otherwise, returns a local cache path in the current working directory.
|
|
20
|
-
*
|
|
21
|
-
* @returns The path to the cache directory
|
|
22
|
-
*/
|
|
23
|
-
function getCacheDirectory() {
|
|
24
|
-
let enableGlobalCache = false;
|
|
25
|
-
try {
|
|
26
|
-
const configFileContent = (0, node_fs_1.readFileSync)('.yarnrc.yml', 'utf8');
|
|
27
|
-
const parsedConfig = (0, yaml_1.parse)(configFileContent);
|
|
28
|
-
enableGlobalCache = parsedConfig?.enableGlobalCache ?? false;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
// If file doesn't exist or can't be read, default to local cache
|
|
32
|
-
if (error.code === 'ENOENT') {
|
|
33
|
-
return (0, node_path_1.join)((0, node_process_1.cwd)(), '.metamask', 'cache');
|
|
34
|
-
}
|
|
35
|
-
// For other errors, log but continue with default
|
|
36
|
-
console.warn('Warning: Error reading .yarnrc.yml, using local cache:', error);
|
|
37
|
-
}
|
|
38
|
-
return enableGlobalCache
|
|
39
|
-
? (0, node_path_1.join)((0, node_os_1.homedir)(), '.cache', 'metamask')
|
|
40
|
-
: (0, node_path_1.join)((0, node_process_1.cwd)(), '.metamask', 'cache');
|
|
41
|
-
}
|
|
42
|
-
exports.getCacheDirectory = getCacheDirectory;
|
|
43
|
-
/**
|
|
44
|
-
* Generates the URL for downloading the Foundry binary archive.
|
|
45
|
-
*
|
|
46
|
-
* @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')
|
|
47
|
-
* @param tag - The release tag (e.g., 'v1.0.0')
|
|
48
|
-
* @param version - The version string
|
|
49
|
-
* @param platform - The target platform (e.g., Platform.Linux)
|
|
50
|
-
* @param arch - The target architecture (e.g., 'amd64')
|
|
51
|
-
* @returns The URL for the binary archive
|
|
52
|
-
*/
|
|
53
|
-
function getBinaryArchiveUrl(repo, tag, version, platform, arch) {
|
|
54
|
-
const ext = platform === types_js_1.Platform.Windows ? types_js_1.Extension.Zip : types_js_1.Extension.Tar;
|
|
55
|
-
return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;
|
|
56
|
-
}
|
|
57
|
-
exports.getBinaryArchiveUrl = getBinaryArchiveUrl;
|
|
58
|
-
/**
|
|
59
|
-
* Checks if binaries are already in the cache. If not, downloads and extracts them.
|
|
60
|
-
*
|
|
61
|
-
* @param url - The URL to download the binaries from
|
|
62
|
-
* @param binaries - The list of binaries to download
|
|
63
|
-
* @param cachePath - The path to the cache directory
|
|
64
|
-
* @param platform - The target platform
|
|
65
|
-
* @param arch - The target architecture
|
|
66
|
-
* @param checksums - Optional checksums for verification
|
|
67
|
-
* @returns A promise that resolves to the directory containing the downloaded binaries
|
|
68
|
-
*/
|
|
69
|
-
async function checkAndDownloadBinaries(url, binaries, cachePath, platform, arch, checksums) {
|
|
70
|
-
let downloadedBinaries;
|
|
71
|
-
try {
|
|
72
|
-
(0, utils_js_1.say)(`checking cache`);
|
|
73
|
-
downloadedBinaries = await (0, promises_1.opendir)(cachePath);
|
|
74
|
-
(0, utils_js_1.say)(`found binaries in cache`);
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
(0, utils_js_1.say)(`binaries not in cache`);
|
|
78
|
-
if (e.code === 'ENOENT') {
|
|
79
|
-
(0, utils_js_1.say)(`installing from ${url.toString()}`);
|
|
80
|
-
// directory doesn't exist, download and extract
|
|
81
|
-
const platformChecksums = (0, utils_js_1.transformChecksums)(checksums, platform, arch);
|
|
82
|
-
await (0, extract_js_1.extractFrom)(url, binaries, cachePath, platformChecksums);
|
|
83
|
-
downloadedBinaries = await (0, promises_1.opendir)(cachePath);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
throw e;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return downloadedBinaries;
|
|
90
|
-
}
|
|
91
|
-
exports.checkAndDownloadBinaries = checkAndDownloadBinaries;
|
|
92
|
-
/**
|
|
93
|
-
* Installs the downloaded binaries by creating symlinks or copying files.
|
|
94
|
-
*
|
|
95
|
-
* @param downloadedBinaries - The directory containing the downloaded binaries
|
|
96
|
-
* @param BIN_DIR - The target directory for installation
|
|
97
|
-
* @param cachePath - The path to the cache directory
|
|
98
|
-
* @returns A promise that resolves when installation is complete
|
|
99
|
-
*/
|
|
100
|
-
async function installBinaries(downloadedBinaries, BIN_DIR, cachePath) {
|
|
101
|
-
for await (const file of downloadedBinaries) {
|
|
102
|
-
if (!file.isFile()) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
const target = (0, node_path_1.join)(file.parentPath, file.name);
|
|
106
|
-
const path = (0, node_path_1.join)(BIN_DIR, (0, node_path_1.relative)(cachePath, target));
|
|
107
|
-
// compute the relative path from where the symlink will be created
|
|
108
|
-
// to the target file, so that it works even if the project is moved
|
|
109
|
-
// (like in some CI environments)
|
|
110
|
-
const relativeTarget = (0, node_path_1.relative)((0, node_path_1.dirname)(path), target);
|
|
111
|
-
// create the BIN_DIR paths if they don't exists already
|
|
112
|
-
await (0, promises_1.mkdir)(BIN_DIR, { recursive: true });
|
|
113
|
-
// clean up any existing files or symlinks
|
|
114
|
-
await (0, promises_1.unlink)(path).catch(utils_js_1.noop);
|
|
115
|
-
try {
|
|
116
|
-
// create new symlink
|
|
117
|
-
await (0, promises_1.symlink)(relativeTarget, path);
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
if (!((0, utils_js_1.isCodedError)(e) && ['EPERM', 'EXDEV'].includes(e.code))) {
|
|
121
|
-
throw e;
|
|
122
|
-
}
|
|
123
|
-
// symlinking can fail if it's a cross-device/filesystem link, or for
|
|
124
|
-
// permissions reasons, so we'll just copy the file instead
|
|
125
|
-
await (0, promises_1.copyFile)(target, path);
|
|
126
|
-
}
|
|
127
|
-
// check that it works by logging the version
|
|
128
|
-
(0, utils_js_1.say)(`installed - ${(0, utils_js_1.getVersion)(path).toString()}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.installBinaries = installBinaries;
|
|
132
|
-
/**
|
|
133
|
-
* Downloads and installs Foundry binaries based on command-line arguments.
|
|
134
|
-
* If the command is 'cache clean', it removes the cache directory.
|
|
135
|
-
* Otherwise, it downloads and installs the specified binaries.
|
|
136
|
-
*
|
|
137
|
-
* @returns A promise that resolves when the operation is complete
|
|
138
|
-
*/
|
|
139
|
-
async function downloadAndInstallFoundryBinaries() {
|
|
140
|
-
const parsedArgs = (0, options_js_1.parseArgs)();
|
|
141
|
-
const CACHE_DIR = getCacheDirectory();
|
|
142
|
-
if (parsedArgs.command === 'cache clean') {
|
|
143
|
-
await (0, promises_1.rm)(CACHE_DIR, { recursive: true, force: true });
|
|
144
|
-
(0, utils_js_1.say)('done!');
|
|
145
|
-
(0, node_process_1.exit)(0);
|
|
146
|
-
}
|
|
147
|
-
const { repo, version: { version, tag }, arch, platform, binaries, checksums, } = parsedArgs.options;
|
|
148
|
-
(0, options_js_1.printBanner)();
|
|
149
|
-
const bins = binaries.join(', ');
|
|
150
|
-
(0, utils_js_1.say)(`fetching ${bins} ${version} for ${platform} ${arch}`);
|
|
151
|
-
const BIN_ARCHIVE_URL = getBinaryArchiveUrl(repo, tag, version, platform, arch);
|
|
152
|
-
const BIN_DIR = (0, node_path_1.join)((0, node_process_1.cwd)(), 'node_modules', '.bin');
|
|
153
|
-
const url = new URL(BIN_ARCHIVE_URL);
|
|
154
|
-
const cacheKey = (0, node_crypto_1.createHash)('sha256')
|
|
155
|
-
.update(`${BIN_ARCHIVE_URL}-${bins}`)
|
|
156
|
-
.digest('hex');
|
|
157
|
-
const cachePath = (0, node_path_1.join)(CACHE_DIR, cacheKey);
|
|
158
|
-
const downloadedBinaries = await checkAndDownloadBinaries(url, binaries, cachePath, platform, arch, checksums);
|
|
159
|
-
await installBinaries(downloadedBinaries, BIN_DIR, cachePath);
|
|
160
|
-
(0, utils_js_1.say)('done!');
|
|
161
|
-
}
|
|
162
|
-
exports.downloadAndInstallFoundryBinaries = downloadAndInstallFoundryBinaries;
|
|
163
|
-
//# sourceMappingURL=index.cjs.map
|