From 64db3064c76b52dec070e113998415b9b5e65430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 2 May 2018 18:12:24 +0800 Subject: [PATCH 001/111] docs(examples): add yarn add webpack-cli step Running node_modules/bin/webpack without webpack-cli installed will get hang. The culprit is that webpack expects a stdin of whether to install webpack-cli or not. However, as examples/build-common use `child_process.exec` to execute `webpack`, the user will not be prompted for any questions since the stdin is not piped and the stdout will be pass to parent process only after the child process exits. We can keep build-common simple by instructing devs to install webpack-cli before they build examples. Also rewrite the install step using yarn since we use yarn in webpack. --- examples/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/README.md b/examples/README.md index 3ab122edd5f..6407710e237 100644 --- a/examples/README.md +++ b/examples/README.md @@ -120,8 +120,9 @@ If you think an example is missing, please report it as issue. :) # Building an Example -1. Run `npm install` in the root of the project. -2. Run `npm link webpack` in the root of the project. -3. Run `node build.js` in the specific example directory. (Ex: `cd examples/commonjs && node build.js`) +1. Run `yarn` in the root of the project. +2. Run `yarn link webpack` in the root of the project. +3. Run `yarn add --dev webpack-cli` in the root of the project. +4. Run `node build.js` in the specific example directory. (Ex: `cd examples/commonjs && node build.js`) Note: To build all examples run `npm run build:examples` From d50f00db879d2e8ec5dd636386197561d4356f8d Mon Sep 17 00:00:00 2001 From: byzyk Date: Thu, 3 May 2018 15:48:17 +0400 Subject: [PATCH 002/111] fix: allow array of strings for library.root --- schemas/WebpackOptions.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index 15b17c0461b..6576e1494e6 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -492,7 +492,14 @@ "properties": { "root": { "description": "Name of the property exposed globally by a UMD library", - "type": "string" + "anyOf": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/common.arrayOfStringValues" + } + ] }, "amd": { "description": "Name of the exposed AMD library in the UMD", From 470663ae1cebe6ba40c763ededf3a540abe3e4bf Mon Sep 17 00:00:00 2001 From: byzyk Date: Thu, 3 May 2018 17:40:58 +0400 Subject: [PATCH 003/111] add prettierignore file --- .prettierignore | 14 ++++++++++++++ package.json | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000000..1d89e6bbbc7 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,14 @@ +# Ignore all paths. +**/*.* + +# Enable prettier for the following paths. +!setup/**/*.js +!lib/**/*.js +!bin/*.js +!hot/*.js +!buildin/*.js +!test/*.js +!test/**/webpack.config.js +!examples/**/webpack.config.js +!schemas/**/*.js +!declarations.d.ts diff --git a/package.json b/package.json index f38f0c4a3e9..7101f65858e 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "code-lint": "eslint setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", "type-lint": "tsc --pretty", "fix": "yarn code-lint --fix", - "pretty": "prettier \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" \"declarations.d.ts\" --write", + "pretty": "prettier --write \"**/*.{js,ts}\"", "schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", "cover": "yarn cover:init && yarn cover:all && yarn cover:report", From 6a919ba8ddfcd7b12aa1080d523fe5f7dfcd30af Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Fri, 20 Apr 2018 17:51:40 -0600 Subject: [PATCH 004/111] chore(types): add type support for Template base class --- lib/Chunk.js | 1 + lib/Module.js | 6 +++--- lib/Template.js | 15 +++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Chunk.js b/lib/Chunk.js index 306697fd907..f0c6f3902dd 100644 --- a/lib/Chunk.js +++ b/lib/Chunk.js @@ -128,6 +128,7 @@ class Chunk { this.chunkReason = undefined; /** @type {boolean} */ this.extraAsync = false; + this.removedModules = undefined; } /** diff --git a/lib/Module.js b/lib/Module.js index 057e767bfac..72f25857225 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -11,8 +11,8 @@ const ModuleReason = require("./ModuleReason"); const SortableSet = require("./util/SortableSet"); const Template = require("./Template"); -/** @typedef {typeof import("./Chunk")} Chunk */ -/** @typedef {typeof import("./RequestShortener")} RequestShortener */ +/** @typedef {import("./Chunk")} Chunk */ +/** @typedef {import("./RequestShortener")} RequestShortener */ const EMPTY_RESOLVE_OPTIONS = {}; @@ -69,7 +69,7 @@ class Module extends DependenciesBlock { this._chunks = new SortableSet(undefined, sortById); // Info from Compilation (per Compilation) - /** @type {number | string} */ + /** @type {number|string} */ this.id = null; /** @type {number} */ this.index = null; diff --git a/lib/Template.js b/lib/Template.js index 59089c2e96a..7c6e6e33b00 100644 --- a/lib/Template.js +++ b/lib/Template.js @@ -44,10 +44,8 @@ const stringifyIdSortPredicate = (a, b) => { return 0; }; -//TODO: Change type to Module when import works -//https://github.com/Microsoft/TypeScript/issues/23375 /** - * @param {HasId} module the module to compare against + * @param {Module} module the module to compare against * @return {boolean} return true if module.id is equal to type "number" */ const moduleIdIsNumber = module => { @@ -133,7 +131,7 @@ class Template { /** * - * @param {string | string[]} str string to convert to identity + * @param {string[] | string} str string to convert to identity * @return {string} converted identity */ static indent(str) { @@ -177,17 +175,19 @@ class Template { /** * - * @param {HasId[]} modules - a collection of modules to get array bounds for + * @param {Module[]} modules a collection of modules to get array bounds for * @return {[number, number] | false} returns the upper and lower array bounds * or false if not every module has a number based id */ static getModulesArrayBounds(modules) { + // Typeguards don't work for .every() with predicate functions + // https://github.com/Microsoft/TypeScript/issues/23799 if (!modules.every(moduleIdIsNumber)) return false; var maxId = -Infinity; var minId = Infinity; for (const module of modules) { - if (maxId < module.id) maxId = module.id; - if (minId > module.id) minId = module.id; + if (maxId < module.id) maxId = /** @type {number} */ (module.id); + if (minId > module.id) minId = /** @type {number} */ (module.id); } if (minId < 16 + ("" + minId).length) { // add minId x ',' instead of 'Array(minId).concat(…)' @@ -206,7 +206,6 @@ class Template { } /** - * * @param {Chunk} chunk chunk whose modules will be rendered * @param {ModuleFilterPredicate} filterFn function used to filter modules from chunk to render * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance used to render modules From a3d3af88a53d1917780ec977b1edd899b3e79d93 Mon Sep 17 00:00:00 2001 From: byzyk Date: Fri, 4 May 2018 15:32:49 +0400 Subject: [PATCH 005/111] add test --- .../configCases/library/umd/webpack.config.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/configCases/library/umd/webpack.config.js b/test/configCases/library/umd/webpack.config.js index 4ce89d69c0a..16b6c9cb6bc 100644 --- a/test/configCases/library/umd/webpack.config.js +++ b/test/configCases/library/umd/webpack.config.js @@ -1,10 +1,22 @@ -module.exports = { - output: { - libraryTarget: "umd", - library: { - root: "testLibrary", - amd: "test-library", - commonjs: "test-library" +module.exports = [ + { + output: { + libraryTarget: "umd", + library: { + root: "testLibrary", + amd: "test-library", + commonjs: "test-library" + } + } + }, + { + output: { + libraryTarget: "umd", + library: { + root: ["test", "library"], + amd: "test-library", + commonjs: "test-library" + } } } -}; +]; From 71b05f9f832654d10a9972d5c3b8c048cf926d3e Mon Sep 17 00:00:00 2001 From: byzyk Date: Fri, 4 May 2018 16:00:18 +0400 Subject: [PATCH 006/111] move test to separate folder --- test/configCases/library/umd-array/index.js | 3 ++ .../library/umd-array/webpack.config.js | 10 +++++++ .../configCases/library/umd/webpack.config.js | 28 ++++++------------- 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 test/configCases/library/umd-array/index.js create mode 100644 test/configCases/library/umd-array/webpack.config.js diff --git a/test/configCases/library/umd-array/index.js b/test/configCases/library/umd-array/index.js new file mode 100644 index 00000000000..9970130cc2c --- /dev/null +++ b/test/configCases/library/umd-array/index.js @@ -0,0 +1,3 @@ +it("should run", function() { + +}); \ No newline at end of file diff --git a/test/configCases/library/umd-array/webpack.config.js b/test/configCases/library/umd-array/webpack.config.js new file mode 100644 index 00000000000..fba3d5e17a1 --- /dev/null +++ b/test/configCases/library/umd-array/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + output: { + libraryTarget: "umd", + library: { + root: ["test", "library"], + amd: "test-library", + commonjs: "test-library" + } + } +}; diff --git a/test/configCases/library/umd/webpack.config.js b/test/configCases/library/umd/webpack.config.js index 16b6c9cb6bc..4ce89d69c0a 100644 --- a/test/configCases/library/umd/webpack.config.js +++ b/test/configCases/library/umd/webpack.config.js @@ -1,22 +1,10 @@ -module.exports = [ - { - output: { - libraryTarget: "umd", - library: { - root: "testLibrary", - amd: "test-library", - commonjs: "test-library" - } - } - }, - { - output: { - libraryTarget: "umd", - library: { - root: ["test", "library"], - amd: "test-library", - commonjs: "test-library" - } +module.exports = { + output: { + libraryTarget: "umd", + library: { + root: "testLibrary", + amd: "test-library", + commonjs: "test-library" } } -]; +}; From ed9d0246d5186333435a225f473474352b9b406c Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Wed, 9 May 2018 11:32:06 +0200 Subject: [PATCH 007/111] Add typings for various library template plugins --- lib/AmdMainTemplatePlugin.js | 10 +++ lib/ExportPropertyMainTemplatePlugin.js | 13 ++++ lib/LibraryTemplatePlugin.js | 99 ++++++++++++++++--------- lib/SetVarMainTemplatePlugin.js | 12 +++ lib/UmdMainTemplatePlugin.js | 49 +++++++++--- 5 files changed, 140 insertions(+), 43 deletions(-) diff --git a/lib/AmdMainTemplatePlugin.js b/lib/AmdMainTemplatePlugin.js index 72f23027d9d..b950ed5e08f 100644 --- a/lib/AmdMainTemplatePlugin.js +++ b/lib/AmdMainTemplatePlugin.js @@ -8,11 +8,21 @@ const { ConcatSource } = require("webpack-sources"); const Template = require("./Template"); +/** @typedef {import("./Compilation")} Compilation */ + class AmdMainTemplatePlugin { + /** + * @param {string} name the library name + */ constructor(name) { + /** @type {string} */ this.name = name; } + /** + * @param {Compilation} compilation the compilation instance + * @returns {void} + */ apply(compilation) { const { mainTemplate, chunkTemplate } = compilation; diff --git a/lib/ExportPropertyMainTemplatePlugin.js b/lib/ExportPropertyMainTemplatePlugin.js index 28d119e5f42..90df031aabb 100644 --- a/lib/ExportPropertyMainTemplatePlugin.js +++ b/lib/ExportPropertyMainTemplatePlugin.js @@ -6,15 +6,28 @@ const { ConcatSource } = require("webpack-sources"); +/** @typedef {import("./Compilation")} Compilation */ + +/** + * @param {string[]} accessor the accessor to convert to path + * @returns {string} the path + */ const accessorToObjectAccess = accessor => { return accessor.map(a => `[${JSON.stringify(a)}]`).join(""); }; class ExportPropertyMainTemplatePlugin { + /** + * @param {string|string[]} property the name of the property to export + */ constructor(property) { this.property = property; } + /** + * @param {Compilation} compilation the compilation instance + * @returns {void} + */ apply(compilation) { const { mainTemplate, chunkTemplate } = compilation; diff --git a/lib/LibraryTemplatePlugin.js b/lib/LibraryTemplatePlugin.js index 88c342cffe8..cc7c828e180 100644 --- a/lib/LibraryTemplatePlugin.js +++ b/lib/LibraryTemplatePlugin.js @@ -6,30 +6,45 @@ const SetVarMainTemplatePlugin = require("./SetVarMainTemplatePlugin"); +/** @typedef {import("./Compiler")} Compiler */ + +/** + * @param {string[]} accessor the accessor to convert to path + * @returns {string} the path + */ const accessorToObjectAccess = accessor => { - return accessor - .map(a => { - return `[${JSON.stringify(a)}]`; - }) - .join(""); + return accessor.map(a => `[${JSON.stringify(a)}]`).join(""); }; -const accessorAccess = (base, accessor, joinWith) => { - accessor = [].concat(accessor); - return accessor - .map((a, idx) => { - a = base - ? base + accessorToObjectAccess(accessor.slice(0, idx + 1)) - : accessor[0] + accessorToObjectAccess(accessor.slice(1, idx + 1)); - if (idx === accessor.length - 1) return a; +/** + * @param {string=} base the path prefix + * @param {string|string[]} accessor the accessor + * @param {string=} joinWith the element separator + * @returns {string} the path + */ +const accessorAccess = (base, accessor, joinWith = "; ") => { + const accessors = Array.isArray(accessor) ? accessor : [accessor]; + return accessors + .map((_, idx) => { + const a = base + ? base + accessorToObjectAccess(accessors.slice(0, idx + 1)) + : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1)); + if (idx === accessors.length - 1) return a; if (idx === 0 && typeof base === "undefined") return `${a} = typeof ${a} === "object" ? ${a} : {}`; return `${a} = ${a} || {}`; }) - .join(joinWith || "; "); + .join(joinWith); }; class LibraryTemplatePlugin { + /** + * @param {string} name name of library + * @param {string} target type of library + * @param {boolean} umdNamedDefine setting this to true will name the UMD module + * @param {string|TODO} auxiliaryComment comment in the UMD wrapper + * @param {string|string[]} exportProperty which export should be exposed as library + */ constructor(name, target, umdNamedDefine, auxiliaryComment, exportProperty) { this.name = name; this.target = target; @@ -38,10 +53,14 @@ class LibraryTemplatePlugin { this.exportProperty = exportProperty; } + /** + * @param {Compiler} compiler the compiler instance + * @returns {void} + */ apply(compiler) { compiler.hooks.thisCompilation.tap("LibraryTemplatePlugin", compilation => { if (this.exportProperty) { - var ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin"); + const ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin"); new ExportPropertyMainTemplatePlugin(this.exportProperty).apply( compilation ); @@ -49,66 +68,80 @@ class LibraryTemplatePlugin { switch (this.target) { case "var": new SetVarMainTemplatePlugin( - `var ${accessorAccess(false, this.name)}` + `var ${accessorAccess(undefined, this.name)}`, + false ).apply(compilation); break; case "assign": new SetVarMainTemplatePlugin( - accessorAccess(undefined, this.name) + accessorAccess(undefined, this.name), + false ).apply(compilation); break; case "this": case "self": case "window": - if (this.name) + if (this.name) { new SetVarMainTemplatePlugin( - accessorAccess(this.target, this.name) + accessorAccess(this.target, this.name), + false ).apply(compilation); - else + } else { new SetVarMainTemplatePlugin(this.target, true).apply(compilation); + } break; case "global": - if (this.name) + if (this.name) { new SetVarMainTemplatePlugin( accessorAccess( compilation.runtimeTemplate.outputOptions.globalObject, this.name - ) + ), + false ).apply(compilation); - else + } else { new SetVarMainTemplatePlugin( compilation.runtimeTemplate.outputOptions.globalObject, true ).apply(compilation); + } break; case "commonjs": - if (this.name) + if (this.name) { new SetVarMainTemplatePlugin( - accessorAccess("exports", this.name) + accessorAccess("exports", this.name), + false ).apply(compilation); - else new SetVarMainTemplatePlugin("exports", true).apply(compilation); + } else { + new SetVarMainTemplatePlugin("exports", true).apply(compilation); + } break; case "commonjs2": case "commonjs-module": - new SetVarMainTemplatePlugin("module.exports").apply(compilation); + new SetVarMainTemplatePlugin("module.exports", false).apply( + compilation + ); break; - case "amd": - var AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin"); + case "amd": { + const AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin"); new AmdMainTemplatePlugin(this.name).apply(compilation); break; + } case "umd": - case "umd2": - var UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin"); + case "umd2": { + const UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin"); new UmdMainTemplatePlugin(this.name, { optionalAmdExternalAsGlobal: this.target === "umd2", namedDefine: this.umdNamedDefine, auxiliaryComment: this.auxiliaryComment }).apply(compilation); break; - case "jsonp": - var JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin"); + } + case "jsonp": { + const JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin"); new JsonpExportMainTemplatePlugin(this.name).apply(compilation); break; + } default: throw new Error(`${this.target} is not a valid Library target`); } diff --git a/lib/SetVarMainTemplatePlugin.js b/lib/SetVarMainTemplatePlugin.js index 441a585d2c5..63db2821a54 100644 --- a/lib/SetVarMainTemplatePlugin.js +++ b/lib/SetVarMainTemplatePlugin.js @@ -6,12 +6,24 @@ const { ConcatSource } = require("webpack-sources"); +/** @typedef {import("./Compilation")} Compilation */ + class SetVarMainTemplatePlugin { + /** + * @param {string} varExpression the accessor where the library is exported + * @param {boolean} copyObject specify copying the exports + */ constructor(varExpression, copyObject) { + /** @type {string} */ this.varExpression = varExpression; + /** @type {boolean} */ this.copyObject = copyObject; } + /** + * @param {Compilation} compilation the compilation instance + * @returns {void} + */ apply(compilation) { const { mainTemplate, chunkTemplate } = compilation; diff --git a/lib/UmdMainTemplatePlugin.js b/lib/UmdMainTemplatePlugin.js index 8f1ea5799c4..2cc6626a9df 100644 --- a/lib/UmdMainTemplatePlugin.js +++ b/lib/UmdMainTemplatePlugin.js @@ -7,22 +7,47 @@ const { ConcatSource, OriginalSource } = require("webpack-sources"); const Template = require("./Template"); -function accessorToObjectAccess(accessor) { +/** @typedef {import("./Compilation")} Compilation */ + +/** + * @param {string[]} accessor the accessor to convert to path + * @returns {string} the path + */ +const accessorToObjectAccess = accessor => { return accessor.map(a => `[${JSON.stringify(a)}]`).join(""); -} +}; -function accessorAccess(base, accessor) { - accessor = [].concat(accessor); - return accessor - .map((a, idx) => { - a = base + accessorToObjectAccess(accessor.slice(0, idx + 1)); - if (idx === accessor.length - 1) return a; +/** + * @param {string=} base the path prefix + * @param {string|string[]} accessor the accessor + * @param {string=} joinWith the element separator + * @returns {string} the path + */ +const accessorAccess = (base, accessor, joinWith = "; ") => { + const accessors = Array.isArray(accessor) ? accessor : [accessor]; + return accessors + .map((_, idx) => { + const a = base + ? base + accessorToObjectAccess(accessors.slice(0, idx + 1)) + : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1)); + if (idx === accessors.length - 1) return a; + if (idx === 0 && typeof base === "undefined") + return `${a} = typeof ${a} === "object" ? ${a} : {}`; return `${a} = ${a} || {}`; }) - .join(", "); -} + .join(joinWith); +}; + +/** + * @typedef {string | string[] | {[k: string]: string | string[]}} UmdMainTemplatePluginName + * @typedef {{optionalAmdExternalAsGlobal: boolean, namedDefine: boolean, auxiliaryComment: TODO}} UmdMainTemplatePluginOption + */ class UmdMainTemplatePlugin { + /** + * @param {UmdMainTemplatePluginName} name the name of the UMD library + * @param {UmdMainTemplatePluginOption} options the plugin option + */ constructor(name, options) { if (typeof name === "object" && !Array.isArray(name)) { this.name = name.root || name.amd || name.commonjs; @@ -40,6 +65,10 @@ class UmdMainTemplatePlugin { this.auxiliaryComment = options.auxiliaryComment; } + /** + * @param {Compilation} compilation the compilation instance + * @returns {void} + */ apply(compilation) { const { mainTemplate, chunkTemplate, runtimeTemplate } = compilation; From 85b5ee33e2686282428dd1a3afef3f74614349c2 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 9 May 2018 17:40:02 +0200 Subject: [PATCH 008/111] chore: bump webassemblyjs 1.4.0 --- package.json | 6 +- yarn.lock | 178 +++++++++++++++++++++++++-------------------------- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/package.json b/package.json index 6b54e031949..7abecaced4c 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "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.3.2", - "@webassemblyjs/wasm-edit": "1.3.2", - "@webassemblyjs/wasm-parser": "1.3.2", + "@webassemblyjs/ast": "1.4.0", + "@webassemblyjs/wasm-edit": "1.4.0", + "@webassemblyjs/wasm-parser": "1.4.0", "acorn": "^5.0.0", "acorn-dynamic-import": "^3.0.0", "ajv": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index 011342076f5..a735bc74eab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,115 +18,115 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd" -"@webassemblyjs/ast@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.3.2.tgz#3312d6f81aaaa1fe74d2e1a42264899fe802828e" +"@webassemblyjs/ast@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.0.tgz#7c633ad9ddbb9001ce2088e729b7000587f04ad5" dependencies: - "@webassemblyjs/helper-wasm-bytecode" "1.3.2" - "@webassemblyjs/wast-parser" "1.3.2" - webassemblyjs "1.3.2" + "@webassemblyjs/helper-wasm-bytecode" "1.4.0" + "@webassemblyjs/wast-parser" "1.4.0" + webassemblyjs "1.4.0" -"@webassemblyjs/floating-point-hex-parser@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.3.2.tgz#a749e630e6b78fab70dbeac5710038fba241548d" +"@webassemblyjs/floating-point-hex-parser@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.0.tgz#1d573e193fc459b42b60626fb6d3d5a1ad988a66" -"@webassemblyjs/helper-buffer@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.3.2.tgz#c5c36f8f158145403beb9e9f7ccf70fb6dc003fa" +"@webassemblyjs/helper-buffer@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.0.tgz#c3571685a2d71ecb0afba85556bd9a3cec3eb689" -"@webassemblyjs/helper-code-frame@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.3.2.tgz#a54b59bf586f91368c8675d20750a05df95c8f3a" +"@webassemblyjs/helper-code-frame@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.0.tgz#c88b5932e312dcac1b01bd5130417820199ad161" dependencies: - "@webassemblyjs/wast-printer" "1.3.2" + "@webassemblyjs/wast-printer" "1.4.0" -"@webassemblyjs/helper-fsm@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.3.2.tgz#05e31f4ca23634a8232b4295889b38df9360bb5b" +"@webassemblyjs/helper-fsm@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.0.tgz#a9a31678fd04c8bfc6124e4e68cefd07971d2421" -"@webassemblyjs/helper-wasm-bytecode@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.3.2.tgz#487c2f0165f1b25dde622bd5fe832307cadc4e45" +"@webassemblyjs/helper-wasm-bytecode@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.0.tgz#bcc4ed104d87f7d62a2ff193f5192222fa5b42ba" -"@webassemblyjs/helper-wasm-section@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.3.2.tgz#b05ad3b21e2d94847242813ea2df6931413ddd70" +"@webassemblyjs/helper-wasm-section@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.0.tgz#9a46e637924312efd193a3012899e0aa4ef486aa" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/helper-buffer" "1.3.2" - "@webassemblyjs/helper-wasm-bytecode" "1.3.2" - "@webassemblyjs/wasm-gen" "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/helper-buffer" "1.4.0" + "@webassemblyjs/helper-wasm-bytecode" "1.4.0" + "@webassemblyjs/wasm-gen" "1.4.0" -"@webassemblyjs/leb128@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.3.2.tgz#f0b0d7e3b711e17a8140e3475ac26292ac6f4245" +"@webassemblyjs/leb128@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.0.tgz#de3ab2a73df41a0b6f07ee1faffe51680f2a0cfa" dependencies: leb "^0.3.0" -"@webassemblyjs/validation@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.3.2.tgz#1a05dd9d7d7414d7a36d39649abf0981cead68f2" +"@webassemblyjs/validation@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.0.tgz#d09b6acb0397089a1eaaf26b7f66d522f89d224e" dependencies: - "@webassemblyjs/ast" "1.3.2" + "@webassemblyjs/ast" "1.4.0" -"@webassemblyjs/wasm-edit@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.3.2.tgz#eaf8df33b4003f88426a34cd4981c60127db0a0d" - dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/helper-buffer" "1.3.2" - "@webassemblyjs/helper-wasm-bytecode" "1.3.2" - "@webassemblyjs/helper-wasm-section" "1.3.2" - "@webassemblyjs/wasm-gen" "1.3.2" - "@webassemblyjs/wasm-opt" "1.3.2" - "@webassemblyjs/wasm-parser" "1.3.2" - "@webassemblyjs/wast-printer" "1.3.2" +"@webassemblyjs/wasm-edit@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.0.tgz#96703293b470bd79fb33304fd940f4c905ece2d2" + dependencies: + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/helper-buffer" "1.4.0" + "@webassemblyjs/helper-wasm-bytecode" "1.4.0" + "@webassemblyjs/helper-wasm-section" "1.4.0" + "@webassemblyjs/wasm-gen" "1.4.0" + "@webassemblyjs/wasm-opt" "1.4.0" + "@webassemblyjs/wasm-parser" "1.4.0" + "@webassemblyjs/wast-printer" "1.4.0" debug "^3.1.0" -"@webassemblyjs/wasm-gen@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.3.2.tgz#1f7baef9dc6c162b290639ea60f4cec9a971701d" +"@webassemblyjs/wasm-gen@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.0.tgz#85824fb95c84ac3ed85313b8c81d5af3053c3bba" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/helper-wasm-bytecode" "1.3.2" - "@webassemblyjs/leb128" "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/helper-wasm-bytecode" "1.4.0" + "@webassemblyjs/leb128" "1.4.0" -"@webassemblyjs/wasm-opt@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.3.2.tgz#3f72c0c59422fdc7511d77e97e5ec462dafe378f" +"@webassemblyjs/wasm-opt@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.0.tgz#b7304cae781616a4987bab2e1804c98d7e29cc1b" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/helper-buffer" "1.3.2" - "@webassemblyjs/wasm-gen" "1.3.2" - "@webassemblyjs/wasm-parser" "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/helper-buffer" "1.4.0" + "@webassemblyjs/wasm-gen" "1.4.0" + "@webassemblyjs/wasm-parser" "1.4.0" -"@webassemblyjs/wasm-parser@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.3.2.tgz#351d368f4a0407afd8ac4454235bdeb2fb8a0913" +"@webassemblyjs/wasm-parser@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.0.tgz#cf98ef396ad5553196a614c11a4b2ecfd13f1e82" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/helper-wasm-bytecode" "1.3.2" - "@webassemblyjs/leb128" "1.3.2" - "@webassemblyjs/wasm-parser" "1.3.2" - webassemblyjs "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/helper-wasm-bytecode" "1.4.0" + "@webassemblyjs/leb128" "1.4.0" + "@webassemblyjs/wasm-parser" "1.4.0" + webassemblyjs "1.4.0" -"@webassemblyjs/wast-parser@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.3.2.tgz#5b78bfaace0b13d38be36719931a8b22fd563a22" +"@webassemblyjs/wast-parser@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.0.tgz#9402dfcd67edd455785f29575ad4c9266e5c14ae" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/floating-point-hex-parser" "1.3.2" - "@webassemblyjs/helper-code-frame" "1.3.2" - "@webassemblyjs/helper-fsm" "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/floating-point-hex-parser" "1.4.0" + "@webassemblyjs/helper-code-frame" "1.4.0" + "@webassemblyjs/helper-fsm" "1.4.0" long "^3.2.0" - webassemblyjs "1.3.2" + webassemblyjs "1.4.0" -"@webassemblyjs/wast-printer@1.3.2": - version "1.3.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.3.2.tgz#6f3392bb9582bf7537e77704e7a2a84176305d20" +"@webassemblyjs/wast-printer@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.0.tgz#7223a32cde1fee681e9160ae50b1c3d8d4b50f09" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/wast-parser" "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/wast-parser" "1.4.0" long "^3.2.0" abab@^1.0.4: @@ -6101,14 +6101,14 @@ watchpack@^1.5.0: graceful-fs "^4.1.2" neo-async "^2.5.0" -webassemblyjs@1.3.2: - version "1.3.2" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.3.2.tgz#bba52db7b56fa0cc7882cb1176e8099ab4dd3e3c" +webassemblyjs@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.0.tgz#19473db20153c558fe0b95f143bd344df39fa83a" dependencies: - "@webassemblyjs/ast" "1.3.2" - "@webassemblyjs/validation" "1.3.2" - "@webassemblyjs/wasm-parser" "1.3.2" - "@webassemblyjs/wast-parser" "1.3.2" + "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/validation" "1.4.0" + "@webassemblyjs/wasm-parser" "1.4.0" + "@webassemblyjs/wast-parser" "1.4.0" long "^3.2.0" webidl-conversions@^4.0.1, webidl-conversions@^4.0.2: From d491fdc786238f8814ffec7919ca81326271088e Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 9 May 2018 17:40:38 +0200 Subject: [PATCH 009/111] feat: uses new APIs --- declarations.d.ts | 15 ++++++++++--- lib/wasm/WebAssemblyGenerator.js | 37 ++++++++++++++++++++------------ lib/wasm/WebAssemblyParser.js | 8 +++---- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/declarations.d.ts b/declarations.d.ts index 398a8973e49..d73b4d8305a 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -33,19 +33,28 @@ declare module "chrome-trace-event" { declare module "@webassemblyjs/ast" { export function traverse( ast: any, - visitor: { [name: string]: (context: { node: Node }) => void } + visitor: { + ModuleImport?: (p: NodePath) => void; + ModuleExport?: (p: NodePath) => void; + Start?: (p: NodePath) => void; + } ); - export class Node { - index: number; + export class NodePath { + node: T; } + export class Node {} export class Identifier extends Node { value: string; } + export class Start extends Node { + index: Identifier; + } export class ModuleImport extends Node { module: string; descr: { type: string; valtype: string; + id: string; }; name: string; } diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 852174799fb..928d90aca1b 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -7,7 +7,7 @@ const Generator = require("../Generator"); const { RawSource } = require("webpack-sources"); -const { edit, add } = require("@webassemblyjs/wasm-edit"); +const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); const { decode } = require("@webassemblyjs/wasm-parser"); const t = require("@webassemblyjs/ast"); @@ -18,9 +18,19 @@ function compose(...fns) { } // Utility functions -const isGlobalImport = moduleImport => moduleImport.descr.type === "GlobalType"; -const isFuncImport = moduleImport => - moduleImport.descr.type === "FuncImportDescr"; + +/** + * @param {t.ModuleImport} n the import + * @returns {boolean} true, if a global was imported + */ +const isGlobalImport = n => n.descr.type === "GlobalType"; + +/** + * @param {t.ModuleImport} n the import + * @returns {boolean} true, if a func was imported + */ +const isFuncImport = n => n.descr.type === "FuncImportDescr"; + const initFuncId = t.identifier("__webpack_init__"); // TODO replace with @callback @@ -35,7 +45,7 @@ const initFuncId = t.identifier("__webpack_init__"); * @returns {ArrayBufferTransform} transform */ const removeStartFunc = state => bin => { - return edit(bin, { + return editWithAST(state.ast, bin, { Start(path) { path.remove(); } @@ -149,7 +159,7 @@ function getNextFuncIndex(ast, countImportedFunc) { const rewriteImportedGlobals = state => bin => { const newGlobals = []; - bin = edit(bin, { + bin = editWithAST(state.ast, bin, { ModuleImport(path) { if (isGlobalImport(path.node) === true) { const globalType = path.node.descr; @@ -168,7 +178,7 @@ const rewriteImportedGlobals = state => bin => { }); // Add global declaration instructions - return add(bin, newGlobals); + return addWithAST(state.ast, bin, newGlobals); }; /** @@ -177,17 +187,17 @@ const rewriteImportedGlobals = state => bin => { * The init function fills the globals given input arguments. * * @param {Object} state transformation state + * @param {Object} state.ast - Module's ast * @param {t.IndexLiteral} state.startAtFuncIndex index of the start function * @param {t.ModuleImport[]} state.importedGlobals list of imported globals - * @param {TODO} state.funcSectionMetadata ?? * @param {t.IndexLiteral} state.nextFuncIndex index of the next function * @param {t.IndexLiteral} state.nextTypeIndex index of the next type * @returns {ArrayBufferTransform} transform */ const addInitFunction = ({ + ast, startAtFuncIndex, importedGlobals, - funcSectionMetadata, nextFuncIndex, nextTypeIndex }) => bin => { @@ -229,7 +239,7 @@ const addInitFunction = ({ // Export section const moduleExport = t.moduleExport(initFuncId.value, "Func", nextFuncIndex); - return add(bin, [func, moduleExport, funcindex, functype]); + return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]); }; class WebAssemblyGenerator extends Generator { @@ -244,20 +254,19 @@ class WebAssemblyGenerator extends Generator { }); const importedGlobals = getImportedGlobals(ast); - const funcSectionMetadata = t.getSectionMetadata(ast, "func"); const countImportedFunc = getCountImportedFunc(ast); const startAtFuncIndex = getStartFuncIndex(ast); const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc); const nextTypeIndex = getNextTypeIndex(ast); const transform = compose( - removeStartFunc({}), + removeStartFunc({ ast }), - rewriteImportedGlobals({}), + rewriteImportedGlobals({ ast }), addInitFunction({ + ast, importedGlobals, - funcSectionMetadata, startAtFuncIndex, nextFuncIndex, nextTypeIndex diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index cbb6167e05a..e0c01ad475b 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -11,16 +11,16 @@ const { Tapable } = require("tapable"); const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); /** - * @param {t.ModuleImport} moduleImport the import + * @param {t.ModuleImport} n the import * @returns {boolean} true, if a memory was imported */ -const isMemoryImport = moduleImport => moduleImport.descr.type === "Memory"; +const isMemoryImport = n => n.descr.type === "Memory"; /** - * @param {t.ModuleImport} moduleImport the import + * @param {t.ModuleImport} n the import * @returns {boolean} true, if a table was imported */ -const isTableImport = moduleImport => moduleImport.descr.type === "Table"; +const isTableImport = n => n.descr.type === "Table"; const decoderOpts = { ignoreCodeSection: true, From d72f7c6b1caa7f43949229e101c90d5baa4ee452 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 9 May 2018 17:47:05 +0200 Subject: [PATCH 010/111] feat: store wasm ast on the module --- lib/wasm/WebAssemblyGenerator.js | 9 +-------- lib/wasm/WebAssemblyParser.js | 2 ++ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 928d90aca1b..21e5c4d222f 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -8,7 +8,6 @@ const Generator = require("../Generator"); const { RawSource } = require("webpack-sources"); const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); -const { decode } = require("@webassemblyjs/wasm-parser"); const t = require("@webassemblyjs/ast"); function compose(...fns) { @@ -244,15 +243,9 @@ const addInitFunction = ({ class WebAssemblyGenerator extends Generator { generate(module) { + const ast = module._ast; const bin = module.originalSource().source(); - // FIXME(sven): this module is parsed twice, we could preserve the AST - // from wasm/WebAssemblyParser.js - const ast = decode(bin, { - ignoreDataSection: true, - ignoreCodeSection: true - }); - const importedGlobals = getImportedGlobals(ast); const countImportedFunc = getCountImportedFunc(ast); const startAtFuncIndex = getStartFuncIndex(ast); diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index e0c01ad475b..6b5580d1cdc 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -73,6 +73,8 @@ class WebAssemblyParser extends Tapable { } }); + state.module._ast = ast; + return state; } } From 8bdc8ad6468c7911f8cbed5aa2c15fd3c1c4bf60 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 9 May 2018 17:53:25 +0200 Subject: [PATCH 011/111] refactor: remove type cast --- lib/wasm/WebAssemblyParser.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index 6b5580d1cdc..a79ffc40008 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -45,27 +45,24 @@ class WebAssemblyParser extends Tapable { const exports = (state.module.buildMeta.providedExports = []); t.traverse(ast, { ModuleExport({ node }) { - const moduleExport = /** @type {t.ModuleExport} */ (node); - exports.push(moduleExport.name); + exports.push(node.name); }, ModuleImport({ node }) { - const moduleImport = /** @type {t.ModuleImport} */ (node); - let onlyDirectImport = false; - if (isMemoryImport(moduleImport) === true) { + if (isMemoryImport(node) === true) { onlyDirectImport = true; } - if (isTableImport(moduleImport) === true) { + if (isTableImport(node) === true) { onlyDirectImport = true; } const dep = new WebAssemblyImportDependency( - moduleImport.module, - moduleImport.name, - moduleImport.descr, + node.module, + node.name, + node.descr, onlyDirectImport ); From a31721a1daa19f647a5ba621c8f89e2e22480eb1 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Tue, 8 May 2018 09:22:00 -0700 Subject: [PATCH 012/111] Update test readme for Jest This documentation still referenced Mocha, but tests were converted to Jest. --- test/README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/README.md b/test/README.md index 05b25ccce10..97fb3320bff 100644 --- a/test/README.md +++ b/test/README.md @@ -4,16 +4,25 @@ Every pull request that you submit to webpack (besides README and spelling corre 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! ❤ ## tl;dr -* Clone repo -* Run tests (this automatically runs the setup) - * `yarn test` +Run all tests (this automatically runs the setup): +```sh +yarn test +``` -* To run an individual suite: (recommended during development for easier isolated diffs) +Run an individual suite: +```sh +yarn jest ConfigTestCases +``` -Example: `$(npm bin)/mocha --grep ConfigTestCases` +Watch mode: +```sh +yarn jest --watch ConfigTestCases +``` + +See also: [Jest CLI docs](https://facebook.github.io/jest/docs/cli.html) ## Test suite overview -We use MochaJS for our tests. For more information on Mocha you can visit their [homepage](https://mochajs.org/)! +We use Jest for our tests. For more information on Jest you can visit their [homepage](https://facebook.github.io/jest/)! ### 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). From 78423b038897933a7290b593e9e31fc19acad776 Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Wed, 9 May 2018 21:13:21 +0200 Subject: [PATCH 013/111] Update rc and deep-extend There is a security issue with 'deep-extend' package which is a dependency of 'rc'. Further details on https://nodesecurity.io/advisories/612 Fixes #7255 --- yarn.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index 011342076f5..52ac6d6fcb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1465,9 +1465,9 @@ decode-uri-component@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" -deep-extend@~0.4.0: - version "0.4.2" - resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f" +deep-extend@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.5.1.tgz#b894a9dd90d3023fbf1c55a394fb858eb2066f1f" deep-is@~0.1.3: version "0.1.3" @@ -4845,10 +4845,10 @@ raw-loader@~0.5.0, raw-loader@~0.5.1: resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-0.5.1.tgz#0c3d0beaed8a01c966d9787bf778281252a979aa" rc@^1.1.7: - version "1.2.6" - resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.6.tgz#eb18989c6d4f4f162c399f79ddd29f3835568092" + version "1.2.7" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.7.tgz#8a10ca30d588d00464360372b890d06dacd02297" dependencies: - deep-extend "~0.4.0" + deep-extend "^0.5.1" ini "~1.3.0" minimist "^1.2.0" strip-json-comments "~2.0.1" From 9b37c6bf2c40ede496de8c2720eb3f93bfc29e62 Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Thu, 10 May 2018 09:13:17 +0200 Subject: [PATCH 014/111] Replace Jade by Pug --- package.json | 2 + test/TestCases.template.js | 4 +- .../{included.jade => included.pug} | 0 .../_resources/{parent.jade => parent.pug} | 0 .../{template.jade => template.pug} | 0 test/cases/loaders/jade-loader/index.js | 4 - test/cases/loaders/pug-loader/index.js | 4 + test/cases/resolving/context/index.js | 2 +- .../subcontent/{test.jade => test.pug} | 0 yarn.lock | 189 +++++++++++++++++- 10 files changed, 191 insertions(+), 14 deletions(-) rename test/cases/loaders/_resources/{included.jade => included.pug} (100%) rename test/cases/loaders/_resources/{parent.jade => parent.pug} (100%) rename test/cases/loaders/_resources/{template.jade => template.pug} (100%) delete mode 100644 test/cases/loaders/jade-loader/index.js create mode 100644 test/cases/loaders/pug-loader/index.js rename test/cases/resolving/context/node_modules/subcontent/{test.jade => test.pug} (100%) diff --git a/package.json b/package.json index 6b54e031949..6913207d4ba 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,8 @@ "less-loader": "^4.0.3", "lodash": "^4.17.4", "prettier": "^1.11.1", + "pug": "^2.0.3", + "pug-loader": "^2.4.0", "raw-loader": "~0.5.0", "react": "^15.2.1", "react-dom": "^15.2.1", diff --git a/test/TestCases.template.js b/test/TestCases.template.js index 8242c61dd6f..c860c7211b4 100644 --- a/test/TestCases.template.js +++ b/test/TestCases.template.js @@ -139,8 +139,8 @@ const describeCases = config => { loader: "coffee-loader" }, { - test: /\.jade$/, - loader: "jade-loader" + test: /\.pug/, + loader: "pug-loader" } ] }, diff --git a/test/cases/loaders/_resources/included.jade b/test/cases/loaders/_resources/included.pug similarity index 100% rename from test/cases/loaders/_resources/included.jade rename to test/cases/loaders/_resources/included.pug diff --git a/test/cases/loaders/_resources/parent.jade b/test/cases/loaders/_resources/parent.pug similarity index 100% rename from test/cases/loaders/_resources/parent.jade rename to test/cases/loaders/_resources/parent.pug diff --git a/test/cases/loaders/_resources/template.jade b/test/cases/loaders/_resources/template.pug similarity index 100% rename from test/cases/loaders/_resources/template.jade rename to test/cases/loaders/_resources/template.pug diff --git a/test/cases/loaders/jade-loader/index.js b/test/cases/loaders/jade-loader/index.js deleted file mode 100644 index ce442433985..00000000000 --- a/test/cases/loaders/jade-loader/index.js +++ /dev/null @@ -1,4 +0,0 @@ -it("should handle the jade loader correctly", function() { - expect(require("!jade-loader?self!../_resources/template.jade")({ abc: "abc" })).toBe("

selfabc

included

"); - expect(require("../_resources/template.jade")({ abc: "abc" })).toBe("

abc

included

"); -}); diff --git a/test/cases/loaders/pug-loader/index.js b/test/cases/loaders/pug-loader/index.js new file mode 100644 index 00000000000..7348ae7df16 --- /dev/null +++ b/test/cases/loaders/pug-loader/index.js @@ -0,0 +1,4 @@ +it("should handle the pug loader correctly", function() { + expect(require("!pug-loader?self!../_resources/template.pug")({ abc: "abc" })).toBe("

selfabc

included

"); + expect(require("../_resources/template.pug")({ abc: "abc" })).toBe("

abc

included

"); +}); diff --git a/test/cases/resolving/context/index.js b/test/cases/resolving/context/index.js index 89c944dc6e1..20708273069 100644 --- a/test/cases/resolving/context/index.js +++ b/test/cases/resolving/context/index.js @@ -5,7 +5,7 @@ it("should resolve loaders relative to require", function() { query: "?query", prev: "module.exports = \"error\";" }); - expect(require("!./loaders/queryloader?query!./node_modules/subcontent/" + test + ".jade")).toEqual({ + expect(require("!./loaders/queryloader?query!./node_modules/subcontent/" + test + ".pug")).toEqual({ resourceQuery: "", query: "?query", prev: "xyz: abc" diff --git a/test/cases/resolving/context/node_modules/subcontent/test.jade b/test/cases/resolving/context/node_modules/subcontent/test.pug similarity index 100% rename from test/cases/resolving/context/node_modules/subcontent/test.jade rename to test/cases/resolving/context/node_modules/subcontent/test.pug diff --git a/yarn.lock b/yarn.lock index 011342076f5..3969bfecca9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,6 +10,16 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@types/babel-types@*", "@types/babel-types@^7.0.0": + version "7.0.2" + resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.2.tgz#63dc3e5e7f6367e1819d2bba5213783cd926c5d5" + +"@types/babylon@^6.16.2": + version "6.16.2" + resolved "https://registry.yarnpkg.com/@types/babylon/-/babylon-6.16.2.tgz#062ce63b693d9af1c246f5aedf928bc9c30589c8" + dependencies: + "@types/babel-types" "*" + "@types/node@^9.6.4": version "9.6.6" resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.6.tgz#439b91f9caf3983cad2eef1e11f6bedcbf9431d2" @@ -160,6 +170,12 @@ acorn-globals@^1.0.3: dependencies: acorn "^2.1.0" +acorn-globals@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-3.1.0.tgz#fd8270f71fbb4996b004fa880ee5d46573a731bf" + dependencies: + acorn "^4.0.4" + acorn-globals@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.1.0.tgz#ab716025dbe17c54d3ef81d32ece2b2d99fe2538" @@ -180,10 +196,14 @@ acorn@^2.1.0: version "2.7.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-2.7.0.tgz#ab6e7d9d886aaca8b085bc3312b79a198433f0e7" -acorn@^3.0.4: +acorn@^3.0.4, acorn@^3.1.0: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" +acorn@^4.0.4, acorn@~4.0.2: + version "4.0.13" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" + acorn@^5.0.0, acorn@^5.5.0: version "5.5.3" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.3.tgz#f473dd47e0277a08e28e9bec5aeeb04751f0b8c9" @@ -934,6 +954,12 @@ character-parser@1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/character-parser/-/character-parser-1.2.1.tgz#c0dde4ab182713b919b970959a123ecc1a30fcd6" +character-parser@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/character-parser/-/character-parser-2.2.0.tgz#c7ce28f36d4bcd9744e5ffc2c5fcde1c73261fc0" + dependencies: + is-regex "^1.0.3" + chardet@^0.4.0: version "0.4.2" resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2" @@ -1001,6 +1027,12 @@ clean-css@^3.1.9: commander "2.8.x" source-map "0.4.x" +clean-css@^4.1.11: + version "4.1.11" + resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.1.11.tgz#2ecdf145aba38f54740f26cefd0ff3e03e125d6a" + dependencies: + source-map "0.5.x" + cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" @@ -1174,6 +1206,15 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" +constantinople@^3.0.1: + version "3.1.2" + resolved "https://registry.yarnpkg.com/constantinople/-/constantinople-3.1.2.tgz#d45ed724f57d3d10500017a7d3a889c1381ae647" + dependencies: + "@types/babel-types" "^7.0.0" + "@types/babylon" "^6.16.2" + babel-types "^6.26.0" + babylon "^6.18.0" + constantinople@~3.0.1: version "3.0.2" resolved "https://registry.yarnpkg.com/constantinople/-/constantinople-3.0.2.tgz#4b945d9937907bcd98ee575122c3817516544141" @@ -1576,6 +1617,10 @@ doctrine@^2.1.0: dependencies: esutils "^2.0.2" +doctypes@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/doctypes/-/doctypes-1.1.0.tgz#ea80b106a87538774e8a3a4a5afe293de489e0a9" + domain-browser@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda" @@ -2751,6 +2796,13 @@ is-equal-shallow@^0.1.3: dependencies: is-primitive "^2.0.0" +is-expression@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-expression/-/is-expression-3.0.0.tgz#39acaa6be7fd1f3471dc42c7416e61c24317ac9f" + dependencies: + acorn "~4.0.2" + object-assign "^4.0.1" + is-extendable@^0.1.0, is-extendable@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" @@ -2889,7 +2941,7 @@ is-property@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84" -is-regex@^1.0.4: +is-regex@^1.0.3, is-regex@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491" dependencies: @@ -3398,6 +3450,10 @@ js-base64@^2.1.9: version "2.4.3" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.3.tgz#2e545ec2b0f2957f41356510205214e98fad6582" +js-stringify@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/js-stringify/-/js-stringify-1.0.2.tgz#1736fddfd9724f28a3682adc6230ae7e4e9679db" + js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" @@ -3527,6 +3583,13 @@ jstransformer@0.0.2: is-promise "^2.0.0" promise "^6.0.1" +jstransformer@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/jstransformer/-/jstransformer-1.0.0.tgz#ed8bf0921e2f3f1ed4d5c1a44f68709ed24722c3" + dependencies: + is-promise "^2.0.0" + promise "^7.0.1" + kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: version "3.2.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" @@ -4705,7 +4768,7 @@ promise@^6.0.1: dependencies: asap "~1.0.0" -promise@^7.1.1: +promise@^7.0.1, promise@^7.1.1: version "7.3.1" resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf" dependencies: @@ -4750,6 +4813,107 @@ public-encrypt@^4.0.0: parse-asn1 "^5.0.0" randombytes "^2.0.1" +pug-attrs@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/pug-attrs/-/pug-attrs-2.0.3.tgz#a3095f970e64151f7bdad957eef55fb5d7905d15" + dependencies: + constantinople "^3.0.1" + js-stringify "^1.0.1" + pug-runtime "^2.0.4" + +pug-code-gen@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/pug-code-gen/-/pug-code-gen-2.0.1.tgz#0951ec83225d74d8cfc476a7f99a259b5f7d050c" + dependencies: + constantinople "^3.0.1" + doctypes "^1.1.0" + js-stringify "^1.0.1" + pug-attrs "^2.0.3" + pug-error "^1.3.2" + pug-runtime "^2.0.4" + void-elements "^2.0.1" + with "^5.0.0" + +pug-error@^1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/pug-error/-/pug-error-1.3.2.tgz#53ae7d9d29bb03cf564493a026109f54c47f5f26" + +pug-filters@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/pug-filters/-/pug-filters-3.1.0.tgz#27165555bc04c236e4aa2b0366246dfa021b626e" + dependencies: + clean-css "^4.1.11" + constantinople "^3.0.1" + jstransformer "1.0.0" + pug-error "^1.3.2" + pug-walk "^1.1.7" + resolve "^1.1.6" + uglify-js "^2.6.1" + +pug-lexer@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/pug-lexer/-/pug-lexer-4.0.0.tgz#210c18457ef2e1760242740c5e647bd794cec278" + dependencies: + character-parser "^2.1.1" + is-expression "^3.0.0" + pug-error "^1.3.2" + +pug-linker@^3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/pug-linker/-/pug-linker-3.0.5.tgz#9e9a7ae4005682d027deeb96b000f88eeb83a02f" + dependencies: + pug-error "^1.3.2" + pug-walk "^1.1.7" + +pug-load@^2.0.11: + version "2.0.11" + resolved "https://registry.yarnpkg.com/pug-load/-/pug-load-2.0.11.tgz#e648e57ed113fe2c1f45d57858ea2bad6bc01527" + dependencies: + object-assign "^4.1.0" + pug-walk "^1.1.7" + +pug-loader@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/pug-loader/-/pug-loader-2.4.0.tgz#18eebdda045d9c31c2856f1cc3ceb8d3df7ca49a" + dependencies: + loader-utils "^1.1.0" + pug-walk "^1.0.0" + resolve "^1.1.7" + +pug-parser@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/pug-parser/-/pug-parser-5.0.0.tgz#e394ad9b3fca93123940aff885c06e44ab7e68e4" + dependencies: + pug-error "^1.3.2" + token-stream "0.0.1" + +pug-runtime@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/pug-runtime/-/pug-runtime-2.0.4.tgz#e178e1bda68ab2e8c0acfc9bced2c54fd88ceb58" + +pug-strip-comments@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/pug-strip-comments/-/pug-strip-comments-1.0.3.tgz#f1559592206edc6f85310dacf4afb48a025af59f" + dependencies: + pug-error "^1.3.2" + +pug-walk@^1.0.0, pug-walk@^1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/pug-walk/-/pug-walk-1.1.7.tgz#c00d5c5128bac5806bec15d2b7e7cdabe42531f3" + +pug@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/pug/-/pug-2.0.3.tgz#71cba82537c95a5eab7ed04696e4221f53aa878e" + dependencies: + pug-code-gen "^2.0.1" + pug-filters "^3.1.0" + pug-lexer "^4.0.0" + pug-linker "^3.0.5" + pug-load "^2.0.11" + pug-parser "^5.0.0" + pug-runtime "^2.0.4" + pug-strip-comments "^1.0.3" + pump@^2.0.0, pump@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/pump/-/pump-2.0.1.tgz#12399add6e4cf7526d973cbc8b5ce2e2908b3909" @@ -5128,7 +5292,7 @@ resolve@1.1.7, resolve@1.1.x: version "1.1.7" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" -resolve@^1.3.3: +resolve@^1.1.6, resolve@^1.1.7, resolve@^1.3.3: version "1.7.1" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3" dependencies: @@ -5439,7 +5603,7 @@ source-map@0.4.x, source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: +source-map@0.5.x, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -5802,6 +5966,10 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" +token-stream@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/token-stream/-/token-stream-0.0.1.tgz#ceeefc717a76c4316f126d0b9dbaa55d7e7df01a" + topo@2.x.x: version "2.0.2" resolved "https://registry.yarnpkg.com/topo/-/topo-2.0.2.tgz#cd5615752539057c0dc0491a621c3bc6fbe1d182" @@ -5888,7 +6056,7 @@ uglify-es@^3.3.4: commander "~2.13.0" source-map "~0.6.1" -uglify-js@^2.4.19, uglify-js@^2.6: +uglify-js@^2.4.19, uglify-js@^2.6, uglify-js@^2.6.1: version "2.8.29" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" dependencies: @@ -6070,7 +6238,7 @@ vm-browserify@0.0.4, vm-browserify@~0.0.0: dependencies: indexof "0.0.1" -void-elements@~2.0.1: +void-elements@^2.0.1, void-elements@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" @@ -6174,6 +6342,13 @@ window-size@0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d" +with@^5.0.0: + version "5.1.1" + resolved "https://registry.yarnpkg.com/with/-/with-5.1.1.tgz#fa4daa92daf32c4ea94ed453c81f04686b575dfe" + dependencies: + acorn "^3.1.0" + acorn-globals "^3.0.0" + with@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/with/-/with-4.0.3.tgz#eefd154e9e79d2c8d3417b647a8f14d9fecce14e" From 8488b882a44da3d23fca6c6fd03d7f0576e36d80 Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Thu, 10 May 2018 16:36:08 +0200 Subject: [PATCH 015/111] Allow banner to be specified as a function --- lib/BannerPlugin.js | 28 ++++++++++++++----- schemas/plugins/BannerPlugin.json | 15 ++++++++-- .../plugins/banner-plugin/index.js | 17 ++++++----- .../plugins/banner-plugin/webpack.config.js | 5 ++++ 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/lib/BannerPlugin.js b/lib/BannerPlugin.js index dc1c46021f4..544d4b4227b 100644 --- a/lib/BannerPlugin.js +++ b/lib/BannerPlugin.js @@ -22,21 +22,33 @@ const wrapComment = str => { class BannerPlugin { constructor(options) { - if (arguments.length > 1) + if (arguments.length > 1) { throw new Error( "BannerPlugin only takes one argument (pass an options object)" ); + } validateOptions(schema, options, "Banner Plugin"); - if (typeof options === "string") + if (typeof options === "string" || typeof options === "function") { options = { banner: options }; + } + this.options = options || {}; - this.banner = this.options.raw - ? options.banner - : wrapComment(options.banner); + + if (typeof options.banner === "function") { + let getBanner = this.options.banner; + this.banner = this.options.raw + ? getBanner + : data => wrapComment(getBanner(data)); + } else { + let banner = this.options.raw + ? this.options.banner + : wrapComment(this.options.banner); + this.banner = () => banner; + } } apply(compiler) { @@ -78,13 +90,15 @@ class BannerPlugin { basename = filename.substr(lastSlashIndex + 1); } - const comment = compilation.getPath(banner, { + const data = { hash, chunk, filename, basename, query - }); + }; + + const comment = compilation.getPath(banner(data), data); compilation.assets[file] = new ConcatSource( comment, diff --git a/schemas/plugins/BannerPlugin.json b/schemas/plugins/BannerPlugin.json index f2e50213217..87e47903611 100644 --- a/schemas/plugins/BannerPlugin.json +++ b/schemas/plugins/BannerPlugin.json @@ -39,8 +39,15 @@ ], "properties": { "banner": { - "description": "The banner as string, it will be wrapped in a comment", - "type": "string" + "description": "Specifies the banner", + "anyOf": [ + { + "instanceof": "Function" + }, + { + "type": "string" + } + ] }, "raw": { "description": "If true, banner will not be wrapped in a comment", @@ -76,6 +83,10 @@ } } }, + { + "description": "The banner as function, it will be wrapped in a comment", + "instanceof": "Function" + }, { "description": "The banner as string, it will be wrapped in a comment", "minLength": 1, diff --git a/test/configCases/plugins/banner-plugin/index.js b/test/configCases/plugins/banner-plugin/index.js index 866cec14fab..105a1f91b12 100644 --- a/test/configCases/plugins/banner-plugin/index.js +++ b/test/configCases/plugins/banner-plugin/index.js @@ -1,13 +1,16 @@ -it("should contain banner in bundle0 chunk", function() { - var fs = require("fs"); - var source = fs.readFileSync(__filename, "utf-8"); +const fs = require("fs"); +const path = require("path"); + +it("should contain banner in bundle0 chunk", () => { + const source = fs.readFileSync(__filename, "utf-8"); expect(source).toMatch("A test value"); + expect(source).toMatch("banner is a string"); + expect(source).toMatch("banner is a function"); + expect(source).toMatch("/*!\n * multiline\n * banner\n * 1\n */"); }); -it("should not contain banner in vendors chunk", function() { - var fs = require("fs"), - path = require("path"); - var source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8"); +it("should not contain banner in vendors chunk", () => { + const source = fs.readFileSync(path.join(__dirname, "vendors.js"), "utf-8"); expect(source).not.toMatch("A test value"); }); diff --git a/test/configCases/plugins/banner-plugin/webpack.config.js b/test/configCases/plugins/banner-plugin/webpack.config.js index f8dda4c4dcc..fcaaee27a46 100644 --- a/test/configCases/plugins/banner-plugin/webpack.config.js +++ b/test/configCases/plugins/banner-plugin/webpack.config.js @@ -12,9 +12,14 @@ module.exports = { filename: "[name].js" }, plugins: [ + new webpack.BannerPlugin("banner is a string"), + new webpack.BannerPlugin(() => "banner is a function"), new webpack.BannerPlugin({ banner: "A test value", exclude: ["vendors.js"] + }), + new webpack.BannerPlugin({ + banner: ({ chunk }) => `multiline\nbanner\n${chunk.id}` }) ] }; From 85ef6343894ed968d557229228f009f2fcc93484 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 10 May 2018 20:19:30 +0200 Subject: [PATCH 016/111] remove _ast variable, add WeakMap --- lib/wasm/WebAssemblyGenerator.js | 3 ++- lib/wasm/WebAssemblyParser.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 21e5c4d222f..d4fb1255a6d 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -6,6 +6,7 @@ const Generator = require("../Generator"); const { RawSource } = require("webpack-sources"); +const WebAssemblyParser = require("./WebAssemblyParser"); const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); const t = require("@webassemblyjs/ast"); @@ -243,7 +244,7 @@ const addInitFunction = ({ class WebAssemblyGenerator extends Generator { generate(module) { - const ast = module._ast; + const ast = WebAssemblyParser.getAst(module); const bin = module.originalSource().source(); const importedGlobals = getImportedGlobals(ast); diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index a79ffc40008..0cfd037257f 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -10,6 +10,8 @@ const { decode } = require("@webassemblyjs/wasm-parser"); const { Tapable } = require("tapable"); const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); +/** @typedef {import("../Module")} Module */ + /** * @param {t.ModuleImport} n the import * @returns {boolean} true, if a memory was imported @@ -27,6 +29,9 @@ const decoderOpts = { ignoreDataSection: true }; +/** @type {WeakMap} */ +const astStore = new WeakMap(); + class WebAssemblyParser extends Tapable { constructor(options) { super(); @@ -34,6 +39,10 @@ class WebAssemblyParser extends Tapable { this.options = options; } + static getAst(module) { + return astStore.get(module); + } + parse(binary, state) { // flag it as ESM state.module.buildMeta.exportsType = "namespace"; @@ -41,6 +50,9 @@ class WebAssemblyParser extends Tapable { // parse it const ast = decode(binary, decoderOpts); + // cache it to be available for generators + astStore.set(state.module, ast); + // extract imports and exports const exports = (state.module.buildMeta.providedExports = []); t.traverse(ast, { @@ -70,8 +82,6 @@ class WebAssemblyParser extends Tapable { } }); - state.module._ast = ast; - return state; } } From 91b648074090a30d079612d8c062f52ead92c774 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Thu, 10 May 2018 22:04:18 +0200 Subject: [PATCH 017/111] chore: bump webassemblyjs --- package.json | 6 +- yarn.lock | 280 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 191 insertions(+), 95 deletions(-) diff --git a/package.json b/package.json index 7abecaced4c..07a33b0f465 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "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.4.0", - "@webassemblyjs/wasm-edit": "1.4.0", - "@webassemblyjs/wasm-parser": "1.4.0", + "@webassemblyjs/ast": "1.4.1", + "@webassemblyjs/wasm-edit": "1.4.1", + "@webassemblyjs/wasm-parser": "1.4.1", "acorn": "^5.0.0", "acorn-dynamic-import": "^3.0.0", "ajv": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index a735bc74eab..d5e28b23112 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,12 @@ # yarn lockfile v1 +"@babel/code-frame@7.0.0-beta.46", "@babel/code-frame@^7.0.0-beta.36": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.46.tgz#e0d002100805daab1461c0fcb32a07e304f3a4f4" + dependencies: + "@babel/highlight" "7.0.0-beta.46" + "@babel/code-frame@^7.0.0-beta.35": version "7.0.0-beta.38" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.38.tgz#c0af5930617e55e050336838e3a3670983b0b2b2" @@ -10,6 +16,41 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@babel/generator@^7.0.0-beta.40": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.46.tgz#6f57159bcc28bf8c3ed6b549789355cebfa3faa7" + dependencies: + "@babel/types" "7.0.0-beta.46" + jsesc "^2.5.1" + lodash "^4.2.0" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/highlight@7.0.0-beta.46": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.46.tgz#c553c51e65f572bdedd6eff66fc0bb563016645e" + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + +"@babel/template@^7.0.0-beta.40": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.46.tgz#8b23982411d5b5dbfa479437bfe414adb1411bb9" + dependencies: + "@babel/code-frame" "7.0.0-beta.46" + "@babel/types" "7.0.0-beta.46" + babylon "7.0.0-beta.46" + lodash "^4.2.0" + +"@babel/types@7.0.0-beta.46", "@babel/types@^7.0.0-beta.40": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.46.tgz#eb84399a699af9fcb244440cce78e1acbeb40e0c" + dependencies: + esutils "^2.0.2" + lodash "^4.2.0" + to-fast-properties "^2.0.0" + "@types/node@^9.6.4": version "9.6.6" resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.6.tgz#439b91f9caf3983cad2eef1e11f6bedcbf9431d2" @@ -18,115 +59,144 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd" -"@webassemblyjs/ast@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.0.tgz#7c633ad9ddbb9001ce2088e729b7000587f04ad5" +"@webassemblyjs/ast@1.0.0-y.7": + version "1.0.0-y.7" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.0.0-y.7.tgz#081dd61dd50030d4008aac9baf0ef5ff0cc2cab9" dependencies: - "@webassemblyjs/helper-wasm-bytecode" "1.4.0" - "@webassemblyjs/wast-parser" "1.4.0" - webassemblyjs "1.4.0" + "@webassemblyjs/wast-parser" "1.0.0-y.7" + webassembly-floating-point-hex-parser "0.1.2" + webassemblyjs "1.0.0-y.7" -"@webassemblyjs/floating-point-hex-parser@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.0.tgz#1d573e193fc459b42b60626fb6d3d5a1ad988a66" +"@webassemblyjs/ast@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.1.tgz#8d44bd45cb3e39c33ea0000ca7c54df4b622f0c8" + dependencies: + "@webassemblyjs/helper-wasm-bytecode" "1.4.1" + "@webassemblyjs/wast-parser" "1.4.1" + debug "^3.1.0" + webassemblyjs "1.4.1" -"@webassemblyjs/helper-buffer@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.0.tgz#c3571685a2d71ecb0afba85556bd9a3cec3eb689" +"@webassemblyjs/floating-point-hex-parser@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.1.tgz#f6aca087e185097472007961e8b8bd58e042f084" -"@webassemblyjs/helper-code-frame@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.0.tgz#c88b5932e312dcac1b01bd5130417820199ad161" +"@webassemblyjs/helper-buffer@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.1.tgz#f0c89990845f97a2e919516c1e66ceef930ae113" + +"@webassemblyjs/helper-code-frame@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.1.tgz#744fedcb8dcc61ef79a599699cb46fdaa8045d68" dependencies: - "@webassemblyjs/wast-printer" "1.4.0" + "@webassemblyjs/wast-printer" "1.4.1" -"@webassemblyjs/helper-fsm@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.0.tgz#a9a31678fd04c8bfc6124e4e68cefd07971d2421" +"@webassemblyjs/helper-fsm@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.1.tgz#b365a3afda50f472163b59c1f61bb83f60ff60b8" -"@webassemblyjs/helper-wasm-bytecode@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.0.tgz#bcc4ed104d87f7d62a2ff193f5192222fa5b42ba" +"@webassemblyjs/helper-wasm-bytecode@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.1.tgz#ef060e989f9ac8c913270f9c80298ef39a0819c1" -"@webassemblyjs/helper-wasm-section@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.0.tgz#9a46e637924312efd193a3012899e0aa4ef486aa" +"@webassemblyjs/helper-wasm-section@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.1.tgz#a76753d812c56c692ee8e8b412772e388fe22f63" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/helper-buffer" "1.4.0" - "@webassemblyjs/helper-wasm-bytecode" "1.4.0" - "@webassemblyjs/wasm-gen" "1.4.0" + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/helper-buffer" "1.4.1" + "@webassemblyjs/helper-wasm-bytecode" "1.4.1" + "@webassemblyjs/wasm-gen" "1.4.1" -"@webassemblyjs/leb128@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.0.tgz#de3ab2a73df41a0b6f07ee1faffe51680f2a0cfa" +"@webassemblyjs/leb128@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.1.tgz#c96f0f65a7b833fb19972b80bceda0d5c0a7ab9c" dependencies: leb "^0.3.0" -"@webassemblyjs/validation@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.0.tgz#d09b6acb0397089a1eaaf26b7f66d522f89d224e" +"@webassemblyjs/validation@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.1.tgz#aaabe07eee5183e5e7e6263f92108c5e68b32019" dependencies: - "@webassemblyjs/ast" "1.4.0" + "@webassemblyjs/ast" "1.4.1" -"@webassemblyjs/wasm-edit@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.0.tgz#96703293b470bd79fb33304fd940f4c905ece2d2" - dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/helper-buffer" "1.4.0" - "@webassemblyjs/helper-wasm-bytecode" "1.4.0" - "@webassemblyjs/helper-wasm-section" "1.4.0" - "@webassemblyjs/wasm-gen" "1.4.0" - "@webassemblyjs/wasm-opt" "1.4.0" - "@webassemblyjs/wasm-parser" "1.4.0" - "@webassemblyjs/wast-printer" "1.4.0" +"@webassemblyjs/wasm-edit@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.1.tgz#76bc68470a64c5c36309146548b566c5cb3ce2ec" + dependencies: + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/helper-buffer" "1.4.1" + "@webassemblyjs/helper-wasm-bytecode" "1.4.1" + "@webassemblyjs/helper-wasm-section" "1.4.1" + "@webassemblyjs/wasm-gen" "1.4.1" + "@webassemblyjs/wasm-opt" "1.4.1" + "@webassemblyjs/wasm-parser" "1.4.1" + "@webassemblyjs/wast-printer" "1.4.1" debug "^3.1.0" -"@webassemblyjs/wasm-gen@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.0.tgz#85824fb95c84ac3ed85313b8c81d5af3053c3bba" +"@webassemblyjs/wasm-gen@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.1.tgz#774e5ed7d21a52cb1241a862d3fc73ceaa857ff0" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/helper-wasm-bytecode" "1.4.0" - "@webassemblyjs/leb128" "1.4.0" + "@babel/generator" "^7.0.0-beta.40" + "@babel/template" "^7.0.0-beta.40" + "@babel/types" "^7.0.0-beta.40" + "@webassemblyjs/wasm-parser" "1.0.0-y.7" + commander "^2.14.1" -"@webassemblyjs/wasm-opt@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.0.tgz#b7304cae781616a4987bab2e1804c98d7e29cc1b" +"@webassemblyjs/wasm-opt@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.1.tgz#e5a30ec5bbfb4fe94e83bf616d3a99182ba76655" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/helper-buffer" "1.4.0" - "@webassemblyjs/wasm-gen" "1.4.0" - "@webassemblyjs/wasm-parser" "1.4.0" + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/helper-buffer" "1.4.1" + "@webassemblyjs/wasm-gen" "1.4.1" + "@webassemblyjs/wasm-parser" "1.4.1" -"@webassemblyjs/wasm-parser@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.0.tgz#cf98ef396ad5553196a614c11a4b2ecfd13f1e82" +"@webassemblyjs/wasm-parser@1.0.0-y.7": + version "1.0.0-y.7" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.0.0-y.7.tgz#aafd74a65330d1b39f195717d987e1cfd9e648ba" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/helper-wasm-bytecode" "1.4.0" - "@webassemblyjs/leb128" "1.4.0" - "@webassemblyjs/wasm-parser" "1.4.0" - webassemblyjs "1.4.0" + "@webassemblyjs/ast" "1.0.0-y.7" + "@webassemblyjs/wasm-parser" "1.0.0-y.7" + webassemblyjs "1.0.0-y.7" -"@webassemblyjs/wast-parser@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.0.tgz#9402dfcd67edd455785f29575ad4c9266e5c14ae" +"@webassemblyjs/wasm-parser@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.1.tgz#363d326187d495024eacd63f8720576dded5b4c4" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/floating-point-hex-parser" "1.4.0" - "@webassemblyjs/helper-code-frame" "1.4.0" - "@webassemblyjs/helper-fsm" "1.4.0" + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/helper-wasm-bytecode" "1.4.1" + "@webassemblyjs/leb128" "1.4.1" + "@webassemblyjs/wasm-parser" "1.4.1" + webassemblyjs "1.4.1" + +"@webassemblyjs/wast-parser@1.0.0-y.7": + version "1.0.0-y.7" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.0.0-y.7.tgz#7a2965048b8478a3595a6c9e2054776277f8c3be" + dependencies: + "@babel/code-frame" "^7.0.0-beta.36" + "@webassemblyjs/ast" "1.0.0-y.7" long "^3.2.0" - webassemblyjs "1.4.0" + webassembly-floating-point-hex-parser "0.1.2" + webassemblyjs "1.0.0-y.7" -"@webassemblyjs/wast-printer@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.0.tgz#7223a32cde1fee681e9160ae50b1c3d8d4b50f09" +"@webassemblyjs/wast-parser@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.1.tgz#e2a56084b6062daa78eb3784ad6d3532f3c5ebd9" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/wast-parser" "1.4.0" + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/floating-point-hex-parser" "1.4.1" + "@webassemblyjs/helper-code-frame" "1.4.1" + "@webassemblyjs/helper-fsm" "1.4.1" + long "^3.2.0" + webassemblyjs "1.4.1" + +"@webassemblyjs/wast-printer@1.4.1": + version "1.4.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.1.tgz#d9288e777aa40dadaca9896c9e92aa535ae4212b" + dependencies: + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/wast-parser" "1.4.1" long "^3.2.0" abab@^1.0.4: @@ -594,6 +664,10 @@ babel-types@^6.18.0, babel-types@^6.26.0: lodash "^4.17.4" to-fast-properties "^1.0.3" +babylon@7.0.0-beta.46: + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.46.tgz#b6ddaba81bbb130313932757ff9c195d527088b6" + babylon@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" @@ -1127,7 +1201,7 @@ commander@2.8.x: dependencies: graceful-readlink ">= 1.0.0" -commander@^2.9.0, commander@^2.x: +commander@^2.14.1, commander@^2.9.0, commander@^2.x: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" @@ -3469,6 +3543,10 @@ jsesc@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" +jsesc@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe" + jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" @@ -3659,7 +3737,7 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0: +lodash@^4.13.1, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0: version "4.17.10" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" @@ -5439,7 +5517,7 @@ source-map@0.4.x, source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: +source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -5780,6 +5858,10 @@ to-fast-properties@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" +to-fast-properties@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" + to-object-path@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" @@ -6101,14 +6183,28 @@ watchpack@^1.5.0: graceful-fs "^4.1.2" neo-async "^2.5.0" -webassemblyjs@1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.0.tgz#19473db20153c558fe0b95f143bd344df39fa83a" +webassembly-floating-point-hex-parser@0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/webassembly-floating-point-hex-parser/-/webassembly-floating-point-hex-parser-0.1.2.tgz#85bb01f54e68690c2645ea0cfad26c1110fdf988" + +webassemblyjs@1.0.0-y.7: + version "1.0.0-y.7" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.0.0-y.7.tgz#142ca4d6b37f81531fdf39c49ec6c79c927b7836" + dependencies: + "@webassemblyjs/ast" "1.0.0-y.7" + "@webassemblyjs/wasm-parser" "1.0.0-y.7" + "@webassemblyjs/wast-parser" "1.0.0-y.7" + long "^3.2.0" + webassembly-floating-point-hex-parser "0.1.2" + +webassemblyjs@1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.1.tgz#fdf1eaab969b5ed274a85ebed21418521382a71c" dependencies: - "@webassemblyjs/ast" "1.4.0" - "@webassemblyjs/validation" "1.4.0" - "@webassemblyjs/wasm-parser" "1.4.0" - "@webassemblyjs/wast-parser" "1.4.0" + "@webassemblyjs/ast" "1.4.1" + "@webassemblyjs/validation" "1.4.1" + "@webassemblyjs/wasm-parser" "1.4.1" + "@webassemblyjs/wast-parser" "1.4.1" long "^3.2.0" webidl-conversions@^4.0.1, webidl-conversions@^4.0.2: From a9c771a8aceef9339217b35d9f569355b2f8b142 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Thu, 10 May 2018 13:13:33 -0700 Subject: [PATCH 018/111] fix eslint error --- lib/Template.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Template.js b/lib/Template.js index afa75f2854b..92327ac49f0 100644 --- a/lib/Template.js +++ b/lib/Template.js @@ -46,7 +46,7 @@ const stringifyIdSortPredicate = (a, b) => { /** * @param {Module} module the module to compare against - * @return {boolean} return true if module.id is equal to type "number" + * @returns {boolean} return true if module.id is equal to type "number" */ const moduleIdIsNumber = module => { return typeof module.id === "number"; @@ -176,7 +176,7 @@ class Template { /** * * @param {Module[]} modules a collection of modules to get array bounds for - * @return {[number, number] | false} returns the upper and lower array bounds + * @returns {[number, number] | false} returns the upper and lower array bounds * or false if not every module has a number based id */ static getModulesArrayBounds(modules) { From 912a1a66cc0775366074b9a7de61869d1c38b382 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Thu, 10 May 2018 22:15:24 +0200 Subject: [PATCH 019/111] chore: update lock --- yarn.lock | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 93b77cf746c..af187894761 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16,6 +16,41 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@babel/generator@^7.0.0-beta.40": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.46.tgz#6f57159bcc28bf8c3ed6b549789355cebfa3faa7" + dependencies: + "@babel/types" "7.0.0-beta.46" + jsesc "^2.5.1" + lodash "^4.2.0" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/highlight@7.0.0-beta.46": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.46.tgz#c553c51e65f572bdedd6eff66fc0bb563016645e" + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + +"@babel/template@^7.0.0-beta.40": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.46.tgz#8b23982411d5b5dbfa479437bfe414adb1411bb9" + dependencies: + "@babel/code-frame" "7.0.0-beta.46" + "@babel/types" "7.0.0-beta.46" + babylon "7.0.0-beta.46" + lodash "^4.2.0" + +"@babel/types@7.0.0-beta.46", "@babel/types@^7.0.0-beta.40": + version "7.0.0-beta.46" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.46.tgz#eb84399a699af9fcb244440cce78e1acbeb40e0c" + dependencies: + esutils "^2.0.2" + lodash "^4.2.0" + to-fast-properties "^2.0.0" + "@types/babel-types@*", "@types/babel-types@^7.0.0": version "7.0.2" resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.2.tgz#63dc3e5e7f6367e1819d2bba5213783cd926c5d5" @@ -5646,7 +5681,7 @@ source-map@0.4.x, source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@0.5.x, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: +source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" From f613e9ac2e6de4e8f767e2268ca7dd636ac3aa9d Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sun, 6 May 2018 23:19:41 -0700 Subject: [PATCH 020/111] chore(types): add basic type info for a few warning and errors --- lib/AsyncDependencyToInitialChunkError.js | 14 ++++++++++++-- lib/CaseSensitiveModulesWarning.js | 22 ++++++++++++++++++++-- lib/ModuleDependencyError.js | 14 ++++++++++++-- lib/WebpackError.js | 10 ++++++++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/lib/AsyncDependencyToInitialChunkError.js b/lib/AsyncDependencyToInitialChunkError.js index 723cf08bb92..78eeb81346c 100644 --- a/lib/AsyncDependencyToInitialChunkError.js +++ b/lib/AsyncDependencyToInitialChunkError.js @@ -6,7 +6,15 @@ const WebpackError = require("./WebpackError"); -module.exports = class AsyncDependencyToInitialChunkError extends WebpackError { +/** @typedef {import("./Module")} Module */ + +class AsyncDependencyToInitialChunkError extends WebpackError { + /** + * Creates an instance of AsyncDependencyToInitialChunkError. + * @param {string} chunkName Name of Chunk + * @param {Module} module module tied to dependency + * @param {TODO} loc location of dependency + */ constructor(chunkName, module, loc) { super(); @@ -18,4 +26,6 @@ module.exports = class AsyncDependencyToInitialChunkError extends WebpackError { Error.captureStackTrace(this, this.constructor); } -}; +} + +module.exports = AsyncDependencyToInitialChunkError; diff --git a/lib/CaseSensitiveModulesWarning.js b/lib/CaseSensitiveModulesWarning.js index 30802331c24..98237cfcb8d 100644 --- a/lib/CaseSensitiveModulesWarning.js +++ b/lib/CaseSensitiveModulesWarning.js @@ -6,7 +6,13 @@ const WebpackError = require("./WebpackError"); -module.exports = class CaseSensitiveModulesWarning extends WebpackError { +/** @typedef {import("./Module")} Module */ + +class CaseSensitiveModulesWarning extends WebpackError { + /** + * Creates an instance of CaseSensitiveModulesWarning. + * @param {Module[]} modules modules that were detected + */ constructor(modules) { super(); @@ -23,6 +29,11 @@ ${modulesList}`; Error.captureStackTrace(this, this.constructor); } + /** + * @private + * @param {Module[]} modules the modules to be sorted + * @returns {Module[]} sorted version of original modules + */ _sort(modules) { return modules.slice().sort((a, b) => { a = a.identifier(); @@ -36,6 +47,11 @@ ${modulesList}`; }); } + /** + * @private + * @param {Module[]} modules each module from throw + * @returns {string} each message from provided moduels + */ _moduleMessages(modules) { return modules .map(m => { @@ -50,4 +66,6 @@ ${modulesList}`; }) .join("\n"); } -}; +} + +module.exports = CaseSensitiveModulesWarning; diff --git a/lib/ModuleDependencyError.js b/lib/ModuleDependencyError.js index 9133e14453d..f52092021a3 100644 --- a/lib/ModuleDependencyError.js +++ b/lib/ModuleDependencyError.js @@ -7,7 +7,15 @@ const WebpackError = require("./WebpackError"); const formatLocation = require("./formatLocation"); -module.exports = class ModuleDependencyError extends WebpackError { +/** @typedef {import("./Module")} Module */ + +class ModuleDependencyError extends WebpackError { + /** + * Creates an instance of ModuleDependencyError. + * @param {Module} module module tied to dependency + * @param {Error} err error thrown + * @param {TODO} loc location of dependency + */ constructor(module, err, loc) { super(); @@ -22,4 +30,6 @@ module.exports = class ModuleDependencyError extends WebpackError { Error.captureStackTrace(this, this.constructor); } -}; +} + +module.exports = ModuleDependencyError; diff --git a/lib/WebpackError.js b/lib/WebpackError.js index 4fd23388178..8451fcb7d74 100644 --- a/lib/WebpackError.js +++ b/lib/WebpackError.js @@ -4,7 +4,11 @@ */ "use strict"; -module.exports = class WebpackError extends Error { +class WebpackError extends Error { + /** + * Creates an instance of WebpackError. + * @param {string=} message error message + */ constructor(message) { super(message); @@ -16,4 +20,6 @@ module.exports = class WebpackError extends Error { inspect() { return this.stack + (this.details ? `\n${this.details}` : ""); } -}; +} + +module.exports = WebpackError; From 561e95eb3154c33613383cf9f027e6f3f50765e9 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 09:46:16 +0200 Subject: [PATCH 021/111] use const --- lib/BannerPlugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/BannerPlugin.js b/lib/BannerPlugin.js index 544d4b4227b..930990ad8d3 100644 --- a/lib/BannerPlugin.js +++ b/lib/BannerPlugin.js @@ -39,12 +39,12 @@ class BannerPlugin { this.options = options || {}; if (typeof options.banner === "function") { - let getBanner = this.options.banner; + const getBanner = this.options.banner; this.banner = this.options.raw ? getBanner : data => wrapComment(getBanner(data)); } else { - let banner = this.options.raw + const banner = this.options.raw ? this.options.banner : wrapComment(this.options.banner); this.banner = () => banner; From 17bcc3c9db736e427a0c2566d011dd56a5aec57d Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 16:06:20 +0200 Subject: [PATCH 022/111] enable eslint caching --- .gitignore | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f7a05a2b815..32814bb493a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ *.log .idea .vscode +.eslintcache package-lock.json diff --git a/package.json b/package.json index 6913207d4ba..4f6c66673ec 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "pretest": "yarn lint", "prelint": "yarn setup", "lint": "yarn code-lint && yarn schema-lint && yarn type-lint", - "code-lint": "eslint setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", + "code-lint": "eslint --cache setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", "type-lint": "tsc --pretty", "fix": "yarn code-lint --fix", "pretty": "prettier \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" \"declarations.d.ts\" --write", From 38456ead4da744a96b5bdf348dea4cc98b53c227 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Fri, 11 May 2018 16:16:01 +0200 Subject: [PATCH 023/111] chore: bump webassemblyjs --- package.json | 6 +- yarn.lock | 293 +++++++++++++++++---------------------------------- 2 files changed, 102 insertions(+), 197 deletions(-) diff --git a/package.json b/package.json index bd2e21abb3d..7ef53b57944 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "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.4.1", - "@webassemblyjs/wasm-edit": "1.4.1", - "@webassemblyjs/wasm-parser": "1.4.1", + "@webassemblyjs/ast": "1.4.2", + "@webassemblyjs/wasm-edit": "1.4.2", + "@webassemblyjs/wasm-parser": "1.4.2", "acorn": "^5.0.0", "acorn-dynamic-import": "^3.0.0", "ajv": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index af187894761..16d0b6b7603 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,12 +2,6 @@ # yarn lockfile v1 -"@babel/code-frame@7.0.0-beta.46", "@babel/code-frame@^7.0.0-beta.36": - version "7.0.0-beta.46" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.46.tgz#e0d002100805daab1461c0fcb32a07e304f3a4f4" - dependencies: - "@babel/highlight" "7.0.0-beta.46" - "@babel/code-frame@^7.0.0-beta.35": version "7.0.0-beta.38" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.38.tgz#c0af5930617e55e050336838e3a3670983b0b2b2" @@ -16,41 +10,6 @@ esutils "^2.0.2" js-tokens "^3.0.0" -"@babel/generator@^7.0.0-beta.40": - version "7.0.0-beta.46" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.46.tgz#6f57159bcc28bf8c3ed6b549789355cebfa3faa7" - dependencies: - "@babel/types" "7.0.0-beta.46" - jsesc "^2.5.1" - lodash "^4.2.0" - source-map "^0.5.0" - trim-right "^1.0.1" - -"@babel/highlight@7.0.0-beta.46": - version "7.0.0-beta.46" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.46.tgz#c553c51e65f572bdedd6eff66fc0bb563016645e" - dependencies: - chalk "^2.0.0" - esutils "^2.0.2" - js-tokens "^3.0.0" - -"@babel/template@^7.0.0-beta.40": - version "7.0.0-beta.46" - resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.46.tgz#8b23982411d5b5dbfa479437bfe414adb1411bb9" - dependencies: - "@babel/code-frame" "7.0.0-beta.46" - "@babel/types" "7.0.0-beta.46" - babylon "7.0.0-beta.46" - lodash "^4.2.0" - -"@babel/types@7.0.0-beta.46", "@babel/types@^7.0.0-beta.40": - version "7.0.0-beta.46" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.46.tgz#eb84399a699af9fcb244440cce78e1acbeb40e0c" - dependencies: - esutils "^2.0.2" - lodash "^4.2.0" - to-fast-properties "^2.0.0" - "@types/babel-types@*", "@types/babel-types@^7.0.0": version "7.0.2" resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.2.tgz#63dc3e5e7f6367e1819d2bba5213783cd926c5d5" @@ -69,144 +28,116 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd" -"@webassemblyjs/ast@1.0.0-y.7": - version "1.0.0-y.7" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.0.0-y.7.tgz#081dd61dd50030d4008aac9baf0ef5ff0cc2cab9" - dependencies: - "@webassemblyjs/wast-parser" "1.0.0-y.7" - webassembly-floating-point-hex-parser "0.1.2" - webassemblyjs "1.0.0-y.7" - -"@webassemblyjs/ast@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.1.tgz#8d44bd45cb3e39c33ea0000ca7c54df4b622f0c8" +"@webassemblyjs/ast@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.2.tgz#ab715aa1fec9dd23c025204dba39690c119418ea" dependencies: - "@webassemblyjs/helper-wasm-bytecode" "1.4.1" - "@webassemblyjs/wast-parser" "1.4.1" + "@webassemblyjs/helper-wasm-bytecode" "1.4.2" + "@webassemblyjs/wast-parser" "1.4.2" debug "^3.1.0" - webassemblyjs "1.4.1" + webassemblyjs "1.4.2" -"@webassemblyjs/floating-point-hex-parser@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.1.tgz#f6aca087e185097472007961e8b8bd58e042f084" +"@webassemblyjs/floating-point-hex-parser@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.2.tgz#9296fb64caa37bf98c8064aa329680e3e2bfacc7" -"@webassemblyjs/helper-buffer@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.1.tgz#f0c89990845f97a2e919516c1e66ceef930ae113" +"@webassemblyjs/helper-buffer@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.2.tgz#3cacecd5a6bfcb67932ed8219f81f92d8b2dafbb" -"@webassemblyjs/helper-code-frame@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.1.tgz#744fedcb8dcc61ef79a599699cb46fdaa8045d68" +"@webassemblyjs/helper-code-frame@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.2.tgz#20526637c3849f12b08f8661248477eef9642329" dependencies: - "@webassemblyjs/wast-printer" "1.4.1" + "@webassemblyjs/wast-printer" "1.4.2" -"@webassemblyjs/helper-fsm@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.1.tgz#b365a3afda50f472163b59c1f61bb83f60ff60b8" +"@webassemblyjs/helper-fsm@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.2.tgz#e41050282994b5be077b95b65b66ecd5a92c5e88" -"@webassemblyjs/helper-wasm-bytecode@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.1.tgz#ef060e989f9ac8c913270f9c80298ef39a0819c1" +"@webassemblyjs/helper-wasm-bytecode@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.2.tgz#b48c289c7921056aa12d71e78a17070ffe90c49c" -"@webassemblyjs/helper-wasm-section@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.1.tgz#a76753d812c56c692ee8e8b412772e388fe22f63" +"@webassemblyjs/helper-wasm-section@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.2.tgz#520e02c0cc3e5e9b5f44f58abc04ba5eda6e5476" dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/helper-buffer" "1.4.1" - "@webassemblyjs/helper-wasm-bytecode" "1.4.1" - "@webassemblyjs/wasm-gen" "1.4.1" + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/helper-buffer" "1.4.2" + "@webassemblyjs/helper-wasm-bytecode" "1.4.2" + "@webassemblyjs/wasm-gen" "1.4.2" -"@webassemblyjs/leb128@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.1.tgz#c96f0f65a7b833fb19972b80bceda0d5c0a7ab9c" +"@webassemblyjs/leb128@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.2.tgz#d13f368abdcefc54428f55a265a993de610f8893" dependencies: leb "^0.3.0" -"@webassemblyjs/validation@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.1.tgz#aaabe07eee5183e5e7e6263f92108c5e68b32019" - dependencies: - "@webassemblyjs/ast" "1.4.1" - -"@webassemblyjs/wasm-edit@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.1.tgz#76bc68470a64c5c36309146548b566c5cb3ce2ec" - dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/helper-buffer" "1.4.1" - "@webassemblyjs/helper-wasm-bytecode" "1.4.1" - "@webassemblyjs/helper-wasm-section" "1.4.1" - "@webassemblyjs/wasm-gen" "1.4.1" - "@webassemblyjs/wasm-opt" "1.4.1" - "@webassemblyjs/wasm-parser" "1.4.1" - "@webassemblyjs/wast-printer" "1.4.1" - debug "^3.1.0" - -"@webassemblyjs/wasm-gen@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.1.tgz#774e5ed7d21a52cb1241a862d3fc73ceaa857ff0" - dependencies: - "@babel/generator" "^7.0.0-beta.40" - "@babel/template" "^7.0.0-beta.40" - "@babel/types" "^7.0.0-beta.40" - "@webassemblyjs/wasm-parser" "1.0.0-y.7" - commander "^2.14.1" - -"@webassemblyjs/wasm-opt@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.1.tgz#e5a30ec5bbfb4fe94e83bf616d3a99182ba76655" +"@webassemblyjs/validation@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.2.tgz#55cf5b219e25900c85773fc35beb9d12ae0ede53" dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/helper-buffer" "1.4.1" - "@webassemblyjs/wasm-gen" "1.4.1" - "@webassemblyjs/wasm-parser" "1.4.1" + "@webassemblyjs/ast" "1.4.2" -"@webassemblyjs/wasm-parser@1.0.0-y.7": - version "1.0.0-y.7" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.0.0-y.7.tgz#aafd74a65330d1b39f195717d987e1cfd9e648ba" +"@webassemblyjs/wasm-edit@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.2.tgz#bde9a581065f63f257ed511d7d9cf04f8cd04524" dependencies: - "@webassemblyjs/ast" "1.0.0-y.7" - "@webassemblyjs/wasm-parser" "1.0.0-y.7" - webassemblyjs "1.0.0-y.7" - -"@webassemblyjs/wasm-parser@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.1.tgz#363d326187d495024eacd63f8720576dded5b4c4" - dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/helper-wasm-bytecode" "1.4.1" - "@webassemblyjs/leb128" "1.4.1" - "@webassemblyjs/wasm-parser" "1.4.1" - webassemblyjs "1.4.1" - -"@webassemblyjs/wast-parser@1.0.0-y.7": - version "1.0.0-y.7" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.0.0-y.7.tgz#7a2965048b8478a3595a6c9e2054776277f8c3be" - dependencies: - "@babel/code-frame" "^7.0.0-beta.36" - "@webassemblyjs/ast" "1.0.0-y.7" - long "^3.2.0" - webassembly-floating-point-hex-parser "0.1.2" - webassemblyjs "1.0.0-y.7" + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/helper-buffer" "1.4.2" + "@webassemblyjs/helper-wasm-bytecode" "1.4.2" + "@webassemblyjs/helper-wasm-section" "1.4.2" + "@webassemblyjs/wasm-gen" "1.4.2" + "@webassemblyjs/wasm-opt" "1.4.2" + "@webassemblyjs/wasm-parser" "1.4.2" + "@webassemblyjs/wast-printer" "1.4.2" + debug "^3.1.0" -"@webassemblyjs/wast-parser@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.1.tgz#e2a56084b6062daa78eb3784ad6d3532f3c5ebd9" - dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/floating-point-hex-parser" "1.4.1" - "@webassemblyjs/helper-code-frame" "1.4.1" - "@webassemblyjs/helper-fsm" "1.4.1" +"@webassemblyjs/wasm-gen@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.2.tgz#0899297f9426073736df799287845a73c597cf90" + dependencies: + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/helper-wasm-bytecode" "1.4.2" + "@webassemblyjs/leb128" "1.4.2" + +"@webassemblyjs/wasm-opt@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.2.tgz#c44ad48e109aec197e3bf69875c54537d76ba2e9" + dependencies: + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/helper-buffer" "1.4.2" + "@webassemblyjs/wasm-gen" "1.4.2" + "@webassemblyjs/wasm-parser" "1.4.2" + +"@webassemblyjs/wasm-parser@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.2.tgz#3bf7e10cfe336db0ecdea0a5d7ed8a63b7a7754a" + dependencies: + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/helper-wasm-bytecode" "1.4.2" + "@webassemblyjs/leb128" "1.4.2" + "@webassemblyjs/wasm-parser" "1.4.2" + webassemblyjs "1.4.2" + +"@webassemblyjs/wast-parser@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.2.tgz#6499c38cf8895a81394f7e40d4681a85aaa84498" + dependencies: + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/floating-point-hex-parser" "1.4.2" + "@webassemblyjs/helper-code-frame" "1.4.2" + "@webassemblyjs/helper-fsm" "1.4.2" long "^3.2.0" - webassemblyjs "1.4.1" + webassemblyjs "1.4.2" -"@webassemblyjs/wast-printer@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.1.tgz#d9288e777aa40dadaca9896c9e92aa535ae4212b" +"@webassemblyjs/wast-printer@1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.2.tgz#ee70a828f0d9730b55b9a5c3ed694094ba68ba57" dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/wast-parser" "1.4.1" + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/wast-parser" "1.4.2" long "^3.2.0" abab@^1.0.4: @@ -684,10 +615,6 @@ babel-types@^6.18.0, babel-types@^6.26.0: lodash "^4.17.4" to-fast-properties "^1.0.3" -babylon@7.0.0-beta.46: - version "7.0.0-beta.46" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.46.tgz#b6ddaba81bbb130313932757ff9c195d527088b6" - babylon@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" @@ -1233,7 +1160,7 @@ commander@2.8.x: dependencies: graceful-readlink ">= 1.0.0" -commander@^2.14.1, commander@^2.9.0, commander@^2.x: +commander@^2.9.0, commander@^2.x: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" @@ -3599,10 +3526,6 @@ jsesc@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" -jsesc@^2.5.1: - version "2.5.1" - resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe" - jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" @@ -3800,7 +3723,7 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -lodash@^4.13.1, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0: +lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0: version "4.17.10" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" @@ -5681,7 +5604,7 @@ source-map@0.4.x, source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: +source-map@0.5.x, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -6022,10 +5945,6 @@ to-fast-properties@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" -to-fast-properties@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" - to-object-path@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" @@ -6351,28 +6270,14 @@ watchpack@^1.5.0: graceful-fs "^4.1.2" neo-async "^2.5.0" -webassembly-floating-point-hex-parser@0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/webassembly-floating-point-hex-parser/-/webassembly-floating-point-hex-parser-0.1.2.tgz#85bb01f54e68690c2645ea0cfad26c1110fdf988" - -webassemblyjs@1.0.0-y.7: - version "1.0.0-y.7" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.0.0-y.7.tgz#142ca4d6b37f81531fdf39c49ec6c79c927b7836" - dependencies: - "@webassemblyjs/ast" "1.0.0-y.7" - "@webassemblyjs/wasm-parser" "1.0.0-y.7" - "@webassemblyjs/wast-parser" "1.0.0-y.7" - long "^3.2.0" - webassembly-floating-point-hex-parser "0.1.2" - -webassemblyjs@1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.1.tgz#fdf1eaab969b5ed274a85ebed21418521382a71c" +webassemblyjs@1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.2.tgz#3b07b506917c97153d83441d8a88ffa2d25cc07d" dependencies: - "@webassemblyjs/ast" "1.4.1" - "@webassemblyjs/validation" "1.4.1" - "@webassemblyjs/wasm-parser" "1.4.1" - "@webassemblyjs/wast-parser" "1.4.1" + "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/validation" "1.4.2" + "@webassemblyjs/wasm-parser" "1.4.2" + "@webassemblyjs/wast-parser" "1.4.2" long "^3.2.0" webidl-conversions@^4.0.1, webidl-conversions@^4.0.2: From e2c8f3d501dcd891ce943c1be393f34aba7d31ca Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 16:46:33 +0200 Subject: [PATCH 024/111] remove passing AST, redecode AST in Generator --- lib/wasm/WebAssemblyGenerator.js | 8 ++++++-- lib/wasm/WebAssemblyParser.js | 10 ---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index d4fb1255a6d..7174be66a91 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -6,9 +6,9 @@ const Generator = require("../Generator"); const { RawSource } = require("webpack-sources"); -const WebAssemblyParser = require("./WebAssemblyParser"); const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); +const { decode } = require("@webassemblyjs/wasm-parser"); const t = require("@webassemblyjs/ast"); function compose(...fns) { @@ -244,9 +244,13 @@ const addInitFunction = ({ class WebAssemblyGenerator extends Generator { generate(module) { - const ast = WebAssemblyParser.getAst(module); const bin = module.originalSource().source(); + const ast = decode(bin, { + ignoreDataSection: true, + ignoreCodeSection: true + }); + const importedGlobals = getImportedGlobals(ast); const countImportedFunc = getCountImportedFunc(ast); const startAtFuncIndex = getStartFuncIndex(ast); diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index 0cfd037257f..559208f4505 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -29,9 +29,6 @@ const decoderOpts = { ignoreDataSection: true }; -/** @type {WeakMap} */ -const astStore = new WeakMap(); - class WebAssemblyParser extends Tapable { constructor(options) { super(); @@ -39,10 +36,6 @@ class WebAssemblyParser extends Tapable { this.options = options; } - static getAst(module) { - return astStore.get(module); - } - parse(binary, state) { // flag it as ESM state.module.buildMeta.exportsType = "namespace"; @@ -50,9 +43,6 @@ class WebAssemblyParser extends Tapable { // parse it const ast = decode(binary, decoderOpts); - // cache it to be available for generators - astStore.set(state.module, ast); - // extract imports and exports const exports = (state.module.buildMeta.providedExports = []); t.traverse(ast, { From bbb9f38b719fd09e85189e69e8e90747808bbf41 Mon Sep 17 00:00:00 2001 From: Krzysztof Czopp Date: Sun, 6 May 2018 09:36:28 +0100 Subject: [PATCH 025/111] fix: ReferenceError: onScriptComplete is not defined when using HMR on Firefox 45 --- lib/web/JsonpMainTemplatePlugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web/JsonpMainTemplatePlugin.js b/lib/web/JsonpMainTemplatePlugin.js index 412e4d68ef5..906dca4c0ff 100644 --- a/lib/web/JsonpMainTemplatePlugin.js +++ b/lib/web/JsonpMainTemplatePlugin.js @@ -173,7 +173,6 @@ class JsonpMainTemplatePlugin { "onScriptComplete({ type: 'timeout', target: script });" ]), `}, ${chunkLoadTimeout});`, - "script.onerror = script.onload = onScriptComplete;", "function onScriptComplete(event) {", Template.indent([ "// avoid mem leaks in IE.", @@ -196,7 +195,8 @@ class JsonpMainTemplatePlugin { ]), "}" ]), - "};" + "};", + "script.onerror = script.onload = onScriptComplete;" ]); } ); From c92eabd3be44d4162be0affc9ef368624b0a6e51 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 18:13:07 +0200 Subject: [PATCH 026/111] 4.8.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ef53b57944..7c1ea3969f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack", - "version": "4.8.1", + "version": "4.8.2", "author": "Tobias Koppers @sokra", "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", From 737eaa51b6ffe3886c85e5660a9446f101f7c71a Mon Sep 17 00:00:00 2001 From: Jaehwan Moon Date: Fri, 11 May 2018 13:06:10 -0400 Subject: [PATCH 027/111] Fix a bug where ProgressPlugin is not working properly with MultiCompiler --- lib/ProgressPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProgressPlugin.js b/lib/ProgressPlugin.js index 713e8d9db26..137bb492ea5 100644 --- a/lib/ProgressPlugin.js +++ b/lib/ProgressPlugin.js @@ -83,7 +83,7 @@ class ProgressPlugin { const states = new Array(compiler.compilers.length); compiler.compilers.forEach((compiler, idx) => { new ProgressPlugin((p, msg, ...args) => { - states[idx] = args; + states[idx] = [p, msg, ...args]; handler( states .map(state => (state && state[0]) || 0) From 81de2d43142da436eceef86f02d3425af17c00e4 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Fri, 11 May 2018 11:35:44 -0700 Subject: [PATCH 028/111] chore(deps): upgrade typescript nightly --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7c1ea3969f1..61bb7b1025f 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "script-loader": "~0.7.0", "simple-git": "^1.65.0", "style-loader": "^0.19.1", - "typescript": "^2.9.0-dev.20180506", + "typescript": "^2.9.0-dev.20180511", "url-loader": "^0.6.2", "val-loader": "^1.0.2", "vm-browserify": "~0.0.0", diff --git a/yarn.lock b/yarn.lock index 16d0b6b7603..14827f7ef3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6042,9 +6042,9 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@^2.9.0-dev.20180506: - version "2.9.0-dev.20180506" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.0-dev.20180506.tgz#e20070caa88fca90227cf040459402611a74e13f" +typescript@^2.9.0-dev.20180511: + version "2.9.0-dev.20180511" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.0-dev.20180511.tgz#e864f6b9bf9e7f654d26f5401e74b76871f5a8e2" ua-parser-js@^0.7.9: version "0.7.17" From f903cd3ef9535000eb110e097b5e24d9c3d8130c Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 9 May 2018 16:19:31 +0200 Subject: [PATCH 029/111] mangle exports of wasm modules mangle webpack init function store WebAssembly.Instance.exports directly connect wasm modules directly when already cached --- lib/MainTemplate.js | 2 +- lib/wasm/WasmMainTemplatePlugin.js | 21 ++++++----- lib/wasm/WebAssemblyGenerator.js | 41 ++++++++++++++++++++-- lib/wasm/WebAssemblyJavascriptGenerator.js | 37 ++++++------------- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/lib/MainTemplate.js b/lib/MainTemplate.js index a9c1be0fd9f..378fbb59c42 100644 --- a/lib/MainTemplate.js +++ b/lib/MainTemplate.js @@ -46,7 +46,7 @@ const Template = require("./Template"); // __webpack_require__.r = define compatibility on export // __webpack_require__.n = compatibility get default export // __webpack_require__.h = the webpack hash -// __webpack_require__.w = an object containing all installed WebAssembly.Modules keys by module id +// __webpack_require__.w = an object containing all installed WebAssembly.Instance export objects keyed by module id // __webpack_require__.oe = the uncaught error handler for the webpack runtime // __webpack_require__.nc = the script nonce diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index 6f4a23d41f7..48ec88566b7 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -67,22 +67,25 @@ function generateImportObject(module) { `installedWasmModules[${JSON.stringify(data.module.id)}]` ); properties.push( - `${JSON.stringify(data.exportName)}: ${instanceVar}.exports` + - `[${JSON.stringify(data.exportName)}]` + `${JSON.stringify(data.exportName)}: ${instanceVar}` + + `[${JSON.stringify(data.usedName)}]` ); } else { const params = data.description.signature.params.map( (param, k) => "p" + k + param.valtype ); - const result = `__webpack_require__(${JSON.stringify( - data.module.id - )})[${JSON.stringify(data.usedName)}](${params})`; + const mod = `installedModules[${JSON.stringify(data.module.id)}]`; + const func = `${mod}.exports[${JSON.stringify(data.usedName)}]`; properties.push( Template.asString([ - `${JSON.stringify(data.exportName)}: function(${params}) {`, - Template.indent([`return ${result};`]), + `${JSON.stringify(data.exportName)}: ` + + (data.module.type.startsWith("webassembly") + ? `${mod} ? ${func} : ` + : "") + + `function(${params}) {`, + Template.indent([`return ${func}(${params});`]), "}" ]) ); @@ -257,7 +260,7 @@ class WasmMainTemplatePlugin { Template.indent([ `return ${ mainTemplate.requireFn - }.w[wasmModuleId] = res.instance || res;` + }.w[wasmModuleId] = (res.instance || res).exports;` ]), "}));" ]), @@ -275,7 +278,7 @@ class WasmMainTemplatePlugin { return Template.asString([ source, "", - "// object with all WebAssembly.instance", + "// object with all WebAssembly.instance exports", `${mainTemplate.requireFn}.w = {};` ]); } diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 7174be66a91..5afc60b5a65 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -5,6 +5,7 @@ "use strict"; const Generator = require("../Generator"); +const Template = require("../Template"); const { RawSource } = require("webpack-sources"); const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); @@ -12,7 +13,7 @@ const { decode } = require("@webassemblyjs/wasm-parser"); const t = require("@webassemblyjs/ast"); function compose(...fns) { - return fns.reverse().reduce((prevFn, nextFn) => { + return fns.reduce((prevFn, nextFn) => { return value => nextFn(prevFn(value)); }, value => value); } @@ -31,8 +32,6 @@ const isGlobalImport = n => n.descr.type === "GlobalType"; */ const isFuncImport = n => n.descr.type === "FuncImportDescr"; -const initFuncId = t.identifier("__webpack_init__"); - // TODO replace with @callback /** * @typedef {(ArrayBuffer) => ArrayBuffer} ArrayBufferTransform @@ -181,6 +180,28 @@ const rewriteImportedGlobals = state => bin => { return addWithAST(state.ast, bin, newGlobals); }; +/** + * Rewrite the export names + * @param {Object} state state + * @param {Object} state.ast Module's ast + * @param {Object} state.module Module + * @returns {ArrayBufferTransform} transform + */ +const rewriteExportNames = ({ ast, module }) => bin => { + return editWithAST(ast, bin, { + ModuleExport(path) { + const usedName = module.isUsed(path.node.name); + if (usedName) { + path.node.name = usedName; + // TODO remove this when fixed in @webassemblyjs + path.node.descr.id = t.numberLiteral(+path.node.descr.id.raw); + } else { + path.remove(); + } + } + }); +}; + /** * Add an init function. * @@ -188,6 +209,7 @@ const rewriteImportedGlobals = state => bin => { * * @param {Object} state transformation state * @param {Object} state.ast - Module's ast + * @param {t.Identifier} state.initFuncId identifier of the init function * @param {t.IndexLiteral} state.startAtFuncIndex index of the start function * @param {t.ModuleImport[]} state.importedGlobals list of imported globals * @param {t.IndexLiteral} state.nextFuncIndex index of the next function @@ -196,6 +218,7 @@ const rewriteImportedGlobals = state => bin => { */ const addInitFunction = ({ ast, + initFuncId, startAtFuncIndex, importedGlobals, nextFuncIndex, @@ -246,6 +269,12 @@ class WebAssemblyGenerator extends Generator { generate(module) { const bin = module.originalSource().source(); + const initFuncId = t.identifier( + Array.isArray(module.usedExports) + ? Template.numberToIdentifer(module.usedExports.length) + : "__webpack_init__" + ); + const ast = decode(bin, { ignoreDataSection: true, ignoreCodeSection: true @@ -258,12 +287,18 @@ class WebAssemblyGenerator extends Generator { const nextTypeIndex = getNextTypeIndex(ast); const transform = compose( + rewriteExportNames({ + ast, + module + }), + removeStartFunc({ ast }), rewriteImportedGlobals({ ast }), addInitFunction({ ast, + initFuncId, importedGlobals, startAtFuncIndex, nextFuncIndex, diff --git a/lib/wasm/WebAssemblyJavascriptGenerator.js b/lib/wasm/WebAssemblyJavascriptGenerator.js index aac4b3cd7cc..8bf15854fe4 100644 --- a/lib/wasm/WebAssemblyJavascriptGenerator.js +++ b/lib/wasm/WebAssemblyJavascriptGenerator.js @@ -39,29 +39,9 @@ function generateInitParams(module) { class WebAssemblyJavascriptGenerator extends Generator { generate(module, dependencyTemplates, runtimeTemplate) { - const generateExports = () => { - if ( - Array.isArray(module.buildMeta.providedExports) && - Array.isArray(module.usedExports) - ) { - // generate mangled exports - return Template.asString( - module.buildMeta.providedExports.map(exp => { - const usedName = module.isUsed(exp); - if (usedName) { - return `${module.exportsArgument}[${JSON.stringify( - usedName - )}] = instance.exports[${JSON.stringify(exp)}];`; - } else { - return `// unused ${JSON.stringify(exp)} export`; - } - }) - ); - } else { - // generate simple export - return `${module.moduleArgument}.exports = instance.exports;`; - } - }; + const initIdentifer = Array.isArray(module.usedExports) + ? Template.numberToIdentifer(module.usedExports.length) + : "__webpack_init__"; const generateImports = () => { const modules = new Map(); @@ -87,17 +67,20 @@ class WebAssemblyJavascriptGenerator extends Generator { [ '"use strict";', "// Instantiate WebAssembly module", - "var instance = __webpack_require__.w[module.i];", + "var wasmExports = __webpack_require__.w[module.i];", // this must be before import for circular dependencies "// export exports from WebAssembly module", - generateExports(), - + Array.isArray(module.usedExports) + ? `${module.moduleArgument}.exports = wasmExports;` + : "for(var name in wasmExports) " + + `if(name != ${JSON.stringify(initIdentifer)}) ` + + `${module.exportsArgument}[name] = wasmExports[name];`, "// exec imports from WebAssembly module (for esm order)", generateImports(), "// exec wasm module", - `instance.exports.__webpack_init__(${initParams})` + `wasmExports[${JSON.stringify(initIdentifer)}](${initParams})` ].join("\n") ); return source; From fb29d633dbfeba009db4f890133c0b0a33e23d3c Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 10 May 2018 11:34:09 +0200 Subject: [PATCH 030/111] Mangle import names and module requests --- lib/wasm/WasmMainTemplatePlugin.js | 112 ++++++++---------- lib/wasm/WebAssemblyGenerator.js | 53 +++++++++ test/cases/wasm/imports-multiple/index.js | 5 + test/cases/wasm/imports-multiple/module.js | 7 ++ test/cases/wasm/imports-multiple/module2.js | 5 + .../wasm/imports-multiple/test.filter.js | 5 + test/cases/wasm/imports-multiple/wasm.wasm | Bin 0 -> 202 bytes 7 files changed, 122 insertions(+), 65 deletions(-) create mode 100644 test/cases/wasm/imports-multiple/index.js create mode 100644 test/cases/wasm/imports-multiple/module.js create mode 100644 test/cases/wasm/imports-multiple/module2.js create mode 100644 test/cases/wasm/imports-multiple/test.filter.js create mode 100644 test/cases/wasm/imports-multiple/wasm.wasm diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index 48ec88566b7..0b0f1cb06ed 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -23,7 +23,9 @@ function getAllWasmModules(chunk) { } function generateImportObject(module) { - const depsByRequest = new Map(); + const waitForPromises = new Map(); + const properties = []; + let importIndex = 0; for (const dep of module.dependencies) { if (dep instanceof WebAssemblyImportDependency) { // Ignore global they will be handled later @@ -31,74 +33,54 @@ function generateImportObject(module) { continue; } - const request = dep.request; - let array = depsByRequest.get(request); - if (!array) { - depsByRequest.set(request, (array = [])); - } - const exportName = dep.name; - const usedName = dep.module && dep.module.isUsed(exportName); - if (dep.module === null) { // Dependency was not found, an error will be thrown later continue; } + const importedModule = dep.module; + const exportName = dep.name; + const usedName = importedModule && importedModule.isUsed(exportName); if (usedName !== false) { - array.push({ - exportName, - usedName, - module: dep.module, - description: dep.description, - direct: dep.onlyDirectImport - }); - } - } - } - const importsCode = []; - const waitForPromises = new Map(); - for (const pair of depsByRequest) { - const properties = []; - for (const data of pair[1]) { - if (data.direct) { - const instanceVar = `m${waitForPromises.size}`; - waitForPromises.set( - instanceVar, - `installedWasmModules[${JSON.stringify(data.module.id)}]` - ); - properties.push( - `${JSON.stringify(data.exportName)}: ${instanceVar}` + - `[${JSON.stringify(data.usedName)}]` - ); - } else { - const params = data.description.signature.params.map( - (param, k) => "p" + k + param.valtype - ); + const description = dep.description; + const direct = dep.onlyDirectImport; - const mod = `installedModules[${JSON.stringify(data.module.id)}]`; - const func = `${mod}.exports[${JSON.stringify(data.usedName)}]`; + const index = importIndex++; - properties.push( - Template.asString([ - `${JSON.stringify(data.exportName)}: ` + - (data.module.type.startsWith("webassembly") - ? `${mod} ? ${func} : ` - : "") + - `function(${params}) {`, - Template.indent([`return ${func}(${params});`]), - "}" - ]) - ); + const propertyName = Template.numberToIdentifer(index); + + if (direct) { + const instanceVar = `m${waitForPromises.size}`; + waitForPromises.set( + instanceVar, + `installedWasmModules[${JSON.stringify(importedModule.id)}]` + ); + properties.push( + `${JSON.stringify(propertyName)}: ${instanceVar}` + + `[${JSON.stringify(usedName)}]` + ); + } else { + const params = description.signature.params.map( + (param, k) => "p" + k + param.valtype + ); + + const mod = `installedModules[${JSON.stringify(importedModule.id)}]`; + const func = `${mod}.exports[${JSON.stringify(usedName)}]`; + + properties.push( + Template.asString([ + `${JSON.stringify(propertyName)}: ` + + (importedModule.type.startsWith("webassembly") + ? `${mod} ? ${func} : ` + : "") + + `function(${params}) {`, + Template.indent([`return ${func}(${params});`]), + "}" + ]) + ); + } } } - - importsCode.push( - Template.asString([ - `${JSON.stringify(pair[0])}: {`, - Template.indent([properties.join(",")]), - "}" - ]) - ); } if (waitForPromises.size > 0) { @@ -114,7 +96,7 @@ function generateImportObject(module) { Template.indent([ variables, "return {", - Template.indent([importsCode.join(",")]), + Template.indent([properties.join(",\n")]), "};" ]), "});" @@ -126,7 +108,7 @@ function generateImportObject(module) { `${JSON.stringify(module.id)}: function() {`, Template.indent([ "return {", - Template.indent([importsCode.join(",")]), + Template.indent([properties.join(",\n")]), "};" ]), "}," @@ -221,13 +203,13 @@ class WasmMainTemplatePlugin { Template.indent([ "promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {", Template.indent([ - "return WebAssembly.instantiate(items[0], items[1]);" + "return WebAssembly.instantiate(items[0], {a:items[1]});" ]), "});" ]), "} else if(typeof WebAssembly.instantiateStreaming === 'function') {", Template.indent([ - "promise = WebAssembly.instantiateStreaming(req, importObject);" + "promise = WebAssembly.instantiateStreaming(req, {a:importObject});" ]) ]) : Template.asString([ @@ -241,7 +223,7 @@ class WasmMainTemplatePlugin { ]), "]).then(function(items) {", Template.indent([ - "return WebAssembly.instantiate(items[0], items[1]);" + "return WebAssembly.instantiate(items[0], {a:items[1]});" ]), "});" ]) @@ -251,7 +233,7 @@ class WasmMainTemplatePlugin { "var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });", "promise = bytesPromise.then(function(bytes) {", Template.indent([ - "return WebAssembly.instantiate(bytes, importObject);" + "return WebAssembly.instantiate(bytes, {a:importObject});" ]), "});" ]), diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 5afc60b5a65..889651dcc84 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -6,6 +6,7 @@ const Generator = require("../Generator"); const Template = require("../Template"); +const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); const { RawSource } = require("webpack-sources"); const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); @@ -202,6 +203,27 @@ const rewriteExportNames = ({ ast, module }) => bin => { }); }; +const rewriteImports = state => bin => { + const importMangleMap = state.importMangleMap; + return edit(bin, { + ModuleImport(path) { + const result = importMangleMap.get( + path.node.module + ":" + path.node.name + ); + if (result === undefined) { + path.remove(); + } else { + path.node.module = "a"; + path.node.name = result; + if (path.node.descr.id) + path.node.descr.id = t.numberLiteral(+path.node.descr.id.raw); + if (path.node.descr.name) + path.node.descr.name = t.numberLiteral(+path.node.descr.name.raw); + } + } + }); +}; + /** * Add an init function. * @@ -265,6 +287,31 @@ const addInitFunction = ({ return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]); }; +const getImportMangleMap = module => { + /** @type {Map} */ + const map = new Map(); + let importIndex = 0; + for (const dep of module.dependencies) { + if (dep instanceof WebAssemblyImportDependency) { + if (dep.description.type === "GlobalType" || dep.module === null) { + continue; + } + + const importedModule = dep.module; + const request = dep.request; + const exportName = dep.name; + const usedName = importedModule && importedModule.isUsed(exportName); + if (usedName !== false) { + map.set( + request + ":" + exportName, + Template.numberToIdentifer(importIndex++) + ); + } + } + } + return map; +}; + class WebAssemblyGenerator extends Generator { generate(module) { const bin = module.originalSource().source(); @@ -286,6 +333,8 @@ class WebAssemblyGenerator extends Generator { const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc); const nextTypeIndex = getNextTypeIndex(ast); + const importMangleMap = getImportMangleMap(module); + const transform = compose( rewriteExportNames({ ast, @@ -296,6 +345,10 @@ class WebAssemblyGenerator extends Generator { rewriteImportedGlobals({ ast }), + rewriteImports({ + importMangleMap + }), + addInitFunction({ ast, initFuncId, diff --git a/test/cases/wasm/imports-multiple/index.js b/test/cases/wasm/imports-multiple/index.js new file mode 100644 index 00000000000..d33df356e44 --- /dev/null +++ b/test/cases/wasm/imports-multiple/index.js @@ -0,0 +1,5 @@ +it("should allow to run a WebAssembly module importing from multiple modules", function() { + return import("./module").then(function(mod) { + expect(mod.result).toBe(42); + }); +}); diff --git a/test/cases/wasm/imports-multiple/module.js b/test/cases/wasm/imports-multiple/module.js new file mode 100644 index 00000000000..239d73c6cad --- /dev/null +++ b/test/cases/wasm/imports-multiple/module.js @@ -0,0 +1,7 @@ +import { getResult } from "./wasm.wasm"; + +export var result = getResult(); + +export function getNumber() { + return 20; +} diff --git a/test/cases/wasm/imports-multiple/module2.js b/test/cases/wasm/imports-multiple/module2.js new file mode 100644 index 00000000000..60b7eac0eab --- /dev/null +++ b/test/cases/wasm/imports-multiple/module2.js @@ -0,0 +1,5 @@ +import { getNumber as getN } from "./wasm.wasm"; + +export function getNumber() { + return getN(); +} diff --git a/test/cases/wasm/imports-multiple/test.filter.js b/test/cases/wasm/imports-multiple/test.filter.js new file mode 100644 index 00000000000..23177349638 --- /dev/null +++ b/test/cases/wasm/imports-multiple/test.filter.js @@ -0,0 +1,5 @@ +var supportsWebAssembly = require("../../../helpers/supportsWebAssembly"); + +module.exports = function(config) { + return supportsWebAssembly(); +}; diff --git a/test/cases/wasm/imports-multiple/wasm.wasm b/test/cases/wasm/imports-multiple/wasm.wasm new file mode 100644 index 0000000000000000000000000000000000000000..19fef4041f6ce8b0552051ac2b910ce44bbed265 GIT binary patch literal 202 zcmZQbEY4+QU|?Y6VoG3OtWRL9XRK$^VdBu!&&^LM%}M1 Date: Thu, 10 May 2018 18:07:24 +0200 Subject: [PATCH 031/111] enforce direct import when types are incompatible with JS types --- declarations.d.ts | 15 ++++---- .../WebAssemblyImportDependency.js | 8 +++-- lib/wasm/WebAssemblyGenerator.js | 2 +- lib/wasm/WebAssemblyParser.js | 33 +++++++++++++++--- .../cases/wasm/imports-complex-types/index.js | 6 ++++ .../wasm/imports-complex-types/other.wasm | Bin 0 -> 68 bytes .../wasm/imports-complex-types/test.filter.js | 5 +++ .../wasm/imports-complex-types/wasm.wasm | Bin 0 -> 119 bytes 8 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 test/cases/wasm/imports-complex-types/index.js create mode 100644 test/cases/wasm/imports-complex-types/other.wasm create mode 100644 test/cases/wasm/imports-complex-types/test.filter.js create mode 100644 test/cases/wasm/imports-complex-types/wasm.wasm diff --git a/declarations.d.ts b/declarations.d.ts index d73b4d8305a..85bb4fc5f6f 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -53,8 +53,9 @@ declare module "@webassemblyjs/ast" { module: string; descr: { type: string; - valtype: string; - id: string; + valtype?: string; + id?: Identifier; + signature?: Signature; }; name: string; } @@ -64,7 +65,9 @@ declare module "@webassemblyjs/ast" { export class IndexLiteral extends Node {} export class NumberLiteral extends Node {} export class Global extends Node {} - export class FuncParam extends Node {} + export class FuncParam extends Node { + valtype: string; + } export class Instruction extends Node {} export class CallInstruction extends Instruction {} export class ObjectInstruction extends Instruction {} @@ -72,8 +75,8 @@ declare module "@webassemblyjs/ast" { signature: Signature; } export class Signature { - params: any; - result: any; + params: FuncParam[]; + results: string[]; } export class TypeInstructionFunc extends Node {} export class IndexInFuncSection extends Node {} @@ -90,7 +93,7 @@ declare module "@webassemblyjs/ast" { init: Node[] ): ObjectInstruction; export function func(initFuncId, funcParams, funcResults, funcBody): Func; - export function typeInstructionFunc(params, result): TypeInstructionFunc; + export function typeInstructionFunc(params: FuncParam[], results: string[]): TypeInstructionFunc; export function indexInFuncSection(index: IndexLiteral): IndexInFuncSection; export function moduleExport( identifier: string, diff --git a/lib/dependencies/WebAssemblyImportDependency.js b/lib/dependencies/WebAssemblyImportDependency.js index 2f03978e2a0..ee1e60755ac 100644 --- a/lib/dependencies/WebAssemblyImportDependency.js +++ b/lib/dependencies/WebAssemblyImportDependency.js @@ -11,8 +11,11 @@ const UnsupportedWebAssemblyFeatureError = require("../wasm/UnsupportedWebAssemb class WebAssemblyImportDependency extends ModuleDependency { constructor(request, name, description, onlyDirectImport) { super(request); + /** @type {string} */ this.name = name; + /** @type {TODO} */ this.description = description; + /** @type {false | string} */ this.onlyDirectImport = onlyDirectImport; } @@ -27,10 +30,11 @@ class WebAssemblyImportDependency extends ModuleDependency { this.module && !this.module.type.startsWith("webassembly") ) { - const type = this.description.type; return [ new UnsupportedWebAssemblyFeatureError( - `${type} imports are only available for direct wasm to wasm dependencies` + `Import with ${ + this.onlyDirectImport + } can only be used for direct wasm to wasm dependencies` ) ]; } diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 889651dcc84..59d8d14642d 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -275,7 +275,7 @@ const addInitFunction = ({ // Type section const functype = t.typeInstructionFunc( func.signature.params, - func.signature.result + func.signature.results ); // Func section diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index 559208f4505..b964b2d9878 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -24,6 +24,25 @@ const isMemoryImport = n => n.descr.type === "Memory"; */ const isTableImport = n => n.descr.type === "Table"; +const JS_COMPAT_TYPES = new Set(["i32", "u32", "f32"]); + +/** + * @param {t.ModuleImport} moduleImport the import + * @returns {null | string} the type incompatible with js types + */ +const getJsIncompatibleType = moduleImport => { + if (moduleImport.descr.type !== "FuncImportDescr") return null; + const signature = moduleImport.descr.signature; + for (const param of signature.params) { + if (!JS_COMPAT_TYPES.has(param.valtype)) + return `${param.valtype} as parameter`; + } + for (const type of signature.results) { + if (!JS_COMPAT_TYPES.has(type)) return `${type} as result`; + } + return null; +}; + const decoderOpts = { ignoreCodeSection: true, ignoreDataSection: true @@ -51,14 +70,18 @@ class WebAssemblyParser extends Tapable { }, ModuleImport({ node }) { + /** @type {false | string} */ let onlyDirectImport = false; if (isMemoryImport(node) === true) { - onlyDirectImport = true; - } - - if (isTableImport(node) === true) { - onlyDirectImport = true; + onlyDirectImport = "Memory"; + } else if (isTableImport(node) === true) { + onlyDirectImport = "Table"; + } else { + const incompatibleType = getJsIncompatibleType(node); + if (incompatibleType) { + onlyDirectImport = `Non-JS-compatible Func Sigurature (${incompatibleType})`; + } } const dep = new WebAssemblyImportDependency( diff --git a/test/cases/wasm/imports-complex-types/index.js b/test/cases/wasm/imports-complex-types/index.js new file mode 100644 index 00000000000..c2e0b23fead --- /dev/null +++ b/test/cases/wasm/imports-complex-types/index.js @@ -0,0 +1,6 @@ +it("should allow to run a WebAssembly module with non-js-compatible imports", function() { + return import("./wasm.wasm").then(function(wasm) { + const result = wasm.testI64(); + expect(result).toEqual(42); + }); +}); diff --git a/test/cases/wasm/imports-complex-types/other.wasm b/test/cases/wasm/imports-complex-types/other.wasm new file mode 100644 index 0000000000000000000000000000000000000000..70c5aee0fa3d0b396998cdca051e8969857e5941 GIT binary patch literal 68 zcmZQbEY4+QU|?WmV@zPIW2|FlVq{?FVq{BCE%7unVPN3mWMpShU~tl^;bstL$xF;l RW#nXJfJ!s5GBN-)0{~OQ39$eG literal 0 HcmV?d00001 diff --git a/test/cases/wasm/imports-complex-types/test.filter.js b/test/cases/wasm/imports-complex-types/test.filter.js new file mode 100644 index 00000000000..23177349638 --- /dev/null +++ b/test/cases/wasm/imports-complex-types/test.filter.js @@ -0,0 +1,5 @@ +var supportsWebAssembly = require("../../../helpers/supportsWebAssembly"); + +module.exports = function(config) { + return supportsWebAssembly(); +}; diff --git a/test/cases/wasm/imports-complex-types/wasm.wasm b/test/cases/wasm/imports-complex-types/wasm.wasm new file mode 100644 index 0000000000000000000000000000000000000000..8374df1439fc93409a083afdeaf1be7ee0fbef0b GIT binary patch literal 119 zcmZQbEY4+QU|?Y6VoG4FW2{SHV60~nXXMe-&o9YHEz&Co%Cn`XmUx<(FfcGPF*34q xGqRVY7J~&Cxnvln7@QiQKtKSAUAvr{L6RjeF*lWwlaT>x1QR Date: Thu, 10 May 2018 18:08:29 +0200 Subject: [PATCH 032/111] generate shorter runtime code for the imports map --- lib/wasm/WasmMainTemplatePlugin.js | 45 +++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index 0b0f1cb06ed..157cc5d95c9 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -23,7 +23,7 @@ function getAllWasmModules(chunk) { } function generateImportObject(module) { - const waitForPromises = new Map(); + const waitForInstances = new Map(); const properties = []; let importIndex = 0; for (const dep of module.dependencies) { @@ -50,11 +50,8 @@ function generateImportObject(module) { const propertyName = Template.numberToIdentifer(index); if (direct) { - const instanceVar = `m${waitForPromises.size}`; - waitForPromises.set( - instanceVar, - `installedWasmModules[${JSON.stringify(importedModule.id)}]` - ); + const instanceVar = `m${waitForInstances.size}`; + waitForInstances.set(instanceVar, importedModule.id); properties.push( `${JSON.stringify(propertyName)}: ${instanceVar}` + `[${JSON.stringify(usedName)}]` @@ -83,18 +80,38 @@ function generateImportObject(module) { } } - if (waitForPromises.size > 0) { - const promises = Array.from(waitForPromises.values()).join(", "); + if (waitForInstances.size === 1) { + const moduleId = Array.from(waitForInstances.values())[0]; + const promise = `installedWasmModules[${JSON.stringify(moduleId)}]`; + const variable = Array.from(waitForInstances.keys())[0]; + return Template.asString([ + `${JSON.stringify(module.id)}: function() {`, + Template.indent([ + `return promiseResolve().then(function() { return ${promise}; }).then(function(${variable}) {`, + Template.indent([ + "return {", + Template.indent([properties.join(",\n")]), + "};" + ]), + "});" + ]), + "}," + ]); + } else if (waitForInstances.size > 0) { + const promises = Array.from( + waitForInstances.values(), + id => `installedWasmModules[${JSON.stringify(id)}]` + ).join(", "); const variables = Array.from( - waitForPromises.keys(), - (name, i) => `var ${name} = array[${i}];` - ).join("\n"); + waitForInstances.keys(), + (name, i) => `${name} = array[${i}];` + ).join(", "); return Template.asString([ `${JSON.stringify(module.id)}: function() {`, Template.indent([ - `return Promise.resolve().then(function() { return Promise.all([${promises}]); }).then(function(array) {`, + `return promiseResolve().then(function() { return Promise.all([${promises}]); }).then(function(array) {`, Template.indent([ - variables, + `var ${variables};`, "return {", Template.indent([properties.join(",\n")]), "};" @@ -134,6 +151,8 @@ class WasmMainTemplatePlugin { "// object to store loaded and loading wasm modules", "var installedWasmModules = {};", "", + "function promiseResolve() { return Promise.resolve(); }", + "", "var wasmImportObjects = {", Template.indent(importObjects), "};" From 08e72f546815fb3dccd947eb18662dcde7e5c65e Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 14:24:08 +0200 Subject: [PATCH 033/111] fix compat types list --- lib/wasm/WebAssemblyParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index b964b2d9878..16103074491 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -24,7 +24,7 @@ const isMemoryImport = n => n.descr.type === "Memory"; */ const isTableImport = n => n.descr.type === "Table"; -const JS_COMPAT_TYPES = new Set(["i32", "u32", "f32"]); +const JS_COMPAT_TYPES = new Set(["i32", "f32", "f64"]); /** * @param {t.ModuleImport} moduleImport the import From 42c0214254df5ade315daf4a51580f0424a1792f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 14:24:40 +0200 Subject: [PATCH 034/111] move common code into separate module --- lib/wasm/WasmMainTemplatePlugin.js | 101 ++++++++++++++--------------- lib/wasm/WebAssemblyGenerator.js | 60 ++++++++--------- lib/wasm/WebAssemblyUtils.js | 48 ++++++++++++++ 3 files changed, 128 insertions(+), 81 deletions(-) create mode 100644 lib/wasm/WebAssemblyUtils.js diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index 157cc5d95c9..1daf0b8c145 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -6,6 +6,9 @@ const Template = require("../Template"); const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); +const WebAssemblyUtils = require("./WebAssemblyUtils"); + +/** @typedef {import("../Module")} Module */ // Get all wasm modules function getAllWasmModules(chunk) { @@ -22,61 +25,51 @@ function getAllWasmModules(chunk) { return array; } +/** + * generates the import object function for a module + * @param {Module} module the module + * @returns {string} source code + */ function generateImportObject(module) { const waitForInstances = new Map(); const properties = []; - let importIndex = 0; - for (const dep of module.dependencies) { - if (dep instanceof WebAssemblyImportDependency) { - // Ignore global they will be handled later - if (dep.description.type === "GlobalType") { - continue; - } - - if (dep.module === null) { - // Dependency was not found, an error will be thrown later - continue; - } + const usedWasmDependencies = WebAssemblyUtils.getUsedDependencies(module); + for (const usedDep of usedWasmDependencies) { + const dep = usedDep.dependency; + const importedModule = dep.module; + const exportName = dep.name; + const usedName = importedModule && importedModule.isUsed(exportName); + const description = dep.description; + const direct = dep.onlyDirectImport; - const importedModule = dep.module; - const exportName = dep.name; - const usedName = importedModule && importedModule.isUsed(exportName); - if (usedName !== false) { - const description = dep.description; - const direct = dep.onlyDirectImport; + const propertyName = usedDep.name; - const index = importIndex++; + if (direct) { + const instanceVar = `m${waitForInstances.size}`; + waitForInstances.set(instanceVar, importedModule.id); + properties.push( + `${JSON.stringify(propertyName)}: ${instanceVar}` + + `[${JSON.stringify(usedName)}]` + ); + } else { + const params = description.signature.params.map( + (param, k) => "p" + k + param.valtype + ); - const propertyName = Template.numberToIdentifer(index); + const mod = `installedModules[${JSON.stringify(importedModule.id)}]`; + const func = `${mod}.exports[${JSON.stringify(usedName)}]`; - if (direct) { - const instanceVar = `m${waitForInstances.size}`; - waitForInstances.set(instanceVar, importedModule.id); - properties.push( - `${JSON.stringify(propertyName)}: ${instanceVar}` + - `[${JSON.stringify(usedName)}]` - ); - } else { - const params = description.signature.params.map( - (param, k) => "p" + k + param.valtype - ); - - const mod = `installedModules[${JSON.stringify(importedModule.id)}]`; - const func = `${mod}.exports[${JSON.stringify(usedName)}]`; - - properties.push( - Template.asString([ - `${JSON.stringify(propertyName)}: ` + - (importedModule.type.startsWith("webassembly") - ? `${mod} ? ${func} : ` - : "") + - `function(${params}) {`, - Template.indent([`return ${func}(${params});`]), - "}" - ]) - ); - } - } + properties.push( + Template.asString([ + `${JSON.stringify(propertyName)}: ` + + (importedModule.type.startsWith("webassembly") + ? `${mod} ? ${func} : ` + : "") + + `function(${params}) {`, + Template.indent([`return ${func}(${params});`]), + "}" + ]) + ); } } @@ -222,13 +215,15 @@ class WasmMainTemplatePlugin { Template.indent([ "promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {", Template.indent([ - "return WebAssembly.instantiate(items[0], {a:items[1]});" + "return WebAssembly.instantiate(items[0], " + + `{ ${WebAssemblyUtils.MANGLED_MODULE}: items[1] });` ]), "});" ]), "} else if(typeof WebAssembly.instantiateStreaming === 'function') {", Template.indent([ - "promise = WebAssembly.instantiateStreaming(req, {a:importObject});" + "promise = WebAssembly.instantiateStreaming(req, " + + `{ ${WebAssemblyUtils.MANGLED_MODULE}: importObject });` ]) ]) : Template.asString([ @@ -242,7 +237,8 @@ class WasmMainTemplatePlugin { ]), "]).then(function(items) {", Template.indent([ - "return WebAssembly.instantiate(items[0], {a:items[1]});" + "return WebAssembly.instantiate(items[0], " + + `{ ${WebAssemblyUtils.MANGLED_MODULE}: items[1] });` ]), "});" ]) @@ -252,7 +248,8 @@ class WasmMainTemplatePlugin { "var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });", "promise = bytesPromise.then(function(bytes) {", Template.indent([ - "return WebAssembly.instantiate(bytes, {a:importObject});" + "return WebAssembly.instantiate(bytes, " + + `{ ${WebAssemblyUtils.MANGLED_MODULE}: importObject });` ]), "});" ]), diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 59d8d14642d..7df42298316 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -6,13 +6,16 @@ const Generator = require("../Generator"); const Template = require("../Template"); -const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); +const WebAssemblyUtils = require("./WebAssemblyUtils"); const { RawSource } = require("webpack-sources"); const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit"); const { decode } = require("@webassemblyjs/wasm-parser"); const t = require("@webassemblyjs/ast"); +/** @typedef {import("../Module")} Module */ +/** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */ + function compose(...fns) { return fns.reduce((prevFn, nextFn) => { return value => nextFn(prevFn(value)); @@ -203,18 +206,24 @@ const rewriteExportNames = ({ ast, module }) => bin => { }); }; -const rewriteImports = state => bin => { - const importMangleMap = state.importMangleMap; - return edit(bin, { +/** + * Mangle import names and modules + * @param {Object} state state + * @param {Object} state.ast Module's ast + * @param {Map} state.usedDependencyMap mappings to mangle names + * @returns {ArrayBufferTransform} transform + */ +const rewriteImports = ({ ast, usedDependencyMap }) => bin => { + return editWithAST(ast, bin, { ModuleImport(path) { - const result = importMangleMap.get( + const result = usedDependencyMap.get( path.node.module + ":" + path.node.name ); if (result === undefined) { path.remove(); } else { - path.node.module = "a"; - path.node.name = result; + path.node.module = WebAssemblyUtils.MANGLED_MODULE; + path.node.name = result.name; if (path.node.descr.id) path.node.descr.id = t.numberLiteral(+path.node.descr.id.raw); if (path.node.descr.name) @@ -287,27 +296,19 @@ const addInitFunction = ({ return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]); }; -const getImportMangleMap = module => { - /** @type {Map} */ +/** + * Extract mangle mappings from module + * @param {Module} module current module + * @returns {Map} mappings to mangled names + */ +const getUsedDependencyMap = module => { + /** @type {Map} */ const map = new Map(); - let importIndex = 0; - for (const dep of module.dependencies) { - if (dep instanceof WebAssemblyImportDependency) { - if (dep.description.type === "GlobalType" || dep.module === null) { - continue; - } - - const importedModule = dep.module; - const request = dep.request; - const exportName = dep.name; - const usedName = importedModule && importedModule.isUsed(exportName); - if (usedName !== false) { - map.set( - request + ":" + exportName, - Template.numberToIdentifer(importIndex++) - ); - } - } + for (const usedDep of WebAssemblyUtils.getUsedDependencies(module)) { + const dep = usedDep.dependency; + const request = dep.request; + const exportName = dep.name; + map.set(request + ":" + exportName, usedDep); } return map; }; @@ -333,7 +334,7 @@ class WebAssemblyGenerator extends Generator { const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc); const nextTypeIndex = getNextTypeIndex(ast); - const importMangleMap = getImportMangleMap(module); + const usedDependencyMap = getUsedDependencyMap(module); const transform = compose( rewriteExportNames({ @@ -346,7 +347,8 @@ class WebAssemblyGenerator extends Generator { rewriteImportedGlobals({ ast }), rewriteImports({ - importMangleMap + ast, + usedDependencyMap }), addInitFunction({ diff --git a/lib/wasm/WebAssemblyUtils.js b/lib/wasm/WebAssemblyUtils.js new file mode 100644 index 00000000000..8514a855b86 --- /dev/null +++ b/lib/wasm/WebAssemblyUtils.js @@ -0,0 +1,48 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const Template = require("../Template"); +const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); + +/** @typedef {import("../Module")} Module */ + +/** @typedef {Object} UsedWasmDependency + * @property {WebAssemblyImportDependency} dependency the dependency + * @property {string} name the export name + */ + +const MANGLED_MODULE = "a"; + +/** + * @param {Module} module the module + * @returns {UsedWasmDependency[]} used dependencies and mangled name + */ +const getUsedDependencies = module => { + /** @type {UsedWasmDependency[]} */ + const array = []; + let importIndex = 0; + for (const dep of module.dependencies) { + if (dep instanceof WebAssemblyImportDependency) { + if (dep.description.type === "GlobalType" || dep.module === null) { + continue; + } + + const importedModule = dep.module; + const exportName = dep.name; + const usedName = importedModule && importedModule.isUsed(exportName); + if (usedName !== false) { + array.push({ + dependency: dep, + name: Template.numberToIdentifer(importIndex++) + }); + } + } + } + return array; +}; + +exports.getUsedDependencies = getUsedDependencies; +exports.MANGLED_MODULE = MANGLED_MODULE; From 22ec60434d9e79fb695f70136168a3513c7b65be Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 11 May 2018 16:30:06 +0200 Subject: [PATCH 035/111] lint and type --- lib/wasm/WasmMainTemplatePlugin.js | 1 - lib/wasm/WebAssemblyGenerator.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index 1daf0b8c145..d87039ef86c 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -5,7 +5,6 @@ "use strict"; const Template = require("../Template"); -const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); const WebAssemblyUtils = require("./WebAssemblyUtils"); /** @typedef {import("../Module")} Module */ diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 7df42298316..2b2e8bf31db 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -16,6 +16,11 @@ const t = require("@webassemblyjs/ast"); /** @typedef {import("../Module")} Module */ /** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */ +/** + * @template T + * @param {Function[]} fns transforms + * @returns {Function} composed transform + */ function compose(...fns) { return fns.reduce((prevFn, nextFn) => { return value => nextFn(prevFn(value)); From cd7980e2a8f8ce6e6364d2bc7b5eb196927d52d5 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Sat, 12 May 2018 10:25:17 +0200 Subject: [PATCH 036/111] add comment about the microtask delay --- lib/wasm/WasmMainTemplatePlugin.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/wasm/WasmMainTemplatePlugin.js b/lib/wasm/WasmMainTemplatePlugin.js index d87039ef86c..1cec8f89600 100644 --- a/lib/wasm/WasmMainTemplatePlugin.js +++ b/lib/wasm/WasmMainTemplatePlugin.js @@ -143,6 +143,10 @@ class WasmMainTemplatePlugin { "// object to store loaded and loading wasm modules", "var installedWasmModules = {};", "", + // This function is used to delay reading the installed wasm module promises + // by a microtask. Sorting them doesn't help because there are egdecases where + // sorting is not possible (modules splitted into different chunks). + // So we not even trying and solve this by a microtask delay. "function promiseResolve() { return Promise.resolve(); }", "", "var wasmImportObjects = {", From 51073cd3a1dc2d39f88ea3a1f36e40f454baf97d Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Sat, 12 May 2018 11:38:09 +0200 Subject: [PATCH 037/111] chore: bump webassemblyjs --- package.json | 6 +- yarn.lock | 194 ++++++++++++++++++++++++++------------------------- 2 files changed, 102 insertions(+), 98 deletions(-) diff --git a/package.json b/package.json index 5ae3ceb0da6..0d3f11b3a2d 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "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.4.2", - "@webassemblyjs/wasm-edit": "1.4.2", - "@webassemblyjs/wasm-parser": "1.4.2", + "@webassemblyjs/ast": "1.4.3", + "@webassemblyjs/wasm-edit": "1.4.3", + "@webassemblyjs/wasm-parser": "1.4.3", "acorn": "^5.0.0", "acorn-dynamic-import": "^3.0.0", "ajv": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index 14827f7ef3d..56a5a9bb526 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28,116 +28,120 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd" -"@webassemblyjs/ast@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.2.tgz#ab715aa1fec9dd23c025204dba39690c119418ea" +"@webassemblyjs/ast@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.3.tgz#3b3f6fced944d8660273347533e6d4d315b5934a" dependencies: - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/wast-parser" "1.4.2" + "@webassemblyjs/helper-wasm-bytecode" "1.4.3" + "@webassemblyjs/wast-parser" "1.4.3" debug "^3.1.0" - webassemblyjs "1.4.2" + webassemblyjs "1.4.3" -"@webassemblyjs/floating-point-hex-parser@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.2.tgz#9296fb64caa37bf98c8064aa329680e3e2bfacc7" +"@webassemblyjs/floating-point-hex-parser@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.3.tgz#f5aee4c376a717c74264d7bacada981e7e44faad" -"@webassemblyjs/helper-buffer@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.2.tgz#3cacecd5a6bfcb67932ed8219f81f92d8b2dafbb" +"@webassemblyjs/helper-buffer@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.3.tgz#0434b55958519bf503697d3824857b1dea80b729" + dependencies: + debug "^3.1.0" -"@webassemblyjs/helper-code-frame@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.2.tgz#20526637c3849f12b08f8661248477eef9642329" +"@webassemblyjs/helper-code-frame@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.3.tgz#f1349ca3e01a8e29ee2098c770773ef97af43641" dependencies: - "@webassemblyjs/wast-printer" "1.4.2" + "@webassemblyjs/wast-printer" "1.4.3" -"@webassemblyjs/helper-fsm@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.2.tgz#e41050282994b5be077b95b65b66ecd5a92c5e88" +"@webassemblyjs/helper-fsm@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.3.tgz#65a921db48fb43e868f17b27497870bdcae22b79" -"@webassemblyjs/helper-wasm-bytecode@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.2.tgz#b48c289c7921056aa12d71e78a17070ffe90c49c" +"@webassemblyjs/helper-wasm-bytecode@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.3.tgz#0e5b4b5418e33f8a26e940b7809862828c3721a5" -"@webassemblyjs/helper-wasm-section@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.2.tgz#520e02c0cc3e5e9b5f44f58abc04ba5eda6e5476" +"@webassemblyjs/helper-wasm-section@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.3.tgz#9ceedd53a3f152c3412e072887ade668d0b1acbf" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-buffer" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/wasm-gen" "1.4.2" + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/helper-buffer" "1.4.3" + "@webassemblyjs/helper-wasm-bytecode" "1.4.3" + "@webassemblyjs/wasm-gen" "1.4.3" + debug "^3.1.0" -"@webassemblyjs/leb128@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.2.tgz#d13f368abdcefc54428f55a265a993de610f8893" +"@webassemblyjs/leb128@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.3.tgz#5a5e5949dbb5adfe3ae95664d0439927ac557fb8" dependencies: leb "^0.3.0" -"@webassemblyjs/validation@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.2.tgz#55cf5b219e25900c85773fc35beb9d12ae0ede53" +"@webassemblyjs/validation@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.3.tgz#9e66c9b3079d7bbcf2070c1bf52a54af2a09aac9" + dependencies: + "@webassemblyjs/ast" "1.4.3" + +"@webassemblyjs/wasm-edit@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.3.tgz#87febd565e0ffb5ae25f6495bb3958d17aa0a779" + dependencies: + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/helper-buffer" "1.4.3" + "@webassemblyjs/helper-wasm-bytecode" "1.4.3" + "@webassemblyjs/helper-wasm-section" "1.4.3" + "@webassemblyjs/wasm-gen" "1.4.3" + "@webassemblyjs/wasm-opt" "1.4.3" + "@webassemblyjs/wasm-parser" "1.4.3" + "@webassemblyjs/wast-printer" "1.4.3" + debug "^3.1.0" + +"@webassemblyjs/wasm-gen@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.3.tgz#8553164d0154a6be8f74d653d7ab355f73240aa4" dependencies: - "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/helper-wasm-bytecode" "1.4.3" + "@webassemblyjs/leb128" "1.4.3" -"@webassemblyjs/wasm-edit@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.2.tgz#bde9a581065f63f257ed511d7d9cf04f8cd04524" +"@webassemblyjs/wasm-opt@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.3.tgz#26c7a23bfb136aa405b1d3410e63408ec60894b8" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-buffer" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/helper-wasm-section" "1.4.2" - "@webassemblyjs/wasm-gen" "1.4.2" - "@webassemblyjs/wasm-opt" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - "@webassemblyjs/wast-printer" "1.4.2" + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/helper-buffer" "1.4.3" + "@webassemblyjs/wasm-gen" "1.4.3" + "@webassemblyjs/wasm-parser" "1.4.3" debug "^3.1.0" -"@webassemblyjs/wasm-gen@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.2.tgz#0899297f9426073736df799287845a73c597cf90" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/leb128" "1.4.2" - -"@webassemblyjs/wasm-opt@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.2.tgz#c44ad48e109aec197e3bf69875c54537d76ba2e9" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-buffer" "1.4.2" - "@webassemblyjs/wasm-gen" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - -"@webassemblyjs/wasm-parser@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.2.tgz#3bf7e10cfe336db0ecdea0a5d7ed8a63b7a7754a" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/leb128" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - webassemblyjs "1.4.2" - -"@webassemblyjs/wast-parser@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.2.tgz#6499c38cf8895a81394f7e40d4681a85aaa84498" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/floating-point-hex-parser" "1.4.2" - "@webassemblyjs/helper-code-frame" "1.4.2" - "@webassemblyjs/helper-fsm" "1.4.2" +"@webassemblyjs/wasm-parser@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.3.tgz#7ddd3e408f8542647ed612019cfb780830993698" + dependencies: + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/helper-wasm-bytecode" "1.4.3" + "@webassemblyjs/leb128" "1.4.3" + "@webassemblyjs/wasm-parser" "1.4.3" + webassemblyjs "1.4.3" + +"@webassemblyjs/wast-parser@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.3.tgz#3250402e2c5ed53dbe2233c9de1fe1f9f0d51745" + dependencies: + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/floating-point-hex-parser" "1.4.3" + "@webassemblyjs/helper-code-frame" "1.4.3" + "@webassemblyjs/helper-fsm" "1.4.3" long "^3.2.0" - webassemblyjs "1.4.2" + webassemblyjs "1.4.3" -"@webassemblyjs/wast-printer@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.2.tgz#ee70a828f0d9730b55b9a5c3ed694094ba68ba57" +"@webassemblyjs/wast-printer@1.4.3": + version "1.4.3" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.3.tgz#3d59aa8d0252d6814a3ef4e6d2a34c9ded3904e0" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/wast-parser" "1.4.2" + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/wast-parser" "1.4.3" long "^3.2.0" abab@^1.0.4: @@ -6270,14 +6274,14 @@ watchpack@^1.5.0: graceful-fs "^4.1.2" neo-async "^2.5.0" -webassemblyjs@1.4.2: - version "1.4.2" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.2.tgz#3b07b506917c97153d83441d8a88ffa2d25cc07d" +webassemblyjs@1.4.3: + version "1.4.3" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.3.tgz#0591893efb8fbde74498251cbe4b2d83df9239cb" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/validation" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - "@webassemblyjs/wast-parser" "1.4.2" + "@webassemblyjs/ast" "1.4.3" + "@webassemblyjs/validation" "1.4.3" + "@webassemblyjs/wasm-parser" "1.4.3" + "@webassemblyjs/wast-parser" "1.4.3" long "^3.2.0" webidl-conversions@^4.0.1, webidl-conversions@^4.0.2: From 9a72294918064d6b976538adf808808de948585f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Sat, 12 May 2018 22:56:19 +0200 Subject: [PATCH 038/111] 4.8.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d3f11b3a2d..f67472e72d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack", - "version": "4.8.2", + "version": "4.8.3", "author": "Tobias Koppers @sokra", "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", From 9a1eca5e202d816ba031f37c9bfb4d34a29308a8 Mon Sep 17 00:00:00 2001 From: Mihail Bodrov Date: Sun, 13 May 2018 01:15:39 +0300 Subject: [PATCH 039/111] Optimize RemoveEmptyChunksPlugin --- lib/optimize/RemoveEmptyChunksPlugin.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/optimize/RemoveEmptyChunksPlugin.js b/lib/optimize/RemoveEmptyChunksPlugin.js index 458e5c318fb..25895b65019 100644 --- a/lib/optimize/RemoveEmptyChunksPlugin.js +++ b/lib/optimize/RemoveEmptyChunksPlugin.js @@ -8,15 +8,16 @@ class RemoveEmptyChunksPlugin { apply(compiler) { compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => { const handler = chunks => { - chunks - .filter( - chunk => - chunk.isEmpty() && !chunk.hasRuntime() && !chunk.hasEntryModule() - ) - .forEach(chunk => { - chunk.remove("empty"); - chunks.splice(chunks.indexOf(chunk), 1); - }); + for (let i = chunks.length - 1; i >= 0; i--) { + const chunk = chunks[i]; + if ( + chunk.isEmpty() && + !chunk.hasRuntime() && + !chunk.hasEntryModule() + ) { + chunks.splice(i, 1); + } + } }; compilation.hooks.optimizeChunksBasic.tap( "RemoveEmptyChunksPlugin", From 8d1d569541bc680a2f1857d9a927ba588163c0a7 Mon Sep 17 00:00:00 2001 From: Mihail Bodrov Date: Sun, 13 May 2018 02:04:06 +0300 Subject: [PATCH 040/111] Fix remove empty --- lib/optimize/RemoveEmptyChunksPlugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/optimize/RemoveEmptyChunksPlugin.js b/lib/optimize/RemoveEmptyChunksPlugin.js index 25895b65019..42ba24a1574 100644 --- a/lib/optimize/RemoveEmptyChunksPlugin.js +++ b/lib/optimize/RemoveEmptyChunksPlugin.js @@ -15,6 +15,7 @@ class RemoveEmptyChunksPlugin { !chunk.hasRuntime() && !chunk.hasEntryModule() ) { + chunk.remove("empty"); chunks.splice(i, 1); } } From 736ac2645d83a31c5400c3640089af5a142cdcb2 Mon Sep 17 00:00:00 2001 From: BeniCheni Date: Sat, 12 May 2018 21:09:04 -0700 Subject: [PATCH 041/111] Update support readme for webpack1 wiki --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9a8c423f813..baf8be38536 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,8 @@ We consider webpack to be a low-level tool used not only individually but also l If you're just getting started, take a look at [our new docs and concepts page](https://webpack.js.org/concepts/). This has a high level overview that is great for beginners!! +Looking for webpack1 docs? Please check out the old [wiki](https://github.com/webpack/docs/wiki/contents), but note that this deprecated version is no longer supported. + If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack) where there are always individuals looking to help out! If you are still having difficulty, we would love for you to post From b77283e8851869424189bda4371509b7149252e6 Mon Sep 17 00:00:00 2001 From: BeniCheni Date: Sat, 12 May 2018 21:11:11 -0700 Subject: [PATCH 042/111] Update keyword "webpack1" to "webpack 1" support readme for webpack1 wiki --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index baf8be38536..ef71f20eb7a 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,7 @@ We consider webpack to be a low-level tool used not only individually but also l If you're just getting started, take a look at [our new docs and concepts page](https://webpack.js.org/concepts/). This has a high level overview that is great for beginners!! -Looking for webpack1 docs? Please check out the old [wiki](https://github.com/webpack/docs/wiki/contents), but note that this deprecated version is no longer supported. +Looking for webpack 1 docs? Please check out the old [wiki](https://github.com/webpack/docs/wiki/contents), but note that this deprecated version is no longer supported. If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack) where there are always individuals looking to help out! From 307591fa49006b6582dbebadca362331a68d1cec Mon Sep 17 00:00:00 2001 From: byzyk Date: Sun, 13 May 2018 17:09:53 +0400 Subject: [PATCH 043/111] remove `pretty` script from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 7101f65858e..0feb3471cbc 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,6 @@ "code-lint": "eslint setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", "type-lint": "tsc --pretty", "fix": "yarn code-lint --fix", - "pretty": "prettier --write \"**/*.{js,ts}\"", "schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", "cover": "yarn cover:init && yarn cover:all && yarn cover:report", From 5230740f6ffe9ed03dd59e0826cecb170bb9089b Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 9 May 2018 15:00:15 +0300 Subject: [PATCH 044/111] feat(cli): support `webpack-command` --- bin/webpack.js | 115 ++++++++++++++++++++++++++++++++-------------- declarations.d.ts | 1 + 2 files changed, 81 insertions(+), 35 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 9d83f9bef43..4c6f3a5bdb6 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -21,61 +21,106 @@ function runCommand(command, options) { }); } -let webpackCliInstalled = false; -try { - require.resolve("webpack-cli"); - webpackCliInstalled = true; -} catch (err) { - webpackCliInstalled = false; +function isInstalled(packageName) { + try { + require.resolve(packageName); + + return true; + } catch (err) { + return false; + } } -if (!webpackCliInstalled) { +const CLI = [ + { + name: "webpack-cli", + installed: isInstalled("webpack-cli"), + URL: "https://github.com/webpack/webpack-cli", + description: "The original webpack full-featured CLI from webpack@3." + }, + { + name: "webpack-command", + installed: isInstalled("webpack-command"), + URL: "https://github.com/webpack-contrib/webpack-command", + description: "A lightweight, opinionated webpack CLI." + } +]; + +if (CLI.every(item => !item.installed)) { const path = require("path"); const fs = require("fs"); const readLine = require("readline"); + + let notify = + "The CLI for webpack must be installed as a separate package, for which there are choices:\n"; + + CLI.forEach(item => { + notify += ` ${item.name} (${item.URL}): ${item.description}\n`; + }); + + console.error(notify); + const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); const packageManager = isYarn ? "yarn" : "npm"; - const options = ["install", "-D", "webpack-cli"]; + const installOptions = ["install", "-D"]; if (isYarn) { - options[0] = "add"; + installOptions[0] = "add"; } - const commandToBeRun = `${packageManager} ${options.join(" ")}`; + let question = `Would you like to install (${CLI.map(item => item.name).join( + "/" + )}):\n`; - const question = `Would you like to install webpack-cli? (That will run ${commandToBeRun}) (yes/NO)`; - - console.error("The CLI moved into a separate package: webpack-cli"); const questionInterface = readLine.createInterface({ input: process.stdin, output: process.stdout }); questionInterface.question(question, answer => { questionInterface.close(); - switch (answer.toLowerCase()) { - case "y": - case "yes": - case "1": { - runCommand(packageManager, options) - .then(result => { - return require("webpack-cli"); //eslint-disable-line - }) - .catch(error => { - console.error(error); - process.exitCode = 1; - }); - break; - } - default: { - console.error( - "It needs to be installed alongside webpack to use the CLI" - ); - process.exitCode = 1; - break; - } + + const normalizedAnswer = answer.toLowerCase(); + const selectedPackage = CLI.find(item => item.name === normalizedAnswer); + + if (!selectedPackage) { + console.error( + "It needs to be installed alongside webpack to use the CLI" + ); + process.exitCode = 1; + + return; } + + installOptions.push(normalizedAnswer); + + console.log( + `Installing '${normalizedAnswer}' (running '${packageManager} ${installOptions.join( + " " + )}')...` + ); + + runCommand(packageManager, installOptions) + .then(result => { + return require(normalizedAnswer); //eslint-disable-line + }) + .catch(error => { + console.error(error); + process.exitCode = 1; + }); }); } else { - require("webpack-cli"); // eslint-disable-line + const installedPackage = CLI.map( + item => (item.installed ? item.name : "") + ).filter(v => v); + + if (installedPackage.length > 1) { + console.warn( + `You have installed ${installedPackage.join( + " and " + )} together. To work with the webpack you need only one CLI package, please remove one of them` + ); + } + + require(installedPackage[0]); // eslint-disable-line } diff --git a/declarations.d.ts b/declarations.d.ts index fe84d642bd8..5d161e7c5d2 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -1,5 +1,6 @@ declare module "*.json"; declare module "webpack-cli"; +declare module "webpack-command"; // Deprecated NodeJS API usages in Webpack declare namespace NodeJS { From 17fd4d8b48902eb1b2bf0015f1e235abd38fef09 Mon Sep 17 00:00:00 2001 From: Oded Niv Date: Tue, 15 May 2018 09:16:39 +0300 Subject: [PATCH 045/111] Align 'Cannot find module' message with native NodeJS --- .../code-splitted-require.context-amd/README.md | 2 +- examples/code-splitted-require.context/README.md | 2 +- examples/code-splitting-harmony/README.md | 2 +- .../README.md | 2 +- .../README.md | 2 +- .../code-splitting-specify-chunk-name/README.md | 2 +- examples/hybrid-routing/README.md | 2 +- examples/mixed/README.md | 2 +- examples/require.context/README.md | 2 +- examples/web-worker/README.md | 2 +- lib/ContextModule.js | 16 ++++++++-------- lib/RuntimeTemplate.js | 2 +- lib/dependencies/WebpackMissingModule.js | 4 ++-- test/ExternalModule.unittest.js | 6 +++--- test/WebpackMissingModule.unittest.js | 6 +++--- test/cases/parsing/issue-2641/index.js | 4 ++-- test/cases/parsing/issue-758/index.js | 4 ++-- .../context-exclusion/simple/index.js | 6 +++--- .../errors/multi-entry-missing-module/index.js | 4 ++-- 19 files changed, 36 insertions(+), 36 deletions(-) diff --git a/examples/code-splitted-require.context-amd/README.md b/examples/code-splitted-require.context-amd/README.md index 580e02fa0b3..07a7855e2d8 100644 --- a/examples/code-splitted-require.context-amd/README.md +++ b/examples/code-splitted-require.context-amd/README.md @@ -259,7 +259,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } diff --git a/examples/code-splitted-require.context/README.md b/examples/code-splitted-require.context/README.md index ada390aca2e..c1251d65308 100644 --- a/examples/code-splitted-require.context/README.md +++ b/examples/code-splitted-require.context/README.md @@ -259,7 +259,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } diff --git a/examples/code-splitting-harmony/README.md b/examples/code-splitting-harmony/README.md index 4db7024d8ce..c3e9e9d4c8d 100644 --- a/examples/code-splitting-harmony/README.md +++ b/examples/code-splitting-harmony/README.md @@ -248,7 +248,7 @@ function webpackAsyncContext(req) { var ids = map[req]; if(!ids) { return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); diff --git a/examples/code-splitting-native-import-context-filter/README.md b/examples/code-splitting-native-import-context-filter/README.md index 50cced4f21a..86f2a9e9164 100644 --- a/examples/code-splitting-native-import-context-filter/README.md +++ b/examples/code-splitting-native-import-context-filter/README.md @@ -275,7 +275,7 @@ function webpackAsyncContext(req) { var ids = map[req]; if(!ids) { return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); diff --git a/examples/code-splitting-native-import-context/README.md b/examples/code-splitting-native-import-context/README.md index f7405567ed3..f751eb9b227 100644 --- a/examples/code-splitting-native-import-context/README.md +++ b/examples/code-splitting-native-import-context/README.md @@ -264,7 +264,7 @@ function webpackAsyncContext(req) { var ids = map[req]; if(!ids) { return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); diff --git a/examples/code-splitting-specify-chunk-name/README.md b/examples/code-splitting-specify-chunk-name/README.md index fc9d18ecb84..16638fad95a 100644 --- a/examples/code-splitting-specify-chunk-name/README.md +++ b/examples/code-splitting-specify-chunk-name/README.md @@ -256,7 +256,7 @@ function webpackAsyncContext(req) { var ids = map[req]; if(!ids) { return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); diff --git a/examples/hybrid-routing/README.md b/examples/hybrid-routing/README.md index 56e6b93201e..c529e057f59 100644 --- a/examples/hybrid-routing/README.md +++ b/examples/hybrid-routing/README.md @@ -153,7 +153,7 @@ function webpackAsyncContext(req) { var ids = map[req]; if(!ids) { return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); diff --git a/examples/mixed/README.md b/examples/mixed/README.md index 38a442ed640..56defcdc409 100644 --- a/examples/mixed/README.md +++ b/examples/mixed/README.md @@ -357,7 +357,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } diff --git a/examples/require.context/README.md b/examples/require.context/README.md index 912cdcf684b..32b55404af1 100644 --- a/examples/require.context/README.md +++ b/examples/require.context/README.md @@ -143,7 +143,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } diff --git a/examples/web-worker/README.md b/examples/web-worker/README.md index d267a214ab3..4ee25044ec5 100644 --- a/examples/web-worker/README.md +++ b/examples/web-worker/README.md @@ -284,7 +284,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } diff --git a/lib/ContextModule.js b/lib/ContextModule.js index fd186bc90f6..85ff4794354 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -330,7 +330,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } @@ -365,7 +365,7 @@ function webpackContext(req) { function webpackContextResolve(req) { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } @@ -404,7 +404,7 @@ function webpackAsyncContextResolve(req) { return Promise.resolve().then(function() { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } @@ -441,7 +441,7 @@ function webpackAsyncContextResolve(req) { return Promise.resolve().then(function() { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } @@ -481,7 +481,7 @@ function webpackAsyncContextResolve(req) { return ${promise}.then(function() { var id = map[req]; if(!(id + 1)) { // check for number or string - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } @@ -540,7 +540,7 @@ function webpackAsyncContext(req) { var ids = map[req]; if(!ids) { return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); @@ -559,7 +559,7 @@ module.exports = webpackAsyncContext;`; getSourceForEmptyContext(id) { return `function webpackEmptyContext(req) { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } @@ -574,7 +574,7 @@ webpackEmptyContext.id = ${JSON.stringify(id)};`; // Here Promise.resolve().then() is used instead of new Promise() to prevent // uncaught exception popping up in devtools return Promise.resolve().then(function() { - var e = new Error('Cannot find module "' + req + '".'); + var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; }); diff --git a/lib/RuntimeTemplate.js b/lib/RuntimeTemplate.js index e3146ad5941..3cb912a20ee 100644 --- a/lib/RuntimeTemplate.js +++ b/lib/RuntimeTemplate.js @@ -44,7 +44,7 @@ module.exports = class RuntimeTemplate { } throwMissingModuleErrorFunction({ request }) { - const err = `Cannot find module "${request}"`; + const err = `Cannot find module '${request}'`; return `function webpackMissingModule() { var e = new Error(${JSON.stringify( err )}); e.code = 'MODULE_NOT_FOUND'; throw e; }`; diff --git a/lib/dependencies/WebpackMissingModule.js b/lib/dependencies/WebpackMissingModule.js index 826bba5a713..a55c9ec087f 100644 --- a/lib/dependencies/WebpackMissingModule.js +++ b/lib/dependencies/WebpackMissingModule.js @@ -10,11 +10,11 @@ exports.module = request => `!(function webpackMissingModule() { ${exports.moduleCode(request)} }())`; exports.promise = request => { - const errorCode = toErrorCode(`Cannot find module "${request}"`); + const errorCode = toErrorCode(`Cannot find module '${request}'`); return `Promise.reject(function webpackMissingModule() { ${errorCode} return e; }())`; }; exports.moduleCode = request => { - const errorCode = toErrorCode(`Cannot find module "${request}"`); + const errorCode = toErrorCode(`Cannot find module '${request}'`); return `${errorCode} throw e;`; }; diff --git a/test/ExternalModule.unittest.js b/test/ExternalModule.unittest.js index 14725a0b5f8..075c4600919 100644 --- a/test/ExternalModule.unittest.js +++ b/test/ExternalModule.unittest.js @@ -171,7 +171,7 @@ describe("ExternalModule", () => { // set up const variableToCheck = "foo"; const request = "bar"; - const expected = `if(typeof foo === 'undefined') {var e = new Error("Cannot find module \\"bar\\""); e.code = 'MODULE_NOT_FOUND'; throw e;} + const expected = `if(typeof foo === 'undefined') {var e = new Error("Cannot find module 'bar'"); e.code = 'MODULE_NOT_FOUND'; throw e;} `; // invoke @@ -207,7 +207,7 @@ describe("ExternalModule", () => { // set up const id = "someId"; const optional = true; - const expected = `if(typeof __WEBPACK_EXTERNAL_MODULE_someId__ === 'undefined') {var e = new Error("Cannot find module \\"some/request\\""); e.code = 'MODULE_NOT_FOUND'; throw e;} + const expected = `if(typeof __WEBPACK_EXTERNAL_MODULE_someId__ === 'undefined') {var e = new Error("Cannot find module 'some/request'"); e.code = 'MODULE_NOT_FOUND'; throw e;} module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`; // invoke @@ -239,7 +239,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`; it("checks for the existence of the request setting it", () => { // set up const optional = true; - const expected = `if(typeof some/request === 'undefined') {var e = new Error("Cannot find module \\"some/request\\""); e.code = 'MODULE_NOT_FOUND'; throw e;} + const expected = `if(typeof some/request === 'undefined') {var e = new Error("Cannot find module 'some/request'"); e.code = 'MODULE_NOT_FOUND'; throw e;} module.exports = some/request;`; // invoke diff --git a/test/WebpackMissingModule.unittest.js b/test/WebpackMissingModule.unittest.js index b8e3c00942b..73ea0a790c8 100644 --- a/test/WebpackMissingModule.unittest.js +++ b/test/WebpackMissingModule.unittest.js @@ -8,7 +8,7 @@ describe("WebpackMissingModule", () => { it("returns an error message based on given error message", () => { const errorMessage = WebpackMissingModule.moduleCode("mock message"); expect(errorMessage).toBe( - 'var e = new Error("Cannot find module \\"mock message\\""); e.code = \'MODULE_NOT_FOUND\'; throw e;' + "var e = new Error(\"Cannot find module 'mock message'\"); e.code = 'MODULE_NOT_FOUND'; throw e;" ); }); }); @@ -17,7 +17,7 @@ describe("WebpackMissingModule", () => { it("returns an error message based on given error message", () => { const errorMessage = WebpackMissingModule.promise("mock message"); expect(errorMessage).toBe( - 'Promise.reject(function webpackMissingModule() { var e = new Error("Cannot find module \\"mock message\\""); e.code = \'MODULE_NOT_FOUND\'; return e; }())' + "Promise.reject(function webpackMissingModule() { var e = new Error(\"Cannot find module 'mock message'\"); e.code = 'MODULE_NOT_FOUND'; return e; }())" ); }); }); @@ -26,7 +26,7 @@ describe("WebpackMissingModule", () => { it("returns an error message based on given error message", () => { const errorMessage = WebpackMissingModule.module("mock message"); expect(errorMessage).toBe( - '!(function webpackMissingModule() { var e = new Error("Cannot find module \\"mock message\\""); e.code = \'MODULE_NOT_FOUND\'; throw e; }())' + "!(function webpackMissingModule() { var e = new Error(\"Cannot find module 'mock message'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())" ); }); }); diff --git a/test/cases/parsing/issue-2641/index.js b/test/cases/parsing/issue-2641/index.js index f47681f8976..4626a3d9cda 100644 --- a/test/cases/parsing/issue-2641/index.js +++ b/test/cases/parsing/issue-2641/index.js @@ -11,7 +11,7 @@ it("should call error callback on missing module", function(done) { require(['./file', './missingModule'], function(file){}, function(error) { try { expect(error).toBeInstanceOf(Error); - expect(error.message).toBe('Cannot find module "./missingModule"'); + expect(error.message).toBe("Cannot find module './missingModule'"); done(); } catch(e) { done(e); @@ -24,7 +24,7 @@ it("should call error callback on missing module in context", function(done) { require(['./' + module], function(file){}, function(error) { try { expect(error).toBeInstanceOf(Error); - expect(error.message).toBe("Cannot find module \"./missingModule\"."); + expect(error.message).toBe("Cannot find module './missingModule'"); done(); } catch(e) { done(e); } }); diff --git a/test/cases/parsing/issue-758/index.js b/test/cases/parsing/issue-758/index.js index a01b9491ec0..01ac1344e2d 100644 --- a/test/cases/parsing/issue-758/index.js +++ b/test/cases/parsing/issue-758/index.js @@ -13,7 +13,7 @@ it("should call error callback on missing module", function(done) { require('./missingModule'); }, function(error) { expect(error).toBeInstanceOf(Error); - expect(error.message).toBe('Cannot find module "./missingModule"'); + expect(error.message).toBe("Cannot find module './missingModule'"); done(); }); }); @@ -24,7 +24,7 @@ it("should call error callback on missing module in context", function(done) { require('./' + module); }, function(error) { expect(error).toBeInstanceOf(Error); - expect(error.message).toBe("Cannot find module \"./missingModule\"."); + expect(error.message).toBe("Cannot find module './missingModule'"); done(); }); })('missingModule'); diff --git a/test/configCases/context-exclusion/simple/index.js b/test/configCases/context-exclusion/simple/index.js index a6b860bd585..47eb9afe063 100644 --- a/test/configCases/context-exclusion/simple/index.js +++ b/test/configCases/context-exclusion/simple/index.js @@ -9,9 +9,9 @@ it("should not exclude paths not matching the exclusion pattern", function() { }); it("should exclude paths/files matching the exclusion pattern", function() { - expect(() => requireInContext("dont")).toThrowError(/Cannot find module ".\/dont"/); + expect(() => requireInContext("dont")).toThrowError(/Cannot find module '.\/dont'/); - expect(() => requireInContext("dont-check-here/file")).toThrowError(/Cannot find module ".\/dont-check-here\/file"/); + expect(() => requireInContext("dont-check-here/file")).toThrowError(/Cannot find module '.\/dont-check-here\/file'/); - expect(() => requireInContext("check-here/dont-check-here/file")).toThrowError(/Cannot find module ".\/check-here\/dont-check-here\/file"/); + expect(() => requireInContext("check-here/dont-check-here/file")).toThrowError(/Cannot find module '.\/check-here\/dont-check-here\/file'/); }); diff --git a/test/configCases/errors/multi-entry-missing-module/index.js b/test/configCases/errors/multi-entry-missing-module/index.js index 0ebf4cc2c7f..e4dec7f2285 100644 --- a/test/configCases/errors/multi-entry-missing-module/index.js +++ b/test/configCases/errors/multi-entry-missing-module/index.js @@ -2,9 +2,9 @@ it("Should use WebpackMissingModule when module is missing with multiple entry s var fs = require("fs"); var path = require("path"); var source = fs.readFileSync(path.join(__dirname, "b.js"), "utf-8"); - expect(source).toMatch("!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"./intentionally-missing-module.js\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());"); + expect(source).toMatch("!(function webpackMissingModule() { var e = new Error(\"Cannot find module './intentionally-missing-module.js'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());"); expect(function() { require("./intentionally-missing-module"); - }).toThrowError("Cannot find module \"./intentionally-missing-module\""); + }).toThrowError("Cannot find module './intentionally-missing-module'"); }); From 9791c0b5c85b0b08160e6163cf87daa4470efc4a Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 15 May 2018 08:32:08 +0200 Subject: [PATCH 046/111] fix spacing --- lib/web/JsonpMainTemplatePlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/JsonpMainTemplatePlugin.js b/lib/web/JsonpMainTemplatePlugin.js index 906dca4c0ff..ad069d5313b 100644 --- a/lib/web/JsonpMainTemplatePlugin.js +++ b/lib/web/JsonpMainTemplatePlugin.js @@ -196,7 +196,7 @@ class JsonpMainTemplatePlugin { "}" ]), "};", - "script.onerror = script.onload = onScriptComplete;" + "script.onerror = script.onload = onScriptComplete;" ]); } ); From 7cc9605ea3ffb4310ae58524550b0f387ab0fc98 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 15 May 2018 10:11:57 +0200 Subject: [PATCH 047/111] Improve pull request template and add automatic issue to docs --- .github/PULL_REQUEST_TEMPLATE.md | 19 ++++++------- open-bot.yaml | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7af602ab91a..998368de95e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,9 @@ + + + + + **What kind of change does this PR introduce?** @@ -8,17 +13,11 @@ -**If relevant, link to documentation update:** - - - -**Summary** - - - - **Does this PR introduce a breaking change?** -**Other information** +**What need to be documented once your changes are merged?** + + + diff --git a/open-bot.yaml b/open-bot.yaml index 46f693cba16..5721f82dbd6 100644 --- a/open-bot.yaml +++ b/open-bot.yaml @@ -517,6 +517,53 @@ rules: If you think this is still a valid issue, please file a new issue with additional information. +# Add action actions box to each pull request +- filters: + pull_request: true + open: true + not: + comment: + matching: admin-actions + author: webpack-bot + actions: + comment: + identifier: admin-actions + message: |- + *For maintainers only:* + + * [x] This need to be documented (issue in webpack/webpack.js.org will be filed when merged) + + +# When a pull request need to be documented, create an issue in webpack/webpack.js.org when merged +- filters: + pull_request: + merged: true + comment: + author: webpack-bot + matching: "\\* \\[x\\] " + not: + comment_1: + author: webpack-bot + matching: admin-action-document-executed + actions: + new_issue: + target: webpack/webpack.js.org + title: "Document webpack change: {{{pull_request.title}}}" + body: |- + + + *A pull request by @{{pull_request.user.login}} was merged and maintainers requested a documentation change.* + + See pull request: {{{pull_request.html_url}}} + + --- + + {{{pull_request.body}}} + comment: + identifier: admin-action-document-executed + message: |- + I've created an issue to document this in webpack/webpack.js.org. + From a8a42b442d22cc0876a287e212c8f30b2172f07a Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 15 May 2018 11:01:13 +0200 Subject: [PATCH 048/111] typos --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 998368de95e..8967c8f0169 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -17,7 +17,7 @@ -**What need to be documented once your changes are merged?** +**What needs to be documented once your changes are merged?** - + From 9c0036ba50c7fdf35136aef45440ff48cf575513 Mon Sep 17 00:00:00 2001 From: Jaehwan Moon Date: Tue, 15 May 2018 07:19:53 -0400 Subject: [PATCH 049/111] Add a test --- test/ProgressPlugin.test.js | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/ProgressPlugin.test.js diff --git a/test/ProgressPlugin.test.js b/test/ProgressPlugin.test.js new file mode 100644 index 00000000000..bfa2691591a --- /dev/null +++ b/test/ProgressPlugin.test.js @@ -0,0 +1,40 @@ +"use strict"; + +const path = require("path"); +const MemoryFs = require("memory-fs"); +const webpack = require("../"); + +const createMultiCompiler = () => { + const compiler = webpack([ + { + context: path.join(__dirname, "fixtures"), + entry: "./a.js" + }, + { + context: path.join(__dirname, "fixtures"), + entry: "./b.js" + } + ]); + compiler.outputFileSystem = new MemoryFs(); + return compiler; +}; + +describe("ProgressPlugin", function() { + it("should not contain NaN as a percentage when it is applied to MultiCompiler", function(done) { + const compiler = createMultiCompiler(); + + let percentage = 0; + new webpack.ProgressPlugin((p, msg, ...args) => { + percentage += p; + }).apply(compiler); + + compiler.run(err => { + if (err) { + throw err; + } else { + expect(percentage).not.toBe(NaN); + done(); + } + }); + }); +}); From d6efad856b325d6574e84833c03268c320f94b6d Mon Sep 17 00:00:00 2001 From: Philipp Klein Date: Tue, 15 May 2018 16:12:54 +0200 Subject: [PATCH 050/111] Allow serve property in webpack configuration The server property is used to configure webpack-serve (https://github.com/webpack-contrib/webpack-serve). Also adapt tests. Fixes #7306 --- schemas/WebpackOptions.json | 4 ++++ test/Validation.test.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index 6576e1494e6..f8d94d68320 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -1679,6 +1679,10 @@ } ] }, + "serve": { + "description": "Options for webpack-serve", + "type": "object" + }, "stats": { "description": "Used by the webpack CLI program to pass stats options.", "anyOf": [ diff --git a/test/Validation.test.js b/test/Validation.test.js index f43b2c031be..6f29d6a9ee5 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -199,7 +199,7 @@ describe("Validation", () => { " - configuration has an unknown property 'postcss'. These properties are valid:", " object { mode?, amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, " + "loader?, module?, name?, node?, output?, optimization?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, " + - "recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }", + "recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }", " For typos: please correct them.", " For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.", " Loaders should be updated to allow passing options via loader options in module.rules.", From 92bcb81ede6adc184699302e17c5f6d10bcf623f Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 15 May 2018 16:56:15 +0200 Subject: [PATCH 051/111] wording, optimizations, types, cleanup --- bin/webpack.js | 130 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 85 insertions(+), 45 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 4c6f3a5bdb6..389bc9527e7 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -1,8 +1,16 @@ #!/usr/bin/env node -function runCommand(command, options) { + +process.exitCode = 0; + +/** + * @param {string} command process to run + * @param {string[]} args commandline arguments + * @returns {Promise} promise + */ +const runCommand = (command, args) => { const cp = require("child_process"); return new Promise((resolve, reject) => { - const executedCommand = cp.spawn(command, options, { + const executedCommand = cp.spawn(command, args, { stdio: "inherit", shell: true }); @@ -13,15 +21,19 @@ function runCommand(command, options) { executedCommand.on("exit", code => { if (code === 0) { - resolve(true); + resolve(); } else { reject(); } }); }); -} +}; -function isInstalled(packageName) { +/** + * @param {string} packageName name of the package + * @returns {boolean} is the package installed? + */ +const isInstalled = packageName => { try { require.resolve(packageName); @@ -29,98 +41,126 @@ function isInstalled(packageName) { } catch (err) { return false; } -} - -const CLI = [ +}; + +/** + * @typedef {Object} CliOption + * @property {string} name display name + * @property {string} package npm package name + * @property {string} alias shortcut for choice + * @property {boolean} installed currently installed? + * @property {string} url homepage + * @property {string} description description + */ + +/** @type {CliOption[]} */ +const CLIs = [ { name: "webpack-cli", + package: "webpack-cli", + alias: "cli", installed: isInstalled("webpack-cli"), - URL: "https://github.com/webpack/webpack-cli", - description: "The original webpack full-featured CLI from webpack@3." + url: "https://github.com/webpack/webpack-cli", + description: "The original webpack full-featured CLI." }, { name: "webpack-command", + package: "webpack-command", + alias: "command", installed: isInstalled("webpack-command"), - URL: "https://github.com/webpack-contrib/webpack-command", + url: "https://github.com/webpack-contrib/webpack-command", description: "A lightweight, opinionated webpack CLI." } ]; -if (CLI.every(item => !item.installed)) { +const installedClis = CLIs.filter(cli => cli.installed); + +if (installedClis.length === 0) { const path = require("path"); const fs = require("fs"); const readLine = require("readline"); let notify = - "The CLI for webpack must be installed as a separate package, for which there are choices:\n"; + "One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:"; - CLI.forEach(item => { - notify += ` ${item.name} (${item.URL}): ${item.description}\n`; - }); + for (const item of CLIs) { + notify += `\n - ${item.name} (${item.url})\n ${item.description}`; + } console.error(notify); const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); const packageManager = isYarn ? "yarn" : "npm"; - const installOptions = ["install", "-D"]; + const installOptions = [isYarn ? "add" : "install", "-D"]; - if (isYarn) { - installOptions[0] = "add"; - } + console.error( + `We will use "${packageManager}" to install the CLI via "${packageManager} ${installOptions.join( + " " + )}".` + ); - let question = `Would you like to install (${CLI.map(item => item.name).join( - "/" - )}):\n`; + let question = `Which one do you like to install (${CLIs.map( + item => item.name + ).join("/")}):\n`; const questionInterface = readLine.createInterface({ input: process.stdin, - output: process.stdout + output: process.stderr }); questionInterface.question(question, answer => { questionInterface.close(); const normalizedAnswer = answer.toLowerCase(); - const selectedPackage = CLI.find(item => item.name === normalizedAnswer); + const selectedPackage = CLIs.find(item => { + return item.name === normalizedAnswer || item.alias === normalizedAnswer; + }); - if (!selectedPackage) { + if (!normalizedAnswer) { console.error( - "It needs to be installed alongside webpack to use the CLI" + "One CLI needs to be installed alongside webpack to use the CLI." + ); + process.exitCode = 1; + + return; + } else if (!selectedPackage) { + console.error( + "No matching choice.\n" + + "One CLI needs to be installed alongside webpack to use the CLI.\n" + + "Try to installing your CLI of choice manually." ); process.exitCode = 1; return; } - installOptions.push(normalizedAnswer); + const packageName = selectedPackage.package; console.log( - `Installing '${normalizedAnswer}' (running '${packageManager} ${installOptions.join( + `Installing '${ + selectedPackage.name + }' (running '${packageManager} ${installOptions.join( " " - )}')...` + )} ${packageName}')...` ); - runCommand(packageManager, installOptions) - .then(result => { - return require(normalizedAnswer); //eslint-disable-line + runCommand(packageManager, installOptions.concat(packageName)) + .then(() => { + require(packageName); //eslint-disable-line }) .catch(error => { console.error(error); process.exitCode = 1; }); }); +} else if (installedClis.length === 1) { + require(installedClis[0].package); // eslint-disable-line } else { - const installedPackage = CLI.map( - item => (item.installed ? item.name : "") - ).filter(v => v); - - if (installedPackage.length > 1) { - console.warn( - `You have installed ${installedPackage.join( + console.warn( + `You have installed ${installedClis + .map(item => item.name) + .join( " and " - )} together. To work with the webpack you need only one CLI package, please remove one of them` - ); - } - - require(installedPackage[0]); // eslint-disable-line + )} together. To work with the "webpack" command you need only one CLI package, please remove one of them or use them directly via their binary.` + ); } From 4c12b796d7fdcdf21d8b611ebad1a1d4c8f28557 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 15 May 2018 17:07:14 +0200 Subject: [PATCH 052/111] remove unused declarations --- declarations.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/declarations.d.ts b/declarations.d.ts index 5d161e7c5d2..06d06158cec 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -1,6 +1,4 @@ declare module "*.json"; -declare module "webpack-cli"; -declare module "webpack-command"; // Deprecated NodeJS API usages in Webpack declare namespace NodeJS { From 0d89a4540378808391cbb9f530e5b5656c3ed302 Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Wed, 16 May 2018 13:03:38 +0200 Subject: [PATCH 053/111] Add a test to check typeof transformation --- test/cases/parsing/issue-7318/index.js | 5 +++++ test/cases/parsing/issue-7318/typeof.js | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 test/cases/parsing/issue-7318/index.js create mode 100644 test/cases/parsing/issue-7318/typeof.js diff --git a/test/cases/parsing/issue-7318/index.js b/test/cases/parsing/issue-7318/index.js new file mode 100644 index 00000000000..b99c6946803 --- /dev/null +++ b/test/cases/parsing/issue-7318/index.js @@ -0,0 +1,5 @@ +const type = require("./typeof"); + +it("should not output invalid code", () => { + expect(type).toBe("number"); +}); diff --git a/test/cases/parsing/issue-7318/typeof.js b/test/cases/parsing/issue-7318/typeof.js new file mode 100644 index 00000000000..e48d9ea1cd1 --- /dev/null +++ b/test/cases/parsing/issue-7318/typeof.js @@ -0,0 +1,2 @@ +typeof 1 +module.exports = "number" From 426e6259e1788db27a614a4a6a59a52ee9505619 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 16 May 2018 13:22:29 +0200 Subject: [PATCH 054/111] chore: bump to v1.5.0 --- package.json | 6 +- yarn.lock | 201 +++++++++++++++++++++++++++------------------------ 2 files changed, 109 insertions(+), 98 deletions(-) diff --git a/package.json b/package.json index 7c1ea3969f1..2df8bf2770b 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "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.4.2", - "@webassemblyjs/wasm-edit": "1.4.2", - "@webassemblyjs/wasm-parser": "1.4.2", + "@webassemblyjs/ast": "1.5.0", + "@webassemblyjs/wasm-edit": "1.5.0", + "@webassemblyjs/wasm-parser": "1.5.0", "acorn": "^5.0.0", "acorn-dynamic-import": "^3.0.0", "ajv": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index 16d0b6b7603..18ae8cce81a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28,116 +28,121 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd" -"@webassemblyjs/ast@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.2.tgz#ab715aa1fec9dd23c025204dba39690c119418ea" +"@webassemblyjs/ast@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.0.tgz#ee70576d035377392c1d74dba3810a0e82f035bc" dependencies: - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/wast-parser" "1.4.2" + "@webassemblyjs/helper-wasm-bytecode" "1.5.0" + "@webassemblyjs/wast-parser" "1.5.0" debug "^3.1.0" - webassemblyjs "1.4.2" + webassemblyjs "1.5.0" -"@webassemblyjs/floating-point-hex-parser@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.4.2.tgz#9296fb64caa37bf98c8064aa329680e3e2bfacc7" +"@webassemblyjs/floating-point-hex-parser@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.5.0.tgz#37fd9785ef9f7b655522235308a23e3770a695a9" -"@webassemblyjs/helper-buffer@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.4.2.tgz#3cacecd5a6bfcb67932ed8219f81f92d8b2dafbb" +"@webassemblyjs/helper-buffer@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.5.0.tgz#87e2192f7b80330cf422684680bc959f0b802fe2" + dependencies: + debug "^3.1.0" -"@webassemblyjs/helper-code-frame@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.4.2.tgz#20526637c3849f12b08f8661248477eef9642329" +"@webassemblyjs/helper-code-frame@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.5.0.tgz#335bfe462ec6c34a3c6f5b18fb79e729529c131f" dependencies: - "@webassemblyjs/wast-printer" "1.4.2" + "@webassemblyjs/wast-printer" "1.5.0" -"@webassemblyjs/helper-fsm@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.4.2.tgz#e41050282994b5be077b95b65b66ecd5a92c5e88" +"@webassemblyjs/helper-fsm@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.5.0.tgz#eb7fd42a8aa3a52bbe4775edd4fbb3acfe5f6b8c" -"@webassemblyjs/helper-wasm-bytecode@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.4.2.tgz#b48c289c7921056aa12d71e78a17070ffe90c49c" +"@webassemblyjs/helper-wasm-bytecode@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.5.0.tgz#2c91bff8628152945604e54d06eaa80ffde0afbd" -"@webassemblyjs/helper-wasm-section@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.4.2.tgz#520e02c0cc3e5e9b5f44f58abc04ba5eda6e5476" +"@webassemblyjs/helper-wasm-section@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.5.0.tgz#d777f1b29394de1d8d1b01f354724c8e6bcc5cce" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-buffer" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/wasm-gen" "1.4.2" + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/helper-buffer" "1.5.0" + "@webassemblyjs/helper-wasm-bytecode" "1.5.0" + "@webassemblyjs/wasm-gen" "1.5.0" + debug "^3.1.0" -"@webassemblyjs/leb128@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.4.2.tgz#d13f368abdcefc54428f55a265a993de610f8893" +"@webassemblyjs/leb128@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.5.0.tgz#1c5f0ae55e8961b1d366f1182969a7b005bc25cb" dependencies: leb "^0.3.0" -"@webassemblyjs/validation@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.4.2.tgz#55cf5b219e25900c85773fc35beb9d12ae0ede53" +"@webassemblyjs/validation@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.5.0.tgz#40decf501635e6e838eb8caa7dde864db8651ee8" + dependencies: + "@webassemblyjs/ast" "1.5.0" + debug "3.0.1" + +"@webassemblyjs/wasm-edit@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.5.0.tgz#3876d692afa4810dc05566e860a2f6c081865a9a" + dependencies: + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/helper-buffer" "1.5.0" + "@webassemblyjs/helper-wasm-bytecode" "1.5.0" + "@webassemblyjs/helper-wasm-section" "1.5.0" + "@webassemblyjs/wasm-gen" "1.5.0" + "@webassemblyjs/wasm-opt" "1.5.0" + "@webassemblyjs/wasm-parser" "1.5.0" + "@webassemblyjs/wast-printer" "1.5.0" + debug "^3.1.0" + +"@webassemblyjs/wasm-gen@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.5.0.tgz#8d8ce57c8dcf395e1538d9343c1f64b37ceb4e37" dependencies: - "@webassemblyjs/ast" "1.4.2" + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/helper-wasm-bytecode" "1.5.0" + "@webassemblyjs/leb128" "1.5.0" -"@webassemblyjs/wasm-edit@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.4.2.tgz#bde9a581065f63f257ed511d7d9cf04f8cd04524" +"@webassemblyjs/wasm-opt@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.5.0.tgz#3aee98a45e5db4e10e712a48fcdf02d07f36f518" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-buffer" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/helper-wasm-section" "1.4.2" - "@webassemblyjs/wasm-gen" "1.4.2" - "@webassemblyjs/wasm-opt" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - "@webassemblyjs/wast-printer" "1.4.2" + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/helper-buffer" "1.5.0" + "@webassemblyjs/wasm-gen" "1.5.0" + "@webassemblyjs/wasm-parser" "1.5.0" debug "^3.1.0" -"@webassemblyjs/wasm-gen@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.4.2.tgz#0899297f9426073736df799287845a73c597cf90" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/leb128" "1.4.2" - -"@webassemblyjs/wasm-opt@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.4.2.tgz#c44ad48e109aec197e3bf69875c54537d76ba2e9" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-buffer" "1.4.2" - "@webassemblyjs/wasm-gen" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - -"@webassemblyjs/wasm-parser@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.4.2.tgz#3bf7e10cfe336db0ecdea0a5d7ed8a63b7a7754a" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/helper-wasm-bytecode" "1.4.2" - "@webassemblyjs/leb128" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - webassemblyjs "1.4.2" - -"@webassemblyjs/wast-parser@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.2.tgz#6499c38cf8895a81394f7e40d4681a85aaa84498" - dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/floating-point-hex-parser" "1.4.2" - "@webassemblyjs/helper-code-frame" "1.4.2" - "@webassemblyjs/helper-fsm" "1.4.2" +"@webassemblyjs/wasm-parser@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.5.0.tgz#d32b277ab8687de84d2a65f6866266796b9cdd27" + dependencies: + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/helper-wasm-bytecode" "1.5.0" + "@webassemblyjs/leb128" "1.5.0" + "@webassemblyjs/wasm-parser" "1.5.0" + webassemblyjs "1.5.0" + +"@webassemblyjs/wast-parser@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.5.0.tgz#7ef24ba1a872d72306f5ad2063236674c7dd7863" + dependencies: + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/floating-point-hex-parser" "1.5.0" + "@webassemblyjs/helper-code-frame" "1.5.0" + "@webassemblyjs/helper-fsm" "1.5.0" long "^3.2.0" - webassemblyjs "1.4.2" + webassemblyjs "1.5.0" -"@webassemblyjs/wast-printer@1.4.2": - version "1.4.2" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.4.2.tgz#ee70a828f0d9730b55b9a5c3ed694094ba68ba57" +"@webassemblyjs/wast-printer@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.5.0.tgz#a2204d71a187936df86ce8f6fbd7157fb229eccf" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/wast-parser" "1.4.2" + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/wast-parser" "1.5.0" long "^3.2.0" abab@^1.0.4: @@ -1481,6 +1486,12 @@ date-now@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" +debug@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.0.1.tgz#0564c612b521dc92d9f2988f0549e34f9c98db64" + dependencies: + ms "2.0.0" + debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -6270,14 +6281,14 @@ watchpack@^1.5.0: graceful-fs "^4.1.2" neo-async "^2.5.0" -webassemblyjs@1.4.2: - version "1.4.2" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.4.2.tgz#3b07b506917c97153d83441d8a88ffa2d25cc07d" +webassemblyjs@1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.5.0.tgz#aad753e53e222e51d33a21782c6697cd353ed280" dependencies: - "@webassemblyjs/ast" "1.4.2" - "@webassemblyjs/validation" "1.4.2" - "@webassemblyjs/wasm-parser" "1.4.2" - "@webassemblyjs/wast-parser" "1.4.2" + "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/validation" "1.5.0" + "@webassemblyjs/wasm-parser" "1.5.0" + "@webassemblyjs/wast-parser" "1.5.0" long "^3.2.0" webidl-conversions@^4.0.1, webidl-conversions@^4.0.2: From d7d82b25d554d4881ce664d3f453b83ff091e160 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 16 May 2018 13:22:46 +0200 Subject: [PATCH 055/111] refactor : use AST utils --- declarations.d.ts | 13 +++++++++---- lib/wasm/WebAssemblyGenerator.js | 22 +++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/declarations.d.ts b/declarations.d.ts index 85bb4fc5f6f..15ae0098193 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -62,6 +62,7 @@ declare module "@webassemblyjs/ast" { export class ModuleExport extends Node { name: string; } + export class ModuleExportDescr extends Node {} export class IndexLiteral extends Node {} export class NumberLiteral extends Node {} export class Global extends Node {} @@ -78,7 +79,7 @@ declare module "@webassemblyjs/ast" { params: FuncParam[]; results: string[]; } - export class TypeInstructionFunc extends Node {} + export class TypeInstruction extends Node {} export class IndexInFuncSection extends Node {} export function indexLiteral(index: number): IndexLiteral; export function numberLiteral(num: number): NumberLiteral; @@ -92,13 +93,17 @@ declare module "@webassemblyjs/ast" { type: string, init: Node[] ): ObjectInstruction; - export function func(initFuncId, funcParams, funcResults, funcBody): Func; - export function typeInstructionFunc(params: FuncParam[], results: string[]): TypeInstructionFunc; + export function signature(params: FuncParam[], results: string[]): Signature; + export function func(initFuncId, Signature, funcBody): Func; + export function typeInstruction(id: Identifier, functype: Signature): TypeInstruction; export function indexInFuncSection(index: IndexLiteral): IndexInFuncSection; export function moduleExport( identifier: string, + descr: ModuleExportDescr + ): ModuleExport; + export function moduleExportDescr( type: string, - index: IndexLiteral + index: ModuleExportDescr ): ModuleExport; export function getSectionMetadata(ast: any, section: string); diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index 2b2e8bf31db..ba9a232bcf1 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -202,8 +202,6 @@ const rewriteExportNames = ({ ast, module }) => bin => { const usedName = module.isUsed(path.node.name); if (usedName) { path.node.name = usedName; - // TODO remove this when fixed in @webassemblyjs - path.node.descr.id = t.numberLiteral(+path.node.descr.id.raw); } else { path.remove(); } @@ -229,10 +227,6 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => { } else { path.node.module = WebAssemblyUtils.MANGLED_MODULE; path.node.name = result.name; - if (path.node.descr.id) - path.node.descr.id = t.numberLiteral(+path.node.descr.id.raw); - if (path.node.descr.name) - path.node.descr.name = t.numberLiteral(+path.node.descr.name.raw); } } }); @@ -284,19 +278,20 @@ const addInitFunction = ({ const funcResults = []; // Code section - const func = t.func(initFuncId, funcParams, funcResults, funcBody); + const funcSignature = t.signature(funcParams, funcResults); + const func = t.func(initFuncId, funcSignature, funcBody); // Type section - const functype = t.typeInstructionFunc( - func.signature.params, - func.signature.results - ); + const functype = t.typeInstruction(undefined, funcSignature); // Func section const funcindex = t.indexInFuncSection(nextTypeIndex); // Export section - const moduleExport = t.moduleExport(initFuncId.value, "Func", nextFuncIndex); + const moduleExport = t.moduleExport( + initFuncId.value, + t.moduleExportDescr("Func", nextFuncIndex) + ); return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]); }; @@ -330,7 +325,8 @@ class WebAssemblyGenerator extends Generator { const ast = decode(bin, { ignoreDataSection: true, - ignoreCodeSection: true + ignoreCodeSection: true, + ignoreCustomNameSection: true }); const importedGlobals = getImportedGlobals(ast); From 78cecc709e672dc40a9cf65fe3a834e3f3ac3c08 Mon Sep 17 00:00:00 2001 From: Sven SAULEAU Date: Wed, 16 May 2018 13:27:57 +0200 Subject: [PATCH 056/111] chore: bump webassemblyjs to v1.5.1 --- package.json | 6 +- yarn.lock | 178 +++++++++++++++++++++++++-------------------------- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/package.json b/package.json index 2df8bf2770b..225b31d4572 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "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.5.0", - "@webassemblyjs/wasm-edit": "1.5.0", - "@webassemblyjs/wasm-parser": "1.5.0", + "@webassemblyjs/ast": "1.5.1", + "@webassemblyjs/wasm-edit": "1.5.1", + "@webassemblyjs/wasm-parser": "1.5.1", "acorn": "^5.0.0", "acorn-dynamic-import": "^3.0.0", "ajv": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index 18ae8cce81a..d182b663a38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28,121 +28,121 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd" -"@webassemblyjs/ast@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.0.tgz#ee70576d035377392c1d74dba3810a0e82f035bc" +"@webassemblyjs/ast@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.1.tgz#b77382eed0c334418508fb08b73f1eae198c6960" dependencies: - "@webassemblyjs/helper-wasm-bytecode" "1.5.0" - "@webassemblyjs/wast-parser" "1.5.0" + "@webassemblyjs/helper-wasm-bytecode" "1.5.1" + "@webassemblyjs/wast-parser" "1.5.1" debug "^3.1.0" - webassemblyjs "1.5.0" + webassemblyjs "1.5.1" -"@webassemblyjs/floating-point-hex-parser@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.5.0.tgz#37fd9785ef9f7b655522235308a23e3770a695a9" +"@webassemblyjs/floating-point-hex-parser@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.5.1.tgz#0af82482faea3d86e37a020643475571197e8b3f" -"@webassemblyjs/helper-buffer@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.5.0.tgz#87e2192f7b80330cf422684680bc959f0b802fe2" +"@webassemblyjs/helper-buffer@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.5.1.tgz#659046a5af671cd7b1d67a021d8dccef043508e3" dependencies: debug "^3.1.0" -"@webassemblyjs/helper-code-frame@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.5.0.tgz#335bfe462ec6c34a3c6f5b18fb79e729529c131f" +"@webassemblyjs/helper-code-frame@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.5.1.tgz#9170e9e5c0af7ac8154a7a2d0cb85d6f7e318207" dependencies: - "@webassemblyjs/wast-printer" "1.5.0" + "@webassemblyjs/wast-printer" "1.5.1" -"@webassemblyjs/helper-fsm@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.5.0.tgz#eb7fd42a8aa3a52bbe4775edd4fbb3acfe5f6b8c" +"@webassemblyjs/helper-fsm@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.5.1.tgz#68f9e4a432b9e825f334db790dc037209c393a07" -"@webassemblyjs/helper-wasm-bytecode@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.5.0.tgz#2c91bff8628152945604e54d06eaa80ffde0afbd" +"@webassemblyjs/helper-wasm-bytecode@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.5.1.tgz#363459069ef44173dcd9d5392fa6074eab7b711d" -"@webassemblyjs/helper-wasm-section@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.5.0.tgz#d777f1b29394de1d8d1b01f354724c8e6bcc5cce" +"@webassemblyjs/helper-wasm-section@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.5.1.tgz#c45b3cc233c5067ef44cd35599b07aff279c531a" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/helper-buffer" "1.5.0" - "@webassemblyjs/helper-wasm-bytecode" "1.5.0" - "@webassemblyjs/wasm-gen" "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/helper-buffer" "1.5.1" + "@webassemblyjs/helper-wasm-bytecode" "1.5.1" + "@webassemblyjs/wasm-gen" "1.5.1" debug "^3.1.0" -"@webassemblyjs/leb128@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.5.0.tgz#1c5f0ae55e8961b1d366f1182969a7b005bc25cb" +"@webassemblyjs/leb128@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.5.1.tgz#a0069a66560547cf1e4228845e760ac035449e0d" dependencies: leb "^0.3.0" -"@webassemblyjs/validation@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.5.0.tgz#40decf501635e6e838eb8caa7dde864db8651ee8" +"@webassemblyjs/validation@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.5.1.tgz#ce8e06f7be7392e0ddb7dab55b6c0f37f63dcaa6" dependencies: - "@webassemblyjs/ast" "1.5.0" + "@webassemblyjs/ast" "1.5.1" debug "3.0.1" -"@webassemblyjs/wasm-edit@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.5.0.tgz#3876d692afa4810dc05566e860a2f6c081865a9a" - dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/helper-buffer" "1.5.0" - "@webassemblyjs/helper-wasm-bytecode" "1.5.0" - "@webassemblyjs/helper-wasm-section" "1.5.0" - "@webassemblyjs/wasm-gen" "1.5.0" - "@webassemblyjs/wasm-opt" "1.5.0" - "@webassemblyjs/wasm-parser" "1.5.0" - "@webassemblyjs/wast-printer" "1.5.0" +"@webassemblyjs/wasm-edit@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.5.1.tgz#4b3eb413031e63de2c4fddd69eda3f0a2a43c772" + dependencies: + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/helper-buffer" "1.5.1" + "@webassemblyjs/helper-wasm-bytecode" "1.5.1" + "@webassemblyjs/helper-wasm-section" "1.5.1" + "@webassemblyjs/wasm-gen" "1.5.1" + "@webassemblyjs/wasm-opt" "1.5.1" + "@webassemblyjs/wasm-parser" "1.5.1" + "@webassemblyjs/wast-printer" "1.5.1" debug "^3.1.0" -"@webassemblyjs/wasm-gen@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.5.0.tgz#8d8ce57c8dcf395e1538d9343c1f64b37ceb4e37" +"@webassemblyjs/wasm-gen@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.5.1.tgz#805c1b15ef43e3f311e96d4f8a648f03bfc3b5a2" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/helper-wasm-bytecode" "1.5.0" - "@webassemblyjs/leb128" "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/helper-wasm-bytecode" "1.5.1" + "@webassemblyjs/leb128" "1.5.1" -"@webassemblyjs/wasm-opt@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.5.0.tgz#3aee98a45e5db4e10e712a48fcdf02d07f36f518" +"@webassemblyjs/wasm-opt@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.5.1.tgz#01f3e0f5ea89762e02a374a8d34a1b418b6066ee" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/helper-buffer" "1.5.0" - "@webassemblyjs/wasm-gen" "1.5.0" - "@webassemblyjs/wasm-parser" "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/helper-buffer" "1.5.1" + "@webassemblyjs/wasm-gen" "1.5.1" + "@webassemblyjs/wasm-parser" "1.5.1" debug "^3.1.0" -"@webassemblyjs/wasm-parser@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.5.0.tgz#d32b277ab8687de84d2a65f6866266796b9cdd27" +"@webassemblyjs/wasm-parser@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.5.1.tgz#ee8c5562fa6a1213dd535c4b59dd2d7760bbf0f3" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/helper-wasm-bytecode" "1.5.0" - "@webassemblyjs/leb128" "1.5.0" - "@webassemblyjs/wasm-parser" "1.5.0" - webassemblyjs "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/helper-wasm-bytecode" "1.5.1" + "@webassemblyjs/leb128" "1.5.1" + "@webassemblyjs/wasm-parser" "1.5.1" + webassemblyjs "1.5.1" -"@webassemblyjs/wast-parser@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.5.0.tgz#7ef24ba1a872d72306f5ad2063236674c7dd7863" +"@webassemblyjs/wast-parser@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.5.1.tgz#4da00bf7f4e2532c6ed674089a072ae604aeaaab" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/floating-point-hex-parser" "1.5.0" - "@webassemblyjs/helper-code-frame" "1.5.0" - "@webassemblyjs/helper-fsm" "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/floating-point-hex-parser" "1.5.1" + "@webassemblyjs/helper-code-frame" "1.5.1" + "@webassemblyjs/helper-fsm" "1.5.1" long "^3.2.0" - webassemblyjs "1.5.0" + webassemblyjs "1.5.1" -"@webassemblyjs/wast-printer@1.5.0": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.5.0.tgz#a2204d71a187936df86ce8f6fbd7157fb229eccf" +"@webassemblyjs/wast-printer@1.5.1": + version "1.5.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.5.1.tgz#91f52975decdd98051d28bf7fe89c1faa978d9a8" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/wast-parser" "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/wast-parser" "1.5.1" long "^3.2.0" abab@^1.0.4: @@ -6281,14 +6281,14 @@ watchpack@^1.5.0: graceful-fs "^4.1.2" neo-async "^2.5.0" -webassemblyjs@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.5.0.tgz#aad753e53e222e51d33a21782c6697cd353ed280" +webassemblyjs@1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.5.1.tgz#645caab374dd1803cfbfbaa7489bb4b72f2061ff" dependencies: - "@webassemblyjs/ast" "1.5.0" - "@webassemblyjs/validation" "1.5.0" - "@webassemblyjs/wasm-parser" "1.5.0" - "@webassemblyjs/wast-parser" "1.5.0" + "@webassemblyjs/ast" "1.5.1" + "@webassemblyjs/validation" "1.5.1" + "@webassemblyjs/wasm-parser" "1.5.1" + "@webassemblyjs/wast-parser" "1.5.1" long "^3.2.0" webidl-conversions@^4.0.1, webidl-conversions@^4.0.2: From cbbe6f8cd0feadd0f21f869cd923ad6c2ff7e18c Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 17 May 2018 10:08:24 +0200 Subject: [PATCH 057/111] add all examples from the WebAssembly explorer as tests --- .../wasm-explorer-examples-async/Q_rsqrt.wasm | Bin 0 -> 156 bytes .../wasm-explorer-examples-async/duff.wasm | Bin 0 -> 531 bytes .../wasm-explorer-examples-async/fact.wasm | Bin 0 -> 154 bytes .../fast-math.wasm | Bin 0 -> 290 bytes .../wasm-explorer-examples-async/index.js | 55 ++++++++++++++++++ .../node_modules/env.js | 1 + .../wasm-explorer-examples-async/popcnt.wasm | Bin 0 -> 120 bytes .../test.filter.js | 5 ++ .../testFunction.wasm | Bin 0 -> 154 bytes .../wasm-explorer-examples-sync/Q_rsqrt.wasm | Bin 0 -> 156 bytes .../wasm-explorer-examples-sync/duff.wasm | Bin 0 -> 531 bytes .../wasm-explorer-examples-sync/fact.wasm | Bin 0 -> 154 bytes .../fast-math.wasm | Bin 0 -> 290 bytes .../wasm/wasm-explorer-examples-sync/index.js | 23 ++++++++ .../node_modules/env.js | 1 + .../wasm-explorer-examples-sync/popcnt.wasm | Bin 0 -> 120 bytes .../test.filter.js | 5 ++ .../testFunction.wasm | Bin 0 -> 154 bytes .../wasm/wasm-explorer-examples-sync/tests.js | 50 ++++++++++++++++ 19 files changed, 140 insertions(+) create mode 100644 test/cases/wasm/wasm-explorer-examples-async/Q_rsqrt.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-async/duff.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-async/fact.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-async/fast-math.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-async/index.js create mode 100644 test/cases/wasm/wasm-explorer-examples-async/node_modules/env.js create mode 100644 test/cases/wasm/wasm-explorer-examples-async/popcnt.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-async/test.filter.js create mode 100644 test/cases/wasm/wasm-explorer-examples-async/testFunction.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/Q_rsqrt.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/duff.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/fact.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/fast-math.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/index.js create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/node_modules/env.js create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/popcnt.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/test.filter.js create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/testFunction.wasm create mode 100644 test/cases/wasm/wasm-explorer-examples-sync/tests.js diff --git a/test/cases/wasm/wasm-explorer-examples-async/Q_rsqrt.wasm b/test/cases/wasm/wasm-explorer-examples-async/Q_rsqrt.wasm new file mode 100644 index 0000000000000000000000000000000000000000..e5c17c16d9316f427e5fecc3c5ff9be22f980233 GIT binary patch literal 156 zcmZQbEY4+QU|?WuYiMX-U`$}FWvpdx0<#%dTEKJx0|RR_M1+y85yW6%p8=wn*m6^I z^NT8(7`Wr3%md?#iVKTM(ij-H4uMtg0h5fi&I}9(>=hV*6odT~B}T{loA3T)RbbfT f$XJ@aPl;iQ0>hNaK&%8(0aB>I2;@zfJcSzo+ifc& literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-async/duff.wasm b/test/cases/wasm/wasm-explorer-examples-async/duff.wasm new file mode 100644 index 0000000000000000000000000000000000000000..0b75ea455a873ad27a1abde856c02784cb186231 GIT binary patch literal 531 zcmaKoyH3O~5Jm6Uj-6z(%P%UViojARJWEhG7O&6`t_|$})cC2H!@Mr>oxZ9#Bhwym0AvVttzHdeX&RoEtyn!R wTTA~Wx5mrq-!@*Fmd%7XEt^%vw(QMYe>C#~m4Zs!ld5Ms8=KX4EXGh?25tqWo&4M`K(_$F2YYS+izOn~ literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-async/fast-math.wasm b/test/cases/wasm/wasm-explorer-examples-async/fast-math.wasm new file mode 100644 index 0000000000000000000000000000000000000000..1733deb9ba7cbe6174e75dd6b0b7cb9a83dce216 GIT binary patch literal 290 zcmZQbEY4+QU|?XJ+|ba#z?{HTQ^Q!3zz8CkYd~zK2_OkZ=G440j`%3!g8cH76b1(7 zHjpSQBLgEN6H5zNMF9f?YcrU|z{u7JVlc2@08wmgxv9DNMU_kp>_7w3^7B&|82RF( zEOQeplTzbzGxLB3GV#PmStKXs~ ymYbTJUsTD&z>=Gona9Au86RbuoL`z(lEuKtH3Mu)2UxuVL#88R33n@u!wmpEmLEs} literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-async/test.filter.js b/test/cases/wasm/wasm-explorer-examples-async/test.filter.js new file mode 100644 index 00000000000..23177349638 --- /dev/null +++ b/test/cases/wasm/wasm-explorer-examples-async/test.filter.js @@ -0,0 +1,5 @@ +var supportsWebAssembly = require("../../../helpers/supportsWebAssembly"); + +module.exports = function(config) { + return supportsWebAssembly(); +}; diff --git a/test/cases/wasm/wasm-explorer-examples-async/testFunction.wasm b/test/cases/wasm/wasm-explorer-examples-async/testFunction.wasm new file mode 100644 index 0000000000000000000000000000000000000000..3be47ce57b4698410ae6f5eed03da4d114cdb8c4 GIT binary patch literal 154 zcmZQbEY4+QU|?WuZ)j*>U`$}DuV<`hZUS={SX#hz0RsbTGem@utr5gvU|#^DnAmbt zbMuQTnHYrQqYRBoQj1I6O7oISGV}8SGBX(%xVD3JZ3L5y^^OdROiT_6jE;;RybR0^ i3Je-d3<^wHicAU&jx1S<3_zLsEG0%>25xQzCT;*J5hNJ^ literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-sync/Q_rsqrt.wasm b/test/cases/wasm/wasm-explorer-examples-sync/Q_rsqrt.wasm new file mode 100644 index 0000000000000000000000000000000000000000..e5c17c16d9316f427e5fecc3c5ff9be22f980233 GIT binary patch literal 156 zcmZQbEY4+QU|?WuYiMX-U`$}FWvpdx0<#%dTEKJx0|RR_M1+y85yW6%p8=wn*m6^I z^NT8(7`Wr3%md?#iVKTM(ij-H4uMtg0h5fi&I}9(>=hV*6odT~B}T{loA3T)RbbfT f$XJ@aPl;iQ0>hNaK&%8(0aB>I2;@zfJcSzo+ifc& literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-sync/duff.wasm b/test/cases/wasm/wasm-explorer-examples-sync/duff.wasm new file mode 100644 index 0000000000000000000000000000000000000000..0b75ea455a873ad27a1abde856c02784cb186231 GIT binary patch literal 531 zcmaKoyH3O~5Jm6Uj-6z(%P%UViojARJWEhG7O&6`t_|$})cC2H!@Mr>oxZ9#Bhwym0AvVttzHdeX&RoEtyn!R wTTA~Wx5mrq-!@*Fmd%7XEt^%vw(QMYe>C#~m4Zs!ld5Ms8=KX4EXGh?25tqWo&4M`K(_$F2YYS+izOn~ literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-sync/fast-math.wasm b/test/cases/wasm/wasm-explorer-examples-sync/fast-math.wasm new file mode 100644 index 0000000000000000000000000000000000000000..1733deb9ba7cbe6174e75dd6b0b7cb9a83dce216 GIT binary patch literal 290 zcmZQbEY4+QU|?XJ+|ba#z?{HTQ^Q!3zz8CkYd~zK2_OkZ=G440j`%3!g8cH76b1(7 zHjpSQBLgEN6H5zNMF9f?YcrU|z{u7JVlc2@08wmgxv9DNMU_kp>_7w3^7B&|82RF( zEOQeplTzbzGxLB3GV#PmStKXs t.run_Q_rsqrt()); +}); + +it("testFunction should work", function() { + return import("./tests").then(t => t.run_testFunction()); +}); + +it("fact should work", function() { + return import("./tests").then(t => t.run_fact()); +}); + +it("popcnt should work", function() { + return import("./tests").then(t => t.run_popcnt()); +}); + +it("fast-math should work", function() { + return import("./tests").then(t => t.run_fastMath()); +}); + +it("duff should work", function() { + return import("./tests").then(t => t.run_duff()); +}); diff --git a/test/cases/wasm/wasm-explorer-examples-sync/node_modules/env.js b/test/cases/wasm/wasm-explorer-examples-sync/node_modules/env.js new file mode 100644 index 00000000000..bb82d984bdc --- /dev/null +++ b/test/cases/wasm/wasm-explorer-examples-sync/node_modules/env.js @@ -0,0 +1 @@ +export const _Z3powdd = Math.pow; diff --git a/test/cases/wasm/wasm-explorer-examples-sync/popcnt.wasm b/test/cases/wasm/wasm-explorer-examples-sync/popcnt.wasm new file mode 100644 index 0000000000000000000000000000000000000000..f605a5a95f78d673d3586e2007b781a3511552db GIT binary patch literal 120 zcmZQbEY4+QU|?WuYiMX-U`$}FXRK##2C~ ymYbTJUsTD&z>=Gona9Au86RbuoL`z(lEuKtH3Mu)2UxuVL#88R33n@u!wmpEmLEs} literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-sync/test.filter.js b/test/cases/wasm/wasm-explorer-examples-sync/test.filter.js new file mode 100644 index 00000000000..23177349638 --- /dev/null +++ b/test/cases/wasm/wasm-explorer-examples-sync/test.filter.js @@ -0,0 +1,5 @@ +var supportsWebAssembly = require("../../../helpers/supportsWebAssembly"); + +module.exports = function(config) { + return supportsWebAssembly(); +}; diff --git a/test/cases/wasm/wasm-explorer-examples-sync/testFunction.wasm b/test/cases/wasm/wasm-explorer-examples-sync/testFunction.wasm new file mode 100644 index 0000000000000000000000000000000000000000..3be47ce57b4698410ae6f5eed03da4d114cdb8c4 GIT binary patch literal 154 zcmZQbEY4+QU|?WuZ)j*>U`$}DuV<`hZUS={SX#hz0RsbTGem@utr5gvU|#^DnAmbt zbMuQTnHYrQqYRBoQj1I6O7oISGV}8SGBX(%xVD3JZ3L5y^^OdROiT_6jE;;RybR0^ i3Je-d3<^wHicAU&jx1S<3_zLsEG0%>25xQzCT;*J5hNJ^ literal 0 HcmV?d00001 diff --git a/test/cases/wasm/wasm-explorer-examples-sync/tests.js b/test/cases/wasm/wasm-explorer-examples-sync/tests.js new file mode 100644 index 00000000000..c957248a967 --- /dev/null +++ b/test/cases/wasm/wasm-explorer-examples-sync/tests.js @@ -0,0 +1,50 @@ +import * as Q_rsqrt from "./Q_rsqrt.wasm"; +import * as testFunction from "./testFunction.wasm"; +import * as fact from "./fact.wasm"; +import * as popcnt from "./popcnt.wasm"; +import * as fastMath from "./fast-math.wasm"; +import * as duff from "./duff.wasm"; + +export function run_Q_rsqrt() { + const result = Q_rsqrt._Z7Q_rsqrtf(1/1764); + expect(result).toBeGreaterThan(41.9); + expect(result).toBeLessThan(42.1); +} + +export function run_testFunction() { + const view = new Int32Array(testFunction.memory.buffer); + view[0] = 123; + view[1] = 1; + view[2] = 2; + view[3] = 3; + const result = testFunction._Z12testFunctionPii(4, 3); + expect(result).toEqual(6); +} + +export function run_fact() { + const result = fact._Z4facti(11); + expect(result).toEqual(39916800); +} + +export function run_popcnt() { + expect(popcnt.main(0xF0F)).toEqual(16); + expect(popcnt._Z5countj(0xF0F)).toEqual(8); +} + +export function run_fastMath() { + expect(fastMath._Z3food(42)).toEqual(14); + expect(fastMath._Z9maybe_mindd(42, 24)).toEqual(24); + expect(fastMath._Z8call_powd(42)).toEqual(9682651996416); + expect(fastMath._Z6do_powd(42)).toEqual(9682651996416); + expect(fastMath._Z6factorddd(42, 42, 42)).toEqual(3528); +} + +export function run_duff() { + const view = new Uint8Array(duff.memory.buffer); + view[0] = 123; + for(let i = 1; i < 100; i++) + view[i] = i; + const result = duff._Z4sendPcS_m(200, 1, 100); + for(let i = 1; i < 100; i++) + expect(view[199 + i]).toEqual(i); +} From 71af5e214e5932809f33bd91a39fa27a930858ed Mon Sep 17 00:00:00 2001 From: byzyk Date: Thu, 17 May 2018 13:08:11 +0400 Subject: [PATCH 058/111] revert: remove pretty script from package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0feb3471cbc..240c5bf9e19 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "code-lint": "eslint setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"", "type-lint": "tsc --pretty", "fix": "yarn code-lint --fix", + "pretty": "prettier --write \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" \"declarations.d.ts\"", "schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", "cover": "yarn cover:init && yarn cover:all && yarn cover:report", From 63a4145e3fa846e4b9b720436a6fddc692c51833 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 17 May 2018 17:29:07 +0200 Subject: [PATCH 059/111] clear output directory on test start --- test/ConfigTestCases.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/ConfigTestCases.test.js b/test/ConfigTestCases.test.js index b0f58ddc86b..0fa46e346b2 100644 --- a/test/ConfigTestCases.test.js +++ b/test/ConfigTestCases.test.js @@ -5,6 +5,7 @@ const path = require("path"); const fs = require("fs"); const vm = require("vm"); const mkdirp = require("mkdirp"); +const rimraf = require("rimraf"); const checkArrayExpectation = require("./checkArrayExpectation"); const Stats = require("../lib/Stats"); @@ -47,7 +48,6 @@ describe("ConfigTestCases", () => { category.name, testName ); - mkdirp.sync(outputDirectory); const exportedTests = []; const exportedBeforeEach = []; const exportedAfterEach = []; @@ -59,6 +59,8 @@ describe("ConfigTestCases", () => { if (err) return reject(err); resolve(); }; + rimraf.sync(outputDirectory); + mkdirp.sync(outputDirectory); const options = prepareOptions( require(path.join(testDirectory, "webpack.config.js")), { testPath: outputDirectory } From 75db965170335acc7b4d1be52dca033fc0f10d9b Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 17 May 2018 12:35:13 +0200 Subject: [PATCH 060/111] update combination when split fails because of max requests fixes #7323 --- lib/optimize/SplitChunksPlugin.js | 319 +++++++++++------- .../__snapshots__/StatsTestCases.test.js.snap | 198 ++++++----- .../statsCases/split-chunks/webpack.config.js | 1 + 3 files changed, 294 insertions(+), 224 deletions(-) diff --git a/lib/optimize/SplitChunksPlugin.js b/lib/optimize/SplitChunksPlugin.js index 202ec7766c5..84f1d31b63a 100644 --- a/lib/optimize/SplitChunksPlugin.js +++ b/lib/optimize/SplitChunksPlugin.js @@ -10,6 +10,7 @@ const GraphHelpers = require("../GraphHelpers"); const { isSubset } = require("../util/SetHelpers"); /** @typedef {import("../Chunk")} Chunk */ +/** @typedef {import("../Module")} Module */ const hashFilename = name => { return crypto @@ -310,7 +311,6 @@ module.exports = class SplitChunksPlugin { // Create a list of possible combinations const combinationsCache = new Map(); // Map[]> - const selectedChunksCacheByChunksSet = new WeakMap(); // WeakMap, WeakMap> const getCombinations = key => { const chunksSet = chunkSetsInGraph.get(key); @@ -330,14 +330,36 @@ module.exports = class SplitChunksPlugin { return array; }; + /** + * @typedef {Object} SelectedChunksResult + * @property {Chunk[]} chunks the list of chunks + * @property {string} key a key of the list + */ + + /** + * @typedef {function(Chunk): boolean} ChunkFilterFunction + */ + + /** @type {WeakMap, WeakMap>} */ + const selectedChunksCacheByChunksSet = new WeakMap(); + + /** + * get list and key by applying the filter function to the list + * It is cached for performance reasons + * @param {Set} chunks list of chunks + * @param {ChunkFilterFunction} chunkFilter filter function for chunks + * @returns {SelectedChunksResult} list and key + */ const getSelectedChunks = (chunks, chunkFilter) => { let entry = selectedChunksCacheByChunksSet.get(chunks); if (entry === undefined) { - entry = new Map(); + entry = new WeakMap(); selectedChunksCacheByChunksSet.set(chunks, entry); } + /** @type {SelectedChunksResult} */ let entry2 = entry.get(chunkFilter); if (entry2 === undefined) { + /** @type {Chunk[]} */ const selectedChunks = []; for (const chunk of chunks) { if (chunkFilter(chunk)) selectedChunks.push(chunk); @@ -351,10 +373,76 @@ module.exports = class SplitChunksPlugin { return entry2; }; + /** + * @typedef {Object} ChunksInfoItem + * @property {SortableSet} modules + * @property {TODO} cacheGroup + * @property {string} name + * @property {number} size + * @property {Map} chunks + * @property {Set} reuseableChunks + * @property {Set} chunksKeys + */ + // Map a list of chunks to a list of modules // For the key the chunk "index" is used, the value is a SortableSet of modules + /** @type {Map} */ const chunksInfoMap = new Map(); + /** + * @param {TODO} cacheGroup the current cache group + * @param {Chunk[]} selectedChunks chunks selected for this module + * @param {string} selectedChunksKey a key of selectedChunks + * @param {Module} module the current module + * @returns {void} + */ + const addModuleToChunksInfoMap = ( + cacheGroup, + selectedChunks, + selectedChunksKey, + module + ) => { + // Break if minimum number of chunks is not reached + if (selectedChunks.length < cacheGroup.minChunks) return; + // Determine name for split chunk + const name = cacheGroup.getName( + module, + selectedChunks, + cacheGroup.key + ); + // Create key for maps + // When it has a name we use the name as key + // Elsewise we create the key from chunks and cache group key + // This automatically merges equal names + const key = + (name && `name:${name}`) || + `chunks:${selectedChunksKey} key:${cacheGroup.key}`; + // Add module to maps + let info = chunksInfoMap.get(key); + if (info === undefined) { + chunksInfoMap.set( + key, + (info = { + modules: new SortableSet(undefined, sortByIdentifier), + cacheGroup, + name, + size: 0, + chunks: new Map(), + reuseableChunks: new Set(), + chunksKeys: new Set() + }) + ); + } + info.modules.add(module); + info.size += module.size(); + if (!info.chunksKeys.has(selectedChunksKey)) { + info.chunksKeys.add(selectedChunksKey); + for (const chunk of selectedChunks) { + info.chunks.set(chunk, chunk.getNumberOfModules()); + } + } + }; + // Walk through all modules for (const module of compilation.modules) { // Get cache group @@ -422,55 +510,17 @@ module.exports = class SplitChunksPlugin { chunkCombination, cacheGroup.chunksFilter ); - // Break if minimum number of chunks is not reached - if (selectedChunks.length < cacheGroup.minChunks) continue; - // Determine name for split chunk - const name = cacheGroup.getName( - module, + + addModuleToChunksInfoMap( + cacheGroup, selectedChunks, - cacheGroup.key + selectedChunksKey, + module ); - // Create key for maps - // When it has a name we use the name as key - // Elsewise we create the key from chunks and cache group key - // This automatically merges equal names - const key = - (name && `name:${name}`) || - `chunks:${selectedChunksKey} key:${cacheGroup.key}`; - // Add module to maps - let info = chunksInfoMap.get(key); - if (info === undefined) { - chunksInfoMap.set( - key, - (info = { - modules: new SortableSet(undefined, sortByIdentifier), - cacheGroup, - name, - size: 0, - chunks: new Map(), - reusedableChunks: new Set(), - chunksKeys: new Set() - }) - ); - } - info.modules.add(module); - info.size += module.size(); - if (!info.chunksKeys.has(selectedChunksKey)) { - info.chunksKeys.add(selectedChunksKey); - for (const chunk of selectedChunks) { - info.chunks.set(chunk, chunk.getNumberOfModules()); - } - } } } } - for (const [key, info] of chunksInfoMap) { - // Get size of module lists - if (info.size < info.cacheGroup.minSize) { - chunksInfoMap.delete(key); - } - } while (chunksInfoMap.size > 0) { // Find best matching entry let bestEntryKey; @@ -478,15 +528,20 @@ module.exports = class SplitChunksPlugin { for (const pair of chunksInfoMap) { const key = pair[0]; const info = pair[1]; - if (bestEntry === undefined) { - bestEntry = info; - bestEntryKey = key; - } else if (compareEntries(bestEntry, info) < 0) { - bestEntry = info; - bestEntryKey = key; + if (info.size >= info.cacheGroup.minSize) { + if (bestEntry === undefined) { + bestEntry = info; + bestEntryKey = key; + } else if (compareEntries(bestEntry, info) < 0) { + bestEntry = info; + bestEntryKey = key; + } } } + // No suitable item left + if (bestEntry === undefined) break; + const item = bestEntry; chunksInfoMap.delete(bestEntryKey); @@ -517,12 +572,19 @@ module.exports = class SplitChunksPlugin { } } } - const usedChunks = []; - // Walk through all chunks - for (const chunk of item.chunks.keys()) { + // Check if maxRequests condition can be fullfilled + + const usedChunks = Array.from(item.chunks.keys()).filter(chunk => { // skip if we address ourself - if ((chunkName && chunk.name === chunkName) || chunk === newChunk) - continue; + return ( + (!chunkName || chunk.name !== chunkName) && chunk !== newChunk + ); + }); + + // Skip when no chunk selected + if (usedChunks.length === 0) continue; + + const chunkInLimit = usedChunks.filter(chunk => { // respect max requests when not enforced const maxRequests = chunk.isOnlyInitial() ? item.cacheGroup.maxInitialRequests @@ -532,88 +594,97 @@ module.exports = class SplitChunksPlugin { item.cacheGroup.maxAsyncRequests ) : item.cacheGroup.maxAsyncRequests; - if (isFinite(maxRequests) && getRequests(chunk) >= maxRequests) - continue; - if (newChunk === undefined) { - // Create the new chunk - newChunk = compilation.addChunk(chunkName); + return !isFinite(maxRequests) || getRequests(chunk) < maxRequests; + }); + + if (chunkInLimit.length < usedChunks.length) { + for (const module of item.modules) { + addModuleToChunksInfoMap( + item.cacheGroup, + chunkInLimit, + getKey(chunkInLimit), + module + ); } + continue; + } + + // Create the new chunk if not reusing one + if (!isReused) { + newChunk = compilation.addChunk(chunkName); + } + // Walk through all chunks + for (const chunk of usedChunks) { // Add graph connections for splitted chunk chunk.split(newChunk); - usedChunks.push(chunk); } - // If we successfully created a new chunk or reused one - if (newChunk) { - // Add a note to the chunk - newChunk.chunkReason = isReused - ? "reused as split chunk" - : "split chunk"; - if (item.cacheGroup.key) { - newChunk.chunkReason += ` (cache group: ${ - item.cacheGroup.key - })`; + // Add a note to the chunk + newChunk.chunkReason = isReused + ? "reused as split chunk" + : "split chunk"; + if (item.cacheGroup.key) { + newChunk.chunkReason += ` (cache group: ${item.cacheGroup.key})`; + } + if (chunkName) { + newChunk.chunkReason += ` (name: ${chunkName})`; + // If the chosen name is already an entry point we remove the entry point + const entrypoint = compilation.entrypoints.get(chunkName); + if (entrypoint) { + compilation.entrypoints.delete(chunkName); + entrypoint.remove(); + newChunk.entryModule = undefined; + } + } + if (item.cacheGroup.filename) { + if (!newChunk.isOnlyInitial()) { + throw new Error( + "SplitChunksPlugin: You are trying to set a filename for a chunk which is (also) loaded on demand. " + + "The runtime can only handle loading of chunks which match the chunkFilename schema. " + + "Using a custom filename would fail at runtime. " + + `(cache group: ${item.cacheGroup.key})` + ); } - if (chunkName) { - newChunk.chunkReason += ` (name: ${chunkName})`; - // If the chosen name is already an entry point we remove the entry point - const entrypoint = compilation.entrypoints.get(chunkName); - if (entrypoint) { - compilation.entrypoints.delete(chunkName); - entrypoint.remove(); - newChunk.entryModule = undefined; + newChunk.filenameTemplate = item.cacheGroup.filename; + } + if (!isReused) { + // Add all modules to the new chunk + for (const module of item.modules) { + if (typeof module.chunkCondition === "function") { + if (!module.chunkCondition(newChunk)) continue; + } + // Add module to new chunk + GraphHelpers.connectChunkAndModule(newChunk, module); + // Remove module from used chunks + for (const chunk of usedChunks) { + chunk.removeModule(module); + module.rewriteChunkInReasons(chunk, [newChunk]); } } - if (item.cacheGroup.filename) { - if (!newChunk.isOnlyInitial()) { - throw new Error( - "SplitChunksPlugin: You are trying to set a filename for a chunk which is (also) loaded on demand. " + - "The runtime can only handle loading of chunks which match the chunkFilename schema. " + - "Using a custom filename would fail at runtime. " + - `(cache group: ${item.cacheGroup.key})` - ); + } else { + // Remove all modules from used chunks + for (const module of item.modules) { + for (const chunk of usedChunks) { + chunk.removeModule(module); + module.rewriteChunkInReasons(chunk, [newChunk]); } - newChunk.filenameTemplate = item.cacheGroup.filename; } - if (!isReused) { - // Add all modules to the new chunk + } + // remove all modules from other entries and update size + for (const [key, info] of chunksInfoMap) { + if (isOverlap(info.chunks, item.chunks)) { + const oldSize = info.modules.size; for (const module of item.modules) { - if (typeof module.chunkCondition === "function") { - if (!module.chunkCondition(newChunk)) continue; - } - // Add module to new chunk - GraphHelpers.connectChunkAndModule(newChunk, module); - // Remove module from used chunks - for (const chunk of usedChunks) { - chunk.removeModule(module); - module.rewriteChunkInReasons(chunk, [newChunk]); - } + info.modules.delete(module); } - } else { - // Remove all modules from used chunks - for (const module of item.modules) { - for (const chunk of usedChunks) { - chunk.removeModule(module); - module.rewriteChunkInReasons(chunk, [newChunk]); - } + if (info.modules.size === 0) { + chunksInfoMap.delete(key); + continue; } - } - // remove all modules from other entries and update size - for (const [key, info] of chunksInfoMap) { - if (isOverlap(info.chunks, item.chunks)) { - const oldSize = info.modules.size; - for (const module of item.modules) { - info.modules.delete(module); - } - if (info.modules.size === 0) { + if (info.modules.size !== oldSize) { + info.size = getModulesSize(info.modules); + if (info.size < info.cacheGroup.minSize) chunksInfoMap.delete(key); - continue; - } - if (info.modules.size !== oldSize) { - info.size = getModulesSize(info.modules); - if (info.size < info.cacheGroup.minSize) - chunksInfoMap.delete(key); - } } } } diff --git a/test/__snapshots__/StatsTestCases.test.js.snap b/test/__snapshots__/StatsTestCases.test.js.snap index a2efbf558d7..74b351dd2ff 100644 --- a/test/__snapshots__/StatsTestCases.test.js.snap +++ b/test/__snapshots__/StatsTestCases.test.js.snap @@ -341,61 +341,61 @@ Child multiple-vendors: > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [2] ./node_modules/x.js 20 bytes {0} [built] - chunk {1} multiple-vendors/a~async-a~async-b~async-c~b~c.js (a~async-a~async-b~async-c~b~c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: a~async-a~async-b~async-c~b~c) + chunk {1} multiple-vendors/async-a~async-b~async-c.js (async-a~async-b~async-c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: async-a~async-b~async-c) > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - chunk {2} multiple-vendors/async-b~async-c~async-g~b~c.js (async-b~async-c~async-g~b~c) 20 bytes <{0}> <{1}> <{10}> <{3}> <{8}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={6}= ={7}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~b~c) + chunk {2} multiple-vendors/async-b~async-c~async-g.js (async-b~async-c~async-g) 20 bytes <{0}> <{1}> <{10}> <{3}> <{6}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={7}= ={8}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g) > ./g [] 6:0-47 > ./g [] 6:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [1] ./f.js 20 bytes {2} {11} {12} [built] - chunk {3} multiple-vendors/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={8}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b) + chunk {3} multiple-vendors/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={7}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b) > ./a a > ./b b > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 [3] ./node_modules/y.js 20 bytes {3} [built] - chunk {4} multiple-vendors/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={7}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c) + chunk {4} multiple-vendors/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={8}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c) > ./c c > ./c [8] ./index.js 3:0-47 [7] ./node_modules/z.js 20 bytes {4} [built] - chunk {5} multiple-vendors/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{8}> ={2}= [rendered] + chunk {5} multiple-vendors/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{6}> ={2}= [rendered] > ./g [] 6:0-47 > ./g [] 6:0-47 [9] ./g.js 34 bytes {5} [built] - chunk {6} multiple-vendors/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] - > ./b [8] ./index.js 2:0-47 - [4] ./b.js 72 bytes {6} {11} [built] - chunk {7} multiple-vendors/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] - > ./c [8] ./index.js 3:0-47 - [5] ./c.js 72 bytes {7} {12} [built] - chunk {8} multiple-vendors/a~async-a.js (a~async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: a~async-a) + chunk {6} multiple-vendors/async-a.js (async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] > ./a [8] ./index.js 1:0-47 - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + [6] ./a.js + 1 modules 156 bytes {6} {10} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] + chunk {7} multiple-vendors/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] + > ./b [8] ./index.js 2:0-47 + [4] ./b.js 72 bytes {7} {11} [built] + chunk {8} multiple-vendors/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] + > ./c [8] ./index.js 3:0-47 + [5] ./c.js 72 bytes {8} {12} [built] chunk {9} multiple-vendors/main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{4}< >{6}< >{7}< >{8}< [entry] [rendered] > ./ main [8] ./index.js 147 bytes {9} [built] chunk {10} multiple-vendors/a.js (a) 176 bytes ={0}= ={3}= >{2}< >{5}< [entry] [rendered] > ./a a [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + [6] ./a.js + 1 modules 156 bytes {6} {10} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] chunk {11} multiple-vendors/b.js (b) 112 bytes ={0}= ={3}= [entry] [rendered] > ./b b [0] ./d.js 20 bytes {1} {10} {11} {12} [built] [1] ./f.js 20 bytes {2} {11} {12} [built] - [4] ./b.js 72 bytes {6} {11} [built] + [4] ./b.js 72 bytes {7} {11} [built] chunk {12} multiple-vendors/c.js (c) 112 bytes ={0}= ={4}= [entry] [rendered] > ./c c [0] ./d.js 20 bytes {1} {10} {11} {12} [built] [1] ./f.js 20 bytes {2} {11} {12} [built] - [5] ./c.js 72 bytes {7} {12} [built] + [5] ./c.js 72 bytes {8} {12} [built] Child all: Entrypoint main = all/main.js Entrypoint a = all/vendors~a~async-a~async-b~async-c~b~c.js all/vendors~a~async-a~async-b~b.js all/a.js @@ -409,61 +409,61 @@ Child all: > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [2] ./node_modules/x.js 20 bytes {0} [built] - chunk {1} all/a~async-a~async-b~async-c~b~c.js (a~async-a~async-b~async-c~b~c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: a~async-a~async-b~async-c~b~c) + chunk {1} all/async-a~async-b~async-c.js (async-a~async-b~async-c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: async-a~async-b~async-c) > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - chunk {2} all/async-b~async-c~async-g~b~c.js (async-b~async-c~async-g~b~c) 20 bytes <{0}> <{1}> <{10}> <{3}> <{8}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={6}= ={7}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~b~c) + chunk {2} all/async-b~async-c~async-g.js (async-b~async-c~async-g) 20 bytes <{0}> <{1}> <{10}> <{3}> <{6}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={7}= ={8}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g) > ./g [] 6:0-47 > ./g [] 6:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [1] ./f.js 20 bytes {2} {11} {12} [built] - chunk {3} all/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={8}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b) + chunk {3} all/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={7}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b) > ./a a > ./b b > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 [3] ./node_modules/y.js 20 bytes {3} [built] - chunk {4} all/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={7}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c) + chunk {4} all/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={8}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c) > ./c c > ./c [8] ./index.js 3:0-47 [7] ./node_modules/z.js 20 bytes {4} [built] - chunk {5} all/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{8}> ={2}= [rendered] + chunk {5} all/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{6}> ={2}= [rendered] > ./g [] 6:0-47 > ./g [] 6:0-47 [9] ./g.js 34 bytes {5} [built] - chunk {6} all/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] - > ./b [8] ./index.js 2:0-47 - [4] ./b.js 72 bytes {6} {11} [built] - chunk {7} all/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] - > ./c [8] ./index.js 3:0-47 - [5] ./c.js 72 bytes {7} {12} [built] - chunk {8} all/a~async-a.js (a~async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: a~async-a) + chunk {6} all/async-a.js (async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] > ./a [8] ./index.js 1:0-47 - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + [6] ./a.js + 1 modules 156 bytes {6} {10} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] + chunk {7} all/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] + > ./b [8] ./index.js 2:0-47 + [4] ./b.js 72 bytes {7} {11} [built] + chunk {8} all/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] + > ./c [8] ./index.js 3:0-47 + [5] ./c.js 72 bytes {8} {12} [built] chunk {9} all/main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{4}< >{6}< >{7}< >{8}< [entry] [rendered] > ./ main [8] ./index.js 147 bytes {9} [built] chunk {10} all/a.js (a) 176 bytes ={0}= ={3}= >{2}< >{5}< [entry] [rendered] > ./a a [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + [6] ./a.js + 1 modules 156 bytes {6} {10} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] chunk {11} all/b.js (b) 112 bytes ={0}= ={3}= [entry] [rendered] > ./b b [0] ./d.js 20 bytes {1} {10} {11} {12} [built] [1] ./f.js 20 bytes {2} {11} {12} [built] - [4] ./b.js 72 bytes {6} {11} [built] + [4] ./b.js 72 bytes {7} {11} [built] chunk {12} all/c.js (c) 112 bytes ={0}= ={4}= [entry] [rendered] > ./c c [0] ./d.js 20 bytes {1} {10} {11} {12} [built] [1] ./f.js 20 bytes {2} {11} {12} [built] - [5] ./c.js 72 bytes {7} {12} [built]" + [5] ./c.js 72 bytes {8} {12} [built]" `; exports[`StatsTestCases should print correct stats for chunk-module-id-range 1`] = ` @@ -2161,61 +2161,61 @@ Child all-chunks: > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [2] ./node_modules/x.js 20 bytes {0} [built] - chunk {1} default/a~async-a~async-b~async-c~b~c.js (a~async-a~async-b~async-c~b~c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: a~async-a~async-b~async-c~b~c) + chunk {1} default/async-a~async-b~async-c.js (async-a~async-b~async-c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: async-a~async-b~async-c) > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - chunk {2} default/async-b~async-c~async-g~b~c.js (async-b~async-c~async-g~b~c) 20 bytes <{0}> <{1}> <{10}> <{3}> <{8}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={6}= ={7}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~b~c) + chunk {2} default/async-b~async-c~async-g.js (async-b~async-c~async-g) 20 bytes <{0}> <{1}> <{10}> <{3}> <{6}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={7}= ={8}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g) > ./g [] 6:0-47 > ./g [] 6:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [1] ./f.js 20 bytes {2} {11} {12} [built] - chunk {3} default/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={8}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b) + chunk {3} default/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={7}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b) > ./a a > ./b b > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 [3] ./node_modules/y.js 20 bytes {3} [built] - chunk {4} default/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={7}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c) + chunk {4} default/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={8}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c) > ./c c > ./c [8] ./index.js 3:0-47 [7] ./node_modules/z.js 20 bytes {4} [built] - chunk {5} default/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{8}> ={2}= [rendered] + chunk {5} default/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{6}> ={2}= [rendered] > ./g [] 6:0-47 > ./g [] 6:0-47 [9] ./g.js 34 bytes {5} [built] - chunk {6} default/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] - > ./b [8] ./index.js 2:0-47 - [4] ./b.js 72 bytes {6} {11} [built] - chunk {7} default/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] - > ./c [8] ./index.js 3:0-47 - [5] ./c.js 72 bytes {7} {12} [built] - chunk {8} default/a~async-a.js (a~async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: a~async-a) + chunk {6} default/async-a.js (async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] > ./a [8] ./index.js 1:0-47 - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + [6] ./a.js + 1 modules 156 bytes {6} {10} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] + chunk {7} default/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] + > ./b [8] ./index.js 2:0-47 + [4] ./b.js 72 bytes {7} {11} [built] + chunk {8} default/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] + > ./c [8] ./index.js 3:0-47 + [5] ./c.js 72 bytes {8} {12} [built] chunk {9} default/main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{4}< >{6}< >{7}< >{8}< [entry] [rendered] > ./ main [8] ./index.js 147 bytes {9} [built] chunk {10} default/a.js (a) 176 bytes ={0}= ={3}= >{2}< >{5}< [entry] [rendered] > ./a a [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + [6] ./a.js + 1 modules 156 bytes {6} {10} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] chunk {11} default/b.js (b) 112 bytes ={0}= ={3}= [entry] [rendered] > ./b b [0] ./d.js 20 bytes {1} {10} {11} {12} [built] [1] ./f.js 20 bytes {2} {11} {12} [built] - [4] ./b.js 72 bytes {6} {11} [built] + [4] ./b.js 72 bytes {7} {11} [built] chunk {12} default/c.js (c) 112 bytes ={0}= ={4}= [entry] [rendered] > ./c c [0] ./d.js 20 bytes {1} {10} {11} {12} [built] [1] ./f.js 20 bytes {2} {11} {12} [built] - [5] ./c.js 72 bytes {7} {12} [built] + [5] ./c.js 72 bytes {8} {12} [built] Child manual: Entrypoint main = default/main.js Entrypoint a = default/vendors.js default/a.js @@ -2274,72 +2274,70 @@ Child manual: [5] ./c.js 72 bytes {4} {8} [built] Child name-too-long: Entrypoint main = main.js - Entrypoint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js - Entrypoint bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js - Entrypoint cccccccccccccccccccccccccccccc = vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js vendors~async-c~cccccccccccccccccccccccccccccc.js cccccccccccccccccccccccccccccc.js - chunk {0} vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js (vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f) 20 bytes <{9}> ={1}= ={10}= ={11}= ={12}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f) + Entrypoint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793.js aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a.js aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js + Entrypoint bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793.js async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc.js bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js + Entrypoint cccccccccccccccccccccccccccccc = vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js vendors~async-c~cccccccccccccccccccccccccccccc.js aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793.js async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc.js cccccccccccccccccccccccccccccc.js + chunk {0} vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f.js (vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f) 20 bytes <{9}> ={1}= ={10}= ={11}= ={12}= ={2}= ={3}= ={4}= ={5}= ={7}= ={8}= >{2}< >{6}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccc~50ebc41f) > ./a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ./b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > ./c cccccccccccccccccccccccccccccc - > ./a [8] ./index.js 1:0-47 - > ./b [8] ./index.js 2:0-47 - > ./c [8] ./index.js 3:0-47 + > ./a [7] ./index.js 1:0-47 + > ./b [7] ./index.js 2:0-47 + > ./c [7] ./index.js 3:0-47 [2] ./node_modules/x.js 20 bytes {0} [built] - chunk {1} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793) - > ./a [8] ./index.js 1:0-47 - > ./b [8] ./index.js 2:0-47 - > ./c [8] ./index.js 3:0-47 - [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - chunk {2} async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc.js (async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc) 20 bytes <{0}> <{1}> <{10}> <{3}> <{8}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={6}= ={7}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc) + chunk {1} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793) 20 bytes <{9}> ={0}= ={10}= ={11}= ={12}= ={2}= ={3}= ={4}= ={5}= ={7}= ={8}= >{2}< >{6}< [initial] [rendered] split chunk (cache group: default) (name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~async-c~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccc~18066793) + > ./a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + > ./b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + > ./c cccccccccccccccccccccccccccccc + > ./a [7] ./index.js 1:0-47 + > ./b [7] ./index.js 2:0-47 + > ./c [7] ./index.js 3:0-47 + [1] ./d.js 20 bytes {1} [built] + chunk {2} async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc.js (async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc) 20 bytes <{0}> <{1}> <{10}> <{3}> <{5}> <{9}> ={0}= ={1}= ={11}= ={12}= ={3}= ={4}= ={6}= ={7}= ={8}= [initial] [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb~cccccccccccccccccccccccccccccc) > ./g [] 6:0-47 > ./g [] 6:0-47 - > ./b [8] ./index.js 2:0-47 - > ./c [8] ./index.js 3:0-47 - [1] ./f.js 20 bytes {2} {11} {12} [built] - chunk {3} vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js (vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={6}= ={8}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) + > ./b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + > ./c cccccccccccccccccccccccccccccc + > ./b [7] ./index.js 2:0-47 + > ./c [7] ./index.js 3:0-47 + [0] ./f.js 20 bytes {2} [built] + chunk {3} vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js (vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) 20 bytes <{9}> ={0}= ={1}= ={10}= ={11}= ={2}= ={5}= ={7}= >{2}< >{6}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a~async-b~bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) > ./a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ./b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb - > ./a [8] ./index.js 1:0-47 - > ./b [8] ./index.js 2:0-47 + > ./a [7] ./index.js 1:0-47 + > ./b [7] ./index.js 2:0-47 [3] ./node_modules/y.js 20 bytes {3} [built] - chunk {4} vendors~async-c~cccccccccccccccccccccccccccccc.js (vendors~async-c~cccccccccccccccccccccccccccccc) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={7}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~cccccccccccccccccccccccccccccc) + chunk {4} vendors~async-c~cccccccccccccccccccccccccccccc.js (vendors~async-c~cccccccccccccccccccccccccccccc) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={8}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~cccccccccccccccccccccccccccccc) > ./c cccccccccccccccccccccccccccccc - > ./c [8] ./index.js 3:0-47 - [7] ./node_modules/z.js 20 bytes {4} [built] - chunk {5} async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{8}> ={2}= [rendered] - > ./g [] 6:0-47 - > ./g [] 6:0-47 - [9] ./g.js 34 bytes {5} [built] - chunk {6} async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] - > ./b [8] ./index.js 2:0-47 - [4] ./b.js 72 bytes {6} {11} [built] - chunk {7} async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] - > ./c [8] ./index.js 3:0-47 - [5] ./c.js 72 bytes {7} {12} [built] - chunk {8} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a) - > ./a [8] ./index.js 1:0-47 - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] + > ./c [7] ./index.js 3:0-47 + [6] ./node_modules/z.js 20 bytes {4} [built] + chunk {5} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a) 156 bytes <{9}> ={0}= ={1}= ={10}= ={3}= >{2}< >{6}< [initial] [rendered] split chunk (cache group: default) (name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~async-a) + > ./a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + > ./a [7] ./index.js 1:0-47 + [8] ./a.js + 1 modules 156 bytes {5} [built] | ./a.js 121 bytes [built] | ./e.js 20 bytes [built] - chunk {9} main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{4}< >{6}< >{7}< >{8}< [entry] [rendered] + chunk {6} async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{5}> ={2}= [rendered] + > ./g [] 6:0-47 + > ./g [] 6:0-47 + [9] ./g.js 34 bytes {6} [built] + chunk {7} async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered] + > ./b [7] ./index.js 2:0-47 + [4] ./b.js 72 bytes {7} {11} [built] + chunk {8} async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered] + > ./c [7] ./index.js 3:0-47 + [5] ./c.js 72 bytes {8} {12} [built] + chunk {9} main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{4}< >{5}< >{7}< >{8}< [entry] [rendered] > ./ main - [8] ./index.js 147 bytes {9} [built] - chunk {10} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 176 bytes ={0}= ={3}= >{2}< >{5}< [entry] [rendered] + [7] ./index.js 147 bytes {9} [built] + chunk {10} aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 0 bytes ={0}= ={1}= ={3}= ={5}= >{2}< >{6}< [entry] [rendered] > ./a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - [6] ./a.js + 1 modules 156 bytes {8} {10} [built] - | ./a.js 121 bytes [built] - | ./e.js 20 bytes [built] - chunk {11} bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) 112 bytes ={0}= ={3}= [entry] [rendered] + chunk {11} bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) 72 bytes ={0}= ={1}= ={2}= ={3}= [entry] [rendered] > ./b bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb - [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - [1] ./f.js 20 bytes {2} {11} {12} [built] - [4] ./b.js 72 bytes {6} {11} [built] - chunk {12} cccccccccccccccccccccccccccccc.js (cccccccccccccccccccccccccccccc) 112 bytes ={0}= ={4}= [entry] [rendered] + [4] ./b.js 72 bytes {7} {11} [built] + chunk {12} cccccccccccccccccccccccccccccc.js (cccccccccccccccccccccccccccccc) 72 bytes ={0}= ={1}= ={2}= ={4}= [entry] [rendered] > ./c cccccccccccccccccccccccccccccc - [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - [1] ./f.js 20 bytes {2} {11} {12} [built] - [5] ./c.js 72 bytes {7} {12} [built] + [5] ./c.js 72 bytes {8} {12} [built] Child custom-chunks-filter: Entrypoint main = default/main.js Entrypoint a = default/a.js @@ -2352,12 +2350,12 @@ Child custom-chunks-filter: > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [2] ./node_modules/x.js 20 bytes {0} {10} [built] - chunk {1} default/async-a~async-b~async-c~b~c.js (async-a~async-b~async-c~b~c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: async-a~async-b~async-c~b~c) + chunk {1} default/async-a~async-b~async-c.js (async-a~async-b~async-c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: async-a~async-b~async-c) > ./a [8] ./index.js 1:0-47 > ./b [8] ./index.js 2:0-47 > ./c [8] ./index.js 3:0-47 [0] ./d.js 20 bytes {1} {10} {11} {12} [built] - chunk {2} default/async-b~async-c~async-g~b~c.js (async-b~async-c~async-g~b~c) 20 bytes <{0}> <{1}> <{10}> <{3}> <{6}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={7}= ={8}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~b~c) + chunk {2} default/async-b~async-c~async-g.js (async-b~async-c~async-g) 20 bytes <{0}> <{1}> <{10}> <{3}> <{6}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={7}= ={8}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g) > ./g [] 6:0-47 > ./g [] 6:0-47 > ./b [8] ./index.js 2:0-47 diff --git a/test/statsCases/split-chunks/webpack.config.js b/test/statsCases/split-chunks/webpack.config.js index f69088f4c98..5172e72b58f 100644 --- a/test/statsCases/split-chunks/webpack.config.js +++ b/test/statsCases/split-chunks/webpack.config.js @@ -94,6 +94,7 @@ module.exports = [ optimization: { splitChunks: { minSize: 0, + maxInitialRequests: Infinity, chunks: "all" } }, From 7453db9dddabf0784f0cdf18a524037f6e4b86f2 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 17 May 2018 18:14:34 +0200 Subject: [PATCH 061/111] Reduce the travis load with build stages --- .travis.yml | 29 +++++++++++++++++++++-------- codecov.yml | 15 +++++++++++++++ package.json | 2 ++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index b1cc16a5835..88f661c3d31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,28 +10,41 @@ branches: cache: yarn: true +stages: + - basic + - advanced + - versions + matrix: include: - os: linux node_js: "10" - env: NO_WATCH_TESTS=1 JOB_PART=lint + env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=basic + stage: basic - os: linux node_js: "10" - env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration + env: NO_WATCH_TESTS=1 JOB_PART=lint + stage: advanced - os: linux - node_js: "8" + node_js: "10" env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration + stage: advanced - os: linux node_js: "10" env: NO_WATCH_TESTS=1 JOB_PART=unit - - os: linux - node_js: "6" - env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration + stage: advanced - os: osx node_js: "10" env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration - allow_failures: - - os: osx + stage: versions + - os: linux + node_js: "8" + env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration + stage: versions + - os: linux + node_js: "6" + env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration + stage: versions fast_finish: true install: diff --git a/codecov.yml b/codecov.yml index 9359b370b8e..0ce74197d90 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,6 +7,9 @@ coverage: status: project: default: off + basic: + flags: basic + target: auto integration: flags: integration target: auto @@ -15,6 +18,10 @@ coverage: target: 0% patch: default: off + integration: + flags: integration + target: 90% + base: pr integration: flags: integration target: 90% @@ -25,6 +32,9 @@ coverage: base: pr changes: default: off + basic: + flags: basic + target: 0% integration: flags: integration target: 0% @@ -32,3 +42,8 @@ coverage: flags: unit target: 0% comment: off +flags: + basic: + joined: false + unit: + joined: false diff --git a/package.json b/package.json index f67472e72d0..973e968cdc0 100644 --- a/package.json +++ b/package.json @@ -99,8 +99,10 @@ "setup": "node ./setup/setup.js", "test": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest", "test:integration": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.test.js\"", + "test:basic": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/{TestCasesNormal,ConfigTestCases}.test.js\"", "test:unit": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\"", "travis:integration": "yarn cover:init && yarn cover:integration --ci $JEST && yarn cover:report-min", + "travis:basic": "yarn test:basic --ci $JEST", "travis:unit": "yarn cover:init && yarn cover:unit --ci", "travis:lint": "yarn lint", "travis:benchmark": "yarn benchmark --ci", From 105dd779a497b46d78af80e6610ef059d5b73c43 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 17 May 2018 19:27:51 +0200 Subject: [PATCH 062/111] Include StatsTestCases --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 973e968cdc0..0550de2fb1f 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "setup": "node ./setup/setup.js", "test": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest", "test:integration": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.test.js\"", - "test:basic": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/{TestCasesNormal,ConfigTestCases}.test.js\"", + "test:basic": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/{TestCasesNormal,StatsTestCases,ConfigTestCases}.test.js\"", "test:unit": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.unittest.js\"", "travis:integration": "yarn cover:init && yarn cover:integration --ci $JEST && yarn cover:report-min", "travis:basic": "yarn test:basic --ci $JEST", From 217a657b7821f09eda8e732d764b8e373356ada1 Mon Sep 17 00:00:00 2001 From: REDDY PRASAD Date: Thu, 17 May 2018 23:23:28 +0530 Subject: [PATCH 063/111] :construction: WIP --- lib/util/cachedMerge.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/util/cachedMerge.js b/lib/util/cachedMerge.js index 863141e6b18..11e5ea9081b 100644 --- a/lib/util/cachedMerge.js +++ b/lib/util/cachedMerge.js @@ -5,7 +5,12 @@ "use strict"; const mergeCache = new WeakMap(); - +/** + * returns something + * @param {object} first first key + * @param {object} second second key + * @returns {WeakMap} new merge + */ const cachedMerge = (first, second) => { let innerCache = mergeCache.get(first); if (innerCache === undefined) { From 5930cf54b92e6a839bf75f42b1eb32ace793b916 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 17 May 2018 20:33:18 +0200 Subject: [PATCH 064/111] add split chunks example --- examples/many-pages/README.md | 141 +++++++++++++++++++++++++ examples/many-pages/build.js | 3 + examples/many-pages/node_modules/m1.js | 1 + examples/many-pages/node_modules/m2.js | 1 + examples/many-pages/node_modules/m3.js | 1 + examples/many-pages/node_modules/m4.js | 1 + examples/many-pages/node_modules/m5.js | 1 + examples/many-pages/node_modules/m6.js | 1 + examples/many-pages/node_modules/m7.js | 1 + examples/many-pages/node_modules/m8.js | 1 + examples/many-pages/pages/a.js | 7 ++ examples/many-pages/pages/b.js | 7 ++ examples/many-pages/pages/c.js | 7 ++ examples/many-pages/pages/d.js | 7 ++ examples/many-pages/pages/e.js | 5 + examples/many-pages/pages/f.js | 7 ++ examples/many-pages/pages/g.js | 3 + examples/many-pages/stuff/s1.js | 1 + examples/many-pages/stuff/s2.js | 1 + examples/many-pages/stuff/s3.js | 1 + examples/many-pages/stuff/s4.js | 1 + examples/many-pages/stuff/s5.js | 1 + examples/many-pages/stuff/s6.js | 1 + examples/many-pages/stuff/s7.js | 1 + examples/many-pages/stuff/s8.js | 1 + examples/many-pages/template.md | 35 ++++++ examples/many-pages/webpack.config.js | 21 ++++ 27 files changed, 259 insertions(+) create mode 100644 examples/many-pages/README.md create mode 100644 examples/many-pages/build.js create mode 100644 examples/many-pages/node_modules/m1.js create mode 100644 examples/many-pages/node_modules/m2.js create mode 100644 examples/many-pages/node_modules/m3.js create mode 100644 examples/many-pages/node_modules/m4.js create mode 100644 examples/many-pages/node_modules/m5.js create mode 100644 examples/many-pages/node_modules/m6.js create mode 100644 examples/many-pages/node_modules/m7.js create mode 100644 examples/many-pages/node_modules/m8.js create mode 100644 examples/many-pages/pages/a.js create mode 100644 examples/many-pages/pages/b.js create mode 100644 examples/many-pages/pages/c.js create mode 100644 examples/many-pages/pages/d.js create mode 100644 examples/many-pages/pages/e.js create mode 100644 examples/many-pages/pages/f.js create mode 100644 examples/many-pages/pages/g.js create mode 100644 examples/many-pages/stuff/s1.js create mode 100644 examples/many-pages/stuff/s2.js create mode 100644 examples/many-pages/stuff/s3.js create mode 100644 examples/many-pages/stuff/s4.js create mode 100644 examples/many-pages/stuff/s5.js create mode 100644 examples/many-pages/stuff/s6.js create mode 100644 examples/many-pages/stuff/s7.js create mode 100644 examples/many-pages/stuff/s8.js create mode 100644 examples/many-pages/template.md create mode 100644 examples/many-pages/webpack.config.js diff --git a/examples/many-pages/README.md b/examples/many-pages/README.md new file mode 100644 index 00000000000..00d976fbc20 --- /dev/null +++ b/examples/many-pages/README.md @@ -0,0 +1,141 @@ +# Info + +This example illustrates webpack's algorthim for automatic deduplication using `optimization.splitChunks`. + +This example application contains 7 pages, each of them importing 1-3 modules from the `node_modules` folder (vendor libs) and 0-3 modules from the `stuff` folder (application modules). In reallity an application is probably more complex, but the same mechanisms apply. + +The following configuration is used: + +* `optimization.splitChunks.chunks: "all"` - This opt-in into automatic splitting of initial chunks which is off by default +* `optimization.splitChunks.maxInitial/AsyncRequests: 20` - This opt-in into a HTTP2 optimized splitting mode by increasing the allowed amount of requests. Browser only supports 6 requests in parallel for HTTP1.1. + +# Interpreting the result + +* `pageA.js` the normal output files for the entrypoint `pageA` +* `vendors~pageD~pageE~pageF~pageG.js` vendor libs shared by these pages extracted into a separate output file when larger then the threshold in size +* `vendors~pageA.js` vendors only used by a single page but larger than the threshold in size +* `pageA~pageD~pageF.js` application modules shared by these pages and larger than the threshold in size + +The threshold is here 40 bytes, but by default (in a real application) 30kb. + +Some modules are intentially duplicated, i. e. `./stuff/s4.js` is shared by `pageA` and `pageC`, but it's the only shared module so no separate output file is created because it would be smaller than the threshold. A separate request (which comes with an overhead and worsen gzipping) is not worth the extra bytes. + +Note: decreasing `maxInitial/AsyncRequest` will increase duplication further to reduce the number of requests. Duplication doesn't affect initial page load, it only affects download size of navigations to other pages of the application. + +## webpack.config.js + +``` +module.exports = { + // mode: "development || "production", + entry: { + pageA: "./pages/a", + pageB: "./pages/b", + pageC: "./pages/c", + pageD: "./pages/d", + pageE: "./pages/e", + pageF: "./pages/f", + pageG: "./pages/g" + }, + optimization: { + splitChunks: { + chunks: "all", + maxInitialRequests: 20, // for HTTP2 + maxAsyncRequests: 20, // for HTTP2 + minSize: 40 // for example only: choosen to match 2 modules + // omit minSize in real use case to use the default of 30kb + } + } +}; +``` + +## Production mode + +``` +Hash: 0a1b2c3d4e5f6a7b8c9d +Version: webpack 4.8.3 + Asset Size Chunks Chunk Names + pageG.js 1.15 KiB 7 [emitted] pageG +vendors~pageD~pageE~pageF~pageG.js 119 bytes 0 [emitted] vendors~pageD~pageE~pageF~pageG + vendors~pageD~pageE~pageF.js 178 bytes 2 [emitted] vendors~pageD~pageE~pageF + vendors~pageA~pageB~pageC.js 180 bytes 3 [emitted] vendors~pageA~pageB~pageC + vendors~pageC.js 121 bytes 4 [emitted] vendors~pageC + vendors~pageB.js 121 bytes 5 [emitted] vendors~pageB + vendors~pageA.js 121 bytes 6 [emitted] vendors~pageA + pageA~pageD~pageF.js 156 bytes 1 [emitted] pageA~pageD~pageF + pageF.js 1.18 KiB 8 [emitted] pageF + pageE.js 1.17 KiB 9 [emitted] pageE + pageD.js 1.18 KiB 10 [emitted] pageD + pageC.js 1.27 KiB 11 [emitted] pageC + pageB.js 1.27 KiB 12 [emitted] pageB + pageA.js 1.18 KiB 13 [emitted] pageA +Entrypoint pageA = vendors~pageA~pageB~pageC.js vendors~pageA.js pageA~pageD~pageF.js pageA.js +Entrypoint pageB = vendors~pageA~pageB~pageC.js vendors~pageB.js pageB.js +Entrypoint pageC = vendors~pageA~pageB~pageC.js vendors~pageC.js pageC.js +Entrypoint pageD = vendors~pageD~pageE~pageF~pageG.js vendors~pageD~pageE~pageF.js pageA~pageD~pageF.js pageD.js +Entrypoint pageE = vendors~pageD~pageE~pageF~pageG.js vendors~pageD~pageE~pageF.js pageE.js +Entrypoint pageF = vendors~pageD~pageE~pageF~pageG.js vendors~pageD~pageE~pageF.js pageA~pageD~pageF.js pageF.js +Entrypoint pageG = vendors~pageD~pageE~pageF~pageG.js pageG.js +chunk {0} vendors~pageD~pageE~pageF~pageG.js (vendors~pageD~pageE~pageF~pageG) 43 bytes ={1}= ={10}= ={2}= ={7}= ={8}= ={9}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~pageD~pageE~pageF~pageG) + > ./pages/d pageD + > ./pages/e pageE + > ./pages/f pageF + > ./pages/g pageG + 1 module +chunk {1} pageA~pageD~pageF.js (pageA~pageD~pageF) 62 bytes ={0}= ={10}= ={13}= ={2}= ={3}= ={6}= ={8}= [initial] [rendered] split chunk (cache group: default) (name: pageA~pageD~pageF) + > ./pages/a pageA + > ./pages/d pageD + > ./pages/f pageF + [6] ./stuff/s3.js 31 bytes {1} [built] + [7] ./stuff/s2.js 31 bytes {1} [built] +chunk {2} vendors~pageD~pageE~pageF.js (vendors~pageD~pageE~pageF) 86 bytes ={0}= ={1}= ={10}= ={8}= ={9}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~pageD~pageE~pageF) + > ./pages/d pageD + > ./pages/e pageE + > ./pages/f pageF + 2 modules +chunk {3} vendors~pageA~pageB~pageC.js (vendors~pageA~pageB~pageC) 86 bytes ={1}= ={11}= ={12}= ={13}= ={4}= ={5}= ={6}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~pageA~pageB~pageC) + > ./pages/a pageA + > ./pages/b pageB + > ./pages/c pageC + 2 modules +chunk {4} vendors~pageC.js (vendors~pageC) 43 bytes ={11}= ={3}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~pageC) + > ./pages/c pageC + 1 module +chunk {5} vendors~pageB.js (vendors~pageB) 43 bytes ={12}= ={3}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~pageB) + > ./pages/b pageB + 1 module +chunk {6} vendors~pageA.js (vendors~pageA) 43 bytes ={1}= ={13}= ={3}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~pageA) + > ./pages/a pageA + 1 module +chunk {7} pageG.js (pageG) 70 bytes ={0}= [entry] [rendered] + > ./pages/g pageG + [0] ./stuff/s1.js 31 bytes {7} {8} {10} {12} [built] + [10] ./pages/g.js 39 bytes {7} [built] +chunk {8} pageF.js (pageF) 144 bytes ={0}= ={1}= ={2}= [entry] [rendered] + > ./pages/f pageF + [0] ./stuff/s1.js 31 bytes {7} {8} {10} {12} [built] + [11] ./pages/f.js 113 bytes {8} [built] +chunk {9} pageE.js (pageE) 98 bytes ={0}= ={2}= [entry] [rendered] + > ./pages/e pageE + [4] ./stuff/s7.js 31 bytes {9} {12} [built] + [12] ./pages/e.js 67 bytes {9} [built] +chunk {10} pageD.js (pageD) 144 bytes ={0}= ={1}= ={2}= [entry] [rendered] + > ./pages/d pageD + [0] ./stuff/s1.js 31 bytes {7} {8} {10} {12} [built] + [13] ./pages/d.js 113 bytes {10} [built] +chunk {11} pageC.js (pageC) 206 bytes ={3}= ={4}= [entry] [rendered] + > ./pages/c pageC + [5] ./stuff/s4.js 31 bytes {11} {13} [built] + [14] ./stuff/s6.js 31 bytes {11} [built] + [15] ./stuff/s5.js 31 bytes {11} [built] + [17] ./pages/c.js 113 bytes {11} [built] +chunk {12} pageB.js (pageB) 206 bytes ={3}= ={5}= [entry] [rendered] + > ./pages/b pageB + [0] ./stuff/s1.js 31 bytes {7} {8} {10} {12} [built] + [4] ./stuff/s7.js 31 bytes {9} {12} [built] + [18] ./stuff/s8.js 31 bytes {12} [built] + [20] ./pages/b.js 113 bytes {12} [built] +chunk {13} pageA.js (pageA) 144 bytes ={1}= ={3}= ={6}= [entry] [rendered] + > ./pages/a pageA + [5] ./stuff/s4.js 31 bytes {11} {13} [built] + [22] ./pages/a.js 113 bytes {13} [built] +``` \ No newline at end of file diff --git a/examples/many-pages/build.js b/examples/many-pages/build.js new file mode 100644 index 00000000000..6ae2decc566 --- /dev/null +++ b/examples/many-pages/build.js @@ -0,0 +1,3 @@ +global.NO_TARGET_ARGS = true; +global.NO_REASONS = true; +require("../build-common"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m1.js b/examples/many-pages/node_modules/m1.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m1.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m2.js b/examples/many-pages/node_modules/m2.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m2.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m3.js b/examples/many-pages/node_modules/m3.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m3.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m4.js b/examples/many-pages/node_modules/m4.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m4.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m5.js b/examples/many-pages/node_modules/m5.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m5.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m6.js b/examples/many-pages/node_modules/m6.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m6.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m7.js b/examples/many-pages/node_modules/m7.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m7.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/node_modules/m8.js b/examples/many-pages/node_modules/m8.js new file mode 100644 index 00000000000..61c8f92a5c5 --- /dev/null +++ b/examples/many-pages/node_modules/m8.js @@ -0,0 +1 @@ +console.log("a module installed from npm"); \ No newline at end of file diff --git a/examples/many-pages/pages/a.js b/examples/many-pages/pages/a.js new file mode 100644 index 00000000000..acad484d636 --- /dev/null +++ b/examples/many-pages/pages/a.js @@ -0,0 +1,7 @@ +import "m1"; +import "m2"; +import "m3"; + +import "../stuff/s2"; +import "../stuff/s3"; +import "../stuff/s4"; diff --git a/examples/many-pages/pages/b.js b/examples/many-pages/pages/b.js new file mode 100644 index 00000000000..a25a154677d --- /dev/null +++ b/examples/many-pages/pages/b.js @@ -0,0 +1,7 @@ +import "m1"; +import "m2"; +import "m4"; + +import "../stuff/s1"; +import "../stuff/s7"; +import "../stuff/s8"; diff --git a/examples/many-pages/pages/c.js b/examples/many-pages/pages/c.js new file mode 100644 index 00000000000..cca60b6112f --- /dev/null +++ b/examples/many-pages/pages/c.js @@ -0,0 +1,7 @@ +import "m1"; +import "m2"; +import "m5"; + +import "../stuff/s4"; +import "../stuff/s5"; +import "../stuff/s6"; diff --git a/examples/many-pages/pages/d.js b/examples/many-pages/pages/d.js new file mode 100644 index 00000000000..b3f8e2bcc1e --- /dev/null +++ b/examples/many-pages/pages/d.js @@ -0,0 +1,7 @@ +import "m6"; +import "m7"; +import "m8"; + +import "../stuff/s1"; +import "../stuff/s2"; +import "../stuff/s3"; diff --git a/examples/many-pages/pages/e.js b/examples/many-pages/pages/e.js new file mode 100644 index 00000000000..05da267adf5 --- /dev/null +++ b/examples/many-pages/pages/e.js @@ -0,0 +1,5 @@ +import "m6"; +import "m7"; +import "m8"; + +import "../stuff/s7"; diff --git a/examples/many-pages/pages/f.js b/examples/many-pages/pages/f.js new file mode 100644 index 00000000000..b3f8e2bcc1e --- /dev/null +++ b/examples/many-pages/pages/f.js @@ -0,0 +1,7 @@ +import "m6"; +import "m7"; +import "m8"; + +import "../stuff/s1"; +import "../stuff/s2"; +import "../stuff/s3"; diff --git a/examples/many-pages/pages/g.js b/examples/many-pages/pages/g.js new file mode 100644 index 00000000000..49f85a16b97 --- /dev/null +++ b/examples/many-pages/pages/g.js @@ -0,0 +1,3 @@ +import "m6"; + +import "../stuff/s1"; diff --git a/examples/many-pages/stuff/s1.js b/examples/many-pages/stuff/s1.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s1.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s2.js b/examples/many-pages/stuff/s2.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s2.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s3.js b/examples/many-pages/stuff/s3.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s3.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s4.js b/examples/many-pages/stuff/s4.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s4.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s5.js b/examples/many-pages/stuff/s5.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s5.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s6.js b/examples/many-pages/stuff/s6.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s6.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s7.js b/examples/many-pages/stuff/s7.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s7.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/stuff/s8.js b/examples/many-pages/stuff/s8.js new file mode 100644 index 00000000000..b5c7e15f13a --- /dev/null +++ b/examples/many-pages/stuff/s8.js @@ -0,0 +1 @@ +console.log("some own module"); \ No newline at end of file diff --git a/examples/many-pages/template.md b/examples/many-pages/template.md new file mode 100644 index 00000000000..7bbc7b0dd44 --- /dev/null +++ b/examples/many-pages/template.md @@ -0,0 +1,35 @@ +# Info + +This example illustrates webpack's algorthim for automatic deduplication using `optimization.splitChunks`. + +This example application contains 7 pages, each of them importing 1-3 modules from the `node_modules` folder (vendor libs) and 0-3 modules from the `stuff` folder (application modules). In reallity an application is probably more complex, but the same mechanisms apply. + +The following configuration is used: + +* `optimization.splitChunks.chunks: "all"` - This opt-in into automatic splitting of initial chunks which is off by default +* `optimization.splitChunks.maxInitial/AsyncRequests: 20` - This opt-in into a HTTP2 optimized splitting mode by increasing the allowed amount of requests. Browser only supports 6 requests in parallel for HTTP1.1. + +# Interpreting the result + +* `pageA.js` the normal output files for the entrypoint `pageA` +* `vendors~pageD~pageE~pageF~pageG.js` vendor libs shared by these pages extracted into a separate output file when larger then the threshold in size +* `vendors~pageA.js` vendors only used by a single page but larger than the threshold in size +* `pageA~pageD~pageF.js` application modules shared by these pages and larger than the threshold in size + +The threshold is here 40 bytes, but by default (in a real application) 30kb. + +Some modules are intentially duplicated, i. e. `./stuff/s4.js` is shared by `pageA` and `pageC`, but it's the only shared module so no separate output file is created because it would be smaller than the threshold. A separate request (which comes with an overhead and worsen gzipping) is not worth the extra bytes. + +Note: decreasing `maxInitial/AsyncRequest` will increase duplication further to reduce the number of requests. Duplication doesn't affect initial page load, it only affects download size of navigations to other pages of the application. + +## webpack.config.js + +``` +{{webpack.config.js}} +``` + +## Production mode + +``` +{{production:stdout}} +``` \ No newline at end of file diff --git a/examples/many-pages/webpack.config.js b/examples/many-pages/webpack.config.js new file mode 100644 index 00000000000..f47598f6309 --- /dev/null +++ b/examples/many-pages/webpack.config.js @@ -0,0 +1,21 @@ +module.exports = { + // mode: "development || "production", + entry: { + pageA: "./pages/a", + pageB: "./pages/b", + pageC: "./pages/c", + pageD: "./pages/d", + pageE: "./pages/e", + pageF: "./pages/f", + pageG: "./pages/g" + }, + optimization: { + splitChunks: { + chunks: "all", + maxInitialRequests: 20, // for HTTP2 + maxAsyncRequests: 20, // for HTTP2 + minSize: 40 // for example only: choosen to match 2 modules + // omit minSize in real use case to use the default of 30kb + } + } +}; From d30aef920d5a56ddbaf61d747cba515c0fc07b38 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 17 May 2018 20:52:50 -0400 Subject: [PATCH 065/111] Add badges to display install size --- README.md | 145 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index ef71f20eb7a..cb5e32d94ad 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ + + install size + @@ -84,25 +87,30 @@ interface](https://webpack.js.org/plugins/). Most of the features within webpack itself use this plugin interface. This makes webpack very **flexible**. -|Name|Status|Description| -|:--:|:----:|:----------| -|[extract-text-webpack-plugin][extract]|![extract-npm]|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)| -|[compression-webpack-plugin][compression]|![compression-npm]|Prepares compressed versions of assets to serve them with Content-Encoding| -|[i18n-webpack-plugin][i18n]|![i18n-npm]|Adds i18n support to your bundles| -|[html-webpack-plugin][html-plugin]|![html-plugin-npm]| Simplifies creation of HTML files (`index.html`) to serve your bundles| +|Name|Status|Install Size|Description| +|:--:|:----:|:----------:|:----------| +|[extract-text-webpack-plugin][extract]|![extract-npm]|![extract-size]|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)| +|[compression-webpack-plugin][compression]|![compression-npm]|![compression-size]|Prepares compressed versions of assets to serve them with Content-Encoding| +|[i18n-webpack-plugin][i18n]|![i18n-npm]|![i18n-size]|Adds i18n support to your bundles| +|[html-webpack-plugin][html-plugin]|![html-plugin-npm]|![html-plugin-size]| Simplifies creation of HTML files (`index.html`) to serve your bundles| [common-npm]: https://img.shields.io/npm/v/webpack.svg [extract]: https://github.com/webpack/extract-text-webpack-plugin [extract-npm]: https://img.shields.io/npm/v/extract-text-webpack-plugin.svg +[extract-size]: https://packagephobia.now.sh/badge?p=extract-text-webpack-plugin [component]: https://github.com/webpack/component-webpack-plugin [component-npm]: https://img.shields.io/npm/v/component-webpack-plugin.svg +[component-size]: https://packagephobia.now.sh/badge?p=component-webpack-plugin [compression]: https://github.com/webpack/compression-webpack-plugin [compression-npm]: https://img.shields.io/npm/v/compression-webpack-plugin.svg +[compression-size]: https://packagephobia.now.sh/badge?p=compression-webpack-plugin [i18n]: https://github.com/webpack/i18n-webpack-plugin [i18n-npm]: https://img.shields.io/npm/v/i18n-webpack-plugin.svg +[i18n-size]: https://packagephobia.now.sh/badge?p=i18n-webpack-plugin [html-plugin]: https://github.com/ampedandwired/html-webpack-plugin [html-plugin-npm]: https://img.shields.io/npm/v/html-webpack-plugin.svg +[html-plugin-size]: https://packagephobia.now.sh/badge?p=html-webpack-plugin ### [Loaders](https://webpack.js.org/loaders/) @@ -115,121 +123,154 @@ or are automatically applied via regex from your webpack configuration. #### Files -|Name|Status|Description| -|:--:|:----:|:----------| -|[raw-loader][raw]|![raw-npm]|Loads raw content of a file (utf-8)| -|[val-loader][val]|![val-npm]|Executes code as module and considers exports as JS code| -|[url-loader][url]|![url-npm]|Works like the file loader, but can return a Data Url if the file is smaller than a limit| -|[file-loader][file]|![file-npm]|Emits the file into the output folder and returns the (relative) url| +|Name|Status|Install Size|Description| +|:--:|:----:|:----------:|:----------| +|[raw-loader][raw]|![raw-npm]|![raw-size]|Loads raw content of a file (utf-8)| +|[val-loader][val]|![val-npm]|![val-size]|Executes code as module and considers exports as JS code| +|[url-loader][url]|![url-npm]|![url-size]|Works like the file loader, but can return a Data Url if the file is smaller than a limit| +|[file-loader][file]|![file-npm]|![file-size]|Emits the file into the output folder and returns the (relative) url| [raw]: https://github.com/webpack/raw-loader [raw-npm]: https://img.shields.io/npm/v/raw-loader.svg +[raw-size]: https://packagephobia.now.sh/badge?p=raw-loader [val]: https://github.com/webpack/val-loader [val-npm]: https://img.shields.io/npm/v/val-loader.svg +[val-size]: https://packagephobia.now.sh/badge?p=val-loader [url]: https://github.com/webpack/url-loader [url-npm]: https://img.shields.io/npm/v/url-loader.svg +[url-size]: https://packagephobia.now.sh/badge?p=url-loader [file]: https://github.com/webpack/file-loader [file-npm]: https://img.shields.io/npm/v/file-loader.svg +[file-size]: https://packagephobia.now.sh/badge?p=file-loader #### JSON -|Name|Status|Description| -|:--:|:----:|:----------| -||![json-npm]|Loads a JSON file (included by default)| -||![json5-npm]|Loads and transpiles a JSON 5 file| -||![cson-npm]|Loads and transpiles a CSON file| +|Name|Status|Install Size|Description| +|:--:|:----:|:----------:|:----------| +||![json-npm]|![json-size]|Loads a JSON file (included by default)| +||![json5-npm]|![json5-size]|Loads and transpiles a JSON 5 file| +||![cson-npm]|![cson-size]|Loads and transpiles a CSON file| [json-npm]: https://img.shields.io/npm/v/json-loader.svg +[json-size]: https://packagephobia.now.sh/badge?p=json-loader [json5-npm]: https://img.shields.io/npm/v/json5-loader.svg +[json5-size]: https://packagephobia.now.sh/badge?p=json5-loader [cson-npm]: https://img.shields.io/npm/v/cson-loader.svg +[cson-size]: https://packagephobia.now.sh/badge?p=cson-loader #### Transpiling -|Name|Status|Description| -|:--:|:----:|:----------| -|`