@fungi.computer/spore 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fungi.cjs ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require("node:child_process");
3
+ const { resolve } = require("node:path");
4
+ const { createHash } = require("node:crypto");
5
+ const { readFileSync } = require("node:fs");
6
+ const { release, cpus } = require("node:os");
7
+
8
+ const runtimes = {
9
+ "linux-x64": "@oven/bun-linux-x64/bin/bun",
10
+ "linux-arm64": "@oven/bun-linux-aarch64/bin/bun",
11
+ "darwin-arm64": "@oven/bun-darwin-aarch64/bin/bun",
12
+ "darwin-x64": "@oven/bun-darwin-x64/bin/bun",
13
+ };
14
+ const platform = `${process.platform}-${process.arch}`;
15
+ // Node runs this check before resolving or loading any native dependency.
16
+ const glibc =
17
+ process.platform === "linux"
18
+ ? process.report.getReport().header.glibcVersionRuntime
19
+ : undefined;
20
+ const [major, minor] = (glibc ?? "").split(".").map(Number);
21
+ const [darwinMajor, darwinMinor] =
22
+ process.platform === "darwin" ? release().split(".").map(Number) : [];
23
+ const hostCpus =
24
+ process.platform === "darwin" && process.arch === "x64" ? cpus() : [];
25
+ const translated =
26
+ process.platform === "darwin" &&
27
+ process.arch === "x64" &&
28
+ (hostCpus.length === 0 || hostCpus.some(({ model }) => /Apple/.test(model)));
29
+ const supported =
30
+ runtimes[platform] !== undefined &&
31
+ !translated &&
32
+ (process.platform !== "linux" || major > 2 || (major === 2 && minor >= 35)) &&
33
+ (process.platform !== "darwin" ||
34
+ darwinMajor > 22 ||
35
+ (darwinMajor === 22 && darwinMinor >= 6));
36
+ if (!supported) {
37
+ if (process.argv[2] === "doctor") {
38
+ console.log(`Platform: ${process.platform} ${process.arch}`);
39
+ console.log(
40
+ `glibc: ${process.platform === "linux" ? (glibc ?? "not detected (musl or unknown libc)") : "not applicable"}`,
41
+ );
42
+ console.log("Sign-in: not checked on an unsupported platform");
43
+ }
44
+ console.error(
45
+ translated
46
+ ? "Use arm64 Node on Apple Silicon and reinstall the CLI with npm install -g @fungi.computer/spore --include=optional. The Intel Bun runtime is not supported under Rosetta."
47
+ : "Fungi CLI needs Linux x64/arm64 with glibc 2.35+, or macOS 13.5+ on Apple Silicon or Intel.",
48
+ );
49
+ process.exit(1);
50
+ }
51
+ const nativePackage = `@fungi.computer/spore-native-${platform}`;
52
+ let bun;
53
+ try {
54
+ require.resolve(`${nativePackage}/bin/fungi-apply-patch`);
55
+ bun = require.resolve(runtimes[platform]);
56
+ } catch (cause) {
57
+ throw new Error(
58
+ "Fungi CLI could not load its native dependencies. Reinstall with npm install -g @fungi.computer/spore --include=optional.",
59
+ { cause },
60
+ );
61
+ }
62
+ const cli = resolve(__dirname, "cli.js");
63
+ const buildId = createHash("sha256").update(readFileSync(cli)).digest("hex");
64
+ const child = spawnSync(bun, [cli, ...process.argv.slice(2)], {
65
+ stdio: "inherit",
66
+ env: {
67
+ ...process.env,
68
+ FUNGI_BUNDLED_CLI: cli,
69
+ FUNGI_BUNDLED_BUILD_ID: buildId,
70
+ FUNGI_LAUNCHER: __filename,
71
+ FUNGI_LAUNCHER_NODE: process.execPath,
72
+ },
73
+ });
74
+ if (child.error) throw child.error;
75
+ if (child.signal) process.kill(process.pid, child.signal);
76
+ process.exitCode = child.status ?? 1;