@foundry-rs/forge 1.3.2 → 1.3.4-nightly.20250906.05d4a02

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/bin/forge.mjs ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ import * as NodeModule from "node:module";
3
+ import * as NodeChildProcess from "node:child_process";
4
+ import * as NodeFS from "node:fs";
5
+ import * as NodePath from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ //#region src/const.ts
9
+ const BINARY_DISTRIBUTION_PACKAGES = {
10
+ darwin: {
11
+ x64: "@foundry-rs/forge-darwin-amd64",
12
+ arm64: "@foundry-rs/forge-darwin-arm64"
13
+ },
14
+ linux: {
15
+ x64: "@foundry-rs/forge-linux-amd64",
16
+ arm64: "@foundry-rs/forge-linux-arm64"
17
+ },
18
+ win32: { x64: "@foundry-rs/forge-win32-amd64" }
19
+ };
20
+ const BINARY_NAME = process.platform === "win32" ? "forge.exe" : "forge";
21
+ const PLATFORM_SPECIFIC_PACKAGE_NAME = BINARY_DISTRIBUTION_PACKAGES[process.platform][process.arch];
22
+
23
+ //#endregion
24
+ //#region src/forge.ts
25
+ const require = NodeModule.createRequire(import.meta.url);
26
+ const __dirname = NodePath.dirname(fileURLToPath(import.meta.url));
27
+ function getBinaryPath() {
28
+ const { platform, arch } = process;
29
+ let packageName;
30
+ let binaryName = "forge";
31
+ switch (platform) {
32
+ case "win32":
33
+ binaryName += ".exe";
34
+ if (arch === "x64") packageName = "@foundry-rs/forge-win32-amd64";
35
+ break;
36
+ case "darwin":
37
+ if (arch === "x64") packageName = "@foundry-rs/forge-darwin-amd64";
38
+ else if (arch === "arm64") packageName = "@foundry-rs/forge-darwin-arm64";
39
+ break;
40
+ case "linux":
41
+ if (arch === "x64") packageName = "@foundry-rs/forge-linux-amd64";
42
+ else if (arch === "arm64") packageName = "@foundry-rs/forge-linux-arm64";
43
+ break;
44
+ default: throw new Error(`Unsupported platform: ${platform}-${arch}`);
45
+ }
46
+ if (!packageName) {
47
+ console.error(`Unsupported platform: ${platform}-${arch}`);
48
+ process.exit(1);
49
+ }
50
+ try {
51
+ const binaryPath = require.resolve(`${packageName}/bin/${binaryName}`);
52
+ if (NodeFS.existsSync(binaryPath)) return binaryPath;
53
+ } catch (error) {
54
+ return NodePath.join(__dirname, "..", "dist", BINARY_NAME);
55
+ }
56
+ console.error(`Platform-specific package ${packageName} not found.`);
57
+ console.error("This usually means the installation failed or your platform is not supported.");
58
+ console.error(`Platform: ${platform}, Architecture: ${arch}`);
59
+ process.exit(1);
60
+ }
61
+ NodeChildProcess.spawn(getBinaryPath(), process.argv.slice(2), { stdio: "inherit" });
62
+
63
+ //#endregion
64
+ export { };
package/dist/index.mjs ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import NodeModule from "node:module";
3
+ import NodeChildProcess from "node:child_process";
4
+ import NodePath from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ //#region src/const.ts
8
+ const BINARY_DISTRIBUTION_PACKAGES = {
9
+ darwin: {
10
+ x64: "@foundry-rs/forge-darwin-amd64",
11
+ arm64: "@foundry-rs/forge-darwin-arm64"
12
+ },
13
+ linux: {
14
+ x64: "@foundry-rs/forge-linux-amd64",
15
+ arm64: "@foundry-rs/forge-linux-arm64"
16
+ },
17
+ win32: { x64: "@foundry-rs/forge-win32-amd64" }
18
+ };
19
+ const BINARY_NAME = process.platform === "win32" ? "forge.exe" : "forge";
20
+ const PLATFORM_SPECIFIC_PACKAGE_NAME = BINARY_DISTRIBUTION_PACKAGES[process.platform][process.arch];
21
+
22
+ //#endregion
23
+ //#region src/index.ts
24
+ const require = NodeModule.createRequire(import.meta.url);
25
+ const __dirname = NodePath.dirname(fileURLToPath(import.meta.url));
26
+ function getBinaryPath() {
27
+ try {
28
+ return require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`);
29
+ } catch (_error) {
30
+ return NodePath.join(__dirname, BINARY_NAME);
31
+ }
32
+ }
33
+ if (import.meta.url === `file://${process.argv[1]}`) NodeChildProcess.execFileSync(getBinaryPath(), process.argv.slice(2), { stdio: "inherit" });
34
+
35
+ //#endregion
36
+ export { };
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ import * as NodeModule from "node:module";
3
+ import * as NodeCrypto from "node:crypto";
4
+ import * as NodeFS from "node:fs";
5
+ import * as NodeHttp from "node:http";
6
+ import * as NodeHttps from "node:https";
7
+ import * as NodePath from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import * as NodeZlib from "node:zlib";
10
+
11
+ //#region src/const.ts
12
+ function getRegistryUrl() {
13
+ return process.env.npm_config_registry || process.env.REGISTRY_URL || "https://registry.npmjs.org";
14
+ }
15
+ const BINARY_DISTRIBUTION_PACKAGES = {
16
+ darwin: {
17
+ x64: "@foundry-rs/forge-darwin-amd64",
18
+ arm64: "@foundry-rs/forge-darwin-arm64"
19
+ },
20
+ linux: {
21
+ x64: "@foundry-rs/forge-linux-amd64",
22
+ arm64: "@foundry-rs/forge-linux-arm64"
23
+ },
24
+ win32: { x64: "@foundry-rs/forge-win32-amd64" }
25
+ };
26
+ const BINARY_NAME = process.platform === "win32" ? "forge.exe" : "forge";
27
+ const PLATFORM_SPECIFIC_PACKAGE_NAME = BINARY_DISTRIBUTION_PACKAGES[process.platform][process.arch];
28
+ const colors = {
29
+ red: "\x1B[31m",
30
+ green: "\x1B[32m",
31
+ yellow: "\x1B[33m",
32
+ blue: "\x1B[34m",
33
+ magenta: "\x1B[35m",
34
+ cyan: "\x1B[36m",
35
+ white: "\x1B[37m",
36
+ reset: "\x1B[0m"
37
+ };
38
+
39
+ //#endregion
40
+ //#region src/install.ts
41
+ const __dirname = NodePath.dirname(fileURLToPath(import.meta.url));
42
+ const fallbackBinaryPath = NodePath.join(__dirname, BINARY_NAME);
43
+ const require = NodeModule.createRequire(import.meta.url);
44
+ function makeRequest(url) {
45
+ return new Promise((resolve, reject) => {
46
+ const client = url.startsWith("https:") ? NodeHttps : NodeHttp;
47
+ client.get(url, (response) => {
48
+ if (response?.statusCode && response.statusCode >= 200 && response.statusCode < 300) {
49
+ const chunks = [];
50
+ response.on("data", (chunk) => chunks.push(chunk));
51
+ response.on("end", () => {
52
+ resolve(Buffer.concat(chunks));
53
+ });
54
+ } else if (response?.statusCode && response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) makeRequest(response.headers.location).then(resolve, reject);
55
+ else reject(/* @__PURE__ */ new Error(`npm responded with status code ${response.statusCode} when downloading the package!`));
56
+ }).on("error", (error) => {
57
+ reject(error);
58
+ });
59
+ });
60
+ }
61
+ function encodePackageNameForRegistry(name) {
62
+ return name.startsWith("@") ? encodeURIComponent(name) : name;
63
+ }
64
+ function extractFileFromTarball(tarballBuffer, filepath) {
65
+ let offset = 0;
66
+ while (offset < tarballBuffer.length) {
67
+ const header = tarballBuffer.subarray(offset, offset + 512);
68
+ offset += 512;
69
+ const fileName = header.toString("utf-8", 0, 100).replace(/\0.*/g, "");
70
+ const fileSize = Number.parseInt(header.toString("utf-8", 124, 136).replace(/\0.*/g, ""), 8);
71
+ if (fileName === filepath) return tarballBuffer.subarray(offset, offset + fileSize);
72
+ offset = offset + fileSize + 511 & -512;
73
+ }
74
+ throw new Error(`File ${filepath} not found in tarball`);
75
+ }
76
+ async function downloadBinaryFromNpm() {
77
+ const registryUrl = getRegistryUrl().replace(/\/$/, "");
78
+ const encodedName = encodePackageNameForRegistry(PLATFORM_SPECIFIC_PACKAGE_NAME);
79
+ let desiredVersion;
80
+ try {
81
+ const pkgJsonPath = NodePath.join(__dirname, "..", "package.json");
82
+ const pkgJson = JSON.parse(NodeFS.readFileSync(pkgJsonPath, "utf8"));
83
+ desiredVersion = pkgJson?.optionalDependencies?.[PLATFORM_SPECIFIC_PACKAGE_NAME] || pkgJson?.version;
84
+ } catch {}
85
+ const metaUrl = `${registryUrl}/${encodedName}`;
86
+ const metaBuffer = await makeRequest(metaUrl);
87
+ const metadata = JSON.parse(metaBuffer.toString("utf8"));
88
+ const version = desiredVersion || metadata?.["dist-tags"]?.latest;
89
+ const versionMeta = metadata?.versions?.[version];
90
+ const dist = versionMeta?.dist;
91
+ if (!dist?.tarball) throw new Error(`Could not find tarball for ${PLATFORM_SPECIFIC_PACKAGE_NAME}@${version} from ${metaUrl}`);
92
+ console.info(colors.green, "Downloading binary from:\n", dist.tarball, "\n", colors.reset);
93
+ const tarballDownloadBuffer = await makeRequest(dist.tarball);
94
+ if (dist.integrity && dist.integrity.startsWith("sha512-")) {
95
+ const expected = dist.integrity.split("sha512-")[1];
96
+ const actual = NodeCrypto.createHash("sha512").update(tarballDownloadBuffer).digest("base64");
97
+ if (expected !== actual) throw new Error("Downloaded tarball failed integrity check (sha512 mismatch)");
98
+ }
99
+ const tarballBuffer = NodeZlib.gunzipSync(tarballDownloadBuffer);
100
+ NodeFS.writeFileSync(fallbackBinaryPath, extractFileFromTarball(tarballBuffer, `package/bin/${BINARY_NAME}`), { mode: 493 });
101
+ }
102
+ function isPlatformSpecificPackageInstalled() {
103
+ try {
104
+ require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`);
105
+ return true;
106
+ } catch (_error) {
107
+ return false;
108
+ }
109
+ }
110
+ if (!PLATFORM_SPECIFIC_PACKAGE_NAME) throw new Error("Platform not supported!");
111
+ if (!isPlatformSpecificPackageInstalled()) {
112
+ console.log("Platform specific package not found. Will manually download binary.");
113
+ downloadBinaryFromNpm();
114
+ } else console.log("Platform specific package already installed. Skipping manual download.");
115
+
116
+ //#endregion
117
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundry-rs/forge",
3
- "version": "1.3.2",
3
+ "version": "1.3.4-nightly.20250906.05d4a02",
4
4
  "type": "module",
5
5
  "homepage": "https://getfoundry.sh/forge",
6
6
  "description": "Fast and flexible Ethereum testing framework",
@@ -19,11 +19,11 @@
19
19
  "postinstall": "node ./dist/install.mjs"
20
20
  },
21
21
  "optionalDependencies": {
22
- "@foundry-rs/forge-darwin-arm64": "1.3.2",
23
- "@foundry-rs/forge-darwin-amd64": "1.3.2",
24
- "@foundry-rs/forge-linux-arm64": "1.3.2",
25
- "@foundry-rs/forge-linux-amd64": "1.3.2",
26
- "@foundry-rs/forge-win32-amd64": "1.3.2"
22
+ "@foundry-rs/forge-darwin-arm64": "1.3.4-nightly.20250906.05d4a02",
23
+ "@foundry-rs/forge-darwin-amd64": "1.3.4-nightly.20250906.05d4a02",
24
+ "@foundry-rs/forge-linux-arm64": "1.3.4-nightly.20250906.05d4a02",
25
+ "@foundry-rs/forge-linux-amd64": "1.3.4-nightly.20250906.05d4a02",
26
+ "@foundry-rs/forge-win32-amd64": "1.3.4-nightly.20250906.05d4a02"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public",