Skip to content

Commit

Permalink
Merge pull request #953 from stealjs/export-node
Browse files Browse the repository at this point in the history
Allow global exports to run in Node
  • Loading branch information
matthewp committed Mar 7, 2018
2 parents 9cb698a + 0f5a904 commit dd10ef3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundle/add_global_shim.js
Expand Up @@ -13,7 +13,7 @@ module.exports = function(bundle, options){
var shimEval = fs.readFileSync(path.join(__dirname, "shim-eval.js"));

// target global variable, self (Web Workers) or window
var g = `typeof self == "object" && self.Object == Object ? self : window`;
var g = `typeof self == "object" && self.Object == Object ? self : (typeof process === "object" && Object.prototype.toString.call(process) === "[object process]") ? global : window`;

var source = prettier.format(
`(${shim.toString()})(
Expand Down
28 changes: 28 additions & 0 deletions test/export_standalone_test.js
Expand Up @@ -62,4 +62,32 @@ describe("+standalone", function(){
}, done);
});
});

it("Can be used for node.js projects", function(done){
this.timeout(10000);

var outPath = __dirname + "/exports_basics/out.js";

stealExport({
steal: {
config: __dirname + "/exports_basics/package.json!npm"
},
options: { quiet: true },
outputs: {
"+standalone": {
exports: { "foo": "FOO.foo" },
dest: function(){
return outPath;
}
}
}
})
.then(function(){
require(outPath);
assert.ok(true, "Was able to require the created module");
done();
})
.catch(done);

});
});

0 comments on commit dd10ef3

Please sign in to comment.