webpack 5.33.0 → 5.35.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 (112) hide show
  1. package/bin/webpack.js +0 -0
  2. package/lib/BannerPlugin.js +11 -7
  3. package/lib/ChunkGraph.js +12 -6
  4. package/lib/CleanPlugin.js +17 -15
  5. package/lib/Compilation.js +1 -1
  6. package/lib/DllPlugin.js +11 -7
  7. package/lib/DllReferencePlugin.js +11 -7
  8. package/lib/FileSystemInfo.js +112 -74
  9. package/lib/IgnorePlugin.js +11 -6
  10. package/lib/LoaderOptionsPlugin.js +10 -7
  11. package/lib/NormalModule.js +2 -2
  12. package/lib/ProgressPlugin.js +10 -6
  13. package/lib/RuntimePlugin.js +3 -1
  14. package/lib/SourceMapDevToolPlugin.js +10 -7
  15. package/lib/WatchIgnorePlugin.js +11 -6
  16. package/lib/WebpackOptionsApply.js +2 -1
  17. package/lib/asset/AssetModulesPlugin.js +33 -14
  18. package/lib/cache/PackFileCacheStrategy.js +16 -2
  19. package/lib/config/defaults.js +2 -1
  20. package/lib/container/ContainerPlugin.js +11 -3
  21. package/lib/container/ContainerReferencePlugin.js +12 -3
  22. package/lib/container/ModuleFederationPlugin.js +12 -5
  23. package/lib/debug/ProfilingPlugin.js +10 -6
  24. package/lib/dependencies/LoaderPlugin.js +6 -1
  25. package/lib/ids/HashedModuleIdsPlugin.js +11 -6
  26. package/lib/ids/OccurrenceChunkIdsPlugin.js +11 -6
  27. package/lib/ids/OccurrenceModuleIdsPlugin.js +11 -6
  28. package/lib/index.js +9 -3
  29. package/lib/json/JsonModulesPlugin.js +9 -8
  30. package/lib/node/CommonJsChunkLoadingPlugin.js +3 -1
  31. package/lib/node/NodeTargetPlugin.js +5 -1
  32. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +3 -1
  33. package/lib/node/ReadFileCompileWasmPlugin.js +3 -1
  34. package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
  35. package/lib/optimize/LimitChunkCountPlugin.js +18 -10
  36. package/lib/optimize/MinChunkSizePlugin.js +11 -7
  37. package/lib/runtime/StartupChunkDependenciesPlugin.js +3 -1
  38. package/lib/serialization/BinaryMiddleware.js +47 -25
  39. package/lib/sharing/ConsumeSharedPlugin.js +11 -3
  40. package/lib/sharing/ProvideSharedPlugin.js +11 -3
  41. package/lib/util/comparators.js +1 -3
  42. package/lib/util/create-schema-validation.js +21 -0
  43. package/lib/util/registerExternalSerializer.js +1 -1
  44. package/lib/web/FetchCompileAsyncWasmPlugin.js +3 -1
  45. package/lib/web/FetchCompileWasmPlugin.js +3 -1
  46. package/lib/web/JsonpChunkLoadingPlugin.js +3 -1
  47. package/lib/webpack.js +7 -2
  48. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  49. package/package.json +6 -6
  50. package/schemas/WebpackOptions.check.d.ts +7 -0
  51. package/schemas/WebpackOptions.check.js +6 -0
  52. package/schemas/WebpackOptions.json +13 -9
  53. package/schemas/plugins/BannerPlugin.check.d.ts +7 -0
  54. package/schemas/plugins/BannerPlugin.check.js +6 -0
  55. package/schemas/plugins/DllPlugin.check.d.ts +7 -0
  56. package/schemas/plugins/DllPlugin.check.js +6 -0
  57. package/schemas/plugins/DllReferencePlugin.check.d.ts +7 -0
  58. package/schemas/plugins/DllReferencePlugin.check.js +6 -0
  59. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +7 -0
  60. package/schemas/plugins/HashedModuleIdsPlugin.check.js +6 -0
  61. package/schemas/plugins/IgnorePlugin.check.d.ts +7 -0
  62. package/schemas/plugins/IgnorePlugin.check.js +6 -0
  63. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +7 -0
  64. package/schemas/plugins/JsonModulesPluginParser.check.js +6 -0
  65. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +7 -0
  66. package/schemas/plugins/LoaderOptionsPlugin.check.js +6 -0
  67. package/schemas/plugins/ProgressPlugin.check.d.ts +7 -0
  68. package/schemas/plugins/ProgressPlugin.check.js +6 -0
  69. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +7 -0
  70. package/schemas/plugins/SourceMapDevToolPlugin.check.js +6 -0
  71. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +7 -0
  72. package/schemas/plugins/WatchIgnorePlugin.check.js +6 -0
  73. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +7 -0
  74. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +6 -0
  75. package/schemas/plugins/asset/AssetGeneratorOptions.json +3 -0
  76. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +7 -0
  77. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +6 -0
  78. package/schemas/plugins/asset/AssetInlineGeneratorOptions.json +3 -0
  79. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +7 -0
  80. package/schemas/plugins/asset/AssetParserOptions.check.js +6 -0
  81. package/schemas/plugins/asset/AssetParserOptions.json +3 -0
  82. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +7 -0
  83. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +6 -0
  84. package/schemas/plugins/asset/AssetResourceGeneratorOptions.json +3 -0
  85. package/schemas/plugins/container/ContainerPlugin.check.d.ts +7 -0
  86. package/schemas/plugins/container/ContainerPlugin.check.js +6 -0
  87. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +7 -0
  88. package/schemas/plugins/container/ContainerReferencePlugin.check.js +6 -0
  89. package/schemas/plugins/container/ExternalsType.check.d.ts +7 -0
  90. package/schemas/plugins/container/ExternalsType.check.js +6 -0
  91. package/schemas/plugins/container/ExternalsType.json +3 -0
  92. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +7 -0
  93. package/schemas/plugins/container/ModuleFederationPlugin.check.js +6 -0
  94. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +7 -0
  95. package/schemas/plugins/debug/ProfilingPlugin.check.js +6 -0
  96. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +7 -0
  97. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +6 -0
  98. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +7 -0
  99. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +6 -0
  100. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +7 -0
  101. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +6 -0
  102. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +7 -0
  103. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +6 -0
  104. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +7 -0
  105. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +6 -0
  106. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +7 -0
  107. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +6 -0
  108. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +7 -0
  109. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +6 -0
  110. package/schemas/plugins/sharing/SharePlugin.check.d.ts +7 -0
  111. package/schemas/plugins/sharing/SharePlugin.check.js +6 -0
  112. package/types.d.ts +21 -3
@@ -5,13 +5,21 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../schemas/plugins/WatchIgnorePlugin.json");
8
+ const createSchemaValidation = require("./util/create-schema-validation");
10
9
 
11
10
  /** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
12
11
  /** @typedef {import("./Compiler")} Compiler */
13
12
  /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
14
13
 
14
+ const validate = createSchemaValidation(
15
+ require("../schemas/plugins/WatchIgnorePlugin.check.js"),
16
+ () => require("../schemas/plugins/WatchIgnorePlugin.json"),
17
+ {
18
+ name: "Watch Ignore Plugin",
19
+ baseDataPath: "options"
20
+ }
21
+ );
22
+
15
23
  const IGNORE_TIME_ENTRY = "ignore";
16
24
 
17
25
  class IgnoringWatchFileSystem {
@@ -90,10 +98,7 @@ class WatchIgnorePlugin {
90
98
  * @param {WatchIgnorePluginOptions} options options
91
99
  */
92
100
  constructor(options) {
93
- validate(schema, options, {
94
- name: "Watch Ignore Plugin",
95
- baseDataPath: "options"
96
- });
101
+ validate(options);
97
102
  this.paths = options.paths;
98
103
  }
99
104
 
@@ -568,7 +568,8 @@ class WebpackOptionsApply extends OptionsApply {
568
568
  "webpack.cache.PackFileCacheStrategy"
569
569
  ),
570
570
  snapshot: options.snapshot,
571
- maxAge: cacheOptions.maxAge
571
+ maxAge: cacheOptions.maxAge,
572
+ allowCollectingMemory: cacheOptions.allowCollectingMemory
572
573
  }),
573
574
  cacheOptions.idleTimeout,
574
575
  cacheOptions.idleTimeoutForInitialStore
@@ -5,9 +5,9 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
8
  const { cleverMerge } = require("../util/cleverMerge");
10
9
  const { compareModulesByIdentifier } = require("../util/comparators");
10
+ const createSchemaValidation = require("../util/create-schema-validation");
11
11
  const memoize = require("../util/memoize");
12
12
 
13
13
  /** @typedef {import("webpack-sources").Source} Source */
@@ -22,13 +22,38 @@ const getSchema = name => {
22
22
  oneOf: [{ $ref: `#/definitions/${name}` }]
23
23
  };
24
24
  };
25
- const getGeneratorSchemaMap = {
26
- asset: memoize(() => getSchema("AssetGeneratorOptions")),
27
- "asset/resource": memoize(() => getSchema("AssetResourceGeneratorOptions")),
28
- "asset/inline": memoize(() => getSchema("AssetInlineGeneratorOptions"))
25
+
26
+ const generatorValidationOptions = {
27
+ name: "Asset Modules Plugin",
28
+ baseDataPath: "generator"
29
+ };
30
+ const validateGeneratorOptions = {
31
+ asset: createSchemaValidation(
32
+ require("../../schemas/plugins/asset/AssetGeneratorOptions.check.js"),
33
+ () => getSchema("AssetGeneratorOptions"),
34
+ generatorValidationOptions
35
+ ),
36
+ "asset/resource": createSchemaValidation(
37
+ require("../../schemas/plugins/asset/AssetResourceGeneratorOptions.check.js"),
38
+ () => getSchema("AssetResourceGeneratorOptions"),
39
+ generatorValidationOptions
40
+ ),
41
+ "asset/inline": createSchemaValidation(
42
+ require("../../schemas/plugins/asset/AssetInlineGeneratorOptions.check.js"),
43
+ () => getSchema("AssetInlineGeneratorOptions"),
44
+ generatorValidationOptions
45
+ )
29
46
  };
30
47
 
31
- const getParserSchema = memoize(() => getSchema("AssetParserOptions"));
48
+ const validateParserOptions = createSchemaValidation(
49
+ require("../../schemas/plugins/asset/AssetParserOptions.check.js"),
50
+ () => getSchema("AssetParserOptions"),
51
+ {
52
+ name: "Asset Modules Plugin",
53
+ baseDataPath: "parser"
54
+ }
55
+ );
56
+
32
57
  const getAssetGenerator = memoize(() => require("./AssetGenerator"));
33
58
  const getAssetParser = memoize(() => require("./AssetParser"));
34
59
  const getAssetSourceParser = memoize(() => require("./AssetSourceParser"));
@@ -52,10 +77,7 @@ class AssetModulesPlugin {
52
77
  normalModuleFactory.hooks.createParser
53
78
  .for("asset")
54
79
  .tap(plugin, parserOptions => {
55
- validate(getParserSchema(), parserOptions, {
56
- name: "Asset Modules Plugin",
57
- baseDataPath: "parser"
58
- });
80
+ validateParserOptions(parserOptions);
59
81
  parserOptions = cleverMerge(
60
82
  compiler.options.module.parser.asset,
61
83
  parserOptions
@@ -100,10 +122,7 @@ class AssetModulesPlugin {
100
122
  .for(type)
101
123
  // eslint-disable-next-line no-loop-func
102
124
  .tap(plugin, generatorOptions => {
103
- validate(getGeneratorSchemaMap[type](), generatorOptions, {
104
- name: "Asset Modules Plugin",
105
- baseDataPath: "generator"
106
- });
125
+ validateGeneratorOptions[type](generatorOptions);
107
126
 
108
127
  let dataUrl = undefined;
109
128
  if (type !== "asset/resource") {
@@ -768,6 +768,14 @@ class PackContent {
768
768
  }
769
769
  }
770
770
 
771
+ const allowCollectingMemory = buf => {
772
+ const wasted = buf.buffer.byteLength - buf.byteLength;
773
+ if (wasted > 8192 && (wasted > 1048576 || wasted > buf.byteLength)) {
774
+ return Buffer.from(buf);
775
+ }
776
+ return buf;
777
+ };
778
+
771
779
  class PackFileCacheStrategy {
772
780
  /**
773
781
  * @param {Object} options options
@@ -779,6 +787,7 @@ class PackFileCacheStrategy {
779
787
  * @param {Logger} options.logger a logger
780
788
  * @param {SnapshotOptions} options.snapshot options regarding snapshotting
781
789
  * @param {number} options.maxAge max age of cache items
790
+ * @param {boolean} options.allowCollectingMemory allow to collect unused memory created during deserialization
782
791
  */
783
792
  constructor({
784
793
  compiler,
@@ -788,7 +797,8 @@ class PackFileCacheStrategy {
788
797
  version,
789
798
  logger,
790
799
  snapshot,
791
- maxAge
800
+ maxAge,
801
+ allowCollectingMemory
792
802
  }) {
793
803
  this.fileSerializer = createFileSerializer(fs);
794
804
  this.fileSystemInfo = new FileSystemInfo(fs, {
@@ -802,6 +812,7 @@ class PackFileCacheStrategy {
802
812
  this.version = version;
803
813
  this.logger = logger;
804
814
  this.maxAge = maxAge;
815
+ this.allowCollectingMemory = allowCollectingMemory;
805
816
  this.snapshot = snapshot;
806
817
  /** @type {Set<string>} */
807
818
  this.buildDependencies = new Set();
@@ -845,7 +856,10 @@ class PackFileCacheStrategy {
845
856
  .deserialize(null, {
846
857
  filename: `${cacheLocation}/index.pack`,
847
858
  extension: ".pack",
848
- logger
859
+ logger,
860
+ retainedBuffer: this.allowCollectingMemory
861
+ ? allowCollectingMemory
862
+ : undefined
849
863
  })
850
864
  .catch(err => {
851
865
  if (err.code !== "ENOENT") {
@@ -295,8 +295,9 @@ const applyCacheDefaults = (cache, { name, mode, development }) => {
295
295
  D(cache, "store", "pack");
296
296
  D(cache, "idleTimeout", 60000);
297
297
  D(cache, "idleTimeoutForInitialStore", 0);
298
- D(cache, "maxMemoryGenerations", development ? 10 : Infinity);
298
+ D(cache, "maxMemoryGenerations", development ? 5 : Infinity);
299
299
  D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
300
+ D(cache, "allowCollectingMemory", development);
300
301
  D(cache.buildDependencies, "defaultWebpack", [
301
302
  path.resolve(__dirname, "..") + path.sep
302
303
  ]);
@@ -5,8 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/container/ContainerPlugin.json");
8
+ const createSchemaValidation = require("../util/create-schema-validation");
10
9
  const ContainerEntryDependency = require("./ContainerEntryDependency");
11
10
  const ContainerEntryModuleFactory = require("./ContainerEntryModuleFactory");
12
11
  const ContainerExposedDependency = require("./ContainerExposedDependency");
@@ -15,6 +14,15 @@ const { parseOptions } = require("./options");
15
14
  /** @typedef {import("../../declarations/plugins/container/ContainerPlugin").ContainerPluginOptions} ContainerPluginOptions */
16
15
  /** @typedef {import("../Compiler")} Compiler */
17
16
 
17
+ const validate = createSchemaValidation(
18
+ require("../../schemas/plugins/container/ContainerPlugin.check.js"),
19
+ () => require("../../schemas/plugins/container/ContainerPlugin.json"),
20
+ {
21
+ name: "Container Plugin",
22
+ baseDataPath: "options"
23
+ }
24
+ );
25
+
18
26
  const PLUGIN_NAME = "ContainerPlugin";
19
27
 
20
28
  class ContainerPlugin {
@@ -22,7 +30,7 @@ class ContainerPlugin {
22
30
  * @param {ContainerPluginOptions} options options
23
31
  */
24
32
  constructor(options) {
25
- validate(schema, options, { name: "Container Plugin" });
33
+ validate(options);
26
34
 
27
35
  this._options = {
28
36
  name: options.name,
@@ -5,10 +5,9 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/container/ContainerReferencePlugin.json");
10
8
  const ExternalsPlugin = require("../ExternalsPlugin");
11
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
+ const createSchemaValidation = require("../util/create-schema-validation");
12
11
  const FallbackDependency = require("./FallbackDependency");
13
12
  const FallbackItemDependency = require("./FallbackItemDependency");
14
13
  const FallbackModuleFactory = require("./FallbackModuleFactory");
@@ -21,6 +20,16 @@ const { parseOptions } = require("./options");
21
20
  /** @typedef {import("../../declarations/plugins/container/ContainerReferencePlugin").RemotesConfig} RemotesConfig */
22
21
  /** @typedef {import("../Compiler")} Compiler */
23
22
 
23
+ const validate = createSchemaValidation(
24
+ require("../../schemas/plugins/container/ContainerReferencePlugin.check.js"),
25
+ () =>
26
+ require("../../schemas/plugins/container/ContainerReferencePlugin.json"),
27
+ {
28
+ name: "Container Reference Plugin",
29
+ baseDataPath: "options"
30
+ }
31
+ );
32
+
24
33
  const slashCode = "/".charCodeAt(0);
25
34
 
26
35
  class ContainerReferencePlugin {
@@ -28,7 +37,7 @@ class ContainerReferencePlugin {
28
37
  * @param {ContainerReferencePluginOptions} options options
29
38
  */
30
39
  constructor(options) {
31
- validate(schema, options, { name: "Container Reference Plugin" });
40
+ validate(options);
32
41
 
33
42
  this._remoteType = options.remoteType;
34
43
  this._remotes = parseOptions(
@@ -5,9 +5,9 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/container/ModuleFederationPlugin.json");
8
+ const isValidExternalsType = require("../../schemas/plugins/container/ExternalsType.check.js");
10
9
  const SharePlugin = require("../sharing/SharePlugin");
10
+ const createSchemaValidation = require("../util/create-schema-validation");
11
11
  const ContainerPlugin = require("./ContainerPlugin");
12
12
  const ContainerReferencePlugin = require("./ContainerReferencePlugin");
13
13
 
@@ -16,12 +16,20 @@ const ContainerReferencePlugin = require("./ContainerReferencePlugin");
16
16
  /** @typedef {import("../../declarations/plugins/container/ModuleFederationPlugin").Shared} Shared */
17
17
  /** @typedef {import("../Compiler")} Compiler */
18
18
 
19
+ const validate = createSchemaValidation(
20
+ require("../../schemas/plugins/container/ModuleFederationPlugin.check.js"),
21
+ () => require("../../schemas/plugins/container/ModuleFederationPlugin.json"),
22
+ {
23
+ name: "Module Federation Plugin",
24
+ baseDataPath: "options"
25
+ }
26
+ );
19
27
  class ModuleFederationPlugin {
20
28
  /**
21
29
  * @param {ModuleFederationPluginOptions} options options
22
30
  */
23
31
  constructor(options) {
24
- validate(schema, options, { name: "Module Federation Plugin" });
32
+ validate(options);
25
33
 
26
34
  this._options = options;
27
35
  }
@@ -36,8 +44,7 @@ class ModuleFederationPlugin {
36
44
  const library = options.library || { type: "var", name: options.name };
37
45
  const remoteType =
38
46
  options.remoteType ||
39
- (options.library &&
40
- schema.definitions.ExternalsType.enum.includes(options.library.type)
47
+ (options.library && isValidExternalsType(options.library.type)
41
48
  ? /** @type {ExternalsType} */ (options.library.type)
42
49
  : "script");
43
50
  if (
@@ -5,13 +5,20 @@
5
5
  "use strict";
6
6
 
7
7
  const { Tracer } = require("chrome-trace-event");
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
8
+ const createSchemaValidation = require("../util/create-schema-validation");
10
9
  const { dirname, mkdirpSync } = require("../util/fs");
11
10
 
12
11
  /** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
13
12
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
14
13
 
14
+ const validate = createSchemaValidation(
15
+ require("../../schemas/plugins/debug/ProfilingPlugin.check.js"),
16
+ () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
17
+ {
18
+ name: "Profiling Plugin",
19
+ baseDataPath: "options"
20
+ }
21
+ );
15
22
  let inspector = undefined;
16
23
 
17
24
  try {
@@ -183,10 +190,7 @@ class ProfilingPlugin {
183
190
  * @param {ProfilingPluginOptions=} options options object
184
191
  */
185
192
  constructor(options = {}) {
186
- validate(schema, options, {
187
- name: "Profiling Plugin",
188
- baseDataPath: "options"
189
- });
193
+ validate(options);
190
194
  this.outputPath = options.outputPath || "events.json";
191
195
  }
192
196
 
@@ -31,6 +31,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
31
31
  /**
32
32
  * @typedef {Object} ImportModuleOptions
33
33
  * @property {string=} layer the target layer
34
+ * @property {string=} publicPath the target public path
34
35
  */
35
36
 
36
37
  class LoaderPlugin {
@@ -199,7 +200,11 @@ class LoaderPlugin {
199
200
  }
200
201
  compilation.executeModule(
201
202
  referencedModule,
202
- {},
203
+ {
204
+ entryOptions: {
205
+ publicPath: options.publicPath
206
+ }
207
+ },
203
208
  (err, result) => {
204
209
  if (err) return callback(err);
205
210
  for (const d of result.fileDependencies) {
@@ -5,25 +5,30 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/HashedModuleIdsPlugin.json");
10
8
  const {
11
9
  compareModulesByPreOrderIndexOrIdentifier
12
10
  } = require("../util/comparators");
11
+ const createSchemaValidation = require("../util/create-schema-validation");
13
12
  const createHash = require("../util/createHash");
14
13
  const { getUsedModuleIds, getFullModuleName } = require("./IdHelpers");
15
14
 
16
15
  /** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
17
16
 
17
+ const validate = createSchemaValidation(
18
+ require("../../schemas/plugins/HashedModuleIdsPlugin.check.js"),
19
+ () => require("../../schemas/plugins/HashedModuleIdsPlugin.json"),
20
+ {
21
+ name: "Hashed Module Ids Plugin",
22
+ baseDataPath: "options"
23
+ }
24
+ );
25
+
18
26
  class HashedModuleIdsPlugin {
19
27
  /**
20
28
  * @param {HashedModuleIdsPluginOptions=} options options object
21
29
  */
22
30
  constructor(options = {}) {
23
- validate(schema, options, {
24
- name: "Hashed Module Ids Plugin",
25
- baseDataPath: "options"
26
- });
31
+ validate(options);
27
32
 
28
33
  /** @type {HashedModuleIdsPluginOptions} */
29
34
  this.options = {
@@ -5,9 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/ids/OccurrenceChunkIdsPlugin.json");
10
8
  const { compareChunksNatural } = require("../util/comparators");
9
+ const createSchemaValidation = require("../util/create-schema-validation");
11
10
  const { assignAscendingChunkIds } = require("./IdHelpers");
12
11
 
13
12
  /** @typedef {import("../../declarations/plugins/ids/OccurrenceChunkIdsPlugin").OccurrenceChunkIdsPluginOptions} OccurrenceChunkIdsPluginOptions */
@@ -15,15 +14,21 @@ const { assignAscendingChunkIds } = require("./IdHelpers");
15
14
  /** @typedef {import("../Compiler")} Compiler */
16
15
  /** @typedef {import("../Module")} Module */
17
16
 
17
+ const validate = createSchemaValidation(
18
+ require("../../schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js"),
19
+ () => require("../../schemas/plugins/ids/OccurrenceChunkIdsPlugin.json"),
20
+ {
21
+ name: "Occurrence Order Chunk Ids Plugin",
22
+ baseDataPath: "options"
23
+ }
24
+ );
25
+
18
26
  class OccurrenceChunkIdsPlugin {
19
27
  /**
20
28
  * @param {OccurrenceChunkIdsPluginOptions=} options options object
21
29
  */
22
30
  constructor(options = {}) {
23
- validate(schema, options, {
24
- name: "Occurrence Order Chunk Ids Plugin",
25
- baseDataPath: "options"
26
- });
31
+ validate(options);
27
32
  this.options = options;
28
33
  }
29
34
 
@@ -5,11 +5,10 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/ids/OccurrenceModuleIdsPlugin.json");
10
8
  const {
11
9
  compareModulesByPreOrderIndexOrIdentifier
12
10
  } = require("../util/comparators");
11
+ const createSchemaValidation = require("../util/create-schema-validation");
13
12
  const { assignAscendingModuleIds } = require("./IdHelpers");
14
13
 
15
14
  /** @typedef {import("../../declarations/plugins/ids/OccurrenceModuleIdsPlugin").OccurrenceModuleIdsPluginOptions} OccurrenceModuleIdsPluginOptions */
@@ -17,15 +16,21 @@ const { assignAscendingModuleIds } = require("./IdHelpers");
17
16
  /** @typedef {import("../Module")} Module */
18
17
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
19
18
 
19
+ const validate = createSchemaValidation(
20
+ require("../../schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js"),
21
+ () => require("../../schemas/plugins/ids/OccurrenceModuleIdsPlugin.json"),
22
+ {
23
+ name: "Occurrence Order Module Ids Plugin",
24
+ baseDataPath: "options"
25
+ }
26
+ );
27
+
20
28
  class OccurrenceModuleIdsPlugin {
21
29
  /**
22
30
  * @param {OccurrenceModuleIdsPluginOptions=} options options object
23
31
  */
24
32
  constructor(options = {}) {
25
- validate(schema, options, {
26
- name: "Occurrence Order Module Ids Plugin",
27
- baseDataPath: "options"
28
- });
33
+ validate(options);
29
34
  this.options = options;
30
35
  }
31
36
 
package/lib/index.js CHANGED
@@ -96,9 +96,15 @@ module.exports = mergeExports(fn, {
96
96
  return require("./webpack");
97
97
  },
98
98
  get validate() {
99
- const validateSchema = require("./validateSchema");
100
- const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
101
- return options => validateSchema(webpackOptionsSchema, options);
99
+ const webpackOptionsSchemaCheck = require("../schemas/WebpackOptions.check.js");
100
+ const getRealValidate = memoize(() => {
101
+ const validateSchema = require("./validateSchema");
102
+ const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
103
+ return options => validateSchema(webpackOptionsSchema, options);
104
+ });
105
+ return options => {
106
+ if (!webpackOptionsSchemaCheck(options)) getRealValidate()(options);
107
+ };
102
108
  },
103
109
  get validateSchema() {
104
110
  const validateSchema = require("./validateSchema");
@@ -5,15 +5,19 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const memoize = require("../util/memoize");
8
+ const createSchemaValidation = require("../util/create-schema-validation");
10
9
  const JsonGenerator = require("./JsonGenerator");
11
10
  const JsonParser = require("./JsonParser");
12
11
 
13
12
  /** @typedef {import("../Compiler")} Compiler */
14
13
 
15
- const getParserSchema = memoize(() =>
16
- require("../../schemas/plugins/JsonModulesPluginParser.json")
14
+ const validate = createSchemaValidation(
15
+ require("../../schemas/plugins/JsonModulesPluginParser.check.js"),
16
+ () => require("../../schemas/plugins/JsonModulesPluginParser.json"),
17
+ {
18
+ name: "Json Modules Plugin",
19
+ baseDataPath: "parser"
20
+ }
17
21
  );
18
22
 
19
23
  class JsonModulesPlugin {
@@ -29,10 +33,7 @@ class JsonModulesPlugin {
29
33
  normalModuleFactory.hooks.createParser
30
34
  .for("json")
31
35
  .tap("JsonModulesPlugin", parserOptions => {
32
- validate(getParserSchema(), parserOptions, {
33
- name: "Json Modules Plugin",
34
- baseDataPath: "parser"
35
- });
36
+ validate(parserOptions);
36
37
 
37
38
  return new JsonParser(parserOptions);
38
39
  });
@@ -39,7 +39,9 @@ class CommonJsChunkLoadingPlugin {
39
39
  const isEnabledForChunk = chunk => {
40
40
  const options = chunk.getEntryOptions();
41
41
  const chunkLoading =
42
- (options && options.chunkLoading) || globalChunkLoading;
42
+ options && options.chunkLoading !== undefined
43
+ ? options.chunkLoading
44
+ : globalChunkLoading;
43
45
  return chunkLoading === chunkLoadingValue;
44
46
  };
45
47
  const onceForChunkSet = new WeakSet();
@@ -54,7 +54,11 @@ const builtins = [
54
54
  "vm",
55
55
  "wasi",
56
56
  "worker_threads",
57
- "zlib"
57
+ "zlib",
58
+
59
+ // cspell:word pnpapi
60
+ // Yarn PnP adds pnpapi as "builtin"
61
+ "pnpapi"
58
62
  ];
59
63
 
60
64
  class NodeTargetPlugin {
@@ -25,7 +25,9 @@ class ReadFileCompileAsyncWasmPlugin {
25
25
  const isEnabledForChunk = chunk => {
26
26
  const options = chunk.getEntryOptions();
27
27
  const wasmLoading =
28
- (options && options.wasmLoading) || globalWasmLoading;
28
+ options && options.wasmLoading !== undefined
29
+ ? options.wasmLoading
30
+ : globalWasmLoading;
29
31
  return wasmLoading === "async-node";
30
32
  };
31
33
  const generateLoadBinaryCode = path =>
@@ -31,7 +31,9 @@ class ReadFileCompileWasmPlugin {
31
31
  const isEnabledForChunk = chunk => {
32
32
  const options = chunk.getEntryOptions();
33
33
  const wasmLoading =
34
- (options && options.wasmLoading) || globalWasmLoading;
34
+ options && options.wasmLoading !== undefined
35
+ ? options.wasmLoading
36
+ : globalWasmLoading;
35
37
  return wasmLoading === "async-node";
36
38
  };
37
39
  const generateLoadBinaryCode = path =>
@@ -5,14 +5,13 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { validate } = require("schema-utils");
9
- const schema = require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json");
10
8
  const { STAGE_ADVANCED } = require("../OptimizationStages");
11
9
  const { intersect } = require("../util/SetHelpers");
12
10
  const {
13
11
  compareModulesByIdentifier,
14
12
  compareChunks
15
13
  } = require("../util/comparators");
14
+ const createSchemaValidation = require("../util/create-schema-validation");
16
15
  const identifierUtils = require("../util/identifier");
17
16
 
18
17
  /** @typedef {import("../../declarations/plugins/optimize/AggressiveSplittingPlugin").AggressiveSplittingPluginOptions} AggressiveSplittingPluginOptions */
@@ -21,6 +20,16 @@ const identifierUtils = require("../util/identifier");
21
20
  /** @typedef {import("../Compiler")} Compiler */
22
21
  /** @typedef {import("../Module")} Module */
23
22
 
23
+ const validate = createSchemaValidation(
24
+ require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.check.js"),
25
+ () =>
26
+ require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json"),
27
+ {
28
+ name: "Aggressive Splitting Plugin",
29
+ baseDataPath: "options"
30
+ }
31
+ );
32
+
24
33
  const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => {
25
34
  return module => {
26
35
  chunkGraph.disconnectChunkAndModule(oldChunk, module);
@@ -47,10 +56,7 @@ class AggressiveSplittingPlugin {
47
56
  * @param {AggressiveSplittingPluginOptions=} options options object
48
57
  */
49
58
  constructor(options = {}) {
50
- validate(schema, options, {
51
- name: "Aggressive Splitting Plugin",
52
- baseDataPath: "options"
53
- });
59
+ validate(options);
54
60
 
55
61
  this.options = options;
56
62
  if (typeof this.options.minSize !== "number") {