@metamask-previews/foundryup 0.0.0-preview-c1fef6e5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +20 -0
- package/README.md +47 -0
- package/dist/cli.cjs +10 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +3 -0
- package/dist/cli.d.cts.map +1 -0
- package/dist/cli.d.mts +3 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +8 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/download.cjs +68 -0
- package/dist/download.cjs.map +1 -0
- package/dist/download.d.cts +18 -0
- package/dist/download.d.cts.map +1 -0
- package/dist/download.d.mts +18 -0
- package/dist/download.d.mts.map +1 -0
- package/dist/download.mjs +64 -0
- package/dist/download.mjs.map +1 -0
- package/dist/extract.cjs +184 -0
- package/dist/extract.cjs.map +1 -0
- package/dist/extract.d.cts +15 -0
- package/dist/extract.d.cts.map +1 -0
- package/dist/extract.d.mts +15 -0
- package/dist/extract.d.mts.map +1 -0
- package/dist/extract.mjs +180 -0
- package/dist/extract.mjs.map +1 -0
- package/dist/index.cjs +116 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +109 -0
- package/dist/index.mjs.map +1 -0
- package/dist/options.cjs +135 -0
- package/dist/options.cjs.map +1 -0
- package/dist/options.d.cts +52 -0
- package/dist/options.d.cts.map +1 -0
- package/dist/options.d.mts +52 -0
- package/dist/options.d.mts.map +1 -0
- package/dist/options.mjs +127 -0
- package/dist/options.mjs.map +1 -0
- package/dist/types.cjs +30 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +72 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +72 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +27 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +104 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +44 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +44 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +95 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAmC;AACnC,+CAA4C;AAC5C,wDAAgC;AAChC,uCAAsD;AACtD,uCASiB;AAEjB,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,SAAgB,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;CAgBb,CAAC,CAAC;AACH,CAAC;AAlBD,kCAkBC;AAED,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,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,qBAAM,CAAC,OAAO,CAAC,CAAC;SACnC,mBAAmB,CAAC;QACnB,eAAe,EAAE,IAAI;QACrB,cAAc,EAAE,IAAI;KACrB,CAAC;QACF,yEAAyE;QACzE,uDAAuD;SACtD,GAAG,CAAC,WAAW,CAAC;SAChB,OAAO,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,0BAA0B,EAAE,CAAC,OAAO,EAAE,EAAE;QAClE,OAAO,C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AC,CAAC,YAAY,CAAC;iBAClB;gBAAC,MAAM;oBACN,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;iBACtC;YACH,CAAC;YACD,QAAQ,EAAE,IAAI;SACf;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,wBAAwB;YACrC,OAAO,EAAE,oBAAoB;SAC9B;QACD,OAAO,EAAE;YACP,KAAK,EAAE,GAAG;YACV,WAAW,EACT,uEAAuE;YACzE,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,CACN,UAAkB,EACkC,EAAE;gBACtD,IAAI,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;oBAChC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;oBAC/C,6DAA6D;iBAC9D;qBAAM,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE;oBACtC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;iBACjD;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,WAA2B;YACpC,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';\nimport { normalizeSystemArchitecture } from './utils';\nimport {\n type Checksums,\n type ParsedOptions,\n type ArchitecturesTuple,\n type BinariesTuple,\n type PlatformsTuple,\n Architecture,\n Binary,\n Platform,\n} from './types';\n\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\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\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\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 (/^nightly/u.test(rawVersion)) {\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 as Architecture,\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,52 @@
|
|
|
1
|
+
import { type Checksums, type ParsedOptions, Architecture, Binary, Platform } from "./types.cjs";
|
|
2
|
+
export declare function printBanner(): void;
|
|
3
|
+
export declare function parseArgs(args?: string[]): {
|
|
4
|
+
readonly command: "cache clean";
|
|
5
|
+
readonly options?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
readonly command: "install";
|
|
8
|
+
readonly options: ParsedOptions<{
|
|
9
|
+
binaries: {
|
|
10
|
+
alias: string;
|
|
11
|
+
type: "array";
|
|
12
|
+
multiple: boolean;
|
|
13
|
+
description: string;
|
|
14
|
+
default: [Binary];
|
|
15
|
+
choices: [Binary];
|
|
16
|
+
coerce: (values: Binary[]) => Binary[];
|
|
17
|
+
};
|
|
18
|
+
checksums: {
|
|
19
|
+
alias: string;
|
|
20
|
+
description: string;
|
|
21
|
+
coerce: (rawChecksums: string | Checksums) => Checksums;
|
|
22
|
+
optional: boolean;
|
|
23
|
+
};
|
|
24
|
+
repo: {
|
|
25
|
+
alias: string;
|
|
26
|
+
description: string;
|
|
27
|
+
default: string;
|
|
28
|
+
};
|
|
29
|
+
version: {
|
|
30
|
+
alias: string;
|
|
31
|
+
description: string;
|
|
32
|
+
default: string;
|
|
33
|
+
coerce: (rawVersion: string) => {
|
|
34
|
+
version: `v${string}` | "nightly";
|
|
35
|
+
tag: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
arch: {
|
|
39
|
+
alias: string;
|
|
40
|
+
description: string;
|
|
41
|
+
default: Architecture;
|
|
42
|
+
choices: [Architecture];
|
|
43
|
+
};
|
|
44
|
+
platform: {
|
|
45
|
+
alias: string;
|
|
46
|
+
description: string;
|
|
47
|
+
default: Platform;
|
|
48
|
+
choices: [Platform];
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=options.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAIlB,YAAY,EACZ,MAAM,EACN,QAAQ,EACT,oBAAgB;AAMjB,wBAAgB,WAAW,SAkB1B;AAED,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Checksums, type ParsedOptions, Architecture, Binary, Platform } from "./types.mjs";
|
|
2
|
+
export declare function printBanner(): void;
|
|
3
|
+
export declare function parseArgs(args?: string[]): {
|
|
4
|
+
readonly command: "cache clean";
|
|
5
|
+
readonly options?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
readonly command: "install";
|
|
8
|
+
readonly options: ParsedOptions<{
|
|
9
|
+
binaries: {
|
|
10
|
+
alias: string;
|
|
11
|
+
type: "array";
|
|
12
|
+
multiple: boolean;
|
|
13
|
+
description: string;
|
|
14
|
+
default: [Binary];
|
|
15
|
+
choices: [Binary];
|
|
16
|
+
coerce: (values: Binary[]) => Binary[];
|
|
17
|
+
};
|
|
18
|
+
checksums: {
|
|
19
|
+
alias: string;
|
|
20
|
+
description: string;
|
|
21
|
+
coerce: (rawChecksums: string | Checksums) => Checksums;
|
|
22
|
+
optional: boolean;
|
|
23
|
+
};
|
|
24
|
+
repo: {
|
|
25
|
+
alias: string;
|
|
26
|
+
description: string;
|
|
27
|
+
default: string;
|
|
28
|
+
};
|
|
29
|
+
version: {
|
|
30
|
+
alias: string;
|
|
31
|
+
description: string;
|
|
32
|
+
default: string;
|
|
33
|
+
coerce: (rawVersion: string) => {
|
|
34
|
+
version: `v${string}` | "nightly";
|
|
35
|
+
tag: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
arch: {
|
|
39
|
+
alias: string;
|
|
40
|
+
description: string;
|
|
41
|
+
default: Architecture;
|
|
42
|
+
choices: [Architecture];
|
|
43
|
+
};
|
|
44
|
+
platform: {
|
|
45
|
+
alias: string;
|
|
46
|
+
description: string;
|
|
47
|
+
default: Platform;
|
|
48
|
+
choices: [Platform];
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=options.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAIlB,YAAY,EACZ,MAAM,EACN,QAAQ,EACT,oBAAgB;AAMjB,wBAAgB,WAAW,SAkB1B;AAED,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
|
package/dist/options.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { platform } from "node:os";
|
|
2
|
+
import { argv, stdout } from "node:process";
|
|
3
|
+
import yargs from "yargs/yargs";
|
|
4
|
+
import { normalizeSystemArchitecture } from "./utils.mjs";
|
|
5
|
+
import { Architecture, Binary, Platform } from "./types.mjs";
|
|
6
|
+
function isVersionString(value) {
|
|
7
|
+
return /^v\d/u.test(value);
|
|
8
|
+
}
|
|
9
|
+
export function printBanner() {
|
|
10
|
+
console.log(`
|
|
11
|
+
.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
|
|
12
|
+
|
|
13
|
+
╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit
|
|
14
|
+
╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development
|
|
15
|
+
╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.
|
|
16
|
+
|
|
17
|
+
.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
|
|
18
|
+
|
|
19
|
+
Repo : https://github.com/foundry-rs/
|
|
20
|
+
Book : https://book.getfoundry.sh/
|
|
21
|
+
Chat : https://t.me/foundry_rs/
|
|
22
|
+
Support : https://t.me/foundry_support/
|
|
23
|
+
Contribute : https://github.com/orgs/foundry-rs/projects/2/
|
|
24
|
+
|
|
25
|
+
.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
|
|
26
|
+
`);
|
|
27
|
+
}
|
|
28
|
+
export function parseArgs(args = argv.slice(2)) {
|
|
29
|
+
const { $0, _, ...parsed } = yargs()
|
|
30
|
+
// Ensure unrecognized commands/options are reported as errors.
|
|
31
|
+
.strict()
|
|
32
|
+
// disable yargs's version, as it doesn't make sense here
|
|
33
|
+
.version(false)
|
|
34
|
+
// use the scriptName in `--help` output
|
|
35
|
+
.scriptName('yarn foundryup')
|
|
36
|
+
// wrap output at a maximum of 120 characters or `stdout.columns`
|
|
37
|
+
.wrap(Math.min(120, stdout.columns))
|
|
38
|
+
.parserConfiguration({
|
|
39
|
+
'strip-aliased': true,
|
|
40
|
+
'strip-dashed': true,
|
|
41
|
+
})
|
|
42
|
+
// enable ENV parsing, which allows the user to specify foundryup options
|
|
43
|
+
// via environment variables prefixed with `FOUNDRYUP_`
|
|
44
|
+
.env('FOUNDRYUP')
|
|
45
|
+
.command(['$0', 'install'], 'Install foundry binaries', (builder) => {
|
|
46
|
+
builder.options(getOptions()).pkgConf('foundryup');
|
|
47
|
+
})
|
|
48
|
+
.command('cache', '', (builder) => {
|
|
49
|
+
builder.command('clean', 'Remove the shared cache files').demandCommand();
|
|
50
|
+
})
|
|
51
|
+
.parseSync(args);
|
|
52
|
+
const command = _.join(' ');
|
|
53
|
+
if (command === 'cache clean') {
|
|
54
|
+
return {
|
|
55
|
+
command,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// if we get here `command` is always 'install' or '' (yargs checks it)
|
|
59
|
+
return {
|
|
60
|
+
command: 'install',
|
|
61
|
+
options: parsed,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const Binaries = Object.values(Binary);
|
|
65
|
+
function getOptions(defaultPlatform = platform(), defaultArch = normalizeSystemArchitecture()) {
|
|
66
|
+
return {
|
|
67
|
+
binaries: {
|
|
68
|
+
alias: 'b',
|
|
69
|
+
type: 'array',
|
|
70
|
+
multiple: true,
|
|
71
|
+
description: 'Specify the binaries to install',
|
|
72
|
+
default: Binaries,
|
|
73
|
+
choices: Binaries,
|
|
74
|
+
coerce: (values) => [...new Set(values)], // Remove duplicates
|
|
75
|
+
},
|
|
76
|
+
checksums: {
|
|
77
|
+
alias: 'c',
|
|
78
|
+
description: 'JSON object containing checksums for the binaries.',
|
|
79
|
+
coerce: (rawChecksums) => {
|
|
80
|
+
try {
|
|
81
|
+
return typeof rawChecksums === 'string'
|
|
82
|
+
? JSON.parse(rawChecksums)
|
|
83
|
+
: rawChecksums;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
throw new Error('Invalid checksums');
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
optional: true,
|
|
90
|
+
},
|
|
91
|
+
repo: {
|
|
92
|
+
alias: 'r',
|
|
93
|
+
description: 'Specify the repository',
|
|
94
|
+
default: 'foundry-rs/foundry',
|
|
95
|
+
},
|
|
96
|
+
version: {
|
|
97
|
+
alias: 'v',
|
|
98
|
+
description: 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',
|
|
99
|
+
default: 'nightly',
|
|
100
|
+
coerce: (rawVersion) => {
|
|
101
|
+
if (/^nightly/u.test(rawVersion)) {
|
|
102
|
+
return { version: 'nightly', tag: rawVersion };
|
|
103
|
+
// we don't validate the version much, we just trust the user
|
|
104
|
+
}
|
|
105
|
+
else if (isVersionString(rawVersion)) {
|
|
106
|
+
return { version: rawVersion, tag: rawVersion };
|
|
107
|
+
}
|
|
108
|
+
throw new Error('Invalid version');
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
arch: {
|
|
112
|
+
alias: 'a',
|
|
113
|
+
description: 'Specify the architecture',
|
|
114
|
+
// if `defaultArch` is not a supported Architecture yargs will throw an error
|
|
115
|
+
default: defaultArch,
|
|
116
|
+
choices: Object.values(Architecture),
|
|
117
|
+
},
|
|
118
|
+
platform: {
|
|
119
|
+
alias: 'p',
|
|
120
|
+
description: 'Specify the platform',
|
|
121
|
+
// if `defaultPlatform` is not a supported Platform yargs will throw an error
|
|
122
|
+
default: defaultPlatform,
|
|
123
|
+
choices: Object.values(Platform),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -0,0 +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;AAChC,OAAO,EAAE,2BAA2B,EAAE,oBAAgB;AACtD,OAAO,EAML,YAAY,EACZ,MAAM,EACN,QAAQ,EACT,oBAAgB;AAEjB,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;CAgBb,CAAC,CAAC;AACH,CAAC;AAED,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,U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AAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,sBAAsB;YACnC,6EAA6E;YAC7E,OAAO,EAAE,eAA2B;YACpC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAmB;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { platform } from 'node:os';\nimport { argv, stdout } from 'node:process';\nimport yargs from 'yargs/yargs';\nimport { normalizeSystemArchitecture } from './utils';\nimport {\n type Checksums,\n type ParsedOptions,\n type ArchitecturesTuple,\n type BinariesTuple,\n type PlatformsTuple,\n Architecture,\n Binary,\n Platform,\n} from './types';\n\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\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\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\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 (/^nightly/u.test(rawVersion)) {\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 as Architecture,\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/types.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Binary = exports.Platform = exports.Extension = exports.Architecture = void 0;
|
|
4
|
+
// #endregion utils
|
|
5
|
+
// #region enums
|
|
6
|
+
var Architecture;
|
|
7
|
+
(function (Architecture) {
|
|
8
|
+
Architecture["Amd64"] = "amd64";
|
|
9
|
+
Architecture["Arm64"] = "arm64";
|
|
10
|
+
})(Architecture || (exports.Architecture = Architecture = {}));
|
|
11
|
+
var Extension;
|
|
12
|
+
(function (Extension) {
|
|
13
|
+
Extension["Zip"] = "zip";
|
|
14
|
+
Extension["Tar"] = "tar.gz";
|
|
15
|
+
})(Extension || (exports.Extension = Extension = {}));
|
|
16
|
+
var Platform;
|
|
17
|
+
(function (Platform) {
|
|
18
|
+
Platform["Windows"] = "win32";
|
|
19
|
+
Platform["Linux"] = "linux";
|
|
20
|
+
Platform["Mac"] = "darwin";
|
|
21
|
+
})(Platform || (exports.Platform = Platform = {}));
|
|
22
|
+
var Binary;
|
|
23
|
+
(function (Binary) {
|
|
24
|
+
Binary["Anvil"] = "anvil";
|
|
25
|
+
Binary["Forge"] = "forge";
|
|
26
|
+
Binary["Cast"] = "cast";
|
|
27
|
+
Binary["Chisel"] = "chisel";
|
|
28
|
+
})(Binary || (exports.Binary = Binary = {}));
|
|
29
|
+
// #endregion helpers
|
|
30
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsBA,mBAAmB;AAEnB,gBAAgB;AAEhB,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,+BAAe,CAAA;AACjB,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,2BAAc,CAAA;AAChB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,2BAAe,CAAA;IACf,0BAAc,CAAA;AAChB,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB;AAED,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,yBAAe,CAAA;IACf,yBAAe,CAAA;IACf,uBAAa,CAAA;IACb,2BAAiB,CAAA;AACnB,CAAC,EALW,MAAM,sBAAN,MAAM,QAKjB;AAoDD,qBAAqB","sourcesContent":["import type { Agent as HttpsAgent } from 'node:https';\nimport type { Agent as HttpAgent } from 'node:http';\nimport type { InferredOptionTypes, Options } from 'yargs';\n\n// #region utils\n\ntype UnionToIntersection<U> = ((k: U) => void) extends (k: infer I) => void\n ? I\n : never;\n\ntype LastInUnion<U extends PropertyKey> = UnionToIntersection<\n U extends PropertyKey ? () => U : never\n> extends () => infer Last\n ? Last\n : never;\n\ntype UnionToTuple<U extends PropertyKey, Last = LastInUnion<U>> = [U] extends [\n never,\n]\n ? []\n : [...UnionToTuple<Exclude<U, Last>>, Last];\n\n// #endregion utils\n\n// #region enums\n\nexport enum Architecture {\n Amd64 = 'amd64',\n Arm64 = 'arm64',\n}\n\nexport enum Extension {\n Zip = 'zip',\n Tar = 'tar.gz',\n}\n\nexport enum Platform {\n Windows = 'win32',\n Linux = 'linux',\n Mac = 'darwin',\n}\n\nexport enum Binary {\n Anvil = 'anvil',\n Forge = 'forge',\n Cast = 'cast',\n Chisel = 'chisel',\n}\n\n// #endregion enums\n\n// #region helpers\n\n/**\n * Tuple representing all members of the {@link Binary} enum.\n */\nexport type BinariesTuple = UnionToTuple<Binary>;\n\n/**\n * Tuple representing all members of the {@link Architecture} enum.\n */\nexport type ArchitecturesTuple = UnionToTuple<Architecture>;\n\n/**\n * Tuple representing all members of the {@link Platform} enum.\n */\nexport type PlatformsTuple = UnionToTuple<Platform>;\n\n/**\n * Checksum types expected by the CLI.\n */\nexport type Checksums = {\n algorithm: string;\n binaries: Record<Binary, Record<`${Platform}-${Architecture}`, string>>;\n};\n\n/**\n * Checksum type expected by application code, specific to the selected\n * {@link Platform} and {@link Architecture}. See also: {@link Checksums}.\n */\nexport type PlatformArchChecksums = {\n algorithm: string;\n binaries: Record<Binary, string>;\n};\n\n/**\n * Given a map of raw yargs options config, returns a map of inferred types.\n */\nexport type ParsedOptions<O extends { [key: string]: Options }> = {\n [key in keyof O]: InferredOptionTypes<O>[key];\n};\n\nexport type DownloadOptions = {\n method?: 'GET' | 'HEAD';\n headers?: Record<string, string>;\n agent?: HttpsAgent | HttpAgent;\n maxRedirects?: number;\n};\n\n// #endregion helpers\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { Agent as HttpsAgent } from "node:https";
|
|
4
|
+
import type { Agent as HttpAgent } from "node:http";
|
|
5
|
+
import type { InferredOptionTypes, Options } from "yargs";
|
|
6
|
+
type UnionToIntersection<U> = ((k: U) => void) extends (k: infer I) => void ? I : never;
|
|
7
|
+
type LastInUnion<U extends PropertyKey> = UnionToIntersection<U extends PropertyKey ? () => U : never> extends () => infer Last ? Last : never;
|
|
8
|
+
type UnionToTuple<U extends PropertyKey, Last = LastInUnion<U>> = [U] extends [
|
|
9
|
+
never
|
|
10
|
+
] ? [] : [...UnionToTuple<Exclude<U, Last>>, Last];
|
|
11
|
+
export declare enum Architecture {
|
|
12
|
+
Amd64 = "amd64",
|
|
13
|
+
Arm64 = "arm64"
|
|
14
|
+
}
|
|
15
|
+
export declare enum Extension {
|
|
16
|
+
Zip = "zip",
|
|
17
|
+
Tar = "tar.gz"
|
|
18
|
+
}
|
|
19
|
+
export declare enum Platform {
|
|
20
|
+
Windows = "win32",
|
|
21
|
+
Linux = "linux",
|
|
22
|
+
Mac = "darwin"
|
|
23
|
+
}
|
|
24
|
+
export declare enum Binary {
|
|
25
|
+
Anvil = "anvil",
|
|
26
|
+
Forge = "forge",
|
|
27
|
+
Cast = "cast",
|
|
28
|
+
Chisel = "chisel"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Tuple representing all members of the {@link Binary} enum.
|
|
32
|
+
*/
|
|
33
|
+
export type BinariesTuple = UnionToTuple<Binary>;
|
|
34
|
+
/**
|
|
35
|
+
* Tuple representing all members of the {@link Architecture} enum.
|
|
36
|
+
*/
|
|
37
|
+
export type ArchitecturesTuple = UnionToTuple<Architecture>;
|
|
38
|
+
/**
|
|
39
|
+
* Tuple representing all members of the {@link Platform} enum.
|
|
40
|
+
*/
|
|
41
|
+
export type PlatformsTuple = UnionToTuple<Platform>;
|
|
42
|
+
/**
|
|
43
|
+
* Checksum types expected by the CLI.
|
|
44
|
+
*/
|
|
45
|
+
export type Checksums = {
|
|
46
|
+
algorithm: string;
|
|
47
|
+
binaries: Record<Binary, Record<`${Platform}-${Architecture}`, string>>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Checksum type expected by application code, specific to the selected
|
|
51
|
+
* {@link Platform} and {@link Architecture}. See also: {@link Checksums}.
|
|
52
|
+
*/
|
|
53
|
+
export type PlatformArchChecksums = {
|
|
54
|
+
algorithm: string;
|
|
55
|
+
binaries: Record<Binary, string>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Given a map of raw yargs options config, returns a map of inferred types.
|
|
59
|
+
*/
|
|
60
|
+
export type ParsedOptions<O extends {
|
|
61
|
+
[key: string]: Options;
|
|
62
|
+
}> = {
|
|
63
|
+
[key in keyof O]: InferredOptionTypes<O>[key];
|
|
64
|
+
};
|
|
65
|
+
export type DownloadOptions = {
|
|
66
|
+
method?: 'GET' | 'HEAD';
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
agent?: HttpsAgent | HttpAgent;
|
|
69
|
+
maxRedirects?: number;
|
|
70
|
+
};
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,mBAAmB;AACtD,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,kBAAkB;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,cAAc;AAI1D,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GACvE,CAAC,GACD,KAAK,CAAC;AAEV,KAAK,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,mBAAmB,CAC3D,CAAC,SAAS,WAAW,GAAG,MAAM,CAAC,GAAG,KAAK,CACxC,SAAS,MAAM,MAAM,IAAI,GACtB,IAAI,GACJ,KAAK,CAAC;AAEV,KAAK,YAAY,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;IAC5E,KAAK;CACN,GACG,EAAE,GACF,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAM9C,oBAAY,YAAY;IACtB,KAAK,UAAU;IACf,KAAK,UAAU;CAChB;AAED,oBAAY,SAAS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CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { Agent as HttpsAgent } from "node:https";
|
|
4
|
+
import type { Agent as HttpAgent } from "node:http";
|
|
5
|
+
import type { InferredOptionTypes, Options } from "yargs";
|
|
6
|
+
type UnionToIntersection<U> = ((k: U) => void) extends (k: infer I) => void ? I : never;
|
|
7
|
+
type LastInUnion<U extends PropertyKey> = UnionToIntersection<U extends PropertyKey ? () => U : never> extends () => infer Last ? Last : never;
|
|
8
|
+
type UnionToTuple<U extends PropertyKey, Last = LastInUnion<U>> = [U] extends [
|
|
9
|
+
never
|
|
10
|
+
] ? [] : [...UnionToTuple<Exclude<U, Last>>, Last];
|
|
11
|
+
export declare enum Architecture {
|
|
12
|
+
Amd64 = "amd64",
|
|
13
|
+
Arm64 = "arm64"
|
|
14
|
+
}
|
|
15
|
+
export declare enum Extension {
|
|
16
|
+
Zip = "zip",
|
|
17
|
+
Tar = "tar.gz"
|
|
18
|
+
}
|
|
19
|
+
export declare enum Platform {
|
|
20
|
+
Windows = "win32",
|
|
21
|
+
Linux = "linux",
|
|
22
|
+
Mac = "darwin"
|
|
23
|
+
}
|
|
24
|
+
export declare enum Binary {
|
|
25
|
+
Anvil = "anvil",
|
|
26
|
+
Forge = "forge",
|
|
27
|
+
Cast = "cast",
|
|
28
|
+
Chisel = "chisel"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Tuple representing all members of the {@link Binary} enum.
|
|
32
|
+
*/
|
|
33
|
+
export type BinariesTuple = UnionToTuple<Binary>;
|
|
34
|
+
/**
|
|
35
|
+
* Tuple representing all members of the {@link Architecture} enum.
|
|
36
|
+
*/
|
|
37
|
+
export type ArchitecturesTuple = UnionToTuple<Architecture>;
|
|
38
|
+
/**
|
|
39
|
+
* Tuple representing all members of the {@link Platform} enum.
|
|
40
|
+
*/
|
|
41
|
+
export type PlatformsTuple = UnionToTuple<Platform>;
|
|
42
|
+
/**
|
|
43
|
+
* Checksum types expected by the CLI.
|
|
44
|
+
*/
|
|
45
|
+
export type Checksums = {
|
|
46
|
+
algorithm: string;
|
|
47
|
+
binaries: Record<Binary, Record<`${Platform}-${Architecture}`, string>>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Checksum type expected by application code, specific to the selected
|
|
51
|
+
* {@link Platform} and {@link Architecture}. See also: {@link Checksums}.
|
|
52
|
+
*/
|
|
53
|
+
export type PlatformArchChecksums = {
|
|
54
|
+
algorithm: string;
|
|
55
|
+
binaries: Record<Binary, string>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Given a map of raw yargs options config, returns a map of inferred types.
|
|
59
|
+
*/
|
|
60
|
+
export type ParsedOptions<O extends {
|
|
61
|
+
[key: string]: Options;
|
|
62
|
+
}> = {
|
|
63
|
+
[key in keyof O]: InferredOptionTypes<O>[key];
|
|
64
|
+
};
|
|
65
|
+
export type DownloadOptions = {
|
|
66
|
+
method?: 'GET' | 'HEAD';
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
agent?: HttpsAgent | HttpAgent;
|
|
69
|
+
maxRedirects?: number;
|
|
70
|
+
};
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,mBAAmB;AACtD,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,kBAAkB;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,cAAc;AAI1D,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GACv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QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,IAAI;KAC/D,GAAG,IAAI,MAAM,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// #endregion utils
|
|
2
|
+
// #region enums
|
|
3
|
+
export var Architecture;
|
|
4
|
+
(function (Architecture) {
|
|
5
|
+
Architecture["Amd64"] = "amd64";
|
|
6
|
+
Architecture["Arm64"] = "arm64";
|
|
7
|
+
})(Architecture || (Architecture = {}));
|
|
8
|
+
export var Extension;
|
|
9
|
+
(function (Extension) {
|
|
10
|
+
Extension["Zip"] = "zip";
|
|
11
|
+
Extension["Tar"] = "tar.gz";
|
|
12
|
+
})(Extension || (Extension = {}));
|
|
13
|
+
export var Platform;
|
|
14
|
+
(function (Platform) {
|
|
15
|
+
Platform["Windows"] = "win32";
|
|
16
|
+
Platform["Linux"] = "linux";
|
|
17
|
+
Platform["Mac"] = "darwin";
|
|
18
|
+
})(Platform || (Platform = {}));
|
|
19
|
+
export var Binary;
|
|
20
|
+
(function (Binary) {
|
|
21
|
+
Binary["Anvil"] = "anvil";
|
|
22
|
+
Binary["Forge"] = "forge";
|
|
23
|
+
Binary["Cast"] = "cast";
|
|
24
|
+
Binary["Chisel"] = "chisel";
|
|
25
|
+
})(Binary || (Binary = {}));
|
|
26
|
+
// #endregion helpers
|
|
27
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsBA,mBAAmB;AAEnB,gBAAgB;AAEhB,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,+BAAe,CAAA;AACjB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,2BAAc,CAAA;AAChB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAED,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,2BAAe,CAAA;IACf,0BAAc,CAAA;AAChB,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB;AAED,MAAM,CAAN,IAAY,MAKX;AALD,WAAY,MAAM;IAChB,yBAAe,CAAA;IACf,yBAAe,CAAA;IACf,uBAAa,CAAA;IACb,2BAAiB,CAAA;AACnB,CAAC,EALW,MAAM,KAAN,MAAM,QAKjB;AAoDD,qBAAqB","sourcesContent":["import type { Agent as HttpsAgent } from 'node:https';\nimport type { Agent as HttpAgent } from 'node:http';\nimport type { InferredOptionTypes, Options } from 'yargs';\n\n// #region utils\n\ntype UnionToIntersection<U> = ((k: U) => void) extends (k: infer I) => void\n ? I\n : never;\n\ntype LastInUnion<U extends PropertyKey> = UnionToIntersection<\n U extends PropertyKey ? () => U : never\n> extends () => infer Last\n ? Last\n : never;\n\ntype UnionToTuple<U extends PropertyKey, Last = LastInUnion<U>> = [U] extends [\n never,\n]\n ? []\n : [...UnionToTuple<Exclude<U, Last>>, Last];\n\n// #endregion utils\n\n// #region enums\n\nexport enum Architecture {\n Amd64 = 'amd64',\n Arm64 = 'arm64',\n}\n\nexport enum Extension {\n Zip = 'zip',\n Tar = 'tar.gz',\n}\n\nexport enum Platform {\n Windows = 'win32',\n Linux = 'linux',\n Mac = 'darwin',\n}\n\nexport enum Binary {\n Anvil = 'anvil',\n Forge = 'forge',\n Cast = 'cast',\n Chisel = 'chisel',\n}\n\n// #endregion enums\n\n// #region helpers\n\n/**\n * Tuple representing all members of the {@link Binary} enum.\n */\nexport type BinariesTuple = UnionToTuple<Binary>;\n\n/**\n * Tuple representing all members of the {@link Architecture} enum.\n */\nexport type ArchitecturesTuple = UnionToTuple<Architecture>;\n\n/**\n * Tuple representing all members of the {@link Platform} enum.\n */\nexport type PlatformsTuple = UnionToTuple<Platform>;\n\n/**\n * Checksum types expected by the CLI.\n */\nexport type Checksums = {\n algorithm: string;\n binaries: Record<Binary, Record<`${Platform}-${Architecture}`, string>>;\n};\n\n/**\n * Checksum type expected by application code, specific to the selected\n * {@link Platform} and {@link Architecture}. See also: {@link Checksums}.\n */\nexport type PlatformArchChecksums = {\n algorithm: string;\n binaries: Record<Binary, string>;\n};\n\n/**\n * Given a map of raw yargs options config, returns a map of inferred types.\n */\nexport type ParsedOptions<O extends { [key: string]: Options }> = {\n [key in keyof O]: InferredOptionTypes<O>[key];\n};\n\nexport type DownloadOptions = {\n method?: 'GET' | 'HEAD';\n headers?: Record<string, string>;\n agent?: HttpsAgent | HttpAgent;\n maxRedirects?: number;\n};\n\n// #endregion helpers\n"]}
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformChecksums = exports.isCodedError = exports.getVersion = exports.say = exports.normalizeSystemArchitecture = exports.noop = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const types_1 = require("./types.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* No Operation. A function that does nothing and returns nothing.
|
|
9
|
+
*
|
|
10
|
+
* @returns `undefined`
|
|
11
|
+
*/
|
|
12
|
+
const noop = () => undefined;
|
|
13
|
+
exports.noop = noop;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the system architecture, normalized to one of the supported
|
|
16
|
+
* {@link Architecture} values.
|
|
17
|
+
*
|
|
18
|
+
* @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
function normalizeSystemArchitecture(architecture = (0, node_os_1.arch)()) {
|
|
22
|
+
if (architecture.startsWith('arm')) {
|
|
23
|
+
// if `arm*`, use `arm64`
|
|
24
|
+
return types_1.Architecture.Arm64;
|
|
25
|
+
}
|
|
26
|
+
else if (architecture === 'x64') {
|
|
27
|
+
// if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon
|
|
28
|
+
// (arm64). we can check this by running `sysctl.proc_translated` and
|
|
29
|
+
// checking the output; `1` === `arm64`. This can happen if the user is
|
|
30
|
+
// running an amd64 version of Node on Apple Silicon. We want to use the
|
|
31
|
+
// binaries native to the system for better performance.
|
|
32
|
+
try {
|
|
33
|
+
if ((0, node_child_process_1.execSync)('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {
|
|
34
|
+
return types_1.Architecture.Arm64;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Ignore error: if sysctl check fails, we assume native amd64
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return types_1.Architecture.Amd64; // Default for all other architectures
|
|
42
|
+
}
|
|
43
|
+
exports.normalizeSystemArchitecture = normalizeSystemArchitecture;
|
|
44
|
+
/**
|
|
45
|
+
* Log a message to the console.
|
|
46
|
+
*
|
|
47
|
+
* @param message - The message to log
|
|
48
|
+
*/
|
|
49
|
+
function say(message) {
|
|
50
|
+
console.log(`[foundryup] ${message}`);
|
|
51
|
+
}
|
|
52
|
+
exports.say = say;
|
|
53
|
+
/**
|
|
54
|
+
* Get the version of the binary at the given path.
|
|
55
|
+
*
|
|
56
|
+
* @param binPath
|
|
57
|
+
* @returns The `--version` reported by the binary
|
|
58
|
+
* @throws If the binary fails to report its version
|
|
59
|
+
*/
|
|
60
|
+
function getVersion(binPath) {
|
|
61
|
+
try {
|
|
62
|
+
return (0, node_child_process_1.execFileSync)(binPath, ['--version']).subarray(0, -1); // ignore newline
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const msg = `Failed to get version for ${binPath}
|
|
66
|
+
|
|
67
|
+
Your selected platform or architecture may be incorrect, or the binary may not
|
|
68
|
+
support your system. If you believe this is an error, please report it.`;
|
|
69
|
+
if (error instanceof Error) {
|
|
70
|
+
error.message = `${msg}\n\n${error.message}`;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
throw new AggregateError([new Error(msg), error]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.getVersion = getVersion;
|
|
77
|
+
function isCodedError(error) {
|
|
78
|
+
return (error instanceof Error && 'code' in error && typeof error.code === 'string');
|
|
79
|
+
}
|
|
80
|
+
exports.isCodedError = isCodedError;
|
|
81
|
+
/**
|
|
82
|
+
* Transforms the CLI checksum object into a platform+arch-specific checksum
|
|
83
|
+
* object.
|
|
84
|
+
*
|
|
85
|
+
* @param checksums - The CLI checksum object
|
|
86
|
+
* @param targetPlatform - The build platform
|
|
87
|
+
* @param targetArch - The build architecture
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
function transformChecksums(checksums, targetPlatform, targetArch) {
|
|
91
|
+
if (!checksums) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const key = `${targetPlatform}-${targetArch}`;
|
|
95
|
+
return {
|
|
96
|
+
algorithm: checksums.algorithm,
|
|
97
|
+
binaries: Object.entries(checksums.binaries).reduce((acc, [name, record]) => {
|
|
98
|
+
acc[name] = record[key];
|
|
99
|
+
return acc;
|
|
100
|
+
}, {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
exports.transformChecksums = transformChecksums;
|
|
104
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2DAA4D;AAC5D,qCAA+B;AAC/B,uCAMiB;AAEjB;;;;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;QAClC,yBAAyB;QACzB,OAAO,oBAAY,CAAC,KAAK,CAAC;KAC3B;SAAM,IAAI,YAAY,KAAK,KAAK,EAAE;QACjC,qEAAqE;QACrE,qEAAqE;QACrE,uEAAuE;QACvE,wEAAwE;QACxE,wDAAwD;QACxD,IAAI;YACF,IAAI,IAAA,6BAAQ,EAAC,8CAA8C,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;gBACrE,OAAO,oBAAY,CAAC,KAAK,CAAC;aAC3B;SACF;QAAC,MAAM;YACN,8DAA8D;SAC/D;KACF;IAED,OAAO,oBAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;AACnE,CAAC;AAtBD,kEAsBC;AAED;;;;GAIG;AACH,SAAgB,GAAG,CAAC,OAAe;IACjC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC;AAFD,kBAEC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,OAAe;IACxC,IAAI;QACF,OAAO,IAAA,iCAAY,EAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB;KAC/E;IAAC,OAAO,KAAc,EAAE;QACvB,MAAM,GAAG,GAAG,6BAA6B,OAAO;;;wEAGoB,CAAC;QACrE,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,KAAK,CAAC,OAAO,GAAG,GAAG,GAAG,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;YAC7C,MAAM,KAAK,CAAC;SACb;QACD,MAAM,IAAI,cAAc,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;KACnD;AACH,CAAC;AAdD,gCAcC;AAED,SAAgB,YAAY,CAC1B,KAAc;IAEd,OAAO,CACL,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC5E,CAAC;AACJ,CAAC;AAND,oCAMC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAAgC,EAChC,cAAwB,EACxB,UAAwB;IAExB,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,IAAI,CAAC;KACb;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';\nimport {\n type Checksums,\n type PlatformArchChecksums,\n Architecture,\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\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\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\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\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"]}
|