Skip to content

Modernize package to Node-API, ES, add TypeScript bindings#19

Open
mjradwin wants to merge 6 commits into
hideo55:masterfrom
mjradwin:master
Open

Modernize package to Node-API, ES, add TypeScript bindings#19
mjradwin wants to merge 6 commits into
hideo55:masterfrom
mjradwin:master

Conversation

@mjradwin

Copy link
Copy Markdown

Replaces the deprecated NAN (Native Abstractions for Node.js) with the stable ABI Node-API via node-addon-api, converts the package to ES modules, adds TypeScript declarations, and bumps to v0.6.0.

Native addon: NAN → Node-API

  • Rewrote src/node_murmurhash3.cc against napi.h
  • Nan::AsyncWorkerNapi::AsyncWorker, NAN_METHODNapi::Value functions, NODE_MODULENODE_API_MODULE
  • Removed all V8-version-specific #if conditionals — Node-API abstracts these
  • Replaced C preprocessor validation macros with a ValidateArg() helper

ES module packaging

  • lib/murmurhash3.js: exports.* → named export function, native addon loaded via createRequire(import.meta.url)
  • package.json: added "type": "module", replaced "main" with "module" + "exports", engines bumped to >=16.0.0
  • test/test.js: require()import
  • Upgraded mocha ^5.2.0^10.8.2 (ESM support)

TypeScript typings

  • Added lib/murmurhash3.d.ts with sync API declarations, referenced via "types" in package.json
import { murmur32Sync, murmur128HexSync } from 'murmurhash3';

const hash: number = murmur32Sync('hello');
const hex: string = murmur128HexSync('hello', 42);

All 96 existing tests pass unchanged.

Copilot AI and others added 6 commits April 24, 2026 22:07
- Replace nan dependency with node-addon-api ^8.7.0
- Update binding.gyp to use node-addon-api includes and NAPI_CPP_EXCEPTIONS
- Rewrite src/node_murmurhash3.cc using napi.h:
  - Napi::AsyncWorker replaces Nan::AsyncWorker
  - Napi::Value functions replace NAN_METHOD macros
  - Napi::Object Init + NODE_API_MODULE replaces NAN_MODULE_INIT + NODE_MODULE
  - Preserve all argument validation and error messages
- All 96 tests pass

Agent-Logs-Url: https://github.com/mjradwin/node-murmurhash3/sessions/5d544747-c0a4-4974-9ba5-8d54470c91a4

Co-authored-by: mjradwin <3769045+mjradwin@users.noreply.github.com>
- Convert lib/murmurhash3.js from CommonJS to ES module (import/export)
- Add "type": "module" to package.json
- Replace "main" with "module" and "exports" fields
- Add TypeScript declaration file lib/murmurhash3.d.ts
- Add "types" field to package.json
- Update test/test.js to use ES module imports
- Upgrade mocha to v10 for ESM support
- Bump version to 0.6.0
- Update engines to node >= 16.0.0

Agent-Logs-Url: https://github.com/mjradwin/node-murmurhash3/sessions/54d77b95-208e-4ab5-8300-44507cd831e1

Co-authored-by: mjradwin <3769045+mjradwin@users.noreply.github.com>
Migrate from NAN to Node-API, convert to ES modules, add TypeScript typings
Extend the TypeScript declarations to cover the async callback-based
functions (murmur32, murmur32Hex, murmur128, murmur128Hex) and the
exported `version` constant. Update the README to use ES module
imports and arrow-function callbacks, and document a util.promisify
pattern for async/await usage.
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.

3 participants