@samva/cli 0.1.0 → 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/AGENTS.md CHANGED
@@ -10,5 +10,7 @@ loads the project's installed authoring toolchain so its compiler and editor ver
10
10
  by the project lockfile. Template authoring commands require Node.js 22 or newer; other CLI commands
11
11
  remain self-contained.
12
12
 
13
- The platform-specific `@samva/cli-*` packages are installer artifacts. Depend on `@samva/cli`, not
14
- on a native package directly.
13
+ `@samva/cli` ships the JavaScript implementation and its runtime dependencies. Its launcher prefers
14
+ the matching platform-specific `@samva/cli-*` executable and falls back to the packaged JavaScript
15
+ CLI through Bun when npm omits optional dependencies. Depend on `@samva/cli`, never a native
16
+ artifact directly.
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # @samva/cli
2
2
 
3
- The `samva` CLI sends and operates email from a terminal. Ordinary commands are
4
- self-contained and require neither Bun nor Node. Template authoring commands run
5
- the project's `@samva/vite` toolchain under Node.js 22 or newer.
3
+ The `samva` CLI sends and operates email from a terminal. The npm package includes
4
+ the JavaScript implementation and selects a self-contained native executable when
5
+ one is available. Template authoring commands run the project's `@samva/vite`
6
+ toolchain under Node.js 22 or newer.
6
7
 
7
8
  ## Install
8
9
 
@@ -11,8 +12,10 @@ npm install -g @samva/cli
11
12
  samva --help
12
13
  ```
13
14
 
14
- The npm package selects the matching macOS or Linux executable. Compiled
15
- binaries are also available from [GitHub releases](https://github.com/AryaLabsHQ/samva/releases).
15
+ The npm package prefers the matching macOS or Linux executable. If npm omits
16
+ optional dependencies, the same command falls back to the packaged JavaScript
17
+ implementation when Bun is installed. Compiled binaries are also available from
18
+ [GitHub releases](https://github.com/AryaLabsHQ/samva/releases).
16
19
 
17
20
  ## Shell completions
18
21
 
package/bin/samva.cjs ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require("node:child_process");
4
+ const { existsSync } = require("node:fs");
5
+ const { dirname, join } = require("node:path");
6
+
7
+ const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"];
8
+
9
+ const run = (command, args) => {
10
+ const child = spawn(command, args, { stdio: "inherit" });
11
+ const forwarders = new Map();
12
+
13
+ for (const signal of forwardedSignals) {
14
+ const forward = () => child.kill(signal);
15
+ forwarders.set(signal, forward);
16
+ process.on(signal, forward);
17
+ }
18
+
19
+ child.on("error", (error) => {
20
+ if (error.code === "ENOENT" && command === "bun") {
21
+ console.error(
22
+ "samva: the native executable is unavailable and Bun is not installed; reinstall @samva/cli with optional dependencies or install Bun",
23
+ );
24
+ } else {
25
+ console.error(`samva: ${error.message}`);
26
+ }
27
+ process.exitCode = 1;
28
+ });
29
+
30
+ child.on("exit", (code, signal) => {
31
+ for (const [forwardedSignal, forward] of forwarders) {
32
+ process.removeListener(forwardedSignal, forward);
33
+ }
34
+ if (signal) process.kill(process.pid, signal);
35
+ else process.exitCode = code ?? 1;
36
+ });
37
+ };
38
+
39
+ const target = `${process.platform}-${process.arch}`;
40
+ const packageName = `@samva/cli-${target}`;
41
+ let nativeExecutable;
42
+
43
+ // oxlint-disable-next-line samva/no-try-catch-or-throw -- CommonJS launcher probes an optional platform package before using the Bun fallback
44
+ try {
45
+ const manifest = require.resolve(`${packageName}/package.json`, { paths: [__dirname] });
46
+ const candidate = join(dirname(manifest), "samva");
47
+ if (existsSync(candidate)) nativeExecutable = candidate;
48
+ } catch {
49
+ // npm may omit optional dependencies. The JavaScript distribution below is
50
+ // the supported fallback rather than an installation-time failure.
51
+ }
52
+
53
+ if (nativeExecutable) {
54
+ run(nativeExecutable, process.argv.slice(2));
55
+ } else {
56
+ run("bun", [join(__dirname, "..", "dist", "bin.mjs"), ...process.argv.slice(2)]);
57
+ }