Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract bindings #128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/load-bindings.ts
Original file line number Diff line number Diff line change
@@ -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')}
Expand Down
5 changes: 2 additions & 3 deletions lib/poller.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions lib/serialport-bindings.ts
Original file line number Diff line number Diff line change
@@ -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