From 1ddbba45fc127c33008fce8bd4bfcf0a9d5f0c80 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 246f5b26b9..15b8f322c8 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 80205fb222..5dcc7d0589 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;