Skip to content

Commit 910cc13

Browse files
committed
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 brianc#398
1 parent 343caef commit 910cc13

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/types/binaryParsers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
var ref = require('ref');
2-
var endian = (ref.endianness === 'LE') ? 'BE' : 'LE';
1+
try {
2+
var ref = require('ref');
3+
var endian = (ref.endianness === 'LE') ? 'BE' : 'LE';
4+
} catch(e) {
5+
}
36

47
var parseBits = function(data, bits, offset, invert, callback) {
58
offset = offset || 0;
@@ -109,6 +112,9 @@ var parseInt32 = function(value) {
109112
};
110113

111114
var parseInt64 = function(value) {
115+
if(typeof ref == 'undefined') {
116+
throw new Error("the ref module is not installed. npm install ref to use the binary parser on bigints");
117+
}
112118
return String(ref['readInt64' + endian](value, 0));
113119
};
114120

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
"main": "./lib",
2020
"dependencies": {
2121
"generic-pool": "2.0.3",
22-
"buffer-writer": "1.0.0",
23-
"ref": "0.1.3"
22+
"buffer-writer": "1.0.0"
2423
},
2524
"devDependencies": {
2625
"jshint": "1.1.0",
2726
"semver": "~1.1.4"
2827
},
28+
"optionalDependencies": {
29+
"ref": "0.1.3"
30+
},
2931
"scripts": {
3032
"test": "make test-travis connectionString=postgres://postgres@localhost:5432/postgres",
3133
"install": "node-gyp rebuild || (exit 0)"

0 commit comments

Comments
 (0)