Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses Object.isExtensible() to identify if require is extensible #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -2,16 +2,19 @@ var mod = require('module');

var __get__ = require("rewire/lib/__get__").toString();
var __set__ = require("rewire/lib/__set__").toString();
var __with__ = require("rewire/lib/__with__").toString();

var exportGet = "Object.defineProperty(module.exports, '__get__', { value: " + __get__ + ", writable: true });\n";
var exportSet = "Object.defineProperty(module.exports, '__set__', { value: " + __set__ + ", writable: true });\n";
var exportWith = "Object.defineProperty(module.exports, '__with__', { value: " + __with__ + ", writable: true });\n";

var initalEnd = mod.wrapper[1];

var embed = "\nif (typeof(module.exports) === 'object' || typeof(module.exports) === 'function') {\n" +
var embed = "\nif (Object.isExtensible(module.exports)) {\n" +
exportGet +
exportSet +
'}';
exportWith +
'}';

var GlobalRewire = {
enable: function() {
Expand Down
3 changes: 2 additions & 1 deletion test/tests/tests.js
Expand Up @@ -48,10 +48,11 @@ describe('global-rewire', function() {
assert.isUndefined(bool.__set__);
});

it('should not make __get__ and __set__ enumerable', function() {
it('should not make __get__ and __set__ and __with__ enumerable', function() {
var keys = require('../fixtures/keys');
assert.notInclude(Object.keys(keys), '__get__');
assert.notInclude(Object.keys(keys), '__set__');
assert.notInclude(Object.keys(keys), '__with__');
});

it('should attach to files without semicolons', function() {
Expand Down