@typerighter/rpc-server 0.4.1 → 0.4.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/install.js +33 -1
- package/package.json +1 -1
- package/platform.js +20 -1
package/install.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, chmodSync, copyFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import {
|
|
5
5
|
dev,
|
|
6
|
+
isNixOS,
|
|
6
7
|
osArch,
|
|
7
8
|
releaseTag,
|
|
8
9
|
artifactName,
|
|
@@ -28,6 +29,37 @@ if (dev()) {
|
|
|
28
29
|
process.exit(0);
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
// On NixOS, build using the Nix derivation
|
|
33
|
+
if (isNixOS()) {
|
|
34
|
+
console.log(
|
|
35
|
+
"[rpc-server] NixOS detected: building typedown-rpc using Nix derivation",
|
|
36
|
+
);
|
|
37
|
+
const binDir = path.dirname(bin);
|
|
38
|
+
mkdirSync(binDir, { recursive: true });
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const outPath = execFileSync(
|
|
42
|
+
"nix",
|
|
43
|
+
["build", ".#typedown-rpc", "--no-link", "--print-out-paths"],
|
|
44
|
+
{
|
|
45
|
+
cwd: repoRoot(),
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
},
|
|
48
|
+
).trim();
|
|
49
|
+
|
|
50
|
+
const builtBin = path.join(outPath, "bin", "typedown-rpc");
|
|
51
|
+
copyFileSync(builtBin, bin);
|
|
52
|
+
if (process.platform !== "win32") {
|
|
53
|
+
chmodSync(bin, 0o755);
|
|
54
|
+
}
|
|
55
|
+
console.log("[rpc-server] typedown-rpc built and installed successfully via Nix");
|
|
56
|
+
process.exit(0);
|
|
57
|
+
} catch {
|
|
58
|
+
console.error("[rpc-server] nix build failed");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
31
63
|
// In non dev mode, fetch the artifacts
|
|
32
64
|
const arch = osArch();
|
|
33
65
|
const tag = releaseTag();
|
package/package.json
CHANGED
package/platform.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import process from "node:process";
|
|
4
5
|
import dotenv from "dotenv";
|
|
@@ -7,12 +8,30 @@ const require = createRequire(import.meta.url);
|
|
|
7
8
|
const pkg = require("./package.json");
|
|
8
9
|
|
|
9
10
|
const env = dotenv.config({ path: new URL(".env", import.meta.url) });
|
|
10
|
-
const isDev =
|
|
11
|
+
const isDev =
|
|
12
|
+
process.env.DEV !== undefined
|
|
13
|
+
? process.env.DEV === "true"
|
|
14
|
+
: env.parsed?.DEV === "true";
|
|
11
15
|
|
|
12
16
|
export function dev() {
|
|
13
17
|
return isDev;
|
|
14
18
|
}
|
|
15
19
|
|
|
20
|
+
export function isNixOS() {
|
|
21
|
+
if (process.platform !== "linux") {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (existsSync("/etc/NIXOS") || existsSync("/etc/nixos")) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const osRelease = readFileSync("/etc/os-release", "utf8");
|
|
29
|
+
return /ID(?:_LIKE)?=["']?nixos["']?/i.test(osRelease);
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
16
35
|
const PLATFORM_MAP = {
|
|
17
36
|
"linux-x64": "linux-x86_64",
|
|
18
37
|
"darwin-x64": "darwin-x86_64",
|