@metamask-previews/foundryup 1.0.1-preview-4f4c98e → 1.0.1-preview-eb263b0ee

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/dist/cli.cjs +23 -0
  3. package/dist/cli.cjs.map +1 -0
  4. package/dist/cli.d.cts +3 -0
  5. package/dist/cli.d.cts.map +1 -0
  6. package/dist/cli.d.mts +3 -0
  7. package/dist/cli.d.mts.map +1 -0
  8. package/dist/{cli.js → cli.mjs} +2 -2
  9. package/dist/cli.mjs.map +1 -0
  10. package/dist/download.cjs +76 -0
  11. package/dist/download.cjs.map +1 -0
  12. package/dist/{download.d.ts → download.d.cts} +9 -4
  13. package/dist/download.d.cts.map +1 -0
  14. package/dist/download.d.mts +30 -0
  15. package/dist/download.d.mts.map +1 -0
  16. package/dist/{download.js → download.mjs} +5 -5
  17. package/dist/download.mjs.map +1 -0
  18. package/dist/extract.cjs +205 -0
  19. package/dist/extract.cjs.map +1 -0
  20. package/dist/{extract.d.ts → extract.d.cts} +2 -2
  21. package/dist/extract.d.cts.map +1 -0
  22. package/dist/extract.d.mts +24 -0
  23. package/dist/extract.d.mts.map +1 -0
  24. package/dist/{extract.js → extract.mjs} +15 -15
  25. package/dist/extract.mjs.map +1 -0
  26. package/dist/index.cjs +163 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/{index.d.ts → index.d.cts} +7 -4
  29. package/dist/index.d.cts.map +1 -0
  30. package/dist/index.d.mts +56 -0
  31. package/dist/index.d.mts.map +1 -0
  32. package/dist/{index.js → index.mjs} +12 -12
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/options.cjs +157 -0
  35. package/dist/options.cjs.map +1 -0
  36. package/dist/options.d.cts +62 -0
  37. package/dist/options.d.cts.map +1 -0
  38. package/dist/options.d.mts +62 -0
  39. package/dist/options.d.mts.map +1 -0
  40. package/dist/{options.js → options.mjs} +6 -6
  41. package/dist/options.mjs.map +1 -0
  42. package/dist/types.cjs +30 -0
  43. package/dist/types.cjs.map +1 -0
  44. package/dist/{types.d.ts → types.d.cts} +10 -4
  45. package/dist/types.d.cts.map +1 -0
  46. package/dist/types.d.mts +78 -0
  47. package/dist/types.d.mts.map +1 -0
  48. package/dist/{types.js → types.mjs} +1 -1
  49. package/dist/types.mjs.map +1 -0
  50. package/dist/utils.cjs +110 -0
  51. package/dist/utils.cjs.map +1 -0
  52. package/dist/{utils.d.ts → utils.d.cts} +3 -3
  53. package/dist/utils.d.cts.map +1 -0
  54. package/dist/utils.d.mts +50 -0
  55. package/dist/utils.d.mts.map +1 -0
  56. package/dist/{utils.js → utils.mjs} +4 -4
  57. package/dist/utils.mjs.map +1 -0
  58. package/package.json +9 -11
  59. package/dist/cli.d.ts +0 -3
  60. package/dist/cli.d.ts.map +0 -1
  61. package/dist/cli.js.map +0 -1
  62. package/dist/download.d.ts.map +0 -1
  63. package/dist/download.js.map +0 -1
  64. package/dist/extract.d.ts.map +0 -1
  65. package/dist/extract.js.map +0 -1
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/index.js.map +0 -1
  68. package/dist/options.d.ts +0 -71
  69. package/dist/options.d.ts.map +0 -1
  70. package/dist/options.js.map +0 -1
  71. package/dist/types.d.ts.map +0 -1
  72. package/dist/types.js.map +0 -1
  73. package/dist/utils.d.ts.map +0 -1
  74. package/dist/utils.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.downloadAndInstallFoundryBinaries = exports.installBinaries = exports.checkAndDownloadBinaries = exports.getBinaryArchiveUrl = exports.getCacheDirectory = void 0;
5
+ const node_crypto_1 = require("node:crypto");
6
+ const node_fs_1 = require("node:fs");
7
+ const promises_1 = require("node:fs/promises");
8
+ const node_os_1 = require("node:os");
9
+ const node_path_1 = require("node:path");
10
+ const node_process_1 = require("node:process");
11
+ const yaml_1 = require("yaml");
12
+ const extract_js_1 = require("./extract.cjs");
13
+ const options_js_1 = require("./options.cjs");
14
+ const types_js_1 = require("./types.cjs");
15
+ const utils_js_1 = require("./utils.cjs");
16
+ /**
17
+ * Determines the cache directory based on the .yarnrc.yml configuration.
18
+ * If global cache is enabled, returns a path in the user's home directory.
19
+ * Otherwise, returns a local cache path in the current working directory.
20
+ *
21
+ * @returns The path to the cache directory
22
+ */
23
+ function getCacheDirectory() {
24
+ let enableGlobalCache = false;
25
+ try {
26
+ const configFileContent = (0, node_fs_1.readFileSync)('.yarnrc.yml', 'utf8');
27
+ const parsedConfig = (0, yaml_1.parse)(configFileContent);
28
+ enableGlobalCache = parsedConfig?.enableGlobalCache ?? false;
29
+ }
30
+ catch (error) {
31
+ // If file doesn't exist or can't be read, default to local cache
32
+ if (error.code === 'ENOENT') {
33
+ return (0, node_path_1.join)((0, node_process_1.cwd)(), '.metamask', 'cache');
34
+ }
35
+ // For other errors, log but continue with default
36
+ console.warn('Warning: Error reading .yarnrc.yml, using local cache:', error);
37
+ }
38
+ return enableGlobalCache
39
+ ? (0, node_path_1.join)((0, node_os_1.homedir)(), '.cache', 'metamask')
40
+ : (0, node_path_1.join)((0, node_process_1.cwd)(), '.metamask', 'cache');
41
+ }
42
+ exports.getCacheDirectory = getCacheDirectory;
43
+ /**
44
+ * Generates the URL for downloading the Foundry binary archive.
45
+ *
46
+ * @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')
47
+ * @param tag - The release tag (e.g., 'v1.0.0')
48
+ * @param version - The version string
49
+ * @param platform - The target platform (e.g., Platform.Linux)
50
+ * @param arch - The target architecture (e.g., 'amd64')
51
+ * @returns The URL for the binary archive
52
+ */
53
+ function getBinaryArchiveUrl(repo, tag, version, platform, arch) {
54
+ const ext = platform === types_js_1.Platform.Windows ? types_js_1.Extension.Zip : types_js_1.Extension.Tar;
55
+ return `https://github.com/${repo}/releases/download/${tag}/foundry_${version}_${platform}_${arch}.${ext}`;
56
+ }
57
+ exports.getBinaryArchiveUrl = getBinaryArchiveUrl;
58
+ /**
59
+ * Checks if binaries are already in the cache. If not, downloads and extracts them.
60
+ *
61
+ * @param url - The URL to download the binaries from
62
+ * @param binaries - The list of binaries to download
63
+ * @param cachePath - The path to the cache directory
64
+ * @param platform - The target platform
65
+ * @param arch - The target architecture
66
+ * @param checksums - Optional checksums for verification
67
+ * @returns A promise that resolves to the directory containing the downloaded binaries
68
+ */
69
+ async function checkAndDownloadBinaries(url, binaries, cachePath, platform, arch, checksums) {
70
+ let downloadedBinaries;
71
+ try {
72
+ (0, utils_js_1.say)(`checking cache`);
73
+ downloadedBinaries = await (0, promises_1.opendir)(cachePath);
74
+ (0, utils_js_1.say)(`found binaries in cache`);
75
+ }
76
+ catch (e) {
77
+ (0, utils_js_1.say)(`binaries not in cache`);
78
+ if (e.code === 'ENOENT') {
79
+ (0, utils_js_1.say)(`installing from ${url.toString()}`);
80
+ // directory doesn't exist, download and extract
81
+ const platformChecksums = (0, utils_js_1.transformChecksums)(checksums, platform, arch);
82
+ await (0, extract_js_1.extractFrom)(url, binaries, cachePath, platformChecksums);
83
+ downloadedBinaries = await (0, promises_1.opendir)(cachePath);
84
+ }
85
+ else {
86
+ throw e;
87
+ }
88
+ }
89
+ return downloadedBinaries;
90
+ }
91
+ exports.checkAndDownloadBinaries = checkAndDownloadBinaries;
92
+ /**
93
+ * Installs the downloaded binaries by creating symlinks or copying files.
94
+ *
95
+ * @param downloadedBinaries - The directory containing the downloaded binaries
96
+ * @param BIN_DIR - The target directory for installation
97
+ * @param cachePath - The path to the cache directory
98
+ * @returns A promise that resolves when installation is complete
99
+ */
100
+ async function installBinaries(downloadedBinaries, BIN_DIR, cachePath) {
101
+ for await (const file of downloadedBinaries) {
102
+ if (!file.isFile()) {
103
+ continue;
104
+ }
105
+ const target = (0, node_path_1.join)(file.parentPath, file.name);
106
+ const path = (0, node_path_1.join)(BIN_DIR, (0, node_path_1.relative)(cachePath, target));
107
+ // compute the relative path from where the symlink will be created
108
+ // to the target file, so that it works even if the project is moved
109
+ // (like in some CI environments)
110
+ const relativeTarget = (0, node_path_1.relative)((0, node_path_1.dirname)(path), target);
111
+ // create the BIN_DIR paths if they don't exists already
112
+ await (0, promises_1.mkdir)(BIN_DIR, { recursive: true });
113
+ // clean up any existing files or symlinks
114
+ await (0, promises_1.unlink)(path).catch(utils_js_1.noop);
115
+ try {
116
+ // create new symlink
117
+ await (0, promises_1.symlink)(relativeTarget, path);
118
+ }
119
+ catch (e) {
120
+ if (!((0, utils_js_1.isCodedError)(e) && ['EPERM', 'EXDEV'].includes(e.code))) {
121
+ throw e;
122
+ }
123
+ // symlinking can fail if it's a cross-device/filesystem link, or for
124
+ // permissions reasons, so we'll just copy the file instead
125
+ await (0, promises_1.copyFile)(target, path);
126
+ }
127
+ // check that it works by logging the version
128
+ (0, utils_js_1.say)(`installed - ${(0, utils_js_1.getVersion)(path).toString()}`);
129
+ }
130
+ }
131
+ exports.installBinaries = installBinaries;
132
+ /**
133
+ * Downloads and installs Foundry binaries based on command-line arguments.
134
+ * If the command is 'cache clean', it removes the cache directory.
135
+ * Otherwise, it downloads and installs the specified binaries.
136
+ *
137
+ * @returns A promise that resolves when the operation is complete
138
+ */
139
+ async function downloadAndInstallFoundryBinaries() {
140
+ const parsedArgs = (0, options_js_1.parseArgs)();
141
+ const CACHE_DIR = getCacheDirectory();
142
+ if (parsedArgs.command === 'cache clean') {
143
+ await (0, promises_1.rm)(CACHE_DIR, { recursive: true, force: true });
144
+ (0, utils_js_1.say)('done!');
145
+ (0, node_process_1.exit)(0);
146
+ }
147
+ const { repo, version: { version, tag }, arch, platform, binaries, checksums, } = parsedArgs.options;
148
+ (0, options_js_1.printBanner)();
149
+ const bins = binaries.join(', ');
150
+ (0, utils_js_1.say)(`fetching ${bins} ${version} for ${platform} ${arch}`);
151
+ const BIN_ARCHIVE_URL = getBinaryArchiveUrl(repo, tag, version, platform, arch);
152
+ const BIN_DIR = (0, node_path_1.join)((0, node_process_1.cwd)(), 'node_modules', '.bin');
153
+ const url = new URL(BIN_ARCHIVE_URL);
154
+ const cacheKey = (0, node_crypto_1.createHash)('sha256')
155
+ .update(`${BIN_ARCHIVE_URL}-${bins}`)
156
+ .digest('hex');
157
+ const cachePath = (0, node_path_1.join)(CACHE_DIR, cacheKey);
158
+ const downloadedBinaries = await checkAndDownloadBinaries(url, binaries, cachePath, platform, arch, checksums);
159
+ await installBinaries(downloadedBinaries, BIN_DIR, cachePath);
160
+ (0, utils_js_1.say)('done!');
161
+ }
162
+ exports.downloadAndInstallFoundryBinaries = downloadAndInstallFoundryBinaries;
163
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,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,OAAO,KAAK,EAAE,CAAC;QACf,iEAAiE;QACjE,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,OAAO,IAAA,gBAAI,EAAC,IAAA,kBAAG,GAAE,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,k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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"]}
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
2
- import type { Dir } from 'node:fs';
3
- import type { Checksums, Architecture, Binary } from './types.js';
4
- import { Platform } from './types.js';
2
+ /// <reference types="node" />
3
+ /// <reference types="node/fs.js" />
4
+ /// <reference types="npm-which/node_modules/@types/node/fs.js" />
5
+ import type { Dir } from "node:fs";
6
+ import type { Checksums, Architecture, Binary } from "./types.cjs";
7
+ import { Platform } from "./types.cjs";
5
8
  /**
6
9
  * Determines the cache directory based on the .yarnrc.yml configuration.
7
10
  * If global cache is enabled, returns a path in the user's home directory.
@@ -50,4 +53,4 @@ export declare function installBinaries(downloadedBinaries: Dir, BIN_DIR: string
50
53
  * @returns A promise that resolves when the operation is complete
51
54
  */
52
55
  export declare function downloadAndInstallFoundryBinaries(): Promise<void>;
53
- //# sourceMappingURL=index.d.ts.map
56
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB;AAgBnC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,oBAAmB;AAClE,OAAO,EAAa,QAAQ,EAAE,oBAAmB;AASjD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAoB1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,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"}
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
2
+ /// <reference types="node" />
3
+ /// <reference types="node/fs.js" />
4
+ /// <reference types="npm-which/node_modules/@types/node/fs.js" />
5
+ import type { Dir } from "node:fs";
6
+ import type { Checksums, Architecture, Binary } from "./types.mjs";
7
+ import { Platform } from "./types.mjs";
8
+ /**
9
+ * Determines the cache directory based on the .yarnrc.yml configuration.
10
+ * If global cache is enabled, returns a path in the user's home directory.
11
+ * Otherwise, returns a local cache path in the current working directory.
12
+ *
13
+ * @returns The path to the cache directory
14
+ */
15
+ export declare function getCacheDirectory(): string;
16
+ /**
17
+ * Generates the URL for downloading the Foundry binary archive.
18
+ *
19
+ * @param repo - The GitHub repository (e.g., 'foundry-rs/foundry')
20
+ * @param tag - The release tag (e.g., 'v1.0.0')
21
+ * @param version - The version string
22
+ * @param platform - The target platform (e.g., Platform.Linux)
23
+ * @param arch - The target architecture (e.g., 'amd64')
24
+ * @returns The URL for the binary archive
25
+ */
26
+ export declare function getBinaryArchiveUrl(repo: string, tag: string, version: string, platform: Platform, arch: string): string;
27
+ /**
28
+ * Checks if binaries are already in the cache. If not, downloads and extracts them.
29
+ *
30
+ * @param url - The URL to download the binaries from
31
+ * @param binaries - The list of binaries to download
32
+ * @param cachePath - The path to the cache directory
33
+ * @param platform - The target platform
34
+ * @param arch - The target architecture
35
+ * @param checksums - Optional checksums for verification
36
+ * @returns A promise that resolves to the directory containing the downloaded binaries
37
+ */
38
+ export declare function checkAndDownloadBinaries(url: URL, binaries: Binary[], cachePath: string, platform: Platform, arch: Architecture, checksums?: Checksums): Promise<Dir>;
39
+ /**
40
+ * Installs the downloaded binaries by creating symlinks or copying files.
41
+ *
42
+ * @param downloadedBinaries - The directory containing the downloaded binaries
43
+ * @param BIN_DIR - The target directory for installation
44
+ * @param cachePath - The path to the cache directory
45
+ * @returns A promise that resolves when installation is complete
46
+ */
47
+ export declare function installBinaries(downloadedBinaries: Dir, BIN_DIR: string, cachePath: string): Promise<void>;
48
+ /**
49
+ * Downloads and installs Foundry binaries based on command-line arguments.
50
+ * If the command is 'cache clean', it removes the cache directory.
51
+ * Otherwise, it downloads and installs the specified binaries.
52
+ *
53
+ * @returns A promise that resolves when the operation is complete
54
+ */
55
+ export declare function downloadAndInstallFoundryBinaries(): Promise<void>;
56
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +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,oBAAmB;AAClE,OAAO,EAAa,QAAQ,EAAE,oBAAmB;AASjD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAoB1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,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"}
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
2
- import { createHash } from 'node:crypto';
3
- import { readFileSync } from 'node:fs';
4
- import { copyFile, mkdir, opendir, rm, symlink, unlink, } from 'node:fs/promises';
5
- import { homedir } from 'node:os';
6
- import { dirname, join, relative } from 'node:path';
7
- import { cwd, exit } from 'node:process';
8
- import { parse as parseYaml } from 'yaml';
9
- import { extractFrom } from './extract.js';
10
- import { parseArgs, printBanner } from './options.js';
11
- import { Extension, Platform } from './types.js';
12
- import { getVersion, isCodedError, noop, say, transformChecksums, } from './utils.js';
2
+ import { createHash } from "node:crypto";
3
+ import { readFileSync } from "node:fs";
4
+ import { copyFile, mkdir, opendir, rm, symlink, unlink } from "node:fs/promises";
5
+ import { homedir } from "node:os";
6
+ import { dirname, join, relative } from "node:path";
7
+ import { cwd, exit } from "node:process";
8
+ import { parse as parseYaml } from "yaml";
9
+ import { extractFrom } from "./extract.mjs";
10
+ import { parseArgs, printBanner } from "./options.mjs";
11
+ import { Extension, Platform } from "./types.mjs";
12
+ import { getVersion, isCodedError, noop, say, transformChecksums } from "./utils.mjs";
13
13
  /**
14
14
  * Determines the cache directory based on the .yarnrc.yml configuration.
15
15
  * If global cache is enabled, returns a path in the user's home directory.
@@ -152,4 +152,4 @@ export async function downloadAndInstallFoundryBinaries() {
152
152
  await installBinaries(downloadedBinaries, BIN_DIR, cachePath);
153
153
  say('done!');
154
154
  }
155
- //# sourceMappingURL=index.js.map
155
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
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,EAC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IAED,MAAM,EACJ,IAAI,EACJ,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EACzB,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,SAAS,GACV,GAAG,UAAU,CAAC,OAAO,CAAC;IAEvB,WAAW,EAAE,CAAC;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"]}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseArgs = exports.printBanner = void 0;
7
+ const node_os_1 = require("node:os");
8
+ const node_process_1 = require("node:process");
9
+ const yargs_1 = __importDefault(require("yargs/yargs"));
10
+ const types_js_1 = require("./types.cjs");
11
+ const utils_js_1 = require("./utils.cjs");
12
+ /**
13
+ * Type guard to check if a string is a valid version string starting with 'v'.
14
+ *
15
+ * @param value - The string to check
16
+ * @returns True if the string is a valid version string
17
+ */
18
+ function isVersionString(value) {
19
+ return /^v\d/u.test(value);
20
+ }
21
+ /**
22
+ * Prints the Foundry banner to the console.
23
+ */
24
+ function printBanner() {
25
+ console.log(`
26
+ .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
27
+
28
+ ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit
29
+ ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development
30
+ ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.
31
+
32
+ .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
33
+
34
+ Repo : https://github.com/foundry-rs/
35
+ Book : https://book.getfoundry.sh/
36
+ Chat : https://t.me/foundry_rs/
37
+ Support : https://t.me/foundry_support/
38
+ Contribute : https://github.com/orgs/foundry-rs/projects/2/
39
+
40
+ .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
41
+ `);
42
+ }
43
+ exports.printBanner = printBanner;
44
+ /**
45
+ * Parses command line arguments and returns the parsed options.
46
+ *
47
+ * @param args - Command line arguments to parse
48
+ * @returns Parsed command line arguments
49
+ */
50
+ function parseArgs(args = node_process_1.argv.slice(2)) {
51
+ const { $0, _, ...parsed } = (0, yargs_1.default)()
52
+ // Ensure unrecognized commands/options are reported as errors.
53
+ .strict()
54
+ // disable yargs's version, as it doesn't make sense here
55
+ .version(false)
56
+ // use the scriptName in `--help` output
57
+ .scriptName('yarn foundryup')
58
+ // wrap output at a maximum of 120 characters or `stdout.columns`
59
+ .wrap(Math.min(120, node_process_1.stdout.columns))
60
+ .parserConfiguration({
61
+ 'strip-aliased': true,
62
+ 'strip-dashed': true,
63
+ })
64
+ // enable ENV parsing, which allows the user to specify foundryup options
65
+ // via environment variables prefixed with `FOUNDRYUP_`
66
+ .env('FOUNDRYUP')
67
+ .command(['$0', 'install'], 'Install foundry binaries', (builder) => {
68
+ builder.options(getOptions()).pkgConf('foundryup');
69
+ })
70
+ .command('cache', '', (builder) => {
71
+ builder.command('clean', 'Remove the shared cache files').demandCommand();
72
+ })
73
+ .parseSync(args);
74
+ const command = _.join(' ');
75
+ if (command === 'cache clean') {
76
+ return {
77
+ command,
78
+ };
79
+ }
80
+ // if we get here `command` is always 'install' or '' (yargs checks it)
81
+ return {
82
+ command: 'install',
83
+ options: parsed,
84
+ };
85
+ }
86
+ exports.parseArgs = parseArgs;
87
+ const Binaries = Object.values(types_js_1.Binary);
88
+ /**
89
+ * Returns the command line options configuration.
90
+ *
91
+ * @param defaultPlatform - Default platform to use
92
+ * @param defaultArch - Default architecture to use
93
+ * @returns Command line options configuration
94
+ */
95
+ function getOptions(defaultPlatform = (0, node_os_1.platform)(), defaultArch = (0, utils_js_1.normalizeSystemArchitecture)()) {
96
+ return {
97
+ binaries: {
98
+ alias: 'b',
99
+ type: 'array',
100
+ multiple: true,
101
+ description: 'Specify the binaries to install',
102
+ default: Binaries,
103
+ choices: Binaries,
104
+ coerce: (values) => [...new Set(values)], // Remove duplicates
105
+ },
106
+ checksums: {
107
+ alias: 'c',
108
+ description: 'JSON object containing checksums for the binaries.',
109
+ coerce: (rawChecksums) => {
110
+ try {
111
+ return typeof rawChecksums === 'string'
112
+ ? JSON.parse(rawChecksums)
113
+ : rawChecksums;
114
+ }
115
+ catch {
116
+ throw new Error('Invalid checksums');
117
+ }
118
+ },
119
+ optional: true,
120
+ },
121
+ repo: {
122
+ alias: 'r',
123
+ description: 'Specify the repository',
124
+ default: 'foundry-rs/foundry',
125
+ },
126
+ version: {
127
+ alias: 'v',
128
+ description: 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',
129
+ default: 'nightly',
130
+ coerce: (rawVersion) => {
131
+ if (rawVersion.startsWith('nightly')) {
132
+ return { version: 'nightly', tag: rawVersion };
133
+ // we don't validate the version much, we just trust the user
134
+ }
135
+ else if (isVersionString(rawVersion)) {
136
+ return { version: rawVersion, tag: rawVersion };
137
+ }
138
+ throw new Error('Invalid version');
139
+ },
140
+ },
141
+ arch: {
142
+ alias: 'a',
143
+ description: 'Specify the architecture',
144
+ // if `defaultArch` is not a supported Architecture yargs will throw an error
145
+ default: defaultArch,
146
+ choices: Object.values(types_js_1.Architecture),
147
+ },
148
+ platform: {
149
+ alias: 'p',
150
+ description: 'Specify the platform',
151
+ // if `defaultPlatform` is not a supported Platform yargs will throw an error
152
+ default: defaultPlatform,
153
+ choices: Object.values(types_js_1.Platform),
154
+ },
155
+ };
156
+ }
157
+ //# sourceMappingURL=options.cjs.map
@@ -0,0 +1 @@
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;SAC9D,MAAM,EAAE;QACT,yDAAyD;SACxD,OAAO,CAAC,KAAK,CAAC;QACf,wCAAwC;SACvC,UAAU,CAAC,gBAAgB,CAAC;QAC7B,iEAAiE;SAChE,IAAI,CAA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AM,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"]}
@@ -0,0 +1,62 @@
1
+ import { Architecture, Binary, Platform } from "./types.cjs";
2
+ import type { Checksums, ParsedOptions } from "./types.cjs";
3
+ /**
4
+ * Prints the Foundry banner to the console.
5
+ */
6
+ export declare function printBanner(): void;
7
+ /**
8
+ * Parses command line arguments and returns the parsed options.
9
+ *
10
+ * @param args - Command line arguments to parse
11
+ * @returns Parsed command line arguments
12
+ */
13
+ export declare function parseArgs(args?: string[]): {
14
+ readonly command: "cache clean";
15
+ readonly options?: undefined;
16
+ } | {
17
+ readonly command: "install";
18
+ readonly options: ParsedOptions<{
19
+ binaries: {
20
+ alias: string;
21
+ type: "array";
22
+ multiple: boolean;
23
+ description: string;
24
+ default: [Binary];
25
+ choices: [Binary];
26
+ coerce: (values: Binary[]) => Binary[];
27
+ };
28
+ checksums: {
29
+ alias: string;
30
+ description: string;
31
+ coerce: (rawChecksums: string | Checksums) => Checksums;
32
+ optional: boolean;
33
+ };
34
+ repo: {
35
+ alias: string;
36
+ description: string;
37
+ default: string;
38
+ };
39
+ version: {
40
+ alias: string;
41
+ description: string;
42
+ default: string;
43
+ coerce: (rawVersion: string) => {
44
+ version: `v${string}` | "nightly";
45
+ tag: string;
46
+ };
47
+ };
48
+ arch: {
49
+ alias: string;
50
+ description: string;
51
+ default: Architecture;
52
+ choices: [Architecture];
53
+ };
54
+ platform: {
55
+ alias: string;
56
+ description: string;
57
+ default: Platform;
58
+ choices: [Platform];
59
+ };
60
+ }>;
61
+ };
62
+ //# sourceMappingURL=options.d.cts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,62 @@
1
+ import { Architecture, Binary, Platform } from "./types.mjs";
2
+ import type { Checksums, ParsedOptions } from "./types.mjs";
3
+ /**
4
+ * Prints the Foundry banner to the console.
5
+ */
6
+ export declare function printBanner(): void;
7
+ /**
8
+ * Parses command line arguments and returns the parsed options.
9
+ *
10
+ * @param args - Command line arguments to parse
11
+ * @returns Parsed command line arguments
12
+ */
13
+ export declare function parseArgs(args?: string[]): {
14
+ readonly command: "cache clean";
15
+ readonly options?: undefined;
16
+ } | {
17
+ readonly command: "install";
18
+ readonly options: ParsedOptions<{
19
+ binaries: {
20
+ alias: string;
21
+ type: "array";
22
+ multiple: boolean;
23
+ description: string;
24
+ default: [Binary];
25
+ choices: [Binary];
26
+ coerce: (values: Binary[]) => Binary[];
27
+ };
28
+ checksums: {
29
+ alias: string;
30
+ description: string;
31
+ coerce: (rawChecksums: string | Checksums) => Checksums;
32
+ optional: boolean;
33
+ };
34
+ repo: {
35
+ alias: string;
36
+ description: string;
37
+ default: string;
38
+ };
39
+ version: {
40
+ alias: string;
41
+ description: string;
42
+ default: string;
43
+ coerce: (rawVersion: string) => {
44
+ version: `v${string}` | "nightly";
45
+ tag: string;
46
+ };
47
+ };
48
+ arch: {
49
+ alias: string;
50
+ description: string;
51
+ default: Architecture;
52
+ choices: [Architecture];
53
+ };
54
+ platform: {
55
+ alias: string;
56
+ description: string;
57
+ default: Platform;
58
+ choices: [Platform];
59
+ };
60
+ }>;
61
+ };
62
+ //# sourceMappingURL=options.d.mts.map