Skip to content

Commit fe82aeb

Browse files
committed
Fix #91
1 parent 3f7798d commit fe82aeb

File tree

5 files changed

+64
-21
lines changed

5 files changed

+64
-21
lines changed

package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-eventstore-client",
3-
"version": "0.2.13",
3+
"version": "0.2.14",
44
"description": "A port of the EventStore .Net ClientAPI to Node.js",
55
"main": "index.js",
66
"types": "index.d.ts",
@@ -9,13 +9,13 @@
99
},
1010
"engineStrict": true,
1111
"scripts": {
12-
"clean": "rm lib/dist.js",
12+
"clean": "rm -f lib/dist.js",
1313
"prebuild": "npm run clean",
14-
"build": "webpack",
14+
"build": "webpack -o ./lib/dist.js",
1515
"pretest": "npm run build",
1616
"test": "nodeunit",
1717
"test-debug": "TESTS_VERBOSE_LOGGING=1 nodeunit",
18-
"prepublish": "npm run build && npm run gendocs",
18+
"prepublishOnly": "npm run build && npm run gendocs",
1919
"gendocs": "rm -rf docs && jsdoc src -r -d docs"
2020
},
2121
"files": [

src/messages/messages.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
22
(function(global, factory) { /* global define, require, module */
33

4-
/* AMD */ if (typeof define === 'function' && define.amd)
5-
define(["protobufjs/minimal"], factory);
4+
/* CommonJS */if (typeof require === 'function' && typeof module === 'object' && module && module.exports)
5+
module.exports = factory(require("protobufjs/minimal"), require("../utils/modules"));
66

7-
/* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports)
8-
module.exports = factory(require("protobufjs/minimal"));
9-
10-
})(this, function($protobuf) {
7+
})(this, function($protobuf, $moduleUtil) {
118
"use strict";
129

10+
// This fixes bug #91 by giving us an isolate copy of protobufjs library so any tampering with it doesn't affect us
11+
var old = $moduleUtil.uncache(require.resolve('protobufjs/minimal'));
12+
$protobuf = require('protobufjs/minimal');
13+
$moduleUtil.recache(old);
14+
1315
// Common aliases
1416
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
1517

src/utils/modules.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports.uncache = function uncache(id) {
2+
var mod = require.cache[id];
3+
if (!mod) return;
4+
delete require.cache[id];
5+
if (mod.children)
6+
for(var i = 0; i < mod.children.length; i++)
7+
uncache(mod.children[i].id);
8+
return mod;
9+
};
10+
11+
exports.recache = function recache(mod) {
12+
if (require.cache[mod.id] === mod) return;
13+
require.cache[mod.id] = mod;
14+
if (mod.children)
15+
for(var i = 0; i < mod.children.length; i++)
16+
recache(mod.children[i]);
17+
};

test/common/base_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ var client = require('../../lib/dist');
55
var FileLogger = require('../../src/common/log/fileLogger');
66
var NoopLogger = require('../../src/common/log/noopLogger');
77

8+
// Make sure we mess with protobufjs setup for bug #91
9+
var protobufJS = require('protobufjs');
10+
protobufJS.util.Long = undefined;
11+
protobufJS.configure();
12+
813
var settings = {
914
log: new NoopLogger()
1015
};

0 commit comments

Comments
 (0)