Skip to content

Commit

Permalink
fix(mac): Use dynamic loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Apr 12, 2021
1 parent a4d6026 commit 79e2526
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/bindings/mac/Adapter.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions lib/bindings/mac/Adapter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/bindings/mac/Adapter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/bindings/mac/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import util from 'util';
import { Adapter, AddressType, GattLocal, MODblue, Peripheral } from '../../models';
import { MacPeripheral } from './Peripheral';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const NobleMac = require('./native').NobleMac;
util.inherits(NobleMac, events.EventEmitter);

export class MacAdapter extends Adapter {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public readonly noble: any = null;

private initDone = false;
Expand All @@ -23,6 +20,11 @@ export class MacAdapter extends Adapter {
public constructor(modblue: MODblue, id: string, name: string) {
super(modblue, id, name);

// This fixes an issue with webpack trying to load the module at compile time
const NAME = 'native';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const NobleMac = require(`./${NAME}`).NobleMac;
util.inherits(NobleMac, events.EventEmitter);
this.noble = new NobleMac();
}

Expand Down

0 comments on commit 79e2526

Please sign in to comment.