mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
extract bindings (#128)
Hello,
I have a use case where size of an application is important, I'd like to
webpack as much as possible. The problematic part is related *.node
files, I found a potential solution, example with sqlite:
```
externals: {
'./sqlite3-binding.js': 'commonjs ./node_sqlite3.node',
}
```
I can replace sqlite3-binding.js [1] with *.node, then I copy
node_sqlite3.node to the main application folder. I'd like to try
something similar with the serialport. However, it is slightly more
complicated since serialport doesn't have single import file. This PR is
an attempt to fix the problem.
[1]
https://github.com/TryGhost/node-sqlite3/blob/master/lib/sqlite3-binding.js
---------
Co-authored-by: Krzysztof Rosiński <krzysiek@jrdltd.co.uk>
This commit is contained in:
parent
4655cc1439
commit
730bc61942
3 changed files with 8 additions and 8 deletions
|
|
@ -1,9 +1,5 @@
|
|||
import nodeGypBuild from 'node-gyp-build'
|
||||
import { promisify } from 'util'
|
||||
import { join } from 'path'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const binding = nodeGypBuild(join(__dirname, '../')) as any
|
||||
import { binding } from './serialport-bindings'
|
||||
|
||||
export const asyncClose = binding.close ? promisify(binding.close) : async () => { throw new Error('"binding.close" Method not implemented')}
|
||||
export const asyncDrain = binding.drain ? promisify(binding.drain) : async () => { throw new Error('"binding.drain" Method not implemented')}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import debug from 'debug'
|
||||
import { EventEmitter } from 'events'
|
||||
import { join } from 'path'
|
||||
import nodeGypBuild from 'node-gyp-build'
|
||||
import { BindingsError } from './errors'
|
||||
import { binding } from './serialport-bindings'
|
||||
|
||||
const { Poller: PollerBindings } = nodeGypBuild(join(__dirname, '../')) as { Poller: PollerClass }
|
||||
const { Poller: PollerBindings } = binding as { Poller: PollerClass }
|
||||
const logger = debug('serialport/bindings-cpp/poller')
|
||||
|
||||
interface PollerClass {
|
||||
|
|
|
|||
5
lib/serialport-bindings.ts
Normal file
5
lib/serialport-bindings.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { join } from 'path'
|
||||
import nodeGypBuild from 'node-gyp-build'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const binding = nodeGypBuild(join(__dirname, '../')) as any
|
||||
Loading…
Add table
Reference in a new issue