webpack 4.9.1 → 4.10.2

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 (279) hide show
  1. package/README.md +755 -755
  2. package/SECURITY.md +9 -9
  3. package/buildin/global.js +20 -20
  4. package/buildin/harmony-module.js +24 -24
  5. package/buildin/module.js +22 -22
  6. package/hot/dev-server.js +61 -61
  7. package/hot/log-apply-result.js +44 -44
  8. package/hot/log.js +45 -45
  9. package/hot/only-dev-server.js +105 -105
  10. package/hot/poll.js +37 -37
  11. package/hot/signal.js +62 -62
  12. package/lib/APIPlugin.js +84 -84
  13. package/lib/AmdMainTemplatePlugin.js +87 -75
  14. package/lib/AsyncDependenciesBlock.js +66 -66
  15. package/lib/AsyncDependencyToInitialChunkError.js +31 -21
  16. package/lib/AutomaticPrefetchPlugin.js +50 -50
  17. package/lib/BannerPlugin.js +3 -1
  18. package/lib/BasicEvaluatedExpression.js +211 -208
  19. package/lib/CachePlugin.js +102 -95
  20. package/lib/CaseSensitiveModulesWarning.js +71 -53
  21. package/lib/Chunk.js +750 -722
  22. package/lib/ChunkGroup.js +13 -5
  23. package/lib/ChunkRenderError.js +32 -32
  24. package/lib/CompatibilityPlugin.js +63 -63
  25. package/lib/Compilation.js +1947 -1905
  26. package/lib/Compiler.js +508 -496
  27. package/lib/ConcurrentCompilationError.js +19 -19
  28. package/lib/ConstPlugin.js +258 -242
  29. package/lib/ContextExclusionPlugin.js +17 -17
  30. package/lib/ContextModule.js +749 -710
  31. package/lib/ContextModuleFactory.js +256 -245
  32. package/lib/ContextReplacementPlugin.js +133 -126
  33. package/lib/DefinePlugin.js +206 -197
  34. package/lib/DelegatedModule.js +101 -101
  35. package/lib/DelegatedModuleFactoryPlugin.js +89 -89
  36. package/lib/DelegatedPlugin.js +39 -39
  37. package/lib/DependenciesBlock.js +89 -87
  38. package/lib/DependenciesBlockVariable.js +52 -51
  39. package/lib/Dependency.js +51 -51
  40. package/lib/DllEntryPlugin.js +51 -51
  41. package/lib/DllModule.js +54 -54
  42. package/lib/DllModuleFactory.js +29 -29
  43. package/lib/DllPlugin.js +44 -42
  44. package/lib/DllReferencePlugin.js +84 -84
  45. package/lib/DynamicEntryPlugin.js +73 -71
  46. package/lib/EntryOptionPlugin.js +33 -33
  47. package/lib/EnvironmentPlugin.js +65 -65
  48. package/lib/ErrorHelpers.js +60 -57
  49. package/lib/EvalDevToolModulePlugin.js +27 -27
  50. package/lib/EvalDevToolModuleTemplatePlugin.js +61 -61
  51. package/lib/EvalSourceMapDevToolPlugin.js +41 -40
  52. package/lib/ExportPropertyMainTemplatePlugin.js +53 -40
  53. package/lib/ExtendedAPIPlugin.js +84 -84
  54. package/lib/ExternalModule.js +159 -159
  55. package/lib/ExternalModuleFactoryPlugin.js +110 -110
  56. package/lib/ExternalsPlugin.js +23 -23
  57. package/lib/FlagDependencyExportsPlugin.js +146 -146
  58. package/lib/FlagDependencyUsagePlugin.js +110 -104
  59. package/lib/FlagInitialModulesAsUsedPlugin.js +36 -36
  60. package/lib/FunctionModulePlugin.js +19 -19
  61. package/lib/FunctionModuleTemplatePlugin.js +100 -98
  62. package/lib/GraphHelpers.js +64 -64
  63. package/lib/HarmonyLinkingError.js +18 -18
  64. package/lib/HashedModuleIdsPlugin.js +53 -53
  65. package/lib/HotModuleReplacement.runtime.js +7 -3
  66. package/lib/HotModuleReplacementPlugin.js +413 -406
  67. package/lib/HotUpdateChunk.js +16 -16
  68. package/lib/HotUpdateChunkTemplate.js +78 -78
  69. package/lib/IgnorePlugin.js +71 -71
  70. package/lib/JavascriptGenerator.js +229 -228
  71. package/lib/JavascriptModulesPlugin.js +179 -184
  72. package/lib/JsonGenerator.js +42 -42
  73. package/lib/JsonModulesPlugin.js +30 -30
  74. package/lib/JsonParser.js +27 -26
  75. package/lib/LibManifestPlugin.js +86 -86
  76. package/lib/LibraryTemplatePlugin.js +153 -119
  77. package/lib/LoaderOptionsPlugin.js +53 -52
  78. package/lib/LoaderTargetPlugin.js +24 -24
  79. package/lib/MainTemplate.js +34 -9
  80. package/lib/Module.js +381 -377
  81. package/lib/ModuleBuildError.js +42 -42
  82. package/lib/ModuleDependencyError.js +35 -25
  83. package/lib/ModuleDependencyWarning.js +25 -25
  84. package/lib/ModuleError.js +28 -28
  85. package/lib/ModuleFilenameHelpers.js +178 -166
  86. package/lib/ModuleParseError.js +44 -44
  87. package/lib/ModuleReason.js +40 -40
  88. package/lib/ModuleTemplate.js +84 -84
  89. package/lib/ModuleWarning.js +30 -30
  90. package/lib/MultiCompiler.js +283 -271
  91. package/lib/MultiEntryPlugin.js +58 -58
  92. package/lib/MultiModule.js +81 -78
  93. package/lib/MultiModuleFactory.js +23 -23
  94. package/lib/MultiStats.js +92 -92
  95. package/lib/MultiWatching.js +38 -38
  96. package/lib/NamedChunksPlugin.js +29 -29
  97. package/lib/NamedModulesPlugin.js +57 -57
  98. package/lib/NoEmitOnErrorsPlugin.js +20 -20
  99. package/lib/NoModeWarning.js +23 -23
  100. package/lib/NodeStuffPlugin.js +179 -178
  101. package/lib/NormalModule.js +497 -490
  102. package/lib/NormalModuleFactory.js +501 -483
  103. package/lib/NormalModuleReplacementPlugin.js +51 -51
  104. package/lib/OptionsDefaulter.js +84 -80
  105. package/lib/Parser.js +2164 -2086
  106. package/lib/ParserHelpers.js +103 -100
  107. package/lib/PrefetchPlugin.js +37 -37
  108. package/lib/ProgressPlugin.js +231 -231
  109. package/lib/ProvidePlugin.js +86 -86
  110. package/lib/RawModule.js +56 -54
  111. package/lib/RecordIdsPlugin.js +166 -162
  112. package/lib/RemovedPluginError.js +13 -13
  113. package/lib/RequestShortener.js +81 -74
  114. package/lib/RequireJsStuffPlugin.js +69 -69
  115. package/lib/ResolverFactory.js +64 -64
  116. package/lib/RuleSet.js +555 -534
  117. package/lib/RuntimeTemplate.js +320 -277
  118. package/lib/SetVarMainTemplatePlugin.js +69 -57
  119. package/lib/SingleEntryPlugin.js +44 -44
  120. package/lib/SizeFormatHelpers.js +24 -24
  121. package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -49
  122. package/lib/SourceMapDevToolPlugin.js +301 -300
  123. package/lib/Stats.js +1408 -1367
  124. package/lib/Template.js +4 -2
  125. package/lib/TemplatedPathPlugin.js +173 -170
  126. package/lib/UmdMainTemplatePlugin.js +304 -264
  127. package/lib/UseStrictPlugin.js +48 -48
  128. package/lib/WarnCaseSensitiveModulesPlugin.js +37 -36
  129. package/lib/WarnNoModeSetPlugin.js +17 -17
  130. package/lib/WatchIgnorePlugin.js +100 -100
  131. package/lib/Watching.js +194 -193
  132. package/lib/WebpackError.js +25 -19
  133. package/lib/WebpackOptionsApply.js +421 -405
  134. package/lib/WebpackOptionsDefaulter.js +347 -344
  135. package/lib/WebpackOptionsValidationError.js +345 -316
  136. package/lib/compareLocations.js +56 -56
  137. package/lib/dependencies/AMDDefineDependency.js +137 -137
  138. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +336 -327
  139. package/lib/dependencies/AMDPlugin.js +250 -250
  140. package/lib/dependencies/AMDRequireArrayDependency.js +49 -49
  141. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  142. package/lib/dependencies/AMDRequireDependenciesBlock.js +43 -43
  143. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +273 -270
  144. package/lib/dependencies/AMDRequireDependency.js +135 -135
  145. package/lib/dependencies/CommonJsPlugin.js +161 -161
  146. package/lib/dependencies/CommonJsRequireContextDependency.js +23 -23
  147. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +130 -130
  148. package/lib/dependencies/ConstDependency.js +33 -33
  149. package/lib/dependencies/ContextDependency.js +68 -68
  150. package/lib/dependencies/ContextDependencyTemplateAsId.js +42 -42
  151. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +38 -38
  152. package/lib/dependencies/ContextElementDependency.js +21 -21
  153. package/lib/dependencies/DelegatedExportsDependency.js +33 -33
  154. package/lib/dependencies/DependencyReference.js +18 -18
  155. package/lib/dependencies/HarmonyAcceptDependency.js +45 -45
  156. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  157. package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -31
  158. package/lib/dependencies/HarmonyDetectionParserPlugin.js +92 -90
  159. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +139 -139
  160. package/lib/dependencies/HarmonyExportExpressionDependency.js +53 -53
  161. package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -30
  162. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -603
  163. package/lib/dependencies/HarmonyExportSpecifierDependency.js +54 -54
  164. package/lib/dependencies/HarmonyImportDependency.js +104 -94
  165. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -214
  166. package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -31
  167. package/lib/dependencies/HarmonyImportSpecifierDependency.js +166 -156
  168. package/lib/dependencies/HarmonyInitDependency.js +60 -60
  169. package/lib/dependencies/HarmonyModulesPlugin.js +146 -146
  170. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -26
  171. package/lib/dependencies/ImportContextDependency.js +23 -23
  172. package/lib/dependencies/ImportDependenciesBlock.js +18 -18
  173. package/lib/dependencies/ImportDependency.js +34 -34
  174. package/lib/dependencies/ImportEagerDependency.js +32 -32
  175. package/lib/dependencies/ImportParserPlugin.js +233 -232
  176. package/lib/dependencies/ImportPlugin.js +82 -82
  177. package/lib/dependencies/ImportWeakDependency.js +34 -34
  178. package/lib/dependencies/JsonExportsDependency.js +26 -26
  179. package/lib/dependencies/LoaderPlugin.js +98 -93
  180. package/lib/dependencies/LocalModuleDependency.js +28 -28
  181. package/lib/dependencies/LocalModulesHelpers.js +52 -45
  182. package/lib/dependencies/ModuleDependency.js +20 -20
  183. package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -17
  184. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -17
  185. package/lib/dependencies/MultiEntryDependency.js +20 -20
  186. package/lib/dependencies/NullDependency.js +20 -20
  187. package/lib/dependencies/RequireContextDependency.js +22 -22
  188. package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -56
  189. package/lib/dependencies/RequireContextPlugin.js +143 -141
  190. package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -33
  191. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -112
  192. package/lib/dependencies/RequireEnsureDependency.js +58 -58
  193. package/lib/dependencies/RequireEnsurePlugin.js +74 -74
  194. package/lib/dependencies/RequireHeaderDependency.js +26 -26
  195. package/lib/dependencies/RequireIncludeDependency.js +39 -39
  196. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -23
  197. package/lib/dependencies/RequireIncludePlugin.js +61 -61
  198. package/lib/dependencies/RequireResolveContextDependency.js +23 -23
  199. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +85 -85
  200. package/lib/dependencies/RequireResolveHeaderDependency.js +26 -26
  201. package/lib/dependencies/SingleEntryDependency.js +18 -18
  202. package/lib/dependencies/SystemPlugin.js +125 -125
  203. package/lib/dependencies/UnsupportedDependency.js +27 -27
  204. package/lib/dependencies/WebAssemblyImportDependency.js +48 -44
  205. package/lib/dependencies/WebpackMissingModule.js +20 -20
  206. package/lib/dependencies/getFunctionExpression.js +52 -52
  207. package/lib/formatLocation.js +61 -53
  208. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  209. package/lib/node/NodeEnvironmentPlugin.js +28 -28
  210. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  211. package/lib/node/NodeMainTemplate.runtime.js +27 -27
  212. package/lib/node/NodeMainTemplateAsync.runtime.js +44 -44
  213. package/lib/node/NodeMainTemplatePlugin.js +323 -320
  214. package/lib/node/NodeSourcePlugin.js +144 -140
  215. package/lib/node/NodeTargetPlugin.js +18 -18
  216. package/lib/node/NodeTemplatePlugin.js +31 -31
  217. package/lib/node/NodeWatchFileSystem.js +99 -82
  218. package/lib/node/ReadFileCompileWasmTemplatePlugin.js +52 -52
  219. package/lib/optimize/AggressiveMergingPlugin.js +87 -87
  220. package/lib/optimize/AggressiveSplittingPlugin.js +287 -281
  221. package/lib/optimize/ChunkModuleIdRangePlugin.js +68 -68
  222. package/lib/optimize/ConcatenatedModule.js +1420 -1413
  223. package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -70
  224. package/lib/optimize/FlagIncludedChunksPlugin.js +99 -99
  225. package/lib/optimize/LimitChunkCountPlugin.js +66 -66
  226. package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -75
  227. package/lib/optimize/MinChunkSizePlugin.js +77 -77
  228. package/lib/optimize/ModuleConcatenationPlugin.js +470 -457
  229. package/lib/optimize/OccurrenceOrderPlugin.js +133 -126
  230. package/lib/optimize/RemoveParentModulesPlugin.js +127 -117
  231. package/lib/optimize/RuntimeChunkPlugin.js +41 -41
  232. package/lib/optimize/SideEffectsFlagPlugin.js +158 -156
  233. package/lib/optimize/SplitChunksPlugin.js +709 -696
  234. package/lib/performance/AssetsOverSizeLimitWarning.js +30 -30
  235. package/lib/performance/EntrypointsOverSizeLimitWarning.js +31 -31
  236. package/lib/performance/NoAsyncChunksWarning.js +21 -21
  237. package/lib/performance/SizeLimitsPlugin.js +105 -105
  238. package/lib/util/Semaphore.js +41 -41
  239. package/lib/util/SortableSet.js +5 -2
  240. package/lib/util/StackedSetMap.js +12 -5
  241. package/lib/util/TrackingSet.js +35 -35
  242. package/lib/util/cachedMerge.js +35 -35
  243. package/lib/util/createHash.js +77 -77
  244. package/lib/util/identifier.js +76 -76
  245. package/lib/validateSchema.js +67 -67
  246. package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +18 -18
  247. package/lib/wasm/WasmMainTemplatePlugin.js +310 -304
  248. package/lib/wasm/WebAssemblyGenerator.js +143 -19
  249. package/lib/wasm/WebAssemblyJavascriptGenerator.js +90 -107
  250. package/lib/wasm/WebAssemblyModulesPlugin.js +80 -80
  251. package/lib/wasm/WebAssemblyParser.js +28 -5
  252. package/lib/wasm/WebAssemblyUtils.js +48 -0
  253. package/lib/web/FetchCompileWasmTemplatePlugin.js +25 -25
  254. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  255. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  256. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  257. package/lib/web/JsonpMainTemplate.runtime.js +65 -64
  258. package/lib/web/JsonpMainTemplatePlugin.js +576 -574
  259. package/lib/web/JsonpTemplatePlugin.js +23 -23
  260. package/lib/webpack.js +183 -182
  261. package/lib/webpack.web.js +31 -31
  262. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  263. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  264. package/lib/webworker/WebWorkerMainTemplate.runtime.js +65 -64
  265. package/lib/webworker/WebWorkerMainTemplatePlugin.js +179 -179
  266. package/lib/webworker/WebWorkerTemplatePlugin.js +25 -25
  267. package/package.json +9 -8
  268. package/schemas/WebpackOptions.json +1988 -1988
  269. package/schemas/ajv.absolutePath.js +55 -55
  270. package/schemas/plugins/DllPlugin.json +32 -32
  271. package/schemas/plugins/DllReferencePlugin.json +99 -99
  272. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  273. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  274. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  275. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  276. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  277. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  278. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  279. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
package/lib/Chunk.js CHANGED
@@ -1,722 +1,750 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const util = require("util");
8
- const SortableSet = require("./util/SortableSet");
9
- const intersect = require("./util/SetHelpers").intersect;
10
- const GraphHelpers = require("./GraphHelpers");
11
- let debugId = 1000;
12
- const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
13
- const ERR_CHUNK_INITIAL =
14
- "Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
15
-
16
- /** @typedef {import("./Module.js")} Module */
17
- /** @typedef {import("./ChunkGroup")} ChunkGroup */
18
- /** @typedef {import("./ModuleReason.js")} ModuleReason */
19
- /** @typedef {import("webpack-sources").Source} Source */
20
-
21
- /**
22
- * @typedef {Object} Identifiable an object who contains an identifier function property
23
- * @property {() => string} identifier the resource or unique identifier of something
24
- */
25
-
26
- /**
27
- * @typedef {Object} WithId an object who has an id property
28
- * @property {string} id the id of the object
29
- */
30
-
31
- /** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */
32
- /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
33
- /** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */
34
-
35
- /**
36
- * @param {WithId} a object that contains an ID property
37
- * @param {WithId} b object that contains an ID property
38
- * @returns {-1|0|1} sort value
39
- */
40
- const sortById = (a, b) => {
41
- if (a.id < b.id) return -1;
42
- if (b.id < a.id) return 1;
43
- return 0;
44
- };
45
-
46
- /**
47
- *
48
- * @param {Identifiable} a first object with ident fn
49
- * @param {Identifiable} b second object with ident fn
50
- * @returns {-1|0|1} The order number of the sort
51
- */
52
- const sortByIdentifier = (a, b) => {
53
- if (a.identifier() > b.identifier()) return 1;
54
- if (a.identifier() < b.identifier()) return -1;
55
- return 0;
56
- };
57
-
58
- /**
59
- * @returns {string} a concatenation of module identifiers sorted
60
- * @param {SortableSet} set to pull module identifiers from
61
- */
62
- const getModulesIdent = set => {
63
- set.sort();
64
- let str = "";
65
- for (const m of set) {
66
- str += m.identifier() + "#";
67
- }
68
- return str;
69
- };
70
-
71
- /**
72
- * @template {T}
73
- * @param {Set<T>} set the set to convert to array
74
- * @returns {Array<T>} the array returned from Array.from(set)
75
- */
76
- const getArray = set => Array.from(set);
77
-
78
- /**
79
- * @param {Set<Module>} set the Set to get the count/size of
80
- * @returns {number} the size of the modules
81
- */
82
- const getModulesSize = set => {
83
- let size = 0;
84
- for (const module of set) {
85
- size += module.size();
86
- }
87
- return size;
88
- };
89
-
90
- /**
91
- * A Chunk is a unit of encapsulation for Modules.
92
- * Chunks are "rendered" into bundles that get emitted when the build completes.
93
- */
94
- class Chunk {
95
- /**
96
- * @param {string=} name of chunk being created, is optional (for subclasses)
97
- */
98
- constructor(name) {
99
- /** @type {number | null} */
100
- this.id = null;
101
- /** @type {number[] | null} */
102
- this.ids = null;
103
- /** @type {number} */
104
- this.debugId = debugId++;
105
- /** @type {string} */
106
- this.name = name;
107
- /** @type {boolean} */
108
- this.preventIntegration = false;
109
- /** @type {Module=} */
110
- this.entryModule = undefined;
111
- //TODO make these typed generics for Module[] and ChunkGroup[] and their sort being (T, T): => 1,-1,0
112
- //See https://github.com/webpack/webpack/pull/7046
113
- /** @private */
114
- this._modules = new SortableSet(undefined, sortByIdentifier);
115
- /** @private */
116
- this._groups = new SortableSet(undefined, sortById);
117
- /** @type {Source[]} */
118
- this.files = [];
119
- /** @type {boolean} */
120
- this.rendered = false;
121
- /** @type {string=} */
122
- this.hash = undefined;
123
- /** @type {Object} */
124
- this.contentHash = Object.create(null);
125
- /** @type {string=} */
126
- this.renderedHash = undefined;
127
- /** @type {string=} */
128
- this.chunkReason = undefined;
129
- /** @type {boolean} */
130
- this.extraAsync = false;
131
- this.removedModules = undefined;
132
- }
133
-
134
- /**
135
- * @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead
136
- * @returns {never} Throws an error trying to access this property
137
- */
138
- get entry() {
139
- throw new Error(ERR_CHUNK_ENTRY);
140
- }
141
-
142
- /**
143
- * @deprecated .entry has been deprecated. Please use .hasRuntime() instead
144
- * @param {never} data The data that was attempting to be set
145
- * @returns {never} Throws an error trying to access this property
146
- */
147
- set entry(data) {
148
- throw new Error(ERR_CHUNK_ENTRY);
149
- }
150
-
151
- /**
152
- * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
153
- * @returns {never} Throws an error trying to access this property
154
- */
155
- get initial() {
156
- throw new Error(ERR_CHUNK_INITIAL);
157
- }
158
-
159
- /**
160
- * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
161
- * @param {never} data The data attempting to be set
162
- * @returns {never} Throws an error trying to access this property
163
- */
164
- set initial(data) {
165
- throw new Error(ERR_CHUNK_INITIAL);
166
- }
167
-
168
- /**
169
- * @returns {boolean} whether or not the Chunk will have a runtime
170
- */
171
- hasRuntime() {
172
- for (const chunkGroup of this._groups) {
173
- // We only need to check the first one
174
- return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this;
175
- }
176
- return false;
177
- }
178
-
179
- /**
180
- * @returns {boolean} whether or not this chunk can be an initial chunk
181
- */
182
- canBeInitial() {
183
- for (const chunkGroup of this._groups) {
184
- if (chunkGroup.isInitial()) return true;
185
- }
186
- return false;
187
- }
188
-
189
- /**
190
- * @returns {boolean} whether this chunk can only be an initial chunk
191
- */
192
- isOnlyInitial() {
193
- if (this._groups.size <= 0) return false;
194
- for (const chunkGroup of this._groups) {
195
- if (!chunkGroup.isInitial()) return false;
196
- }
197
- return true;
198
- }
199
-
200
- /**
201
- * @returns {boolean} if this chunk contains the entry module
202
- */
203
- hasEntryModule() {
204
- return !!this.entryModule;
205
- }
206
-
207
- /**
208
- * @param {Module} module the module that will be added to this chunk.
209
- * @returns {boolean} returns true if the chunk doesn't have the module and it was added
210
- */
211
- addModule(module) {
212
- if (!this._modules.has(module)) {
213
- this._modules.add(module);
214
- return true;
215
- }
216
- return false;
217
- }
218
-
219
- /**
220
- * @param {Module} module the module that will be removed from this chunk
221
- * @returns {boolean} returns true if chunk exists and is successfully deleted
222
- */
223
- removeModule(module) {
224
- if (this._modules.delete(module)) {
225
- module.removeChunk(this);
226
- return true;
227
- }
228
- return false;
229
- }
230
-
231
- /**
232
- * @param {Module[]} modules the new modules to be set
233
- * @returns {void} set new modules to this chunk and return nothing
234
- */
235
- setModules(modules) {
236
- this._modules = new SortableSet(modules, sortByIdentifier);
237
- }
238
-
239
- /**
240
- * @returns {number} the amount of modules in chunk
241
- */
242
- getNumberOfModules() {
243
- return this._modules.size;
244
- }
245
-
246
- /**
247
- * @returns {SortableSet} return the modules SortableSet for this chunk
248
- */
249
- get modulesIterable() {
250
- return this._modules;
251
- }
252
-
253
- /**
254
- * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added
255
- * @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully
256
- */
257
- addGroup(chunkGroup) {
258
- if (this._groups.has(chunkGroup)) return false;
259
- this._groups.add(chunkGroup);
260
- return true;
261
- }
262
-
263
- /**
264
- * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from
265
- * @returns {boolean} returns true if chunk does exist in chunkGroup and is removed
266
- */
267
- removeGroup(chunkGroup) {
268
- if (!this._groups.has(chunkGroup)) return false;
269
- this._groups.delete(chunkGroup);
270
- return true;
271
- }
272
-
273
- /**
274
- * @param {ChunkGroup} chunkGroup the chunkGroup to check
275
- * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup
276
- */
277
- isInGroup(chunkGroup) {
278
- return this._groups.has(chunkGroup);
279
- }
280
-
281
- /**
282
- * @returns {number} the amount of groups said chunk is in
283
- */
284
- getNumberOfGroups() {
285
- return this._groups.size;
286
- }
287
-
288
- /**
289
- * @returns {SortableSet} the chunkGroups that said chunk is referenced in
290
- */
291
- get groupsIterable() {
292
- return this._groups;
293
- }
294
-
295
- /**
296
- * @param {Chunk} otherChunk the chunk to compare itself with
297
- * @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order
298
- */
299
- compareTo(otherChunk) {
300
- this._modules.sort();
301
- otherChunk._modules.sort();
302
- if (this._modules.size > otherChunk._modules.size) return -1;
303
- if (this._modules.size < otherChunk._modules.size) return 1;
304
- const a = this._modules[Symbol.iterator]();
305
- const b = otherChunk._modules[Symbol.iterator]();
306
- // eslint-disable-next-line
307
- while (true) {
308
- const aItem = a.next();
309
- const bItem = b.next();
310
- if (aItem.done) return 0;
311
- const aModuleIdentifier = aItem.value.identifier();
312
- const bModuleIdentifier = bItem.value.identifier();
313
- if (aModuleIdentifier < bModuleIdentifier) return -1;
314
- if (aModuleIdentifier > bModuleIdentifier) return 1;
315
- }
316
- }
317
-
318
- /**
319
- * @param {Module} module Module to check
320
- * @returns {boolean} returns true if module does exist in this chunk
321
- */
322
- containsModule(module) {
323
- return this._modules.has(module);
324
- }
325
-
326
- getModules() {
327
- return this._modules.getFromCache(getArray);
328
- }
329
-
330
- getModulesIdent() {
331
- return this._modules.getFromUnorderedCache(getModulesIdent);
332
- }
333
-
334
- remove() {
335
- // cleanup modules
336
- // Array.from is used here to create a clone, because removeChunk modifies this._modules
337
- for (const module of Array.from(this._modules)) {
338
- module.removeChunk(this);
339
- }
340
- for (const chunkGroup of this._groups) {
341
- chunkGroup.removeChunk(this);
342
- }
343
- }
344
-
345
- /**
346
- *
347
- * @param {Module} module module to move
348
- * @param {Chunk} otherChunk other chunk to move it to
349
- * @returns {void}
350
- */
351
- moveModule(module, otherChunk) {
352
- GraphHelpers.disconnectChunkAndModule(this, module);
353
- GraphHelpers.connectChunkAndModule(otherChunk, module);
354
- module.rewriteChunkInReasons(this, [otherChunk]);
355
- }
356
-
357
- /**
358
- *
359
- * @param {Chunk} otherChunk the chunk to integrate with
360
- * @param {ModuleReason} reason reason why the module is being integrated
361
- * @returns {boolean} returns true or false if integration succeeds or fails
362
- */
363
- integrate(otherChunk, reason) {
364
- if (!this.canBeIntegrated(otherChunk)) {
365
- return false;
366
- }
367
-
368
- // Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
369
- for (const module of Array.from(otherChunk._modules)) {
370
- otherChunk.moveModule(module, this);
371
- }
372
- otherChunk._modules.clear();
373
-
374
- for (const chunkGroup of otherChunk._groups) {
375
- chunkGroup.replaceChunk(otherChunk, this);
376
- this.addGroup(chunkGroup);
377
- }
378
- otherChunk._groups.clear();
379
-
380
- if (this.name && otherChunk.name) {
381
- if (this.name.length !== otherChunk.name.length)
382
- this.name =
383
- this.name.length < otherChunk.name.length
384
- ? this.name
385
- : otherChunk.name;
386
- else
387
- this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
388
- }
389
-
390
- return true;
391
- }
392
-
393
- /**
394
- * @param {Chunk} newChunk the new chunk that will be split out of, and then chunk raphi twil=
395
- * @returns {void}
396
- */
397
- split(newChunk) {
398
- for (const chunkGroup of this._groups) {
399
- chunkGroup.insertChunk(newChunk, this);
400
- newChunk.addGroup(chunkGroup);
401
- }
402
- }
403
-
404
- isEmpty() {
405
- return this._modules.size === 0;
406
- }
407
-
408
- updateHash(hash) {
409
- hash.update(`${this.id} `);
410
- hash.update(this.ids ? this.ids.join(",") : "");
411
- hash.update(`${this.name || ""} `);
412
- for (const m of this._modules) {
413
- hash.update(m.hash);
414
- }
415
- }
416
-
417
- canBeIntegrated(otherChunk) {
418
- const isAvailable = (a, b) => {
419
- const queue = new Set(b.groupsIterable);
420
- for (const chunkGroup of queue) {
421
- if (a.isInGroup(chunkGroup)) continue;
422
- if (chunkGroup.isInitial()) return false;
423
- for (const parent of chunkGroup.parentsIterable) queue.add(parent);
424
- }
425
- return true;
426
- };
427
-
428
- if (this.preventIntegration || otherChunk.preventIntegration) return false;
429
-
430
- if (this.hasRuntime() !== otherChunk.hasRuntime()) {
431
- if (this.hasRuntime()) {
432
- return isAvailable(this, otherChunk);
433
- } else if (otherChunk.hasRuntime()) {
434
- return isAvailable(otherChunk, this);
435
- } else {
436
- return false;
437
- }
438
- }
439
- if (this.hasEntryModule() || otherChunk.hasEntryModule()) return false;
440
- return true;
441
- }
442
-
443
- /**
444
- *
445
- * @param {number} size the size
446
- * @param {Object} options the options passed in
447
- * @returns {number} the multiplier returned
448
- */
449
- addMultiplierAndOverhead(size, options) {
450
- const overhead =
451
- typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
452
- const multiplicator = this.canBeInitial()
453
- ? options.entryChunkMultiplicator || 10
454
- : 1;
455
-
456
- return size * multiplicator + overhead;
457
- }
458
-
459
- /**
460
- * @returns {number} the size of all modules
461
- */
462
- modulesSize() {
463
- return this._modules.getFromUnorderedCache(getModulesSize);
464
- }
465
-
466
- /**
467
- * @param {Object} options the size display options
468
- * @returns {number} the chunk size
469
- */
470
- size(options) {
471
- return this.addMultiplierAndOverhead(this.modulesSize(), options);
472
- }
473
-
474
- integratedSize(otherChunk, options) {
475
- // Chunk if it's possible to integrate this chunk
476
- if (!this.canBeIntegrated(otherChunk)) {
477
- return false;
478
- }
479
-
480
- let integratedModulesSize = this.modulesSize();
481
- // only count modules that do not exist in this chunk!
482
- for (const otherModule of otherChunk._modules) {
483
- if (!this._modules.has(otherModule)) {
484
- integratedModulesSize += otherModule.size();
485
- }
486
- }
487
-
488
- return this.addMultiplierAndOverhead(integratedModulesSize, options);
489
- }
490
-
491
- /**
492
- * @param {ModuleSortPredicate=} sortByFn a predicate function used to sort modules
493
- * @returns {void}
494
- */
495
- sortModules(sortByFn) {
496
- this._modules.sortWith(sortByFn || sortById);
497
- }
498
-
499
- sortItems(sortChunks) {
500
- this.sortModules();
501
- }
502
-
503
- getAllAsyncChunks() {
504
- const queue = new Set();
505
- const chunks = new Set();
506
-
507
- const initialChunks = intersect(
508
- Array.from(this.groupsIterable, g => new Set(g.chunks))
509
- );
510
-
511
- for (const chunkGroup of this.groupsIterable) {
512
- for (const child of chunkGroup.childrenIterable) queue.add(child);
513
- }
514
-
515
- for (const chunkGroup of queue) {
516
- for (const chunk of chunkGroup.chunks) {
517
- if (!initialChunks.has(chunk)) chunks.add(chunk);
518
- }
519
- for (const child of chunkGroup.childrenIterable) queue.add(child);
520
- }
521
-
522
- return chunks;
523
- }
524
-
525
- getChunkMaps(realHash) {
526
- const chunkHashMap = Object.create(null);
527
- const chunkContentHashMap = Object.create(null);
528
- const chunkNameMap = Object.create(null);
529
-
530
- for (const chunk of this.getAllAsyncChunks()) {
531
- chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
532
- for (const key of Object.keys(chunk.contentHash)) {
533
- if (!chunkContentHashMap[key])
534
- chunkContentHashMap[key] = Object.create(null);
535
- chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
536
- }
537
- if (chunk.name) chunkNameMap[chunk.id] = chunk.name;
538
- }
539
-
540
- return {
541
- hash: chunkHashMap,
542
- contentHash: chunkContentHashMap,
543
- name: chunkNameMap
544
- };
545
- }
546
-
547
- getChildIdsByOrders() {
548
- const lists = new Map();
549
- for (const group of this.groupsIterable) {
550
- if (group.chunks[group.chunks.length - 1] === this) {
551
- for (const childGroup of group.childrenIterable) {
552
- // TODO webpack 5 remove this check for options
553
- if (typeof childGroup.options === "object") {
554
- for (const key of Object.keys(childGroup.options)) {
555
- if (key.endsWith("Order")) {
556
- const name = key.substr(0, key.length - "Order".length);
557
- let list = lists.get(name);
558
- if (list === undefined) lists.set(name, (list = []));
559
- list.push({
560
- order: childGroup.options[key],
561
- group: childGroup
562
- });
563
- }
564
- }
565
- }
566
- }
567
- }
568
- }
569
- const result = Object.create(null);
570
- for (const [name, list] of lists) {
571
- list.sort((a, b) => {
572
- const cmp = b.order - a.order;
573
- if (cmp !== 0) return cmp;
574
- // TOOD webpack 5 remove this check of compareTo
575
- if (a.group.compareTo) return a.group.compareTo(b.group);
576
- return 0;
577
- });
578
- result[name] = Array.from(
579
- list.reduce((set, item) => {
580
- for (const chunk of item.group.chunks) set.add(chunk.id);
581
- return set;
582
- }, new Set())
583
- );
584
- }
585
- return result;
586
- }
587
-
588
- getChildIdsByOrdersMap() {
589
- const chunkMaps = Object.create(null);
590
-
591
- for (const chunk of this.getAllAsyncChunks()) {
592
- const data = chunk.getChildIdsByOrders();
593
- for (const key of Object.keys(data)) {
594
- let chunkMap = chunkMaps[key];
595
- if (chunkMap === undefined)
596
- chunkMaps[key] = chunkMap = Object.create(null);
597
- chunkMap[chunk.id] = data[key];
598
- }
599
- }
600
- return chunkMaps;
601
- }
602
-
603
- getChunkModuleMaps(filterFn) {
604
- const chunkModuleIdMap = Object.create(null);
605
- const chunkModuleHashMap = Object.create(null);
606
-
607
- for (const chunk of this.getAllAsyncChunks()) {
608
- let array;
609
- for (const module of chunk.modulesIterable) {
610
- if (filterFn(module)) {
611
- if (array === undefined) {
612
- array = [];
613
- chunkModuleIdMap[chunk.id] = array;
614
- }
615
- array.push(module.id);
616
- chunkModuleHashMap[module.id] = module.renderedHash;
617
- }
618
- }
619
- if (array !== undefined) {
620
- array.sort();
621
- }
622
- }
623
-
624
- return {
625
- id: chunkModuleIdMap,
626
- hash: chunkModuleHashMap
627
- };
628
- }
629
-
630
- /**
631
- *
632
- * @param {ModuleFilterPredicate} filterFn predicate function used to filter modules
633
- * @param {ChunkFilterPredicate} filterChunkFn predicate function used to filter chunks
634
- * @returns {boolean} return true if module exists in graph
635
- */
636
- hasModuleInGraph(filterFn, filterChunkFn) {
637
- const queue = new Set(this.groupsIterable);
638
- const chunksProcessed = new Set();
639
-
640
- for (const chunkGroup of queue) {
641
- for (const chunk of chunkGroup.chunks) {
642
- if (!chunksProcessed.has(chunk)) {
643
- chunksProcessed.add(chunk);
644
- if (!filterChunkFn || filterChunkFn(chunk)) {
645
- for (const module of chunk.modulesIterable)
646
- if (filterFn(module)) return true;
647
- }
648
- }
649
- }
650
- for (const child of chunkGroup.childrenIterable) queue.add(child);
651
- }
652
- return false;
653
- }
654
-
655
- toString() {
656
- return `Chunk[${Array.from(this._modules).join()}]`;
657
- }
658
- }
659
-
660
- // TODO remove in webpack 5
661
- Object.defineProperty(Chunk.prototype, "forEachModule", {
662
- configurable: false,
663
- value: util.deprecate(function(fn) {
664
- this._modules.forEach(fn);
665
- }, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead")
666
- });
667
-
668
- // TODO remove in webpack 5
669
- Object.defineProperty(Chunk.prototype, "mapModules", {
670
- configurable: false,
671
- value: util.deprecate(function(fn) {
672
- return Array.from(this._modules, fn);
673
- }, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead")
674
- });
675
-
676
- // TODO remove in webpack 5
677
- Object.defineProperty(Chunk.prototype, "chunks", {
678
- configurable: false,
679
- get() {
680
- throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
681
- },
682
- set() {
683
- throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
684
- }
685
- });
686
-
687
- // TODO remove in webpack 5
688
- Object.defineProperty(Chunk.prototype, "parents", {
689
- configurable: false,
690
- get() {
691
- throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
692
- },
693
- set() {
694
- throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
695
- }
696
- });
697
-
698
- // TODO remove in webpack 5
699
- Object.defineProperty(Chunk.prototype, "blocks", {
700
- configurable: false,
701
- get() {
702
- throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
703
- },
704
- set() {
705
- throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
706
- }
707
- });
708
-
709
- // TODO remove in webpack 5
710
- Object.defineProperty(Chunk.prototype, "entrypoints", {
711
- configurable: false,
712
- get() {
713
- throw new Error(
714
- "Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
715
- );
716
- },
717
- set() {
718
- throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
719
- }
720
- });
721
-
722
- module.exports = Chunk;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const util = require("util");
8
+ const SortableSet = require("./util/SortableSet");
9
+ const intersect = require("./util/SetHelpers").intersect;
10
+ const GraphHelpers = require("./GraphHelpers");
11
+ let debugId = 1000;
12
+ const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
13
+ const ERR_CHUNK_INITIAL =
14
+ "Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
15
+
16
+ /** @typedef {import("./Module.js")} Module */
17
+ /** @typedef {import("./ChunkGroup")} ChunkGroup */
18
+ /** @typedef {import("./ModuleReason.js")} ModuleReason */
19
+ /** @typedef {import("webpack-sources").Source} Source */
20
+
21
+ /**
22
+ * @typedef {Object} Identifiable an object who contains an identifier function property
23
+ * @property {() => string} identifier the resource or unique identifier of something
24
+ */
25
+
26
+ /**
27
+ * @typedef {Object} WithId an object who has an id property
28
+ * @property {string} id the id of the object
29
+ */
30
+
31
+ /** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */
32
+ /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
33
+ /** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */
34
+
35
+ /**
36
+ * @param {WithId} a object that contains an ID property
37
+ * @param {WithId} b object that contains an ID property
38
+ * @returns {-1|0|1} sort value
39
+ */
40
+ const sortById = (a, b) => {
41
+ if (a.id < b.id) return -1;
42
+ if (b.id < a.id) return 1;
43
+ return 0;
44
+ };
45
+
46
+ /**
47
+ *
48
+ * @param {Identifiable} a first object with ident fn
49
+ * @param {Identifiable} b second object with ident fn
50
+ * @returns {-1|0|1} The order number of the sort
51
+ */
52
+ const sortByIdentifier = (a, b) => {
53
+ if (a.identifier() > b.identifier()) return 1;
54
+ if (a.identifier() < b.identifier()) return -1;
55
+ return 0;
56
+ };
57
+
58
+ /**
59
+ * @returns {string} a concatenation of module identifiers sorted
60
+ * @param {SortableSet} set to pull module identifiers from
61
+ */
62
+ const getModulesIdent = set => {
63
+ set.sort();
64
+ let str = "";
65
+ for (const m of set) {
66
+ str += m.identifier() + "#";
67
+ }
68
+ return str;
69
+ };
70
+
71
+ /**
72
+ * @template {T}
73
+ * @param {Set<T>} set the set to convert to array
74
+ * @returns {Array<T>} the array returned from Array.from(set)
75
+ */
76
+ const getArray = set => Array.from(set);
77
+
78
+ /**
79
+ * @param {Set<Module>} set the Set to get the count/size of
80
+ * @returns {number} the size of the modules
81
+ */
82
+ const getModulesSize = set => {
83
+ let size = 0;
84
+ for (const module of set) {
85
+ size += module.size();
86
+ }
87
+ return size;
88
+ };
89
+
90
+ /**
91
+ * A Chunk is a unit of encapsulation for Modules.
92
+ * Chunks are "rendered" into bundles that get emitted when the build completes.
93
+ */
94
+ class Chunk {
95
+ /**
96
+ * @param {string=} name of chunk being created, is optional (for subclasses)
97
+ */
98
+ constructor(name) {
99
+ /** @type {number | null} */
100
+ this.id = null;
101
+ /** @type {number[] | null} */
102
+ this.ids = null;
103
+ /** @type {number} */
104
+ this.debugId = debugId++;
105
+ /** @type {string} */
106
+ this.name = name;
107
+ /** @type {boolean} */
108
+ this.preventIntegration = false;
109
+ /** @type {Module=} */
110
+ this.entryModule = undefined;
111
+ //TODO make these typed generics for Module[] and ChunkGroup[] and their sort being (T, T): => 1,-1,0
112
+ //See https://github.com/webpack/webpack/pull/7046
113
+ /** @private */
114
+ this._modules = new SortableSet(undefined, sortByIdentifier);
115
+ /** @private */
116
+ this._groups = new SortableSet(undefined, sortById);
117
+ /** @type {Source[]} */
118
+ this.files = [];
119
+ /** @type {boolean} */
120
+ this.rendered = false;
121
+ /** @type {string=} */
122
+ this.hash = undefined;
123
+ /** @type {Object} */
124
+ this.contentHash = Object.create(null);
125
+ /** @type {string=} */
126
+ this.renderedHash = undefined;
127
+ /** @type {string=} */
128
+ this.chunkReason = undefined;
129
+ /** @type {boolean} */
130
+ this.extraAsync = false;
131
+ this.removedModules = undefined;
132
+ }
133
+
134
+ /**
135
+ * @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead
136
+ * @returns {never} Throws an error trying to access this property
137
+ */
138
+ get entry() {
139
+ throw new Error(ERR_CHUNK_ENTRY);
140
+ }
141
+
142
+ /**
143
+ * @deprecated .entry has been deprecated. Please use .hasRuntime() instead
144
+ * @param {never} data The data that was attempting to be set
145
+ * @returns {never} Throws an error trying to access this property
146
+ */
147
+ set entry(data) {
148
+ throw new Error(ERR_CHUNK_ENTRY);
149
+ }
150
+
151
+ /**
152
+ * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
153
+ * @returns {never} Throws an error trying to access this property
154
+ */
155
+ get initial() {
156
+ throw new Error(ERR_CHUNK_INITIAL);
157
+ }
158
+
159
+ /**
160
+ * @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
161
+ * @param {never} data The data attempting to be set
162
+ * @returns {never} Throws an error trying to access this property
163
+ */
164
+ set initial(data) {
165
+ throw new Error(ERR_CHUNK_INITIAL);
166
+ }
167
+
168
+ /**
169
+ * @returns {boolean} whether or not the Chunk will have a runtime
170
+ */
171
+ hasRuntime() {
172
+ for (const chunkGroup of this._groups) {
173
+ // We only need to check the first one
174
+ return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this;
175
+ }
176
+ return false;
177
+ }
178
+
179
+ /**
180
+ * @returns {boolean} whether or not this chunk can be an initial chunk
181
+ */
182
+ canBeInitial() {
183
+ for (const chunkGroup of this._groups) {
184
+ if (chunkGroup.isInitial()) return true;
185
+ }
186
+ return false;
187
+ }
188
+
189
+ /**
190
+ * @returns {boolean} whether this chunk can only be an initial chunk
191
+ */
192
+ isOnlyInitial() {
193
+ if (this._groups.size <= 0) return false;
194
+ for (const chunkGroup of this._groups) {
195
+ if (!chunkGroup.isInitial()) return false;
196
+ }
197
+ return true;
198
+ }
199
+
200
+ /**
201
+ * @returns {boolean} if this chunk contains the entry module
202
+ */
203
+ hasEntryModule() {
204
+ return !!this.entryModule;
205
+ }
206
+
207
+ /**
208
+ * @param {Module} module the module that will be added to this chunk.
209
+ * @returns {boolean} returns true if the chunk doesn't have the module and it was added
210
+ */
211
+ addModule(module) {
212
+ if (!this._modules.has(module)) {
213
+ this._modules.add(module);
214
+ return true;
215
+ }
216
+ return false;
217
+ }
218
+
219
+ /**
220
+ * @param {Module} module the module that will be removed from this chunk
221
+ * @returns {boolean} returns true if chunk exists and is successfully deleted
222
+ */
223
+ removeModule(module) {
224
+ if (this._modules.delete(module)) {
225
+ module.removeChunk(this);
226
+ return true;
227
+ }
228
+ return false;
229
+ }
230
+
231
+ /**
232
+ * @param {Module[]} modules the new modules to be set
233
+ * @returns {void} set new modules to this chunk and return nothing
234
+ */
235
+ setModules(modules) {
236
+ this._modules = new SortableSet(modules, sortByIdentifier);
237
+ }
238
+
239
+ /**
240
+ * @returns {number} the amount of modules in chunk
241
+ */
242
+ getNumberOfModules() {
243
+ return this._modules.size;
244
+ }
245
+
246
+ /**
247
+ * @returns {SortableSet} return the modules SortableSet for this chunk
248
+ */
249
+ get modulesIterable() {
250
+ return this._modules;
251
+ }
252
+
253
+ /**
254
+ * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added
255
+ * @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully
256
+ */
257
+ addGroup(chunkGroup) {
258
+ if (this._groups.has(chunkGroup)) return false;
259
+ this._groups.add(chunkGroup);
260
+ return true;
261
+ }
262
+
263
+ /**
264
+ * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from
265
+ * @returns {boolean} returns true if chunk does exist in chunkGroup and is removed
266
+ */
267
+ removeGroup(chunkGroup) {
268
+ if (!this._groups.has(chunkGroup)) return false;
269
+ this._groups.delete(chunkGroup);
270
+ return true;
271
+ }
272
+
273
+ /**
274
+ * @param {ChunkGroup} chunkGroup the chunkGroup to check
275
+ * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup
276
+ */
277
+ isInGroup(chunkGroup) {
278
+ return this._groups.has(chunkGroup);
279
+ }
280
+
281
+ /**
282
+ * @returns {number} the amount of groups said chunk is in
283
+ */
284
+ getNumberOfGroups() {
285
+ return this._groups.size;
286
+ }
287
+
288
+ /**
289
+ * @returns {SortableSet} the chunkGroups that said chunk is referenced in
290
+ */
291
+ get groupsIterable() {
292
+ return this._groups;
293
+ }
294
+
295
+ /**
296
+ * @param {Chunk} otherChunk the chunk to compare itself with
297
+ * @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order
298
+ */
299
+ compareTo(otherChunk) {
300
+ this._modules.sort();
301
+ otherChunk._modules.sort();
302
+ if (this._modules.size > otherChunk._modules.size) return -1;
303
+ if (this._modules.size < otherChunk._modules.size) return 1;
304
+ const a = this._modules[Symbol.iterator]();
305
+ const b = otherChunk._modules[Symbol.iterator]();
306
+ // eslint-disable-next-line
307
+ while (true) {
308
+ const aItem = a.next();
309
+ const bItem = b.next();
310
+ if (aItem.done) return 0;
311
+ const aModuleIdentifier = aItem.value.identifier();
312
+ const bModuleIdentifier = bItem.value.identifier();
313
+ if (aModuleIdentifier < bModuleIdentifier) return -1;
314
+ if (aModuleIdentifier > bModuleIdentifier) return 1;
315
+ }
316
+ }
317
+
318
+ /**
319
+ * @param {Module} module Module to check
320
+ * @returns {boolean} returns true if module does exist in this chunk
321
+ */
322
+ containsModule(module) {
323
+ return this._modules.has(module);
324
+ }
325
+
326
+ getModules() {
327
+ return this._modules.getFromCache(getArray);
328
+ }
329
+
330
+ getModulesIdent() {
331
+ return this._modules.getFromUnorderedCache(getModulesIdent);
332
+ }
333
+
334
+ remove() {
335
+ // cleanup modules
336
+ // Array.from is used here to create a clone, because removeChunk modifies this._modules
337
+ for (const module of Array.from(this._modules)) {
338
+ module.removeChunk(this);
339
+ }
340
+ for (const chunkGroup of this._groups) {
341
+ chunkGroup.removeChunk(this);
342
+ }
343
+ }
344
+
345
+ /**
346
+ *
347
+ * @param {Module} module module to move
348
+ * @param {Chunk} otherChunk other chunk to move it to
349
+ * @returns {void}
350
+ */
351
+ moveModule(module, otherChunk) {
352
+ GraphHelpers.disconnectChunkAndModule(this, module);
353
+ GraphHelpers.connectChunkAndModule(otherChunk, module);
354
+ module.rewriteChunkInReasons(this, [otherChunk]);
355
+ }
356
+
357
+ /**
358
+ *
359
+ * @param {Chunk} otherChunk the chunk to integrate with
360
+ * @param {ModuleReason} reason reason why the module is being integrated
361
+ * @returns {boolean} returns true or false if integration succeeds or fails
362
+ */
363
+ integrate(otherChunk, reason) {
364
+ if (!this.canBeIntegrated(otherChunk)) {
365
+ return false;
366
+ }
367
+
368
+ // Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
369
+ for (const module of Array.from(otherChunk._modules)) {
370
+ otherChunk.moveModule(module, this);
371
+ }
372
+ otherChunk._modules.clear();
373
+
374
+ for (const chunkGroup of otherChunk._groups) {
375
+ chunkGroup.replaceChunk(otherChunk, this);
376
+ this.addGroup(chunkGroup);
377
+ }
378
+ otherChunk._groups.clear();
379
+
380
+ if (this.name && otherChunk.name) {
381
+ if (this.name.length !== otherChunk.name.length) {
382
+ this.name =
383
+ this.name.length < otherChunk.name.length
384
+ ? this.name
385
+ : otherChunk.name;
386
+ } else {
387
+ this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
388
+ }
389
+ }
390
+
391
+ return true;
392
+ }
393
+
394
+ /**
395
+ * @param {Chunk} newChunk the new chunk that will be split out of, and then chunk raphi twil=
396
+ * @returns {void}
397
+ */
398
+ split(newChunk) {
399
+ for (const chunkGroup of this._groups) {
400
+ chunkGroup.insertChunk(newChunk, this);
401
+ newChunk.addGroup(chunkGroup);
402
+ }
403
+ }
404
+
405
+ isEmpty() {
406
+ return this._modules.size === 0;
407
+ }
408
+
409
+ updateHash(hash) {
410
+ hash.update(`${this.id} `);
411
+ hash.update(this.ids ? this.ids.join(",") : "");
412
+ hash.update(`${this.name || ""} `);
413
+ for (const m of this._modules) {
414
+ hash.update(m.hash);
415
+ }
416
+ }
417
+
418
+ canBeIntegrated(otherChunk) {
419
+ const isAvailable = (a, b) => {
420
+ const queue = new Set(b.groupsIterable);
421
+ for (const chunkGroup of queue) {
422
+ if (a.isInGroup(chunkGroup)) continue;
423
+ if (chunkGroup.isInitial()) return false;
424
+ for (const parent of chunkGroup.parentsIterable) {
425
+ queue.add(parent);
426
+ }
427
+ }
428
+ return true;
429
+ };
430
+
431
+ if (this.preventIntegration || otherChunk.preventIntegration) {
432
+ return false;
433
+ }
434
+
435
+ if (this.hasRuntime() !== otherChunk.hasRuntime()) {
436
+ if (this.hasRuntime()) {
437
+ return isAvailable(this, otherChunk);
438
+ } else if (otherChunk.hasRuntime()) {
439
+ return isAvailable(otherChunk, this);
440
+ } else {
441
+ return false;
442
+ }
443
+ }
444
+
445
+ if (this.hasEntryModule() || otherChunk.hasEntryModule()) {
446
+ return false;
447
+ }
448
+
449
+ return true;
450
+ }
451
+
452
+ /**
453
+ *
454
+ * @param {number} size the size
455
+ * @param {Object} options the options passed in
456
+ * @returns {number} the multiplier returned
457
+ */
458
+ addMultiplierAndOverhead(size, options) {
459
+ const overhead =
460
+ typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
461
+ const multiplicator = this.canBeInitial()
462
+ ? options.entryChunkMultiplicator || 10
463
+ : 1;
464
+
465
+ return size * multiplicator + overhead;
466
+ }
467
+
468
+ /**
469
+ * @returns {number} the size of all modules
470
+ */
471
+ modulesSize() {
472
+ return this._modules.getFromUnorderedCache(getModulesSize);
473
+ }
474
+
475
+ /**
476
+ * @param {Object} options the size display options
477
+ * @returns {number} the chunk size
478
+ */
479
+ size(options) {
480
+ return this.addMultiplierAndOverhead(this.modulesSize(), options);
481
+ }
482
+
483
+ integratedSize(otherChunk, options) {
484
+ // Chunk if it's possible to integrate this chunk
485
+ if (!this.canBeIntegrated(otherChunk)) {
486
+ return false;
487
+ }
488
+
489
+ let integratedModulesSize = this.modulesSize();
490
+ // only count modules that do not exist in this chunk!
491
+ for (const otherModule of otherChunk._modules) {
492
+ if (!this._modules.has(otherModule)) {
493
+ integratedModulesSize += otherModule.size();
494
+ }
495
+ }
496
+
497
+ return this.addMultiplierAndOverhead(integratedModulesSize, options);
498
+ }
499
+
500
+ /**
501
+ * @param {ModuleSortPredicate=} sortByFn a predicate function used to sort modules
502
+ * @returns {void}
503
+ */
504
+ sortModules(sortByFn) {
505
+ this._modules.sortWith(sortByFn || sortById);
506
+ }
507
+
508
+ sortItems(sortChunks) {
509
+ this.sortModules();
510
+ }
511
+
512
+ getAllAsyncChunks() {
513
+ const queue = new Set();
514
+ const chunks = new Set();
515
+
516
+ const initialChunks = intersect(
517
+ Array.from(this.groupsIterable, g => new Set(g.chunks))
518
+ );
519
+
520
+ for (const chunkGroup of this.groupsIterable) {
521
+ for (const child of chunkGroup.childrenIterable) {
522
+ queue.add(child);
523
+ }
524
+ }
525
+
526
+ for (const chunkGroup of queue) {
527
+ for (const chunk of chunkGroup.chunks) {
528
+ if (!initialChunks.has(chunk)) {
529
+ chunks.add(chunk);
530
+ }
531
+ }
532
+ for (const child of chunkGroup.childrenIterable) {
533
+ queue.add(child);
534
+ }
535
+ }
536
+
537
+ return chunks;
538
+ }
539
+
540
+ getChunkMaps(realHash) {
541
+ const chunkHashMap = Object.create(null);
542
+ const chunkContentHashMap = Object.create(null);
543
+ const chunkNameMap = Object.create(null);
544
+
545
+ for (const chunk of this.getAllAsyncChunks()) {
546
+ chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
547
+ for (const key of Object.keys(chunk.contentHash)) {
548
+ if (!chunkContentHashMap[key]) {
549
+ chunkContentHashMap[key] = Object.create(null);
550
+ }
551
+ chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
552
+ }
553
+ if (chunk.name) {
554
+ chunkNameMap[chunk.id] = chunk.name;
555
+ }
556
+ }
557
+
558
+ return {
559
+ hash: chunkHashMap,
560
+ contentHash: chunkContentHashMap,
561
+ name: chunkNameMap
562
+ };
563
+ }
564
+
565
+ getChildIdsByOrders() {
566
+ const lists = new Map();
567
+ for (const group of this.groupsIterable) {
568
+ if (group.chunks[group.chunks.length - 1] === this) {
569
+ for (const childGroup of group.childrenIterable) {
570
+ // TODO webpack 5 remove this check for options
571
+ if (typeof childGroup.options === "object") {
572
+ for (const key of Object.keys(childGroup.options)) {
573
+ if (key.endsWith("Order")) {
574
+ const name = key.substr(0, key.length - "Order".length);
575
+ let list = lists.get(name);
576
+ if (list === undefined) lists.set(name, (list = []));
577
+ list.push({
578
+ order: childGroup.options[key],
579
+ group: childGroup
580
+ });
581
+ }
582
+ }
583
+ }
584
+ }
585
+ }
586
+ }
587
+ const result = Object.create(null);
588
+ for (const [name, list] of lists) {
589
+ list.sort((a, b) => {
590
+ const cmp = b.order - a.order;
591
+ if (cmp !== 0) return cmp;
592
+ // TOOD webpack 5 remove this check of compareTo
593
+ if (a.group.compareTo) {
594
+ return a.group.compareTo(b.group);
595
+ }
596
+ return 0;
597
+ });
598
+ result[name] = Array.from(
599
+ list.reduce((set, item) => {
600
+ for (const chunk of item.group.chunks) {
601
+ set.add(chunk.id);
602
+ }
603
+ return set;
604
+ }, new Set())
605
+ );
606
+ }
607
+ return result;
608
+ }
609
+
610
+ getChildIdsByOrdersMap() {
611
+ const chunkMaps = Object.create(null);
612
+
613
+ for (const chunk of this.getAllAsyncChunks()) {
614
+ const data = chunk.getChildIdsByOrders();
615
+ for (const key of Object.keys(data)) {
616
+ let chunkMap = chunkMaps[key];
617
+ if (chunkMap === undefined) {
618
+ chunkMaps[key] = chunkMap = Object.create(null);
619
+ }
620
+ chunkMap[chunk.id] = data[key];
621
+ }
622
+ }
623
+ return chunkMaps;
624
+ }
625
+
626
+ getChunkModuleMaps(filterFn) {
627
+ const chunkModuleIdMap = Object.create(null);
628
+ const chunkModuleHashMap = Object.create(null);
629
+
630
+ for (const chunk of this.getAllAsyncChunks()) {
631
+ let array;
632
+ for (const module of chunk.modulesIterable) {
633
+ if (filterFn(module)) {
634
+ if (array === undefined) {
635
+ array = [];
636
+ chunkModuleIdMap[chunk.id] = array;
637
+ }
638
+ array.push(module.id);
639
+ chunkModuleHashMap[module.id] = module.renderedHash;
640
+ }
641
+ }
642
+ if (array !== undefined) {
643
+ array.sort();
644
+ }
645
+ }
646
+
647
+ return {
648
+ id: chunkModuleIdMap,
649
+ hash: chunkModuleHashMap
650
+ };
651
+ }
652
+
653
+ /**
654
+ *
655
+ * @param {ModuleFilterPredicate} filterFn predicate function used to filter modules
656
+ * @param {ChunkFilterPredicate} filterChunkFn predicate function used to filter chunks
657
+ * @returns {boolean} return true if module exists in graph
658
+ */
659
+ hasModuleInGraph(filterFn, filterChunkFn) {
660
+ const queue = new Set(this.groupsIterable);
661
+ const chunksProcessed = new Set();
662
+
663
+ for (const chunkGroup of queue) {
664
+ for (const chunk of chunkGroup.chunks) {
665
+ if (!chunksProcessed.has(chunk)) {
666
+ chunksProcessed.add(chunk);
667
+ if (!filterChunkFn || filterChunkFn(chunk)) {
668
+ for (const module of chunk.modulesIterable) {
669
+ if (filterFn(module)) {
670
+ return true;
671
+ }
672
+ }
673
+ }
674
+ }
675
+ }
676
+ for (const child of chunkGroup.childrenIterable) {
677
+ queue.add(child);
678
+ }
679
+ }
680
+ return false;
681
+ }
682
+
683
+ toString() {
684
+ return `Chunk[${Array.from(this._modules).join()}]`;
685
+ }
686
+ }
687
+
688
+ // TODO remove in webpack 5
689
+ Object.defineProperty(Chunk.prototype, "forEachModule", {
690
+ configurable: false,
691
+ value: util.deprecate(function(fn) {
692
+ this._modules.forEach(fn);
693
+ }, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead")
694
+ });
695
+
696
+ // TODO remove in webpack 5
697
+ Object.defineProperty(Chunk.prototype, "mapModules", {
698
+ configurable: false,
699
+ value: util.deprecate(function(fn) {
700
+ return Array.from(this._modules, fn);
701
+ }, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead")
702
+ });
703
+
704
+ // TODO remove in webpack 5
705
+ Object.defineProperty(Chunk.prototype, "chunks", {
706
+ configurable: false,
707
+ get() {
708
+ throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
709
+ },
710
+ set() {
711
+ throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
712
+ }
713
+ });
714
+
715
+ // TODO remove in webpack 5
716
+ Object.defineProperty(Chunk.prototype, "parents", {
717
+ configurable: false,
718
+ get() {
719
+ throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
720
+ },
721
+ set() {
722
+ throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
723
+ }
724
+ });
725
+
726
+ // TODO remove in webpack 5
727
+ Object.defineProperty(Chunk.prototype, "blocks", {
728
+ configurable: false,
729
+ get() {
730
+ throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
731
+ },
732
+ set() {
733
+ throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
734
+ }
735
+ });
736
+
737
+ // TODO remove in webpack 5
738
+ Object.defineProperty(Chunk.prototype, "entrypoints", {
739
+ configurable: false,
740
+ get() {
741
+ throw new Error(
742
+ "Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
743
+ );
744
+ },
745
+ set() {
746
+ throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
747
+ }
748
+ });
749
+
750
+ module.exports = Chunk;