webpack 5.75.0 → 5.76.0

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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

package/README.md CHANGED
@@ -158,11 +158,11 @@ or are automatically applied via regex from your webpack configuration.
158
158
 
159
159
  #### Transpiling
160
160
 
161
- | Name | Status | Install Size | Description |
162
- | :--------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
163
- | <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
164
- | <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
165
- | <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
161
+ | Name | Status | Install Size | Description |
162
+ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
163
+ | <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
164
+ | <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://raw.githubusercontent.com/microsoft/TypeScript-Website/f407e1ae19e5e990d9901ac8064a32a8cc60edf0/packages/typescriptlang-org/static/branding/ts-logo-128.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
165
+ | <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
166
166
 
167
167
  [babel-npm]: https://img.shields.io/npm/v/babel-loader.svg
168
168
  [babel-size]: https://packagephobia.com/badge?p=babel-loader
@@ -175,7 +175,7 @@ or are automatically applied via regex from your webpack configuration.
175
175
 
176
176
  | Name | Status | Install Size | Description |
177
177
  | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
178
- | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
178
+ | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5-2.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
179
179
  | <a href="https://github.com/pugjs/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug-npm] | ![pug-size] | Loads Pug templates and returns a function |
180
180
  | <a href="https://github.com/webdiscus/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug3-npm] | ![pug3-size] | Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular |
181
181
  | <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
package/bin/webpack.js CHANGED
File without changes
@@ -330,6 +330,8 @@ class NormalModule extends Module {
330
330
  this._isEvaluatingSideEffects = false;
331
331
  /** @type {WeakSet<ModuleGraph> | undefined} */
332
332
  this._addedSideEffectsBailout = undefined;
333
+ /** @type {Map<string, any>} */
334
+ this._codeGeneratorData = new Map();
333
335
  }
334
336
 
335
337
  /**
@@ -1188,11 +1190,9 @@ class NormalModule extends Module {
1188
1190
  runtimeRequirements.add(RuntimeGlobals.thisAsExports);
1189
1191
  }
1190
1192
 
1191
- /** @type {Map<string, any>} */
1192
- let data;
1193
+ /** @type {function(): Map<string, any>} */
1193
1194
  const getData = () => {
1194
- if (data === undefined) data = new Map();
1195
- return data;
1195
+ return this._codeGeneratorData;
1196
1196
  };
1197
1197
 
1198
1198
  const sources = new Map();
@@ -1223,7 +1223,7 @@ class NormalModule extends Module {
1223
1223
  const resultEntry = {
1224
1224
  sources,
1225
1225
  runtimeRequirements,
1226
- data
1226
+ data: this._codeGeneratorData
1227
1227
  };
1228
1228
  return resultEntry;
1229
1229
  }
@@ -1371,6 +1371,7 @@ class NormalModule extends Module {
1371
1371
  write(this.error);
1372
1372
  write(this._lastSuccessfulBuildMeta);
1373
1373
  write(this._forceBuild);
1374
+ write(this._codeGeneratorData);
1374
1375
  super.serialize(context);
1375
1376
  }
1376
1377
 
@@ -1403,6 +1404,7 @@ class NormalModule extends Module {
1403
1404
  this.error = read();
1404
1405
  this._lastSuccessfulBuildMeta = read();
1405
1406
  this._forceBuild = read();
1407
+ this._codeGeneratorData = read();
1406
1408
  super.deserialize(context);
1407
1409
  }
1408
1410
  }
@@ -137,7 +137,7 @@ class ImportParserPlugin {
137
137
  if (importOptions.webpackInclude !== undefined) {
138
138
  if (
139
139
  !importOptions.webpackInclude ||
140
- importOptions.webpackInclude.constructor.name !== "RegExp"
140
+ !(importOptions.webpackInclude instanceof RegExp)
141
141
  ) {
142
142
  parser.state.module.addWarning(
143
143
  new UnsupportedFeatureWarning(
@@ -146,13 +146,13 @@ class ImportParserPlugin {
146
146
  )
147
147
  );
148
148
  } else {
149
- include = new RegExp(importOptions.webpackInclude);
149
+ include = importOptions.webpackInclude;
150
150
  }
151
151
  }
152
152
  if (importOptions.webpackExclude !== undefined) {
153
153
  if (
154
154
  !importOptions.webpackExclude ||
155
- importOptions.webpackExclude.constructor.name !== "RegExp"
155
+ !(importOptions.webpackExclude instanceof RegExp)
156
156
  ) {
157
157
  parser.state.module.addWarning(
158
158
  new UnsupportedFeatureWarning(
@@ -161,7 +161,7 @@ class ImportParserPlugin {
161
161
  )
162
162
  );
163
163
  } else {
164
- exclude = new RegExp(importOptions.webpackExclude);
164
+ exclude = importOptions.webpackExclude;
165
165
  }
166
166
  }
167
167
  if (importOptions.webpackExports !== undefined) {
@@ -3635,17 +3635,27 @@ class JavascriptParser extends Parser {
3635
3635
  return EMPTY_COMMENT_OPTIONS;
3636
3636
  }
3637
3637
  let options = {};
3638
+ /** @type {unknown[]} */
3638
3639
  let errors = [];
3639
3640
  for (const comment of comments) {
3640
3641
  const { value } = comment;
3641
3642
  if (value && webpackCommentRegExp.test(value)) {
3642
3643
  // try compile only if webpack options comment is present
3643
3644
  try {
3644
- const val = vm.runInNewContext(`(function(){return {${value}};})()`);
3645
- Object.assign(options, val);
3645
+ for (let [key, val] of Object.entries(
3646
+ vm.runInNewContext(`(function(){return {${value}};})()`)
3647
+ )) {
3648
+ if (typeof val === "object" && val !== null) {
3649
+ if (val.constructor.name === "RegExp") val = new RegExp(val);
3650
+ else val = JSON.parse(JSON.stringify(val));
3651
+ }
3652
+ options[key] = val;
3653
+ }
3646
3654
  } catch (e) {
3647
- e.comment = comment;
3648
- errors.push(e);
3655
+ const newErr = new Error(String(e.message));
3656
+ newErr.stack = String(e.stack);
3657
+ Object.assign(newErr, { comment });
3658
+ errors.push(newErr);
3649
3659
  }
3650
3660
  }
3651
3661
  }
@@ -178,10 +178,43 @@ class RealContentHashPlugin {
178
178
  }
179
179
  }
180
180
  if (hashToAssets.size === 0) return;
181
- const hashRegExp = new RegExp(
182
- Array.from(hashToAssets.keys(), quoteMeta).join("|"),
183
- "g"
181
+ const hashRegExps = Array.from(hashToAssets.keys(), quoteMeta).map(
182
+ hash => new RegExp(hash, "g")
184
183
  );
184
+
185
+ /**
186
+ * @param {string} str string to be matched against all hashRegExps
187
+ * @returns {string[] | null} matches found
188
+ */
189
+ const hashMatch = str => {
190
+ /** @type {string[]} */
191
+ const results = [];
192
+ for (const hashRegExp of hashRegExps) {
193
+ const matches = str.match(hashRegExp);
194
+ if (matches) {
195
+ matches.forEach(match => results.push(match));
196
+ }
197
+ }
198
+ if (results.length) {
199
+ return results;
200
+ } else {
201
+ return null;
202
+ }
203
+ };
204
+
205
+ /**
206
+ * @param {string} str string to be replaced with all hashRegExps
207
+ * @param {function(string): string} fn replacement function to use when a hash is found
208
+ * @returns {string} replaced content
209
+ */
210
+ const hashReplace = (str, fn) => {
211
+ let result = str;
212
+ for (const hashRegExp of hashRegExps) {
213
+ result = result.replace(hashRegExp, fn);
214
+ }
215
+ return result;
216
+ };
217
+
185
218
  await Promise.all(
186
219
  assetsWithInfo.map(async asset => {
187
220
  const { name, source, content, hashes } = asset;
@@ -198,7 +231,7 @@ class RealContentHashPlugin {
198
231
  await cacheAnalyse.providePromise(name, etag, () => {
199
232
  const referencedHashes = new Set();
200
233
  let ownHashes = new Set();
201
- const inContent = content.match(hashRegExp);
234
+ const inContent = hashMatch(content);
202
235
  if (inContent) {
203
236
  for (const hash of inContent) {
204
237
  if (hashes.has(hash)) {
@@ -298,7 +331,7 @@ ${referencingAssets
298
331
  identifier,
299
332
  etag,
300
333
  () => {
301
- const newContent = asset.content.replace(hashRegExp, hash =>
334
+ const newContent = hashReplace(asset.content, hash =>
302
335
  hashToNewHash.get(hash)
303
336
  );
304
337
  return new RawSource(newContent);
@@ -323,15 +356,12 @@ ${referencingAssets
323
356
  identifier,
324
357
  etag,
325
358
  () => {
326
- const newContent = asset.content.replace(
327
- hashRegExp,
328
- hash => {
329
- if (asset.ownHashes.has(hash)) {
330
- return "";
331
- }
332
- return hashToNewHash.get(hash);
359
+ const newContent = hashReplace(asset.content, hash => {
360
+ if (asset.ownHashes.has(hash)) {
361
+ return "";
333
362
  }
334
- );
363
+ return hashToNewHash.get(hash);
364
+ });
335
365
  return new RawSource(newContent);
336
366
  }
337
367
  );
@@ -342,7 +372,6 @@ ${referencingAssets
342
372
  for (const oldHash of hashesInOrder) {
343
373
  const assets = hashToAssets.get(oldHash);
344
374
  assets.sort(comparator);
345
- const hash = createHash(this._hashFunction);
346
375
  await Promise.all(
347
376
  assets.map(asset =>
348
377
  asset.ownHashes.has(oldHash)
@@ -363,6 +392,7 @@ ${referencingAssets
363
392
  });
364
393
  let newHash = hooks.updateHash.call(assetsContent, oldHash);
365
394
  if (!newHash) {
395
+ const hash = createHash(this._hashFunction);
366
396
  for (const content of assetsContent) {
367
397
  hash.update(content);
368
398
  }
@@ -374,7 +404,7 @@ ${referencingAssets
374
404
  await Promise.all(
375
405
  assetsWithInfo.map(async asset => {
376
406
  await computeNewContent(asset);
377
- const newName = asset.name.replace(hashRegExp, hash =>
407
+ const newName = hashReplace(asset.name, hash =>
378
408
  hashToNewHash.get(hash)
379
409
  );
380
410
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.75.0",
3
+ "version": "5.76.0",
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",
@@ -76,7 +76,7 @@
76
76
  "less": "^4.0.0",
77
77
  "less-loader": "^8.0.0",
78
78
  "lint-staged": "^11.0.0",
79
- "loader-utils": "^2.0.0",
79
+ "loader-utils": "^2.0.3",
80
80
  "lodash": "^4.17.19",
81
81
  "lodash-es": "^4.17.15",
82
82
  "memfs": "^3.2.0",
package/types.d.ts CHANGED
@@ -6595,6 +6595,12 @@ declare interface LoaderRunnerLoaderContext<OptionsType> {
6595
6595
  * Example: "/abc/resource.js?query#frag"
6596
6596
  */
6597
6597
  resource: string;
6598
+
6599
+ /**
6600
+ * Target of compilation.
6601
+ * Example: "web"
6602
+ */
6603
+ target: string;
6598
6604
  }
6599
6605
  declare class LoaderTargetPlugin {
6600
6606
  constructor(target: string);