@metamask-previews/foundryup 1.0.1-preview-159e76e4 → 1.0.1-preview-5c1b2b1
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/download.cjs.map +1 -1
- package/dist/download.d.cts +1 -1
- package/dist/download.d.cts.map +1 -1
- package/dist/download.d.mts +1 -1
- package/dist/download.d.mts.map +1 -1
- package/dist/download.mjs.map +1 -1
- package/dist/extract.cjs.map +1 -1
- package/dist/extract.d.cts +1 -1
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +1 -1
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs.map +1 -1
- package/dist/options.cjs.map +1 -1
- package/dist/options.d.cts +2 -1
- package/dist/options.d.cts.map +1 -1
- package/dist/options.d.mts +2 -1
- package/dist/options.d.mts.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
package/dist/download.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.cjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;;AAAA,
|
|
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,OAA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M,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';\n\n/**\n * A PassThrough stream that emits a 'response' event when the HTTP(S) response is available.\n */\nclass DownloadStream extends Stream.PassThrough {\n /**\n * Returns a promise that resolves with the HTTP(S) IncomingMessage response.\n *\n * @returns The HTTP(S) response stream.\n */\n async response(): Promise<IncomingMessage> {\n return new Promise((resolve, reject) => {\n this.once('response', resolve);\n this.once('error', reject);\n });\n }\n}\n\n/**\n * Starts a download from the given URL.\n *\n * @param url - The URL to download from\n * @param options - The download options\n * @param redirects - The number of redirects that have occurred\n * @returns A stream of the download\n */\nexport function startDownload(\n url: URL,\n options: DownloadOptions = {},\n redirects: number = 0,\n) {\n const MAX_REDIRECTS = options.maxRedirects ?? 5;\n const request = url.protocol === 'http:' ? httpRequest : httpsRequest;\n const stream = new DownloadStream();\n request(url, options, (response) => {\n stream.once('close', () => {\n response.destroy();\n });\n\n const { statusCode, statusMessage, headers } = response;\n // handle redirects\n if (\n statusCode &&\n statusCode >= 300 &&\n statusCode < 400 &&\n headers.location\n ) {\n if (redirects >= MAX_REDIRECTS) {\n stream.emit('error', new Error('Too many redirects'));\n response.destroy();\n } else {\n // note: we don't emit a response until we're done redirecting, because\n // handlers only expect it to be emitted once.\n pipeline(\n startDownload(new URL(headers.location, url), options, redirects + 1)\n // emit the response event to the stream\n .once('response', stream.emit.bind(stream, 'response')),\n stream,\n ).catch(stream.emit.bind(stream, 'error'));\n response.destroy();\n }\n }\n\n // check for HTTP errors\n else if (!statusCode || statusCode < 200 || statusCode >= 300) {\n stream.emit(\n 'error',\n new Error(\n `Request to ${url} failed. Status Code: ${statusCode} - ${statusMessage}`,\n ),\n );\n response.destroy();\n } else {\n // resolve with response stream\n stream.emit('response', response);\n\n response.once('error', stream.emit.bind(stream, 'error'));\n pipeline(response, stream).catch(stream.emit.bind(stream, 'error'));\n }\n })\n .once('error', stream.emit.bind(stream, 'error'))\n .end();\n return stream;\n}\n"]}
|
package/dist/download.d.cts
CHANGED
package/dist/download.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.cts","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;
|
|
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"}
|
package/dist/download.d.mts
CHANGED
package/dist/download.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.mts","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;
|
|
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"}
|
package/dist/download.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.mjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,
|
|
1
|
+
{"version":3,"file":"download.mjs","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,O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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';\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.map
CHANGED
|
@@ -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;AAC5C,uCAAyD;AAEzD,6CAA2C;AAC3C,uCAAiD;AACjD,uCAA8B;AAE9B;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACI,KAAK,UAAU,WAAW,CAC/B,GAAQ,EACR,QAAkB,EAClB,GAAW,EACX,SAAyE;IAEzE,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,iBAAS,CAAC,GAAG,CAAC;QAChE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,cAAc,CAAC;IACnB,2EAA2E;IAC3E,mEAAmE;IACnE,4EAA4E;IAC5E,0BAA0B;IAC1B,MAAM,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC;IACrC,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,CAAC;QACH,8CAA8C;QAC9C,MAAM,IAAA,aAAE,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,0DAA0D;QAC1D,MAAM,IAAA,gBAAK,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE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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, type Source, type Entry } from 'unzipper';\n\nimport { startDownload } from './download';\nimport { Extension, 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,yCAA+C;AAC/C,2CAAiD;AACjD,yCAA8D;AAC9D,mDAAgD;AAChD,6BAA4C;AAC5C,uCAAgC;AAGhC,6CAA2C;AAC3C,uCAAoC;AAEpC,uCAA8B;AAE9B;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACI,KAAK,UAAU,WAAW,CAC/B,GAAQ,EACR,QAAkB,EAClB,GAAW,EACX,SAAyE;IAEzE,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,iBAAS,CAAC,GAAG,CAAC;QAChE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,cAAc,CAAC;IACnB,2EAA2E;IAC3E,mEAAmE;IACnE,4EAA4E;IAC5E,0BAA0B;IAC1B,MAAM,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC;IACrC,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,CAAC;QACH,8CAA8C;QAC9C,MAAM,IAAA,aAAE,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,0DAA0D;QAC1D,MAAM,IAAA,gB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C,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"]}
|
package/dist/extract.d.cts
CHANGED
package/dist/extract.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.cts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/extract.d.mts
CHANGED
package/dist/extract.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.mts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract.d.mts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAGtC;;;;;;;;GAQG;AAEH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I,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, type Source, type Entry } from 'unzipper';\n\nimport { startDownload } from './download';\nimport { Extension, 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,OAAO,EAAE,aAAa,EA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AAC,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';\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"]}
|
package/dist/options.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,+CAA4C;AAC5C,wDAAgC;AAEhC,
|
|
1
|
+
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,+CAA4C;AAC5C,wDAAgC;AAEhC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ACV,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,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"]}
|
package/dist/options.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Architecture, Binary, Platform } from "./types.cjs";
|
|
2
|
+
import type { Checksums, ParsedOptions } from "./types.cjs";
|
|
2
3
|
/**
|
|
3
4
|
* Prints the Foundry banner to the console.
|
|
4
5
|
*/
|
package/dist/options.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
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"}
|
package/dist/options.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Architecture, Binary, Platform } from "./types.mjs";
|
|
2
|
+
import type { Checksums, ParsedOptions } from "./types.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Prints the Foundry banner to the console.
|
|
4
5
|
*/
|
package/dist/options.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
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"}
|
package/dist/options.mjs.map
CHANGED
|
@@ -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,
|
|
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,2BAA2B,EAAE,oBAAgB;AAEtD;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;CAgBb,CAAC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,OAAiB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,EAAE;QAClC,+DAA+D;SAC9D,MAAM,EAAE;QACT,yDAAyD;SACxD,OAAO,CAAC,KAAK,CAAC;QACf,wCAAwC;SACvC,UAAU,CAAC,gBAAgB,CAAC;QAC7B,iEAAiE;SAChE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GA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;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"]}
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2DAA4D;AAC5D,qCAA+B;AAE/B,
|
|
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,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,oBAAY,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,IA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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"]}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { Architecture } from "./types.cjs";
|
|
3
|
+
import type { Checksums, PlatformArchChecksums, Platform } from "./types.cjs";
|
|
3
4
|
/**
|
|
4
5
|
* No Operation. A function that does nothing and returns nothing.
|
|
5
6
|
*
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAGA,OAAO,
|
|
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"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { Architecture } from "./types.mjs";
|
|
3
|
+
import type { Checksums, PlatformArchChecksums, Platform } from "./types.mjs";
|
|
3
4
|
/**
|
|
4
5
|
* No Operation. A function that does nothing and returns nothing.
|
|
5
6
|
*
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAGA,OAAO,
|
|
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"}
|
package/dist/utils.mjs.map
CHANGED
|
@@ -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,
|
|
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,YA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AAM,KAAK,CAAC;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"]}
|