From 49c7888717f37b13e27333e0093e8d035b7c85bb Mon Sep 17 00:00:00 2001 From: Stephen Hebson Date: Fri, 14 Aug 2015 13:40:55 -0400 Subject: [PATCH] Only add __set__ and __get__ methods if module.exports is an extensible object --- lib/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/index.js b/lib/index.js index c5bcb68..626d0f3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,8 +33,10 @@ module.exports = function rewireify(file, options) { function end() { post += "/* This code was injected by Rewireify */\n"; + post += "if (typeof module.exports === 'object' && Object.isExtensible(module.exports)) {\n"; post += "Object.defineProperty(module.exports, '__get__', { value: " + __get__ + ", writable: true });\n"; post += "Object.defineProperty(module.exports, '__set__', { value: " + __set__ + ", writable: true });\n"; + post += "}\n"; this.queue(data); this.queue(post);