@metamask-previews/foundryup 1.0.1-preview-0dfe3b334 → 1.0.1-preview-a3e31582e

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/dist/cli.cjs CHANGED
@@ -7,11 +7,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  * This script downloads and installs Foundry binaries.
8
8
  * If an error occurs, it logs the error and exits with code 1.
9
9
  */
10
- const _1 = require("./index.cjs");
10
+ const index_js_1 = require("./index.cjs");
11
11
  /**
12
12
  * Run the main installation process and handle errors.
13
13
  */
14
- (0, _1.downloadAndInstallFoundryBinaries)().catch((error) => {
14
+ (0, index_js_1.downloadAndInstallFoundryBinaries)().catch((error) => {
15
15
  /**
16
16
  * Log any error that occurs during installation and exit with code 1.
17
17
  *
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,kCAAsD;AAEtD;;GAEG;AACH,IAAA,oCAAiC,GAAE,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 '.';\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"]}
1
+ {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,0CAA+D;AAE/D;;GAEG;AACH,IAAA,4CAAiC,GAAE,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/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,OAAO,EAAE,iCAAiC,EAAE,oBAAU;AAEtD;;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 '.';\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"]}
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"]}
@@ -1 +1 @@
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,O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AI,CAAC,UAAU,IAAI,UAAU,GAAG,GAAG,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CACT,OAAO,EACP,IAAI,KAAK,CACP,cAAc,GAAG,yBAAyB,UAAU,MAAM,aAAa,EAAE,CAC1E,CACF,CAAC;YACF,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,+BAA+B;YAC/B,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAElC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YAC1D,IAAA,mBAAQ,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';\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"]}
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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,CAAC,CAAC,EACzD,MAAM,CACP,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC3C,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;QAED,wBAAwB;aACnB,IAAI,CAAC,UAAU,IAAI,UAAU,GAAG,GAAG,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CACT,OAAO,EACP,IAAI,KAAK,CACP,cAAc,GAAG,yBAAyB,UAAU,MAAM,aAAa,EAAE,CAC1E,CACF,CAAC;YACF,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,+BAA+B;YAC/B,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAElC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YAC1D,IAAA,mBAAQ,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"]}
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node/http" />
3
- /// <reference types="npm-which/node_modules/@types/node/http" />
4
- /// <reference types="node/stream" />
5
- /// <reference types="npm-which/node_modules/@types/node/stream" />
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
6
  import type { IncomingMessage } from "node:http";
7
7
  import { Stream } from "node:stream";
8
8
  import type { DownloadOptions } from "./types.cjs";
@@ -1 +1 @@
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,oBAAgB;AAE/C;;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"}
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"}
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node/http" />
3
- /// <reference types="npm-which/node_modules/@types/node/http" />
4
- /// <reference types="node/stream" />
5
- /// <reference types="npm-which/node_modules/@types/node/stream" />
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
6
  import type { IncomingMessage } from "node:http";
7
7
  import { Stream } from "node:stream";
8
8
  import type { DownloadOptions } from "./types.mjs";
@@ -1 +1 @@
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,oBAAgB;AAE/C;;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"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"download.mjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,I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MAAM,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';\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"]}
1
+ {"version":3,"file":"download.mjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,kBAAkB;AAEnD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,mBAAmB;AACrD,OAAO,EAAE,MAAM,EAAE,oBAAoB;AACrC,OAAO,EAAE,QAAQ,EAAE,6BAA6B;AAIhD;;GAEG;AACH,MAAM,cAAe,SAAQ,MAAM,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,MAAM,UAAU,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,WAAW,CAAC,CAAC,CAAC,YAAY,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,OAA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AAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YAC1D,QAAQ,CAAC,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","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 CHANGED
@@ -12,9 +12,9 @@ const node_path_1 = require("node:path");
12
12
  const promises_2 = require("node:stream/promises");
13
13
  const tar_1 = require("tar");
14
14
  const unzipper_1 = require("unzipper");
15
- const download_1 = require("./download.cjs");
16
- const types_1 = require("./types.cjs");
17
- const utils_1 = require("./utils.cjs");
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
18
  /**
19
19
  * Extracts the binaries from the given URL and writes them to the destination.
20
20
  *
@@ -34,7 +34,7 @@ const utils_1 = require("./utils.cjs");
34
34
  * @returns The list of binaries extracted
35
35
  */
36
36
  async function extractFrom(url, binaries, dir, checksums) {
37
- const extract = url.pathname.toLowerCase().endsWith(types_1.Extension.Tar)
37
+ const extract = url.pathname.toLowerCase().endsWith(types_js_1.Extension.Tar)
38
38
  ? extractFromTar
39
39
  : extractFromZip;
40
40
  // write all files to a temporary directory first, then rename to the final
@@ -53,10 +53,10 @@ async function extractFrom(url, binaries, dir, checksums) {
53
53
  const paths = [];
54
54
  for (const { path, binary, checksum } of downloads) {
55
55
  if (checksums) {
56
- (0, utils_1.say)(`verifying checksum for ${binary}`);
56
+ (0, utils_js_1.say)(`verifying checksum for ${binary}`);
57
57
  const expected = checksums.binaries[binary];
58
58
  if (checksum === expected) {
59
- (0, utils_1.say)(`checksum verified for ${binary}`);
59
+ (0, utils_js_1.say)(`checksum verified for ${binary}`);
60
60
  }
61
61
  else {
62
62
  throw new Error(`checksum mismatch for ${binary}, expected ${expected}, got ${checksum}`);
@@ -109,7 +109,7 @@ exports.extractFrom = extractFrom;
109
109
  */
110
110
  async function extractFromTar(url, binaries, dir, checksumAlgorithm) {
111
111
  const downloads = [];
112
- await (0, promises_2.pipeline)((0, download_1.startDownload)(url), (0, tar_1.extract)({
112
+ await (0, promises_2.pipeline)((0, download_js_1.startDownload)(url), (0, tar_1.extract)({
113
113
  cwd: dir,
114
114
  transform: (entry) => {
115
115
  const absolutePath = entry.absolute;
@@ -155,7 +155,7 @@ async function extractFromZip(url, binaries, dir, checksumAlgorithm) {
155
155
  });
156
156
  const source = {
157
157
  async size() {
158
- const download = (0, download_1.startDownload)(url, { agent, method: 'HEAD' });
158
+ const download = (0, download_js_1.startDownload)(url, { agent, method: 'HEAD' });
159
159
  const response = await download.response();
160
160
  const contentLength = response.headers['content-length'];
161
161
  return contentLength ? parseInt(contentLength, 10) : 0;
@@ -167,7 +167,7 @@ async function extractFromZip(url, binaries, dir, checksumAlgorithm) {
167
167
  range: `bytes=${offset}-${bytes ? offset + bytes : ''}`,
168
168
  },
169
169
  };
170
- return (0, download_1.startDownload)(url, options);
170
+ return (0, download_js_1.startDownload)(url, options);
171
171
  },
172
172
  };
173
173
  const { files } = await unzipper_1.Open.custom(source, {});
@@ -1 +1 @@
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;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IAAA,mBAAO,EAAC,IAAI,CAAC,CAAW,CAAC,CAC3D,CAAC;IACF,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACtC,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,IAAA,2BAAiB,EAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,IAAA,oBAAQ,EAAC,IAAI,EAAE,IAAA,mBAAO,EAAC,IAAI,CAAC,CAAW,CAAC;QACvD,IAAI,iBAAiB,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,iBAAiB,CAAC,CAAC;YAC3C,MAAM,UAAU,GAAG,KAAK,SAAS,CAAC,EAAE,WAAkB;gBACpD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;oBACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACnB,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC,CAAC;YACF,MAAM,IAAA,mBAAQ,EAAC,KAAK,EAAE,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';\nimport { Extension } from './types';\nimport type { Binary } from './types';\nimport { say } from './utils';\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 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"]}
1
+ {"version":3,"file":"extract.cjs","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,+CAAwC;AACxC,6CAAyC;AACzC,qCAA4C;AAC5C,+CAAqD;AACrD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';\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 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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.cts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAGtC;;;;;;;;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"}
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.mts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAGtC;;;;;;;;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"}
1
+ {"version":3,"file":"extract.d.mts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EA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,CAAC,CAAW,CAAC;QACvD,IAAI,iBAAiB,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;YAC3C,MAAM,UAAU,GAAG,KAAK,SAAS,CAAC,EAAE,WAAkB;gBACpD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;oBACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACnB,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC,CAAC;YACF,MAAM,QAAQ,CAAC,KAAK,EAAE,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,QAAQ,CAAC,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';\nimport { Extension } from './types';\nimport type { Binary } from './types';\nimport { say } from './utils';\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 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"]}
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,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB;AAC9D,OAAO,EAAE,QAAQ,EAAE,6BAA6B;AAChD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,YAAY;AAC5C,OAAO,EAAE,IAAI,EAAE,iBAAiB;AAGhC,OAA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G,CACtB,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAW,CAAC;QACvD,IAAI,iBAAiB,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;YAC3C,MAAM,UAAU,GAAG,KAAK,SAAS,CAAC,EAAE,WAAkB;gBACpD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;oBACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACnB,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC,CAAC;YACF,MAAM,QAAQ,CAAC,KAAK,EAAE,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,QAAQ,CAAC,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 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 CHANGED
@@ -9,10 +9,10 @@ const node_os_1 = require("node:os");
9
9
  const node_path_1 = require("node:path");
10
10
  const node_process_1 = require("node:process");
11
11
  const yaml_1 = require("yaml");
12
- const extract_1 = require("./extract.cjs");
13
- const options_1 = require("./options.cjs");
14
- const types_1 = require("./types.cjs");
15
- const utils_1 = require("./utils.cjs");
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
16
  /**
17
17
  * Determines the cache directory based on the .yarnrc.yml configuration.
18
18
  * If global cache is enabled, returns a path in the user's home directory.
@@ -51,7 +51,7 @@ exports.getCacheDirectory = getCacheDirectory;
51
51
  * @returns The URL for the binary archive
52
52
  */
53
53
  function getBinaryArchiveUrl(repo, tag, version, platform, arch) {
54
- const ext = platform === types_1.Platform.Windows ? types_1.Extension.Zip : types_1.Extension.Tar;
54
+ const ext = platform === types_js_1.Platform.Windows ? types_js_1.Extension.Zip : types_js_1.Extension.Tar;
55
55
  return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;
56
56
  }
57
57
  exports.getBinaryArchiveUrl = getBinaryArchiveUrl;
@@ -69,17 +69,17 @@ exports.getBinaryArchiveUrl = getBinaryArchiveUrl;
69
69
  async function checkAndDownloadBinaries(url, binaries, cachePath, platform, arch, checksums) {
70
70
  let downloadedBinaries;
71
71
  try {
72
- (0, utils_1.say)(`checking cache`);
72
+ (0, utils_js_1.say)(`checking cache`);
73
73
  downloadedBinaries = await (0, promises_1.opendir)(cachePath);
74
- (0, utils_1.say)(`found binaries in cache`);
74
+ (0, utils_js_1.say)(`found binaries in cache`);
75
75
  }
76
76
  catch (e) {
77
- (0, utils_1.say)(`binaries not in cache`);
77
+ (0, utils_js_1.say)(`binaries not in cache`);
78
78
  if (e.code === 'ENOENT') {
79
- (0, utils_1.say)(`installing from ${url.toString()}`);
79
+ (0, utils_js_1.say)(`installing from ${url.toString()}`);
80
80
  // directory doesn't exist, download and extract
81
- const platformChecksums = (0, utils_1.transformChecksums)(checksums, platform, arch);
82
- await (0, extract_1.extractFrom)(url, binaries, cachePath, platformChecksums);
81
+ const platformChecksums = (0, utils_js_1.transformChecksums)(checksums, platform, arch);
82
+ await (0, extract_js_1.extractFrom)(url, binaries, cachePath, platformChecksums);
83
83
  downloadedBinaries = await (0, promises_1.opendir)(cachePath);
84
84
  }
85
85
  else {
@@ -111,13 +111,13 @@ async function installBinaries(downloadedBinaries, BIN_DIR, cachePath) {
111
111
  // create the BIN_DIR paths if they don't exists already
112
112
  await (0, promises_1.mkdir)(BIN_DIR, { recursive: true });
113
113
  // clean up any existing files or symlinks
114
- await (0, promises_1.unlink)(path).catch(utils_1.noop);
114
+ await (0, promises_1.unlink)(path).catch(utils_js_1.noop);
115
115
  try {
116
116
  // create new symlink
117
117
  await (0, promises_1.symlink)(relativeTarget, path);
118
118
  }
119
119
  catch (e) {
120
- if (!((0, utils_1.isCodedError)(e) && ['EPERM', 'EXDEV'].includes(e.code))) {
120
+ if (!((0, utils_js_1.isCodedError)(e) && ['EPERM', 'EXDEV'].includes(e.code))) {
121
121
  throw e;
122
122
  }
123
123
  // symlinking can fail if it's a cross-device/filesystem link, or for
@@ -125,7 +125,7 @@ async function installBinaries(downloadedBinaries, BIN_DIR, cachePath) {
125
125
  await (0, promises_1.copyFile)(target, path);
126
126
  }
127
127
  // check that it works by logging the version
128
- (0, utils_1.say)(`installed - ${(0, utils_1.getVersion)(path).toString()}`);
128
+ (0, utils_js_1.say)(`installed - ${(0, utils_js_1.getVersion)(path).toString()}`);
129
129
  }
130
130
  }
131
131
  exports.installBinaries = installBinaries;
@@ -137,17 +137,17 @@ exports.installBinaries = installBinaries;
137
137
  * @returns A promise that resolves when the operation is complete
138
138
  */
139
139
  async function downloadAndInstallFoundryBinaries() {
140
- const parsedArgs = (0, options_1.parseArgs)();
140
+ const parsedArgs = (0, options_js_1.parseArgs)();
141
141
  const CACHE_DIR = getCacheDirectory();
142
142
  if (parsedArgs.command === 'cache clean') {
143
143
  await (0, promises_1.rm)(CACHE_DIR, { recursive: true, force: true });
144
- (0, utils_1.say)('done!');
144
+ (0, utils_js_1.say)('done!');
145
145
  (0, node_process_1.exit)(0);
146
146
  }
147
147
  const { repo, version: { version, tag }, arch, platform, binaries, checksums, } = parsedArgs.options;
148
- (0, options_1.printBanner)();
148
+ (0, options_js_1.printBanner)();
149
149
  const bins = binaries.join(', ');
150
- (0, utils_1.say)(`fetching ${bins} ${version} for ${platform} ${arch}`);
150
+ (0, utils_js_1.say)(`fetching ${bins} ${version} for ${platform} ${arch}`);
151
151
  const BIN_ARCHIVE_URL = getBinaryArchiveUrl(repo, tag, version, platform, arch);
152
152
  const BIN_DIR = (0, node_path_1.join)((0, node_process_1.cwd)(), 'node_modules', '.bin');
153
153
  const url = new URL(BIN_ARCHIVE_URL);
@@ -157,7 +157,7 @@ async function downloadAndInstallFoundryBinaries() {
157
157
  const cachePath = (0, node_path_1.join)(CACHE_DIR, cacheKey);
158
158
  const downloadedBinaries = await checkAndDownloadBinaries(url, binaries, cachePath, platform, arch, checksums);
159
159
  await installBinaries(downloadedBinaries, BIN_DIR, cachePath);
160
- (0, utils_1.say)('done!');
160
+ (0, utils_js_1.say)('done!');
161
161
  }
162
162
  exports.downloadAndInstallFoundryBinaries = downloadAndInstallFoundryBinaries;
163
163
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAEA,6CAAyC;AACzC,qCAAuC;AAEvC,+CAO0B;AAC1B,qCAAkC;AAClC,yCAAoD;AACpD,+CAAyC;AACzC,+BAA0C;AAE1C,2CAAwC;AACxC,2CAAmD;AAEnD,uCAA8C;AAC9C,uCAMiB;AAEjB;;;;;;GAMG;AACH,SAAgB,iBAAiB;IAC/B,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,IAAA,sBAAY,EAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAC9D,MAAM,YAAY,GAAG,IAAA,YAAS,EAAC,iBAAiB,CAAC,CAAC;QAClD,iBAAiB,GAAG,YAAY,EAAE,iBAAiB,IAAI,KAAK,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iEAAiE;QACjE,IAA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AI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,IAAA,WAAG,EAAC,YAAY,IAAI,IAAI,OAAO,QAAQ,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IAE3D,MAAM,eAAe,GAAG,mBAAmB,CACzC,IAAI,EACJ,GAAG,EACH,OAAO,EACP,QAAQ,EACR,IAAI,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,IAAA,kBAAG,GAAE,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAEpD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC;SAClC,MAAM,CAAC,GAAG,eAAe,IAAI,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjB,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE5C,MAAM,kBAAkB,GAAG,MAAM,wBAAwB,CACvD,GAAG,EACH,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,SAAS,CACV,CAAC;IAEF,MAAM,eAAe,CAAC,kBAAkB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE9D,IAAA,WAAG,EAAC,OAAO,CAAC,CAAC;AACf,CAAC;AAnDD,8EAmDC","sourcesContent":["#!/usr/bin/env -S node --require \"./node_modules/tsx/dist/preflight.cjs\" --import \"./node_modules/tsx/dist/loader.mjs\"\n\nimport { createHash } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport type { Dir } from 'node:fs';\nimport {\n copyFile,\n mkdir,\n opendir,\n rm,\n symlink,\n unlink,\n} from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join, relative } from 'node:path';\nimport { cwd, exit } from 'node:process';\nimport { parse as parseYaml } from 'yaml';\n\nimport { extractFrom } from './extract';\nimport { parseArgs, printBanner } from './options';\nimport type { Checksums, Architecture, Binary } from './types';\nimport { Extension, Platform } from './types';\nimport {\n getVersion,\n isCodedError,\n noop,\n say,\n transformChecksums,\n} from './utils';\n\n/**\n * Determines the cache directory based on the .yarnrc.yml configuration.\n * If global cache is enabled, returns a path in the user's home directory.\n * Otherwise, returns a local cache path in the current working directory.\n *\n * @returns The path to the cache directory\n */\nexport function getCacheDirectory(): string {\n let enableGlobalCache = false;\n try {\n const configFileContent = readFileSync('.yarnrc.yml', 'utf8');\n const parsedConfig = parseYaml(configFileContent);\n enableGlobalCache = parsedConfig?.enableGlobalCache ?? false;\n } catch (error) {\n // If file doesn't exist or can't be read, default to local cache\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return join(cwd(), '.metamask', 'cache');\n }\n // For other errors, log but continue with default\n console.warn(\n 'Warning: Error reading .yarnrc.yml, using local cache:',\n error,\n );\n }\n return enableGlobalCache\n ? join(homedir(), '.cache', 'metamask')\n : join(cwd(), '.metamask', 'cache');\n}\n\n/**\n * Generates the URL for downloading the Foundry binary archive.\n *\n * @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')\n * @param tag - The release tag (e.g., 'v1.0.0')\n * @param version - The version string\n * @param platform - The target platform (e.g., Platform.Linux)\n * @param arch - The target architecture (e.g., 'amd64')\n * @returns The URL for the binary archive\n */\nexport function getBinaryArchiveUrl(\n repo: string,\n tag: string,\n version: string,\n platform: Platform,\n arch: string,\n): string {\n const ext = platform === Platform.Windows ? Extension.Zip : Extension.Tar;\n return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;\n}\n\n/**\n * Checks if binaries are already in the cache. If not, downloads and extracts them.\n *\n * @param url - The URL to download the binaries from\n * @param binaries - The list of binaries to download\n * @param cachePath - The path to the cache directory\n * @param platform - The target platform\n * @param arch - The target architecture\n * @param checksums - Optional checksums for verification\n * @returns A promise that resolves to the directory containing the downloaded binaries\n */\nexport async function checkAndDownloadBinaries(\n url: URL,\n binaries: Binary[],\n cachePath: string,\n platform: Platform,\n arch: Architecture,\n checksums?: Checksums,\n): Promise<Dir> {\n let downloadedBinaries: Dir;\n try {\n say(`checking cache`);\n downloadedBinaries = await opendir(cachePath);\n say(`found binaries in cache`);\n } catch (e: unknown) {\n say(`binaries not in cache`);\n if ((e as NodeJS.ErrnoException).code === 'ENOENT') {\n say(`installing from ${url.toString()}`);\n // directory doesn't exist, download and extract\n const platformChecksums = transformChecksums(checksums, platform, arch);\n await extractFrom(url, binaries, cachePath, platformChecksums);\n downloadedBinaries = await opendir(cachePath);\n } else {\n throw e;\n }\n }\n return downloadedBinaries;\n}\n\n/**\n * Installs the downloaded binaries by creating symlinks or copying files.\n *\n * @param downloadedBinaries - The directory containing the downloaded binaries\n * @param BIN_DIR - The target directory for installation\n * @param cachePath - The path to the cache directory\n * @returns A promise that resolves when installation is complete\n */\nexport async function installBinaries(\n downloadedBinaries: Dir,\n BIN_DIR: string,\n cachePath: string,\n): Promise<void> {\n for await (const file of downloadedBinaries) {\n if (!file.isFile()) {\n continue;\n }\n const target = join(file.parentPath, file.name);\n const path = join(BIN_DIR, relative(cachePath, target));\n\n // compute the relative path from where the symlink will be created\n // to the target file, so that it works even if the project is moved\n // (like in some CI environments)\n const relativeTarget = relative(dirname(path), target);\n\n // create the BIN_DIR paths if they don't exists already\n await mkdir(BIN_DIR, { recursive: true });\n\n // clean up any existing files or symlinks\n await unlink(path).catch(noop);\n try {\n // create new symlink\n await symlink(relativeTarget, path);\n } catch (e) {\n if (!(isCodedError(e) && ['EPERM', 'EXDEV'].includes(e.code))) {\n throw e;\n }\n // symlinking can fail if it's a cross-device/filesystem link, or for\n // permissions reasons, so we'll just copy the file instead\n await copyFile(target, path);\n }\n // check that it works by logging the version\n say(`installed - ${getVersion(path).toString()}`);\n }\n}\n\n/**\n * Downloads and installs Foundry binaries based on command-line arguments.\n * If the command is 'cache clean', it removes the cache directory.\n * Otherwise, it downloads and installs the specified binaries.\n *\n * @returns A promise that resolves when the operation is complete\n */\nexport async function downloadAndInstallFoundryBinaries(): Promise<void> {\n const parsedArgs = parseArgs();\n\n const CACHE_DIR = getCacheDirectory();\n\n if (parsedArgs.command === 'cache clean') {\n await rm(CACHE_DIR, { recursive: true, force: true });\n say('done!');\n exit(0);\n }\n\n const {\n repo,\n version: { version, tag },\n arch,\n platform,\n binaries,\n checksums,\n } = parsedArgs.options;\n\n printBanner();\n const bins = binaries.join(', ');\n say(`fetching ${bins} ${version} for ${platform} ${arch}`);\n\n const BIN_ARCHIVE_URL = getBinaryArchiveUrl(\n repo,\n tag,\n version,\n platform,\n arch,\n );\n const BIN_DIR = join(cwd(), 'node_modules', '.bin');\n\n const url = new URL(BIN_ARCHIVE_URL);\n const cacheKey = createHash('sha256')\n .update(`${BIN_ARCHIVE_URL}-${bins}`)\n .digest('hex');\n const cachePath = join(CACHE_DIR, cacheKey);\n\n const downloadedBinaries = await checkAndDownloadBinaries(\n url,\n binaries,\n cachePath,\n platform,\n arch,\n checksums,\n );\n\n await installBinaries(downloadedBinaries, BIN_DIR, cachePath);\n\n say('done!');\n}\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAEA,6CAAyC;AACzC,qCAAuC;AAEvC,+CAO0B;AAC1B,qCAAkC;AAClC,yCAAoD;AACpD,+CAAyC;AACzC,+BAA0C;AAE1C,8CAA2C;AAC3C,8CAAsD;AAEtD,0CAAiD;AACjD,0CAMoB;AAEpB;;;;;;GAMG;AACH,SAAgB,iBAAiB;IAC/B,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,IAAA,sBAAY,EAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAC9D,MAAM,YAAY,GAAG,IAAA,YAAS,EAAC,iBAAiB,CAAC,CAAC;QAClD,iBAAiB,GAAG,YAAY,EAAE,iBAAiB,IAAI,KAAK,CAAC;IAC/D,CAAC;IAAC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C;IAEvB,IAAA,wBAAW,GAAE,CAAC;IACd,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,IAAA,cAAG,EAAC,YAAY,IAAI,IAAI,OAAO,QAAQ,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IAE3D,MAAM,eAAe,GAAG,mBAAmB,CACzC,IAAI,EACJ,GAAG,EACH,OAAO,EACP,QAAQ,EACR,IAAI,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,IAAA,kBAAG,GAAE,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAEpD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC;SAClC,MAAM,CAAC,GAAG,eAAe,IAAI,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjB,MAAM,SAAS,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE5C,MAAM,kBAAkB,GAAG,MAAM,wBAAwB,CACvD,GAAG,EACH,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,SAAS,CACV,CAAC;IAEF,MAAM,eAAe,CAAC,kBAAkB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE9D,IAAA,cAAG,EAAC,OAAO,CAAC,CAAC;AACf,CAAC;AAnDD,8EAmDC","sourcesContent":["#!/usr/bin/env -S node --require \"./node_modules/tsx/dist/preflight.cjs\" --import \"./node_modules/tsx/dist/loader.mjs\"\n\nimport { createHash } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport type { Dir } from 'node:fs';\nimport {\n copyFile,\n mkdir,\n opendir,\n rm,\n symlink,\n unlink,\n} from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join, relative } from 'node:path';\nimport { cwd, exit } from 'node:process';\nimport { parse as parseYaml } from 'yaml';\n\nimport { extractFrom } from './extract.js';\nimport { parseArgs, printBanner } from './options.js';\nimport type { Checksums, Architecture, Binary } from './types.js';\nimport { Extension, Platform } from './types.js';\nimport {\n getVersion,\n isCodedError,\n noop,\n say,\n transformChecksums,\n} from './utils.js';\n\n/**\n * Determines the cache directory based on the .yarnrc.yml configuration.\n * If global cache is enabled, returns a path in the user's home directory.\n * Otherwise, returns a local cache path in the current working directory.\n *\n * @returns The path to the cache directory\n */\nexport function getCacheDirectory(): string {\n let enableGlobalCache = false;\n try {\n const configFileContent = readFileSync('.yarnrc.yml', 'utf8');\n const parsedConfig = parseYaml(configFileContent);\n enableGlobalCache = parsedConfig?.enableGlobalCache ?? false;\n } catch (error) {\n // If file doesn't exist or can't be read, default to local cache\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return join(cwd(), '.metamask', 'cache');\n }\n // For other errors, log but continue with default\n console.warn(\n 'Warning: Error reading .yarnrc.yml, using local cache:',\n error,\n );\n }\n return enableGlobalCache\n ? join(homedir(), '.cache', 'metamask')\n : join(cwd(), '.metamask', 'cache');\n}\n\n/**\n * Generates the URL for downloading the Foundry binary archive.\n *\n * @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')\n * @param tag - The release tag (e.g., 'v1.0.0')\n * @param version - The version string\n * @param platform - The target platform (e.g., Platform.Linux)\n * @param arch - The target architecture (e.g., 'amd64')\n * @returns The URL for the binary archive\n */\nexport function getBinaryArchiveUrl(\n repo: string,\n tag: string,\n version: string,\n platform: Platform,\n arch: string,\n): string {\n const ext = platform === Platform.Windows ? Extension.Zip : Extension.Tar;\n return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;\n}\n\n/**\n * Checks if binaries are already in the cache. If not, downloads and extracts them.\n *\n * @param url - The URL to download the binaries from\n * @param binaries - The list of binaries to download\n * @param cachePath - The path to the cache directory\n * @param platform - The target platform\n * @param arch - The target architecture\n * @param checksums - Optional checksums for verification\n * @returns A promise that resolves to the directory containing the downloaded binaries\n */\nexport async function checkAndDownloadBinaries(\n url: URL,\n binaries: Binary[],\n cachePath: string,\n platform: Platform,\n arch: Architecture,\n checksums?: Checksums,\n): Promise<Dir> {\n let downloadedBinaries: Dir;\n try {\n say(`checking cache`);\n downloadedBinaries = await opendir(cachePath);\n say(`found binaries in cache`);\n } catch (e: unknown) {\n say(`binaries not in cache`);\n if ((e as NodeJS.ErrnoException).code === 'ENOENT') {\n say(`installing from ${url.toString()}`);\n // directory doesn't exist, download and extract\n const platformChecksums = transformChecksums(checksums, platform, arch);\n await extractFrom(url, binaries, cachePath, platformChecksums);\n downloadedBinaries = await opendir(cachePath);\n } else {\n throw e;\n }\n }\n return downloadedBinaries;\n}\n\n/**\n * Installs the downloaded binaries by creating symlinks or copying files.\n *\n * @param downloadedBinaries - The directory containing the downloaded binaries\n * @param BIN_DIR - The target directory for installation\n * @param cachePath - The path to the cache directory\n * @returns A promise that resolves when installation is complete\n */\nexport async function installBinaries(\n downloadedBinaries: Dir,\n BIN_DIR: string,\n cachePath: string,\n): Promise<void> {\n for await (const file of downloadedBinaries) {\n if (!file.isFile()) {\n continue;\n }\n const target = join(file.parentPath, file.name);\n const path = join(BIN_DIR, relative(cachePath, target));\n\n // compute the relative path from where the symlink will be created\n // to the target file, so that it works even if the project is moved\n // (like in some CI environments)\n const relativeTarget = relative(dirname(path), target);\n\n // create the BIN_DIR paths if they don't exists already\n await mkdir(BIN_DIR, { recursive: true });\n\n // clean up any existing files or symlinks\n await unlink(path).catch(noop);\n try {\n // create new symlink\n await symlink(relativeTarget, path);\n } catch (e) {\n if (!(isCodedError(e) && ['EPERM', 'EXDEV'].includes(e.code))) {\n throw e;\n }\n // symlinking can fail if it's a cross-device/filesystem link, or for\n // permissions reasons, so we'll just copy the file instead\n await copyFile(target, path);\n }\n // check that it works by logging the version\n say(`installed - ${getVersion(path).toString()}`);\n }\n}\n\n/**\n * Downloads and installs Foundry binaries based on command-line arguments.\n * If the command is 'cache clean', it removes the cache directory.\n * Otherwise, it downloads and installs the specified binaries.\n *\n * @returns A promise that resolves when the operation is complete\n */\nexport async function downloadAndInstallFoundryBinaries(): Promise<void> {\n const parsedArgs = parseArgs();\n\n const CACHE_DIR = getCacheDirectory();\n\n if (parsedArgs.command === 'cache clean') {\n await rm(CACHE_DIR, { recursive: true, force: true });\n say('done!');\n exit(0);\n }\n\n const {\n repo,\n version: { version, tag },\n arch,\n platform,\n binaries,\n checksums,\n } = parsedArgs.options;\n\n printBanner();\n const bins = binaries.join(', ');\n say(`fetching ${bins} ${version} for ${platform} ${arch}`);\n\n const BIN_ARCHIVE_URL = getBinaryArchiveUrl(\n repo,\n tag,\n version,\n platform,\n arch,\n );\n const BIN_DIR = join(cwd(), 'node_modules', '.bin');\n\n const url = new URL(BIN_ARCHIVE_URL);\n const cacheKey = createHash('sha256')\n .update(`${BIN_ARCHIVE_URL}-${bins}`)\n .digest('hex');\n const cachePath = join(CACHE_DIR, cacheKey);\n\n const downloadedBinaries = await checkAndDownloadBinaries(\n url,\n binaries,\n cachePath,\n platform,\n arch,\n checksums,\n );\n\n await installBinaries(downloadedBinaries, BIN_DIR, cachePath);\n\n say('done!');\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
2
2
  /// <reference types="node" />
3
- /// <reference types="node/fs" />
4
- /// <reference types="npm-which/node_modules/@types/node/fs" />
3
+ /// <reference types="node/fs.js" />
4
+ /// <reference types="npm-which/node_modules/@types/node/fs.js" />
5
5
  import type { Dir } from "node:fs";
6
6
  import type { Checksums, Architecture, Binary } from "./types.cjs";
7
7
  import { Platform } from "./types.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB;AAgBnC,OAAO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,IAAI,EAAE,MAAM,GACX,MAAM,CAGR;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,YAAY,EAClB,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,GAAG,CAAC,CAmBd;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,kBAAkB,EAAE,GAAG,EACvB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED;;;;;;GAMG;AACH,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,IAAI,CAAC,CAmDvE"}
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
2
2
  /// <reference types="node" />
3
- /// <reference types="node/fs" />
4
- /// <reference types="npm-which/node_modules/@types/node/fs" />
3
+ /// <reference types="node/fs.js" />
4
+ /// <reference types="npm-which/node_modules/@types/node/fs.js" />
5
5
  import type { Dir } from "node:fs";
6
6
  import type { Checksums, Architecture, Binary } from "./types.mjs";
7
7
  import { Platform } from "./types.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB;AAgBnC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,oBAAgB;AAC/D,OAAO,EAAa,QAAQ,EAAE,oBAAgB;AAS9C;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAoB1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE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mB,CACzC,IAAI,EACJ,GAAG,EACH,OAAO,EACP,QAAQ,EACR,IAAI,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAEpD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;SAClC,MAAM,CAAC,GAAG,eAAe,IAAI,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE5C,MAAM,kBAAkB,GAAG,MAAM,wBAAwB,CACvD,GAAG,EACH,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,SAAS,CACV,CAAC;IAEF,MAAM,eAAe,CAAC,kBAAkB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE9D,GAAG,CAAC,OAAO,CAAC,CAAC;AACf,CAAC","sourcesContent":["#!/usr/bin/env -S node --require \"./node_modules/tsx/dist/preflight.cjs\" --import \"./node_modules/tsx/dist/loader.mjs\"\n\nimport { createHash } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport type { Dir } from 'node:fs';\nimport {\n copyFile,\n mkdir,\n opendir,\n rm,\n symlink,\n unlink,\n} from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join, relative } from 'node:path';\nimport { cwd, exit } from 'node:process';\nimport { parse as parseYaml } from 'yaml';\n\nimport { extractFrom } from './extract';\nimport { parseArgs, printBanner } from './options';\nimport type { Checksums, Architecture, Binary } from './types';\nimport { Extension, Platform } from './types';\nimport {\n getVersion,\n isCodedError,\n noop,\n say,\n transformChecksums,\n} from './utils';\n\n/**\n * Determines the cache directory based on the .yarnrc.yml configuration.\n * If global cache is enabled, returns a path in the user's home directory.\n * Otherwise, returns a local cache path in the current working directory.\n *\n * @returns The path to the cache directory\n */\nexport function getCacheDirectory(): string {\n let enableGlobalCache = false;\n try {\n const configFileContent = readFileSync('.yarnrc.yml', 'utf8');\n const parsedConfig = parseYaml(configFileContent);\n enableGlobalCache = parsedConfig?.enableGlobalCache ?? false;\n } catch (error) {\n // If file doesn't exist or can't be read, default to local cache\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return join(cwd(), '.metamask', 'cache');\n }\n // For other errors, log but continue with default\n console.warn(\n 'Warning: Error reading .yarnrc.yml, using local cache:',\n error,\n );\n }\n return enableGlobalCache\n ? join(homedir(), '.cache', 'metamask')\n : join(cwd(), '.metamask', 'cache');\n}\n\n/**\n * Generates the URL for downloading the Foundry binary archive.\n *\n * @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')\n * @param tag - The release tag (e.g., 'v1.0.0')\n * @param version - The version string\n * @param platform - The target platform (e.g., Platform.Linux)\n * @param arch - The target architecture (e.g., 'amd64')\n * @returns The URL for the binary archive\n */\nexport function getBinaryArchiveUrl(\n repo: string,\n tag: string,\n version: string,\n platform: Platform,\n arch: string,\n): string {\n const ext = platform === Platform.Windows ? Extension.Zip : Extension.Tar;\n return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;\n}\n\n/**\n * Checks if binaries are already in the cache. If not, downloads and extracts them.\n *\n * @param url - The URL to download the binaries from\n * @param binaries - The list of binaries to download\n * @param cachePath - The path to the cache directory\n * @param platform - The target platform\n * @param arch - The target architecture\n * @param checksums - Optional checksums for verification\n * @returns A promise that resolves to the directory containing the downloaded binaries\n */\nexport async function checkAndDownloadBinaries(\n url: URL,\n binaries: Binary[],\n cachePath: string,\n platform: Platform,\n arch: Architecture,\n checksums?: Checksums,\n): Promise<Dir> {\n let downloadedBinaries: Dir;\n try {\n say(`checking cache`);\n downloadedBinaries = await opendir(cachePath);\n say(`found binaries in cache`);\n } catch (e: unknown) {\n say(`binaries not in cache`);\n if ((e as NodeJS.ErrnoException).code === 'ENOENT') {\n say(`installing from ${url.toString()}`);\n // directory doesn't exist, download and extract\n const platformChecksums = transformChecksums(checksums, platform, arch);\n await extractFrom(url, binaries, cachePath, platformChecksums);\n downloadedBinaries = await opendir(cachePath);\n } else {\n throw e;\n }\n }\n return downloadedBinaries;\n}\n\n/**\n * Installs the downloaded binaries by creating symlinks or copying files.\n *\n * @param downloadedBinaries - The directory containing the downloaded binaries\n * @param BIN_DIR - The target directory for installation\n * @param cachePath - The path to the cache directory\n * @returns A promise that resolves when installation is complete\n */\nexport async function installBinaries(\n downloadedBinaries: Dir,\n BIN_DIR: string,\n cachePath: string,\n): Promise<void> {\n for await (const file of downloadedBinaries) {\n if (!file.isFile()) {\n continue;\n }\n const target = join(file.parentPath, file.name);\n const path = join(BIN_DIR, relative(cachePath, target));\n\n // compute the relative path from where the symlink will be created\n // to the target file, so that it works even if the project is moved\n // (like in some CI environments)\n const relativeTarget = relative(dirname(path), target);\n\n // create the BIN_DIR paths if they don't exists already\n await mkdir(BIN_DIR, { recursive: true });\n\n // clean up any existing files or symlinks\n await unlink(path).catch(noop);\n try {\n // create new symlink\n await symlink(relativeTarget, path);\n } catch (e) {\n if (!(isCodedError(e) && ['EPERM', 'EXDEV'].includes(e.code))) {\n throw e;\n }\n // symlinking can fail if it's a cross-device/filesystem link, or for\n // permissions reasons, so we'll just copy the file instead\n await copyFile(target, path);\n }\n // check that it works by logging the version\n say(`installed - ${getVersion(path).toString()}`);\n }\n}\n\n/**\n * Downloads and installs Foundry binaries based on command-line arguments.\n * If the command is 'cache clean', it removes the cache directory.\n * Otherwise, it downloads and installs the specified binaries.\n *\n * @returns A promise that resolves when the operation is complete\n */\nexport async function downloadAndInstallFoundryBinaries(): Promise<void> {\n const parsedArgs = parseArgs();\n\n const CACHE_DIR = getCacheDirectory();\n\n if (parsedArgs.command === 'cache clean') {\n await rm(CACHE_DIR, { recursive: true, force: true });\n say('done!');\n exit(0);\n }\n\n const {\n repo,\n version: { version, tag },\n arch,\n platform,\n binaries,\n checksums,\n } = parsedArgs.options;\n\n printBanner();\n const bins = binaries.join(', ');\n say(`fetching ${bins} ${version} for ${platform} ${arch}`);\n\n const BIN_ARCHIVE_URL = getBinaryArchiveUrl(\n repo,\n tag,\n version,\n platform,\n arch,\n );\n const BIN_DIR = join(cwd(), 'node_modules', '.bin');\n\n const url = new URL(BIN_ARCHIVE_URL);\n const cacheKey = createHash('sha256')\n .update(`${BIN_ARCHIVE_URL}-${bins}`)\n .digest('hex');\n const cachePath = join(CACHE_DIR, cacheKey);\n\n const downloadedBinaries = await checkAndDownloadBinaries(\n url,\n binaries,\n cachePath,\n platform,\n arch,\n checksums,\n );\n\n await installBinaries(downloadedBinaries, BIN_DIR, cachePath);\n\n say('done!');\n}\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,EAAE,oBAAoB;AACzC,OAAO,EAAE,YAAY,EAAE,gBAAgB;AAEvC,OAAO,EACL,QAAQ,EACR,KAAK,EACL,OAAO,EACP,EAAE,EACF,OAAO,EACP,MAAM,EACP,yBAAyB;AAC1B,OAAO,EAAE,OAAO,EAAE,gBAAgB;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB;AACpD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,qBAAqB;AACzC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,aAAa;AAE1C,OAAO,EAAE,WAAW,EAAE,sBAAqB;AAC3C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAqB;AAEtD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,oBAAmB;AACjD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,GAAG,EACH,kBAAkB,EACnB,oBAAmB;AAEpB;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,CAAC;QACH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;IACd,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,GAAG,CAAC,YAAY,IAAI,IAAI,OAAO,QAAQ,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IAE3D,MAAM,eAAe,GAAG,mBAAmB,CACzC,IAAI,EACJ,GAAG,EACH,OAAO,EACP,QAAQ,EACR,IAAI,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAEpD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;SAClC,MAAM,CAAC,GAAG,eAAe,IAAI,IAAI,EAAE,CAAC;SACpC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAE5C,MAAM,kBAAkB,GAAG,MAAM,wBAAwB,CACvD,GAAG,EACH,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,SAAS,CACV,CAAC;IAEF,MAAM,eAAe,CAAC,kBAAkB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE9D,GAAG,CAAC,OAAO,CAAC,CAAC;AACf,CAAC","sourcesContent":["#!/usr/bin/env -S node --require \"./node_modules/tsx/dist/preflight.cjs\" --import \"./node_modules/tsx/dist/loader.mjs\"\n\nimport { createHash } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport type { Dir } from 'node:fs';\nimport {\n copyFile,\n mkdir,\n opendir,\n rm,\n symlink,\n unlink,\n} from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join, relative } from 'node:path';\nimport { cwd, exit } from 'node:process';\nimport { parse as parseYaml } from 'yaml';\n\nimport { extractFrom } from './extract.js';\nimport { parseArgs, printBanner } from './options.js';\nimport type { Checksums, Architecture, Binary } from './types.js';\nimport { Extension, Platform } from './types.js';\nimport {\n getVersion,\n isCodedError,\n noop,\n say,\n transformChecksums,\n} from './utils.js';\n\n/**\n * Determines the cache directory based on the .yarnrc.yml configuration.\n * If global cache is enabled, returns a path in the user's home directory.\n * Otherwise, returns a local cache path in the current working directory.\n *\n * @returns The path to the cache directory\n */\nexport function getCacheDirectory(): string {\n let enableGlobalCache = false;\n try {\n const configFileContent = readFileSync('.yarnrc.yml', 'utf8');\n const parsedConfig = parseYaml(configFileContent);\n enableGlobalCache = parsedConfig?.enableGlobalCache ?? false;\n } catch (error) {\n // If file doesn't exist or can't be read, default to local cache\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return join(cwd(), '.metamask', 'cache');\n }\n // For other errors, log but continue with default\n console.warn(\n 'Warning: Error reading .yarnrc.yml, using local cache:',\n error,\n );\n }\n return enableGlobalCache\n ? join(homedir(), '.cache', 'metamask')\n : join(cwd(), '.metamask', 'cache');\n}\n\n/**\n * Generates the URL for downloading the Foundry binary archive.\n *\n * @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')\n * @param tag - The release tag (e.g., 'v1.0.0')\n * @param version - The version string\n * @param platform - The target platform (e.g., Platform.Linux)\n * @param arch - The target architecture (e.g., 'amd64')\n * @returns The URL for the binary archive\n */\nexport function getBinaryArchiveUrl(\n repo: string,\n tag: string,\n version: string,\n platform: Platform,\n arch: string,\n): string {\n const ext = platform === Platform.Windows ? Extension.Zip : Extension.Tar;\n return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;\n}\n\n/**\n * Checks if binaries are already in the cache. If not, downloads and extracts them.\n *\n * @param url - The URL to download the binaries from\n * @param binaries - The list of binaries to download\n * @param cachePath - The path to the cache directory\n * @param platform - The target platform\n * @param arch - The target architecture\n * @param checksums - Optional checksums for verification\n * @returns A promise that resolves to the directory containing the downloaded binaries\n */\nexport async function checkAndDownloadBinaries(\n url: URL,\n binaries: Binary[],\n cachePath: string,\n platform: Platform,\n arch: Architecture,\n checksums?: Checksums,\n): Promise<Dir> {\n let downloadedBinaries: Dir;\n try {\n say(`checking cache`);\n downloadedBinaries = await opendir(cachePath);\n say(`found binaries in cache`);\n } catch (e: unknown) {\n say(`binaries not in cache`);\n if ((e as NodeJS.ErrnoException).code === 'ENOENT') {\n say(`installing from ${url.toString()}`);\n // directory doesn't exist, download and extract\n const platformChecksums = transformChecksums(checksums, platform, arch);\n await extractFrom(url, binaries, cachePath, platformChecksums);\n downloadedBinaries = await opendir(cachePath);\n } else {\n throw e;\n }\n }\n return downloadedBinaries;\n}\n\n/**\n * Installs the downloaded binaries by creating symlinks or copying files.\n *\n * @param downloadedBinaries - The directory containing the downloaded binaries\n * @param BIN_DIR - The target directory for installation\n * @param cachePath - The path to the cache directory\n * @returns A promise that resolves when installation is complete\n */\nexport async function installBinaries(\n downloadedBinaries: Dir,\n BIN_DIR: string,\n cachePath: string,\n): Promise<void> {\n for await (const file of downloadedBinaries) {\n if (!file.isFile()) {\n continue;\n }\n const target = join(file.parentPath, file.name);\n const path = join(BIN_DIR, relative(cachePath, target));\n\n // compute the relative path from where the symlink will be created\n // to the target file, so that it works even if the project is moved\n // (like in some CI environments)\n const relativeTarget = relative(dirname(path), target);\n\n // create the BIN_DIR paths if they don't exists already\n await mkdir(BIN_DIR, { recursive: true });\n\n // clean up any existing files or symlinks\n await unlink(path).catch(noop);\n try {\n // create new symlink\n await symlink(relativeTarget, path);\n } catch (e) {\n if (!(isCodedError(e) && ['EPERM', 'EXDEV'].includes(e.code))) {\n throw e;\n }\n // symlinking can fail if it's a cross-device/filesystem link, or for\n // permissions reasons, so we'll just copy the file instead\n await copyFile(target, path);\n }\n // check that it works by logging the version\n say(`installed - ${getVersion(path).toString()}`);\n }\n}\n\n/**\n * Downloads and installs Foundry binaries based on command-line arguments.\n * If the command is 'cache clean', it removes the cache directory.\n * Otherwise, it downloads and installs the specified binaries.\n *\n * @returns A promise that resolves when the operation is complete\n */\nexport async function downloadAndInstallFoundryBinaries(): Promise<void> {\n const parsedArgs = parseArgs();\n\n const CACHE_DIR = getCacheDirectory();\n\n if (parsedArgs.command === 'cache clean') {\n await rm(CACHE_DIR, { recursive: true, force: true });\n say('done!');\n exit(0);\n }\n\n const {\n repo,\n version: { version, tag },\n arch,\n platform,\n binaries,\n checksums,\n } = parsedArgs.options;\n\n printBanner();\n const bins = binaries.join(', ');\n say(`fetching ${bins} ${version} for ${platform} ${arch}`);\n\n const BIN_ARCHIVE_URL = getBinaryArchiveUrl(\n repo,\n tag,\n version,\n platform,\n arch,\n );\n const BIN_DIR = join(cwd(), 'node_modules', '.bin');\n\n const url = new URL(BIN_ARCHIVE_URL);\n const cacheKey = createHash('sha256')\n .update(`${BIN_ARCHIVE_URL}-${bins}`)\n .digest('hex');\n const cachePath = join(CACHE_DIR, cacheKey);\n\n const downloadedBinaries = await checkAndDownloadBinaries(\n url,\n binaries,\n cachePath,\n platform,\n arch,\n checksums,\n );\n\n await installBinaries(downloadedBinaries, BIN_DIR, cachePath);\n\n say('done!');\n}\n"]}
package/dist/options.cjs CHANGED
@@ -7,8 +7,8 @@ exports.parseArgs = exports.printBanner = void 0;
7
7
  const node_os_1 = require("node:os");
8
8
  const node_process_1 = require("node:process");
9
9
  const yargs_1 = __importDefault(require("yargs/yargs"));
10
- const types_1 = require("./types.cjs");
11
- const utils_1 = require("./utils.cjs");
10
+ const types_js_1 = require("./types.cjs");
11
+ const utils_js_1 = require("./utils.cjs");
12
12
  /**
13
13
  * Type guard to check if a string is a valid version string starting with 'v'.
14
14
  *
@@ -84,7 +84,7 @@ function parseArgs(args = node_process_1.argv.slice(2)) {
84
84
  };
85
85
  }
86
86
  exports.parseArgs = parseArgs;
87
- const Binaries = Object.values(types_1.Binary);
87
+ const Binaries = Object.values(types_js_1.Binary);
88
88
  /**
89
89
  * Returns the command line options configuration.
90
90
  *
@@ -92,7 +92,7 @@ const Binaries = Object.values(types_1.Binary);
92
92
  * @param defaultArch - Default architecture to use
93
93
  * @returns Command line options configuration
94
94
  */
95
- function getOptions(defaultPlatform = (0, node_os_1.platform)(), defaultArch = (0, utils_1.normalizeSystemArchitecture)()) {
95
+ function getOptions(defaultPlatform = (0, node_os_1.platform)(), defaultArch = (0, utils_js_1.normalizeSystemArchitecture)()) {
96
96
  return {
97
97
  binaries: {
98
98
  alias: 'b',
@@ -143,14 +143,14 @@ function getOptions(defaultPlatform = (0, node_os_1.platform)(), defaultArch = (
143
143
  description: 'Specify the architecture',
144
144
  // if `defaultArch` is not a supported Architecture yargs will throw an error
145
145
  default: defaultArch,
146
- choices: Object.values(types_1.Architecture),
146
+ choices: Object.values(types_js_1.Architecture),
147
147
  },
148
148
  platform: {
149
149
  alias: 'p',
150
150
  description: 'Specify the platform',
151
151
  // if `defaultPlatform` is not a supported Platform yargs will throw an error
152
152
  default: defaultPlatform,
153
- choices: Object.values(types_1.Platform),
153
+ choices: Object.values(types_js_1.Platform),
154
154
  },
155
155
  };
156
156
  }
@@ -1 +1 @@
1
- {"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,+CAA4C;AAC5C,wDAAgC;AAEhC,uCAAyD;AAQzD,uCAAsD;AAEtD;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;CAgBb,CAAC,CAAC;AACH,CAAC;AAlBD,kCAkBC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,OAAiB,mBAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,IAAA,eAAK,GAAE;QAClC,+DAA+D;SAC9D,MAAM,EAAE;QACT,yDAAyD;SACxD,OAAO,CAAC,KA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YACV,WAAW,EAAE,0BAA0B;YACvC,6EAA6E;YAC7E,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,oBAAY,CAAuB;SAC3D;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,sBAAsB;YACnC,6EAA6E;YAC7E,OAAO,EAAE,eAA2B;YACpC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAQ,CAAmB;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { platform } from 'node:os';\nimport { argv, stdout } from 'node:process';\nimport yargs from 'yargs/yargs';\n\nimport { Architecture, Binary, Platform } from './types';\nimport type {\n Checksums,\n ParsedOptions,\n ArchitecturesTuple,\n BinariesTuple,\n PlatformsTuple,\n} from './types';\nimport { normalizeSystemArchitecture } from './utils';\n\n/**\n * Type guard to check if a string is a valid version string starting with 'v'.\n *\n * @param value - The string to check\n * @returns True if the string is a valid version string\n */\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\n\n/**\n * Prints the Foundry banner to the console.\n */\nexport function printBanner() {\n console.log(`\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\n ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit\n ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development\n ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\nRepo : https://github.com/foundry-rs/\nBook : https://book.getfoundry.sh/\nChat : https://t.me/foundry_rs/\nSupport : https://t.me/foundry_support/\nContribute : https://github.com/orgs/foundry-rs/projects/2/\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n`);\n}\n\n/**\n * Parses command line arguments and returns the parsed options.\n *\n * @param args - Command line arguments to parse\n * @returns Parsed command line arguments\n */\nexport function parseArgs(args: string[] = argv.slice(2)) {\n const { $0, _, ...parsed } = yargs()\n // Ensure unrecognized commands/options are reported as errors.\n .strict()\n // disable yargs's version, as it doesn't make sense here\n .version(false)\n // use the scriptName in `--help` output\n .scriptName('yarn foundryup')\n // wrap output at a maximum of 120 characters or `stdout.columns`\n .wrap(Math.min(120, stdout.columns))\n .parserConfiguration({\n 'strip-aliased': true,\n 'strip-dashed': true,\n })\n // enable ENV parsing, which allows the user to specify foundryup options\n // via environment variables prefixed with `FOUNDRYUP_`\n .env('FOUNDRYUP')\n .command(['$0', 'install'], 'Install foundry binaries', (builder) => {\n builder.options(getOptions()).pkgConf('foundryup');\n })\n .command('cache', '', (builder) => {\n builder.command('clean', 'Remove the shared cache files').demandCommand();\n })\n .parseSync(args);\n\n const command = _.join(' ');\n if (command === 'cache clean') {\n return {\n command,\n } as const;\n }\n\n // if we get here `command` is always 'install' or '' (yargs checks it)\n return {\n command: 'install',\n options: parsed as ParsedOptions<ReturnType<typeof getOptions>>,\n } as const;\n}\n\nconst Binaries = Object.values(Binary) as BinariesTuple;\n\n/**\n * Returns the command line options configuration.\n *\n * @param defaultPlatform - Default platform to use\n * @param defaultArch - Default architecture to use\n * @returns Command line options configuration\n */\nfunction getOptions(\n defaultPlatform = platform(),\n defaultArch = normalizeSystemArchitecture(),\n) {\n return {\n binaries: {\n alias: 'b',\n type: 'array' as const,\n multiple: true,\n description: 'Specify the binaries to install',\n default: Binaries,\n choices: Binaries,\n coerce: (values: Binary[]): Binary[] => [...new Set(values)], // Remove duplicates\n },\n checksums: {\n alias: 'c',\n description: 'JSON object containing checksums for the binaries.',\n coerce: (rawChecksums: string | Checksums): Checksums => {\n try {\n return typeof rawChecksums === 'string'\n ? JSON.parse(rawChecksums)\n : rawChecksums;\n } catch {\n throw new Error('Invalid checksums');\n }\n },\n optional: true,\n },\n repo: {\n alias: 'r',\n description: 'Specify the repository',\n default: 'foundry-rs/foundry',\n },\n version: {\n alias: 'v',\n description:\n 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',\n default: 'nightly',\n coerce: (\n rawVersion: string,\n ): { version: 'nightly' | `v${string}`; tag: string } => {\n if (rawVersion.startsWith('nightly')) {\n return { version: 'nightly', tag: rawVersion };\n // we don't validate the version much, we just trust the user\n } else if (isVersionString(rawVersion)) {\n return { version: rawVersion, tag: rawVersion };\n }\n throw new Error('Invalid version');\n },\n },\n arch: {\n alias: 'a',\n description: 'Specify the architecture',\n // if `defaultArch` is not a supported Architecture yargs will throw an error\n default: defaultArch,\n choices: Object.values(Architecture) as ArchitecturesTuple,\n },\n platform: {\n alias: 'p',\n description: 'Specify the platform',\n // if `defaultPlatform` is not a supported Platform yargs will throw an error\n default: defaultPlatform as Platform,\n choices: Object.values(Platform) as PlatformsTuple,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,+CAA4C;AAC5C,wDAAgC;AAEhC,0CAA4D;AAQ5D,0CAAyD;AAEzD;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;CAgBb,CAAC,CAAC;AACH,CAAC;AAlBD,kCAkBC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,OAAiB,mBAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,IAAA,eAAK,GAAE;QAClC,+DAA+D;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C,CAAC;SACF;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,0BAA0B;YACvC,6EAA6E;YAC7E,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,uBAAY,CAAuB;SAC3D;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,sBAAsB;YACnC,6EAA6E;YAC7E,OAAO,EAAE,eAA2B;YACpC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAQ,CAAmB;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { platform } from 'node:os';\nimport { argv, stdout } from 'node:process';\nimport yargs from 'yargs/yargs';\n\nimport { Architecture, Binary, Platform } from './types.js';\nimport type {\n Checksums,\n ParsedOptions,\n ArchitecturesTuple,\n BinariesTuple,\n PlatformsTuple,\n} from './types.js';\nimport { normalizeSystemArchitecture } from './utils.js';\n\n/**\n * Type guard to check if a string is a valid version string starting with 'v'.\n *\n * @param value - The string to check\n * @returns True if the string is a valid version string\n */\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\n\n/**\n * Prints the Foundry banner to the console.\n */\nexport function printBanner() {\n console.log(`\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\n ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit\n ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development\n ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\nRepo : https://github.com/foundry-rs/\nBook : https://book.getfoundry.sh/\nChat : https://t.me/foundry_rs/\nSupport : https://t.me/foundry_support/\nContribute : https://github.com/orgs/foundry-rs/projects/2/\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n`);\n}\n\n/**\n * Parses command line arguments and returns the parsed options.\n *\n * @param args - Command line arguments to parse\n * @returns Parsed command line arguments\n */\nexport function parseArgs(args: string[] = argv.slice(2)) {\n const { $0, _, ...parsed } = yargs()\n // Ensure unrecognized commands/options are reported as errors.\n .strict()\n // disable yargs's version, as it doesn't make sense here\n .version(false)\n // use the scriptName in `--help` output\n .scriptName('yarn foundryup')\n // wrap output at a maximum of 120 characters or `stdout.columns`\n .wrap(Math.min(120, stdout.columns))\n .parserConfiguration({\n 'strip-aliased': true,\n 'strip-dashed': true,\n })\n // enable ENV parsing, which allows the user to specify foundryup options\n // via environment variables prefixed with `FOUNDRYUP_`\n .env('FOUNDRYUP')\n .command(['$0', 'install'], 'Install foundry binaries', (builder) => {\n builder.options(getOptions()).pkgConf('foundryup');\n })\n .command('cache', '', (builder) => {\n builder.command('clean', 'Remove the shared cache files').demandCommand();\n })\n .parseSync(args);\n\n const command = _.join(' ');\n if (command === 'cache clean') {\n return {\n command,\n } as const;\n }\n\n // if we get here `command` is always 'install' or '' (yargs checks it)\n return {\n command: 'install',\n options: parsed as ParsedOptions<ReturnType<typeof getOptions>>,\n } as const;\n}\n\nconst Binaries = Object.values(Binary) as BinariesTuple;\n\n/**\n * Returns the command line options configuration.\n *\n * @param defaultPlatform - Default platform to use\n * @param defaultArch - Default architecture to use\n * @returns Command line options configuration\n */\nfunction getOptions(\n defaultPlatform = platform(),\n defaultArch = normalizeSystemArchitecture(),\n) {\n return {\n binaries: {\n alias: 'b',\n type: 'array' as const,\n multiple: true,\n description: 'Specify the binaries to install',\n default: Binaries,\n choices: Binaries,\n coerce: (values: Binary[]): Binary[] => [...new Set(values)], // Remove duplicates\n },\n checksums: {\n alias: 'c',\n description: 'JSON object containing checksums for the binaries.',\n coerce: (rawChecksums: string | Checksums): Checksums => {\n try {\n return typeof rawChecksums === 'string'\n ? JSON.parse(rawChecksums)\n : rawChecksums;\n } catch {\n throw new Error('Invalid checksums');\n }\n },\n optional: true,\n },\n repo: {\n alias: 'r',\n description: 'Specify the repository',\n default: 'foundry-rs/foundry',\n },\n version: {\n alias: 'v',\n description:\n 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',\n default: 'nightly',\n coerce: (\n rawVersion: string,\n ): { version: 'nightly' | `v${string}`; tag: string } => {\n if (rawVersion.startsWith('nightly')) {\n return { version: 'nightly', tag: rawVersion };\n // we don't validate the version much, we just trust the user\n } else if (isVersionString(rawVersion)) {\n return { version: rawVersion, tag: rawVersion };\n }\n throw new Error('Invalid version');\n },\n },\n arch: {\n alias: 'a',\n description: 'Specify the architecture',\n // if `defaultArch` is not a supported Architecture yargs will throw an error\n default: defaultArch,\n choices: Object.values(Architecture) as ArchitecturesTuple,\n },\n platform: {\n alias: 'p',\n description: 'Specify the platform',\n // if `defaultPlatform` is not a supported Platform yargs will throw an error\n default: defaultPlatform as Platform,\n choices: Object.values(Platform) as PlatformsTuple,\n },\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAgB;AACzD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAId,oBAAgB;AAajB;;GAEG;AACH,wBAAgB,WAAW,SAkB1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
1
+ {"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAmB;AAC5D,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAId,oBAAmB;AAapB;;GAEG;AACH,wBAAgB,WAAW,SAkB1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAgB;AACzD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAId,oBAAgB;AAajB;;GAEG;AACH,wBAAgB,WAAW,SAkB1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
1
+ {"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAmB;AAC5D,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAId,oBAAmB;AAapB;;GAEG;AACH,wBAAgB,WAAW,SAkB1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.mjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,qBAAqB;AAC5C,OAAO,KAAK,oBAAoB;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAgB;AAQzD,OAAO,EAAE,2BAA2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B,MAAM,EAAE,CACN,UAAkB,EACkC,EAAE;gBACtD,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;oBACrC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;oBAC/C,6DAA6D;gBAC/D,CAAC;qBAAM,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;oBACvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;gBAClD,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACrC,CAAC;SACF;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,0BAA0B;YACvC,6EAA6E;YAC7E,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAuB;SAC3D;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,sBAAsB;YACnC,6EAA6E;YAC7E,OAAO,EAAE,eAA2B;YACpC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAmB;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { platform } from 'node:os';\nimport { argv, stdout } from 'node:process';\nimport yargs from 'yargs/yargs';\n\nimport { Architecture, Binary, Platform } from './types';\nimport type {\n Checksums,\n ParsedOptions,\n ArchitecturesTuple,\n BinariesTuple,\n PlatformsTuple,\n} from './types';\nimport { normalizeSystemArchitecture } from './utils';\n\n/**\n * Type guard to check if a string is a valid version string starting with 'v'.\n *\n * @param value - The string to check\n * @returns True if the string is a valid version string\n */\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\n\n/**\n * Prints the Foundry banner to the console.\n */\nexport function printBanner() {\n console.log(`\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\n ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit\n ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development\n ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\nRepo : https://github.com/foundry-rs/\nBook : https://book.getfoundry.sh/\nChat : https://t.me/foundry_rs/\nSupport : https://t.me/foundry_support/\nContribute : https://github.com/orgs/foundry-rs/projects/2/\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n`);\n}\n\n/**\n * Parses command line arguments and returns the parsed options.\n *\n * @param args - Command line arguments to parse\n * @returns Parsed command line arguments\n */\nexport function parseArgs(args: string[] = argv.slice(2)) {\n const { $0, _, ...parsed } = yargs()\n // Ensure unrecognized commands/options are reported as errors.\n .strict()\n // disable yargs's version, as it doesn't make sense here\n .version(false)\n // use the scriptName in `--help` output\n .scriptName('yarn foundryup')\n // wrap output at a maximum of 120 characters or `stdout.columns`\n .wrap(Math.min(120, stdout.columns))\n .parserConfiguration({\n 'strip-aliased': true,\n 'strip-dashed': true,\n })\n // enable ENV parsing, which allows the user to specify foundryup options\n // via environment variables prefixed with `FOUNDRYUP_`\n .env('FOUNDRYUP')\n .command(['$0', 'install'], 'Install foundry binaries', (builder) => {\n builder.options(getOptions()).pkgConf('foundryup');\n })\n .command('cache', '', (builder) => {\n builder.command('clean', 'Remove the shared cache files').demandCommand();\n })\n .parseSync(args);\n\n const command = _.join(' ');\n if (command === 'cache clean') {\n return {\n command,\n } as const;\n }\n\n // if we get here `command` is always 'install' or '' (yargs checks it)\n return {\n command: 'install',\n options: parsed as ParsedOptions<ReturnType<typeof getOptions>>,\n } as const;\n}\n\nconst Binaries = Object.values(Binary) as BinariesTuple;\n\n/**\n * Returns the command line options configuration.\n *\n * @param defaultPlatform - Default platform to use\n * @param defaultArch - Default architecture to use\n * @returns Command line options configuration\n */\nfunction getOptions(\n defaultPlatform = platform(),\n defaultArch = normalizeSystemArchitecture(),\n) {\n return {\n binaries: {\n alias: 'b',\n type: 'array' as const,\n multiple: true,\n description: 'Specify the binaries to install',\n default: Binaries,\n choices: Binaries,\n coerce: (values: Binary[]): Binary[] => [...new Set(values)], // Remove duplicates\n },\n checksums: {\n alias: 'c',\n description: 'JSON object containing checksums for the binaries.',\n coerce: (rawChecksums: string | Checksums): Checksums => {\n try {\n return typeof rawChecksums === 'string'\n ? JSON.parse(rawChecksums)\n : rawChecksums;\n } catch {\n throw new Error('Invalid checksums');\n }\n },\n optional: true,\n },\n repo: {\n alias: 'r',\n description: 'Specify the repository',\n default: 'foundry-rs/foundry',\n },\n version: {\n alias: 'v',\n description:\n 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',\n default: 'nightly',\n coerce: (\n rawVersion: string,\n ): { version: 'nightly' | `v${string}`; tag: string } => {\n if (rawVersion.startsWith('nightly')) {\n return { version: 'nightly', tag: rawVersion };\n // we don't validate the version much, we just trust the user\n } else if (isVersionString(rawVersion)) {\n return { version: rawVersion, tag: rawVersion };\n }\n throw new Error('Invalid version');\n },\n },\n arch: {\n alias: 'a',\n description: 'Specify the architecture',\n // if `defaultArch` is not a supported Architecture yargs will throw an error\n default: defaultArch,\n choices: Object.values(Architecture) as ArchitecturesTuple,\n },\n platform: {\n alias: 'p',\n description: 'Specify the platform',\n // if `defaultPlatform` is not a supported Platform yargs will throw an error\n default: defaultPlatform as Platform,\n choices: Object.values(Platform) as PlatformsTuple,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"options.mjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB;AACnC,OAAO,EAAE,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;YACV,WAAW,EAAE,wBAAwB;YACrC,OAAO,EAAE,oBAAoB;SAC9B;QACD,OAAO,EAAE;YACP,KAAK,EAAE,GAAG;YACV,WAAW,EACT,uEAAuE;YACzE,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,CACN,UAAkB,EACkC,EAAE;gBACtD,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;oBACrC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;oBAC/C,6DAA6D;gBAC/D,CAAC;qBAAM,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;oBACvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;gBAClD,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACrC,CAAC;SACF;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,0BAA0B;YACvC,6EAA6E;YAC7E,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAuB;SAC3D;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,sBAAsB;YACnC,6EAA6E;YAC7E,OAAO,EAAE,eAA2B;YACpC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAmB;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { platform } from 'node:os';\nimport { argv, stdout } from 'node:process';\nimport yargs from 'yargs/yargs';\n\nimport { Architecture, Binary, Platform } from './types.js';\nimport type {\n Checksums,\n ParsedOptions,\n ArchitecturesTuple,\n BinariesTuple,\n PlatformsTuple,\n} from './types.js';\nimport { normalizeSystemArchitecture } from './utils.js';\n\n/**\n * Type guard to check if a string is a valid version string starting with 'v'.\n *\n * @param value - The string to check\n * @returns True if the string is a valid version string\n */\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\n\n/**\n * Prints the Foundry banner to the console.\n */\nexport function printBanner() {\n console.log(`\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\n ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit\n ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development\n ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\nRepo : https://github.com/foundry-rs/\nBook : https://book.getfoundry.sh/\nChat : https://t.me/foundry_rs/\nSupport : https://t.me/foundry_support/\nContribute : https://github.com/orgs/foundry-rs/projects/2/\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n`);\n}\n\n/**\n * Parses command line arguments and returns the parsed options.\n *\n * @param args - Command line arguments to parse\n * @returns Parsed command line arguments\n */\nexport function parseArgs(args: string[] = argv.slice(2)) {\n const { $0, _, ...parsed } = yargs()\n // Ensure unrecognized commands/options are reported as errors.\n .strict()\n // disable yargs's version, as it doesn't make sense here\n .version(false)\n // use the scriptName in `--help` output\n .scriptName('yarn foundryup')\n // wrap output at a maximum of 120 characters or `stdout.columns`\n .wrap(Math.min(120, stdout.columns))\n .parserConfiguration({\n 'strip-aliased': true,\n 'strip-dashed': true,\n })\n // enable ENV parsing, which allows the user to specify foundryup options\n // via environment variables prefixed with `FOUNDRYUP_`\n .env('FOUNDRYUP')\n .command(['$0', 'install'], 'Install foundry binaries', (builder) => {\n builder.options(getOptions()).pkgConf('foundryup');\n })\n .command('cache', '', (builder) => {\n builder.command('clean', 'Remove the shared cache files').demandCommand();\n })\n .parseSync(args);\n\n const command = _.join(' ');\n if (command === 'cache clean') {\n return {\n command,\n } as const;\n }\n\n // if we get here `command` is always 'install' or '' (yargs checks it)\n return {\n command: 'install',\n options: parsed as ParsedOptions<ReturnType<typeof getOptions>>,\n } as const;\n}\n\nconst Binaries = Object.values(Binary) as BinariesTuple;\n\n/**\n * Returns the command line options configuration.\n *\n * @param defaultPlatform - Default platform to use\n * @param defaultArch - Default architecture to use\n * @returns Command line options configuration\n */\nfunction getOptions(\n defaultPlatform = platform(),\n defaultArch = normalizeSystemArchitecture(),\n) {\n return {\n binaries: {\n alias: 'b',\n type: 'array' as const,\n multiple: true,\n description: 'Specify the binaries to install',\n default: Binaries,\n choices: Binaries,\n coerce: (values: Binary[]): Binary[] => [...new Set(values)], // Remove duplicates\n },\n checksums: {\n alias: 'c',\n description: 'JSON object containing checksums for the binaries.',\n coerce: (rawChecksums: string | Checksums): Checksums => {\n try {\n return typeof rawChecksums === 'string'\n ? JSON.parse(rawChecksums)\n : rawChecksums;\n } catch {\n throw new Error('Invalid checksums');\n }\n },\n optional: true,\n },\n repo: {\n alias: 'r',\n description: 'Specify the repository',\n default: 'foundry-rs/foundry',\n },\n version: {\n alias: 'v',\n description:\n 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',\n default: 'nightly',\n coerce: (\n rawVersion: string,\n ): { version: 'nightly' | `v${string}`; tag: string } => {\n if (rawVersion.startsWith('nightly')) {\n return { version: 'nightly', tag: rawVersion };\n // we don't validate the version much, we just trust the user\n } else if (isVersionString(rawVersion)) {\n return { version: rawVersion, tag: rawVersion };\n }\n throw new Error('Invalid version');\n },\n },\n arch: {\n alias: 'a',\n description: 'Specify the architecture',\n // if `defaultArch` is not a supported Architecture yargs will throw an error\n default: defaultArch,\n choices: Object.values(Architecture) as ArchitecturesTuple,\n },\n platform: {\n alias: 'p',\n description: 'Specify the platform',\n // if `defaultPlatform` is not a supported Platform yargs will throw an error\n default: defaultPlatform as Platform,\n choices: Object.values(Platform) as PlatformsTuple,\n },\n };\n}\n"]}
package/dist/utils.cjs CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformChecksums = exports.isCodedError = exports.getVersion = exports.say = exports.normalizeSystemArchitecture = exports.noop = void 0;
4
4
  const node_child_process_1 = require("node:child_process");
5
5
  const node_os_1 = require("node:os");
6
- const types_1 = require("./types.cjs");
6
+ const types_js_1 = require("./types.cjs");
7
7
  /**
8
8
  * No Operation. A function that does nothing and returns nothing.
9
9
  *
@@ -21,7 +21,7 @@ exports.noop = noop;
21
21
  function normalizeSystemArchitecture(architecture = (0, node_os_1.arch)()) {
22
22
  if (architecture.startsWith('arm')) {
23
23
  // if `arm*`, use `arm64`
24
- return types_1.Architecture.Arm64;
24
+ return types_js_1.Architecture.Arm64;
25
25
  }
26
26
  else if (architecture === 'x64') {
27
27
  // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon
@@ -31,14 +31,14 @@ function normalizeSystemArchitecture(architecture = (0, node_os_1.arch)()) {
31
31
  // binaries native to the system for better performance.
32
32
  try {
33
33
  if ((0, node_child_process_1.execSync)('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {
34
- return types_1.Architecture.Arm64;
34
+ return types_js_1.Architecture.Arm64;
35
35
  }
36
36
  }
37
37
  catch {
38
38
  // Ignore error: if sysctl check fails, we assume native amd64
39
39
  }
40
40
  }
41
- return types_1.Architecture.Amd64; // Default for all other architectures
41
+ return types_js_1.Architecture.Amd64; // Default for all other architectures
42
42
  }
43
43
  exports.normalizeSystemArchitecture = normalizeSystemArchitecture;
44
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2DAA4D;AAC5D,qCAA+B;AAE/B,uCAAuC;AAQvC;;;;GAIG;AACI,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;AAAvB,QAAA,IAAI,QAAm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AC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAdD,gCAcC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAC1B,KAAc;IAEd,OAAO,CACL,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC5E,CAAC;AACJ,CAAC;AAND,oCAMC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAAgC,EAChC,cAAwB,EACxB,UAAwB;IAExB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,cAAc,IAAI,UAAU,EAAW,CAAC;IACvD,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACtB,GAAG,CAAC,IAAc,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B;KACF,CAAC;AACJ,CAAC;AApBD,gDAoBC","sourcesContent":["import { execFileSync, execSync } from 'node:child_process';\nimport { arch } from 'node:os';\n\nimport { Architecture } from './types';\nimport type {\n Checksums,\n PlatformArchChecksums,\n Binary,\n Platform,\n} from './types';\n\n/**\n * No Operation. A function that does nothing and returns nothing.\n *\n * @returns `undefined`\n */\nexport const noop = () => undefined;\n\n/**\n * Returns the system architecture, normalized to one of the supported\n * {@link Architecture} values.\n *\n * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')\n * @returns The normalized architecture value\n */\nexport function normalizeSystemArchitecture(\n architecture: string = arch(),\n): Architecture {\n if (architecture.startsWith('arm')) {\n // if `arm*`, use `arm64`\n return Architecture.Arm64;\n } else if (architecture === 'x64') {\n // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon\n // (arm64). we can check this by running `sysctl.proc_translated` and\n // checking the output; `1` === `arm64`. This can happen if the user is\n // running an amd64 version of Node on Apple Silicon. We want to use the\n // binaries native to the system for better performance.\n try {\n if (execSync('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {\n return Architecture.Arm64;\n }\n } catch {\n // Ignore error: if sysctl check fails, we assume native amd64\n }\n }\n\n return Architecture.Amd64; // Default for all other architectures\n}\n\n/**\n * Log a message to the console.\n *\n * @param message - The message to log\n */\nexport function say(message: string) {\n console.log(`[foundryup] ${message}`);\n}\n\n/**\n * Get the version of the binary at the given path.\n *\n * @param binPath - Path to the binary executable\n * @returns The `--version` reported by the binary\n * @throws If the binary fails to report its version\n */\nexport function getVersion(binPath: string): Buffer {\n try {\n return execFileSync(binPath, ['--version']).subarray(0, -1); // ignore newline\n } catch (error: unknown) {\n const msg = `Failed to get version for ${binPath}\n\nYour selected platform or architecture may be incorrect, or the binary may not\nsupport your system. If you believe this is an error, please report it.`;\n if (error instanceof Error) {\n error.message = `${msg}\\n\\n${error.message}`;\n throw error;\n }\n throw new AggregateError([new Error(msg), error]);\n }\n}\n\n/**\n * Type guard to check if an error has a code property.\n *\n * @param error - The error to check\n * @returns True if the error has a code property\n */\nexport function isCodedError(\n error: unknown,\n): error is Error & { code: string } {\n return (\n error instanceof Error && 'code' in error && typeof error.code === 'string'\n );\n}\n\n/**\n * Transforms the CLI checksum object into a platform+arch-specific checksum\n * object.\n *\n * @param checksums - The CLI checksum object\n * @param targetPlatform - The build platform\n * @param targetArch - The build architecture\n * @returns Platform and architecture specific checksums or null if no checksums provided\n */\nexport function transformChecksums(\n checksums: Checksums | undefined,\n targetPlatform: Platform,\n targetArch: Architecture,\n): PlatformArchChecksums | null {\n if (!checksums) {\n return null;\n }\n\n const key = `${targetPlatform}-${targetArch}` as const;\n return {\n algorithm: checksums.algorithm,\n binaries: Object.entries(checksums.binaries).reduce(\n (acc, [name, record]) => {\n acc[name as Binary] = record[key];\n return acc;\n },\n {} as Record<Binary, string>,\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2DAA4D;AAC5D,qCAA+B;AAE/B,0CAA0C;AAQ1C;;;;GAIG;AACI,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;AAAvB,QAAA,IAAI,QAAmB;AAEpC;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACzC,eAAuB,IAAA,cAAI,GAAE;IAE7B,IAAI,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,yBAAyB;QACzB,OAAO,uBAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;SAAM,IAAI,YAAY,KAAK,KAAK,EAAE,CAAC;QAClC,qEAAqE;QACrE,qEAAqE;QACrE,uEAAuE;QACvE,wEAAwE;QACxE,wDAAwD;QACxD,IAAI,CAAC;YACH,IAAI,IAAA,6BAAQ,EAAC,8CAA8C,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtE,OAAO,uBAAY,CAAC,KAAK,CAAC;YAC5B,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,8DAA8D;QAChE,CAAC;IACH,CAAC;IAED,OAAO,uBAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;AACnE,CAAC;AAtBD,kEAsBC;AAED;;;;GAIG;AACH,SAAgB,GAAG,CAAC,OAAe;IACjC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC;AAFD,kBAEC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,OAAe;IACxC,IAAI,CAAC;QACH,OAAO,IAAA,iCAAY,EAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC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\n\nimport { Architecture } from './types.js';\nimport type {\n Checksums,\n PlatformArchChecksums,\n Binary,\n Platform,\n} from './types.js';\n\n/**\n * No Operation. A function that does nothing and returns nothing.\n *\n * @returns `undefined`\n */\nexport const noop = () => undefined;\n\n/**\n * Returns the system architecture, normalized to one of the supported\n * {@link Architecture} values.\n *\n * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')\n * @returns The normalized architecture value\n */\nexport function normalizeSystemArchitecture(\n architecture: string = arch(),\n): Architecture {\n if (architecture.startsWith('arm')) {\n // if `arm*`, use `arm64`\n return Architecture.Arm64;\n } else if (architecture === 'x64') {\n // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon\n // (arm64). we can check this by running `sysctl.proc_translated` and\n // checking the output; `1` === `arm64`. This can happen if the user is\n // running an amd64 version of Node on Apple Silicon. We want to use the\n // binaries native to the system for better performance.\n try {\n if (execSync('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {\n return Architecture.Arm64;\n }\n } catch {\n // Ignore error: if sysctl check fails, we assume native amd64\n }\n }\n\n return Architecture.Amd64; // Default for all other architectures\n}\n\n/**\n * Log a message to the console.\n *\n * @param message - The message to log\n */\nexport function say(message: string) {\n console.log(`[foundryup] ${message}`);\n}\n\n/**\n * Get the version of the binary at the given path.\n *\n * @param binPath - Path to the binary executable\n * @returns The `--version` reported by the binary\n * @throws If the binary fails to report its version\n */\nexport function getVersion(binPath: string): Buffer {\n try {\n return execFileSync(binPath, ['--version']).subarray(0, -1); // ignore newline\n } catch (error: unknown) {\n const msg = `Failed to get version for ${binPath}\n\nYour selected platform or architecture may be incorrect, or the binary may not\nsupport your system. If you believe this is an error, please report it.`;\n if (error instanceof Error) {\n error.message = `${msg}\\n\\n${error.message}`;\n throw error;\n }\n throw new AggregateError([new Error(msg), error]);\n }\n}\n\n/**\n * Type guard to check if an error has a code property.\n *\n * @param error - The error to check\n * @returns True if the error has a code property\n */\nexport function isCodedError(\n error: unknown,\n): error is Error & { code: string } {\n return (\n error instanceof Error && 'code' in error && typeof error.code === 'string'\n );\n}\n\n/**\n * Transforms the CLI checksum object into a platform+arch-specific checksum\n * object.\n *\n * @param checksums - The CLI checksum object\n * @param targetPlatform - The build platform\n * @param targetArch - The build architecture\n * @returns Platform and architecture specific checksums or null if no checksums provided\n */\nexport function transformChecksums(\n checksums: Checksums | undefined,\n targetPlatform: Platform,\n targetArch: Architecture,\n): PlatformArchChecksums | null {\n if (!checksums) {\n return null;\n }\n\n const key = `${targetPlatform}-${targetArch}` as const;\n return {\n algorithm: checksums.algorithm,\n binaries: Object.entries(checksums.binaries).reduce(\n (acc, [name, record]) => {\n acc[name as Binary] = record[key];\n return acc;\n },\n {} as Record<Binary, string>,\n ),\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,oBAAgB;AACvC,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,QAAQ,EACT,oBAAgB;AAEjB;;;;GAIG;AACH,eAAO,MAAM,IAAI,iBAAkB,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,GAAE,MAAe,GAC5B,YAAY,CAoBd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,YAAY,GACvB,qBAAqB,GAAG,IAAI,CAgB9B"}
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAC1C,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,QAAQ,EACT,oBAAmB;AAEpB;;;;GAIG;AACH,eAAO,MAAM,IAAI,iBAAkB,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,GAAE,MAAe,GAC5B,YAAY,CAoBd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,YAAY,GACvB,qBAAqB,GAAG,IAAI,CAgB9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,oBAAgB;AACvC,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,QAAQ,EACT,oBAAgB;AAEjB;;;;GAIG;AACH,eAAO,MAAM,IAAI,iBAAkB,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,GAAE,MAAe,GAC5B,YAAY,CAoBd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,YAAY,GACvB,qBAAqB,GAAG,IAAI,CAgB9B"}
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAC1C,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,QAAQ,EACT,oBAAmB;AAEpB;;;;GAIG;AACH,eAAO,MAAM,IAAI,iBAAkB,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,GAAE,MAAe,GAC5B,YAAY,CAoBd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,YAAY,GACvB,qBAAqB,GAAG,IAAI,CAgB9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,2BAA2B;AAC5D,OAAO,EAAE,IAAI,EAAE,gBAAgB;AAE/B,OAAO,EAAE,YAAY,EAAE,oB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AAC;QACd,CAAC;QACD,MAAM,IAAI,cAAc,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAc;IAEd,OAAO,CACL,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC5E,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAgC,EAChC,cAAwB,EACxB,UAAwB;IAExB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,cAAc,IAAI,UAAU,EAAW,CAAC;IACvD,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACtB,GAAG,CAAC,IAAc,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { execFileSync, execSync } from 'node:child_process';\nimport { arch } from 'node:os';\n\nimport { Architecture } from './types';\nimport type {\n Checksums,\n PlatformArchChecksums,\n Binary,\n Platform,\n} from './types';\n\n/**\n * No Operation. A function that does nothing and returns nothing.\n *\n * @returns `undefined`\n */\nexport const noop = () => undefined;\n\n/**\n * Returns the system architecture, normalized to one of the supported\n * {@link Architecture} values.\n *\n * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')\n * @returns The normalized architecture value\n */\nexport function normalizeSystemArchitecture(\n architecture: string = arch(),\n): Architecture {\n if (architecture.startsWith('arm')) {\n // if `arm*`, use `arm64`\n return Architecture.Arm64;\n } else if (architecture === 'x64') {\n // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon\n // (arm64). we can check this by running `sysctl.proc_translated` and\n // checking the output; `1` === `arm64`. This can happen if the user is\n // running an amd64 version of Node on Apple Silicon. We want to use the\n // binaries native to the system for better performance.\n try {\n if (execSync('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {\n return Architecture.Arm64;\n }\n } catch {\n // Ignore error: if sysctl check fails, we assume native amd64\n }\n }\n\n return Architecture.Amd64; // Default for all other architectures\n}\n\n/**\n * Log a message to the console.\n *\n * @param message - The message to log\n */\nexport function say(message: string) {\n console.log(`[foundryup] ${message}`);\n}\n\n/**\n * Get the version of the binary at the given path.\n *\n * @param binPath - Path to the binary executable\n * @returns The `--version` reported by the binary\n * @throws If the binary fails to report its version\n */\nexport function getVersion(binPath: string): Buffer {\n try {\n return execFileSync(binPath, ['--version']).subarray(0, -1); // ignore newline\n } catch (error: unknown) {\n const msg = `Failed to get version for ${binPath}\n\nYour selected platform or architecture may be incorrect, or the binary may not\nsupport your system. If you believe this is an error, please report it.`;\n if (error instanceof Error) {\n error.message = `${msg}\\n\\n${error.message}`;\n throw error;\n }\n throw new AggregateError([new Error(msg), error]);\n }\n}\n\n/**\n * Type guard to check if an error has a code property.\n *\n * @param error - The error to check\n * @returns True if the error has a code property\n */\nexport function isCodedError(\n error: unknown,\n): error is Error & { code: string } {\n return (\n error instanceof Error && 'code' in error && typeof error.code === 'string'\n );\n}\n\n/**\n * Transforms the CLI checksum object into a platform+arch-specific checksum\n * object.\n *\n * @param checksums - The CLI checksum object\n * @param targetPlatform - The build platform\n * @param targetArch - The build architecture\n * @returns Platform and architecture specific checksums or null if no checksums provided\n */\nexport function transformChecksums(\n checksums: Checksums | undefined,\n targetPlatform: Platform,\n targetArch: Architecture,\n): PlatformArchChecksums | null {\n if (!checksums) {\n return null;\n }\n\n const key = `${targetPlatform}-${targetArch}` as const;\n return {\n algorithm: checksums.algorithm,\n binaries: Object.entries(checksums.binaries).reduce(\n (acc, [name, record]) => {\n acc[name as Binary] = record[key];\n return acc;\n },\n {} as Record<Binary, string>,\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,2BAA2B;AAC5D,OAAO,EAAE,IAAI,EAAE,gBAAgB;AAE/B,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAQ1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CACzC,eAAuB,IAAI,EAAE;IAE7B,IAAI,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,yBAAyB;QACzB,OAAO,YAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;SAAM,IAAI,YAAY,KAAK,KAAK,EAAE,CAAC;QAClC,qEAAqE;QACrE,qEAAqE;QACrE,uEAAuE;QACvE,wEAAwE;QACxE,wDAAwD;QACxD,IAAI,CAAC;YACH,IAAI,QAAQ,CAAC,8CAA8C,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtE,OAAO,YAAY,CAAC,KAAK,CAAC;YAC5B,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,8DAA8D;QAChE,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,OAAe;IACjC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,EAAE,C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nimport { arch } from 'node:os';\n\nimport { Architecture } from './types.js';\nimport type {\n Checksums,\n PlatformArchChecksums,\n Binary,\n Platform,\n} from './types.js';\n\n/**\n * No Operation. A function that does nothing and returns nothing.\n *\n * @returns `undefined`\n */\nexport const noop = () => undefined;\n\n/**\n * Returns the system architecture, normalized to one of the supported\n * {@link Architecture} values.\n *\n * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')\n * @returns The normalized architecture value\n */\nexport function normalizeSystemArchitecture(\n architecture: string = arch(),\n): Architecture {\n if (architecture.startsWith('arm')) {\n // if `arm*`, use `arm64`\n return Architecture.Arm64;\n } else if (architecture === 'x64') {\n // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon\n // (arm64). we can check this by running `sysctl.proc_translated` and\n // checking the output; `1` === `arm64`. This can happen if the user is\n // running an amd64 version of Node on Apple Silicon. We want to use the\n // binaries native to the system for better performance.\n try {\n if (execSync('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {\n return Architecture.Arm64;\n }\n } catch {\n // Ignore error: if sysctl check fails, we assume native amd64\n }\n }\n\n return Architecture.Amd64; // Default for all other architectures\n}\n\n/**\n * Log a message to the console.\n *\n * @param message - The message to log\n */\nexport function say(message: string) {\n console.log(`[foundryup] ${message}`);\n}\n\n/**\n * Get the version of the binary at the given path.\n *\n * @param binPath - Path to the binary executable\n * @returns The `--version` reported by the binary\n * @throws If the binary fails to report its version\n */\nexport function getVersion(binPath: string): Buffer {\n try {\n return execFileSync(binPath, ['--version']).subarray(0, -1); // ignore newline\n } catch (error: unknown) {\n const msg = `Failed to get version for ${binPath}\n\nYour selected platform or architecture may be incorrect, or the binary may not\nsupport your system. If you believe this is an error, please report it.`;\n if (error instanceof Error) {\n error.message = `${msg}\\n\\n${error.message}`;\n throw error;\n }\n throw new AggregateError([new Error(msg), error]);\n }\n}\n\n/**\n * Type guard to check if an error has a code property.\n *\n * @param error - The error to check\n * @returns True if the error has a code property\n */\nexport function isCodedError(\n error: unknown,\n): error is Error & { code: string } {\n return (\n error instanceof Error && 'code' in error && typeof error.code === 'string'\n );\n}\n\n/**\n * Transforms the CLI checksum object into a platform+arch-specific checksum\n * object.\n *\n * @param checksums - The CLI checksum object\n * @param targetPlatform - The build platform\n * @param targetArch - The build architecture\n * @returns Platform and architecture specific checksums or null if no checksums provided\n */\nexport function transformChecksums(\n checksums: Checksums | undefined,\n targetPlatform: Platform,\n targetArch: Architecture,\n): PlatformArchChecksums | null {\n if (!checksums) {\n return null;\n }\n\n const key = `${targetPlatform}-${targetArch}` as const;\n return {\n algorithm: checksums.algorithm,\n binaries: Object.entries(checksums.binaries).reduce(\n (acc, [name, record]) => {\n acc[name as Binary] = record[key];\n return acc;\n },\n {} as Record<Binary, string>,\n ),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/foundryup",
3
- "version": "1.0.1-preview-0dfe3b334",
3
+ "version": "1.0.1-preview-a3e31582e",
4
4
  "description": "foundryup",
5
5
  "keywords": [
6
6
  "Ethereum",