webpack 5.76.2 → 5.77.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/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),
@@ -85,6 +85,7 @@ const EMPTY_GENERATOR_OPTIONS = {};
85
85
  const EMPTY_ELEMENTS = [];
86
86
 
87
87
  const MATCH_RESOURCE_REGEX = /^([^!]+)!=!/;
88
+ const LEADING_DOT_EXTENSION_REGEX = /^[^.]/;
88
89
 
89
90
  const loaderToIdent = data => {
90
91
  if (!data.options) {
@@ -841,10 +842,10 @@ class NormalModuleFactory extends ModuleFactory {
841
842
  (err2, hints) => {
842
843
  if (err2) {
843
844
  err.message += `
844
- An fatal error happened during resolving additional hints for this error: ${err2.message}`;
845
+ A fatal error happened during resolving additional hints for this error: ${err2.message}`;
845
846
  err.stack += `
846
847
 
847
- An fatal error happened during resolving additional hints for this error:
848
+ A fatal error happened during resolving additional hints for this error:
848
849
  ${err2.stack}`;
849
850
  return callback(err);
850
851
  }
@@ -852,6 +853,25 @@ ${err2.stack}`;
852
853
  err.message += `
853
854
  ${hints.join("\n\n")}`;
854
855
  }
856
+
857
+ // Check if the extension is missing a leading dot (e.g. "js" instead of ".js")
858
+ let appendResolveExtensionsHint = false;
859
+ const specifiedExtensions = Array.from(
860
+ resolver.options.extensions
861
+ );
862
+ const expectedExtensions = specifiedExtensions.map(extension => {
863
+ if (LEADING_DOT_EXTENSION_REGEX.test(extension)) {
864
+ appendResolveExtensionsHint = true;
865
+ return `.${extension}`;
866
+ }
867
+ return extension;
868
+ });
869
+ if (appendResolveExtensionsHint) {
870
+ err.message += `\nDid you miss the leading dot in 'resolve.extensions'? Did you mean '${JSON.stringify(
871
+ expectedExtensions
872
+ )}' instead of '${JSON.stringify(specifiedExtensions)}'?`;
873
+ }
874
+
855
875
  callback(err);
856
876
  }
857
877
  );
@@ -391,7 +391,8 @@ class WebpackOptionsApply extends OptionsApply {
391
391
  new WorkerPlugin(
392
392
  options.output.workerChunkLoading,
393
393
  options.output.workerWasmLoading,
394
- options.output.module
394
+ options.output.module,
395
+ options.output.workerPublicPath
395
396
  ).apply(compiler);
396
397
 
397
398
  new DefaultStatsFactoryPlugin().apply(compiler);
@@ -916,6 +916,7 @@ const applyOutputDefaults = (
916
916
  ? "auto"
917
917
  : ""
918
918
  );
919
+ D(output, "workerPublicPath", "");
919
920
  D(output, "chunkLoadTimeout", 120000);
920
921
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
921
922
  D(output, "hashDigest", "hex");
@@ -369,6 +369,7 @@ const getNormalizedWebpackOptions = config => {
369
369
  uniqueName: output.uniqueName,
370
370
  wasmLoading: output.wasmLoading,
371
371
  webassemblyModuleFilename: output.webassemblyModuleFilename,
372
+ workerPublicPath: output.workerPublicPath,
372
373
  workerChunkLoading: output.workerChunkLoading,
373
374
  workerWasmLoading: output.workerWasmLoading
374
375
  };
@@ -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);
@@ -25,10 +25,16 @@ class WorkerDependency extends ModuleDependency {
25
25
  /**
26
26
  * @param {string} request request
27
27
  * @param {[number, number]} range range
28
+ * @param {Object} workerDependencyOptions options
29
+ * @param {string} workerDependencyOptions.publicPath public path for the worker
28
30
  */
29
- constructor(request, range) {
31
+ constructor(request, range, workerDependencyOptions) {
30
32
  super(request);
31
33
  this.range = range;
34
+ // If options are updated, don't forget to update the hash and serialization functions
35
+ this.options = workerDependencyOptions;
36
+ /** Cache the hash */
37
+ this._hashUpdate = undefined;
32
38
  }
33
39
 
34
40
  /**
@@ -48,6 +54,31 @@ class WorkerDependency extends ModuleDependency {
48
54
  get category() {
49
55
  return "worker";
50
56
  }
57
+
58
+ /**
59
+ * Update the hash
60
+ * @param {Hash} hash hash to be updated
61
+ * @param {UpdateHashContext} context context
62
+ * @returns {void}
63
+ */
64
+ updateHash(hash, context) {
65
+ if (this._hashUpdate === undefined) {
66
+ this._hashUpdate = JSON.stringify(this.options);
67
+ }
68
+ hash.update(this._hashUpdate);
69
+ }
70
+
71
+ serialize(context) {
72
+ const { write } = context;
73
+ write(this.options);
74
+ super.serialize(context);
75
+ }
76
+
77
+ deserialize(context) {
78
+ const { read } = context;
79
+ this.options = read();
80
+ super.deserialize(context);
81
+ }
51
82
  }
52
83
 
53
84
  WorkerDependency.Template = class WorkerDependencyTemplate extends (
@@ -69,6 +100,10 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
69
100
  chunkGraph.getBlockChunkGroup(block)
70
101
  );
71
102
  const chunk = entrypoint.getEntrypointChunk();
103
+ // We use the workerPublicPath option if provided, else we fallback to the RuntimeGlobal publicPath
104
+ const workerImportBaseUrl = dep.options.publicPath
105
+ ? `"${dep.options.publicPath}"`
106
+ : RuntimeGlobals.publicPath;
72
107
 
73
108
  runtimeRequirements.add(RuntimeGlobals.publicPath);
74
109
  runtimeRequirements.add(RuntimeGlobals.baseURI);
@@ -77,7 +112,7 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
77
112
  source.replace(
78
113
  dep.range[0],
79
114
  dep.range[1] - 1,
80
- `/* worker import */ ${RuntimeGlobals.publicPath} + ${
115
+ `/* worker import */ ${workerImportBaseUrl} + ${
81
116
  RuntimeGlobals.getChunkScriptFilename
82
117
  }(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`
83
118
  );
@@ -48,10 +48,11 @@ const DEFAULT_SYNTAX = [
48
48
  const workerIndexMap = new WeakMap();
49
49
 
50
50
  class WorkerPlugin {
51
- constructor(chunkLoading, wasmLoading, module) {
51
+ constructor(chunkLoading, wasmLoading, module, workerPublicPath) {
52
52
  this._chunkLoading = chunkLoading;
53
53
  this._wasmLoading = wasmLoading;
54
54
  this._module = module;
55
+ this._workerPublicPath = workerPublicPath;
55
56
  }
56
57
  /**
57
58
  * Apply the plugin
@@ -298,7 +299,9 @@ class WorkerPlugin {
298
299
  }
299
300
  });
300
301
  block.loc = expr.loc;
301
- const dep = new WorkerDependency(url.string, range);
302
+ const dep = new WorkerDependency(url.string, range, {
303
+ publicPath: this._workerPublicPath
304
+ });
302
305
  dep.loc = expr.loc;
303
306
  block.addDependency(dep);
304
307
  parser.state.module.addBlock(block);
@@ -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(
@@ -31,6 +31,7 @@ const builtins = [
31
31
  "http2",
32
32
  "https",
33
33
  "inspector",
34
+ "inspector/promises",
34
35
  "module",
35
36
  "net",
36
37
  "os",
@@ -42,8 +43,10 @@ const builtins = [
42
43
  "punycode",
43
44
  "querystring",
44
45
  "readline",
46
+ "readline/promises",
45
47
  "repl",
46
48
  "stream",
49
+ "stream/consumers",
47
50
  "stream/promises",
48
51
  "stream/web",
49
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}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.76.2",
3
+ "version": "5.77.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",