@zigc/cli 0.15.20 → 0.16.0-dev.3041

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/README.md +1 -5
  2. package/bin/zig +20 -93
  3. package/package.json +10 -9
package/README.md CHANGED
@@ -27,8 +27,4 @@ The `@zigc/cli` package resolves the correct native binary for your platform via
27
27
  | `@zigc/win32-x64` | Windows x64 |
28
28
  | `@zigc/win32-arm64` | Windows ARM64 |
29
29
 
30
- The standard library is shipped separately in `@zigc/lib` (shared across all platforms).
31
-
32
- ## License
33
-
34
- MIT
30
+ The standard library is shipped separately in `@zigc/lib` (shared across all platforms).
package/bin/zig CHANGED
@@ -1,99 +1,26 @@
1
1
  #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { createRequire } from 'node:module';
2
4
 
3
- // Stub that delegates to the native zig binary from the platform package.
4
- // Sets ZIG_LIB_DIR to the shared @zigc/lib package.
5
-
6
- import { execFileSync } from "child_process";
7
- import { existsSync, readFileSync } from "fs";
8
- import { createRequire } from "module";
9
- import { dirname, join } from "path";
10
- import { fileURLToPath } from "url";
11
-
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
5
  const require = createRequire(import.meta.url);
14
- const isWindows = process.platform === "win32";
15
- const ext = isWindows ? ".exe" : "";
16
- const platformKey = `${process.platform}-${process.arch}`;
17
-
18
- const platformDirs = {
19
- "darwin-arm64": "darwin-arm64",
20
- "darwin-x64": "darwin-x64",
21
- "linux-x64": "linux-x64",
22
- "linux-arm64": "linux-arm64",
23
- "win32-x64": "win32-x64",
24
- "win32-arm64": "win32-arm64",
25
- };
26
-
27
- function isNativeBinary(filePath) {
28
- try {
29
- const buf = readFileSync(filePath, { encoding: null, flag: "r" });
30
- return buf.length > 2 && !(buf[0] === 0x23 && buf[1] === 0x21);
31
- } catch { return false; }
32
- }
33
-
34
- function findBinary() {
35
- const binName = `zig${ext}`;
36
-
37
- // 1. Check if a real binary exists next to this stub
38
- const localBin = join(__dirname, binName);
39
- if (existsSync(localBin) && isNativeBinary(localBin)) return localBin;
40
-
41
- // 2. Resolve from the platform-specific optional dependency (npm installed)
42
- const pkgName = `@zigc/${platformDirs[platformKey]}`;
43
- if (pkgName) {
44
- try {
45
- const pkgDir = dirname(require.resolve(`${pkgName}/package.json`));
46
- const bin = join(pkgDir, "bin", binName);
47
- if (existsSync(bin)) return bin;
48
- } catch {}
49
- }
50
-
51
- // 3. Check sibling workspace directory (local dev with prepare.sh)
52
- const dir = platformDirs[platformKey];
53
- if (dir) {
54
- const sibling = join(__dirname, "..", "..", dir, "bin", binName);
55
- if (existsSync(sibling)) return sibling;
56
- }
57
-
58
- return null;
59
- }
60
-
61
- function findLibDir() {
62
- // 1. Resolve from @zigc/lib package (npm installed)
63
- try {
64
- const libPkgDir = dirname(require.resolve("@zigc/lib/package.json"));
65
- const libDir = join(libPkgDir, "lib");
66
- if (existsSync(libDir)) return libDir;
67
- } catch {}
68
-
69
- // 2. Check sibling workspace directory (local dev)
70
- const sibling = join(__dirname, "..", "..", "lib", "lib");
71
- if (existsSync(sibling)) return sibling;
72
-
73
- return null;
74
- }
75
-
76
- const bin = findBinary();
77
- if (!bin) {
78
- console.error("Error: zig binary not found for this platform.");
79
- console.error(`Platform: ${platformKey}`);
80
- console.error("Run 'bash prepare.sh' in the @zigc directory to download binaries.");
81
- process.exit(1);
82
- }
83
-
84
- const env = { ...process.env };
85
-
86
- // Set ZIG_LIB_DIR so zig can find its standard library
87
- const libDir = findLibDir();
88
- if (libDir) {
89
- env.ZIG_LIB_DIR = libDir;
90
- }
6
+ const pkgName = `@zigc/${process.platform}-${process.arch}`;
7
+ const ext = process.platform === 'win32' ? '.exe' : '';
91
8
 
92
9
  try {
93
- execFileSync(bin, process.argv.slice(2), { stdio: "inherit", env });
10
+ const binaryPath = require.resolve(`${pkgName}/bin/zig${ext}`);
11
+
12
+ const child = spawn(binaryPath, process.argv.slice(2), {
13
+ stdio: 'inherit',
14
+ shell: process.platform === 'win32'
15
+ });
16
+
17
+ child.on('exit', (code) => process.exit(code ?? 0));
18
+ child.on('error', (err) => {
19
+ console.error('Failed to start child process:', err);
20
+ process.exit(1);
21
+ });
94
22
  } catch (e) {
95
- if (e.status !== undefined) {
96
- process.exit(e.status);
97
- }
98
- throw e;
99
- }
23
+ console.error(`Error: Could not find binary for ${process.platform}-${process.arch}`);
24
+ console.error(`Ensure the optional dependency "${pkgName}" is installed.`);
25
+ process.exit(1);
26
+ }
package/package.json CHANGED
@@ -1,25 +1,26 @@
1
1
  {
2
2
  "name": "@zigc/cli",
3
- "version": "0.15.20",
3
+ "version": "0.16.0-dev.3041",
4
+ "type": "module",
4
5
  "description": "Zig compiler CLI via npm - run `bunx @zigc/cli` or `npx @zigc/cli`",
5
6
  "bin": {
6
7
  "zig": "bin/zig"
7
8
  },
8
9
  "repository": {
9
10
  "type": "git",
10
- "url": "git+https://github.com/ziex-dev/ziex.git"
11
+ "url": "git+https://github.com/ziex-dev/zigc.git"
11
12
  },
12
13
  "license": "MIT",
13
14
  "preferUnplugged": true,
14
15
  "dependencies": {
15
- "@zigc/lib": "0.15.20"
16
+ "@zigc/lib": "0.16.0-dev.3041"
16
17
  },
17
18
  "optionalDependencies": {
18
- "@zigc/darwin-arm64": "0.15.20",
19
- "@zigc/darwin-x64": "0.15.20",
20
- "@zigc/linux-x64": "0.15.20",
21
- "@zigc/linux-arm64": "0.15.20",
22
- "@zigc/win32-x64": "0.15.20",
23
- "@zigc/win32-arm64": "0.15.20"
19
+ "@zigc/darwin-arm64": "0.16.0-dev.3041",
20
+ "@zigc/darwin-x64": "0.16.0-dev.3041",
21
+ "@zigc/linux-x64": "0.16.0-dev.3041",
22
+ "@zigc/linux-arm64": "0.16.0-dev.3041",
23
+ "@zigc/win32-x64": "0.16.0-dev.3041",
24
+ "@zigc/win32-arm64": "0.16.0-dev.3041"
24
25
  }
25
26
  }