@depup/webpack 5.110.1-depup.0 → 5.110.3-depup.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.
Files changed (70) hide show
  1. package/README.md +4 -4
  2. package/changes.json +3 -3
  3. package/lib/ChunkGraph.js +20 -18
  4. package/lib/Compilation.js +1 -1
  5. package/lib/ConcatenationScope.js +25 -35
  6. package/lib/DotenvPlugin.js +41 -13
  7. package/lib/ExportsInfo.js +10 -0
  8. package/lib/FlagDependencyUsagePlugin.js +8 -2
  9. package/lib/NormalModule.js +13 -20
  10. package/lib/RuntimePlugin.js +3 -0
  11. package/lib/RuntimeTemplate.js +437 -432
  12. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  13. package/lib/config/defaults.js +26 -16
  14. package/lib/config/normalization.js +18 -8
  15. package/lib/css/CssLoadingRuntimeModule.js +32 -13
  16. package/lib/css/CssModulesPlugin.js +9 -17
  17. package/lib/css/data.js +13 -3
  18. package/lib/css/syntax.js +78 -10
  19. package/lib/dependencies/CommonJsRequireDependency.js +18 -4
  20. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  21. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
  22. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  23. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +143 -17
  24. package/lib/dependencies/HarmonyImportDependency.js +94 -41
  25. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +93 -14
  26. package/lib/dependencies/HarmonyImportSideEffectDependency.js +114 -0
  27. package/lib/dependencies/HtmlEntryDependency.js +12 -2
  28. package/lib/dependencies/ImportContextDependency.js +43 -3
  29. package/lib/dependencies/ImportDependency.js +8 -29
  30. package/lib/dependencies/ImportParserPlugin.js +24 -14
  31. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  32. package/lib/dependencies/WorkerAndWorkletPlugin.js +1 -0
  33. package/lib/dependencies/WorkerDependency.js +6 -12
  34. package/lib/dependencies/WorkletDependency.js +7 -11
  35. package/lib/dependencies/importOptionsCheck.js +47 -0
  36. package/lib/errors/DotenvFileError.js +29 -0
  37. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  38. package/lib/esm/ModuleChunkLoadingPlugin.js +6 -9
  39. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -1
  40. package/lib/html/HtmlModulesPlugin.js +84 -38
  41. package/lib/html/syntax.js +417 -169
  42. package/lib/javascript/JavascriptModulesPlugin.js +5 -10
  43. package/lib/loaders/LoaderRunner.js +33 -5
  44. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
  45. package/lib/optimize/ConcatenatedModule.js +46 -7
  46. package/lib/optimize/ConstExportsPlugin.js +5 -0
  47. package/lib/optimize/InlineExports.js +121 -0
  48. package/lib/optimize/RealContentHashPlugin.js +111 -35
  49. package/lib/prefetch/ResourceHintPlugin.js +12 -13
  50. package/lib/runtime/AsyncModuleRuntimeModule.js +5 -1
  51. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +11 -1
  52. package/lib/schemes/HttpUriPlugin.js +22 -5
  53. package/lib/serialization/FileMiddleware.js +15 -2
  54. package/lib/typescript/TypeScriptPlugin.js +8 -10
  55. package/lib/util/ArrayQueue.js +3 -3
  56. package/lib/util/SourceProcessor.js +24 -8
  57. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  58. package/lib/util/conventions.js +5 -1
  59. package/lib/util/createMappings.js +25 -3
  60. package/lib/util/internalSerializables.js +2 -0
  61. package/lib/util/removeBOM.js +82 -1
  62. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +5 -3
  63. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -3
  64. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
  65. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
  66. package/lib/web/FetchCompileWasmPlugin.js +4 -2
  67. package/package.json +7 -7
  68. package/schemas/WebpackOptions.check.js +1 -1
  69. package/schemas/WebpackOptions.json +9 -10
  70. package/types.d.ts +95 -27
@@ -31,7 +31,7 @@ const preloadModuleType = require("../util/preloadModuleType");
31
31
  const {
32
32
  PUBLIC_PATH_AUTO: autoPlaceholder
33
33
  } = require("../util/publicPathPlaceholder");
34
- const removeBOM = require("../util/removeBOM");
34
+ const { removeBOMFromResult } = require("../util/removeBOM");
35
35
  const HtmlModule = require("./HtmlModule");
36
36
 
37
37
  const getMimeTypes = memoize(() => require("../util/mimeTypes"));
@@ -222,6 +222,9 @@ const isIntegrityEnabled = (integrity) =>
222
222
  // `\.html`/`\.css` request matchers for the synthetic `output.html` wrapper.
223
223
  const HTML_REQUEST_RE = /\.html(\?|$)/i;
224
224
  const CSS_REQUEST_RE = /\.css(\?|$)/i;
225
+ // The wrapper's own resource — the media type must end here, so that a
226
+ // `data:text/htmlx,` entry (JavaScript to `DataUriPlugin`) is not one.
227
+ const HTML_DATA_URL_RE = /^data:text\/html[,;]/i;
225
228
 
226
229
  /**
227
230
  * Requests an `output.html` page must load for an entry: its `dependOn`
@@ -238,7 +241,12 @@ const collectHtmlEntryRequests = (name, entries) => {
238
241
  const seenRequests = new Set();
239
242
  /** @type {Set<string>} */
240
243
  const visited = new Set();
241
- const walk = (/** @type {string} */ entryName) => {
244
+ /**
245
+ * Collects an entry's non-html requests, `dependOn` entries included.
246
+ * @param {string} entryName entry to walk
247
+ * @returns {void}
248
+ */
249
+ const walk = (entryName) => {
242
250
  if (visited.has(entryName)) return;
243
251
  visited.add(entryName);
244
252
  const desc = entries[entryName];
@@ -610,12 +618,13 @@ class HtmlModulesPlugin {
610
618
  );
611
619
  }
612
620
  const { htmlModules } = getState(compilation);
613
- // Record HTML modules as they appear — freshly built
614
- // (`succeedModule`) or restored from cache (`stillValidModule`) —
615
- // so `finishMake` creates their entries without scanning every
616
- // module in the graph. Tracking only records; entries are still
617
- // added (and awaited) in `finishMake`.
618
- const trackHtmlModule = (/** @type {import("../Module")} */ module) => {
621
+ /**
622
+ * Records HTML modules as they are built or restored, so `finishMake`
623
+ * creates their entries without scanning the whole module graph.
624
+ * @param {import("../Module")} module built or restored module
625
+ * @returns {void}
626
+ */
627
+ const trackHtmlModule = (module) => {
619
628
  if (module.type !== HTML_MODULE_TYPE) return;
620
629
  // enabled here, not on the compilation hook: an integrity build
621
630
  // with no html module must not load the generator
@@ -714,28 +723,64 @@ class HtmlModulesPlugin {
714
723
  // An inlined chunk file is dead weight once nothing else references
715
724
  // it by URL (another page's tag, or the runtime's async chunk map);
716
725
  // a content-hashed filename makes a substring hit a real reference.
726
+ /** @type {Set<string>} */
727
+ const deletionCandidates = new Set(inlinedFiles);
728
+ // A wrapper entry's chunk only rebuilds the page's own markup; the
729
+ // page loads the `<script src>` entries the parser split out of it.
730
+ for (const entrypoint of compilation.entrypoints.values()) {
731
+ const chunk = entrypoint.getEntrypointChunk();
732
+ if (!chunk) continue;
733
+ let wrapperOnly = false;
734
+ for (const entryModule of compilation.chunkGraph.getChunkEntryModulesIterable(
735
+ chunk
736
+ )) {
737
+ const { resource } = /** @type {import("../NormalModule")} */ (
738
+ entryModule
739
+ );
740
+ wrapperOnly =
741
+ typeof resource === "string" &&
742
+ HTML_DATA_URL_RE.test(resource);
743
+ if (!wrapperOnly) break;
744
+ }
745
+ if (!wrapperOnly) continue;
746
+ for (const file of chunk.files) deletionCandidates.add(file);
747
+ }
717
748
  // Materialize each other asset's source once (it can be expensive to
718
- // render) and test all inlined files against it, rather than
719
- // re-materializing every asset per inlined file.
720
- if (inlinedFiles.size > 0) {
749
+ // render) and test all candidates against it, rather than
750
+ // re-materializing every asset per candidate.
751
+ if (deletionCandidates.size > 0) {
721
752
  /** @type {Set<string>} */
722
753
  const stillReferenced = new Set();
723
- for (const name of Object.keys(compilation.assets)) {
724
- if (
725
- inlinedFiles.has(name) ||
726
- stillReferenced.size === inlinedFiles.size
727
- ) {
728
- continue;
729
- }
754
+ /** @type {string[]} */
755
+ const pending = [];
756
+ /**
757
+ * @param {string} name asset whose source may name a candidate
758
+ */
759
+ const markReferenced = (name) => {
730
760
  const source = compilation.assets[name].source();
731
- if (typeof source !== "string") continue;
732
- for (const file of inlinedFiles) {
761
+ if (typeof source !== "string") return;
762
+ for (const file of deletionCandidates) {
733
763
  if (!stillReferenced.has(file) && source.includes(file)) {
734
764
  stillReferenced.add(file);
765
+ pending.push(file);
735
766
  }
736
767
  }
768
+ };
769
+ for (const name of Object.keys(compilation.assets)) {
770
+ if (
771
+ deletionCandidates.has(name) ||
772
+ stillReferenced.size === deletionCandidates.size
773
+ ) {
774
+ continue;
775
+ }
776
+ markReferenced(name);
777
+ }
778
+ // A kept candidate can reference another through its async chunk
779
+ // map, so follow each until nothing new is kept.
780
+ while (pending.length > 0) {
781
+ markReferenced(/** @type {string} */ (pending.pop()));
737
782
  }
738
- for (const file of inlinedFiles) {
783
+ for (const file of deletionCandidates) {
739
784
  if (!stillReferenced.has(file)) compilation.deleteAsset(file);
740
785
  }
741
786
  }
@@ -896,14 +941,14 @@ class HtmlModulesPlugin {
896
941
  PLUGIN_NAME,
897
942
  (result, module) => {
898
943
  if (module.type === HTML_MODULE_TYPE) {
899
- const [source, ...rest] = result;
944
+ const [source, ...rest] = removeBOMFromResult(result);
900
945
  // `applyTemplate` is a no-op unless `module.parser.html.template`
901
946
  // is set. Running it here (where the returned source becomes the
902
947
  // module's stored source) keeps the parser's dependency offsets
903
948
  // and the generator's render base in sync.
904
949
  const parser = /** @type {HtmlParser} */ (module.parser);
905
950
 
906
- return [parser.applyTemplate(removeBOM(source), module), ...rest];
951
+ return [parser.applyTemplate(source, module), ...rest];
907
952
  }
908
953
 
909
954
  return result;
@@ -942,15 +987,15 @@ class HtmlModulesPlugin {
942
987
  /** @type {WeakMap<import("webpack-sources").Source, { resolvedContent: string, contentHash: string }>} */
943
988
  const resolvedSentinelHashCache = new WeakMap();
944
989
 
945
- // Compute a linked/entry HTML page's emitted filename + chunk-URL-resolved
946
- // content + content hash for one (module, chunk). Shared by the emit loop
947
- // below and the page-link resolver. The content hash covers only the
948
- // chunk-URL-resolved source — links to *other* pages stay sentinels here,
949
- // so a page's filename doesn't depend on the filenames of pages it links to.
950
- const computePageEmit = (
951
- /** @type {NormalModule} */ module,
952
- /** @type {import("../Chunk")} */ chunk
953
- ) => {
990
+ /**
991
+ * Computes an HTML page's emitted filename, chunk-URL-resolved content and
992
+ * content hash. Links to other pages stay sentinels, so a page's filename
993
+ * never depends on the filenames of the pages it links to.
994
+ * @param {NormalModule} module the page's html module
995
+ * @param {import("../Chunk")} chunk chunk the page is emitted from
996
+ * @returns {{ resolvedContent: string, contentHash: string, filename: string, info: import("../Compilation").AssetInfo } | undefined} the page's emit, or `undefined` when it generates no html
997
+ */
998
+ const computePageEmit = (module, chunk) => {
954
999
  const { chunkGraph, outputOptions } = compilation;
955
1000
  const codeGenResult =
956
1001
  /** @type {import("../CodeGenerationResults")} */ (
@@ -1027,14 +1072,15 @@ class HtmlModulesPlugin {
1027
1072
  };
1028
1073
  };
1029
1074
 
1030
- // Emitted filename of a linked `type: "html"` page, keyed by its entry
1031
- // name. Looked up from the page's own entry chunk so it's independent of
1032
- // chunk render order; cached for the compilation.
1033
1075
  /** @type {Map<string, string>} */
1034
1076
  const htmlPageFilenameCache = new Map();
1035
- const computePageFilenameByEntry = (
1036
- /** @type {string} */ entryName
1037
- ) => {
1077
+ /**
1078
+ * Emitted filename of a linked `type: "html"` page, read from the page's
1079
+ * own entry chunk so chunk render order cannot affect it.
1080
+ * @param {string} entryName entry name of the linked page
1081
+ * @returns {string} the page's emitted filename, `"data:,"` when it has none
1082
+ */
1083
+ const computePageFilenameByEntry = (entryName) => {
1038
1084
  const cached = htmlPageFilenameCache.get(entryName);
1039
1085
  if (cached !== undefined) return cached;
1040
1086
  let filename = "data:,";