From a79ff28d88c010dfbb5c42d413dd0d7db8d14da2 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Sat, 2 Apr 2016 20:29:02 -0400 Subject: [PATCH] Dependency cleanup (quick pass) - Eliminates use of node-pre-gyp as an actual module dependency (just a package dependency, this might even be just a devDep now?) - Reduces 5 blocking fs operations to 1 Signed-off-by: Rick Waldron --- serialport.js | 13 +++++++------ test/mocks/darwin-hardware.js | 10 ++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/serialport.js b/serialport.js index abf044e..da4e898 100644 --- a/serialport.js +++ b/serialport.js @@ -6,18 +6,19 @@ // node-pre-gyp, if something fails or package not available fallback // to regular build from source. +// 3rd Party Dependencies var debug = require('debug')('serialport'); -var binary = require('node-pre-gyp'); -var path = require('path'); -var PACKAGE_JSON = path.join(__dirname, 'package.json'); -var binding_path = binary.find(path.resolve(PACKAGE_JSON)); -var SerialPortBinding = require(binding_path); + +// Internal Dependencies +var SerialPortBinding = require('bindings')('serialport.node'); var parsers = require('./lib/parsers'); var listUnix = require('./lib/list-unix'); + +// Built-ins Dependencies var EventEmitter = require('events').EventEmitter; -var util = require('util'); var fs = require('fs'); var stream = require('stream'); +var util = require('util'); function SerialPortFactory() { var factory = this; diff --git a/test/mocks/darwin-hardware.js b/test/mocks/darwin-hardware.js index 2133c78..1fd87dd 100644 --- a/test/mocks/darwin-hardware.js +++ b/test/mocks/darwin-hardware.js @@ -196,14 +196,8 @@ var serialPort = SandboxedModule.require('../../serialport', { fs: { read: hardware.fakeRead.bind(hardware) }, - 'node-pre-gyp': { - find: function() { - // this one is silly - we don't want it to find the binary - // so we say hey! it's this already mocked require! - // if it found the binary it would be loaded in a sandbox - // and wouldn't be able to be loaded in a regular context - return 'mock-binding'; - } + 'bindings': function() { + return hardware.mockBinding; }, 'mock-binding': hardware.mockBinding },