@phpsandbox/cli 0.1.0
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/phpsandbox.js +69 -0
- package/package.json +32 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/distribution/launcher.ts
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
|
|
7
|
+
// src/distribution/platforms.ts
|
|
8
|
+
var platforms = [
|
|
9
|
+
{ id: "darwin-arm64", os: "darwin", cpu: "arm64" },
|
|
10
|
+
{ id: "darwin-x64", os: "darwin", cpu: "x64" },
|
|
11
|
+
{ id: "linux-x64", os: "linux", cpu: "x64", libc: "glibc" },
|
|
12
|
+
{ id: "linux-arm64", os: "linux", cpu: "arm64", libc: "glibc" },
|
|
13
|
+
{ id: "linux-x64-musl", os: "linux", cpu: "x64", libc: "musl" },
|
|
14
|
+
{ id: "linux-arm64-musl", os: "linux", cpu: "arm64", libc: "musl" },
|
|
15
|
+
{ id: "windows-x64", os: "win32", cpu: "x64" }
|
|
16
|
+
];
|
|
17
|
+
function platformFor(os, cpu, libc = "glibc") {
|
|
18
|
+
const platform = platforms.find((candidate) => candidate.os === os && candidate.cpu === cpu && (!("libc" in candidate) || candidate.libc === libc));
|
|
19
|
+
if (!platform) {
|
|
20
|
+
throw new Error(`PHPSandbox does not support ${os}/${cpu}/${libc}.`);
|
|
21
|
+
}
|
|
22
|
+
return platform;
|
|
23
|
+
}
|
|
24
|
+
function packageName(platform) {
|
|
25
|
+
return `@phpsandbox/cli-${platform.id}`;
|
|
26
|
+
}
|
|
27
|
+
function binaryName(platform) {
|
|
28
|
+
return platform.os === "win32" ? "phpsandbox.exe" : "phpsandbox";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/distribution/launcher.ts
|
|
32
|
+
try {
|
|
33
|
+
const report = process.platform === "linux" ? process.report.getReport() : undefined;
|
|
34
|
+
const header = typeof report === "object" && "header" in report ? report.header : undefined;
|
|
35
|
+
const libc = typeof header === "object" && header !== null && "glibcVersionRuntime" in header && typeof header.glibcVersionRuntime === "string" ? "glibc" : "musl";
|
|
36
|
+
const platform = platformFor(process.platform, process.arch, libc);
|
|
37
|
+
const name = packageName(platform);
|
|
38
|
+
const require2 = createRequire(import.meta.url);
|
|
39
|
+
let executable;
|
|
40
|
+
try {
|
|
41
|
+
executable = require2.resolve(`${name}/bin/${binaryName(platform)}`);
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error(`Missing ${name}. Reinstall @phpsandbox/cli with optional dependencies enabled (npm install -g @phpsandbox/cli --include=optional).`);
|
|
44
|
+
}
|
|
45
|
+
const child = spawn(executable, process.argv.slice(2), { stdio: "inherit" });
|
|
46
|
+
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
47
|
+
for (const signal of signals) {
|
|
48
|
+
process.on(signal, () => {
|
|
49
|
+
child.kill(signal);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
child.on("error", (error) => {
|
|
53
|
+
console.error(`Could not start PHPSandbox: ${error.message}`);
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
});
|
|
56
|
+
child.on("exit", (code, signal) => {
|
|
57
|
+
for (const forwarded of signals) {
|
|
58
|
+
process.removeAllListeners(forwarded);
|
|
59
|
+
}
|
|
60
|
+
if (signal) {
|
|
61
|
+
process.kill(process.pid, signal);
|
|
62
|
+
} else {
|
|
63
|
+
process.exitCode = code ?? 1;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/phpsandbox/cli.git"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"name": "@phpsandbox/cli",
|
|
12
|
+
"description": "A friendly command-line workspace for PHPSandbox",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"bin": {
|
|
15
|
+
"phpsandbox": "bin/phpsandbox.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"@phpsandbox/cli-darwin-arm64": "0.1.0",
|
|
25
|
+
"@phpsandbox/cli-darwin-x64": "0.1.0",
|
|
26
|
+
"@phpsandbox/cli-linux-x64": "0.1.0",
|
|
27
|
+
"@phpsandbox/cli-linux-arm64": "0.1.0",
|
|
28
|
+
"@phpsandbox/cli-linux-x64-musl": "0.1.0",
|
|
29
|
+
"@phpsandbox/cli-linux-arm64-musl": "0.1.0",
|
|
30
|
+
"@phpsandbox/cli-windows-x64": "0.1.0"
|
|
31
|
+
}
|
|
32
|
+
}
|