don't shim shims and update node-libs
This commit is contained in:
parent
d2a5464e0d
commit
8da6f6c81a
|
@ -34,6 +34,14 @@ NodeSourcePlugin.prototype.apply = function(compiler) {
|
|||
return "require(" + JSON.stringify(moduleJsPath) + ")";
|
||||
}
|
||||
|
||||
function addExpression(parser, name, module, type, suffix) {
|
||||
suffix = suffix || "";
|
||||
parser.plugin("expression " + name, function() {
|
||||
if(this.state.module && this.state.module.resource === getPathToModule(module, type)) return;
|
||||
return ModuleParserHelpers.addParsedVariable(this, name, buildExpression(this.state.module.context, getPathToModule(module, type)) + suffix);
|
||||
});
|
||||
}
|
||||
|
||||
compiler.plugin("compilation", function(compilation, params) {
|
||||
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
|
||||
|
||||
|
@ -44,37 +52,27 @@ NodeSourcePlugin.prototype.apply = function(compiler) {
|
|||
if(parserOptions.node)
|
||||
localOptions = objectAssign({}, localOptions, parserOptions.node);
|
||||
|
||||
if(localOptions.process) {
|
||||
var processType = localOptions.process;
|
||||
parser.plugin("expression process", function() {
|
||||
return ModuleParserHelpers.addParsedVariable(this, "process", buildExpression(this.state.module.context, getPathToModule("process", processType)));
|
||||
});
|
||||
}
|
||||
if(localOptions.global) {
|
||||
parser.plugin("expression global", function() {
|
||||
return ModuleParserHelpers.addParsedVariable(this, "global", buildExpression(this.state.module.context, require.resolve("../../buildin/global.js")));
|
||||
});
|
||||
}
|
||||
if(localOptions.process) {
|
||||
var processType = localOptions.process;
|
||||
addExpression(parser, "process", "process", processType);
|
||||
}
|
||||
if(localOptions.console) {
|
||||
var consoleType = localOptions.console;
|
||||
parser.plugin("expression console", function() {
|
||||
return ModuleParserHelpers.addParsedVariable(this, "console", buildExpression(this.state.module.context, getPathToModule("console", consoleType)));
|
||||
});
|
||||
addExpression(parser, "console", "console", consoleType);
|
||||
}
|
||||
var bufferType = localOptions.Buffer;
|
||||
if(bufferType) {
|
||||
parser.plugin("expression Buffer", function() {
|
||||
return ModuleParserHelpers.addParsedVariable(this, "Buffer", buildExpression(this.state.module.context, getPathToModule("buffer", bufferType)) + ".Buffer");
|
||||
});
|
||||
addExpression(parser, "Buffer", "buffer", bufferType, ".Buffer");
|
||||
}
|
||||
if(localOptions.setImmediate) {
|
||||
var setImmediateType = localOptions.setImmediate;
|
||||
parser.plugin("expression setImmediate", function() {
|
||||
return ModuleParserHelpers.addParsedVariable(this, "setImmediate", buildExpression(this.state.module.context, getPathToModule("timers", setImmediateType)) + ".setImmediate");
|
||||
});
|
||||
parser.plugin("expression clearImmediate", function() {
|
||||
return ModuleParserHelpers.addParsedVariable(this, "clearImmediate", buildExpression(this.state.module.context, getPathToModule("timers", setImmediateType)) + ".clearImmediate");
|
||||
});
|
||||
addExpression(parser, "setImmediate", "timers", setImmediateType, ".setImmediate");
|
||||
addExpression(parser, "clearImmediate", "timers", setImmediateType, ".clearImmediate");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"loader-utils": "^0.2.16",
|
||||
"memory-fs": "~0.3.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"node-libs-browser": "^1.0.0",
|
||||
"node-libs-browser": "^2.0.0",
|
||||
"object-assign": "^4.0.1",
|
||||
"source-map": "^0.5.3",
|
||||
"supports-color": "^3.1.0",
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
require("should");
|
||||
|
||||
// shimming global window object so the http-module is happy.
|
||||
// window is assigned without var on purpose.
|
||||
window = {
|
||||
XMLHttpRequest: function() {}
|
||||
};
|
||||
// shimming global XMLHttpRequest object so the http-module is happy.
|
||||
global.XMLHttpRequest = function() {};
|
||||
global.XMLHttpRequest.prototype.open = function() {};
|
||||
|
||||
it("should provide a global Buffer constructor", function() {
|
||||
Buffer.should.be.a.Function;
|
||||
|
|
Loading…
Reference in New Issue