Skip to content

Conversation

@mathiask88
Copy link
Owner

Summary

  • rewrite client and server bindings from NAN to N-API
  • expose promise-first APIs with optional callbacks and sync variants for PLC operations
  • add prebuildify-based toolchain and node-gyp-build loader; drop prebuild-install/bindings
  • publish CJS/ESM entries and TypeScript definitions (lib/node-snap7.{js,mjs,d.ts}) via exports map
  • set engines to node >=18
  • expand prebuild scripts for multiple platforms/arches with prebuildify/prebuildify-ci/prebuildify-cross
  • refresh docs and add tests
  • bump version to 2.0.0-beta

Build and packaging
- replace NAN include with node-addon-api target and disable deprecated APIs
- enforce no-exceptions builds per platform (linux/freebsd/mac/win) while keeping hidden visibility flags
- keep snap7 secondary target, enabling exceptions where needed on native sources
- add node-gyp-build loader (binding.js) to resolve local builds or prebuilds
- move package.json to 2.0.0-beta with exports map (CJS/ESM/types) and .d.ts entry
- raise engines to >=18; switch runtime dep to node-gyp-build
- replace prebuild/install flow with prebuildify/prebuildify-ci/prebuildify-cross scripts
- add devDeps for node-addon-api, node-gyp, and prebuildify toolchain; update rebuild/test/download scripts

JavaScript API
- route native binding through node-gyp-build; export both CJS and ESM entry points
- wrap S7Server with EventEmitter using util.inherits
- generate client methods that return promises with optional callback bridges
- add Sync variants calling underscore-prefixed native methods
- recreate DB/MB/EB/AB/TM/CT helpers for async/sync read/write with optional db number
- update copyright headers to 2025

Types
- add lib/node-snap7.d.ts defining Snap7Error, client/server methods, areas/word lengths, and helper shapes
- ensure exports map points to types for TS consumers

Addon entry
- convert module init from NAN to NODE_API_MODULE using Napi::Env/Napi::Object exports
- register S7Client/S7Server via N-API init functions

Native client
- port NAN class wrapper to N-API (ObjectWrap/DefineClass) with StaticValue constant exports
- update constructors/destructors and mutex handling for N-API
- switch method signatures to Napi::CallbackInfo, throw Napi::TypeError on bad args
- promise-returning methods with internal sync variants for ReadArea/WriteArea/MultiVars/etc.
- rewrite Upload/FullUpload/Download to allocate buffers via N-API and return JS buffers
- move shared helpers into new node_snap7_helpers.h; drop Nan::To and legacy buffer helpers
- refresh error/enum exports to StaticValue instead of prototype templates

Native server
- port server wrapper from NAN templates to N-API DefineClass
- export server constants via StaticValue; align method bindings to N-API signatures
- update constructor/registration and status handling for N-API
- keep snap7 server setup and callbacks consistent with new wrapper types

Headers/helpers
- add node_snap7_helpers.h for shared conversions/buffer helpers
- update client/server headers for N-API class declarations and exports

ESM support
- add lib/node-snap7.mjs as ESM entry that re-exports the CJS binding

Notes
- large deletions come from removing NAN scaffolding in favor of N-API
- promise-first API remains callback-compatible via optional last-arg callback
- add Node/Electron test runner scripts with runtime version logging
- update npm scripts and .npmignore to use new runners
- run Electron tests on Ubuntu CI (AppArmor tweak + xvfb)
- clarify README testing section for Node vs Electron suites
Drop LastError bindings and state; rely on thrown/rejected Snap7Error instead.
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.

2 participants