zignapi 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # zignapi
2
2
 
3
- The CLI for [zigbind](https://github.com/zigbind/zigbind): scaffold and build
3
+ The CLI for [zignapi](https://github.com/zignapi/zignapi): scaffold and build
4
4
  native Node.js addons written in Zig. Written in TypeScript, compiled to ESM with
5
5
  **zero runtime dependencies**, no `node-gyp`. Requires **Zig 0.16.0** on `PATH`
6
6
  and **Node >= 18**.
@@ -17,7 +17,7 @@ zignapi build [--release] # run `zig build` in the cwd, emit ./<name>.node
17
17
  ```
18
18
 
19
19
  - `new` copies the template tree (substituting the project name) and pins the
20
- `zigbind` Zig dependency with `zig fetch --save`.
20
+ `zignapi` Zig dependency with `zig fetch --save`.
21
21
  - `build` runs `zig build` (adding `-Doptimize=ReleaseFast` with `--release`),
22
22
  then copies the produced shared library to `./<name>.node`. If `build.zig.zon`
23
23
  is missing a fingerprint, it fills in the value Zig suggests and retries.
package/dist/new.js CHANGED
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, } from
3
3
  import { join, dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import process from "node:process";
6
- import { releaseUrl, resolveZigbindSources, runZig } from "./zig.js";
6
+ import { releaseUrl, resolveZignapiSources, runZig } from "./zig.js";
7
7
  // The template tree lives at the package root (as `templates/`), so it resolves
8
8
  // the same whether we run from the compiled `dist/` or the source `src/`.
9
9
  const TEMPLATES_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "templates");
@@ -14,7 +14,7 @@ Usage:
14
14
  zignapi new <name> [--local]
15
15
 
16
16
  Creates ./<name> from the built-in template, substituting the project name,
17
- then wires up the zigbind Zig dependency with "zig fetch --save" (pinned by
17
+ then wires up the zignapi Zig dependency with "zig fetch --save" (pinned by
18
18
  content hash). By default it fetches the hosted release tarball, so the project
19
19
  is portable across machines/CI; if that's unreachable it falls back to the Zig
20
20
  sources bundled with the CLI.
@@ -46,7 +46,7 @@ export async function runNew(argv) {
46
46
  throw new Error(`directory '${name}' already exists`);
47
47
  }
48
48
  copyTemplate(TEMPLATES_DIR, target, name);
49
- addZigbindDependency(target, { local: values.local ?? false });
49
+ addZignapiDependency(target, { local: values.local ?? false });
50
50
  process.stdout.write(`✔ created ${name}/\n\n` +
51
51
  `Next steps:\n` +
52
52
  ` cd ${name}\n` +
@@ -54,36 +54,36 @@ export async function runNew(argv) {
54
54
  ` node --test\n`);
55
55
  }
56
56
  /**
57
- * Add the `zigbind` Zig dependency to the freshly scaffolded project via
57
+ * Add the `zignapi` Zig dependency to the freshly scaffolded project via
58
58
  * `zig fetch --save`, pinning it by content hash. Prefers the hosted release
59
59
  * tarball (portable across machines) and falls back to the Zig sources bundled
60
60
  * with the CLI if that's unreachable or `local` is set. Non-fatal: if Zig isn't
61
61
  * available at all, tell the user how to finish the wiring later.
62
62
  */
63
- function addZigbindDependency(target, { local }) {
63
+ function addZignapiDependency(target, { local }) {
64
64
  const repairZon = join(target, "build.zig.zon");
65
65
  if (!local) {
66
66
  const url = releaseUrl();
67
67
  try {
68
- runZig(target, ["fetch", "--save=zigbind", url], { repairZon });
69
- process.stdout.write(`✔ added zigbind dependency from ${url}\n`);
68
+ runZig(target, ["fetch", "--save=zignapi", url], { repairZon });
69
+ process.stdout.write(`✔ added zignapi dependency from ${url}\n`);
70
70
  return;
71
71
  }
72
72
  catch (err) {
73
- process.stderr.write(`note: could not fetch the hosted zigbind release (${errMessage(err)}); ` +
73
+ process.stderr.write(`note: could not fetch the hosted zignapi release (${errMessage(err)}); ` +
74
74
  `falling back to the bundled sources.\n`);
75
75
  }
76
76
  }
77
77
  let sources;
78
78
  try {
79
- sources = resolveZigbindSources();
80
- runZig(target, ["fetch", "--save=zigbind", sources], { repairZon });
81
- process.stdout.write("✔ added zigbind dependency from bundled sources\n");
79
+ sources = resolveZignapiSources();
80
+ runZig(target, ["fetch", "--save=zignapi", sources], { repairZon });
81
+ process.stdout.write("✔ added zignapi dependency from bundled sources\n");
82
82
  }
83
83
  catch (err) {
84
- process.stderr.write(`warning: could not add the zigbind dependency automatically ` +
84
+ process.stderr.write(`warning: could not add the zignapi dependency automatically ` +
85
85
  `(${errMessage(err)}).\nRun this inside the project once Zig 0.16.0 is ` +
86
- `available:\n zig fetch --save=zigbind ${sources ?? releaseUrl()}\n`);
86
+ `available:\n zig fetch --save=zignapi ${sources ?? releaseUrl()}\n`);
87
87
  }
88
88
  }
89
89
  /**
package/dist/zig.js CHANGED
@@ -7,25 +7,25 @@ import process from "node:process";
7
7
  // up is the package root.
8
8
  const PKG_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
9
9
  /**
10
- * The hosted release tarball of the zigbind Zig package, used as the default
11
- * (portable, shareable) dependency source. Overridable via ZIGBIND_RELEASE_URL
10
+ * The hosted release tarball of the zignapi Zig package, used as the default
11
+ * (portable, shareable) dependency source. Overridable via ZIGNAPI_RELEASE_URL
12
12
  * — handy for testing against a local `file://` tarball or a mirror. The
13
13
  * version is taken from this CLI's package.json and must match the release tag.
14
14
  */
15
15
  export function releaseUrl() {
16
- const override = process.env.ZIGBIND_RELEASE_URL;
16
+ const override = process.env.ZIGNAPI_RELEASE_URL;
17
17
  if (override)
18
18
  return override;
19
19
  const pkg = JSON.parse(readFileSync(join(PKG_ROOT, "package.json"), "utf8"));
20
20
  const v = pkg.version;
21
- return `https://github.com/zigbind/zigbind/releases/download/v${v}/zigbind-${v}.tar.gz`;
21
+ return `https://github.com/zignapi/zignapi/releases/download/v${v}/zignapi-${v}.tar.gz`;
22
22
  }
23
23
  /**
24
- * Locate the zigbind Zig sources (the `native/` directory) that ship with this
24
+ * Locate the zignapi Zig sources (the `native/` directory) that ship with this
25
25
  * CLI. Works both from the published npm package (bundled at `<pkg>/native`)
26
- * and from the monorepo checkout (`packages/zigbind` -> `../../native`).
26
+ * and from the monorepo checkout (`packages/zignapi` -> `../../native`).
27
27
  */
28
- export function resolveZigbindSources() {
28
+ export function resolveZignapiSources() {
29
29
  const candidates = [
30
30
  join(PKG_ROOT, "native"), // bundled inside the published package
31
31
  join(PKG_ROOT, "..", "..", "native"), // monorepo layout
@@ -34,7 +34,7 @@ export function resolveZigbindSources() {
34
34
  if (existsSync(join(dir, "build.zig.zon")))
35
35
  return dir;
36
36
  }
37
- throw new Error("could not locate the zigbind Zig sources (native/) shipped with the CLI");
37
+ throw new Error("could not locate the zignapi Zig sources (native/) shipped with the CLI");
38
38
  }
39
39
  /**
40
40
  * Run `zig` with the given args in `cwd`. If the run fails because
package/native/build.zig CHANGED
@@ -1,9 +1,9 @@
1
1
  const std = @import("std");
2
2
 
3
- /// Build script for the `zigbind` Zig library.
3
+ /// Build script for the `zignapi` Zig library.
4
4
  ///
5
5
  /// This is a Zig package, not an npm package. Its main product is the Zig
6
- /// module named "zigbind" (exposed via `b.addModule`), which addons import to
6
+ /// module named "zignapi" (exposed via `b.addModule`), which addons import to
7
7
  /// register their functions with Node. Building here also runs two local
8
8
  /// checks so `zig build` in this directory validates the library on its own:
9
9
  ///
@@ -16,12 +16,12 @@ pub fn build(b: *std.Build) void {
16
16
 
17
17
  const headers = b.path("vendor/node-api-headers");
18
18
 
19
- // The module consumers import as `@import("zigbind")`. It links libc (for
19
+ // The module consumers import as `@import("zignapi")`. It links libc (for
20
20
  // the C allocator used to marshal string arguments, and to make the N-API
21
21
  // headers available to `@cImport`). Target/optimize are left unset here so
22
22
  // each consumer picks them; the include path travels with the module.
23
- const mod = b.addModule("zigbind", .{
24
- .root_source_file = b.path("src/zigbind.zig"),
23
+ const mod = b.addModule("zignapi", .{
24
+ .root_source_file = b.path("src/zignapi.zig"),
25
25
  .link_libc = true,
26
26
  });
27
27
  mod.addIncludePath(headers);
@@ -37,7 +37,7 @@ pub fn build(b: *std.Build) void {
37
37
  });
38
38
  check_mod.addIncludePath(headers);
39
39
  const check_obj = b.addObject(.{
40
- .name = "zigbind-check",
40
+ .name = "zignapi-check",
41
41
  .root_module = check_mod,
42
42
  });
43
43
  b.getInstallStep().dependOn(&check_obj.step);
@@ -53,6 +53,6 @@ pub fn build(b: *std.Build) void {
53
53
  tests_mod.addIncludePath(headers);
54
54
  const unit_tests = b.addTest(.{ .root_module = tests_mod });
55
55
  const run_tests = b.addRunArtifact(unit_tests);
56
- const test_step = b.step("test", "Run zigbind unit tests");
56
+ const test_step = b.step("test", "Run zignapi unit tests");
57
57
  test_step.dependOn(&run_tests.step);
58
58
  }
@@ -1,7 +1,7 @@
1
1
  .{
2
- .name = .zigbind,
3
- .version = "0.1.0",
4
- .fingerprint = 0xb615899b08c4e528, // Changing this has security and trust implications.
2
+ .name = .zignapi,
3
+ .version = "0.1.1",
4
+ .fingerprint = 0x582024f92c57df77, // Changing this has security and trust implications.
5
5
  .minimum_zig_version = "0.16.0",
6
6
  .dependencies = .{},
7
7
  .paths = .{
@@ -1,13 +1,13 @@
1
1
  //! Build-only compile check (never shipped to consumers, not imported by
2
- //! `zigbind.zig`). Building this as an *object* forces the whole comptime
2
+ //! `zignapi.zig`). Building this as an *object* forces the whole comptime
3
3
  //! pipeline — `register` → the per-function callback trampolines → `convert`
4
4
  //! for every supported type, including an error union — to be analyzed, so
5
5
  //! `zig build` in `native/` fails loudly on any API or type mistake. The
6
6
  //! N-API symbols it references stay undefined in the object file; they are
7
7
  //! resolved when a real addon links, exactly as in production.
8
8
 
9
- const zigbind = @import("zigbind.zig");
10
- const napi = zigbind.napi;
9
+ const zignapi = @import("zignapi.zig");
10
+ const napi = zignapi.napi;
11
11
 
12
12
  // Reference the concrete (non-generic) wrappers so they are compiled too.
13
13
  comptime {
@@ -35,7 +35,7 @@ fn checked(x: i32) !i32 {
35
35
  }
36
36
 
37
37
  comptime {
38
- zigbind.register(.{
38
+ zignapi.register(.{
39
39
  .add = add,
40
40
  .negate = negate,
41
41
  .scale = scale,
@@ -31,7 +31,7 @@ pub fn classify(comptime T: type) Kind {
31
31
  /// Compile-time guard that fails with a readable message for unsupported types.
32
32
  fn assertSupported(comptime T: type) void {
33
33
  if (classify(T) == .unsupported) {
34
- @compileError("zigbind: unsupported type '" ++ @typeName(T) ++
34
+ @compileError("zignapi: unsupported type '" ++ @typeName(T) ++
35
35
  "' (supported: integers, floats, bool, []const u8)");
36
36
  }
37
37
  }
@@ -4,9 +4,9 @@
4
4
  //! Usage from an addon's root source file:
5
5
  //!
6
6
  //! ```zig
7
- //! const zigbind = @import("zigbind");
7
+ //! const zignapi = @import("zignapi");
8
8
  //! pub fn add(a: i32, b: i32) i32 { return a + b; }
9
- //! comptime { zigbind.register(.{ .add = add }); }
9
+ //! comptime { zignapi.register(.{ .add = add }); }
10
10
  //! ```
11
11
 
12
12
  const std = @import("std");
@@ -24,7 +24,7 @@ pub fn register(comptime defs: anytype) void {
24
24
  const Defs = @TypeOf(defs);
25
25
  switch (@typeInfo(Defs)) {
26
26
  .@"struct" => {},
27
- else => @compileError("zigbind.register expects a struct literal, e.g. .{ .add = add }"),
27
+ else => @compileError("zignapi.register expects a struct literal, e.g. .{ .add = add }"),
28
28
  }
29
29
 
30
30
  const Registrar = struct {
@@ -32,7 +32,7 @@ pub fn register(comptime defs: anytype) void {
32
32
  inline for (@typeInfo(Defs).@"struct".fields) |field| {
33
33
  const func = @field(defs, field.name);
34
34
  registerOne(env, exports, field.name, func) catch {
35
- napi.throwError(env, "zigbind: failed to register '" ++ field.name ++ "'");
35
+ napi.throwError(env, "zignapi: failed to register '" ++ field.name ++ "'");
36
36
  return null;
37
37
  };
38
38
  }
@@ -67,7 +67,7 @@ fn Wrap(comptime func: anytype) type {
67
67
  // Collect the JS arguments (one slot per Zig parameter).
68
68
  var argv: [fn_info.params.len]napi.Value = undefined;
69
69
  _ = napi.getCallbackInfo(env, info, &argv) catch {
70
- napi.throwError(env, "zigbind: failed to read arguments");
70
+ napi.throwError(env, "zignapi: failed to read arguments");
71
71
  return null;
72
72
  };
73
73
 
@@ -81,7 +81,7 @@ fn Wrap(comptime func: anytype) type {
81
81
  var args: std.meta.ArgsTuple(@TypeOf(func)) = undefined;
82
82
  inline for (fn_info.params, 0..) |param, i| {
83
83
  args[i] = convert.fromJs(param.type.?, env, argv[i], allocator) catch {
84
- napi.throwError(env, "zigbind: failed to convert argument");
84
+ napi.throwError(env, "zignapi: failed to convert argument");
85
85
  return null;
86
86
  };
87
87
  }
@@ -108,7 +108,7 @@ fn Wrap(comptime func: anytype) type {
108
108
 
109
109
  fn toJs(env: napi.Env, comptime T: type, value: T) napi.Value {
110
110
  return convert.toJs(T, env, value) catch {
111
- napi.throwError(env, "zigbind: failed to convert return value");
111
+ napi.throwError(env, "zignapi: failed to convert return value");
112
112
  return null;
113
113
  };
114
114
  }
@@ -1,7 +1,7 @@
1
- //! zigbind — write native Node.js addons in Zig.
1
+ //! zignapi — write native Node.js addons in Zig.
2
2
  //!
3
3
  //! This is the public entry point of the Zig module consumers import with
4
- //! `@import("zigbind")`. It re-exports the pieces an addon author needs:
4
+ //! `@import("zignapi")`. It re-exports the pieces an addon author needs:
5
5
  //!
6
6
  //! - `register` : expose Zig functions to JS and emit `napi_register_module_v1`.
7
7
  //! - `napi` : the raw N-API bindings and thin wrappers, for escape hatches.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zignapi",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI to scaffold and build native Node.js addons written in Zig (the `zignapi` command)",
5
5
  "keywords": [
6
6
  "zig",
@@ -8,13 +8,13 @@
8
8
  "node-api",
9
9
  "native",
10
10
  "addon",
11
- "zigbind"
11
+ "zignapi"
12
12
  ],
13
- "homepage": "https://github.com/zigbind/zigbind",
13
+ "homepage": "https://github.com/zignapi/zignapi",
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "git+https://github.com/zigbind/zigbind.git",
17
- "directory": "packages/zigbind"
16
+ "url": "git+https://github.com/zignapi/zignapi.git",
17
+ "directory": "packages/zignapi"
18
18
  },
19
19
  "type": "module",
20
20
  "bin": {
@@ -1,17 +1,17 @@
1
1
  # __NAME__
2
2
 
3
3
  A native Node.js addon written in [Zig](https://ziglang.org/) with
4
- [zigbind](https://github.com/) — requires **Zig 0.16.0** and **Node >= 18**.
4
+ [zignapi](https://github.com/) — requires **Zig 0.16.0** and **Node >= 18**.
5
5
 
6
6
  ```sh
7
7
  zignapi build # compiles src/main.zig into __NAME__.node (and zig-out/lib/)
8
8
  node --test # runs test.js
9
9
  ```
10
10
 
11
- Edit `src/main.zig` to add functions, then list them in the `zigbind.register`
11
+ Edit `src/main.zig` to add functions, then list them in the `zignapi.register`
12
12
  call at the bottom of that file.
13
13
 
14
- ## The zigbind dependency
14
+ ## The zignapi dependency
15
15
 
16
16
  `zignapi new` added the `zignapi` Zig module to `build.zig.zon` with
17
17
  `zig fetch --save`, which pins it by content hash:
@@ -2,13 +2,13 @@ const std = @import("std");
2
2
 
3
3
  /// Builds the addon into `zig-out/lib/__NAME__.node`.
4
4
  ///
5
- /// The addon is a dynamic library importing the `zigbind` module. N-API symbols
5
+ /// The addon is a dynamic library importing the `zignapi` module. N-API symbols
6
6
  /// are left undefined at link time and resolved by Node when it loads the addon.
7
7
  pub fn build(b: *std.Build) void {
8
8
  const target = b.standardTargetOptions(.{});
9
9
  const optimize = b.standardOptimizeOption(.{});
10
10
 
11
- const zigbind = b.dependency("zigbind", .{}).module("zigbind");
11
+ const zignapi = b.dependency("zignapi", .{}).module("zignapi");
12
12
 
13
13
  const addon = b.addLibrary(.{
14
14
  .name = "__NAME__",
@@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void {
19
19
  .optimize = optimize,
20
20
  .link_libc = true,
21
21
  .imports = &.{
22
- .{ .name = "zigbind", .module = zigbind },
22
+ .{ .name = "zignapi", .module = zignapi },
23
23
  },
24
24
  }),
25
25
  });
@@ -2,8 +2,8 @@
2
2
  .name = .__NAME__,
3
3
  .version = "0.1.0",
4
4
  .minimum_zig_version = "0.16.0",
5
- // `zignapi new` fills in `.fingerprint` and adds the `zigbind` dependency
6
- // below via `zig fetch --save` (which pins zigbind by content hash).
5
+ // `zignapi new` fills in `.fingerprint` and adds the `zignapi` dependency
6
+ // below via `zig fetch --save` (which pins zignapi by content hash).
7
7
  .dependencies = .{},
8
8
  .paths = .{
9
9
  "build.zig",
@@ -1,4 +1,4 @@
1
- const zigbind = @import("zigbind");
1
+ const zignapi = @import("zignapi");
2
2
 
3
3
  /// Exposed to JS as `addon.add(a, b)`.
4
4
  pub fn add(a: i32, b: i32) i32 {
@@ -14,7 +14,7 @@ pub fn greet(name: []const u8) []const u8 {
14
14
  // Emits `napi_register_module_v1`. Each field becomes a property on the addon's
15
15
  // `exports`. Add your own Zig functions here.
16
16
  comptime {
17
- zigbind.register(.{
17
+ zignapi.register(.{
18
18
  .add = add,
19
19
  .greet = greet,
20
20
  });