@wordbricks/velen 0.2.19-darwin-arm64 → 0.2.19

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/velen.js ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { chmodSync, existsSync, statSync } from "node:fs";
5
+ import { createRequire } from "node:module";
6
+ import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ const require = createRequire(import.meta.url);
12
+
13
+ const CLI_PACKAGE_NAME = "@wordbricks/velen";
14
+ const PLATFORM_PACKAGE_BY_TARGET = {
15
+ "aarch64-apple-darwin": "velen-darwin-arm64",
16
+ };
17
+
18
+ const { platform, arch } = process;
19
+ let targetTriple = null;
20
+ if (platform === "darwin" && arch === "arm64") {
21
+ targetTriple = "aarch64-apple-darwin";
22
+ }
23
+
24
+ if (!targetTriple) {
25
+ throw new Error(`Unsupported platform: ${platform} (${arch})`);
26
+ }
27
+
28
+ const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
29
+ if (!platformPackage) {
30
+ throw new Error(`Unsupported target triple: ${targetTriple}`);
31
+ }
32
+
33
+ // COMMENT: This target map is intentionally duplicated here so the published
34
+ // Node launcher stays self-contained, while the typed helper lives in src/.
35
+
36
+ // CONTEXT: platform packages are installed through npm alias names so the
37
+ // launcher resolves the alias folder, not the underlying published package id.
38
+ const binaryName = "velen";
39
+ const localVendorRoot = path.join(__dirname, "..", "vendor");
40
+ const localBinaryPath = path.join(
41
+ localVendorRoot,
42
+ targetTriple,
43
+ "velen",
44
+ binaryName
45
+ );
46
+
47
+ let vendorRoot;
48
+ try {
49
+ const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
50
+ vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
51
+ } catch {
52
+ if (existsSync(localBinaryPath)) {
53
+ vendorRoot = localVendorRoot;
54
+ } else {
55
+ const packageManager = detectPackageManager();
56
+ const reinstallCommand =
57
+ packageManager === "bun"
58
+ ? `bun install -g ${CLI_PACKAGE_NAME}@latest`
59
+ : `npm install -g ${CLI_PACKAGE_NAME}@latest`;
60
+ throw new Error(
61
+ `Missing optional dependency ${platformPackage}. Reinstall Velen CLI: ${reinstallCommand}`
62
+ );
63
+ }
64
+ }
65
+
66
+ const binaryPath = path.join(vendorRoot, targetTriple, "velen", binaryName);
67
+
68
+ ensureExecutable(binaryPath);
69
+
70
+ const child = spawn(binaryPath, process.argv.slice(2), {
71
+ env: process.env,
72
+ stdio: "inherit",
73
+ });
74
+
75
+ child.on("error", (error) => {
76
+ console.error(error);
77
+ process.exit(1);
78
+ });
79
+
80
+ const forwardSignal = (signal) => {
81
+ if (child.killed) {
82
+ return;
83
+ }
84
+
85
+ try {
86
+ child.kill(signal);
87
+ } catch {
88
+ // Ignore forwarding failures if the child already exited.
89
+ }
90
+ };
91
+
92
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((signal) => {
93
+ process.on(signal, () => forwardSignal(signal));
94
+ });
95
+
96
+ const childResult = await new Promise((resolve) => {
97
+ child.on("exit", (code, signal) => {
98
+ if (signal) {
99
+ resolve({ signal, type: "signal" });
100
+ return;
101
+ }
102
+
103
+ resolve({ exitCode: code ?? 1, type: "code" });
104
+ });
105
+ });
106
+
107
+ if (childResult.type === "signal") {
108
+ process.kill(process.pid, childResult.signal);
109
+ } else {
110
+ process.exit(childResult.exitCode);
111
+ }
112
+
113
+ function detectPackageManager() {
114
+ const userAgent = process.env.npm_config_user_agent ?? "";
115
+ if (/\bbun\//.test(userAgent)) {
116
+ return "bun";
117
+ }
118
+
119
+ const execPath = process.env.npm_execpath ?? "";
120
+ if (execPath.includes("bun")) {
121
+ return "bun";
122
+ }
123
+
124
+ if (
125
+ __dirname.includes(".bun/install/global") ||
126
+ __dirname.includes(".bun\\install\\global")
127
+ ) {
128
+ return "bun";
129
+ }
130
+
131
+ return userAgent ? "npm" : null;
132
+ }
133
+
134
+ function ensureExecutable(filePath) {
135
+ const currentMode = statSync(filePath).mode & 0o777;
136
+ if ((currentMode & 0o111) !== 0) {
137
+ return;
138
+ }
139
+
140
+ // CONTEXT: npm tarballs store vendored native binaries without execute bits,
141
+ // so restore the expected mode before spawning the packaged CLI binary.
142
+ chmodSync(filePath, currentMode | 0o755);
143
+ }
package/package.json CHANGED
@@ -1,27 +1,28 @@
1
1
  {
2
- "cpu": [
3
- "arm64"
4
- ],
2
+ "name": "@wordbricks/velen",
3
+ "version": "0.2.19",
5
4
  "description": "Velen CLI",
6
- "files": [
7
- "vendor",
8
- "README.md"
9
- ],
10
5
  "license": "Apache-2.0",
11
- "name": "@wordbricks/velen",
12
- "os": [
13
- "darwin"
14
- ],
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
6
  "repository": {
19
7
  "type": "git",
20
8
  "url": "git+https://github.com/wordbricks/velen.git",
21
9
  "directory": "apps/cli"
22
10
  },
23
- "version": "0.2.19-darwin-arm64",
11
+ "bin": {
12
+ "velen": "bin/velen.js"
13
+ },
14
+ "files": [
15
+ "bin",
16
+ "README.md"
17
+ ],
18
+ "type": "module",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
24
22
  "engines": {
25
23
  "node": ">=18"
24
+ },
25
+ "optionalDependencies": {
26
+ "velen-darwin-arm64": "npm:@wordbricks/velen@0.2.19-darwin-arm64"
26
27
  }
27
28
  }