@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAmB;AAC5D,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAId,oBAAmB;AAapB;;GAEG;AACH,wBAAgB,WAAW,SAkB1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAAM,EAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCvD"}
@@ -1,8 +1,8 @@
1
- import { platform } from 'node:os';
2
- import { argv, stdout } from 'node:process';
3
- import yargs from 'yargs/yargs';
4
- import { Architecture, Binary, Platform } from './types.js';
5
- import { normalizeSystemArchitecture } from './utils.js';
1
+ import { platform } from "node:os";
2
+ import { argv, stdout } from "node:process";
3
+ import yargs from "yargs/yargs";
4
+ import { Architecture, Binary, Platform } from "./types.mjs";
5
+ import { normalizeSystemArchitecture } from "./utils.mjs";
6
6
  /**
7
7
  * Type guard to check if a string is a valid version string starting with 'v'.
8
8
  *
@@ -146,4 +146,4 @@ function getOptions(defaultPlatform = platform(), defaultArch = normalizeSystemA
146
146
  },
147
147
  };
148
148
  }
149
- //# sourceMappingURL=options.js.map
149
+ //# 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;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAmB;AAQ5D,OAAO,EAAE,2BAA2B,EAAE,oBAAmB;AAEzD;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;CAgBb,CAAC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,OAAiB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,EAAE;QAClC,+DAA+D;SAC9D,MAAM,EAA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,GAAG;YACV,WAAW,EAAE,0BAA0B;YACvC,6EAA6E;YAC7E,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAuB;SAC3D;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,sBAAsB;YACnC,6EAA6E;YAC7E,OAAO,EAAE,eAA2B;YACpC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAmB;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { platform } from 'node:os';\nimport { argv, stdout } from 'node:process';\nimport yargs from 'yargs/yargs';\n\nimport { Architecture, Binary, Platform } from './types.js';\nimport type {\n Checksums,\n ParsedOptions,\n ArchitecturesTuple,\n BinariesTuple,\n PlatformsTuple,\n} from './types.js';\nimport { normalizeSystemArchitecture } from './utils.js';\n\n/**\n * Type guard to check if a string is a valid version string starting with 'v'.\n *\n * @param value - The string to check\n * @returns True if the string is a valid version string\n */\nfunction isVersionString(value: string): value is `v${string}` {\n return /^v\\d/u.test(value);\n}\n\n/**\n * Prints the Foundry banner to the console.\n */\nexport function printBanner() {\n console.log(`\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\n ╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit\n ╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development\n ╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n\nRepo : https://github.com/foundry-rs/\nBook : https://book.getfoundry.sh/\nChat : https://t.me/foundry_rs/\nSupport : https://t.me/foundry_support/\nContribute : https://github.com/orgs/foundry-rs/projects/2/\n\n.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx\n`);\n}\n\n/**\n * Parses command line arguments and returns the parsed options.\n *\n * @param args - Command line arguments to parse\n * @returns Parsed command line arguments\n */\nexport function parseArgs(args: string[] = argv.slice(2)) {\n const { $0, _, ...parsed } = yargs()\n // Ensure unrecognized commands/options are reported as errors.\n .strict()\n // disable yargs's version, as it doesn't make sense here\n .version(false)\n // use the scriptName in `--help` output\n .scriptName('yarn foundryup')\n // wrap output at a maximum of 120 characters or `stdout.columns`\n .wrap(Math.min(120, stdout.columns))\n .parserConfiguration({\n 'strip-aliased': true,\n 'strip-dashed': true,\n })\n // enable ENV parsing, which allows the user to specify foundryup options\n // via environment variables prefixed with `FOUNDRYUP_`\n .env('FOUNDRYUP')\n .command(['$0', 'install'], 'Install foundry binaries', (builder) => {\n builder.options(getOptions()).pkgConf('foundryup');\n })\n .command('cache', '', (builder) => {\n builder.command('clean', 'Remove the shared cache files').demandCommand();\n })\n .parseSync(args);\n\n const command = _.join(' ');\n if (command === 'cache clean') {\n return {\n command,\n } as const;\n }\n\n // if we get here `command` is always 'install' or '' (yargs checks it)\n return {\n command: 'install',\n options: parsed as ParsedOptions<ReturnType<typeof getOptions>>,\n } as const;\n}\n\nconst Binaries = Object.values(Binary) as BinariesTuple;\n\n/**\n * Returns the command line options configuration.\n *\n * @param defaultPlatform - Default platform to use\n * @param defaultArch - Default architecture to use\n * @returns Command line options configuration\n */\nfunction getOptions(\n defaultPlatform = platform(),\n defaultArch = normalizeSystemArchitecture(),\n) {\n return {\n binaries: {\n alias: 'b',\n type: 'array' as const,\n multiple: true,\n description: 'Specify the binaries to install',\n default: Binaries,\n choices: Binaries,\n coerce: (values: Binary[]): Binary[] => [...new Set(values)], // Remove duplicates\n },\n checksums: {\n alias: 'c',\n description: 'JSON object containing checksums for the binaries.',\n coerce: (rawChecksums: string | Checksums): Checksums => {\n try {\n return typeof rawChecksums === 'string'\n ? JSON.parse(rawChecksums)\n : rawChecksums;\n } catch {\n throw new Error('Invalid checksums');\n }\n },\n optional: true,\n },\n repo: {\n alias: 'r',\n description: 'Specify the repository',\n default: 'foundry-rs/foundry',\n },\n version: {\n alias: 'v',\n description:\n 'Specify the version (see: https://github.com/foundry-rs/foundry/tags)',\n default: 'nightly',\n coerce: (\n rawVersion: string,\n ): { version: 'nightly' | `v${string}`; tag: string } => {\n if (rawVersion.startsWith('nightly')) {\n return { version: 'nightly', tag: rawVersion };\n // we don't validate the version much, we just trust the user\n } else if (isVersionString(rawVersion)) {\n return { version: rawVersion, tag: rawVersion };\n }\n throw new Error('Invalid version');\n },\n },\n arch: {\n alias: 'a',\n description: 'Specify the architecture',\n // if `defaultArch` is not a supported Architecture yargs will throw an error\n default: defaultArch,\n choices: Object.values(Architecture) as ArchitecturesTuple,\n },\n platform: {\n alias: 'p',\n description: 'Specify the platform',\n // if `defaultPlatform` is not a supported Platform yargs will throw an error\n default: defaultPlatform as Platform,\n choices: Object.values(Platform) as PlatformsTuple,\n },\n };\n}\n"]}
package/dist/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":";;;AAuBA,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;AAsDD,qBAAqB","sourcesContent":["import type { Agent as HttpAgent } from 'node:http';\nimport type { Agent as HttpsAgent } from 'node:https';\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> =\n 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}.\n *\n * 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"]}
@@ -1,6 +1,12 @@
1
- import type { Agent as HttpAgent } from 'node:http';
2
- import type { Agent as HttpsAgent } from 'node:https';
3
- import type { InferredOptionTypes, Options } from 'yargs';
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node/http" />
4
+ /// <reference types="npm-which/node_modules/@types/node/http" />
5
+ /// <reference types="node/https" />
6
+ /// <reference types="npm-which/node_modules/@types/node/https" />
7
+ import type { Agent as HttpAgent } from "node:http";
8
+ import type { Agent as HttpsAgent } from "node:https";
9
+ import type { InferredOptionTypes, Options } from "yargs";
4
10
  type UnionToIntersection<U> = ((k: U) => void) extends (k: infer I) => void ? I : never;
5
11
  type LastInUnion<U extends PropertyKey> = UnionToIntersection<U extends PropertyKey ? () => U : never> extends () => infer Last ? Last : never;
6
12
  type UnionToTuple<U extends PropertyKey, Last = LastInUnion<U>> = [U] extends [
@@ -69,4 +75,4 @@ export type DownloadOptions = {
69
75
  maxRedirects?: number;
70
76
  };
71
77
  export {};
72
- //# sourceMappingURL=types.d.ts.map
78
+ //# 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,SAAS,EAAE,kBAAkB;AACpD,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,mBAAmB;AACtD,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,IACpC,mBAAmB,CACjB,CAAC,SAAS,WAAW,GAAG,MAAM,CAAC,GAAG,KAAK,CACxC,SAAS,MAAM,MAAM,IAAI,GACtB,IAAI,GACJ,KAAK,CAAC;AAEZ,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,UAA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AC,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -0,0 +1,78 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node/http" />
4
+ /// <reference types="npm-which/node_modules/@types/node/http" />
5
+ /// <reference types="node/https" />
6
+ /// <reference types="npm-which/node_modules/@types/node/https" />
7
+ import type { Agent as HttpAgent } from "node:http";
8
+ import type { Agent as HttpsAgent } from "node:https";
9
+ import type { InferredOptionTypes, Options } from "yargs";
10
+ type UnionToIntersection<U> = ((k: U) => void) extends (k: infer I) => void ? I : never;
11
+ type LastInUnion<U extends PropertyKey> = UnionToIntersection<U extends PropertyKey ? () => U : never> extends () => infer Last ? Last : never;
12
+ type UnionToTuple<U extends PropertyKey, Last = LastInUnion<U>> = [U] extends [
13
+ never
14
+ ] ? [] : [...UnionToTuple<Exclude<U, Last>>, Last];
15
+ export declare enum Architecture {
16
+ Amd64 = "amd64",
17
+ Arm64 = "arm64"
18
+ }
19
+ export declare enum Extension {
20
+ Zip = "zip",
21
+ Tar = "tar.gz"
22
+ }
23
+ export declare enum Platform {
24
+ Windows = "win32",
25
+ Linux = "linux",
26
+ Mac = "darwin"
27
+ }
28
+ export declare enum Binary {
29
+ Anvil = "anvil",
30
+ Forge = "forge",
31
+ Cast = "cast",
32
+ Chisel = "chisel"
33
+ }
34
+ /**
35
+ * Tuple representing all members of the {@link Binary} enum.
36
+ */
37
+ export type BinariesTuple = UnionToTuple<Binary>;
38
+ /**
39
+ * Tuple representing all members of the {@link Architecture} enum.
40
+ */
41
+ export type ArchitecturesTuple = UnionToTuple<Architecture>;
42
+ /**
43
+ * Tuple representing all members of the {@link Platform} enum.
44
+ */
45
+ export type PlatformsTuple = UnionToTuple<Platform>;
46
+ /**
47
+ * Checksum types expected by the CLI.
48
+ */
49
+ export type Checksums = {
50
+ algorithm: string;
51
+ binaries: Record<Binary, Record<`${Platform}-${Architecture}`, string>>;
52
+ };
53
+ /**
54
+ * Checksum type expected by application code, specific to the selected
55
+ * {@link Platform} and {@link Architecture}.
56
+ *
57
+ * See also: {@link Checksums}.
58
+ */
59
+ export type PlatformArchChecksums = {
60
+ algorithm: string;
61
+ binaries: Record<Binary, string>;
62
+ };
63
+ /**
64
+ * Given a map of raw yargs options config, returns a map of inferred types.
65
+ */
66
+ export type ParsedOptions<O extends {
67
+ [key: string]: Options;
68
+ }> = {
69
+ [key in keyof O]: InferredOptionTypes<O>[key];
70
+ };
71
+ export type DownloadOptions = {
72
+ method?: 'GET' | 'HEAD';
73
+ headers?: Record<string, string>;
74
+ agent?: HttpsAgent | HttpAgent;
75
+ maxRedirects?: number;
76
+ };
77
+ export {};
78
+ //# 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,SAAS,EAAE,kBAAkB;AACpD,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,mBAAmB;AACtD,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,IACpC,mBAAmB,CACjB,CAAC,SAAS,WAAW,GAAG,MAAM,CAAC,GAAG,KAAK,CACxC,SAAS,MAAM,MAAM,IAAI,GACtB,IAAI,GACJ,KAAK,CAAC;AAEZ,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,CA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AAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -24,4 +24,4 @@ export var Binary;
24
24
  Binary["Chisel"] = "chisel";
25
25
  })(Binary || (Binary = {}));
26
26
  // #endregion helpers
27
- //# sourceMappingURL=types.js.map
27
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuBA,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;AAsDD,qBAAqB","sourcesContent":["import type { Agent as HttpAgent } from 'node:http';\nimport type { Agent as HttpsAgent } from 'node:https';\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> =\n 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}.\n *\n * 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,110 @@
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_js_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 The normalized architecture value
20
+ */
21
+ function normalizeSystemArchitecture(architecture = (0, node_os_1.arch)()) {
22
+ if (architecture.startsWith('arm')) {
23
+ // if `arm*`, use `arm64`
24
+ return types_js_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_js_1.Architecture.Arm64;
35
+ }
36
+ }
37
+ catch {
38
+ // Ignore error: if sysctl check fails, we assume native amd64
39
+ }
40
+ }
41
+ return types_js_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 - Path to the binary executable
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
+ /**
78
+ * Type guard to check if an error has a code property.
79
+ *
80
+ * @param error - The error to check
81
+ * @returns True if the error has a code property
82
+ */
83
+ function isCodedError(error) {
84
+ return (error instanceof Error && 'code' in error && typeof error.code === 'string');
85
+ }
86
+ exports.isCodedError = isCodedError;
87
+ /**
88
+ * Transforms the CLI checksum object into a platform+arch-specific checksum
89
+ * object.
90
+ *
91
+ * @param checksums - The CLI checksum object
92
+ * @param targetPlatform - The build platform
93
+ * @param targetArch - The build architecture
94
+ * @returns Platform and architecture specific checksums or null if no checksums provided
95
+ */
96
+ function transformChecksums(checksums, targetPlatform, targetArch) {
97
+ if (!checksums) {
98
+ return null;
99
+ }
100
+ const key = `${targetPlatform}-${targetArch}`;
101
+ return {
102
+ algorithm: checksums.algorithm,
103
+ binaries: Object.entries(checksums.binaries).reduce((acc, [name, record]) => {
104
+ acc[name] = record[key];
105
+ return acc;
106
+ }, {}),
107
+ };
108
+ }
109
+ exports.transformChecksums = transformChecksums;
110
+ //# 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;AAE/B,0CAA0C;AAQ1C;;;;GAIG;AACI,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;AAAvB,QAAA,IAAI,QAAmB;AAEpC;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACzC,eAAuB,IAAA,cAAI,GAAE;IAE7B,IAAI,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,yBAAyB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AEd,OAAO,CACL,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC5E,CAAC;AACJ,CAAC;AAND,oCAMC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAAgC,EAChC,cAAwB,EACxB,UAAwB;IAExB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,cAAc,IAAI,UAAU,EAAW,CAAC;IACvD,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACtB,GAAG,CAAC,IAAc,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B;KACF,CAAC;AACJ,CAAC;AApBD,gDAoBC","sourcesContent":["import { execFileSync, execSync } from 'node:child_process';\nimport { arch } from 'node:os';\n\nimport { Architecture } from './types.js';\nimport type {\n Checksums,\n PlatformArchChecksums,\n Binary,\n Platform,\n} from './types.js';\n\n/**\n * No Operation. A function that does nothing and returns nothing.\n *\n * @returns `undefined`\n */\nexport const noop = () => undefined;\n\n/**\n * Returns the system architecture, normalized to one of the supported\n * {@link Architecture} values.\n *\n * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')\n * @returns The normalized architecture value\n */\nexport function normalizeSystemArchitecture(\n architecture: string = arch(),\n): Architecture {\n if (architecture.startsWith('arm')) {\n // if `arm*`, use `arm64`\n return Architecture.Arm64;\n } else if (architecture === 'x64') {\n // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon\n // (arm64). we can check this by running `sysctl.proc_translated` and\n // checking the output; `1` === `arm64`. This can happen if the user is\n // running an amd64 version of Node on Apple Silicon. We want to use the\n // binaries native to the system for better performance.\n try {\n if (execSync('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {\n return Architecture.Arm64;\n }\n } catch {\n // Ignore error: if sysctl check fails, we assume native amd64\n }\n }\n\n return Architecture.Amd64; // Default for all other architectures\n}\n\n/**\n * Log a message to the console.\n *\n * @param message - The message to log\n */\nexport function say(message: string) {\n console.log(`[foundryup] ${message}`);\n}\n\n/**\n * Get the version of the binary at the given path.\n *\n * @param binPath - Path to the binary executable\n * @returns The `--version` reported by the binary\n * @throws If the binary fails to report its version\n */\nexport function getVersion(binPath: string): Buffer {\n try {\n return execFileSync(binPath, ['--version']).subarray(0, -1); // ignore newline\n } catch (error: unknown) {\n const msg = `Failed to get version for ${binPath}\n\nYour selected platform or architecture may be incorrect, or the binary may not\nsupport your system. If you believe this is an error, please report it.`;\n if (error instanceof Error) {\n error.message = `${msg}\\n\\n${error.message}`;\n throw error;\n }\n throw new AggregateError([new Error(msg), error]);\n }\n}\n\n/**\n * Type guard to check if an error has a code property.\n *\n * @param error - The error to check\n * @returns True if the error has a code property\n */\nexport function isCodedError(\n error: unknown,\n): error is Error & { code: string } {\n return (\n error instanceof Error && 'code' in error && typeof error.code === 'string'\n );\n}\n\n/**\n * Transforms the CLI checksum object into a platform+arch-specific checksum\n * object.\n *\n * @param checksums - The CLI checksum object\n * @param targetPlatform - The build platform\n * @param targetArch - The build architecture\n * @returns Platform and architecture specific checksums or null if no checksums provided\n */\nexport function transformChecksums(\n checksums: Checksums | undefined,\n targetPlatform: Platform,\n targetArch: Architecture,\n): PlatformArchChecksums | null {\n if (!checksums) {\n return null;\n }\n\n const key = `${targetPlatform}-${targetArch}` as const;\n return {\n algorithm: checksums.algorithm,\n binaries: Object.entries(checksums.binaries).reduce(\n (acc, [name, record]) => {\n acc[name as Binary] = record[key];\n return acc;\n },\n {} as Record<Binary, string>,\n ),\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { Architecture } from './types.js';
2
- import type { Checksums, PlatformArchChecksums, Platform } from './types.js';
1
+ import { Architecture } from "./types.cjs";
2
+ import type { Checksums, PlatformArchChecksums, Platform } from "./types.cjs";
3
3
  /**
4
4
  * No Operation. A function that does nothing and returns nothing.
5
5
  *
@@ -47,4 +47,4 @@ export declare function isCodedError(error: unknown): error is Error & {
47
47
  * @returns Platform and architecture specific checksums or null if no checksums provided
48
48
  */
49
49
  export declare function transformChecksums(checksums: Checksums | undefined, targetPlatform: Platform, targetArch: Architecture): PlatformArchChecksums | null;
50
- //# sourceMappingURL=utils.d.ts.map
50
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAC1C,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,QAAQ,EACT,oBAAmB;AAEpB;;;;GAIG;AACH,eAAO,MAAM,IAAI,iBAAkB,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,GAAE,MAAe,GAC5B,YAAY,CAoBd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,YAAY,GACvB,qBAAqB,GAAG,IAAI,CAgB9B"}
@@ -0,0 +1,50 @@
1
+ import { Architecture } from "./types.mjs";
2
+ import type { Checksums, PlatformArchChecksums, Platform } from "./types.mjs";
3
+ /**
4
+ * No Operation. A function that does nothing and returns nothing.
5
+ *
6
+ * @returns `undefined`
7
+ */
8
+ export declare const noop: () => undefined;
9
+ /**
10
+ * Returns the system architecture, normalized to one of the supported
11
+ * {@link Architecture} values.
12
+ *
13
+ * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')
14
+ * @returns The normalized architecture value
15
+ */
16
+ export declare function normalizeSystemArchitecture(architecture?: string): Architecture;
17
+ /**
18
+ * Log a message to the console.
19
+ *
20
+ * @param message - The message to log
21
+ */
22
+ export declare function say(message: string): void;
23
+ /**
24
+ * Get the version of the binary at the given path.
25
+ *
26
+ * @param binPath - Path to the binary executable
27
+ * @returns The `--version` reported by the binary
28
+ * @throws If the binary fails to report its version
29
+ */
30
+ export declare function getVersion(binPath: string): Buffer;
31
+ /**
32
+ * Type guard to check if an error has a code property.
33
+ *
34
+ * @param error - The error to check
35
+ * @returns True if the error has a code property
36
+ */
37
+ export declare function isCodedError(error: unknown): error is Error & {
38
+ code: string;
39
+ };
40
+ /**
41
+ * Transforms the CLI checksum object into a platform+arch-specific checksum
42
+ * object.
43
+ *
44
+ * @param checksums - The CLI checksum object
45
+ * @param targetPlatform - The build platform
46
+ * @param targetArch - The build architecture
47
+ * @returns Platform and architecture specific checksums or null if no checksums provided
48
+ */
49
+ export declare function transformChecksums(checksums: Checksums | undefined, targetPlatform: Platform, targetArch: Architecture): PlatformArchChecksums | null;
50
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAC1C,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EAErB,QAAQ,EACT,oBAAmB;AAEpB;;;;GAIG;AACH,eAAO,MAAM,IAAI,iBAAkB,CAAC;AAEpC;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,GAAE,MAAe,GAC5B,YAAY,CAoBd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAInC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,YAAY,GACvB,qBAAqB,GAAG,IAAI,CAgB9B"}
@@ -1,6 +1,6 @@
1
- import { execFileSync, execSync } from 'node:child_process';
2
- import { arch } from 'node:os';
3
- import { Architecture } from './types.js';
1
+ import { execFileSync, execSync } from "node:child_process";
2
+ import { arch } from "node:os";
3
+ import { Architecture } from "./types.mjs";
4
4
  /**
5
5
  * No Operation. A function that does nothing and returns nothing.
6
6
  *
@@ -98,4 +98,4 @@ export function transformChecksums(checksums, targetPlatform, targetArch) {
98
98
  }, {}),
99
99
  };
100
100
  }
101
- //# sourceMappingURL=utils.js.map
101
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,2BAA2B;AAC5D,OAAO,EAAE,IAAI,EAAE,gBAAgB;AAE/B,OAAO,EAAE,YAAY,EAAE,oBAAmB;AAQ1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CACzC,eAAuB,IAAI,EAAE;IAE7B,IAAI,YAAY,CAAC,UAAU,CAAC,KA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CACL,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC5E,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAgC,EAChC,cAAwB,EACxB,UAAwB;IAExB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,cAAc,IAAI,UAAU,EAAW,CAAC;IACvD,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACtB,GAAG,CAAC,IAAc,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { execFileSync, execSync } from 'node:child_process';\nimport { arch } from 'node:os';\n\nimport { Architecture } from './types.js';\nimport type {\n Checksums,\n PlatformArchChecksums,\n Binary,\n Platform,\n} from './types.js';\n\n/**\n * No Operation. A function that does nothing and returns nothing.\n *\n * @returns `undefined`\n */\nexport const noop = () => undefined;\n\n/**\n * Returns the system architecture, normalized to one of the supported\n * {@link Architecture} values.\n *\n * @param architecture - The architecture string to normalize (e.g., 'x64', 'arm64')\n * @returns The normalized architecture value\n */\nexport function normalizeSystemArchitecture(\n architecture: string = arch(),\n): Architecture {\n if (architecture.startsWith('arm')) {\n // if `arm*`, use `arm64`\n return Architecture.Arm64;\n } else if (architecture === 'x64') {\n // if `x64`, it _might_ be amd64 running via Rosetta on Apple Silicon\n // (arm64). we can check this by running `sysctl.proc_translated` and\n // checking the output; `1` === `arm64`. This can happen if the user is\n // running an amd64 version of Node on Apple Silicon. We want to use the\n // binaries native to the system for better performance.\n try {\n if (execSync('sysctl -n sysctl.proc_translated 2>/dev/null')[0] === 1) {\n return Architecture.Arm64;\n }\n } catch {\n // Ignore error: if sysctl check fails, we assume native amd64\n }\n }\n\n return Architecture.Amd64; // Default for all other architectures\n}\n\n/**\n * Log a message to the console.\n *\n * @param message - The message to log\n */\nexport function say(message: string) {\n console.log(`[foundryup] ${message}`);\n}\n\n/**\n * Get the version of the binary at the given path.\n *\n * @param binPath - Path to the binary executable\n * @returns The `--version` reported by the binary\n * @throws If the binary fails to report its version\n */\nexport function getVersion(binPath: string): Buffer {\n try {\n return execFileSync(binPath, ['--version']).subarray(0, -1); // ignore newline\n } catch (error: unknown) {\n const msg = `Failed to get version for ${binPath}\n\nYour selected platform or architecture may be incorrect, or the binary may not\nsupport your system. If you believe this is an error, please report it.`;\n if (error instanceof Error) {\n error.message = `${msg}\\n\\n${error.message}`;\n throw error;\n }\n throw new AggregateError([new Error(msg), error]);\n }\n}\n\n/**\n * Type guard to check if an error has a code property.\n *\n * @param error - The error to check\n * @returns True if the error has a code property\n */\nexport function isCodedError(\n error: unknown,\n): error is Error & { code: string } {\n return (\n error instanceof Error && 'code' in error && typeof error.code === 'string'\n );\n}\n\n/**\n * Transforms the CLI checksum object into a platform+arch-specific checksum\n * object.\n *\n * @param checksums - The CLI checksum object\n * @param targetPlatform - The build platform\n * @param targetArch - The build architecture\n * @returns Platform and architecture specific checksums or null if no checksums provided\n */\nexport function transformChecksums(\n checksums: Checksums | undefined,\n targetPlatform: Platform,\n targetArch: Architecture,\n): PlatformArchChecksums | null {\n if (!checksums) {\n return null;\n }\n\n const key = `${targetPlatform}-${targetArch}` as const;\n return {\n algorithm: checksums.algorithm,\n binaries: Object.entries(checksums.binaries).reduce(\n (acc, [name, record]) => {\n acc[name as Binary] = record[key];\n return acc;\n },\n {} as Record<Binary, string>,\n ),\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/foundryup",
3
- "version": "1.0.1-preview-4f4c98e",
3
+ "version": "1.0.1-preview-eb263b0ee",
4
4
  "description": "foundryup",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -16,13 +16,14 @@
16
16
  "url": "https://github.com/MetaMask/core.git"
17
17
  },
18
18
  "bin": {
19
- "mm-foundryup": "./dist/cli.js"
19
+ "mm-foundryup": "./dist/cli.mjs"
20
20
  },
21
21
  "files": [
22
22
  "dist/"
23
23
  ],
24
- "type": "module",
25
24
  "sideEffects": false,
25
+ "main": "./dist/index.cjs",
26
+ "types": "./dist/index.d.cts",
26
27
  "exports": {
27
28
  "./package.json": "./package.json"
28
29
  },
@@ -32,11 +33,9 @@
32
33
  },
33
34
  "scripts": {
34
35
  "anvil": "node_modules/.bin/anvil",
35
- "build": "tsc --project tsconfig.build.json",
36
- "build:all": "tsc --build tsconfig.build.json --verbose",
37
- "build:clean": "yarn build:only-clean && yarn build",
36
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
37
+ "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
38
38
  "build:docs": "typedoc",
39
- "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
40
39
  "changelog:update": "../../scripts/update-changelog.sh @metamask/foundryup",
41
40
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/foundryup",
42
41
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -56,23 +55,22 @@
56
55
  },
57
56
  "devDependencies": {
58
57
  "@metamask/auto-changelog": "^6.1.0",
58
+ "@ts-bridge/cli": "^0.6.4",
59
59
  "@types/jest": "^30.0.0",
60
60
  "@types/unzipper": "^0.10.10",
61
61
  "@types/yargs": "^17.0.32",
62
62
  "@types/yargs-parser": "^21.0.3",
63
- "@typescript/native": "npm:typescript@^7.0.2",
64
63
  "deepmerge": "^4.2.2",
65
64
  "jest": "^30.4.2",
66
65
  "nock": "^13.3.1",
67
- "rimraf": "^5.0.5",
68
66
  "ts-jest": "^29.4.11",
69
67
  "tsx": "^4.20.5",
70
68
  "typedoc": "^0.25.13",
71
69
  "typedoc-plugin-missing-exports": "^2.0.0",
72
- "typescript": "npm:@typescript/typescript6@^6.0.2",
70
+ "typescript": "~5.3.3",
73
71
  "yaml": "^2.3.4"
74
72
  },
75
73
  "engines": {
76
- "node": "^22.14.0 || ^24"
74
+ "node": "^18.18 || >=20"
77
75
  }
78
76
  }
package/dist/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAE/D;;GAEG;AACH,iCAAiC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAClD;;;;OAIG;IACH,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * CLI entry point for Foundryup.\n *\n * This script downloads and installs Foundry binaries.\n * If an error occurs, it logs the error and exits with code 1.\n */\nimport { downloadAndInstallFoundryBinaries } from './index.js';\n\n/**\n * Run the main installation process and handle errors.\n */\ndownloadAndInstallFoundryBinaries().catch((error) => {\n /**\n * Log any error that occurs during installation and exit with code 1.\n *\n * @param error - The error thrown during installation.\n */\n console.error('Error:', error);\n process.exit(1);\n});\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../src/download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AG,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CACT,OAAO,EACP,IAAI,KAAK,CACP,cAAc,GAAG,yBAAyB,UAAU,MAAM,aAAa,EAAE,CAC1E,CACF,CAAC;YACF,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,+BAA+B;YAC/B,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAElC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YAC1D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC,CAAC;SACC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SAChD,GAAG,EAAE,CAAC;IACT,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { request as httpRequest } from 'node:http';\nimport type { IncomingMessage } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { Stream } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport type { DownloadOptions } from './types.js';\n\n/**\n * A PassThrough stream that emits a 'response' event when the HTTP(S) response is available.\n */\nclass DownloadStream extends Stream.PassThrough {\n /**\n * Returns a promise that resolves with the HTTP(S) IncomingMessage response.\n *\n * @returns The HTTP(S) response stream.\n */\n async response(): Promise<IncomingMessage> {\n return new Promise((resolve, reject) => {\n this.once('response', resolve);\n this.once('error', reject);\n });\n }\n}\n\n/**\n * Starts a download from the given URL.\n *\n * @param url - The URL to download from\n * @param options - The download options\n * @param redirects - The number of redirects that have occurred\n * @returns A stream of the download\n */\nexport function startDownload(\n url: URL,\n options: DownloadOptions = {},\n redirects: number = 0,\n) {\n const MAX_REDIRECTS = options.maxRedirects ?? 5;\n const request = url.protocol === 'http:' ? httpRequest : httpsRequest;\n const stream = new DownloadStream();\n request(url, options, (response) => {\n stream.once('close', () => {\n response.destroy();\n });\n\n const { statusCode, statusMessage, headers } = response;\n // handle redirects\n if (\n statusCode &&\n statusCode >= 300 &&\n statusCode < 400 &&\n headers.location\n ) {\n if (redirects >= MAX_REDIRECTS) {\n stream.emit('error', new Error('Too many redirects'));\n response.destroy();\n } else {\n // note: we don't emit a response until we're done redirecting, because\n // handlers only expect it to be emitted once.\n pipeline(\n startDownload(new URL(headers.location, url), options, redirects + 1)\n // emit the response event to the stream\n .once('response', stream.emit.bind(stream, 'response')),\n stream,\n ).catch(stream.emit.bind(stream, 'error'));\n response.destroy();\n }\n }\n\n // check for HTTP errors\n else if (!statusCode || statusCode < 200 || statusCode >= 300) {\n stream.emit(\n 'error',\n new Error(\n `Request to ${url} failed. Status Code: ${statusCode} - ${statusMessage}`,\n ),\n );\n response.destroy();\n } else {\n // resolve with response stream\n stream.emit('response', response);\n\n response.once('error', stream.emit.bind(stream, 'error'));\n pipeline(response, stream).catch(stream.emit.bind(stream, 'error'));\n }\n })\n .once('error', stream.emit.bind(stream, 'error'))\n .end();\n return stream;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,IAAI,qBAoE1E"}
@@ -1 +0,0 @@
1
- {"version":3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,KAAK,SAAS,CAAC,EAAE,WAAkB;gBACpD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;oBACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACnB,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC,CAAC;YACF,MAAM,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YAC9C,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,MAAM;gBACN,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;aAC7B,CAAC;QACJ,CAAC;QACD,MAAM,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,IAAI;YACV,MAAM;SACP,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { Minipass } from 'minipass';\nimport { ok } from 'node:assert/strict';\nimport { createHash } from 'node:crypto';\nimport { createWriteStream } from 'node:fs';\nimport { rename, mkdir, rm } from 'node:fs/promises';\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { join, basename, extname, relative } from 'node:path';\nimport { pipeline } from 'node:stream/promises';\nimport { extract as extractTar } from 'tar';\nimport { Open } from 'unzipper';\nimport type { Source, Entry } from 'unzipper';\n\nimport { startDownload } from './download.js';\nimport { Extension } from './types.js';\nimport type { Binary } from './types.js';\nimport { say } from './utils.js';\n\n/**\n * Extracts the binaries from the given URL and writes them to the destination.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksums - The checksums to verify the binaries against\n * @returns The list of binaries extracted\n */\n\n/**\n * Extracts the binaries from the given URL and writes them to the destination.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksums - The checksums to verify the binaries against\n * @returns The list of binaries extracted\n */\nexport async function extractFrom(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksums: { algorithm: string; binaries: Record<Binary, string> } | null,\n) {\n const extract = url.pathname.toLowerCase().endsWith(Extension.Tar)\n ? extractFromTar\n : extractFromZip;\n // write all files to a temporary directory first, then rename to the final\n // destination to avoid accidental partial extraction. We don't use\n // `os.tmpdir` for this because `rename` will fail if the directories are on\n // different file systems.\n const tempDir = `${dir}.downloading`;\n const rmOpts = { recursive: true, maxRetries: 3, force: true };\n try {\n // clean up any previous in-progress downloads\n await rm(tempDir, rmOpts);\n // make the temporary directory to extract the binaries to\n await mkdir(tempDir, { recursive: true });\n const downloads = await extract(\n url,\n binaries,\n tempDir,\n checksums?.algorithm,\n );\n ok(downloads.length === binaries.length, 'Failed to extract all binaries');\n\n const paths: string[] = [];\n for (const { path, binary, checksum } of downloads) {\n if (checksums) {\n say(`verifying checksum for ${binary}`);\n const expected = checksums.binaries[binary];\n if (checksum === expected) {\n say(`checksum verified for ${binary}`);\n } else {\n throw new Error(\n `checksum mismatch for ${binary}, expected ${expected}, got ${checksum}`,\n );\n }\n }\n // add the *final* path to the list of binaries\n paths.push(join(dir, relative(tempDir, path)));\n }\n\n // this directory shouldn't exist, but if two simultaneous `yarn foundryup`\n // processes are running, it might. Last process wins, so we remove other\n // `dir`s just in case.\n await rm(dir, rmOpts);\n // everything has been extracted; move the files to their final destination\n await rename(tempDir, dir);\n // return the list of extracted binaries\n return paths;\n } catch (error) {\n // if things fail for any reason try to clean up a bit. it is very important\n // to not leave `dir` behind, as its existence is a signal that the binaries\n // are installed.\n const rmErrors = (\n await Promise.allSettled([rm(tempDir, rmOpts), rm(dir, rmOpts)])\n )\n .filter((r) => r.status === 'rejected')\n .map((r) => r.reason);\n\n // if we failed to clean up, create an aggregate error message\n if (rmErrors.length) {\n throw new AggregateError(\n [error, ...rmErrors],\n 'This is a bug; you should report it.',\n );\n }\n throw error;\n }\n}\n/**\n * Extracts the binaries from a tar archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\n\n/**\n * Extracts the binaries from a tar archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\nasync function extractFromTar(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksumAlgorithm?: string,\n) {\n const downloads: {\n path: string;\n binary: Binary;\n checksum?: string;\n }[] = [];\n await pipeline(\n startDownload(url),\n extractTar(\n {\n cwd: dir,\n // @ts-expect-error: Types here broke in `tar@7.5.12`, but it appears to\n // work fine as-is.\n // See: https://github.com/isaacs/node-tar/issues/459\n transform: (entry) => {\n const absolutePath = entry.absolute;\n if (!absolutePath) {\n throw new Error('Missing absolute path for entry');\n }\n\n if (checksumAlgorithm) {\n const hash = createHash(checksumAlgorithm);\n const passThrough = new Minipass({ async: true });\n passThrough.pipe(hash);\n passThrough.on('end', () => {\n downloads.push({\n path: absolutePath,\n binary: entry.path as Binary,\n checksum: hash.digest('hex'),\n });\n });\n return passThrough;\n }\n\n // When no checksum is needed, record the entry and return undefined\n // to use the original stream without transformation\n downloads.push({\n path: absolutePath,\n binary: entry.path as Binary,\n });\n return undefined;\n },\n },\n binaries,\n ),\n );\n return downloads;\n}\n/**\n * Extracts the binaries from a zip archive.\n *\n * @param url - The URL of the archive to extract the binaries from\n * @param binaries - The list of binaries to extract\n * @param dir - The destination directory\n * @param checksumAlgorithm - The checksum algorithm to use\n * @returns The list of binaries extracted\n */\nasync function extractFromZip(\n url: URL,\n binaries: Binary[],\n dir: string,\n checksumAlgorithm?: string,\n) {\n const agent = new (url.protocol === 'http:' ? HttpAgent : HttpsAgent)({\n keepAlive: true,\n });\n const source: Source = {\n async size() {\n const download = startDownload(url, { agent, method: 'HEAD' });\n const response = await download.response();\n const contentLength = response.headers['content-length'];\n return contentLength ? parseInt(contentLength, 10) : 0;\n },\n stream(offset: number, bytes: number) {\n const options = {\n agent,\n headers: {\n range: `bytes=${offset}-${bytes ? offset + bytes : ''}`,\n },\n };\n return startDownload(url, options);\n },\n };\n\n const { files } = await Open.custom(source, {});\n const filtered = files.filter(({ path }) =>\n binaries.includes(basename(path, extname(path)) as Binary),\n );\n return await Promise.all(\n filtered.map(async ({ path, stream }) => {\n const dest = join(dir, path);\n const entry = stream();\n const destStream = createWriteStream(dest);\n const binary = basename(path, extname(path)) as Binary;\n if (checksumAlgorithm) {\n const hash = createHash(checksumAlgorithm);\n const hashStream = async function* (entryStream: Entry) {\n for await (const chunk of entryStream) {\n hash.update(chunk);\n yield chunk;\n }\n };\n await pipeline(entry, hashStream, destStream);\n return {\n path: dest,\n binary,\n checksum: hash.digest('hex'),\n };\n }\n await pipeline(entry, destStream);\n return {\n path: dest,\n binary,\n };\n }),\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAgBnC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAa,QAAQ,EAAE,MAAM,YAAY,CAAC;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"}