webpack 5.76.0 → 5.76.3

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/bin/webpack.js CHANGED
@@ -53,6 +53,19 @@ const isInstalled = packageName => {
53
53
  }
54
54
  } while (dir !== (dir = path.dirname(dir)));
55
55
 
56
+ // https://github.com/nodejs/node/blob/v18.9.1/lib/internal/modules/cjs/loader.js#L1274
57
+ // eslint-disable-next-line no-warning-comments
58
+ // @ts-ignore
59
+ for (const internalPath of require("module").globalPaths) {
60
+ try {
61
+ if (fs.statSync(path.join(internalPath, packageName)).isDirectory()) {
62
+ return true;
63
+ }
64
+ } catch (_error) {
65
+ // Nothing
66
+ }
67
+ }
68
+
56
69
  return false;
57
70
  };
58
71
 
@@ -162,6 +162,7 @@ ModuleFilenameHelpers.createFilename = (
162
162
  resource: resource,
163
163
  resourcePath: memoize(resourcePath),
164
164
  absoluteResourcePath: memoize(absoluteResourcePath),
165
+ loaders: memoize(loaders),
165
166
  allLoaders: memoize(allLoaders),
166
167
  query: memoize(query),
167
168
  moduleId: memoize(moduleId),
@@ -128,6 +128,9 @@ class ModuleGraph {
128
128
 
129
129
  /** @type {Map<Module, WeakTupleMap<any, any>>} */
130
130
  this._moduleMemCaches = undefined;
131
+
132
+ /** @type {string} */
133
+ this._cacheStage = undefined;
131
134
  }
132
135
 
133
136
  /**
@@ -841,10 +841,10 @@ class NormalModuleFactory extends ModuleFactory {
841
841
  (err2, hints) => {
842
842
  if (err2) {
843
843
  err.message += `
844
- An fatal error happened during resolving additional hints for this error: ${err2.message}`;
844
+ A fatal error happened during resolving additional hints for this error: ${err2.message}`;
845
845
  err.stack += `
846
846
 
847
- An fatal error happened during resolving additional hints for this error:
847
+ A fatal error happened during resolving additional hints for this error:
848
848
  ${err2.stack}`;
849
849
  return callback(err);
850
850
  }
@@ -47,13 +47,32 @@ const validate = createSchemaValidation(
47
47
  * @property {ItemCacheFacade} cacheItem cache item
48
48
  */
49
49
 
50
+ const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g;
51
+ const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(:\w+)?\]/;
52
+ const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i;
53
+ const CSS_EXTENSION_DETECT_REGEXP = /\.css($|\?)/i;
54
+ const MAP_URL_COMMENT_REGEXP = /\[map\]/g;
55
+ const URL_COMMENT_REGEXP = /\[url\]/g;
56
+ const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/;
57
+
58
+ /**
59
+ * Reset's .lastIndex of stateful Regular Expressions
60
+ * For when `test` or `exec` is called on them
61
+ * @param {RegExp} regexp Stateful Regular Expression to be reset
62
+ * @returns {void}
63
+ *
64
+ */
65
+ const resetRegexpState = regexp => {
66
+ regexp.lastIndex = -1;
67
+ };
68
+
50
69
  /**
51
70
  * Escapes regular expression metacharacters
52
71
  * @param {string} str String to quote
53
72
  * @returns {string} Escaped string
54
73
  */
55
74
  const quoteMeta = str => {
56
- return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
75
+ return str.replace(METACHARACTERS_REGEXP, "\\$&");
57
76
  };
58
77
 
59
78
  /**
@@ -152,7 +171,7 @@ class SourceMapDevToolPlugin {
152
171
  const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
153
172
  const requestShortener = compiler.requestShortener;
154
173
  const options = this.options;
155
- options.test = options.test || /\.((c|m)?js|css)($|\?)/i;
174
+ options.test = options.test || CSS_AND_JS_MODULE_EXTENSIONS_REGEXP;
156
175
 
157
176
  const matchObject = ModuleFilenameHelpers.matchObject.bind(
158
177
  undefined,
@@ -409,7 +428,9 @@ class SourceMapDevToolPlugin {
409
428
  sourceMap.file = file;
410
429
  const usesContentHash =
411
430
  sourceMapFilename &&
412
- /\[contenthash(:\w+)?\]/.test(sourceMapFilename);
431
+ CONTENT_HASH_DETECT_REGEXP.test(sourceMapFilename);
432
+
433
+ resetRegexpState(CONTENT_HASH_DETECT_REGEXP);
413
434
 
414
435
  // If SourceMap and asset uses contenthash, avoid a circular dependency by hiding hash in `file`
415
436
  if (usesContentHash && task.assetInfo.contenthash) {
@@ -428,13 +449,16 @@ class SourceMapDevToolPlugin {
428
449
 
429
450
  /** @type {string | false} */
430
451
  let currentSourceMappingURLComment = sourceMappingURLComment;
452
+ let cssExtensionDetected =
453
+ CSS_EXTENSION_DETECT_REGEXP.test(file);
454
+ resetRegexpState(CSS_EXTENSION_DETECT_REGEXP);
431
455
  if (
432
456
  currentSourceMappingURLComment !== false &&
433
- /\.css($|\?)/i.test(file)
457
+ cssExtensionDetected
434
458
  ) {
435
459
  currentSourceMappingURLComment =
436
460
  currentSourceMappingURLComment.replace(
437
- /^\n\/\/(.*)$/,
461
+ URL_FORMATTING_REGEXP,
438
462
  "\n/*$1*/"
439
463
  );
440
464
  }
@@ -516,9 +540,9 @@ class SourceMapDevToolPlugin {
516
540
  const asset = new ConcatSource(
517
541
  new RawSource(source),
518
542
  currentSourceMappingURLComment
519
- .replace(/\[map\]/g, () => sourceMapString)
543
+ .replace(MAP_URL_COMMENT_REGEXP, () => sourceMapString)
520
544
  .replace(
521
- /\[url\]/g,
545
+ URL_COMMENT_REGEXP,
522
546
  () =>
523
547
  `data:application/json;charset=utf-8;base64,${Buffer.from(
524
548
  sourceMapString,
@@ -64,7 +64,9 @@ class ContainerPlugin {
64
64
  const { name, exposes, shareScope, filename, library, runtime } =
65
65
  this._options;
66
66
 
67
- compiler.options.output.enabledLibraryTypes.push(library.type);
67
+ if (!compiler.options.output.enabledLibraryTypes.includes(library.type)) {
68
+ compiler.options.output.enabledLibraryTypes.push(library.type);
69
+ }
68
70
 
69
71
  compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
70
72
  const dep = new ContainerEntryDependency(name, exposes, shareScope);
@@ -11,6 +11,7 @@ const HotUpdateChunk = require("../HotUpdateChunk");
11
11
  const Template = require("../Template");
12
12
  const { getAllChunks } = require("../javascript/ChunkHelpers");
13
13
  const {
14
+ chunkHasJs,
14
15
  getCompilationHooks,
15
16
  getChunkFilenameTemplate
16
17
  } = require("../javascript/JavascriptModulesPlugin");
@@ -147,7 +148,11 @@ class ModuleChunkFormatPlugin {
147
148
  undefined
148
149
  );
149
150
  for (const chunk of chunks) {
150
- if (loadedChunks.has(chunk)) continue;
151
+ if (
152
+ loadedChunks.has(chunk) ||
153
+ !chunkHasJs(chunk, chunkGraph)
154
+ )
155
+ continue;
151
156
  loadedChunks.add(chunk);
152
157
  startupSource.add(
153
158
  `import * as __webpack_chunk_${index}__ from ${JSON.stringify(
@@ -11,6 +11,7 @@ const ExternalsPlugin = require("../ExternalsPlugin");
11
11
 
12
12
  const builtins = [
13
13
  "assert",
14
+ "assert/strict",
14
15
  "async_hooks",
15
16
  "buffer",
16
17
  "child_process",
@@ -30,6 +31,7 @@ const builtins = [
30
31
  "http2",
31
32
  "https",
32
33
  "inspector",
34
+ "inspector/promises",
33
35
  "module",
34
36
  "net",
35
37
  "os",
@@ -41,8 +43,10 @@ const builtins = [
41
43
  "punycode",
42
44
  "querystring",
43
45
  "readline",
46
+ "readline/promises",
44
47
  "repl",
45
48
  "stream",
49
+ "stream/consumers",
46
50
  "stream/promises",
47
51
  "stream/web",
48
52
  "string_decoder",
@@ -38,10 +38,8 @@ module.exports = ({ colors, appendOnly, stream }) => {
38
38
 
39
39
  const writeStatusMessage = () => {
40
40
  if (!currentStatusMessage) return;
41
- const l = stream.columns;
42
- const args = l
43
- ? truncateArgs(currentStatusMessage, l - 1)
44
- : currentStatusMessage;
41
+ const l = stream.columns || 40;
42
+ const args = truncateArgs(currentStatusMessage, l - 1);
45
43
  const str = args.join(" ");
46
44
  const coloredStr = `\u001b[1m${str}\u001b[39m\u001b[22m`;
47
45
  stream.write(`\x1b[2K\r${coloredStr}`);
@@ -178,43 +178,10 @@ class RealContentHashPlugin {
178
178
  }
179
179
  }
180
180
  if (hashToAssets.size === 0) return;
181
- const hashRegExps = Array.from(hashToAssets.keys(), quoteMeta).map(
182
- hash => new RegExp(hash, "g")
181
+ const hashRegExp = new RegExp(
182
+ Array.from(hashToAssets.keys(), quoteMeta).join("|"),
183
+ "g"
183
184
  );
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
-
218
185
  await Promise.all(
219
186
  assetsWithInfo.map(async asset => {
220
187
  const { name, source, content, hashes } = asset;
@@ -231,7 +198,7 @@ class RealContentHashPlugin {
231
198
  await cacheAnalyse.providePromise(name, etag, () => {
232
199
  const referencedHashes = new Set();
233
200
  let ownHashes = new Set();
234
- const inContent = hashMatch(content);
201
+ const inContent = content.match(hashRegExp);
235
202
  if (inContent) {
236
203
  for (const hash of inContent) {
237
204
  if (hashes.has(hash)) {
@@ -331,7 +298,7 @@ ${referencingAssets
331
298
  identifier,
332
299
  etag,
333
300
  () => {
334
- const newContent = hashReplace(asset.content, hash =>
301
+ const newContent = asset.content.replace(hashRegExp, hash =>
335
302
  hashToNewHash.get(hash)
336
303
  );
337
304
  return new RawSource(newContent);
@@ -356,12 +323,15 @@ ${referencingAssets
356
323
  identifier,
357
324
  etag,
358
325
  () => {
359
- const newContent = hashReplace(asset.content, hash => {
360
- if (asset.ownHashes.has(hash)) {
361
- return "";
326
+ const newContent = asset.content.replace(
327
+ hashRegExp,
328
+ hash => {
329
+ if (asset.ownHashes.has(hash)) {
330
+ return "";
331
+ }
332
+ return hashToNewHash.get(hash);
362
333
  }
363
- return hashToNewHash.get(hash);
364
- });
334
+ );
365
335
  return new RawSource(newContent);
366
336
  }
367
337
  );
@@ -393,6 +363,9 @@ ${referencingAssets
393
363
  let newHash = hooks.updateHash.call(assetsContent, oldHash);
394
364
  if (!newHash) {
395
365
  const hash = createHash(this._hashFunction);
366
+ if (compilation.outputOptions.hashSalt) {
367
+ hash.update(compilation.outputOptions.hashSalt);
368
+ }
396
369
  for (const content of assetsContent) {
397
370
  hash.update(content);
398
371
  }
@@ -404,7 +377,7 @@ ${referencingAssets
404
377
  await Promise.all(
405
378
  assetsWithInfo.map(async asset => {
406
379
  await computeNewContent(asset);
407
- const newName = hashReplace(asset.name, hash =>
380
+ const newName = asset.name.replace(hashRegExp, hash =>
408
381
  hashToNewHash.get(hash)
409
382
  );
410
383
 
@@ -43,7 +43,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
43
43
  "if (!scriptUrl && document) {",
44
44
  Template.indent([
45
45
  `if (document.currentScript)`,
46
- Template.indent(`scriptUrl = document.currentScript.src`),
46
+ Template.indent(`scriptUrl = document.currentScript.src;`),
47
47
  "if (!scriptUrl) {",
48
48
  Template.indent([
49
49
  'var scripts = document.getElementsByTagName("script");',
@@ -146,8 +146,7 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
146
146
  )});`,
147
147
  "if(prev) return prev(event);"
148
148
  ])
149
- ) +
150
- ";",
149
+ ),
151
150
  `var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
152
151
  "script.onerror = onScriptComplete.bind(null, script.onerror);",
153
152
  "script.onload = onScriptComplete.bind(null, script.onload);",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.76.0",
3
+ "version": "5.76.3",
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",
package/types.d.ts CHANGED
@@ -9358,6 +9358,15 @@ declare class RawSource extends Source {
9358
9358
  constructor(source: string | Buffer, convertToString?: boolean);
9359
9359
  isBuffer(): boolean;
9360
9360
  }
9361
+ declare interface RawSourceMap {
9362
+ version: number;
9363
+ sources: string[];
9364
+ names: string[];
9365
+ sourceRoot?: string;
9366
+ sourcesContent?: string[];
9367
+ mappings: string;
9368
+ file: string;
9369
+ }
9361
9370
  declare class ReadFileCompileWasmPlugin {
9362
9371
  constructor(options?: any);
9363
9372
  options: any;
@@ -11104,7 +11113,7 @@ declare abstract class SortableSet<T> extends Set<T> {
11104
11113
  declare class Source {
11105
11114
  constructor();
11106
11115
  size(): number;
11107
- map(options?: MapOptions): Object;
11116
+ map(options?: MapOptions): null | RawSourceMap;
11108
11117
  sourceAndMap(options?: MapOptions): { source: string | Buffer; map: Object };
11109
11118
  updateHash(hash: Hash): void;
11110
11119
  source(): string | Buffer;