webpack 5.1.2 → 5.3.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.

Files changed (42) hide show
  1. package/lib/ChunkGraph.js +19 -0
  2. package/lib/Compilation.js +37 -9
  3. package/lib/Compiler.js +26 -2
  4. package/lib/ConditionalInitFragment.js +109 -0
  5. package/lib/ContextModule.js +1 -1
  6. package/lib/DelegatedModule.js +1 -1
  7. package/lib/Dependency.js +1 -0
  8. package/lib/ExportsInfo.js +62 -16
  9. package/lib/ExternalModule.js +7 -6
  10. package/lib/FlagDependencyUsagePlugin.js +38 -42
  11. package/lib/Module.js +8 -0
  12. package/lib/NormalModule.js +26 -20
  13. package/lib/RawModule.js +1 -1
  14. package/lib/RuntimeGlobals.js +5 -0
  15. package/lib/RuntimeModule.js +4 -1
  16. package/lib/RuntimePlugin.js +8 -0
  17. package/lib/RuntimeTemplate.js +41 -0
  18. package/lib/SourceMapDevToolModuleOptionsPlugin.js +25 -0
  19. package/lib/SourceMapDevToolPlugin.js +6 -2
  20. package/lib/Template.js +1 -0
  21. package/lib/WebpackOptionsApply.js +3 -1
  22. package/lib/asset/AssetGenerator.js +10 -6
  23. package/lib/buildChunkGraph.js +111 -25
  24. package/lib/config/browserslistTargetHandler.js +4 -2
  25. package/lib/config/defaults.js +1 -1
  26. package/lib/container/ContainerEntryModule.js +4 -2
  27. package/lib/dependencies/HarmonyAcceptDependency.js +33 -5
  28. package/lib/dependencies/HarmonyImportDependency.js +70 -28
  29. package/lib/dependencies/HarmonyImportSpecifierDependency.js +2 -2
  30. package/lib/dependencies/PureExpressionDependency.js +30 -6
  31. package/lib/dependencies/WorkerPlugin.js +8 -3
  32. package/lib/javascript/JavascriptModulesPlugin.js +16 -10
  33. package/lib/optimize/ConcatenatedModule.js +87 -20
  34. package/lib/optimize/ModuleConcatenationPlugin.js +71 -6
  35. package/lib/optimize/SideEffectsFlagPlugin.js +112 -100
  36. package/lib/runtime/RuntimeIdRuntimeModule.js +29 -0
  37. package/lib/stats/DefaultStatsPrinterPlugin.js +17 -1
  38. package/lib/util/compileBooleanMatcher.js +13 -1
  39. package/lib/util/runtime.js +63 -1
  40. package/package.json +7 -7
  41. package/schemas/WebpackOptions.json +13 -2
  42. package/types.d.ts +63 -8
@@ -234,6 +234,16 @@ const SIMPLE_PRINTERS = {
234
234
 
235
235
  "asset.info.immutable": (immutable, { green, formatFlag }) =>
236
236
  immutable ? green(formatFlag("immutable")) : undefined,
237
+ "asset.info.javascriptModule": (javascriptModule, { formatFlag }) =>
238
+ javascriptModule ? formatFlag("javascript module") : undefined,
239
+ "asset.info.sourceFilename": (sourceFilename, { formatFlag }) =>
240
+ sourceFilename
241
+ ? formatFlag(
242
+ sourceFilename === true
243
+ ? "from source file"
244
+ : `from: ${sourceFilename}`
245
+ )
246
+ : undefined,
237
247
  "asset.info.development": (development, { green, formatFlag }) =>
238
248
  development ? green(formatFlag("dev")) : undefined,
239
249
  "asset.info.hotModuleReplacement": (
@@ -644,7 +654,13 @@ const PREFERRED_ORDERS = {
644
654
  "children",
645
655
  "filteredChildren"
646
656
  ],
647
- "asset.info": ["immutable", "development", "hotModuleReplacement"],
657
+ "asset.info": [
658
+ "immutable",
659
+ "sourceFilename",
660
+ "javascriptModule",
661
+ "development",
662
+ "hotModuleReplacement"
663
+ ],
648
664
  chunkGroup: [
649
665
  "kind!",
650
666
  "name",
@@ -25,6 +25,17 @@ const compileBooleanMatcher = map => {
25
25
  const negativeItems = Object.keys(map).filter(i => !map[i]);
26
26
  if (positiveItems.length === 0) return false;
27
27
  if (negativeItems.length === 0) return true;
28
+ return compileBooleanMatcherFromLists(positiveItems, negativeItems);
29
+ };
30
+
31
+ /**
32
+ * @param {string[]} positiveItems positive items
33
+ * @param {string[]} negativeItems negative items
34
+ * @returns {function(string): string} a template function to determine the value at runtime
35
+ */
36
+ const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
37
+ if (positiveItems.length === 0) return () => "false";
38
+ if (negativeItems.length === 0) return () => "true";
28
39
  if (positiveItems.length === 1)
29
40
  return value => `${toSimpleString(positiveItems[0])} == ${value}`;
30
41
  if (negativeItems.length === 1)
@@ -188,5 +199,6 @@ const itemsToRegexp = itemsArr => {
188
199
  return `(${conditional.join("|")})`;
189
200
  };
190
201
 
202
+ compileBooleanMatcher.fromLists = compileBooleanMatcherFromLists;
203
+ compileBooleanMatcher.itemsToRegexp = itemsToRegexp;
191
204
  module.exports = compileBooleanMatcher;
192
- module.exports.itemsToRegexp = itemsToRegexp;
@@ -44,7 +44,7 @@ exports.getEntryRuntime = (compilation, name, options) => {
44
44
  result = mergeRuntimeOwned(result, runtime || name);
45
45
  }
46
46
  }
47
- return result;
47
+ return result || name;
48
48
  } else {
49
49
  return runtime || name;
50
50
  }
@@ -280,6 +280,68 @@ exports.intersectRuntime = (a, b) => {
280
280
  }
281
281
  };
282
282
 
283
+ exports.subtractRuntime = (a, b) => {
284
+ if (a === undefined) {
285
+ return undefined;
286
+ } else if (b === undefined) {
287
+ return a;
288
+ } else if (a === b) {
289
+ return undefined;
290
+ } else if (typeof a === "string") {
291
+ if (typeof b === "string") {
292
+ return undefined;
293
+ } else if (b.has(a)) {
294
+ return undefined;
295
+ } else {
296
+ return a;
297
+ }
298
+ } else {
299
+ if (typeof b === "string") {
300
+ if (!a.has(b)) return a;
301
+ if (a.size === 2) {
302
+ for (const item of a) {
303
+ if (item !== b) return item;
304
+ }
305
+ }
306
+ const set = new SortableSet(a);
307
+ set.delete(b);
308
+ } else {
309
+ const set = new SortableSet();
310
+ for (const item of a) {
311
+ if (!b.has(item)) set.add(item);
312
+ }
313
+ if (set.size === 0) return undefined;
314
+ if (set.size === 1) for (const item of set) return item;
315
+ return set;
316
+ }
317
+ }
318
+ };
319
+
320
+ /**
321
+ * @param {RuntimeSpec} runtime runtime
322
+ * @param {function(RuntimeSpec): boolean} filter filter function
323
+ * @returns {boolean | RuntimeSpec} true/false if filter is constant for all runtimes, otherwise runtimes that are active
324
+ */
325
+ exports.filterRuntime = (runtime, filter) => {
326
+ if (runtime === undefined) return filter(undefined);
327
+ if (typeof runtime === "string") return filter(runtime);
328
+ let some = false;
329
+ let every = true;
330
+ let result = undefined;
331
+ for (const r of runtime) {
332
+ const v = filter(r);
333
+ if (v) {
334
+ some = true;
335
+ result = mergeRuntimeOwned(result, r);
336
+ } else {
337
+ every = false;
338
+ }
339
+ }
340
+ if (!some) return false;
341
+ if (every) return true;
342
+ return result;
343
+ };
344
+
283
345
  /**
284
346
  * @template T
285
347
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.1.2",
3
+ "version": "5.3.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",
@@ -11,11 +11,11 @@
11
11
  "@webassemblyjs/helper-module-context": "1.9.0",
12
12
  "@webassemblyjs/wasm-edit": "1.9.0",
13
13
  "@webassemblyjs/wasm-parser": "1.9.0",
14
- "acorn": "^8.0.3",
15
- "browserslist": "^4.14.3",
14
+ "acorn": "^8.0.4",
15
+ "browserslist": "^4.14.5",
16
16
  "chrome-trace-event": "^1.0.2",
17
- "enhanced-resolve": "^5.2.0",
18
- "eslint-scope": "^5.1.0",
17
+ "enhanced-resolve": "^5.3.1",
18
+ "eslint-scope": "^5.1.1",
19
19
  "events": "^3.2.0",
20
20
  "glob-to-regexp": "^0.4.1",
21
21
  "graceful-fs": "^4.2.4",
@@ -28,7 +28,7 @@
28
28
  "tapable": "^2.0.0",
29
29
  "terser-webpack-plugin": "^5.0.0",
30
30
  "watchpack": "^2.0.0",
31
- "webpack-sources": "^2.0.1"
31
+ "webpack-sources": "^2.1.0"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
34
  "webpack-cli": {
@@ -75,7 +75,7 @@
75
75
  "lodash": "^4.17.19",
76
76
  "lodash-es": "^4.17.15",
77
77
  "memfs": "^3.2.0",
78
- "mini-css-extract-plugin": "^0.10.0",
78
+ "mini-css-extract-plugin": "^1.0.0",
79
79
  "mini-svg-data-uri": "^1.2.3",
80
80
  "open-cli": "^6.0.1",
81
81
  "prettier": "^2.0.5",
@@ -1350,8 +1350,15 @@
1350
1350
  "$ref": "#/definitions/OptimizationRuntimeChunk"
1351
1351
  },
1352
1352
  "sideEffects": {
1353
- "description": "Skip over modules which are flagged to contain no side effects when exports are not used.",
1354
- "type": "boolean"
1353
+ "description": "Skip over modules which contain no side effects when exports are not used (false: disabled, 'flag': only use manually placed side effects flag, true: also analyse source code for side effects).",
1354
+ "anyOf": [
1355
+ {
1356
+ "enum": ["flag"]
1357
+ },
1358
+ {
1359
+ "type": "boolean"
1360
+ }
1361
+ ]
1355
1362
  },
1356
1363
  "splitChunks": {
1357
1364
  "description": "Optimize duplication and caching by splitting chunks by shared modules and cache group.",
@@ -3602,6 +3609,10 @@
3602
3609
  "description": "Delay the rebuilt after the first change. Value is a time in ms.",
3603
3610
  "type": "number"
3604
3611
  },
3612
+ "followSymlinks": {
3613
+ "description": "Resolve symlinks and watch symlink and real file. This is usually not needed as webpack already resolves symlinks ('resolve.symlinks').",
3614
+ "type": "boolean"
3615
+ },
3605
3616
  "ignored": {
3606
3617
  "description": "Ignore some files from watching (glob pattern or regexp).",
3607
3618
  "anyOf": [
package/types.d.ts CHANGED
@@ -234,6 +234,11 @@ declare interface AssetInfo {
234
234
  */
235
235
  contenthash?: LibraryExport;
236
236
 
237
+ /**
238
+ * when asset was created from a source file (potentially transformed), the original filename relative to compilation context
239
+ */
240
+ sourceFilename?: string;
241
+
237
242
  /**
238
243
  * size in bytes, only set after asset has been emitted
239
244
  */
@@ -249,6 +254,11 @@ declare interface AssetInfo {
249
254
  */
250
255
  hotModuleReplacement?: boolean;
251
256
 
257
+ /**
258
+ * true, when asset is javascript and an ESM
259
+ */
260
+ javascriptModule?: boolean;
261
+
252
262
  /**
253
263
  * object of pointers to other assets, keyed by type of relation (only points from parent to child)
254
264
  */
@@ -774,6 +784,8 @@ declare class ChunkGraph {
774
784
  disconnectChunkGroup(chunkGroup: ChunkGroup): void;
775
785
  getModuleId(module: Module): string | number;
776
786
  setModuleId(module: Module, id: string | number): void;
787
+ getRuntimeId(runtime: string): string | number;
788
+ setRuntimeId(runtime: string, id: string | number): void;
777
789
  hasModuleHashes(
778
790
  module: Module,
779
791
  runtime: string | SortableSet<string>
@@ -1440,6 +1452,7 @@ declare class Compilation {
1440
1452
  ): void;
1441
1453
  patchChunksAfterReasonRemoval(module: Module, chunk: Chunk): void;
1442
1454
  removeChunkFromDependencies(block: DependenciesBlock, chunk: Chunk): void;
1455
+ assignRuntimeIds(): void;
1443
1456
  sortItemsWithChunkIds(): void;
1444
1457
  summarizeDependencies(): void;
1445
1458
  createModuleHashes(): void;
@@ -1547,14 +1560,14 @@ declare class Compilation {
1547
1560
  static PROCESS_ASSETS_STAGE_DEV_TOOLING: number;
1548
1561
 
1549
1562
  /**
1550
- * Optimize the transfer of existing assets, e. g. by preparing a compressed (gzip) file as separate asset.
1563
+ * Optimize the hashes of the assets, e. g. by generating real hashes of the asset content.
1551
1564
  */
1552
- static PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER: number;
1565
+ static PROCESS_ASSETS_STAGE_OPTIMIZE_HASH: number;
1553
1566
 
1554
1567
  /**
1555
- * Optimize the hashes of the assets, e. g. by generating real hashes of the asset content.
1568
+ * Optimize the transfer of existing assets, e. g. by preparing a compressed (gzip) file as separate asset.
1556
1569
  */
1557
- static PROCESS_ASSETS_STAGE_OPTIMIZE_HASH: number;
1570
+ static PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER: number;
1558
1571
 
1559
1572
  /**
1560
1573
  * Analyse existing assets.
@@ -1580,6 +1593,7 @@ declare interface CompilationHooksJavascriptModulesPlugin {
1580
1593
  render: SyncWaterfallHook<[Source, RenderContextObject]>;
1581
1594
  renderRequire: SyncWaterfallHook<[string, RenderBootstrapContext]>;
1582
1595
  chunkHash: SyncHook<[Chunk, Hash, ChunkHashContext], void>;
1596
+ useSourceMap: SyncBailHook<[Chunk, RenderContextObject], boolean>;
1583
1597
  }
1584
1598
  declare interface CompilationParams {
1585
1599
  normalModuleFactory: NormalModuleFactory;
@@ -3076,6 +3090,7 @@ declare abstract class ExportsInfo {
3076
3090
  setAllKnownExportsUsed(runtime: string | SortableSet<string>): boolean;
3077
3091
  setUsedForSideEffectsOnly(runtime: string | SortableSet<string>): boolean;
3078
3092
  isUsed(runtime: string | SortableSet<string>): boolean;
3093
+ isModuleUsed(runtime: string | SortableSet<string>): boolean;
3079
3094
  getUsedExports(
3080
3095
  runtime: string | SortableSet<string>
3081
3096
  ): boolean | SortableSet<string>;
@@ -4782,6 +4797,8 @@ declare class Module extends DependenciesBlock {
4782
4797
  debugId: number;
4783
4798
  resolveOptions: ResolveOptionsWebpackOptions;
4784
4799
  factoryMeta: any;
4800
+ useSourceMap: boolean;
4801
+ useSimpleSourceMap: boolean;
4785
4802
  buildMeta: KnownBuildMeta & Record<string, any>;
4786
4803
  buildInfo: any;
4787
4804
  presentationalDependencies: Dependency[];
@@ -4894,7 +4911,6 @@ declare class Module extends DependenciesBlock {
4894
4911
  missingDependencies: LazySet<string>,
4895
4912
  buildDependencies: LazySet<string>
4896
4913
  ): void;
4897
- useSourceMap: any;
4898
4914
  readonly hasEqualsChunks: any;
4899
4915
  readonly isUsed: any;
4900
4916
  readonly errors: any;
@@ -5831,9 +5847,9 @@ declare interface Optimization {
5831
5847
  runtimeChunk?: OptimizationRuntimeChunk;
5832
5848
 
5833
5849
  /**
5834
- * Skip over modules which are flagged to contain no side effects when exports are not used.
5850
+ * Skip over modules which contain no side effects when exports are not used (false: disabled, 'flag': only use manually placed side effects flag, true: also analyse source code for side effects).
5835
5851
  */
5836
- sideEffects?: boolean;
5852
+ sideEffects?: boolean | "flag";
5837
5853
 
5838
5854
  /**
5839
5855
  * Optimize duplication and caching by splitting chunks by shared modules and cache group.
@@ -6993,6 +7009,7 @@ declare interface RenderManifestEntryTemplated {
6993
7009
  render: () => Source;
6994
7010
  filenameTemplate: string | ((arg0: PathData, arg1: AssetInfo) => string);
6995
7011
  pathOptions?: PathData;
7012
+ info?: AssetInfo;
6996
7013
  identifier: string;
6997
7014
  hash?: string;
6998
7015
  auxiliary?: boolean;
@@ -8006,6 +8023,7 @@ declare abstract class RuntimeTemplate {
8006
8023
  outputOptions: OutputNormalized;
8007
8024
  requestShortener: RequestShortener;
8008
8025
  isIIFE(): boolean;
8026
+ isModule(): boolean;
8009
8027
  supportsConst(): boolean;
8010
8028
  supportsArrowFunction(): boolean;
8011
8029
  supportsForOf(): boolean;
@@ -8219,6 +8237,24 @@ declare abstract class RuntimeTemplate {
8219
8237
  */
8220
8238
  runtimeRequirements: Set<string>;
8221
8239
  }): string;
8240
+ runtimeConditionExpression(__0: {
8241
+ /**
8242
+ * the chunk graph
8243
+ */
8244
+ chunkGraph: ChunkGraph;
8245
+ /**
8246
+ * runtime for which this code will be generated
8247
+ */
8248
+ runtime?: string | SortableSet<string>;
8249
+ /**
8250
+ * only execute the statement in some runtimes
8251
+ */
8252
+ runtimeCondition?: string | boolean | SortableSet<string>;
8253
+ /**
8254
+ * if set, will be filled with runtime requirements
8255
+ */
8256
+ runtimeRequirements: Set<string>;
8257
+ }): string;
8222
8258
  importStatement(__0: {
8223
8259
  /**
8224
8260
  * whether a new variable should be created or the existing one updated
@@ -8248,6 +8284,14 @@ declare abstract class RuntimeTemplate {
8248
8284
  * true, if this is a weak dependency
8249
8285
  */
8250
8286
  weak?: boolean;
8287
+ /**
8288
+ * runtime for which this code will be generated
8289
+ */
8290
+ runtime?: string | SortableSet<string>;
8291
+ /**
8292
+ * only execute the statement in some runtimes
8293
+ */
8294
+ runtimeCondition?: string | boolean | SortableSet<string>;
8251
8295
  /**
8252
8296
  * if set, will be filled with runtime requirements
8253
8297
  */
@@ -8475,7 +8519,7 @@ declare interface SharedObject {
8475
8519
  [index: string]: string | SharedConfig;
8476
8520
  }
8477
8521
  declare class SideEffectsFlagPlugin {
8478
- constructor();
8522
+ constructor(analyseSource?: boolean);
8479
8523
 
8480
8524
  /**
8481
8525
  * Apply the plugin
@@ -9309,6 +9353,7 @@ declare const UNDEFINED_MARKER: unique symbol;
9309
9353
  declare interface UpdateHashContextDependency {
9310
9354
  chunkGraph: ChunkGraph;
9311
9355
  runtime: string | SortableSet<string>;
9356
+ runtimeTemplate?: RuntimeTemplate;
9312
9357
  }
9313
9358
  declare interface UpdateHashContextGenerator {
9314
9359
  /**
@@ -9533,6 +9578,11 @@ declare interface WatchOptions {
9533
9578
  */
9534
9579
  aggregateTimeout?: number;
9535
9580
 
9581
+ /**
9582
+ * Resolve symlinks and watch symlink and real file. This is usually not needed as webpack already resolves symlinks ('resolve.symlinks').
9583
+ */
9584
+ followSymlinks?: boolean;
9585
+
9536
9586
  /**
9537
9587
  * Ignore some files from watching (glob pattern or regexp).
9538
9588
  */
@@ -9581,6 +9631,10 @@ declare abstract class Watching {
9581
9631
  * Delay the rebuilt after the first change. Value is a time in ms.
9582
9632
  */
9583
9633
  aggregateTimeout?: number;
9634
+ /**
9635
+ * Resolve symlinks and watch symlink and real file. This is usually not needed as webpack already resolves symlinks ('resolve.symlinks').
9636
+ */
9637
+ followSymlinks?: boolean;
9584
9638
  /**
9585
9639
  * Ignore some files from watching (glob pattern or regexp).
9586
9640
  */
@@ -10088,6 +10142,7 @@ declare namespace exports {
10088
10142
  export let scriptNonce: string;
10089
10143
  export let loadScript: string;
10090
10144
  export let chunkName: string;
10145
+ export let runtimeId: string;
10091
10146
  export let getChunkScriptFilename: string;
10092
10147
  export let getChunkUpdateScriptFilename: string;
10093
10148
  export let startup: string;