Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: webpack @ 4.30.0 .. 4.32.2

bin/webpack.js

@@ -109,7 +109,7 @@
)}".`
);
- let question = `Do you want to install 'webpack-cli' (yes/no): `;
+ const question = `Do you want to install 'webpack-cli' (yes/no): `;
const questionInterface = readLine.createInterface({
input: process.stdin,

declarations/WebpackOptions.d.ts

@@ -22,6 +22,8 @@
*/
export type EntryStatic = EntryObject | EntryItem;
/**
+ * A non-empty array of non-empty strings
+ *
* This interface was referenced by `WebpackOptions`'s JSON-Schema
* via the `definition` "NonEmptyArrayOfUniqueStringValues".
*/
@@ -369,7 +371,14 @@
stats?:
| StatsOptions
| boolean
- | ("none" | "errors-only" | "minimal" | "normal" | "detailed" | "verbose");
+ | (
+ | "none"
+ | "errors-only"
+ | "minimal"
+ | "normal"
+ | "detailed"
+ | "verbose"
+ | "errors-warnings");
/**
* Environment to build for
*/
@@ -1054,7 +1063,7 @@
*/
filename?: string | Function;
/**
- * Use the future version of asset emitting logic, which is allows freeing memory of assets after emitting. It could break plugins which assume that assets are still readable after emitting. Will be the new default in the next major version.
+ * Use the future version of asset emitting logic, which allows freeing memory of assets after emitting. It could break plugins which assume that assets are still readable after emitting. Will be the new default in the next major version.
*/
futureEmitAssets?: boolean;
/**

lib/Chunk.js

@@ -688,7 +688,15 @@
};
if (includeDirectChildren) {
- addChildIdsByOrdersToMap(this);
+ const chunks = new Set();
+ for (const chunkGroup of this.groupsIterable) {
+ for (const chunk of chunkGroup.chunks) {
+ chunks.add(chunk);
+ }
+ }
+ for (const chunk of chunks) {
+ addChildIdsByOrdersToMap(chunk);
+ }
}
for (const chunk of this.getAllAsyncChunks()) {

lib/CommonJsStuffPlugin.js

@@ -0,0 +1,114 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const path = require("path");
+const ParserHelpers = require("./ParserHelpers");
+
+class CommonJsStuffPlugin {
+ apply(compiler) {
+ compiler.hooks.compilation.tap(
+ "CommonJsStuffPlugin",
+ (compilation, { normalModuleFactory }) => {
+ const handler = (parser, parserOptions) => {
+ parser.hooks.expression
+ .for("require.main.require")
+ .tap(
+ "CommonJsStuffPlugin",
+ ParserHelpers.expressionIsUnsupported(
+ parser,
+ "require.main.require is not supported by webpack."
+ )
+ );
+ parser.hooks.expression
+ .for("module.parent.require")
+ .tap(
+ "CommonJsStuffPlugin",
+ ParserHelpers.expressionIsUnsupported(
+ parser,
+ "module.parent.require is not supported by webpack."
+ )
+ );
+ parser.hooks.expression
+ .for("require.main")
+ .tap(
+ "CommonJsStuffPlugin",
+ ParserHelpers.toConstantDependencyWithWebpackRequire(
+ parser,
+ "__webpack_require__.c[__webpack_require__.s]"
+ )
+ );
+ parser.hooks.expression
+ .for("module.loaded")
+ .tap("CommonJsStuffPlugin", expr => {
+ parser.state.module.buildMeta.moduleConcatenationBailout =
+ "module.loaded";
+ return ParserHelpers.toConstantDependency(parser, "module.l")(
+ expr
+ );
+ });
+ parser.hooks.expression
+ .for("module.id")
+ .tap("CommonJsStuffPlugin", expr => {
+ parser.state.module.buildMeta.moduleConcatenationBailout =
+ "module.id";
+ return ParserHelpers.toConstantDependency(parser, "module.i")(
+ expr
+ );
+ });
+ parser.hooks.expression
+ .for("module.exports")
+ .tap("CommonJsStuffPlugin", () => {
+ const module = parser.state.module;
+ const isHarmony =
+ module.buildMeta && module.buildMeta.exportsType;
+ if (!isHarmony) return true;
+ });
+ parser.hooks.evaluateIdentifier
+ .for("module.hot")
+ .tap(
+ "CommonJsStuffPlugin",
+ ParserHelpers.evaluateToIdentifier("module.hot", false)
+ );
+ parser.hooks.expression
+ .for("module")
+ .tap("CommonJsStuffPlugin", () => {
+ const module = parser.state.module;
+ const isHarmony =
+ module.buildMeta && module.buildMeta.exportsType;
+ let moduleJsPath = path.join(
+ __dirname,
+ "..",
+ "buildin",
+ isHarmony ? "harmony-module.js" : "module.js"
+ );
+ if (module.context) {
+ moduleJsPath = path.relative(
+ parser.state.module.context,
+ moduleJsPath
+ );
+ if (!/^[A-Z]:/i.test(moduleJsPath)) {
+ moduleJsPath = `./${moduleJsPath.replace(/\\/g, "/")}`;
+ }
+ }
+ return ParserHelpers.addParsedVariableToModule(
+ parser,
+ "module",
+ `require(${JSON.stringify(moduleJsPath)})(module)`
+ );
+ });
+ };
+
+ normalModuleFactory.hooks.parser
+ .for("javascript/auto")
+ .tap("CommonJsStuffPlugin", handler);
+ normalModuleFactory.hooks.parser
+ .for("javascript/dynamic")
+ .tap("CommonJsStuffPlugin", handler);
+ }
+ );
+ }
+}
+module.exports = CommonJsStuffPlugin;

lib/dependencies/HarmonyExportImportedSpecifierDependency.js

@@ -50,6 +50,7 @@
) {
super(request, originModule, sourceOrder, parserScope);
this.id = id;
+ this.redirectedId = undefined;
this.name = name;
this.activeExports = activeExports;
this.otherStarExports = otherStarExports;
@@ -60,9 +61,13 @@
return "harmony export imported specifier";
}
+ get _id() {
+ return this.redirectedId || this.id;
+ }
+
getMode(ignoreUnused) {
const name = this.name;
- const id = this.id;
+ const id = this._id;
const used = this.originModule.isUsed(name);
const importedModule = this._module;
@@ -288,7 +293,7 @@
};
}
- const importedModule = this.module;
+ const importedModule = this._module;
if (!importedModule) {
// no imported module available
@@ -350,11 +355,11 @@
// It's not an harmony module
if (
this.originModule.buildMeta.strictHarmonyModule &&
- this.id !== "default"
+ this._id !== "default"
) {
// In strict harmony modules we only support the default export
- const exportName = this.id
- ? `the named export '${this.id}'`
+ const exportName = this._id
+ ? `the named export '${this._id}'`
: "the namespace object";
return [
new HarmonyLinkingError(
@@ -365,20 +370,20 @@
return;
}
- if (!this.id) {
+ if (!this._id) {
return;
}
- if (importedModule.isProvided(this.id) !== false) {
+ if (importedModule.isProvided(this._id) !== false) {
// It's provided or we are not sure
return;
}
// We are sure that it's not provided
const idIsNotNameMessage =
- this.id !== this.name ? ` (reexported as '${this.name}')` : "";
+ this._id !== this.name ? ` (reexported as '${this.name}')` : "";
const errorMessage = `"export '${
- this.id
+ this._id
}'${idIsNotNameMessage} was not found in '${this.userRequest}'`;
return [new HarmonyLinkingError(errorMessage)];
}
@@ -402,6 +407,11 @@
importedModule.used + stringifiedUsedExport + stringifiedProvidedExport
);
}
+
+ disconnect() {
+ super.disconnect();
+ this.redirectedId = undefined;
+ }
}
module.exports = HarmonyExportImportedSpecifierDependency;

lib/MainTemplate.js

@@ -98,6 +98,8 @@
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
/** @type {SyncWaterfallHook<string, Chunk, string>} */
startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
+ /** @type {SyncWaterfallHook<string, Chunk, string>} */
+ afterStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
render: new SyncWaterfallHook([
"source",
"chunk",
@@ -404,7 +406,20 @@
);
buf.push("");
buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
+ const afterStartupCode = Template.asString(
+ this.hooks.afterStartup.call("", chunk, hash)
+ );
+ if (afterStartupCode) {
+ // TODO webpack 5: this is a bit hacky to avoid a breaking change
+ // change it to a better way
+ buf.push("var startupResult = (function() {");
+ }
buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
+ if (afterStartupCode) {
+ buf.push("})();");
+ buf.push(afterStartupCode);
+ buf.push("return startupResult;");
+ }
return buf;
}

lib/NodeStuffPlugin.js

@@ -58,9 +58,10 @@
});
};
const context = compiler.context;
+ if (localOptions.__filename) {
if (localOptions.__filename === "mock") {
setConstant("__filename", "/index.js");
- } else if (localOptions.__filename) {
+ } else {
setModuleConstant("__filename", module =>
path.relative(context, module.resource)
);
@@ -75,9 +76,11 @@
i < 0 ? resource : resource.substr(0, i)
)(expr);
});
+ }
+ if (localOptions.__dirname) {
if (localOptions.__dirname === "mock") {
setConstant("__dirname", "/");
- } else if (localOptions.__dirname) {
+ } else {
setModuleConstant("__dirname", module =>
path.relative(context, module.context)
);
@@ -90,15 +93,7 @@
parser.state.module.context
)(expr);
});
- parser.hooks.expression
- .for("require.main")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.toConstantDependencyWithWebpackRequire(
- parser,
- "__webpack_require__.c[__webpack_require__.s]"
- )
- );
+ }
parser.hooks.expression
.for("require.extensions")
.tap(
@@ -108,80 +103,6 @@
"require.extensions is not supported by webpack. Use a loader instead."
)
);
- parser.hooks.expression
- .for("require.main.require")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.expressionIsUnsupported(
- parser,
- "require.main.require is not supported by webpack."
- )
- );
- parser.hooks.expression
- .for("module.parent.require")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.expressionIsUnsupported(
- parser,
- "module.parent.require is not supported by webpack."
- )
- );
- parser.hooks.expression
- .for("module.loaded")
- .tap("NodeStuffPlugin", expr => {
- parser.state.module.buildMeta.moduleConcatenationBailout =
- "module.loaded";
- return ParserHelpers.toConstantDependency(parser, "module.l")(
- expr
- );
- });
- parser.hooks.expression
- .for("module.id")
- .tap("NodeStuffPlugin", expr => {
- parser.state.module.buildMeta.moduleConcatenationBailout =
- "module.id";
- return ParserHelpers.toConstantDependency(parser, "module.i")(
- expr
- );
- });
- parser.hooks.expression
- .for("module.exports")
- .tap("NodeStuffPlugin", () => {
- const module = parser.state.module;
- const isHarmony =
- module.buildMeta && module.buildMeta.exportsType;
- if (!isHarmony) return true;
- });
- parser.hooks.evaluateIdentifier
- .for("module.hot")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.evaluateToIdentifier("module.hot", false)
- );
- parser.hooks.expression.for("module").tap("NodeStuffPlugin", () => {
- const module = parser.state.module;
- const isHarmony = module.buildMeta && module.buildMeta.exportsType;
- let moduleJsPath = path.join(
- __dirname,
- "..",
- "buildin",
- isHarmony ? "harmony-module.js" : "module.js"
- );
- if (module.context) {
- moduleJsPath = path.relative(
- parser.state.module.context,
- moduleJsPath
- );
- if (!/^[A-Z]:/i.test(moduleJsPath)) {
- moduleJsPath = `./${moduleJsPath.replace(/\\/g, "/")}`;
- }
- }
- return ParserHelpers.addParsedVariableToModule(
- parser,
- "module",
- `require(${JSON.stringify(moduleJsPath)})(module)`
- );
- });
};
normalModuleFactory.hooks.parser

lib/NoModeWarning.js

@@ -16,7 +16,7 @@
"The 'mode' option has not been set, webpack will fallback to 'production' for this value. " +
"Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\n" +
"You can also set it to 'none' to disable any default behavior. " +
- "Learn more: https://webpack.js.org/concepts/mode/";
+ "Learn more: https://webpack.js.org/configuration/mode/";
Error.captureStackTrace(this, this.constructor);
}

lib/NormalModule.js

@@ -212,6 +212,7 @@
rootContext: options.context,
webpack: true,
sourceMap: !!this.useSourceMap,
+ mode: options.mode || "production",
_module: this,
_compilation: compilation,
_compiler: compilation.compiler,

lib/optimize/ConcatenatedModule.js

@@ -521,7 +521,7 @@
dep instanceof HarmonyExportImportedSpecifierDependency
) {
const exportName = dep.name;
- const importName = dep.id;
+ const importName = dep._id;
const importedModule = dep._module;
if (exportName && importName) {
if (!reexportMap.has(exportName)) {
@@ -1390,12 +1390,12 @@
getExports(dep) {
const importModule = dep._module;
- if (dep.id) {
+ if (dep._id) {
// export { named } from "module"
return [
{
name: dep.name,
- id: dep.id,
+ id: dep._id,
module: importModule
}
];

lib/optimize/SideEffectsFlagPlugin.js

@@ -111,8 +111,9 @@
const reason = module.reasons[i];
const dep = reason.dependency;
if (
- dep instanceof HarmonyImportSpecifierDependency &&
- !dep.namespaceObjectAsContext
+ dep instanceof HarmonyExportImportedSpecifierDependency ||
+ (dep instanceof HarmonyImportSpecifierDependency &&
+ !dep.namespaceObjectAsContext)
) {
const mapping = map.get(dep.id);
if (mapping) {

lib/Parser.js

@@ -1954,6 +1954,9 @@
case "RestElement":
this.enterRestElement(pattern, onIdent);
break;
+ case "Property":
+ this.enterPattern(pattern.value, onIdent);
+ break;
}
}
@@ -1968,7 +1971,7 @@
propIndex++
) {
const prop = pattern.properties[propIndex];
- this.enterPattern(prop.value, onIdent);
+ this.enterPattern(prop, onIdent);
}
}
@@ -2238,6 +2241,8 @@
if (type === "auto") {
parserOptions.sourceType = "module";
+ } else if (parserOptions.sourceType === "script") {
+ parserOptions.allowReturnOutsideFunction = true;
}
let ast;
@@ -2252,6 +2257,7 @@
if (threw && type === "auto") {
parserOptions.sourceType = "script";
+ parserOptions.allowReturnOutsideFunction = true;
if (Array.isArray(parserOptions.onComment)) {
parserOptions.onComment.length = 0;
}

lib/Stats.js

@@ -1408,6 +1408,12 @@
errors: true,
moduleTrace: true
};
+ case "errors-warnings":
+ return {
+ all: false,
+ errors: true,
+ warnings: true
+ };
default:
return {};
}

lib/web/JsonpMainTemplatePlugin.js

@@ -115,7 +115,11 @@
),
"};",
"",
- needEntryDeferringCode(chunk) ? "var deferredModules = [];" : ""
+ needEntryDeferringCode(chunk)
+ ? needPrefetchingCode(chunk)
+ ? "var deferredModules = [], deferredPrefetch = [];"
+ : "var deferredModules = [];"
+ : ""
);
}
if (needChunkOnDemandLoadingCode(chunk)) {
@@ -169,6 +173,8 @@
"}"
])
: "",
+ "// create error before stack unwound to get useful stacktrace later",
+ "var error = new Error();",
"onScriptComplete = function (event) {",
Template.indent([
"// avoid mem leaks in IE.",
@@ -181,7 +187,7 @@
Template.indent([
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
"var realSrc = event && event.target && event.target.src;",
- "var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');",
+ "error.message = 'Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
"error.type = errorType;",
"error.request = realSrc;",
"chunk[1](error);"
@@ -384,7 +390,9 @@
"}",
"if(parentJsonpFunction) parentJsonpFunction(data);",
withPrefetch
- ? Template.asString([
+ ? withDefer
+ ? "deferredPrefetch.push.apply(deferredPrefetch, prefetchChunks);"
+ : Template.asString([
"// chunk prefetching for javascript",
"prefetchChunks.forEach(function(chunkId) {",
Template.indent([
@@ -441,6 +449,31 @@
"}"
]),
"}",
+ withPrefetch
+ ? Template.asString([
+ "if(deferredModules.length === 0) {",
+ Template.indent([
+ "// chunk prefetching for javascript",
+ "deferredPrefetch.forEach(function(chunkId) {",
+ Template.indent([
+ "if(installedChunks[chunkId] === undefined) {",
+ Template.indent([
+ "installedChunks[chunkId] = null;",
+ mainTemplate.hooks.linkPrefetch.call(
+ "",
+ chunk,
+ hash
+ ),
+ "document.head.appendChild(link);"
+ ]),
+ "}"
+ ]),
+ "});",
+ "deferredPrefetch.length = 0;"
+ ]),
+ "}"
+ ])
+ : "",
"return result;"
]),
"}"
@@ -473,7 +506,7 @@
return source;
}
);
- mainTemplate.hooks.beforeStartup.tap(
+ mainTemplate.hooks.afterStartup.tap(
"JsonpMainTemplatePlugin",
(source, chunk, hash) => {
const prefetchChunks = chunk.getChildIdsByOrders().prefetch;

lib/WebpackOptionsApply.js

@@ -21,7 +21,7 @@
const APIPlugin = require("./APIPlugin");
const ConstPlugin = require("./ConstPlugin");
-const NodeStuffPlugin = require("./NodeStuffPlugin");
+const CommonJsStuffPlugin = require("./CommonJsStuffPlugin");
const CompatibilityPlugin = require("./CompatibilityPlugin");
const TemplatedPathPlugin = require("./TemplatedPathPlugin");
@@ -290,7 +290,11 @@
}
new CommonJsPlugin(options.module).apply(compiler);
new LoaderPlugin().apply(compiler);
+ if (options.node !== false) {
+ const NodeStuffPlugin = require("./NodeStuffPlugin");
new NodeStuffPlugin(options.node).apply(compiler);
+ }
+ new CommonJsStuffPlugin().apply(compiler);
new APIPlugin().apply(compiler);
new ConstPlugin().apply(compiler);
new UseStrictPlugin().apply(compiler);

lib/WebpackOptionsValidationError.js

@@ -50,13 +50,34 @@
return "";
};
+const SPECIFICITY = {
+ type: 1,
+ oneOf: 1,
+ anyOf: 1,
+ allOf: 1,
+ additionalProperties: 2,
+ enum: 1,
+ instanceof: 1,
+ required: 2,
+ minimum: 2,
+ uniqueItems: 2,
+ minLength: 2,
+ minItems: 2,
+ minProperties: 2,
+ absolutePath: 2
+};
+
+const filterMax = (array, fn) => {
+ const max = array.reduce((max, item) => Math.max(max, fn(item)), 0);
+ return array.filter(item => fn(item) === max);
+};
+
const filterChildren = children => {
- return children.filter(
- err =>
- err.keyword !== "anyOf" &&
- err.keyword !== "allOf" &&
- err.keyword !== "oneOf"
+ children = filterMax(children, err =>
+ err.dataPath ? err.dataPath.length : 0
);
+ children = filterMax(children, err => SPECIFICITY[err.keyword] || 2);
+ return children;
};
const indent = (str, prefix, firstLine) => {
@@ -154,6 +175,10 @@
return "RegExp";
}
+ if (schema.enum) {
+ return schema.enum.map(item => JSON.stringify(item)).join(" | ");
+ }
+
if (schema.$ref) {
return formatInnerSchema(getSchemaPart(schema.$ref), true);
}
@@ -166,9 +191,6 @@
if (schema.anyOf) {
return schema.anyOf.map(formatInnerSchema).join(" | ");
}
- if (schema.enum) {
- return schema.enum.map(item => JSON.stringify(item)).join(" | ");
- }
return JSON.stringify(schema, null, 2);
}
@@ -229,11 +251,17 @@
})
);
}
+ const children = filterChildren(err.children);
+ if (children.length === 1) {
+ return WebpackOptionsValidationError.formatValidationError(
+ children[0]
+ );
+ }
return (
`${dataPath} should be one of these:\n${getSchemaPartText(
err.parentSchema
)}\n` +
- `Details:\n${filterChildren(err.children)
+ `Details:\n${children
.map(
err =>
" * " +
@@ -312,7 +340,21 @@
err.keyword === "minProperties"
) {
if (err.params.limit === 1) {
- return `${dataPath} should not be empty.${getSchemaPartDescription(
+ switch (err.keyword) {
+ case "minLength":
+ return `${dataPath} should be an non-empty string.${getSchemaPartDescription(
+ err.parentSchema
+ )}`;
+ case "minItems":
+ return `${dataPath} should be an non-empty array.${getSchemaPartDescription(
+ err.parentSchema
+ )}`;
+ case "minProperties":
+ return `${dataPath} should be an non-empty object.${getSchemaPartDescription(
+ err.parentSchema
+ )}`;
+ }
+ return `${dataPath} should be not empty.${getSchemaPartDescription(
err.parentSchema
)}`;
} else {

package.json

@@ -1,6 +1,6 @@
{
"name": "webpack",
- "version": "4.30.0",
+ "version": "4.32.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",

README.md

@@ -90,7 +90,7 @@
### Get Started
-Check out webpack's quick [**Get Started**](https://webpack.js.org/get-started/) guide and the [other guides](https://webpack.js.org/guides/).
+Check out webpack's quick [**Get Started**](https://webpack.js.org/guides/getting-started) guide and the [other guides](https://webpack.js.org/guides/).
### Browser Compatibility

schemas/WebpackOptions.json

@@ -385,6 +385,7 @@
}
},
"NonEmptyArrayOfUniqueStringValues": {
+ "description": "A non-empty array of non-empty strings",
"type": "array",
"items": {
"description": "A non-empty string",
@@ -868,7 +869,7 @@
]
},
"futureEmitAssets": {
- "description": "Use the future version of asset emitting logic, which is allows freeing memory of assets after emitting. It could break plugins which assume that assets are still readable after emitting. Will be the new default in the next major version.",
+ "description": "Use the future version of asset emitting logic, which allows freeing memory of assets after emitting. It could break plugins which assume that assets are still readable after emitting. Will be the new default in the next major version.",
"type": "boolean"
},
"globalObject": {
@@ -2110,7 +2111,8 @@
"minimal",
"normal",
"detailed",
- "verbose"
+ "verbose",
+ "errors-warnings"
]
}
]