@rivetkit/engine-cli 2.2.1-pr.4600.252b48e

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 (4) hide show
  1. package/README.md +25 -0
  2. package/index.d.ts +14 -0
  3. package/index.js +108 -0
  4. package/package.json +23 -0
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # @rivetkit/engine-cli
2
+
3
+ Platform-specific rivet-engine binary distribution. Shipped as a set of
4
+ `@rivetkit/engine-cli-<platform>` packages. The meta package at
5
+ `@rivetkit/engine-cli` exposes `getEnginePath()` which returns the absolute
6
+ path to the binary for the current host.
7
+
8
+ ## Supported platforms
9
+
10
+ - `linux-x64-musl` — Linux x86_64 (static, runs on any distro)
11
+ - `linux-arm64-musl` — Linux aarch64 (static)
12
+ - `darwin-x64` — macOS Intel
13
+ - `darwin-arm64` — macOS Apple Silicon
14
+
15
+ Windows is not currently published via this package — engine Windows builds
16
+ are handled separately via the release workflow.
17
+
18
+ ## Usage
19
+
20
+ ```js
21
+ const { getEnginePath } = require("@rivetkit/engine-cli");
22
+ const { spawn } = require("node:child_process");
23
+
24
+ const child = spawn(getEnginePath(), ["start"]);
25
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns the absolute path to the rivet-engine binary for the current host.
3
+ *
4
+ * Resolution order:
5
+ * 1. `RIVET_ENGINE_BINARY` env var (absolute path override)
6
+ * 2. Local `rivet-engine` binary next to this package (dev builds)
7
+ * 3. The platform-specific `@rivetkit/engine-cli-<platform>` npm package
8
+ *
9
+ * Throws if none of the above yields a binary.
10
+ */
11
+ export function getEnginePath(): string;
12
+
13
+ /** Returns the expected name of the platform-specific npm package for the current host, or null if unsupported. */
14
+ export function getPlatformPackageName(): string | null;
package/index.js ADDED
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @rivetkit/engine-cli
3
+ *
4
+ * Platform-specific rivet-engine binary resolver. The binary itself is shipped
5
+ * in one of several `@rivetkit/engine-cli-<platform>` packages as an
6
+ * optionalDependency — npm only installs the one matching the current
7
+ * `os`/`cpu`/`libc` at install time.
8
+ *
9
+ * Priority at resolve time:
10
+ * 1. `RIVET_ENGINE_BINARY` env var (absolute path override for debugging)
11
+ * 2. Local `rivet-engine` binary next to this package (dev builds)
12
+ * 3. The platform-specific `@rivetkit/engine-cli-<platform>` npm package
13
+ */
14
+ const { existsSync, readFileSync } = require("node:fs");
15
+ const { dirname, join } = require("node:path");
16
+
17
+ /** Detect if we're on Linux musl or glibc. */
18
+ function isMusl() {
19
+ if (!process.report || typeof process.report.getReport !== "function") {
20
+ try {
21
+ const lddPath = require("node:child_process")
22
+ .execSync("which ldd")
23
+ .toString()
24
+ .trim();
25
+ return readFileSync(lddPath, "utf8").includes("musl");
26
+ } catch {
27
+ return true;
28
+ }
29
+ }
30
+ const { glibcVersionRuntime } = process.report.getReport().header;
31
+ return !glibcVersionRuntime;
32
+ }
33
+
34
+ /** Returns the name of the platform-specific npm package for the current host. */
35
+ function getPlatformPackageName() {
36
+ const { platform, arch } = process;
37
+ switch (platform) {
38
+ case "linux":
39
+ if (arch === "x64") {
40
+ return isMusl()
41
+ ? "@rivetkit/engine-cli-linux-x64-musl"
42
+ : "@rivetkit/engine-cli-linux-x64-gnu";
43
+ }
44
+ if (arch === "arm64") {
45
+ return isMusl()
46
+ ? "@rivetkit/engine-cli-linux-arm64-musl"
47
+ : "@rivetkit/engine-cli-linux-arm64-gnu";
48
+ }
49
+ break;
50
+ case "darwin":
51
+ if (arch === "x64") return "@rivetkit/engine-cli-darwin-x64";
52
+ if (arch === "arm64") return "@rivetkit/engine-cli-darwin-arm64";
53
+ break;
54
+ case "win32":
55
+ if (arch === "x64") return "@rivetkit/engine-cli-win32-x64";
56
+ break;
57
+ }
58
+ return null;
59
+ }
60
+
61
+ /** The binary filename inside each platform package. */
62
+ const BINARY_NAME =
63
+ process.platform === "win32" ? "rivet-engine.exe" : "rivet-engine";
64
+
65
+ /**
66
+ * Returns the absolute path to the rivet-engine binary for the current host.
67
+ * @returns {string}
68
+ */
69
+ function getEnginePath() {
70
+ // 1) Env var override.
71
+ if (process.env.RIVET_ENGINE_BINARY) {
72
+ if (!existsSync(process.env.RIVET_ENGINE_BINARY)) {
73
+ throw new Error(
74
+ `RIVET_ENGINE_BINARY is set to ${process.env.RIVET_ENGINE_BINARY} but the file does not exist`,
75
+ );
76
+ }
77
+ return process.env.RIVET_ENGINE_BINARY;
78
+ }
79
+
80
+ // 2) Local binary next to this package (dev flow: copy from cargo target).
81
+ const localBinary = join(__dirname, BINARY_NAME);
82
+ if (existsSync(localBinary)) {
83
+ return localBinary;
84
+ }
85
+
86
+ // 3) Platform-specific npm package.
87
+ const platformPkg = getPlatformPackageName();
88
+ if (!platformPkg) {
89
+ throw new Error(
90
+ `@rivetkit/engine-cli: unsupported platform ${process.platform}/${process.arch}`,
91
+ );
92
+ }
93
+ let pkgJsonPath;
94
+ try {
95
+ pkgJsonPath = require.resolve(`${platformPkg}/package.json`);
96
+ } catch {
97
+ throw new Error(
98
+ `@rivetkit/engine-cli: platform package ${platformPkg} is not installed.\n` +
99
+ `This usually means the platform is not supported or optionalDependencies\n` +
100
+ `were skipped during install. Try: npm install --include=optional ${platformPkg}\n` +
101
+ `Or set RIVET_ENGINE_BINARY to a local rivet-engine binary.`,
102
+ );
103
+ }
104
+ return join(dirname(pkgJsonPath), BINARY_NAME);
105
+ }
106
+
107
+ module.exports.getEnginePath = getEnginePath;
108
+ module.exports.getPlatformPackageName = getPlatformPackageName;
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@rivetkit/engine-cli",
3
+ "version": "2.2.1-pr.4600.252b48e",
4
+ "description": "Rivet Engine binary distributed as platform-specific npm packages",
5
+ "license": "Apache-2.0",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "engines": {
9
+ "node": ">= 20.0.0"
10
+ },
11
+ "files": [
12
+ "index.js",
13
+ "index.d.ts",
14
+ "package.json",
15
+ "README.md"
16
+ ],
17
+ "optionalDependencies": {
18
+ "@rivetkit/engine-cli-darwin-arm64": "2.2.1-pr.4600.252b48e",
19
+ "@rivetkit/engine-cli-darwin-x64": "2.2.1-pr.4600.252b48e",
20
+ "@rivetkit/engine-cli-linux-arm64-musl": "2.2.1-pr.4600.252b48e",
21
+ "@rivetkit/engine-cli-linux-x64-musl": "2.2.1-pr.4600.252b48e"
22
+ }
23
+ }