webpack 4.40.0 → 4.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,11 +37,11 @@ const compareLocations = require("./compareLocations");
37
37
  const { Logger, LogType } = require("./logging/Logger");
38
38
  const ErrorHelpers = require("./ErrorHelpers");
39
39
  const buildChunkGraph = require("./buildChunkGraph");
40
+ const WebpackError = require("./WebpackError");
40
41
 
41
42
  /** @typedef {import("./Module")} Module */
42
43
  /** @typedef {import("./Compiler")} Compiler */
43
44
  /** @typedef {import("webpack-sources").Source} Source */
44
- /** @typedef {import("./WebpackError")} WebpackError */
45
45
  /** @typedef {import("./DependenciesBlockVariable")} DependenciesBlockVariable */
46
46
  /** @typedef {import("./dependencies/SingleEntryDependency")} SingleEntryDependency */
47
47
  /** @typedef {import("./dependencies/MultiEntryDependency")} MultiEntryDependency */
@@ -221,6 +221,25 @@ const addAllToSet = (set, otherSet) => {
221
221
  }
222
222
  };
223
223
 
224
+ /**
225
+ * @param {Source} a a source
226
+ * @param {Source} b another source
227
+ * @returns {boolean} true, when both sources are equal
228
+ */
229
+ const isSourceEqual = (a, b) => {
230
+ if (a === b) return true;
231
+ // TODO webpack 5: check .buffer() instead, it's called anyway during emit
232
+ /** @type {Buffer|string} */
233
+ let aSource = a.source();
234
+ /** @type {Buffer|string} */
235
+ let bSource = b.source();
236
+ if (aSource === bSource) return true;
237
+ if (typeof aSource === "string" && typeof bSource === "string") return false;
238
+ if (!Buffer.isBuffer(aSource)) aSource = Buffer.from(aSource, "utf-8");
239
+ if (!Buffer.isBuffer(bSource)) bSource = Buffer.from(bSource, "utf-8");
240
+ return aSource.equals(bSource);
241
+ };
242
+
224
243
  class Compilation extends Tapable {
225
244
  /**
226
245
  * Creates an instance of Compilation.
@@ -1990,10 +2009,16 @@ class Compilation extends Tapable {
1990
2009
  */
1991
2010
  emitAsset(file, source, assetInfo = {}) {
1992
2011
  if (this.assets[file]) {
1993
- if (this.assets[file] !== source) {
1994
- throw new Error(
1995
- `Conflict: Multiple assets emit to the same filename ${file}`
2012
+ if (!isSourceEqual(this.assets[file], source)) {
2013
+ // TODO webpack 5: make this an error instead
2014
+ this.warnings.push(
2015
+ new WebpackError(
2016
+ `Conflict: Multiple assets emit different content to the same filename ${file}`
2017
+ )
1996
2018
  );
2019
+ this.assets[file] = source;
2020
+ this.assetsInfo.set(file, assetInfo);
2021
+ return;
1997
2022
  }
1998
2023
  const oldInfo = this.assetsInfo.get(file);
1999
2024
  this.assetsInfo.set(file, Object.assign({}, oldInfo, assetInfo));
@@ -40,6 +40,7 @@ module.exports = class SizeLimitsPlugin {
40
40
  entrypoint.getFiles().reduce((currentSize, file) => {
41
41
  const asset = compilation.getAsset(file);
42
42
  if (
43
+ asset &&
43
44
  assetFilter(asset.name, asset.source, asset.info) &&
44
45
  asset.source
45
46
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.40.0",
3
+ "version": "4.40.1",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "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.",
6
6
  "license": "MIT",