mirror of https://github.com/webpack/webpack.git
Merge branch 'master' into extract-to-parser-helpers-extended
This commit is contained in:
commit
41e689a47e
|
|
@ -32,6 +32,7 @@ matrix:
|
|||
env: NO_WATCH_TESTS=1 JOB_PART=test
|
||||
allow_failures:
|
||||
- os: osx
|
||||
- env: NO_WATCH_TESTS=1 JOB_PART=benchmark
|
||||
fast_finish: true
|
||||
|
||||
before_script:
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
require(["./a"]);
|
||||
require(["./a", "./b"]);
|
||||
require(["./a", "./b", "./c"]);
|
||||
require(["./a", "./b", "./c", "./d"]);
|
||||
|
|
@ -0,0 +1 @@
|
|||
require(["./a"]);
|
||||
|
|
@ -0,0 +1 @@
|
|||
require(["./a", "./b"]);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
require(["./a", "./b", "./c"]);
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
require(["./a", "./b", "./c", "./d"]);
|
||||
|
|
@ -2,10 +2,10 @@ var path = require("path");
|
|||
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
|
||||
module.exports = {
|
||||
entry: {
|
||||
pageA: "./page?A",
|
||||
pageB: "./page?B",
|
||||
pageC: "./page?C",
|
||||
pageD: "./page?D"
|
||||
pageA: "./pageA",
|
||||
pageB: "./pageB",
|
||||
pageC: "./pageC",
|
||||
pageD: "./pageD"
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
chunkFilename: "[id].chunk.js"
|
||||
},
|
||||
plugins: [
|
||||
// check for common modules in children of pageA and move them to the parent
|
||||
//check for common modules in children of pageA and move them to the parent
|
||||
new CommonsChunkPlugin({
|
||||
name: "pageA",
|
||||
children: true
|
||||
|
|
@ -32,7 +32,7 @@ module.exports = {
|
|||
children: true,
|
||||
minChunks: function(module, count) {
|
||||
// move only module "b"
|
||||
return /b\.js$/.test(module.identifier());
|
||||
return !/b\.js$/.test(module.identifier());
|
||||
}
|
||||
})
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,61 +2,52 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var DependenciesBlock = require("./DependenciesBlock");
|
||||
"use strict";
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
|
||||
function AsyncDependenciesBlock(name, module, loc) {
|
||||
DependenciesBlock.call(this);
|
||||
this.chunkName = name;
|
||||
this.chunks = null;
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
|
||||
Object.defineProperty(this, "chunk", {
|
||||
get: function() {
|
||||
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
|
||||
},
|
||||
set: function() {
|
||||
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
module.exports = AsyncDependenciesBlock;
|
||||
|
||||
AsyncDependenciesBlock.prototype = Object.create(DependenciesBlock.prototype);
|
||||
AsyncDependenciesBlock.prototype.constructor = AsyncDependenciesBlock;
|
||||
|
||||
AsyncDependenciesBlock.prototype.updateHash = function updateHash(hash) {
|
||||
hash.update(this.chunkName || "");
|
||||
hash.update(this.chunks && this.chunks.map(function(chunk) {
|
||||
return typeof chunk.id === "number" ? chunk.id : "";
|
||||
}).join(",") || "");
|
||||
DependenciesBlock.prototype.updateHash.call(this, hash);
|
||||
};
|
||||
|
||||
AsyncDependenciesBlock.prototype.disconnect = function() {
|
||||
this.chunks = null;
|
||||
DependenciesBlock.prototype.disconnect.call(this);
|
||||
};
|
||||
|
||||
AsyncDependenciesBlock.prototype.unseal = function() {
|
||||
this.chunks = null;
|
||||
DependenciesBlock.prototype.unseal.call(this);
|
||||
};
|
||||
|
||||
AsyncDependenciesBlock.prototype.sortItems = function() {
|
||||
DependenciesBlock.prototype.sortItems.call(this);
|
||||
if(this.chunks) {
|
||||
this.chunks.sort(function(a, b) {
|
||||
var i = 0;
|
||||
while(true) { // eslint-disable-line no-constant-condition
|
||||
if(!a.modules[i] && !b.modules[i]) return 0;
|
||||
if(!a.modules[i]) return -1;
|
||||
if(!b.modules[i]) return 1;
|
||||
if(a.modules[i].id > b.modules[i].id) return 1;
|
||||
if(a.modules[i].id < b.modules[i].id) return -1;
|
||||
i++;
|
||||
}
|
||||
});
|
||||
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
|
||||
constructor(name, module, loc) {
|
||||
super();
|
||||
this.chunkName = name;
|
||||
this.chunks = null;
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
}
|
||||
};
|
||||
get chunk() {
|
||||
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
|
||||
}
|
||||
set chunk(chunk) {
|
||||
throw new Error("`chunk` was been renamed to `chunks` and is now an array");
|
||||
}
|
||||
updateHash(hash) {
|
||||
hash.update(this.chunkName || "");
|
||||
hash.update(this.chunks && this.chunks.map((chunk) => {
|
||||
return typeof chunk.id === "number" ? chunk.id : "";
|
||||
}).join(",") || "");
|
||||
super.updateHash(hash);
|
||||
}
|
||||
disconnect() {
|
||||
this.chunks = null;
|
||||
super.disconnect();
|
||||
}
|
||||
unseal() {
|
||||
this.chunks = null;
|
||||
super.unseal();
|
||||
}
|
||||
sortItems() {
|
||||
super.sortItems();
|
||||
if(this.chunks) {
|
||||
this.chunks.sort((a, b) => {
|
||||
let i = 0;
|
||||
while(true) { // eslint-disable-line no-constant-condition
|
||||
if(!a.modules[i] && !b.modules[i]) return 0;
|
||||
if(!a.modules[i]) return -1;
|
||||
if(!b.modules[i]) return 1;
|
||||
if(a.modules[i].id > b.modules[i].id) return 1;
|
||||
if(a.modules[i].id < b.modules[i].id) return -1;
|
||||
i++;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,19 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
function LoaderTargetPlugin(target) {
|
||||
this.target = target;
|
||||
}
|
||||
module.exports = LoaderTargetPlugin;
|
||||
LoaderTargetPlugin.prototype.apply = function(compiler) {
|
||||
var target = this.target;
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.plugin("normal-module-loader", function(loaderContext) {
|
||||
loaderContext.target = target;
|
||||
"use strict";
|
||||
|
||||
class LoaderTargetPlugin {
|
||||
constructor(target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
let target = this.target;
|
||||
compiler.plugin("compilation", (compilation) => {
|
||||
compilation.plugin("normal-module-loader", (loaderContext) => loaderContext.target = target);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LoaderTargetPlugin;
|
||||
|
|
|
|||
|
|
@ -2,55 +2,57 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var path = require("path");
|
||||
"use strict";
|
||||
|
||||
function RequestShortener(directory) {
|
||||
directory = directory.replace(/\\/g, "/");
|
||||
var parentDirectory = path.dirname(directory);
|
||||
if(/[\/\\]$/.test(directory)) directory = directory.substr(0, directory.length - 1);
|
||||
if(directory) {
|
||||
var currentDirectoryRegExp = directory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
currentDirectoryRegExp = new RegExp("^" + currentDirectoryRegExp + "|(!)" + currentDirectoryRegExp, "g");
|
||||
const path = require("path");
|
||||
|
||||
this.currentDirectoryRegExp = currentDirectoryRegExp;
|
||||
class RequestShortener {
|
||||
constructor(directory) {
|
||||
directory = directory.replace(/\\/g, "/");
|
||||
let parentDirectory = path.dirname(directory);
|
||||
if(/[\/\\]$/.test(directory)) directory = directory.substr(0, directory.length - 1);
|
||||
|
||||
if(directory) {
|
||||
let currentDirectoryRegExp = directory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
currentDirectoryRegExp = new RegExp("^" + currentDirectoryRegExp + "|(!)" + currentDirectoryRegExp, "g");
|
||||
this.currentDirectoryRegExp = currentDirectoryRegExp;
|
||||
}
|
||||
|
||||
if(/[\/\\]$/.test(parentDirectory)) parentDirectory = parentDirectory.substr(0, parentDirectory.length - 1);
|
||||
if(parentDirectory && parentDirectory !== directory) {
|
||||
let parentDirectoryRegExp = parentDirectory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
parentDirectoryRegExp = new RegExp("^" + parentDirectoryRegExp + "|(!)" + parentDirectoryRegExp, "g");
|
||||
this.parentDirectoryRegExp = parentDirectoryRegExp;
|
||||
}
|
||||
|
||||
if(__dirname.length >= 2) {
|
||||
let buildins = path.join(__dirname, "..").replace(/\\/g, "/");
|
||||
let buildinsAsModule = this.currentDirectoryRegExp && this.currentDirectoryRegExp.test(buildins);
|
||||
let buildinsRegExp = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
buildinsRegExp = new RegExp("^" + buildinsRegExp + "|(!)" + buildinsRegExp, "g");
|
||||
this.buildinsAsModule = buildinsAsModule;
|
||||
this.buildinsRegExp = buildinsRegExp;
|
||||
}
|
||||
|
||||
this.nodeModulesRegExp = /\/node_modules\//g;
|
||||
this.indexJsRegExp = /\/index.js(!|\?|\(query\))/g;
|
||||
}
|
||||
|
||||
if(/[\/\\]$/.test(parentDirectory)) parentDirectory = parentDirectory.substr(0, parentDirectory.length - 1);
|
||||
if(parentDirectory && parentDirectory !== directory) {
|
||||
var parentDirectoryRegExp = parentDirectory.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
parentDirectoryRegExp = new RegExp("^" + parentDirectoryRegExp + "|(!)" + parentDirectoryRegExp, "g");
|
||||
|
||||
this.parentDirectoryRegExp = parentDirectoryRegExp;
|
||||
shorten(request) {
|
||||
if(!request) return request;
|
||||
request = request.replace(/\\/g, "/");
|
||||
if(this.buildinsAsModule && this.buildinsRegExp)
|
||||
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
||||
if(this.currentDirectoryRegExp)
|
||||
request = request.replace(this.currentDirectoryRegExp, "!.");
|
||||
if(this.parentDirectoryRegExp)
|
||||
request = request.replace(this.parentDirectoryRegExp, "!..");
|
||||
if(!this.buildinsAsModule && this.buildinsRegExp)
|
||||
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
||||
request = request.replace(this.nodeModulesRegExp, "/~/");
|
||||
request = request.replace(this.indexJsRegExp, "$1");
|
||||
return request.replace(/^!|!$/, "");
|
||||
}
|
||||
|
||||
if(__dirname.length >= 2) {
|
||||
var buildins = path.join(__dirname, "..").replace(/\\/g, "/");
|
||||
var buildinsAsModule = currentDirectoryRegExp && currentDirectoryRegExp.test(buildins);
|
||||
var buildinsRegExp = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
buildinsRegExp = new RegExp("^" + buildinsRegExp + "|(!)" + buildinsRegExp, "g");
|
||||
|
||||
this.buildinsAsModule = buildinsAsModule;
|
||||
this.buildinsRegExp = buildinsRegExp;
|
||||
}
|
||||
|
||||
this.nodeModulesRegExp = /\/node_modules\//g;
|
||||
this.indexJsRegExp = /\/index.js(!|\?|\(query\))/g;
|
||||
}
|
||||
module.exports = RequestShortener;
|
||||
|
||||
RequestShortener.prototype.shorten = function(request) {
|
||||
if(!request)
|
||||
return request;
|
||||
request = request.replace(/\\/g, "/");
|
||||
if(this.buildinsAsModule && this.buildinsRegExp)
|
||||
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
||||
if(this.currentDirectoryRegExp)
|
||||
request = request.replace(this.currentDirectoryRegExp, "!.");
|
||||
if(this.parentDirectoryRegExp)
|
||||
request = request.replace(this.parentDirectoryRegExp, "!..");
|
||||
if(!this.buildinsAsModule && this.buildinsRegExp)
|
||||
request = request.replace(this.buildinsRegExp, "!(webpack)");
|
||||
request = request.replace(this.nodeModulesRegExp, "/~/");
|
||||
request = request.replace(this.indexJsRegExp, "$1");
|
||||
return request.replace(/^!|!$/, "");
|
||||
};
|
||||
module.exports = RequestShortener;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
module.exports = function compareLocations(a, b) {
|
||||
if(typeof a === "string") {
|
||||
if(typeof b === "string") {
|
||||
|
|
@ -17,14 +18,14 @@ module.exports = function compareLocations(a, b) {
|
|||
if(typeof b === "string") {
|
||||
return -1;
|
||||
} else if(typeof b === "object") {
|
||||
var aa = a.start ? a.start : a;
|
||||
var bb = b.start ? b.start : b;
|
||||
if(aa.line < bb.line) return -1;
|
||||
if(aa.line > bb.line) return 1;
|
||||
if(aa.column < bb.column) return -1;
|
||||
if(aa.column > bb.column) return 1;
|
||||
if(aa.index < bb.index) return -1;
|
||||
if(aa.index > bb.index) return 1;
|
||||
if(a.start && b.start) {
|
||||
const ap = a.start;
|
||||
const bp = b.start;
|
||||
if(ap.line < bp.line) return -1;
|
||||
if(ap.line > bp.line) return 1;
|
||||
if(ap.column < bp.column) return -1;
|
||||
if(ap.column > bp.column) return 1;
|
||||
}
|
||||
if(a.index < b.index) return -1;
|
||||
if(a.index > b.index) return 1;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -2,85 +2,89 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var CommonJsRequireDependency = require("./CommonJsRequireDependency");
|
||||
var CommonJsRequireContextDependency = require("./CommonJsRequireContextDependency");
|
||||
var RequireHeaderDependency = require("./RequireHeaderDependency");
|
||||
var LocalModuleDependency = require("./LocalModuleDependency");
|
||||
var ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
||||
var LocalModulesHelpers = require("./LocalModulesHelpers");
|
||||
var ParserHelpers = require("../ParserHelpers");
|
||||
"use strict";
|
||||
|
||||
function CommonJsRequireDependencyParserPlugin(options) {
|
||||
this.options = options;
|
||||
}
|
||||
const ConstDependency = require("./ConstDependency");
|
||||
const CommonJsRequireDependency = require("./CommonJsRequireDependency");
|
||||
const CommonJsRequireContextDependency = require("./CommonJsRequireContextDependency");
|
||||
const RequireHeaderDependency = require("./RequireHeaderDependency");
|
||||
const LocalModuleDependency = require("./LocalModuleDependency");
|
||||
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
||||
const LocalModulesHelpers = require("./LocalModulesHelpers");
|
||||
const ParserHelpers = require("../ParserHelpers");
|
||||
|
||||
module.exports = CommonJsRequireDependencyParserPlugin;
|
||||
class CommonJsRequireDependencyParserPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
|
||||
var options = this.options;
|
||||
parser.plugin("expression require.cache", ParserHelpers.toConstantDependency("__webpack_require__.c"));
|
||||
parser.plugin("expression require", function(expr) {
|
||||
var dep = new CommonJsRequireContextDependency(options.unknownContextRequest, options.unknownContextRecursive, options.unknownContextRegExp, expr.range);
|
||||
dep.critical = options.unknownContextCritical && "require function is used in a way in which dependencies cannot be statically extracted";
|
||||
dep.loc = expr.loc;
|
||||
dep.optional = !!this.scope.inTry;
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
parser.plugin("call require", function(expr) {
|
||||
if(expr.arguments.length !== 1) return;
|
||||
var localModule, dep;
|
||||
var param = this.evaluateExpression(expr.arguments[0]);
|
||||
if(param.isConditional()) {
|
||||
var isExpression = false;
|
||||
var prevLength = this.state.current.dependencies.length;
|
||||
dep = new RequireHeaderDependency(expr.callee.range);
|
||||
apply(parser) {
|
||||
const options = this.options;
|
||||
parser.plugin("expression require.cache", ParserHelpers.toConstantDependency("__webpack_require__.c"));
|
||||
parser.plugin("expression require", (expr) => {
|
||||
const dep = new CommonJsRequireContextDependency(options.unknownContextRequest, options.unknownContextRecursive, options.unknownContextRegExp, expr.range);
|
||||
dep.critical = options.unknownContextCritical && "require function is used in a way in which dependencies cannot be statically extracted";
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
param.options.forEach(function(param) {
|
||||
var result = this.applyPluginsBailResult("call require:commonjs:item", expr, param);
|
||||
if(result === undefined) {
|
||||
isExpression = true;
|
||||
}
|
||||
}, this);
|
||||
if(isExpression) {
|
||||
this.state.current.dependencies.length = prevLength;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
|
||||
dep = new LocalModuleDependency(localModule, expr.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
dep.optional = !!parser.scope.inTry;
|
||||
parser.state.current.addDependency(dep);
|
||||
return true;
|
||||
} else {
|
||||
var result = this.applyPluginsBailResult("call require:commonjs:item", expr, param);
|
||||
if(result === undefined) {
|
||||
this.applyPluginsBailResult("call require:commonjs:context", expr, param);
|
||||
} else {
|
||||
});
|
||||
parser.plugin("call require", (expr) => {
|
||||
if(expr.arguments.length !== 1) return;
|
||||
let localModule, dep;
|
||||
const param = parser.evaluateExpression(expr.arguments[0]);
|
||||
if(param.isConditional()) {
|
||||
let isExpression = false;
|
||||
const prevLength = parser.state.current.dependencies.length;
|
||||
dep = new RequireHeaderDependency(expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
parser.state.current.addDependency(dep);
|
||||
param.options.forEach(function(param) {
|
||||
const result = parser.applyPluginsBailResult("call require:commonjs:item", expr, param);
|
||||
if(result === undefined) {
|
||||
isExpression = true;
|
||||
}
|
||||
});
|
||||
if(isExpression) {
|
||||
parser.state.current.dependencies.length = prevLength;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
parser.plugin("call require:commonjs:item", function(expr, param) {
|
||||
if(param.isString()) {
|
||||
var dep = new CommonJsRequireDependency(param.string, param.range);
|
||||
if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(parser.state, param.string))) {
|
||||
dep = new LocalModuleDependency(localModule, expr.range);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.current.addDependency(dep);
|
||||
return true;
|
||||
} else {
|
||||
const result = parser.applyPluginsBailResult("call require:commonjs:item", expr, param);
|
||||
if(result === undefined) {
|
||||
parser.applyPluginsBailResult("call require:commonjs:context", expr, param);
|
||||
} else {
|
||||
dep = new RequireHeaderDependency(expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.current.addDependency(dep);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
parser.plugin("call require:commonjs:item", (expr, param) => {
|
||||
if(param.isString()) {
|
||||
const dep = new CommonJsRequireDependency(param.string, param.range);
|
||||
dep.loc = expr.loc;
|
||||
dep.optional = !!parser.scope.inTry;
|
||||
parser.state.current.addDependency(dep);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
parser.plugin("call require:commonjs:context", (expr, param) => {
|
||||
const dep = ContextDependencyHelpers.create(CommonJsRequireContextDependency, expr.range, param, expr, options);
|
||||
if(!dep) return;
|
||||
dep.loc = expr.loc;
|
||||
dep.optional = !!this.scope.inTry;
|
||||
this.state.current.addDependency(dep);
|
||||
dep.optional = !!parser.scope.inTry;
|
||||
parser.state.current.addDependency(dep);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
parser.plugin("call require:commonjs:context", function(expr, param) {
|
||||
var dep = ContextDependencyHelpers.create(CommonJsRequireContextDependency, expr.range, param, expr, options);
|
||||
if(!dep) return;
|
||||
dep.loc = expr.loc;
|
||||
dep.optional = !!this.scope.inTry;
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = CommonJsRequireDependencyParserPlugin;
|
||||
|
|
|
|||
|
|
@ -2,27 +2,30 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
function ContextDependencyTemplateAsId() {}
|
||||
module.exports = ContextDependencyTemplateAsId;
|
||||
"use strict";
|
||||
|
||||
ContextDependencyTemplateAsId.prototype.apply = function(dep, source, outputOptions, requestShortener) {
|
||||
var comment = "";
|
||||
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(dep.request) + " */ ";
|
||||
if(dep.module && dep.module.dependencies && dep.module.dependencies.length > 0) {
|
||||
if(dep.valueRange) {
|
||||
if(Array.isArray(dep.replaces)) {
|
||||
for(var i = 0; i < dep.replaces.length; i++) {
|
||||
var rep = dep.replaces[i];
|
||||
source.replace(rep.range[0], rep.range[1] - 1, rep.value);
|
||||
class ContextDependencyTemplateAsId {
|
||||
|
||||
apply(dep, source, outputOptions, requestShortener) {
|
||||
let comment = "";
|
||||
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(dep.request) + " */ ";
|
||||
if(dep.module && dep.module.dependencies && dep.module.dependencies.length > 0) {
|
||||
if(dep.valueRange) {
|
||||
if(Array.isArray(dep.replaces)) {
|
||||
for(let i = 0; i < dep.replaces.length; i++) {
|
||||
const rep = dep.replaces[i];
|
||||
source.replace(rep.range[0], rep.range[1] - 1, rep.value);
|
||||
}
|
||||
}
|
||||
source.replace(dep.valueRange[1], dep.range[1] - 1, ")");
|
||||
source.replace(dep.range[0], dep.valueRange[0] - 1, "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ").resolve(" + (typeof dep.prepend === "string" ? JSON.stringify(dep.prepend) : "") + "");
|
||||
} else {
|
||||
source.replace(dep.range[0], dep.range[1] - 1, "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ").resolve");
|
||||
}
|
||||
source.replace(dep.valueRange[1], dep.range[1] - 1, ")");
|
||||
source.replace(dep.range[0], dep.valueRange[0] - 1, "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ").resolve(" + (typeof dep.prepend === "string" ? JSON.stringify(dep.prepend) : "") + "");
|
||||
} else {
|
||||
source.replace(dep.range[0], dep.range[1] - 1, "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ").resolve");
|
||||
const content = require("./WebpackMissingModule").module(dep.request);
|
||||
source.replace(dep.range[0], dep.range[1] - 1, content);
|
||||
}
|
||||
} else {
|
||||
var content = require("./WebpackMissingModule").module(dep.request);
|
||||
source.replace(dep.range[0], dep.range[1] - 1, content);
|
||||
}
|
||||
};
|
||||
}
|
||||
module.exports = ContextDependencyTemplateAsId;
|
||||
|
|
|
|||
|
|
@ -2,66 +2,68 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
var HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
||||
var HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
|
||||
var HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
|
||||
var HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
|
||||
var HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
||||
var HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
|
||||
var HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
|
||||
var HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
|
||||
"use strict";
|
||||
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
||||
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
||||
const HarmonyCompatiblilityDependency = require("./HarmonyCompatibilityDependency");
|
||||
const HarmonyExportHeaderDependency = require("./HarmonyExportHeaderDependency");
|
||||
const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
|
||||
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
||||
const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImportedSpecifierDependency");
|
||||
const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
|
||||
const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
|
||||
|
||||
var NullFactory = require("../NullFactory");
|
||||
const NullFactory = require("../NullFactory");
|
||||
|
||||
var HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
|
||||
var HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
|
||||
var HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
|
||||
const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
|
||||
const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
|
||||
const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
|
||||
|
||||
function HarmonyModulesPlugin() {}
|
||||
module.exports = HarmonyModulesPlugin;
|
||||
class HarmonyModulesPlugin {
|
||||
|
||||
HarmonyModulesPlugin.prototype.apply = function(compiler) {
|
||||
compiler.plugin("compilation", function(compilation, params) {
|
||||
var normalModuleFactory = params.normalModuleFactory;
|
||||
apply(compiler) {
|
||||
compiler.plugin("compilation", (compilation, params) => {
|
||||
const normalModuleFactory = params.normalModuleFactory;
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyImportDependency, normalModuleFactory);
|
||||
compilation.dependencyTemplates.set(HarmonyImportDependency, new HarmonyImportDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyImportDependency, normalModuleFactory);
|
||||
compilation.dependencyTemplates.set(HarmonyImportDependency, new HarmonyImportDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyImportSpecifierDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyImportSpecifierDependency, new HarmonyImportSpecifierDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyImportSpecifierDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyImportSpecifierDependency, new HarmonyImportSpecifierDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyCompatibilityDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyCompatibilityDependency, new HarmonyCompatibilityDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyCompatiblilityDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyCompatiblilityDependency, new HarmonyCompatiblilityDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyExportHeaderDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportHeaderDependency, new HarmonyExportHeaderDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyExportHeaderDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportHeaderDependency, new HarmonyExportHeaderDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyExportExpressionDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportExpressionDependency, new HarmonyExportExpressionDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyExportExpressionDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportExpressionDependency, new HarmonyExportExpressionDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyExportSpecifierDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportSpecifierDependency, new HarmonyExportSpecifierDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyExportSpecifierDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportSpecifierDependency, new HarmonyExportSpecifierDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyExportImportedSpecifierDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportImportedSpecifierDependency, new HarmonyExportImportedSpecifierDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyExportImportedSpecifierDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyExportImportedSpecifierDependency, new HarmonyExportImportedSpecifierDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyAcceptDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyAcceptDependency, new HarmonyAcceptDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyAcceptDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(HarmonyAcceptDependency, new HarmonyAcceptDependency.Template());
|
||||
|
||||
compilation.dependencyFactories.set(HarmonyAcceptImportDependency, normalModuleFactory);
|
||||
compilation.dependencyTemplates.set(HarmonyAcceptImportDependency, new HarmonyAcceptImportDependency.Template());
|
||||
compilation.dependencyFactories.set(HarmonyAcceptImportDependency, normalModuleFactory);
|
||||
compilation.dependencyTemplates.set(HarmonyAcceptImportDependency, new HarmonyAcceptImportDependency.Template());
|
||||
|
||||
params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
|
||||
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
||||
|
||||
if(typeof parserOptions.harmony !== "undefined" && !parserOptions.harmony)
|
||||
return;
|
||||
if(typeof parserOptions.harmony !== "undefined" && !parserOptions.harmony)
|
||||
return;
|
||||
|
||||
parser.apply(
|
||||
new HarmonyDetectionParserPlugin(),
|
||||
new HarmonyImportDependencyParserPlugin(),
|
||||
new HarmonyExportDependencyParserPlugin()
|
||||
);
|
||||
parser.apply(
|
||||
new HarmonyDetectionParserPlugin(),
|
||||
new HarmonyImportDependencyParserPlugin(),
|
||||
new HarmonyExportDependencyParserPlugin()
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
module.exports = HarmonyModulesPlugin;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Gajus Kuizinas @gajus
|
||||
*/
|
||||
var Ajv = require("ajv");
|
||||
var ajv = new Ajv({
|
||||
"use strict";
|
||||
|
||||
const Ajv = require("ajv");
|
||||
const ajv = new Ajv({
|
||||
errorDataPath: "configuration",
|
||||
allErrors: true,
|
||||
verbose: true
|
||||
|
|
@ -12,16 +14,16 @@ require("ajv-keywords")(ajv, ["instanceof"]);
|
|||
|
||||
function validateSchema(schema, options) {
|
||||
if(Array.isArray(options)) {
|
||||
var errors = options.map(validateObject.bind(this, schema));
|
||||
errors.forEach(function(list, idx) {
|
||||
const errors = options.map((options) => validateObject(schema, options));
|
||||
errors.forEach((list, idx) => {
|
||||
list.forEach(function applyPrefix(err) {
|
||||
err.dataPath = "[" + idx + "]" + err.dataPath;
|
||||
err.dataPath = `[${idx}]${err.dataPath}`;
|
||||
if(err.children) {
|
||||
err.children.forEach(applyPrefix);
|
||||
}
|
||||
});
|
||||
});
|
||||
return errors.reduce(function(arr, items) {
|
||||
return errors.reduce((arr, items) => {
|
||||
return arr.concat(items);
|
||||
}, []);
|
||||
} else {
|
||||
|
|
@ -30,22 +32,20 @@ function validateSchema(schema, options) {
|
|||
}
|
||||
|
||||
function validateObject(schema, options) {
|
||||
var validate = ajv.compile(schema);
|
||||
var valid = validate(options);
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = validate(options);
|
||||
return valid ? [] : filterErrors(validate.errors);
|
||||
}
|
||||
|
||||
function filterErrors(errors) {
|
||||
var newErrors = [];
|
||||
errors.forEach(function(err) {
|
||||
var dataPath = err.dataPath;
|
||||
var children = [];
|
||||
newErrors = newErrors.filter(function(oldError) {
|
||||
if(oldError.dataPath.indexOf(dataPath) >= 0) {
|
||||
let newErrors = [];
|
||||
errors.forEach((err) => {
|
||||
const dataPath = err.dataPath;
|
||||
let children = [];
|
||||
newErrors = newErrors.filter((oldError) => {
|
||||
if(oldError.dataPath.includes(dataPath)) {
|
||||
if(oldError.children) {
|
||||
oldError.children.forEach(function(child) {
|
||||
children.push(child);
|
||||
});
|
||||
children = children.concat(oldError.children.slice(0));
|
||||
}
|
||||
oldError.children = undefined;
|
||||
children.push(oldError);
|
||||
|
|
@ -58,7 +58,7 @@ function filterErrors(errors) {
|
|||
}
|
||||
newErrors.push(err);
|
||||
});
|
||||
//console.log(JSON.stringify(newErrors, 0, 2));
|
||||
|
||||
return newErrors;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,30 @@
|
|||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment");
|
||||
var ConcatSource = require("webpack-sources").ConcatSource;
|
||||
var AmdMainTemplatePlugin = require("../lib/AmdMainTemplatePlugin");
|
||||
"use strict";
|
||||
|
||||
describe("AmdMainTemplatePlugin", function() {
|
||||
var env;
|
||||
const should = require("should");
|
||||
const sinon = require("sinon");
|
||||
const TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment");
|
||||
const ConcatSource = require("webpack-sources").ConcatSource;
|
||||
const AmdMainTemplatePlugin = require("../lib/AmdMainTemplatePlugin");
|
||||
|
||||
var applyTemplatePluginWithOptions = function(Plugin, name) {
|
||||
var plugin = new Plugin(name);
|
||||
var templatePluginEnvironment = new TemplatePluginEnvironment();
|
||||
var environment = templatePluginEnvironment.getEnvironmentStub();
|
||||
describe("AmdMainTemplatePlugin", () => {
|
||||
let env;
|
||||
|
||||
const applyTemplatePluginWithOptions = function(Plugin, name) {
|
||||
const plugin = new Plugin(name);
|
||||
const templatePluginEnvironment = new TemplatePluginEnvironment();
|
||||
const environment = templatePluginEnvironment.getEnvironmentStub();
|
||||
environment.mainTemplate.applyPluginsWaterfall = () => "templateName";
|
||||
plugin.apply(environment);
|
||||
return templatePluginEnvironment
|
||||
return templatePluginEnvironment;
|
||||
};
|
||||
|
||||
var setupPluginAndGetEventBinding = function(name) {
|
||||
var templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, name);
|
||||
var eventBindings = templatePlugin.getEventBindings();
|
||||
const setupPluginAndGetEventBinding = function(name) {
|
||||
const templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, name);
|
||||
const eventBindings = templatePlugin.getEventBindings();
|
||||
return eventBindings[0];
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
env = {
|
||||
modulesListWithExternals: [{
|
||||
id: "module-1",
|
||||
|
|
@ -48,77 +50,67 @@ describe("AmdMainTemplatePlugin", function() {
|
|||
};
|
||||
});
|
||||
|
||||
it("has apply function", function() {
|
||||
(new AmdMainTemplatePlugin()).apply.should.be.a.Function();
|
||||
});
|
||||
it("has apply function", () => new AmdMainTemplatePlugin().apply.should.be.a.Function());
|
||||
|
||||
describe("when applied", function() {
|
||||
beforeEach(function() {
|
||||
env.templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, "foo");
|
||||
});
|
||||
describe("when applied", () => {
|
||||
beforeEach(() =>
|
||||
env.templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, "foo"));
|
||||
|
||||
describe("event handlers", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBindings = env.templatePlugin.getEventBindings();
|
||||
});
|
||||
describe("event handlers", () => {
|
||||
beforeEach(() => env.eventBindings = env.templatePlugin.getEventBindings());
|
||||
|
||||
it("binds one handlers", function() {
|
||||
env.eventBindings.length.should.be.exactly(1);
|
||||
});
|
||||
it("binds one handlers", () => env.eventBindings.length.should.be.exactly(1));
|
||||
|
||||
describe("render-with-entry handler", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBinding = env.eventBindings[0];
|
||||
});
|
||||
describe("render-with-entry handler", () => {
|
||||
beforeEach(() => env.eventBinding = env.eventBindings[0]);
|
||||
|
||||
it("binds to render-with-entry event", function() {
|
||||
env.eventBinding.name.should.be.exactly("render-with-entry");
|
||||
});
|
||||
it("binds to render-with-entry event", () =>
|
||||
env.eventBinding.name.should.be.exactly("render-with-entry"));
|
||||
|
||||
describe("with name", function() {
|
||||
beforeEach(function() {
|
||||
describe("with name", () => {
|
||||
beforeEach(() => {
|
||||
env.chunk = {
|
||||
modules: env.modulesListWithExternals
|
||||
};
|
||||
env.eventBinding = setupPluginAndGetEventBinding("foo");
|
||||
});
|
||||
|
||||
it("creates source wrapper with module name and external dependencies", function() {
|
||||
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
|
||||
it("creates source wrapper with module name and external dependencies", () => {
|
||||
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
|
||||
source.should.be.instanceof(ConcatSource);
|
||||
source.source().should.be.exactly('define("templateName", ["external-amd-module","external-non-amd-module",null], function(__WEBPACK_EXTERNAL_MODULE_module-1__, __WEBPACK_EXTERNAL_MODULE_module-2__, __WEBPACK_EXTERNAL_MODULE_module-3__) { return moduleSource()});');
|
||||
});
|
||||
});
|
||||
|
||||
describe("with external dependencies", function() {
|
||||
beforeEach(function() {
|
||||
describe("with external dependencies", () => {
|
||||
beforeEach(() => {
|
||||
env.chunk = {
|
||||
modules: env.modulesListWithExternals
|
||||
};
|
||||
env.eventBinding = setupPluginAndGetEventBinding();
|
||||
});
|
||||
|
||||
it("creates source wrapper with external dependencies", function() {
|
||||
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
|
||||
it("creates source wrapper with external dependencies", () => {
|
||||
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
|
||||
source.should.be.instanceof(ConcatSource);
|
||||
source.source().should.be.exactly('define(["external-amd-module","external-non-amd-module",null], function(__WEBPACK_EXTERNAL_MODULE_module-1__, __WEBPACK_EXTERNAL_MODULE_module-2__, __WEBPACK_EXTERNAL_MODULE_module-3__) { return moduleSource()});');
|
||||
});
|
||||
});
|
||||
|
||||
describe("with only local dependencies", function() {
|
||||
beforeEach(function() {
|
||||
var externalFlag = {
|
||||
describe("with only local dependencies", () => {
|
||||
beforeEach(() => {
|
||||
const externalFlag = {
|
||||
external: false
|
||||
};
|
||||
var noExternals = env.modulesListWithExternals.map((module) => Object.assign(module, externalFlag));
|
||||
const noExternals = env.modulesListWithExternals.map((module) => Object.assign(module, externalFlag));
|
||||
env.chunk = {
|
||||
modules: noExternals
|
||||
};
|
||||
env.eventBinding = setupPluginAndGetEventBinding();
|
||||
});
|
||||
|
||||
it("creates source wrapper with callback only", function() {
|
||||
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
|
||||
it("creates source wrapper with callback only", () => {
|
||||
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
|
||||
source.should.be.instanceof(ConcatSource);
|
||||
source.source().should.be.exactly('define(function() { return moduleSource()});');
|
||||
});
|
||||
|
|
@ -126,40 +118,29 @@ describe("AmdMainTemplatePlugin", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("main template event handlers", function() {
|
||||
beforeEach(function() {
|
||||
env.mainTemplateBindings = env.templatePlugin.getMainTemplateBindings();
|
||||
describe("main template event handlers", () => {
|
||||
beforeEach(() =>
|
||||
env.mainTemplateBindings = env.templatePlugin.getMainTemplateBindings());
|
||||
|
||||
it("binds two handlers", () => env.mainTemplateBindings.length.should.be.exactly(2));
|
||||
|
||||
describe("global-hash-paths handler", () => {
|
||||
beforeEach(() => env.mainTemplateBinding = env.mainTemplateBindings[0]);
|
||||
|
||||
it("binds to global-hash-paths event", () =>
|
||||
env.mainTemplateBinding.name.should.be.exactly("global-hash-paths"));
|
||||
|
||||
it("adds name to path array", () =>
|
||||
env.mainTemplateBinding.handler([]).should.deepEqual(["foo"]));
|
||||
});
|
||||
|
||||
it("binds two handlers", function() {
|
||||
env.mainTemplateBindings.length.should.be.exactly(2);
|
||||
});
|
||||
describe("hash handler", () => {
|
||||
beforeEach(() => env.mainTemplateBinding = env.mainTemplateBindings[1]);
|
||||
|
||||
describe("global-hash-paths handler", function() {
|
||||
beforeEach(function() {
|
||||
env.mainTemplateBinding = env.mainTemplateBindings[0];
|
||||
});
|
||||
it("binds to hash event", () => env.mainTemplateBinding.name.should.be.exactly("hash"));
|
||||
|
||||
it("binds to global-hash-paths event", function() {
|
||||
env.mainTemplateBinding.name.should.be.exactly("global-hash-paths");
|
||||
});
|
||||
|
||||
it("adds name to path array", function() {
|
||||
env.mainTemplateBinding.handler([]).should.deepEqual(["foo"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hash handler", function() {
|
||||
beforeEach(function() {
|
||||
env.mainTemplateBinding = env.mainTemplateBindings[1];
|
||||
});
|
||||
|
||||
it("binds to hash event", function() {
|
||||
env.mainTemplateBinding.name.should.be.exactly("hash");
|
||||
});
|
||||
|
||||
it("updates hash", function() {
|
||||
var hash = {
|
||||
it("updates hash", () => {
|
||||
const hash = {
|
||||
update: sinon.spy()
|
||||
};
|
||||
env.mainTemplateBinding.handler(hash);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var CachePlugin = require("../lib/CachePlugin");
|
||||
var applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
|
||||
"use strict";
|
||||
|
||||
describe("CachePlugin", function() {
|
||||
var env;
|
||||
const should = require("should");
|
||||
const sinon = require("sinon");
|
||||
const CachePlugin = require("../lib/CachePlugin");
|
||||
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
|
||||
|
||||
beforeEach(function() {
|
||||
describe("CachePlugin", () => {
|
||||
let env;
|
||||
|
||||
beforeEach(() => {
|
||||
env = {
|
||||
compilation: {
|
||||
compiler: {},
|
||||
|
|
@ -15,47 +17,44 @@ describe("CachePlugin", function() {
|
|||
};
|
||||
});
|
||||
|
||||
it("has apply function", function() {
|
||||
it("has apply ", () => {
|
||||
(new CachePlugin()).apply.should.be.a.Function();
|
||||
});
|
||||
describe("applyMtime", () => {
|
||||
beforeEach(() => env.plugin = new CachePlugin());
|
||||
|
||||
describe('applyMtime', function() {
|
||||
beforeEach(function() {
|
||||
env.plugin = new CachePlugin();
|
||||
});
|
||||
|
||||
it("sets file system accuracy to 1 for granular modification timestamp", function() {
|
||||
env.plugin.applyMtime(1483819067001)
|
||||
it("sets file system accuracy to 1 for granular modification timestamp", () => {
|
||||
env.plugin.applyMtime(1483819067001);
|
||||
env.plugin.FS_ACCURENCY.should.be.exactly(1);
|
||||
});
|
||||
|
||||
it("sets file system accuracy to 10 for moderately granular modification timestamp", function() {
|
||||
env.plugin.applyMtime(1483819067004)
|
||||
it("sets file system accuracy to 10 for moderately granular modification timestamp", () => {
|
||||
env.plugin.applyMtime(1483819067004);
|
||||
env.plugin.FS_ACCURENCY.should.be.exactly(10);
|
||||
});
|
||||
|
||||
it("sets file system accuracy to 100 for moderately coarse modification timestamp", function() {
|
||||
env.plugin.applyMtime(1483819067040)
|
||||
it("sets file system accuracy to 100 for moderately coarse modification timestamp", () => {
|
||||
env.plugin.applyMtime(1483819067040);
|
||||
env.plugin.FS_ACCURENCY.should.be.exactly(100);
|
||||
});
|
||||
|
||||
it("sets file system accuracy to 1000 for coarse modification timestamp", function() {
|
||||
env.plugin.applyMtime(1483819067400)
|
||||
it("sets file system accuracy to 1000 for coarse modification timestamp", () => {
|
||||
env.plugin.applyMtime(1483819067400);
|
||||
env.plugin.FS_ACCURENCY.should.be.exactly(1000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when applied", function() {
|
||||
describe("for multiple compilers", function() {
|
||||
beforeEach(function() {
|
||||
var plugin = new CachePlugin();
|
||||
describe("when applied", () => {
|
||||
describe("for multiple compilers", () => {
|
||||
beforeEach(() => {
|
||||
const plugin = new CachePlugin();
|
||||
env.compilers = [sinon.spy(), sinon.spy()];
|
||||
plugin.apply({
|
||||
compilers: env.compilers
|
||||
});
|
||||
});
|
||||
|
||||
it("calls each compilers apply with the cache plugin context", function() {
|
||||
it("calls each compilers apply with the cache plugin context", () => {
|
||||
env.compilers[0].callCount.should.be.exactly(1);
|
||||
env.compilers[0].firstCall.thisValue.should.be.instanceOf(CachePlugin);
|
||||
env.compilers[1].callCount.should.be.exactly(1);
|
||||
|
|
@ -63,75 +62,66 @@ describe("CachePlugin", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("for a single compiler", function() {
|
||||
beforeEach(function() {
|
||||
var applyContext = {};
|
||||
describe("for a single compiler", () => {
|
||||
beforeEach(() => {
|
||||
const applyContext = {};
|
||||
env.eventBindings = applyPluginWithOptions.call(applyContext, CachePlugin, {
|
||||
test: true
|
||||
});
|
||||
env.plugin = applyContext.plugin;
|
||||
});
|
||||
|
||||
it("binds four event handlers", function() {
|
||||
env.eventBindings.length.should.be.exactly(4);
|
||||
});
|
||||
it("binds four event handlers", () =>
|
||||
env.eventBindings.length.should.be.exactly(4));
|
||||
|
||||
it("sets the initial cache", function() {
|
||||
env.plugin.cache.test.should.be.true();
|
||||
});
|
||||
it("sets the initial cache", () =>
|
||||
env.plugin.cache.test.should.be.true());
|
||||
|
||||
describe("compilation handler", function() {
|
||||
it("binds to compilation event", function() {
|
||||
env.eventBindings[0].name.should.be.exactly("compilation");
|
||||
});
|
||||
describe("compilation handler", () => {
|
||||
it("binds to compilation event", () =>
|
||||
env.eventBindings[0].name.should.be.exactly("compilation"));
|
||||
|
||||
describe("when cachable", function() {
|
||||
describe("and not watching", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBindings[0].handler(env.compilation);
|
||||
});
|
||||
describe("when cachable", () => {
|
||||
describe("and not watching", () => {
|
||||
beforeEach(() =>
|
||||
env.eventBindings[0].handler(env.compilation));
|
||||
|
||||
it("sets the compilation cache", function() {
|
||||
it("sets the compilation cache", () =>
|
||||
env.compilation.cache.should.deepEqual({
|
||||
test: true
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe("and watching", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBindings[1].handler(env.compilation, function() {});
|
||||
describe("and watching", () => {
|
||||
beforeEach(() => {
|
||||
env.eventBindings[1].handler(env.compilation, () => {});
|
||||
env.eventBindings[0].handler(env.compilation);
|
||||
});
|
||||
|
||||
it("does not add a compilation warning is added", function() {
|
||||
env.compilation.warnings.should.be.empty();
|
||||
});
|
||||
it("does not add a compilation warning is added", () =>
|
||||
env.compilation.warnings.should.be.empty());
|
||||
});
|
||||
});
|
||||
|
||||
describe("when not cachable", function() {
|
||||
beforeEach(function() {
|
||||
env.compilation.notCacheable = true;
|
||||
describe("when not cachable", () => {
|
||||
beforeEach(() =>
|
||||
env.compilation.notCacheable = true);
|
||||
|
||||
describe("and not watching", () => {
|
||||
beforeEach(() =>
|
||||
env.eventBindings[0].handler(env.compilation));
|
||||
|
||||
it("does not set the cache", () =>
|
||||
should(env.compilation.cache).be.undefined());
|
||||
});
|
||||
|
||||
describe("and not watching", function() {
|
||||
beforeEach(function() {
|
||||
describe("and watching", () => {
|
||||
beforeEach(() => {
|
||||
env.eventBindings[1].handler(env.compilation, () => {});
|
||||
env.eventBindings[0].handler(env.compilation);
|
||||
});
|
||||
|
||||
it("does not set the cache", function() {
|
||||
should(env.compilation.cache).be.undefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("and watching", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBindings[1].handler(env.compilation, function() {});
|
||||
env.eventBindings[0].handler(env.compilation);
|
||||
});
|
||||
|
||||
it("adds a compilation warning", function() {
|
||||
it("adds a compilation warning", () => {
|
||||
env.compilation.warnings.length.should.be.exactly(1);
|
||||
env.compilation.warnings[0].should.be.Error("CachePlugin - Cache cannot be used because of: true");
|
||||
});
|
||||
|
|
@ -139,27 +129,24 @@ describe("CachePlugin", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("watch-run handler", function() {
|
||||
beforeEach(function() {
|
||||
describe("watch-run handler", () => {
|
||||
beforeEach(() => {
|
||||
env.callback = sinon.spy();
|
||||
env.eventBindings[1].handler(env.compilation.compiler, env.callback);
|
||||
});
|
||||
|
||||
it("binds to watch-run event", function() {
|
||||
env.eventBindings[1].name.should.be.exactly("watch-run");
|
||||
});
|
||||
it("binds to watch-run event", () =>
|
||||
env.eventBindings[1].name.should.be.exactly("watch-run"));
|
||||
|
||||
it("sets watching flag", function() {
|
||||
env.plugin.watching.should.be.true();
|
||||
});
|
||||
it("sets watching flag", () =>
|
||||
env.plugin.watching.should.be.true());
|
||||
|
||||
it("calls callback", function() {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
});
|
||||
it("calls callback", () =>
|
||||
env.callback.callCount.should.be.exactly(1));
|
||||
});
|
||||
|
||||
describe("run handler", function() {
|
||||
beforeEach(function() {
|
||||
describe("run handler", () => {
|
||||
beforeEach(() => {
|
||||
env.fsStat = sinon.spy();
|
||||
env.callback = sinon.spy();
|
||||
env.compilation.compiler.inputFileSystem = {
|
||||
|
|
@ -167,116 +154,102 @@ describe("CachePlugin", function() {
|
|||
};
|
||||
});
|
||||
|
||||
it("binds to run event", function() {
|
||||
env.eventBindings[2].name.should.be.exactly("run");
|
||||
});
|
||||
it("binds to run event", () =>
|
||||
env.eventBindings[2].name.should.be.exactly("run"));
|
||||
|
||||
describe("Has not previously compiled", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBindings[2].handler(env.compilation.compiler, env.callback);
|
||||
});
|
||||
describe("Has not previously compiled", () => {
|
||||
beforeEach(() =>
|
||||
env.eventBindings[2].handler(env.compilation.compiler, env.callback));
|
||||
|
||||
it("does not get any file stats", function() {
|
||||
env.fsStat.callCount.should.be.exactly(0);
|
||||
});
|
||||
it("does not get any file stats", () =>
|
||||
env.fsStat.callCount.should.be.exactly(0));
|
||||
|
||||
it("calls the callback", function() {
|
||||
it("calls the callback", () => {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
should(env.callback.firstCall.args[0]).be.undefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Has previously compiled", function() {
|
||||
beforeEach(function() {
|
||||
describe("Has previously compiled", () => {
|
||||
beforeEach(() => {
|
||||
env.compilation.fileDependencies = ["foo"];
|
||||
env.compilation.contextDependencies = ["bar"];
|
||||
env.eventBindings[3].handler(env.compilation, function() {});
|
||||
env.eventBindings[3].handler(env.compilation, () => {});
|
||||
env.eventBindings[2].handler(env.compilation.compiler, env.callback);
|
||||
});
|
||||
|
||||
it("calls for file stats for file dependencies", function() {
|
||||
it("calls for file stats for file dependencies", () => {
|
||||
env.fsStat.callCount.should.be.exactly(1);
|
||||
env.fsStat.firstCall.args[0].should.be.exactly("foo");
|
||||
});
|
||||
|
||||
describe('file stats callback', function() {
|
||||
beforeEach(function() {
|
||||
env.fsStatCallback = env.fsStat.firstCall.args[1];
|
||||
});
|
||||
describe("file stats callback", () => {
|
||||
beforeEach(() =>
|
||||
env.fsStatCallback = env.fsStat.firstCall.args[1]);
|
||||
|
||||
describe('when error occurs', function() {
|
||||
beforeEach(function() {
|
||||
env.fsStatCallback(new Error('Test Error'));
|
||||
});
|
||||
describe("when error occurs", () => {
|
||||
beforeEach(() =>
|
||||
env.fsStatCallback(new Error("Test Error")));
|
||||
|
||||
it('calls handler callback with error', function() {
|
||||
it("calls handler callback with error", () => {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
env.callback.firstCall.args[0].should.be.Error('Test Error');
|
||||
env.callback.firstCall.args[0].should.be.Error("Test Error");
|
||||
});
|
||||
});
|
||||
|
||||
describe('when ENOENT error occurs', function() {
|
||||
beforeEach(function() {
|
||||
describe("when ENOENT error occurs", () => {
|
||||
beforeEach(() =>
|
||||
env.fsStatCallback({
|
||||
code: 'ENOENT'
|
||||
});
|
||||
});
|
||||
code: "ENOENT"
|
||||
}));
|
||||
|
||||
it('calls handler callback without error', function() {
|
||||
it("calls handler callback without error", () => {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
should(env.callback.firstCall.args[0]).be.undefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when stat does not have modified time', function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(env.plugin, 'applyMtime');
|
||||
describe("when stat does not have modified time", () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(env.plugin, "applyMtime");
|
||||
env.fsStatCallback(null, {});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.plugin.applyMtime.restore();
|
||||
});
|
||||
afterEach(() => env.plugin.applyMtime.restore());
|
||||
|
||||
it('does not update file system accuracy', function() {
|
||||
env.plugin.applyMtime.callCount.should.be.exactly(0);
|
||||
});
|
||||
it("does not update file system accuracy", () =>
|
||||
env.plugin.applyMtime.callCount.should.be.exactly(0));
|
||||
|
||||
it('updates file modified timestamp to infinity', function() {
|
||||
it("updates file modified timestamp to infinity", () =>
|
||||
env.compilation.compiler.fileTimestamps.should.deepEqual({
|
||||
foo: Infinity
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls handler callback without error', function() {
|
||||
it("calls handler callback without error", () => {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
should(env.callback.firstCall.args[0]).be.undefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when stat has modified time', function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(env.plugin, 'applyMtime');
|
||||
describe("when stat has modified time", () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(env.plugin, "applyMtime");
|
||||
env.fsStatCallback(null, {
|
||||
mtime: 1483819067001
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
env.plugin.applyMtime.restore();
|
||||
});
|
||||
afterEach(() => env.plugin.applyMtime.restore());
|
||||
|
||||
it('does not update file system accuracy', function() {
|
||||
env.plugin.applyMtime.callCount.should.be.exactly(1);
|
||||
});
|
||||
it("does not update file system accuracy", () =>
|
||||
env.plugin.applyMtime.callCount.should.be.exactly(1));
|
||||
|
||||
it('updates file modified timestamp to modified time with accuracy value', function() {
|
||||
it("updates file modified timestamp to modified time with accuracy value", () =>
|
||||
env.compilation.compiler.fileTimestamps.should.deepEqual({
|
||||
foo: 1483819069001
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('calls handler callback without error', function() {
|
||||
it("calls handler callback without error", () => {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
should(env.callback.firstCall.args[0]).be.undefined();
|
||||
});
|
||||
|
|
@ -285,28 +258,26 @@ describe("CachePlugin", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("after-compile handler", function() {
|
||||
beforeEach(function() {
|
||||
describe("after-compile handler", () => {
|
||||
beforeEach(() => {
|
||||
env.compilation.fileDependencies = ["foo"];
|
||||
env.compilation.contextDependencies = ["bar"];
|
||||
env.callback = sinon.spy();
|
||||
env.eventBindings[3].handler(env.compilation, env.callback);
|
||||
});
|
||||
|
||||
it("binds to after-compile event", function() {
|
||||
env.eventBindings[3].name.should.be.exactly("after-compile");
|
||||
});
|
||||
it("binds to after-compile event", () =>
|
||||
env.eventBindings[3].name.should.be.exactly("after-compile"));
|
||||
|
||||
it("saves copy of compilation file dependecies", function() {
|
||||
it("saves copy of compilation file dependecies", () => {
|
||||
env.compilation.compiler.should.deepEqual({
|
||||
_lastCompilationFileDependencies: ["foo"],
|
||||
_lastCompilationContextDependencies: ["bar"]
|
||||
});
|
||||
});
|
||||
|
||||
it("calls callback", function() {
|
||||
env.callback.callCount.should.be.exactly(1);
|
||||
});
|
||||
it("calls callback", () =>
|
||||
env.callback.callCount.should.be.exactly(1));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
var should = require("should");
|
||||
var CaseSensitiveModulesWarning = require("../lib/CaseSensitiveModulesWarning");
|
||||
"use strict";
|
||||
|
||||
var createModule = function(identifier, numberOfReasons) {
|
||||
var reasons = new Array(numberOfReasons || 0).fill(null).map(function(value, index) {
|
||||
const should = require("should");
|
||||
const CaseSensitiveModulesWarning = require("../lib/CaseSensitiveModulesWarning");
|
||||
|
||||
const createModule = function(identifier, numberOfReasons) {
|
||||
const reasons = new Array(numberOfReasons || 0).fill(null).map((value, index) => {
|
||||
return {
|
||||
module: createModule(`${identifier}-reason-${index}`)
|
||||
};
|
||||
|
|
@ -14,23 +16,22 @@ var createModule = function(identifier, numberOfReasons) {
|
|||
};
|
||||
};
|
||||
|
||||
describe("CaseSensitiveModulesWarning", function() {
|
||||
var myCaseSensitiveModulesWarning, modules;
|
||||
describe("CaseSensitiveModulesWarning", () => {
|
||||
let myCaseSensitiveModulesWarning;
|
||||
let modules;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
modules = [
|
||||
createModule('FOOBAR'),
|
||||
createModule('FooBar', 1),
|
||||
createModule('foobar', 2)
|
||||
createModule("FOOBAR"),
|
||||
createModule("FooBar", 1),
|
||||
createModule("foobar", 2)
|
||||
];
|
||||
myCaseSensitiveModulesWarning = new CaseSensitiveModulesWarning(modules);
|
||||
});
|
||||
|
||||
it('has the a name', function() {
|
||||
myCaseSensitiveModulesWarning.name.should.be.exactly('CaseSensitiveModulesWarning');
|
||||
});
|
||||
it("has the a name", () => myCaseSensitiveModulesWarning.name.should.be.exactly("CaseSensitiveModulesWarning"));
|
||||
|
||||
it('has the a message', function() {
|
||||
it("has the a message", () => {
|
||||
myCaseSensitiveModulesWarning.message.should.be.exactly(`
|
||||
There are multiple modules with names that only differ in casing.
|
||||
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
|
||||
|
|
@ -45,11 +46,9 @@ Use equal casing. Compare these module identifiers:
|
|||
`.trim());
|
||||
});
|
||||
|
||||
it('has the an origin', function() {
|
||||
myCaseSensitiveModulesWarning.origin.should.be.exactly(modules[0]);
|
||||
});
|
||||
it("has the an origin", () =>
|
||||
myCaseSensitiveModulesWarning.origin.should.be.exactly(modules[0]));
|
||||
|
||||
it('has the a module', function() {
|
||||
myCaseSensitiveModulesWarning.module.should.be.exactly(modules[0]);
|
||||
});
|
||||
it('has the a module', () =>
|
||||
myCaseSensitiveModulesWarning.module.should.be.exactly(modules[0]));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
var path = require("path");
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var ModuleDependencyError = require("../lib/ModuleDependencyError");
|
||||
|
||||
describe("ModuleDependencyError", function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = {};
|
||||
});
|
||||
|
||||
it("is a function", function() {
|
||||
ModuleDependencyError.should.be.a.Function();
|
||||
});
|
||||
|
||||
describe("when new error created", function() {
|
||||
beforeEach(function() {
|
||||
env.error = new Error("Error Message");
|
||||
env.moduleDependencyError = new ModuleDependencyError("myModule", env.error, "Location");
|
||||
});
|
||||
|
||||
it("is an error", function() {
|
||||
env.moduleDependencyError.should.be.an.Error();
|
||||
});
|
||||
|
||||
it("has a name property", function() {
|
||||
env.moduleDependencyError.name.should.be.exactly("ModuleDependencyError");
|
||||
});
|
||||
|
||||
it("has a message property", function() {
|
||||
env.moduleDependencyError.message.should.be.exactly("Location Error Message");
|
||||
});
|
||||
|
||||
it("has a details property", function() {
|
||||
env.moduleDependencyError.details.should.containEql(path.join("test", "ModuleDependencyError.test.js:"));
|
||||
});
|
||||
|
||||
it("has an origin property", function() {
|
||||
env.moduleDependencyError.origin.should.be.exactly("myModule");
|
||||
});
|
||||
|
||||
it("has an error property", function() {
|
||||
env.moduleDependencyError.error.should.be.exactly(env.error);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var NullDependency = require("../lib/dependencies/NullDependency");
|
||||
|
||||
describe("NullDependency", function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = {};
|
||||
});
|
||||
|
||||
it("is a function", function() {
|
||||
NullDependency.should.be.a.Function();
|
||||
});
|
||||
|
||||
describe("when created", function() {
|
||||
beforeEach(function() {
|
||||
env.nullDependency = new NullDependency();
|
||||
});
|
||||
|
||||
it("has a null type", function() {
|
||||
env.nullDependency.type.should.be.exactly("null");
|
||||
});
|
||||
|
||||
it("is not an equal resource", function() {
|
||||
env.nullDependency.isEqualResource().should.be.False();
|
||||
});
|
||||
|
||||
it("has update hash function", function() {
|
||||
env.nullDependency.updateHash.should.be.Function();
|
||||
});
|
||||
|
||||
it("does not update hash", function() {
|
||||
const hash = {
|
||||
update: sinon.stub()
|
||||
};
|
||||
env.nullDependency.updateHash(hash);
|
||||
hash.update.called.should.be.false();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Template", function() {
|
||||
it("is a function", function() {
|
||||
NullDependency.Template.should.be.a.Function();
|
||||
});
|
||||
|
||||
describe("when created", function() {
|
||||
beforeEach(function() {
|
||||
env.nullDependencyTemplate = new NullDependency.Template();
|
||||
});
|
||||
|
||||
it("has apply function", function() {
|
||||
env.nullDependencyTemplate.apply.should.be.Function();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Welcome to the webpack test suite!!!!
|
||||
Every pull request that you submit to webpack (besides README and spelling corrections in comments) requires tests that are created.
|
||||
Every pull request that you submit to webpack (besides README and spelling corrections in comments) requires tests that are created.
|
||||
|
||||
But don't give up hope!!! Although our tests may appear complex and overwhelming, once you become familiar with the test suite and structure, adding and creating tests will be fun and beneficial as you work inside the codebase! ❤
|
||||
|
||||
|
|
@ -7,9 +7,10 @@ But don't give up hope!!! Although our tests may appear complex and overwhelming
|
|||
* Clone repo
|
||||
* install and link deps
|
||||
* `yarn install && yarn link && yarn link webpack`
|
||||
* `npm run test` or `npm t`
|
||||
* `yarn test`
|
||||
|
||||
* To run an individual suite: (recommended during development for easier isolated diffs)
|
||||
|
||||
|
||||
Example: `$(npm bin)/mocha --grep ConfigTestCases`
|
||||
|
||||
## Test suite overview
|
||||
|
|
@ -17,36 +18,35 @@ We use MochaJS for our tests. For more information on Mocha you can visit their
|
|||
|
||||
### Class Tests
|
||||
All test files can be found in *.test.js. There are many tests that simply test API's of a specific class/file (such as `Compiler`, `Errors`, Integration, `Parser`, `RuleSet`, Validation).
|
||||
If the feature you are contributing involves one of those classes, then best to start there to understand the structure.
|
||||
If the feature you are contributing involves one of those classes, then best to start there to understand the structure.
|
||||
|
||||
### xCases
|
||||
In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding *.test.js files.
|
||||
|
||||
#### cases (`TestCases.test.js`) <sup>1</sup>
|
||||
Cases are a set of general purpose tests that will run against a variety of permutations of webpack configurations. When you are making a general purpose change that doesn't require you to have a special configuration, you would likely add your tests here. Inside of the `./test/cases` directory you will find tests are broken into thematic sub directories. Take a moment to explore the different options.
|
||||
Cases are a set of general purpose tests that will run against a variety of permutations of webpack configurations. When you are making a general purpose change that doesn't require you to have a special configuration, you would likely add your tests here. Inside of the `./test/cases` directory you will find tests are broken into thematic sub directories. Take a moment to explore the different options.
|
||||
|
||||
To add a new case, create a new directory inside of the top level test groups, and then add an `index.js` file (and any other supporting files).
|
||||
To add a new case, create a new directory inside of the top level test groups, and then add an `index.js` file (and any other supporting files).
|
||||
|
||||
By default this file will be the entry point for the test suite and you can add your `it()`'s there. This will also become bundled so that node env support happens as well.
|
||||
By default this file will be the entry point for the test suite and you can add your `it()`'s there. This will also become bundled so that node env support happens as well.
|
||||
|
||||
#### configCases (`ConfigTestCases.test.js`) <sup>1</sup>
|
||||
If you are trying to solve a bug which is reproducible when x and y properties are used together in a config, then configCases is the place to be!!!!
|
||||
If you are trying to solve a bug which is reproducible when x and y properties are used together in a config, then configCases is the place to be!!!!
|
||||
|
||||
In addition to an `index.js`, these configCases require a `webpack.config.js` is located inside of your test suite. This will run this specific config through `webpack` just as you were building individually. They will use the same loading/bundling technique of your `it()` tests, however you now have a more specific config use cases that you can write even before you start coding.
|
||||
In addition to an `index.js`, these configCases require a `webpack.config.js` is located inside of your test suite. This will run this specific config through `webpack` just as you were building individually. They will use the same loading/bundling technique of your `it()` tests, however you now have a more specific config use cases that you can write even before you start coding.
|
||||
|
||||
#### statsCases (`Stats.test.js`)
|
||||
Stats cases are similar to configCases except specifically focusing on the `expected` output of your stats. Instead of writing to the console, however the output of stats will be written to disk.
|
||||
Stats cases are similar to configCases except specifically focusing on the `expected` output of your stats. Instead of writing to the console, however the output of stats will be written to disk.
|
||||
|
||||
By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run the following happens:
|
||||
|
||||
* Checks for `expected.txt` file containing expected results.
|
||||
* Checks for `expected.txt` file containing expected results.
|
||||
* If the `expected.txt` doesn't match what is output, then an `actual.txt` stats output file will be created and the test will fail. (A typical workflow for stats cases is to fail the test and copy the results from `actual.txt` to `expected.txt`.)
|
||||
* If the actual output matches `expected.txt`, the tests passes and you are free to submit that PR with pride!!!
|
||||
|
||||
## Questions? Comments?
|
||||
## Questions? Comments?
|
||||
If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on!
|
||||
|
||||
|
||||
## Footnotes
|
||||
<sup>1</sup> webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow NodeJS's timeline for dropping older versions of node. Because of this we expect your tests on Travis to pass all the way back to NodeJS v0.12; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful exapmles you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
var should = require("should");
|
||||
var webpack = require("../lib/webpack");
|
||||
var WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError");
|
||||
"use strict";
|
||||
|
||||
const should = require("should");
|
||||
const webpack = require("../lib/webpack");
|
||||
const WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError");
|
||||
|
||||
describe("Validation", function() {
|
||||
var testCases = [{
|
||||
const testCases = [{
|
||||
name: "undefined configuration",
|
||||
config: undefined,
|
||||
message: [
|
||||
|
|
|
|||
|
|
@ -0,0 +1,277 @@
|
|||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var WebWorkerMainTemplatePlugin = require("../lib/webworker/WebWorkerMainTemplatePlugin");
|
||||
var applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
|
||||
|
||||
describe("WebWorkerMainTemplatePlugin", function() {
|
||||
var env;
|
||||
|
||||
beforeEach(function() {
|
||||
env = {};
|
||||
});
|
||||
|
||||
it("has apply function", function() {
|
||||
(new WebWorkerMainTemplatePlugin()).apply.should.be.a.Function();
|
||||
});
|
||||
|
||||
describe("when applied", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBindings = applyPluginWithOptions(WebWorkerMainTemplatePlugin);
|
||||
env.handlerContext = {
|
||||
requireFn: 'requireFn',
|
||||
indent: (value) => typeof value === 'string' ? value : value.join("\n"),
|
||||
asString: (values) => values.join("\n"),
|
||||
renderCurrentHashCode: (value) => value,
|
||||
outputOptions: {
|
||||
chunkFilename: 'chunkFilename'
|
||||
},
|
||||
applyPluginsWaterfall: (moduleName, fileName, data) => {
|
||||
return '"' + moduleName + data.hash + data.hashWithLength() + (data.chunk && data.chunk.id || '') + '"';
|
||||
},
|
||||
renderAddModule: () => 'renderAddModuleSource();',
|
||||
};
|
||||
});
|
||||
|
||||
it("binds five event handlers", function() {
|
||||
env.eventBindings.length.should.be.exactly(5);
|
||||
});
|
||||
|
||||
describe("local-vars handler", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBinding = env.eventBindings[0];
|
||||
});
|
||||
|
||||
it("binds to local-vars event", function() {
|
||||
env.eventBinding.name.should.be.exactly("local-vars");
|
||||
});
|
||||
|
||||
describe("when no chunks are provided", function() {
|
||||
beforeEach(function() {
|
||||
var chunk = {
|
||||
ids: [],
|
||||
chunks: []
|
||||
};
|
||||
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk);
|
||||
});
|
||||
|
||||
it("returns the original source", function() {
|
||||
env.source.should.be.exactly("moduleSource()")
|
||||
});
|
||||
});
|
||||
|
||||
describe("when chunks are provided", function() {
|
||||
beforeEach(function() {
|
||||
var chunk = {
|
||||
ids: [1, 2, 3],
|
||||
chunks: [
|
||||
'foo',
|
||||
'bar',
|
||||
'baz'
|
||||
]
|
||||
};
|
||||
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk, 'abc123');
|
||||
});
|
||||
|
||||
it("returns the original source with installed mapping", function() {
|
||||
env.source.should.be.exactly(`
|
||||
moduleSource()
|
||||
|
||||
// object to store loaded chunks
|
||||
// "1" means "already loaded"
|
||||
var installedChunks = {
|
||||
1: 1,
|
||||
2: 1,
|
||||
3: 1
|
||||
};
|
||||
`.trim())
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("require-ensure handler", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBinding = env.eventBindings[1];
|
||||
});
|
||||
|
||||
it("binds to require-ensure event", function() {
|
||||
env.eventBinding.name.should.be.exactly("require-ensure");
|
||||
});
|
||||
|
||||
describe("when called", function() {
|
||||
beforeEach(function() {
|
||||
var chunk = {};
|
||||
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk, 'abc123');
|
||||
});
|
||||
|
||||
it("creates import scripts call and promise resolve", function() {
|
||||
env.source.should.be.exactly(`
|
||||
// "1" is the signal for "already loaded"
|
||||
if(!installedChunks[chunkId]) {
|
||||
importScripts("asset-path" + abc123 + "" + abc123 + "" + chunkId + "");
|
||||
}
|
||||
return Promise.resolve();
|
||||
`.trim())
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("bootstrap handler", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBinding = env.eventBindings[2];
|
||||
});
|
||||
|
||||
it("binds to bootstrap event", function() {
|
||||
env.eventBinding.name.should.be.exactly("bootstrap");
|
||||
});
|
||||
|
||||
describe("when no chunks are provided", function() {
|
||||
beforeEach(function() {
|
||||
var chunk = {
|
||||
ids: [],
|
||||
chunks: []
|
||||
};
|
||||
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk);
|
||||
});
|
||||
|
||||
it("returns the original source", function() {
|
||||
env.source.should.be.exactly("moduleSource()")
|
||||
});
|
||||
});
|
||||
|
||||
describe("when chunks are provided", function() {
|
||||
beforeEach(function() {
|
||||
var chunk = {
|
||||
ids: [1, 2, 3],
|
||||
chunks: [
|
||||
'foo',
|
||||
'bar',
|
||||
'baz'
|
||||
]
|
||||
};
|
||||
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk);
|
||||
});
|
||||
|
||||
it("returns the original source with chunk callback", function() {
|
||||
env.source.should.be.exactly(`
|
||||
moduleSource()
|
||||
this["webpackChunk"] = function webpackChunkCallback(chunkIds, moreModules) {
|
||||
for(var moduleId in moreModules) {
|
||||
renderAddModuleSource();
|
||||
}
|
||||
while(chunkIds.length)
|
||||
installedChunks[chunkIds.pop()] = 1;
|
||||
};
|
||||
`.trim())
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("hot-bootstrap handler", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBinding = env.eventBindings[3];
|
||||
});
|
||||
|
||||
it("binds to hot-bootstrap event", function() {
|
||||
env.eventBinding.name.should.be.exactly("hot-bootstrap");
|
||||
});
|
||||
|
||||
describe("when called", function() {
|
||||
beforeEach(function() {
|
||||
var chunk = {};
|
||||
env.source = env.eventBinding.handler.call(env.handlerContext, "moduleSource()", chunk, 'abc123');
|
||||
});
|
||||
|
||||
it("returns the original source with hot update callback", function() {
|
||||
env.source.should.be.exactly(`
|
||||
moduleSource()
|
||||
var parentHotUpdateCallback = this["webpackHotUpdate"];
|
||||
this["webpackHotUpdate"] = function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars
|
||||
hotAddUpdateChunk(chunkId, moreModules);
|
||||
if(parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules);
|
||||
} ;
|
||||
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
importScripts(requireFn.p + "asset-path" + abc123 + "" + abc123 + "" + chunkId + "");
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
return new Promise(function(resolve, reject) {
|
||||
if(typeof XMLHttpRequest === "undefined")
|
||||
return reject(new Error("No browser support"));
|
||||
try {
|
||||
var request = new XMLHttpRequest();
|
||||
var requestPath = requireFn.p + "asset-path" + abc123 + "" + abc123 + "";
|
||||
request.open("GET", requestPath, true);
|
||||
request.timeout = 10000;
|
||||
request.send(null);
|
||||
} catch(err) {
|
||||
return reject(err);
|
||||
}
|
||||
request.onreadystatechange = function() {
|
||||
if(request.readyState !== 4) return;
|
||||
if(request.status === 0) {
|
||||
// timeout
|
||||
reject(new Error("Manifest request to " + requestPath + " timed out."));
|
||||
} else if(request.status === 404) {
|
||||
// no update available
|
||||
resolve();
|
||||
} else if(request.status !== 200 && request.status !== 304) {
|
||||
// other failure
|
||||
reject(new Error("Manifest request to " + requestPath + " failed."));
|
||||
} else {
|
||||
// success
|
||||
try {
|
||||
var update = JSON.parse(request.responseText);
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
resolve(update);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars
|
||||
delete installedChunks[chunkId];
|
||||
}
|
||||
`.trim())
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("hash handler", function() {
|
||||
beforeEach(function() {
|
||||
env.eventBinding = env.eventBindings[4];
|
||||
env.handlerContext = {
|
||||
outputOptions: {
|
||||
publicPath: "Alpha",
|
||||
filename: "Bravo",
|
||||
chunkFilename: "Charlie",
|
||||
chunkCallbackName: "Delta",
|
||||
library: "Echo"
|
||||
}
|
||||
};
|
||||
env.hashMock = {
|
||||
update: sinon.spy()
|
||||
};
|
||||
env.eventBinding.handler.call(env.handlerContext, env.hashMock);
|
||||
});
|
||||
|
||||
it("binds to hash event", function() {
|
||||
env.eventBinding.name.should.be.exactly("hash");
|
||||
});
|
||||
|
||||
it("updates hash object", function() {
|
||||
env.hashMock.update.callCount.should.be.exactly(7);
|
||||
sinon.assert.calledWith(env.hashMock.update, "webworker");
|
||||
sinon.assert.calledWith(env.hashMock.update, "3");
|
||||
sinon.assert.calledWith(env.hashMock.update, "Alpha");
|
||||
sinon.assert.calledWith(env.hashMock.update, "Bravo");
|
||||
sinon.assert.calledWith(env.hashMock.update, "Charlie");
|
||||
sinon.assert.calledWith(env.hashMock.update, "Delta");
|
||||
sinon.assert.calledWith(env.hashMock.update, "Echo");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,33 +1,39 @@
|
|||
var should = require("should");
|
||||
var compareLocations = require("../lib/compareLocations");
|
||||
var createLocation = function(overides) {
|
||||
"use strict";
|
||||
|
||||
const should = require("should");
|
||||
const compareLocations = require("../lib/compareLocations");
|
||||
const createPosition = function(overides) {
|
||||
return Object.assign({
|
||||
line: 10,
|
||||
column: 5,
|
||||
index: 3
|
||||
column: 5
|
||||
}, overides);
|
||||
};
|
||||
|
||||
describe('compareLocations', function() {
|
||||
describe('string location comparison', function() {
|
||||
it('returns -1 when the first string comes before the second string', function() {
|
||||
compareLocations('alpha', 'beta').should.be.exactly(-1);
|
||||
});
|
||||
const createLocation = function(start, end, index) {
|
||||
return {
|
||||
start: createPosition(start),
|
||||
end: createPosition(end),
|
||||
index: index || 3
|
||||
};
|
||||
};
|
||||
|
||||
it('returns 1 when the first string comes after the second string', function() {
|
||||
compareLocations('beta', 'alpha').should.be.exactly(1);
|
||||
});
|
||||
describe("compareLocations", () => {
|
||||
describe("string location comparison", () => {
|
||||
it("returns -1 when the first string comes before the second string", () =>
|
||||
compareLocations("alpha", "beta").should.be.exactly(-1));
|
||||
|
||||
it('returns 0 when the first string is the same as the second string', function() {
|
||||
compareLocations('charlie', 'charlie').should.be.exactly(0);
|
||||
});
|
||||
it("returns 1 when the first string comes after the second string", () =>
|
||||
compareLocations("beta", "alpha").should.be.exactly(1));
|
||||
|
||||
it("returns 0 when the first string is the same as the second string", () =>
|
||||
compareLocations("charlie", "charlie").should.be.exactly(0));
|
||||
});
|
||||
|
||||
describe('object location comparison', function() {
|
||||
var a, b;
|
||||
describe("object location comparison", () => {
|
||||
let a, b;
|
||||
|
||||
describe('location line number', function() {
|
||||
beforeEach(function() {
|
||||
describe("location line number", () => {
|
||||
beforeEach(() => {
|
||||
a = createLocation({
|
||||
line: 10
|
||||
});
|
||||
|
|
@ -36,17 +42,16 @@ describe('compareLocations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('returns -1 when the first location line number comes before the second location line number', function() {
|
||||
compareLocations(a, b).should.be.exactly(-1);
|
||||
it("returns -1 when the first location line number comes before the second location line number", () => {
|
||||
return compareLocations(a, b).should.be.exactly(-1)
|
||||
});
|
||||
|
||||
it('returns 1 when the first location line number comes after the second location line number', function() {
|
||||
compareLocations(b, a).should.be.exactly(1);
|
||||
});
|
||||
it("returns 1 when the first location line number comes after the second location line number", () =>
|
||||
compareLocations(b, a).should.be.exactly(1));
|
||||
});
|
||||
|
||||
describe('location column number', function() {
|
||||
beforeEach(function() {
|
||||
describe("location column number", () => {
|
||||
beforeEach(() => {
|
||||
a = createLocation({
|
||||
column: 10
|
||||
});
|
||||
|
|
@ -55,98 +60,61 @@ describe('compareLocations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('returns -1 when the first location column number comes before the second location column number', function() {
|
||||
compareLocations(a, b).should.be.exactly(-1);
|
||||
});
|
||||
it("returns -1 when the first location column number comes before the second location column number", () =>
|
||||
compareLocations(a, b).should.be.exactly(-1));
|
||||
|
||||
it('returns 1 when the first location column number comes after the second location column number', function() {
|
||||
compareLocations(b, a).should.be.exactly(1);
|
||||
});
|
||||
it("returns 1 when the first location column number comes after the second location column number", () =>
|
||||
compareLocations(b, a).should.be.exactly(1));
|
||||
});
|
||||
|
||||
describe('location index number', function() {
|
||||
beforeEach(function() {
|
||||
a = createLocation({
|
||||
index: 10
|
||||
});
|
||||
b = createLocation({
|
||||
index: 20
|
||||
});
|
||||
describe("location index number", () => {
|
||||
beforeEach(() => {
|
||||
a = createLocation(null, null, 10);
|
||||
b = createLocation(null, null, 20);
|
||||
});
|
||||
|
||||
it('returns -1 when the first location index number comes before the second location index number', function() {
|
||||
compareLocations(a, b).should.be.exactly(-1);
|
||||
});
|
||||
it("returns -1 when the first location index number comes before the second location index number", () =>
|
||||
compareLocations(a, b).should.be.exactly(-1));
|
||||
|
||||
it('returns 1 when the first location index number comes after the second location index number', function() {
|
||||
compareLocations(b, a).should.be.exactly(1);
|
||||
});
|
||||
it("returns 1 when the first location index number comes after the second location index number", () =>
|
||||
compareLocations(b, a).should.be.exactly(1));
|
||||
});
|
||||
|
||||
describe('same location', function() {
|
||||
beforeEach(function() {
|
||||
describe("same location", () => {
|
||||
beforeEach(() => {
|
||||
a = createLocation();
|
||||
b = createLocation();
|
||||
});
|
||||
|
||||
it('returns 0', function() {
|
||||
it("returns 0", () => {
|
||||
compareLocations(a, b).should.be.exactly(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('start location set', function() {
|
||||
beforeEach(function() {
|
||||
a = {
|
||||
start: createLocation({
|
||||
line: 10
|
||||
})
|
||||
};
|
||||
b = {
|
||||
start: createLocation({
|
||||
line: 20
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
it('returns -1 when the first location line number comes before the second location line number', function() {
|
||||
compareLocations(a, b).should.be.exactly(-1);
|
||||
});
|
||||
|
||||
it('returns 1 when the first location line number comes after the second location line number', function() {
|
||||
compareLocations(b, a).should.be.exactly(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('string and object location comparison', function() {
|
||||
it('returns 1 when the first parameter is a string and the second parameter is an object', function() {
|
||||
compareLocations('alpha', createLocation()).should.be.exactly(1);
|
||||
});
|
||||
describe("string and object location comparison", () => {
|
||||
it("returns 1 when the first parameter is a string and the second parameter is an object", () =>
|
||||
compareLocations("alpha", createLocation()).should.be.exactly(1));
|
||||
|
||||
it('returns -1 when the first parameter is an object and the second parameter is a string', function() {
|
||||
compareLocations(createLocation(), 'alpha').should.be.exactly(-1);
|
||||
});
|
||||
it("returns -1 when the first parameter is an object and the second parameter is a string", () =>
|
||||
compareLocations(createLocation(), "alpha").should.be.exactly(-1));
|
||||
});
|
||||
|
||||
describe('unknown location type comparison', function() {
|
||||
it('returns 0 when the first parameter is an object and the second parameter is a number', function() {
|
||||
compareLocations(createLocation(), 123).should.be.exactly(0);
|
||||
});
|
||||
describe("unknown location type comparison", () => {
|
||||
it("returns 0 when the first parameter is an object and the second parameter is a number", () =>
|
||||
compareLocations(createLocation(), 123).should.be.exactly(0));
|
||||
|
||||
it('returns undefined when the first parameter is a number and the second parameter is an object', function() {
|
||||
should(compareLocations(123, createLocation())).be.undefined();
|
||||
});
|
||||
it("returns undefined when the first parameter is a number and the second parameter is an object", () =>
|
||||
should(compareLocations(123, createLocation())).be.undefined());
|
||||
|
||||
it('returns 0 when the first parameter is a string and the second parameter is a number', function() {
|
||||
compareLocations('alpha', 123).should.be.exactly(0);
|
||||
});
|
||||
it("returns 0 when the first parameter is a string and the second parameter is a number", () =>
|
||||
compareLocations("alpha", 123).should.be.exactly(0));
|
||||
|
||||
it('returns undefined when the first parameter is a number and the second parameter is a string', function() {
|
||||
should(compareLocations(123, 'alpha')).be.undefined();
|
||||
});
|
||||
it("returns undefined when the first parameter is a number and the second parameter is a string", () =>
|
||||
should(compareLocations(123, "alpha")).be.undefined());
|
||||
|
||||
it("returns undefined when both the first parameter and the second parameter is a number", () =>
|
||||
should(compareLocations(123, 456)).be.undefined());
|
||||
|
||||
it('returns undefined when both the first parameter and the second parameter is a number', function() {
|
||||
should(compareLocations(123, 456)).be.undefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,17 +1,41 @@
|
|||
var fs = require("fs");
|
||||
require("should");
|
||||
|
||||
var findFile = function(files, regex) {
|
||||
return files.find(function(file) {
|
||||
if(regex.test(file)) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var verifyFilenameLength = function(filename, expectedNameLength) {
|
||||
filename.should.match(new RegExp("^.{" + expectedNameLength + "}$"));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
findBundle: function(i, options) {
|
||||
var files = fs.readdirSync(options.output.path);
|
||||
var expectedNameLength = options.amd.expectedFilenameLength;
|
||||
var bundleDetect = new RegExp("^bundle" + i, "i");
|
||||
for(var j = 0, file; j < files.length; j++) {
|
||||
file = files[j];
|
||||
if (bundleDetect.test(file)) {
|
||||
file.should.match(new RegExp("^.{" + expectedNameLength + "}$"));
|
||||
return "./" + file;
|
||||
}
|
||||
|
||||
var bundleDetects = [{
|
||||
regex: new RegExp("^0.bundle" + i, "i"),
|
||||
expectedNameLength: options.amd.expectedChunkFilenameLength
|
||||
}, {
|
||||
regex: new RegExp("^bundle" + i, "i"),
|
||||
expectedNameLength: options.amd.expectedFilenameLength
|
||||
}];
|
||||
|
||||
var bundleDetect;
|
||||
var filename;
|
||||
|
||||
for(bundleDetect of bundleDetects) {
|
||||
filename = findFile(files, bundleDetect.regex);
|
||||
verifyFilenameLength(
|
||||
filename,
|
||||
bundleDetect.expectedNameLength
|
||||
);
|
||||
}
|
||||
|
||||
return "./" + filename;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ module.exports = [{
|
|||
output: {
|
||||
publicPath: "/[hash:6]/",
|
||||
filename: "bundle0.[hash:6].js",
|
||||
chunkFilename: "[id].bundle1.[hash:6].js"
|
||||
chunkFilename: "[id].bundle0.[hash:6].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 17
|
||||
expectedFilenameLength: 17,
|
||||
expectedChunkFilenameLength: 19
|
||||
}
|
||||
}, {
|
||||
name: "hash in publicPath",
|
||||
|
|
@ -17,7 +18,8 @@ module.exports = [{
|
|||
chunkFilename: "[id].bundle1.[hash].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 31
|
||||
expectedFilenameLength: 31,
|
||||
expectedChunkFilenameLength: 33
|
||||
}
|
||||
}, {
|
||||
name: "chunkhash with length",
|
||||
|
|
@ -26,7 +28,8 @@ module.exports = [{
|
|||
chunkFilename: "[id].bundle2.[chunkhash:8].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 19
|
||||
expectedFilenameLength: 19,
|
||||
expectedChunkFilenameLength: 21
|
||||
}
|
||||
}, {
|
||||
name: "chunkhash",
|
||||
|
|
@ -35,7 +38,8 @@ module.exports = [{
|
|||
chunkFilename: "[id].bundle3.[chunkhash].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 31
|
||||
expectedFilenameLength: 31,
|
||||
expectedChunkFilenameLength: 33
|
||||
}
|
||||
}, {
|
||||
name: "hash with and without length",
|
||||
|
|
@ -44,7 +48,8 @@ module.exports = [{
|
|||
chunkFilename: "[id].bundle4.[hash:8].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 31
|
||||
expectedFilenameLength: 31,
|
||||
expectedChunkFilenameLength: 21
|
||||
}
|
||||
}, {
|
||||
name: "hash with length",
|
||||
|
|
@ -53,7 +58,8 @@ module.exports = [{
|
|||
chunkFilename: "[id].bundle5.[hash:8].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 17
|
||||
expectedFilenameLength: 17,
|
||||
expectedChunkFilenameLength: 21
|
||||
}
|
||||
}, {
|
||||
name: "chunkhash in chunkFilename ",
|
||||
|
|
@ -62,12 +68,51 @@ module.exports = [{
|
|||
chunkFilename: "[id].bundle6.[chunkhash:7].js"
|
||||
},
|
||||
amd: {
|
||||
expectedFilenameLength: 31
|
||||
expectedFilenameLength: 31,
|
||||
expectedChunkFilenameLength: 20
|
||||
},
|
||||
plugins: [
|
||||
new webpack.HotModuleReplacementPlugin()
|
||||
]
|
||||
}];
|
||||
}, {
|
||||
name: "hash with length and chunkhash with length",
|
||||
output: {
|
||||
filename: "bundle7.[hash:7].js",
|
||||
chunkFilename: "[id].bundle7.[chunkhash:7].js"
|
||||
},
|
||||
target: "node",
|
||||
amd: {
|
||||
expectedFilenameLength: 18,
|
||||
expectedChunkFilenameLength: 20
|
||||
}
|
||||
}, {
|
||||
name: "hash with length in chunkFilename",
|
||||
output: {
|
||||
filename: "bundle8.[hash].js",
|
||||
chunkFilename: "[id].bundle8.[hash:7].js"
|
||||
|
||||
},
|
||||
target: "node",
|
||||
amd: {
|
||||
expectedFilenameLength: 31,
|
||||
expectedChunkFilenameLength: 20
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "chunkhash with length in chunkFilename",
|
||||
output: {
|
||||
filename: "bundle9.[hash].js",
|
||||
chunkFilename: "[id].bundle9.[chunkhash:7].js"
|
||||
|
||||
},
|
||||
target: "node",
|
||||
amd: {
|
||||
expectedFilenameLength: 31,
|
||||
expectedChunkFilenameLength: 20
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
module.exports.forEach(function(options) {
|
||||
options.plugins = options.plugins || [];
|
||||
options.plugins.push(new webpack.DefinePlugin({
|
||||
|
|
|
|||
Loading…
Reference in New Issue