Skip to content

Commit 730bc61

Browse files
rosek86td-krzysiek
andauthored
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 <[email protected]>
1 parent 4655cc1 commit 730bc61

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/load-bindings.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import nodeGypBuild from 'node-gyp-build'
21
import { promisify } from 'util'
3-
import { join } from 'path'
4-
5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
const binding = nodeGypBuild(join(__dirname, '../')) as any
2+
import { binding } from './serialport-bindings'
73

84
export const asyncClose = binding.close ? promisify(binding.close) : async () => { throw new Error('"binding.close" Method not implemented')}
95
export const asyncDrain = binding.drain ? promisify(binding.drain) : async () => { throw new Error('"binding.drain" Method not implemented')}

lib/poller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import debug from 'debug'
22
import { EventEmitter } from 'events'
3-
import { join } from 'path'
4-
import nodeGypBuild from 'node-gyp-build'
53
import { BindingsError } from './errors'
4+
import { binding } from './serialport-bindings'
65

7-
const { Poller: PollerBindings } = nodeGypBuild(join(__dirname, '../')) as { Poller: PollerClass }
6+
const { Poller: PollerBindings } = binding as { Poller: PollerClass }
87
const logger = debug('serialport/bindings-cpp/poller')
98

109
interface PollerClass {

lib/serialport-bindings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { join } from 'path'
2+
import nodeGypBuild from 'node-gyp-build'
3+
4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5+
export const binding = nodeGypBuild(join(__dirname, '../')) as any

0 commit comments

Comments
 (0)