Skip to content

Migrate native addon from V8 API to node-addon-api, add Bun support#1259

Open
zaccharyfavere wants to merge 6 commits into
SkipLabs:mainfrom
zaccharyfavere:migration-napi-clean
Open

Migrate native addon from V8 API to node-addon-api, add Bun support#1259
zaccharyfavere wants to merge 6 commits into
SkipLabs:mainfrom
zaccharyfavere:migration-napi-clean

Conversation

@zaccharyfavere
Copy link
Copy Markdown

cc @skiplabsdaniel

  • Rewrite the native addon (cjson, common, fromjs, tojs, main) from V8 direct API to node-addon-api for better ABI stability across Node.js versions.
  • Add #include in common.cc for std::ostringstream support.
  • Add Bun runtime support:
    • New unit test spec (tests/src/addon.bun.spec.ts) running the test suite under Bun via mocha with a dedicated .mocharc.bun.json config.
    • New shell script (tests/examples/bun/run_examples.sh) executing examples under Bun in src mode.
    • New Makefile targets: test-bun-unit, test-bun-examples, test-skipruntime-ts-bun.
  • Adapt database example for dual-runtime compatibility:
    • Use dynamic import to select bun:sqlite under Bun, better-sqlite3 under Node, via a small getDatabase() helper in database.ts and database-server.ts.
    • Switch to positional SQL parameters (?) for compatibility between the two sqlite drivers.
  • Use JSON.stringify in groups-client.ts and database-client.ts to produce deterministic output across runtimes.
  • Update database.exp.out and groups.exp.out to match the JSON.stringify output format.
  • Add node-addon-api 8.7.0 as a dependency of @skipruntime/native.

- Rewrite the native addon (cjson, common, fromjs, tojs, main) from V8 direct
  API to node-addon-api for better ABI stability across Node.js versions.
- Add #include <sstream> in common.cc for std::ostringstream support.
- Add Bun runtime support:
  - New unit test spec (tests/src/addon.bun.spec.ts) running the test suite
    under Bun via mocha with a dedicated .mocharc.bun.json config.
  - New shell script (tests/examples/bun/run_examples.sh) executing examples
    under Bun in src mode.
  - New Makefile targets: test-bun-unit, test-bun-examples,
    test-skipruntime-ts-bun.
- Adapt database example for dual-runtime compatibility:
  - Use dynamic import to select bun:sqlite under Bun, better-sqlite3 under
    Node, via a small getDatabase() helper in database.ts and database-server.ts.
  - Switch to positional SQL parameters (?) for compatibility between the two
    sqlite drivers.
- Use JSON.stringify in groups-client.ts and database-client.ts to produce
  deterministic output across runtimes.
- Update database.exp.out and groups.exp.out to match the JSON.stringify
  output format.
- Add node-addon-api 8.7.0 as a dependency of @skipruntime/native.
@mbouaziz mbouaziz requested a review from skiplabsdaniel May 29, 2026 13:47
- Apply clang-format to addon C++ sources, prettier to TS/JSON files
  per the repo's 'make fmt' standards.
- Exclude tests/src/addon.bun.spec.ts from eslint's typed-linting since
  it is intentionally outside the tsconfig project (it is excluded from
  tsc compilation because it uses Bun-specific features).
The no-unsafe-call rule covers both unsafe calls and unsafe constructions
on any-typed values, so a single pragma is sufficient. Other disable
directives reported errors as unused (no-explicit-any, no-unsafe-construction)
so they are removed.
Regenerates package-lock.json to incorporate both upstream's engines.node
relaxation (SkipLabs#1262) and the node-addon-api dependency added for the V8 to
node-addon-api migration.
The original code used the BSD-style u_int32_t typedef in
SkipRuntime_getChangeManager. Replace it with the C99 standard uint32_t
for portability (u_int32_t is not available on all platforms, e.g. MSVC
without specific includes).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant