Merge tag 'v4.29.5' into next

4.29.5
This commit is contained in:
Tobias Koppers 2019-02-19 08:58:46 +01:00
commit d34d69e62b
26 changed files with 658 additions and 636 deletions

View File

@ -1,8 +1,8 @@
# Ignore test fixtures
test
test/*.*
!test/*.js
!test/**/webpack.config.js
# Ignore example fixtures
examples
examples/*.*
!examples/**/webpack.config.js

2
declarations.d.ts vendored
View File

@ -192,7 +192,7 @@ declare module "@webassemblyjs/ast" {
export function global(globalType: string, nodes: Node[]): Global;
export function identifier(indentifier: string): Identifier;
export function funcParam(valType: string, id: Identifier): FuncParam;
export function instruction(inst: string, args: Node[]): Instruction;
export function instruction(inst: string, args?: Node[]): Instruction;
export function callInstruction(funcIndex: Index): CallInstruction;
export function objectInstruction(
kind: string,

View File

@ -180,9 +180,12 @@ const rewriteImportedGlobals = state => bin => {
globalType.mutability = "var";
const init = createDefaultInitForGlobal(globalType);
const init = [
createDefaultInitForGlobal(globalType),
t.instruction("end")
];
newGlobals.push(t.global(globalType, [init]));
newGlobals.push(t.global(globalType, init));
path.remove();
}
@ -199,7 +202,10 @@ const rewriteImportedGlobals = state => bin => {
const initialGlobalidx = init.args[0];
node.init = [createDefaultInitForGlobal(node.globalType)];
node.init = [
createDefaultInitForGlobal(node.globalType),
t.instruction("end")
];
additionalInitCode.push(
/**
@ -325,6 +331,8 @@ const addInitFunction = ({
funcBody.push(instr);
}
funcBody.push(t.instruction("end"));
const funcResults = [];
// Code section

View File

@ -5,10 +5,10 @@
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"license": "MIT",
"dependencies": {
"@webassemblyjs/ast": "1.7.11",
"@webassemblyjs/helper-module-context": "1.7.11",
"@webassemblyjs/wasm-edit": "1.7.11",
"@webassemblyjs/wasm-parser": "1.7.11",
"@webassemblyjs/ast": "1.8.3",
"@webassemblyjs/helper-module-context": "1.8.3",
"@webassemblyjs/wasm-edit": "1.8.3",
"@webassemblyjs/wasm-parser": "1.8.3",
"acorn": "^6.0.5",
"acorn-dynamic-import": "^4.0.0",
"ajv": "^6.1.0",

View File

@ -279,63 +279,57 @@ describe("BenchmarkTestCases", function() {
describe(`${testName} create benchmarks`, function() {
baselines.forEach(baseline => {
let baselineStats = null;
it(
`should benchmark ${baseline.name} (${baseline.rev})`,
function(done) {
const outputDirectory = path.join(
__dirname,
"js",
"benchmark",
`baseline-${baseline.name}`,
testName
);
const config =
Object.create(
require.requireActual(
path.join(testDirectory, "webpack.config.js")
)
) || {};
config.output = Object.create(config.output || {});
if (!config.context) config.context = testDirectory;
if (!config.output.path) config.output.path = outputDirectory;
runBenchmark(baseline.webpack, config, (err, stats) => {
if (err) return done(err);
process.stderr.write(` ${baseline.name} ${stats.text}`);
if (baseline.name === "HEAD") headStats = stats;
else baselineStats = stats;
done();
});
},
180000
);
it(
`should benchmark ${baseline.name} (${baseline.rev})`,
done => {
const outputDirectory = path.join(
__dirname,
"js",
"benchmark",
`baseline-${baseline.name}`,
testName
);
const config =
it(`should benchmark ${baseline.name} (${
baseline.rev
})`, function(done) {
const outputDirectory = path.join(
__dirname,
"js",
"benchmark",
`baseline-${baseline.name}`,
testName
);
const config =
Object.create(
require.requireActual(
path.join(testDirectory, "webpack.config.js")
) || {};
config.output = config.output || {};
if (!config.context) config.context = testDirectory;
if (!config.output.path) config.output.path = outputDirectory;
runBenchmark(baseline.webpack, config, (err, stats) => {
if (err) return done(err);
process.stderr.write(` ${baseline.name} ${stats.text}`);
if (baseline.name === "HEAD") headStats = stats;
else baselineStats = stats;
done();
});
},
180000
);
)
) || {};
config.output = Object.create(config.output || {});
if (!config.context) config.context = testDirectory;
if (!config.output.path) config.output.path = outputDirectory;
runBenchmark(baseline.webpack, config, (err, stats) => {
if (err) return done(err);
process.stderr.write(` ${baseline.name} ${stats.text}`);
if (baseline.name === "HEAD") headStats = stats;
else baselineStats = stats;
done();
});
}, 180000);
it(`should benchmark ${baseline.name} (${baseline.rev})`, done => {
const outputDirectory = path.join(
__dirname,
"js",
"benchmark",
`baseline-${baseline.name}`,
testName
);
const config =
require.requireActual(
path.join(testDirectory, "webpack.config.js")
) || {};
config.output = config.output || {};
if (!config.context) config.context = testDirectory;
if (!config.output.path) config.output.path = outputDirectory;
runBenchmark(baseline.webpack, config, (err, stats) => {
if (err) return done(err);
process.stderr.write(` ${baseline.name} ${stats.text}`);
if (baseline.name === "HEAD") headStats = stats;
else baselineStats = stats;
done();
});
}, 180000);
if (baseline.name !== "HEAD") {
it(`HEAD should not be slower than ${baseline.name} (${

View File

@ -571,9 +571,9 @@ describe("Compiler", () => {
output: {
path: "/",
filename: "bundle.js"
},
}
});
compiler.hooks.failed.tap('CompilerTest', failedSpy);
compiler.hooks.failed.tap("CompilerTest", failedSpy);
compiler.outputFileSystem = new MemoryFs();
compiler.run((err, stats) => {
expect(err).toBeTruthy();

View File

@ -256,7 +256,9 @@ describe("ConfigTestCases", () => {
const bundlePath = testConfig.findBundle(i, optionsArr[i]);
if (bundlePath) {
filesCount++;
results.push(_require(outputDirectory, optionsArr[i], bundlePath));
results.push(
_require(outputDirectory, optionsArr[i], bundlePath)
);
}
}
// give a free pass to compilation that generated an error
@ -269,12 +271,16 @@ describe("ConfigTestCases", () => {
"Should have found at least one bundle file per webpack config"
)
);
Promise.all(results).then(() => {
if (getNumberOfTests() < filesCount)
return done(new Error("No tests exported by test case"));
if (testConfig.afterExecute) testConfig.afterExecute();
done();
}).catch(done);
Promise.all(results)
.then(() => {
if (getNumberOfTests() < filesCount)
return done(
new Error("No tests exported by test case")
);
if (testConfig.afterExecute) testConfig.afterExecute();
done();
})
.catch(done);
});
})
);

View File

@ -100,10 +100,7 @@ describe("HotModuleReplacementPlugin", () => {
it("should correct working when entry is Object and key is a number", done => {
const outputPath = path.join(__dirname, "js", "HotModuleReplacementPlugin");
const entryFile = path.join(
outputPath,
"entry.js"
);
const entryFile = path.join(outputPath, "entry.js");
const statsFile3 = path.join(
outputPath,
"HotModuleReplacementPlugin.test.stats3.txt"
@ -112,10 +109,7 @@ describe("HotModuleReplacementPlugin", () => {
outputPath,
"HotModuleReplacementPlugin.test.stats4.txt"
);
const recordsFile = path.join(
outputPath,
"records.json"
);
const recordsFile = path.join(outputPath, "records.json");
try {
mkdirp.sync(outputPath);
} catch (e) {
@ -156,7 +150,10 @@ describe("HotModuleReplacementPlugin", () => {
if (err) throw err;
fs.writeFileSync(statsFile3, stats.toString());
const result = JSON.parse(
fs.readFileSync(path.join(outputPath, `${hash}.hot-update.json`), "utf-8")
fs.readFileSync(
path.join(outputPath, `${hash}.hot-update.json`),
"utf-8"
)
)["c"];
expect(result).toEqual([chunkName]);
done();

View File

@ -48,7 +48,10 @@ const describeCases = config => {
const fakeUpdateLoaderOptions = {
updateIndex: 0
};
const configPath = path.join(testDirectory, "webpack.config.js");
const configPath = path.join(
testDirectory,
"webpack.config.js"
);
let options = {};
if (fs.existsSync(configPath)) options = require(configPath);
if (!options.mode) options.mode = "development";
@ -113,13 +116,15 @@ const describeCases = config => {
}
const window = {
fetch: (url) => {
fetch: url => {
return Promise.resolve({
ok: true,
json() {
return Promise.resolve(require(path.resolve(outputDirectory, url)));
return Promise.resolve(
require(path.resolve(outputDirectory, url))
);
}
})
});
},
importScripts: url => {
_require("./" + url);
@ -136,7 +141,7 @@ const describeCases = config => {
},
head: {
appendChild(element) {
if(element._type === "script") {
if (element._type === "script") {
// run it
Promise.resolve().then(() => {
_require("./" + element.src);
@ -145,7 +150,7 @@ const describeCases = config => {
}
},
getElementsByTagName(name) {
if(name === "head") return [this.head];
if (name === "head") return [this.head];
throw new Error("Not supported");
}
}
@ -189,38 +194,38 @@ const describeCases = config => {
function _require(module) {
if (module.substr(0, 2) === "./") {
const p = path.join(outputDirectory, module);
if(module.endsWith(".json")) {
if (module.endsWith(".json")) {
return JSON.parse(fs.readFileSync(p, "utf-8"));
} else {
const fn = vm.runInThisContext(
"(function(require, module, exports, __dirname, __filename, it, expect, self, window, fetch, document, importScripts, NEXT, STATS) {" +
"global.expect = expect;" +
'function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }' +
fs.readFileSync(p, "utf-8") +
"\n})",
p
);
const m = {
exports: {}
};
fn.call(
m.exports,
_require,
m,
m.exports,
outputDirectory,
p,
_it,
expect,
window,
window,
window.fetch,
window.document,
window.importScripts,
_next,
jsonStats
);
return m.exports;
const fn = vm.runInThisContext(
"(function(require, module, exports, __dirname, __filename, it, expect, self, window, fetch, document, importScripts, NEXT, STATS) {" +
"global.expect = expect;" +
'function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }' +
fs.readFileSync(p, "utf-8") +
"\n})",
p
);
const m = {
exports: {}
};
fn.call(
m.exports,
_require,
m,
m.exports,
outputDirectory,
p,
_it,
expect,
window,
window,
window.fetch,
window.document,
window.importScripts,
_next,
jsonStats
);
return m.exports;
}
} else return require(module);
}

View File

@ -6,21 +6,24 @@ const MemoryFs = require("memory-fs");
describe("MultiStats", () => {
it("should create JSON of children stats", done => {
const compiler = webpack([{
context: __dirname,
entry: "./fixtures/a"
},{
context: __dirname,
entry: "./fixtures/b"
}]);
const compiler = webpack([
{
context: __dirname,
entry: "./fixtures/a"
},
{
context: __dirname,
entry: "./fixtures/b"
}
]);
compiler.outputFileSystem = new MemoryFs();
compiler.run((err, stats) => {
if (err) return done(err);
try {
const statsObject = stats.toJson();
expect(
statsObject
).toEqual(expect.objectContaining({children: expect.any(Array)}));
expect(statsObject).toEqual(
expect.objectContaining({ children: expect.any(Array) })
);
expect(statsObject.children).toHaveLength(2);
done();
} catch (e) {

View File

@ -129,7 +129,10 @@ describe("StatsTestCases", () => {
);
}
const testPath = path.join(base, testName);
const testPathPattern = testPath.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
const testPathPattern = testPath.replace(
/[-[\]\\/{}()*+?.^$|]/g,
"\\$&"
);
actual = actual
.replace(/\r\n?/g, "\n")
.replace(/[\t ]*Version:.+\n/g, "")

View File

@ -3,32 +3,34 @@ const fs = require("fs");
const path = require("path");
const check = (expected, actual) => {
if(expected instanceof RegExp) {
if (expected instanceof RegExp) {
expected = { message: expected };
}
return Object.keys(expected).every(key => {
let value = actual[key];
if(typeof value === "object") {
if (typeof value === "object") {
value = JSON.stringify(value);
}
return expected[key].test(value);
})
}
});
};
const explain = object => {
if(object instanceof RegExp) {
if (object instanceof RegExp) {
object = { message: object };
}
return Object.keys(object).map(key => {
let value = object[key];
if(typeof value === "object" && !(value instanceof RegExp)) {
value = JSON.stringify(value);
}
let msg = `${key} = ${value}`
if(msg.length > 100) msg = msg.slice(0, 97) + "...";
return msg;
}).join("; ");
}
return Object.keys(object)
.map(key => {
let value = object[key];
if (typeof value === "object" && !(value instanceof RegExp)) {
value = JSON.stringify(value);
}
let msg = `${key} = ${value}`;
if (msg.length > 100) msg = msg.slice(0, 97) + "...";
return msg;
})
.join("; ");
};
module.exports = function checkArrayExpectation(
testDirectory,
@ -45,7 +47,7 @@ module.exports = function checkArrayExpectation(
}
let array = object[`${kind}s`];
if (Array.isArray(array)) {
if (kind === "warning"){
if (kind === "warning") {
array = array.filter(item => !/from Terser/.test(item));
}
}
@ -56,9 +58,9 @@ module.exports = function checkArrayExpectation(
return (
done(
new Error(
`More ${kind}s while compiling than expected:\n\n${array.map(explain).join(
"\n\n"
)}. Check expected ${kind}s: ${expectedFilename}`
`More ${kind}s while compiling than expected:\n\n${array
.map(explain)
.join("\n\n")}. Check expected ${kind}s: ${expectedFilename}`
)
),
true
@ -67,9 +69,9 @@ module.exports = function checkArrayExpectation(
return (
done(
new Error(
`Less ${kind}s while compiling than expected:\n\n${array.map(explain).join(
"\n\n"
)}. Check expected ${kind}s: ${expectedFilename}`
`Less ${kind}s while compiling than expected:\n\n${array
.map(explain)
.join("\n\n")}. Check expected ${kind}s: ${expectedFilename}`
)
),
true
@ -82,9 +84,9 @@ module.exports = function checkArrayExpectation(
return (
done(
new Error(
`${upperCaseKind} ${i}: ${explain(array[i])} doesn't match ${explain(expected[
i
][j])}`
`${upperCaseKind} ${i}: ${explain(
array[i]
)} doesn't match ${explain(expected[i][j])}`
)
),
true
@ -95,9 +97,9 @@ module.exports = function checkArrayExpectation(
return (
done(
new Error(
`${upperCaseKind} ${i}: ${explain(array[i])} doesn't match ${explain(expected[
i
])}`
`${upperCaseKind} ${i}: ${explain(
array[i]
)} doesn't match ${explain(expected[i])}`
)
),
true
@ -106,7 +108,11 @@ module.exports = function checkArrayExpectation(
} else if (array.length > 0) {
return (
done(
new Error(`${upperCaseKind}s while compiling:\n\n${array.map(explain).join("\n\n")}`)
new Error(
`${upperCaseKind}s while compiling:\n\n${array
.map(explain)
.join("\n\n")}`
)
),
true
);

View File

@ -80,9 +80,7 @@ module.exports = {
.sort((a, b) => a[0] - b[0])
.map(
([i, m]) =>
`${i}: ${m.readableIdentifier(
compilation.requestShortener
)}`
`${i}: ${m.readableIdentifier(compilation.requestShortener)}`
)
.join(", ");
const indicies2 = Array.from(compilation.modules)
@ -91,9 +89,7 @@ module.exports = {
.sort((a, b) => a[0] - b[0])
.map(
([i, m]) =>
`${i}: ${m.readableIdentifier(
compilation.requestShortener
)}`
`${i}: ${m.readableIdentifier(compilation.requestShortener)}`
)
.join(", ");
expect(indicies).toEqual(

View File

@ -8,28 +8,27 @@ module.exports = {
plugins: [
function() {
this.hooks.compilation.tap("Test", compilation => {
compilation.hooks.dependencyReference.tap(
"Test",
(ref, dep) => {
const module = compilation.moduleGraph.getParentModule(dep);
if (
module.identifier().endsWith("module.js") &&
ref.module &&
ref.module.identifier().endsWith("reference.js") &&
Array.isArray(ref.importedNames) &&
ref.importedNames.includes("unused")
) {
const newExports = ref.importedNames.filter(item => item !== "unused");
return new DependencyReference(
() => ref.module,
newExports.length > 0 ? newExports : false,
ref.weak,
ref.order
);
}
return ref;
compilation.hooks.dependencyReference.tap("Test", (ref, dep) => {
const module = compilation.moduleGraph.getParentModule(dep);
if (
module.identifier().endsWith("module.js") &&
ref.module &&
ref.module.identifier().endsWith("reference.js") &&
Array.isArray(ref.importedNames) &&
ref.importedNames.includes("unused")
) {
const newExports = ref.importedNames.filter(
item => item !== "unused"
);
return new DependencyReference(
() => ref.module,
newExports.length > 0 ? newExports : false,
ref.weak,
ref.order
);
}
);
return ref;
});
});
}
]

View File

@ -8,28 +8,27 @@ module.exports = {
plugins: [
function() {
this.hooks.compilation.tap("Test", compilation => {
compilation.hooks.dependencyReference.tap(
"Test",
(ref, dep) => {
const module = compilation.moduleGraph.getParentModule(dep);
if (
module.identifier().endsWith("module.js") &&
ref.module &&
ref.module.identifier().endsWith("reference.js") &&
Array.isArray(ref.importedNames) &&
ref.importedNames.includes("unused")
) {
const newExports = ref.importedNames.filter(item => item !== "unused");
return new DependencyReference(
() => ref.module,
newExports.length > 0 ? newExports : false,
ref.weak,
ref.order
);
}
return ref;
compilation.hooks.dependencyReference.tap("Test", (ref, dep) => {
const module = compilation.moduleGraph.getParentModule(dep);
if (
module.identifier().endsWith("module.js") &&
ref.module &&
ref.module.identifier().endsWith("reference.js") &&
Array.isArray(ref.importedNames) &&
ref.importedNames.includes("unused")
) {
const newExports = ref.importedNames.filter(
item => item !== "unused"
);
return new DependencyReference(
() => ref.module,
newExports.length > 0 ? newExports : false,
ref.weak,
ref.order
);
}
);
return ref;
});
});
}
]

View File

@ -1,4 +1,4 @@
const Compiler = require('../../../../lib/Compiler');
const Compiler = require("../../../../lib/Compiler");
module.exports = {
optimization: {
@ -7,12 +7,12 @@ module.exports = {
{
apply(compiler) {
expect(compiler).toBeInstanceOf(Compiler);
},
}
},
function(compiler) {
expect(compiler).toBe(this);
expect(compiler).toBeInstanceOf(Compiler);
}
],
},
]
}
};

View File

@ -11,13 +11,10 @@ module.exports = {
{
apply: compiler => {
compiler.hooks.compilation.tap("CustomPlugin", compilation => {
compilation.hooks.optimize.tap(
"CustomPlugin",
() => {
const reportProgress = webpack.ProgressPlugin.getReporter(compiler);
reportProgress(0, "custom category", "custom message");
}
);
compilation.hooks.optimize.tap("CustomPlugin", () => {
const reportProgress = webpack.ProgressPlugin.getReporter(compiler);
reportProgress(0, "custom category", "custom message");
});
});
}
}

View File

@ -1,3 +1,3 @@
module.exports = {
mode: 'development',
mode: "development"
};

View File

@ -8,7 +8,7 @@ module.exports = {
"./module": {
id: 1,
buildMeta: {
exportsType: "namespace",
exportsType: "namespace"
},
exports: ["default"]
}

View File

@ -34,7 +34,7 @@ module.exports = [
test: /node_modules/,
name: m => {
const match = m.nameForCondition().match(/([b-d]+)\.js$/);
if(match) return "vendors-" + match[1];
if (match) return "vendors-" + match[1];
}
}
}

View File

@ -43,16 +43,11 @@ describe("util/identifier", () => {
"c:\\some\\\\dir\\to\\\\somewhere|some/other/dir!../more/dir",
"./to/somewhere|some/other/dir!../more/dir"
],
[
"/dir",
"/dir/to/somewhere??ref-123",
"./to/somewhere??ref-123"
]
["/dir", "/dir/to/somewhere??ref-123", "./to/somewhere??ref-123"]
].forEach(([context, pathConstruct, expected]) => {
expect(identifierUtil.makePathsRelative(context, pathConstruct)).toBe(
expected
);
expect(identifierUtil.makePathsRelative(context, pathConstruct)).toBe(
expected
);
});
});
});

View File

@ -52,44 +52,55 @@ if (process.env.ALTERNATIVE_SORT) {
}
// Setup debugging info for tests
if(process.env.DEBUG_INFO) {
const addDebugInfo = (it) => {
if (process.env.DEBUG_INFO) {
const addDebugInfo = it => {
return (name, fn, timeout) => {
if(fn.length === 0) {
it(name, () => {
process.stdout.write(`START1 ${name}\n`);
try {
const promise = fn();
if(promise && promise.then) {
return promise.then(r => {
if (fn.length === 0) {
it(
name,
() => {
process.stdout.write(`START1 ${name}\n`);
try {
const promise = fn();
if (promise && promise.then) {
return promise.then(
r => {
process.stdout.write(`DONE OK ${name}\n`);
return r;
},
e => {
process.stdout.write(`DONE FAIL ${name}\n`);
throw e;
}
);
} else {
process.stdout.write(`DONE OK ${name}\n`);
return r;
}, e => {
process.stdout.write(`DONE FAIL ${name}\n`);
throw e;
});
} else {
process.stdout.write(`DONE OK ${name}\n`);
}
} catch(e) {
process.stdout.write(`DONE FAIL ${name}\n`);
throw e;
}
}, timeout);
} else {
it(name, done => {
process.stdout.write(`START2 ${name}\n`);
return fn(err => {
if(err) {
}
} catch (e) {
process.stdout.write(`DONE FAIL ${name}\n`);
} else {
process.stdout.write(`DONE OK ${name}\n`);
throw e;
}
return done(err);
})
}, timeout)
},
timeout
);
} else {
it(
name,
done => {
process.stdout.write(`START2 ${name}\n`);
return fn(err => {
if (err) {
process.stdout.write(`DONE FAIL ${name}\n`);
} else {
process.stdout.write(`DONE OK ${name}\n`);
}
return done(err);
});
},
timeout
);
}
}
};
};
const env = jasmine.getEnv();
env.it = addDebugInfo(env.it);
@ -101,4 +112,3 @@ if(process.env.DEBUG_INFO) {
require("wast-loader");
process.removeAllListeners("uncaughtException");
process.removeAllListeners("unhandledRejection");

View File

@ -3,6 +3,6 @@ module.exports = {
entry: "./index",
stats: {
modules: true,
reasons: true,
reasons: true
}
};

View File

@ -122,5 +122,5 @@ module.exports = [
}
},
stats
},
}
];

View File

@ -8,12 +8,9 @@ const valueFile = path.resolve(
module.exports = {
plugins: [
new webpack.DefinePlugin({
TEST_VALUE: webpack.DefinePlugin.runtimeValue(
() => {
return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim());
},
[valueFile]
),
TEST_VALUE: webpack.DefinePlugin.runtimeValue(() => {
return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim());
}, [valueFile]),
TEST_VALUE2: webpack.DefinePlugin.runtimeValue(() => {
return JSON.stringify(fs.readFileSync(valueFile, "utf-8").trim());
}, []),

735
yarn.lock

File diff suppressed because it is too large Load Diff