From a71d97cbe5c765b4ff0755396a6f5c7490ad8969 Mon Sep 17 00:00:00 2001 From: Jake Murzy Date: Mon, 14 Aug 2017 16:06:53 -0700 Subject: [PATCH] fix issue with re-require()'ing native modules Discussion on why this change was required can be found in the following issues: https://github.com/facebook/jest/issues/3552 https://github.com/facebook/jest/issues/3550 https://github.com/nodejs/node/issues/5016 --- generate/templates/templates/nodegit.js | 7 +++++++ lib/revwalk.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/generate/templates/templates/nodegit.js b/generate/templates/templates/nodegit.js index 246f5b26b..15b8f322c 100644 --- a/generate/templates/templates/nodegit.js +++ b/generate/templates/templates/nodegit.js @@ -1,3 +1,4 @@ +var _ = require("lodash"); var promisify = require("promisify-node"); var rawApi; @@ -15,6 +16,12 @@ catch (ex) { rawApi = require("../build/Debug/nodegit.node"); } +// For disccussion on why `cloneDeep` is required, see: +// https://github.com/facebook/jest/issues/3552 +// https://github.com/facebook/jest/issues/3550 +// https://github.com/nodejs/node/issues/5016 +rawApi = _.cloneDeep(rawApi); + // Native methods do not return an identifiable function, so we // have to override them here /* jshint ignore:start */ diff --git a/lib/revwalk.js b/lib/revwalk.js index 80205fb22..5dcc7d058 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -2,7 +2,8 @@ var NodeGit = require("../"); var Revwalk = NodeGit.Revwalk; Object.defineProperty(Revwalk.prototype, "repo", { - get: function () { return this.repository(); } + get: function () { return this.repository(); }, + configurable: true }); var _sorting = Revwalk.prototype.sorting;