@falentio/bandar 0.0.0 → 0.2.4
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/bandar.cjs +124 -0
- package/package.json +30 -3
package/bin/bandar.cjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { spawn } = require("node:child_process");
|
|
5
|
+
const { existsSync, readFileSync } = require("node:fs");
|
|
6
|
+
const { dirname, join } = require("node:path");
|
|
7
|
+
|
|
8
|
+
const PACKAGES = new Map([
|
|
9
|
+
[
|
|
10
|
+
"linux-x64",
|
|
11
|
+
{ name: "@falentio/bandar-linux-x64", asset: "linux", file: "bin/bandar", libc: "glibc" },
|
|
12
|
+
],
|
|
13
|
+
["win32-x64", { name: "@falentio/bandar-windows-x64", asset: "windows", file: "bin/bandar.exe" }],
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const INSTALLER =
|
|
17
|
+
"curl -fsSL https://raw.githubusercontent.com/falentio/bandar/main/install.sh | sh";
|
|
18
|
+
|
|
19
|
+
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
20
|
+
|
|
21
|
+
function isMusl() {
|
|
22
|
+
return (
|
|
23
|
+
process.platform === "linux" &&
|
|
24
|
+
process.report?.getReport?.()?.header?.glibcVersionRuntime === undefined
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolveBinary(platform, arch, resolve = require.resolve) {
|
|
29
|
+
const key = `${platform}-${arch}`;
|
|
30
|
+
const entry = PACKAGES.get(key);
|
|
31
|
+
|
|
32
|
+
if (entry === undefined) {
|
|
33
|
+
return {
|
|
34
|
+
kind: "unsupported",
|
|
35
|
+
reason: `bandar has no npm build for ${key}; npm ships ${[...PACKAGES.keys()].join(", ")}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let manifest;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
manifest = resolve(`${entry.name}/package.json`);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error.code !== "MODULE_NOT_FOUND") throw error;
|
|
45
|
+
|
|
46
|
+
if (entry.libc === "glibc" && isMusl()) {
|
|
47
|
+
return {
|
|
48
|
+
kind: "unsupported",
|
|
49
|
+
reason: `${entry.name} links glibc and this Linux uses musl, so bandar has no build for it; neither npm nor install.sh can install one`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
kind: "absent",
|
|
55
|
+
reason: `npm did not install ${entry.name} for ${key}; run "npm install -g @falentio/bandar@latest", or install with ${INSTALLER}`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const version = JSON.parse(readFileSync(manifest, "utf8")).version;
|
|
60
|
+
const own = require("../package.json").version;
|
|
61
|
+
|
|
62
|
+
if (version !== own) {
|
|
63
|
+
return {
|
|
64
|
+
kind: "mismatch",
|
|
65
|
+
reason: `${entry.name} is ${version}, but this loader is ${own}; run "npm install -g @falentio/bandar@latest"`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const path = join(dirname(manifest), entry.file);
|
|
70
|
+
|
|
71
|
+
if (!existsSync(path)) {
|
|
72
|
+
return { kind: "absent", reason: `${entry.name} is installed without ${entry.file}` };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { kind: "ready", path };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function launch(path, argv) {
|
|
79
|
+
const child = spawn(path, argv, { stdio: "inherit", windowsHide: true });
|
|
80
|
+
const forwarding = new Map();
|
|
81
|
+
|
|
82
|
+
// Windows delivers a console Ctrl+C to every process already, so forwarding would signal the
|
|
83
|
+
// child twice, and Node cannot raise a real SIGTERM there anyway.
|
|
84
|
+
if (process.platform !== "win32") {
|
|
85
|
+
for (const signal of SIGNALS) {
|
|
86
|
+
const forward = () => child.kill(signal);
|
|
87
|
+
|
|
88
|
+
forwarding.set(signal, forward);
|
|
89
|
+
process.on(signal, forward);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
child.on("error", (error) => {
|
|
94
|
+
process.stderr.write(`bandar: could not run ${path}: ${error.message}\n`);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
child.on("exit", (code, signal) => {
|
|
99
|
+
for (const [name, forward] of forwarding) process.off(name, forward);
|
|
100
|
+
|
|
101
|
+
if (signal === null) {
|
|
102
|
+
process.exit(code ?? 1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
process.kill(process.pid, signal);
|
|
107
|
+
} catch {
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = { PACKAGES, resolveBinary };
|
|
114
|
+
|
|
115
|
+
if (require.main === module) {
|
|
116
|
+
const target = resolveBinary(process.platform, process.arch);
|
|
117
|
+
|
|
118
|
+
if (target.kind !== "ready") {
|
|
119
|
+
process.stderr.write(`bandar: ${target.reason}\n`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
launch(target.path, process.argv.slice(2));
|
|
124
|
+
}
|
package/package.json
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
1
|
+
{
|
|
2
|
+
"name": "@falentio/bandar",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "Run the released bandar binary.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/falentio/bandar.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/falentio/bandar#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/falentio/bandar/issues"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"bandar": "bin/bandar.cjs"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin/bandar.cjs"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"optionalDependencies": {
|
|
27
|
+
"@falentio/bandar-linux-x64": "0.2.4",
|
|
28
|
+
"@falentio/bandar-windows-x64": "0.2.4"
|
|
29
|
+
}
|
|
30
|
+
}
|