From 910cc134c9e8a454586773343eb6edb26a4704dd Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Tue, 23 Jul 2013 10:10:41 -0500 Subject: [PATCH] Make ref an optional dependency The ref module adds a compile step even when using the pure-JavaScript client. This makes the installation optional so if the install fails due to not having a compiler around you can still use the JavaScript client. closes #398 --- lib/types/binaryParsers.js | 10 ++++++++-- package.json | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/types/binaryParsers.js b/lib/types/binaryParsers.js index 7d3319e..32837ca 100644 --- a/lib/types/binaryParsers.js +++ b/lib/types/binaryParsers.js @@ -1,5 +1,8 @@ -var ref = require('ref'); -var endian = (ref.endianness === 'LE') ? 'BE' : 'LE'; +try { + var ref = require('ref'); + var endian = (ref.endianness === 'LE') ? 'BE' : 'LE'; +} catch(e) { +} var parseBits = function(data, bits, offset, invert, callback) { offset = offset || 0; @@ -109,6 +112,9 @@ var parseInt32 = function(value) { }; var parseInt64 = function(value) { + if(typeof ref == 'undefined') { + throw new Error("the ref module is not installed. npm install ref to use the binary parser on bigints"); + } return String(ref['readInt64' + endian](value, 0)); }; diff --git a/package.json b/package.json index 00878b6..7de5fa8 100644 --- a/package.json +++ b/package.json @@ -19,13 +19,15 @@ "main": "./lib", "dependencies": { "generic-pool": "2.0.3", - "buffer-writer": "1.0.0", - "ref": "0.1.3" + "buffer-writer": "1.0.0" }, "devDependencies": { "jshint": "1.1.0", "semver": "~1.1.4" }, + "optionalDependencies": { + "ref": "0.1.3" + }, "scripts": { "test": "make test-travis connectionString=postgres://postgres@localhost:5432/postgres", "install": "node-gyp rebuild || (exit 0)"