@typerighter/rpc-server 0.4.1 → 0.4.3

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.
Files changed (3) hide show
  1. package/install.js +44 -1
  2. package/package.json +1 -1
  3. package/platform.js +20 -1
package/install.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { execFileSync } from "node:child_process";
2
- import { existsSync, mkdirSync, chmodSync } from "node:fs";
2
+ import { mkdirSync, chmodSync, copyFileSync, existsSync } 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,48 @@ if (dev()) {
28
29
  process.exit(0);
29
30
  }
30
31
 
32
+ // On NixOS, build using Nix derivation
33
+ if (isNixOS()) {
34
+ const tag = releaseTag();
35
+ const flakeTarget = existsSync(path.join(repoRoot(), "flake.nix"))
36
+ ? ".#typedown-rpc"
37
+ : `github:huydo862003/typerighter/${tag}#typedown-rpc`;
38
+
39
+ console.log(
40
+ `[rpc-server] NixOS detected: building typedown-rpc using Nix derivation (${flakeTarget})`,
41
+ );
42
+ const binDir = path.dirname(bin);
43
+ mkdirSync(binDir, { recursive: true });
44
+
45
+ try {
46
+ const outPath = execFileSync(
47
+ "nix",
48
+ [
49
+ "--extra-experimental-features",
50
+ "nix-command flakes",
51
+ "build",
52
+ flakeTarget,
53
+ "--no-link",
54
+ "--print-out-paths",
55
+ ],
56
+ {
57
+ cwd: repoRoot(),
58
+ encoding: "utf8",
59
+ },
60
+ ).trim();
61
+
62
+ const builtBin = path.join(outPath, "bin", "typedown-rpc");
63
+ copyFileSync(builtBin, bin);
64
+ if (process.platform !== "win32") {
65
+ chmodSync(bin, 0o755);
66
+ }
67
+ console.log("[rpc-server] typedown-rpc built and installed successfully via Nix");
68
+ process.exit(0);
69
+ } catch {
70
+ console.warn("[rpc-server] nix build failed, falling back to binary download");
71
+ }
72
+ }
73
+
31
74
  // In non dev mode, fetch the artifacts
32
75
  const arch = osArch();
33
76
  const tag = releaseTag();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@typerighter/rpc-server",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "description": "Typedown RPC server binary.",
6
6
  "repository": {
7
7
  "type": "git",
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 = env.parsed?.DEV === "true";
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",