@coreframe/cli-runtime 0.0.0-stage → 3.0.0-beta.2

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/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /** Resolve the installed executable without building or downloading code. */
2
+ export function resolveBinary(tool: "coreframe"): string
3
+
4
+ /** Launch the executable with inherited terminal streams and return its exit status. */
5
+ export function runBinary(
6
+ tool: "coreframe",
7
+ args?: string[],
8
+ options?: { env?: Record<string, string | undefined>; cwd?: string },
9
+ ): Promise<number>
package/index.js ADDED
@@ -0,0 +1,86 @@
1
+ import { spawn } from "node:child_process"
2
+ import { accessSync, constants } from "node:fs"
3
+ import { createRequire } from "node:module"
4
+ import { dirname, join } from "node:path"
5
+
6
+ import platforms from "./platforms.json" with { type: "json" }
7
+
8
+ const require = createRequire(import.meta.url)
9
+ const tools = new Set(["coreframe"])
10
+
11
+ /** Resolve the installed host executable without building or downloading code. */
12
+ export function resolveBinary(tool) {
13
+ if (!tools.has(tool)) {
14
+ throw new Error(`Unknown Coreframe executable: ${tool}`)
15
+ }
16
+
17
+ const platform = `${process.platform}-${process.arch}`
18
+
19
+ if (!Object.hasOwn(platforms, platform)) {
20
+ throw new Error(`Coreframe does not provide a native executable for ${platform}.`)
21
+ }
22
+
23
+ const packageName = `@coreframe/cli-${platform}`
24
+
25
+ try {
26
+ const manifest = require.resolve(`${packageName}/package.json`)
27
+ const filename = tool + (process.platform === "win32" ? ".exe" : "")
28
+ const executable = join(dirname(manifest), "bin", filename)
29
+
30
+ accessSync(executable, process.platform === "win32" ? constants.F_OK : constants.X_OK)
31
+ return executable
32
+ } catch {
33
+ throw new Error(
34
+ `Coreframe's native executable is missing. Reinstall project dependencies with optional dependencies enabled (${packageName}). Maintainers can run pnpm build:cli before testing an unpublished checkout.`,
35
+ )
36
+ }
37
+ }
38
+
39
+ /** Launch a selected Go tool, preserving terminal streams and the process exit code. */
40
+ export async function runBinary(tool, args = process.argv.slice(2), { env, cwd } = {}) {
41
+ const executable = resolveBinary(tool)
42
+
43
+ return new Promise((resolve, reject) => {
44
+ const child = spawn(executable, args, {
45
+ stdio: "inherit",
46
+ env,
47
+ cwd,
48
+ })
49
+
50
+ const signals =
51
+ process.platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGHUP", "SIGINT", "SIGTERM"]
52
+
53
+ const handlers = new Map()
54
+ const cleanup = () => {
55
+ for (const [signal, handler] of handlers) {
56
+ process.off(signal, handler)
57
+ }
58
+ }
59
+
60
+ for (const signal of signals) {
61
+ const handler = () => {
62
+ if (child.exitCode === null && child.signalCode === null) {
63
+ child.kill(signal)
64
+ }
65
+ }
66
+
67
+ handlers.set(signal, handler)
68
+ process.on(signal, handler)
69
+ }
70
+
71
+ child.once("error", () => {
72
+ cleanup()
73
+ reject(new Error(`Could not start the Coreframe ${tool} executable.`))
74
+ })
75
+ child.once("close", (code, signal) => {
76
+ cleanup()
77
+ const signalCodes = {
78
+ SIGHUP: 129,
79
+ SIGINT: 130,
80
+ SIGTERM: 143,
81
+ }
82
+
83
+ resolve(code ?? signalCodes[signal] ?? 1)
84
+ })
85
+ })
86
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@coreframe/cli-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "3.0.0-beta.2",
4
+ "description": "Native executable resolution and launch for Coreframe tools",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/coreframe-js/coreframe.git",
8
+ "directory": "node/cli-runtime"
9
+ },
10
+ "files": [
11
+ "index.d.ts",
12
+ "index.js",
13
+ "platforms.json"
14
+ ],
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./index.d.ts",
19
+ "default": "./index.js"
20
+ },
21
+ "./platforms": "./platforms.json"
22
+ },
23
+ "optionalDependencies": {
24
+ "@coreframe/cli-darwin-arm64": "3.0.0-beta.2",
25
+ "@coreframe/cli-darwin-x64": "3.0.0-beta.2",
26
+ "@coreframe/cli-linux-arm64": "3.0.0-beta.2",
27
+ "@coreframe/cli-linux-x64": "3.0.0-beta.2",
28
+ "@coreframe/cli-win32-x64": "3.0.0-beta.2"
29
+ },
30
+ "engines": {
31
+ "node": ">=24.3.0"
32
+ },
33
+ "scripts": {
34
+ "build": "node ../../cli/scripts/build.mjs",
35
+ "test": "node --test index.test.js"
36
+ }
6
37
  }
package/platforms.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "darwin-arm64": { "os": "darwin", "arch": "arm64" },
3
+ "darwin-x64": { "os": "darwin", "arch": "amd64" },
4
+ "linux-arm64": { "os": "linux", "arch": "arm64" },
5
+ "linux-x64": { "os": "linux", "arch": "amd64" },
6
+ "win32-x64": { "os": "windows", "arch": "amd64" }
7
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.