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
@@ -1,710 +1,749 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
- const path = require("path");
7
- const util = require("util");
8
- const { OriginalSource, RawSource } = require("webpack-sources");
9
- const Module = require("./Module");
10
- const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
11
- const Template = require("./Template");
12
-
13
- class ContextModule extends Module {
14
- // type ContextMode = "sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"
15
- // type ContextOptions = { resource: string, recursive: boolean, regExp: RegExp, addon?: string, mode?: ContextMode, chunkName?: string, include?: RegExp, exclude?: RegExp, groupOptions?: Object }
16
- // resolveDependencies: (fs: FS, options: ContextOptions, (err: Error?, dependencies: Dependency[]) => void) => void
17
- // options: ContextOptions
18
- constructor(resolveDependencies, options) {
19
- let resource;
20
- let resourceQuery;
21
- const queryIdx = options.resource.indexOf("?");
22
- if (queryIdx >= 0) {
23
- resource = options.resource.substr(0, queryIdx);
24
- resourceQuery = options.resource.substr(queryIdx);
25
- } else {
26
- resource = options.resource;
27
- resourceQuery = "";
28
- }
29
-
30
- super("javascript/dynamic", resource);
31
-
32
- // Info from Factory
33
- this.resolveDependencies = resolveDependencies;
34
- this.options = Object.assign({}, options, {
35
- resource: resource,
36
- resourceQuery: resourceQuery
37
- });
38
- if (options.resolveOptions !== undefined)
39
- this.resolveOptions = options.resolveOptions;
40
-
41
- // Info from Build
42
- this._contextDependencies = new Set([this.context]);
43
-
44
- if (typeof options.mode !== "string")
45
- throw new Error("options.mode is a required option");
46
-
47
- this._identifier = this._createIdentifier();
48
- }
49
-
50
- updateCacheModule(module) {
51
- this.resolveDependencies = module.resolveDependencies;
52
- this.options = module.options;
53
- this.resolveOptions = module.resolveOptions;
54
- }
55
-
56
- prettyRegExp(regexString) {
57
- // remove the "/" at the front and the beginning
58
- // "/foo/" -> "foo"
59
- return regexString.substring(1, regexString.length - 1);
60
- }
61
-
62
- contextify(context, request) {
63
- return request
64
- .split("!")
65
- .map(subrequest => {
66
- let rp = path.relative(context, subrequest);
67
- if (path.sep === "\\") rp = rp.replace(/\\/g, "/");
68
- if (rp.indexOf("../") !== 0) rp = "./" + rp;
69
- return rp;
70
- })
71
- .join("!");
72
- }
73
-
74
- _createIdentifier() {
75
- let identifier = this.context;
76
- if (this.options.resourceQuery)
77
- identifier += ` ${this.options.resourceQuery}`;
78
- if (this.options.mode) identifier += ` ${this.options.mode}`;
79
- if (!this.options.recursive) identifier += " nonrecursive";
80
- if (this.options.addon) identifier += ` ${this.options.addon}`;
81
- if (this.options.regExp) identifier += ` ${this.options.regExp}`;
82
- if (this.options.include) identifier += ` include: ${this.options.include}`;
83
- if (this.options.exclude) identifier += ` exclude: ${this.options.exclude}`;
84
- if (this.options.groupOptions) {
85
- identifier += ` groupOptions: ${JSON.stringify(
86
- this.options.groupOptions
87
- )}`;
88
- }
89
- if (this.options.namespaceObject === "strict")
90
- identifier += " strict namespace object";
91
- else if (this.options.namespaceObject) identifier += " namespace object";
92
-
93
- return identifier;
94
- }
95
-
96
- identifier() {
97
- return this._identifier;
98
- }
99
-
100
- readableIdentifier(requestShortener) {
101
- let identifier = requestShortener.shorten(this.context);
102
- if (this.options.resourceQuery)
103
- identifier += ` ${this.options.resourceQuery}`;
104
- if (this.options.mode) identifier += ` ${this.options.mode}`;
105
- if (!this.options.recursive) identifier += " nonrecursive";
106
- if (this.options.addon)
107
- identifier += ` ${requestShortener.shorten(this.options.addon)}`;
108
- if (this.options.regExp)
109
- identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
110
- if (this.options.include)
111
- identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
112
- if (this.options.exclude)
113
- identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
114
- if (this.options.groupOptions) {
115
- const groupOptions = this.options.groupOptions;
116
- for (const key of Object.keys(groupOptions))
117
- identifier += ` ${key}: ${groupOptions[key]}`;
118
- }
119
- if (this.options.namespaceObject === "strict")
120
- identifier += " strict namespace object";
121
- else if (this.options.namespaceObject) identifier += " namespace object";
122
-
123
- return identifier;
124
- }
125
-
126
- libIdent(options) {
127
- let identifier = this.contextify(options.context, this.context);
128
- if (this.options.mode) identifier += ` ${this.options.mode}`;
129
- if (this.options.recursive) identifier += " recursive";
130
- if (this.options.addon)
131
- identifier += ` ${this.contextify(options.context, this.options.addon)}`;
132
- if (this.options.regExp)
133
- identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
134
- if (this.options.include)
135
- identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
136
- if (this.options.exclude)
137
- identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
138
-
139
- return identifier;
140
- }
141
-
142
- needRebuild(fileTimestamps, contextTimestamps) {
143
- const ts = contextTimestamps.get(this.context);
144
- if (!ts) {
145
- return true;
146
- }
147
-
148
- return ts >= this.buildInfo.builtTime;
149
- }
150
-
151
- build(options, compilation, resolver, fs, callback) {
152
- this.built = true;
153
- this.buildMeta = {};
154
- this.buildInfo = {
155
- builtTime: Date.now(),
156
- contextDependencies: this._contextDependencies
157
- };
158
- this.resolveDependencies(fs, this.options, (err, dependencies) => {
159
- if (err) return callback(err);
160
-
161
- // abort if something failed
162
- // this will create an empty context
163
- if (!dependencies) {
164
- callback();
165
- return;
166
- }
167
-
168
- // enhance dependencies with meta info
169
- for (const dep of dependencies) {
170
- dep.loc = dep.userRequest;
171
- dep.request = this.options.addon + dep.request;
172
- }
173
-
174
- if (this.options.mode === "sync" || this.options.mode === "eager") {
175
- // if we have an sync or eager context
176
- // just add all dependencies and continue
177
- this.dependencies = dependencies;
178
- } else if (this.options.mode === "lazy-once") {
179
- // for the lazy-once mode create a new async dependency block
180
- // and add that block to this context
181
- if (dependencies.length > 0) {
182
- const block = new AsyncDependenciesBlock(
183
- Object.assign({}, this.options.groupOptions, {
184
- name: this.options.chunkName
185
- }),
186
- this
187
- );
188
- for (const dep of dependencies) {
189
- block.addDependency(dep);
190
- }
191
- this.addBlock(block);
192
- }
193
- } else if (
194
- this.options.mode === "weak" ||
195
- this.options.mode === "async-weak"
196
- ) {
197
- // we mark all dependencies as weak
198
- for (const dep of dependencies) {
199
- dep.weak = true;
200
- }
201
- this.dependencies = dependencies;
202
- } else if (this.options.mode === "lazy") {
203
- // if we are lazy create a new async dependency block per dependency
204
- // and add all blocks to this context
205
- let index = 0;
206
- for (const dep of dependencies) {
207
- let chunkName = this.options.chunkName;
208
- if (chunkName) {
209
- if (!/\[(index|request)\]/.test(chunkName)) chunkName += "[index]";
210
- chunkName = chunkName.replace(/\[index\]/g, index++);
211
- chunkName = chunkName.replace(
212
- /\[request\]/g,
213
- Template.toPath(dep.userRequest)
214
- );
215
- }
216
- const block = new AsyncDependenciesBlock(
217
- Object.assign({}, this.options.groupOptions, {
218
- name: chunkName
219
- }),
220
- dep.module,
221
- dep.loc,
222
- dep.userRequest
223
- );
224
- block.addDependency(dep);
225
- this.addBlock(block);
226
- }
227
- } else {
228
- callback(
229
- new Error(`Unsupported mode "${this.options.mode}" in context`)
230
- );
231
- return;
232
- }
233
- callback();
234
- });
235
- }
236
-
237
- getUserRequestMap(dependencies) {
238
- // if we filter first we get a new array
239
- // therefor we dont need to create a clone of dependencies explicitly
240
- // therefore the order of this is !important!
241
- return dependencies
242
- .filter(dependency => dependency.module)
243
- .sort((a, b) => {
244
- if (a.userRequest === b.userRequest) {
245
- return 0;
246
- }
247
- return a.userRequest < b.userRequest ? -1 : 1;
248
- })
249
- .reduce((map, dep) => {
250
- map[dep.userRequest] = dep.module.id;
251
- return map;
252
- }, Object.create(null));
253
- }
254
-
255
- getFakeMap(dependencies) {
256
- if (!this.options.namespaceObject) return 1;
257
- // if we filter first we get a new array
258
- // therefor we dont need to create a clone of dependencies explicitly
259
- // therefore the order of this is !important!
260
- let hasNonHarmony = false;
261
- let hasNamespace = false;
262
- let hasNamed = false;
263
- const fakeMap = dependencies
264
- .filter(dependency => dependency.module)
265
- .sort((a, b) => {
266
- return b.module.id - a.module.id;
267
- })
268
- .reduce((map, dep) => {
269
- const exportsType =
270
- dep.module.buildMeta && dep.module.buildMeta.exportsType;
271
- if (!exportsType) hasNonHarmony = true;
272
- if (exportsType === "namespace") hasNamespace = true;
273
- if (exportsType === "named") hasNamed = true;
274
- map[dep.module.id] =
275
- {
276
- namespace: 1,
277
- named: 2
278
- }[exportsType] || 0;
279
- return map;
280
- }, Object.create(null));
281
- if (!hasNamespace && hasNonHarmony && !hasNamed) return 0;
282
- if (hasNamespace && !hasNonHarmony && !hasNamed) return 1;
283
- if (!hasNamespace && !hasNonHarmony && hasNamed) return 2;
284
- if (!hasNamespace && !hasNonHarmony && !hasNamed) return 1;
285
- return fakeMap;
286
- }
287
-
288
- getFakeMapInitStatement(fakeMap) {
289
- return typeof fakeMap === "object"
290
- ? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
291
- : "";
292
- }
293
-
294
- getReturn(type) {
295
- if (type === 1) return "module";
296
- if (type === 2)
297
- return 'Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module })';
298
- if (type === 0) {
299
- if (this.options.namespaceObject === "strict") {
300
- return '/* fake namespace object */ { "default": module }';
301
- } else {
302
- return '(typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }))';
303
- }
304
- }
305
- }
306
-
307
- getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
308
- if (typeof fakeMap === "number")
309
- return `return ${this.getReturn(fakeMap)};`;
310
- return `return ${fakeMapDataExpression} === 1 ? ${this.getReturn(
311
- 1
312
- )} : ${fakeMapDataExpression} ? ${this.getReturn(2)} : ${this.getReturn(
313
- 0
314
- )};`;
315
- }
316
-
317
- getSyncSource(dependencies, id) {
318
- const map = this.getUserRequestMap(dependencies);
319
- const fakeMap = this.getFakeMap(dependencies);
320
- const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
321
-
322
- return `var map = ${JSON.stringify(map, null, "\t")};
323
- ${this.getFakeMapInitStatement(fakeMap)}
324
-
325
- function webpackContext(req) {
326
- var id = webpackContextResolve(req);
327
- var module = __webpack_require__(id);
328
- ${returnModuleObject}
329
- }
330
- function webpackContextResolve(req) {
331
- var id = map[req];
332
- if(!(id + 1)) { // check for number or string
333
- var e = new Error("Cannot find module '" + req + "'");
334
- e.code = 'MODULE_NOT_FOUND';
335
- throw e;
336
- }
337
- return id;
338
- }
339
- webpackContext.keys = function webpackContextKeys() {
340
- return Object.keys(map);
341
- };
342
- webpackContext.resolve = webpackContextResolve;
343
- module.exports = webpackContext;
344
- webpackContext.id = ${JSON.stringify(id)};`;
345
- }
346
-
347
- getWeakSyncSource(dependencies, id) {
348
- const map = this.getUserRequestMap(dependencies);
349
- const fakeMap = this.getFakeMap(dependencies);
350
- const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
351
-
352
- return `var map = ${JSON.stringify(map, null, "\t")};
353
- ${this.getFakeMapInitStatement(fakeMap)}
354
-
355
- function webpackContext(req) {
356
- var id = webpackContextResolve(req);
357
- if(!__webpack_require__.m[id]) {
358
- var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
359
- e.code = 'MODULE_NOT_FOUND';
360
- throw e;
361
- }
362
- var module = __webpack_require__(id);
363
- ${returnModuleObject}
364
- }
365
- function webpackContextResolve(req) {
366
- var id = map[req];
367
- if(!(id + 1)) { // check for number or string
368
- var e = new Error("Cannot find module '" + req + "'");
369
- e.code = 'MODULE_NOT_FOUND';
370
- throw e;
371
- }
372
- return id;
373
- }
374
- webpackContext.keys = function webpackContextKeys() {
375
- return Object.keys(map);
376
- };
377
- webpackContext.resolve = webpackContextResolve;
378
- webpackContext.id = ${JSON.stringify(id)};
379
- module.exports = webpackContext;`;
380
- }
381
-
382
- getAsyncWeakSource(dependencies, id) {
383
- const map = this.getUserRequestMap(dependencies);
384
- const fakeMap = this.getFakeMap(dependencies);
385
- const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
386
-
387
- return `var map = ${JSON.stringify(map, null, "\t")};
388
- ${this.getFakeMapInitStatement(fakeMap)}
389
-
390
- function webpackAsyncContext(req) {
391
- return webpackAsyncContextResolve(req).then(function(id) {
392
- if(!__webpack_require__.m[id]) {
393
- var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
394
- e.code = 'MODULE_NOT_FOUND';
395
- throw e;
396
- }
397
- var module = __webpack_require__(id);
398
- ${returnModuleObject}
399
- });
400
- }
401
- function webpackAsyncContextResolve(req) {
402
- // Here Promise.resolve().then() is used instead of new Promise() to prevent
403
- // uncaught exception popping up in devtools
404
- return Promise.resolve().then(function() {
405
- var id = map[req];
406
- if(!(id + 1)) { // check for number or string
407
- var e = new Error("Cannot find module '" + req + "'");
408
- e.code = 'MODULE_NOT_FOUND';
409
- throw e;
410
- }
411
- return id;
412
- });
413
- }
414
- webpackAsyncContext.keys = function webpackAsyncContextKeys() {
415
- return Object.keys(map);
416
- };
417
- webpackAsyncContext.resolve = webpackAsyncContextResolve;
418
- webpackAsyncContext.id = ${JSON.stringify(id)};
419
- module.exports = webpackAsyncContext;`;
420
- }
421
-
422
- getEagerSource(dependencies, id) {
423
- const map = this.getUserRequestMap(dependencies);
424
- const fakeMap = this.getFakeMap(dependencies);
425
- const thenFunction =
426
- fakeMap !== 1
427
- ? `function(id) {
428
- var module = __webpack_require__(id);
429
- ${this.getReturnModuleObjectSource(fakeMap)}
430
- }`
431
- : "__webpack_require__";
432
- return `var map = ${JSON.stringify(map, null, "\t")};
433
- ${this.getFakeMapInitStatement(fakeMap)}
434
-
435
- function webpackAsyncContext(req) {
436
- return webpackAsyncContextResolve(req).then(${thenFunction});
437
- }
438
- function webpackAsyncContextResolve(req) {
439
- // Here Promise.resolve().then() is used instead of new Promise() to prevent
440
- // uncaught exception popping up in devtools
441
- return Promise.resolve().then(function() {
442
- var id = map[req];
443
- if(!(id + 1)) { // check for number or string
444
- var e = new Error("Cannot find module '" + req + "'");
445
- e.code = 'MODULE_NOT_FOUND';
446
- throw e;
447
- }
448
- return id;
449
- });
450
- }
451
- webpackAsyncContext.keys = function webpackAsyncContextKeys() {
452
- return Object.keys(map);
453
- };
454
- webpackAsyncContext.resolve = webpackAsyncContextResolve;
455
- webpackAsyncContext.id = ${JSON.stringify(id)};
456
- module.exports = webpackAsyncContext;`;
457
- }
458
-
459
- getLazyOnceSource(block, dependencies, id, runtimeTemplate) {
460
- const promise = runtimeTemplate.blockPromise({
461
- block,
462
- message: "lazy-once context"
463
- });
464
- const map = this.getUserRequestMap(dependencies);
465
- const fakeMap = this.getFakeMap(dependencies);
466
- const thenFunction =
467
- fakeMap !== 1
468
- ? `function(id) {
469
- var module = __webpack_require__(id);
470
- ${this.getReturnModuleObjectSource(fakeMap)};
471
- }`
472
- : "__webpack_require__";
473
-
474
- return `var map = ${JSON.stringify(map, null, "\t")};
475
- ${this.getFakeMapInitStatement(fakeMap)}
476
-
477
- function webpackAsyncContext(req) {
478
- return webpackAsyncContextResolve(req).then(${thenFunction});
479
- }
480
- function webpackAsyncContextResolve(req) {
481
- return ${promise}.then(function() {
482
- var id = map[req];
483
- if(!(id + 1)) { // check for number or string
484
- var e = new Error("Cannot find module '" + req + "'");
485
- e.code = 'MODULE_NOT_FOUND';
486
- throw e;
487
- }
488
- return id;
489
- });
490
- }
491
- webpackAsyncContext.keys = function webpackAsyncContextKeys() {
492
- return Object.keys(map);
493
- };
494
- webpackAsyncContext.resolve = webpackAsyncContextResolve;
495
- webpackAsyncContext.id = ${JSON.stringify(id)};
496
- module.exports = webpackAsyncContext;`;
497
- }
498
-
499
- getLazySource(blocks, id) {
500
- let hasMultipleOrNoChunks = false;
501
- const fakeMap = this.getFakeMap(blocks.map(b => b.dependencies[0]));
502
- const map = blocks
503
- .filter(block => block.dependencies[0].module)
504
- .map(block => ({
505
- dependency: block.dependencies[0],
506
- block: block,
507
- userRequest: block.dependencies[0].userRequest
508
- }))
509
- .sort((a, b) => {
510
- if (a.userRequest === b.userRequest) return 0;
511
- return a.userRequest < b.userRequest ? -1 : 1;
512
- })
513
- .reduce((map, item) => {
514
- const chunks =
515
- (item.block.chunkGroup && item.block.chunkGroup.chunks) || [];
516
- if (chunks.length !== 1) {
517
- hasMultipleOrNoChunks = true;
518
- }
519
- const arrayStart = [item.dependency.module.id];
520
- if (typeof fakeMap === "object")
521
- arrayStart.push(fakeMap[item.dependency.module.id]);
522
- map[item.userRequest] = arrayStart.concat(
523
- chunks.map(chunk => chunk.id)
524
- );
525
-
526
- return map;
527
- }, Object.create(null));
528
-
529
- const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1;
530
- const requestPrefix = hasMultipleOrNoChunks
531
- ? `Promise.all(ids.slice(${chunksStartPosition}).map(__webpack_require__.e))`
532
- : `__webpack_require__.e(ids[${chunksStartPosition}])`;
533
- const returnModuleObject = this.getReturnModuleObjectSource(
534
- fakeMap,
535
- "ids[1]"
536
- );
537
-
538
- return `var map = ${JSON.stringify(map, null, "\t")};
539
- function webpackAsyncContext(req) {
540
- var ids = map[req];
541
- if(!ids) {
542
- return Promise.resolve().then(function() {
543
- var e = new Error("Cannot find module '" + req + "'");
544
- e.code = 'MODULE_NOT_FOUND';
545
- throw e;
546
- });
547
- }
548
- return ${requestPrefix}.then(function() {
549
- var module = __webpack_require__(ids[0]);
550
- ${returnModuleObject}
551
- });
552
- }
553
- webpackAsyncContext.keys = function webpackAsyncContextKeys() {
554
- return Object.keys(map);
555
- };
556
- webpackAsyncContext.id = ${JSON.stringify(id)};
557
- module.exports = webpackAsyncContext;`;
558
- }
559
-
560
- getSourceForEmptyContext(id) {
561
- return `function webpackEmptyContext(req) {
562
- var e = new Error("Cannot find module '" + req + "'");
563
- e.code = 'MODULE_NOT_FOUND';
564
- throw e;
565
- }
566
- webpackEmptyContext.keys = function() { return []; };
567
- webpackEmptyContext.resolve = webpackEmptyContext;
568
- module.exports = webpackEmptyContext;
569
- webpackEmptyContext.id = ${JSON.stringify(id)};`;
570
- }
571
-
572
- getSourceForEmptyAsyncContext(id) {
573
- return `function webpackEmptyAsyncContext(req) {
574
- // Here Promise.resolve().then() is used instead of new Promise() to prevent
575
- // uncaught exception popping up in devtools
576
- return Promise.resolve().then(function() {
577
- var e = new Error("Cannot find module '" + req + "'");
578
- e.code = 'MODULE_NOT_FOUND';
579
- throw e;
580
- });
581
- }
582
- webpackEmptyAsyncContext.keys = function() { return []; };
583
- webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
584
- module.exports = webpackEmptyAsyncContext;
585
- webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
586
- }
587
-
588
- getSourceString(asyncMode, runtimeTemplate) {
589
- if (asyncMode === "lazy") {
590
- if (this.blocks && this.blocks.length > 0) {
591
- return this.getLazySource(this.blocks, this.id);
592
- }
593
- return this.getSourceForEmptyAsyncContext(this.id);
594
- }
595
- if (asyncMode === "eager") {
596
- if (this.dependencies && this.dependencies.length > 0) {
597
- return this.getEagerSource(this.dependencies, this.id);
598
- }
599
- return this.getSourceForEmptyAsyncContext(this.id);
600
- }
601
- if (asyncMode === "lazy-once") {
602
- const block = this.blocks[0];
603
- if (block) {
604
- return this.getLazyOnceSource(
605
- block,
606
- block.dependencies,
607
- this.id,
608
- runtimeTemplate
609
- );
610
- }
611
- return this.getSourceForEmptyAsyncContext(this.id);
612
- }
613
- if (asyncMode === "async-weak") {
614
- if (this.dependencies && this.dependencies.length > 0) {
615
- return this.getAsyncWeakSource(this.dependencies, this.id);
616
- }
617
- return this.getSourceForEmptyAsyncContext(this.id);
618
- }
619
- if (asyncMode === "weak") {
620
- if (this.dependencies && this.dependencies.length > 0) {
621
- return this.getWeakSyncSource(this.dependencies, this.id);
622
- }
623
- }
624
- if (this.dependencies && this.dependencies.length > 0) {
625
- return this.getSyncSource(this.dependencies, this.id);
626
- }
627
- return this.getSourceForEmptyContext(this.id);
628
- }
629
-
630
- getSource(sourceString) {
631
- if (this.useSourceMap) {
632
- return new OriginalSource(sourceString, this.identifier());
633
- }
634
- return new RawSource(sourceString);
635
- }
636
-
637
- source(dependencyTemplates, runtimeTemplate) {
638
- return this.getSource(
639
- this.getSourceString(this.options.mode, runtimeTemplate)
640
- );
641
- }
642
-
643
- size() {
644
- // base penalty
645
- const initialSize = 160;
646
-
647
- // if we dont have dependencies we stop here.
648
- return this.dependencies.reduce(
649
- (size, dependency) => size + 5 + dependency.userRequest.length,
650
- initialSize
651
- );
652
- }
653
- }
654
-
655
- // TODO remove in webpack 5
656
- Object.defineProperty(ContextModule.prototype, "recursive", {
657
- configurable: false,
658
- get: util.deprecate(function() {
659
- return this.options.recursive;
660
- }, "ContextModule.recursive has been moved to ContextModule.options.recursive"),
661
- set: util.deprecate(function(value) {
662
- this.options.recursive = value;
663
- }, "ContextModule.recursive has been moved to ContextModule.options.recursive")
664
- });
665
-
666
- // TODO remove in webpack 5
667
- Object.defineProperty(ContextModule.prototype, "regExp", {
668
- configurable: false,
669
- get: util.deprecate(function() {
670
- return this.options.regExp;
671
- }, "ContextModule.regExp has been moved to ContextModule.options.regExp"),
672
- set: util.deprecate(function(value) {
673
- this.options.regExp = value;
674
- }, "ContextModule.regExp has been moved to ContextModule.options.regExp")
675
- });
676
-
677
- // TODO remove in webpack 5
678
- Object.defineProperty(ContextModule.prototype, "addon", {
679
- configurable: false,
680
- get: util.deprecate(function() {
681
- return this.options.addon;
682
- }, "ContextModule.addon has been moved to ContextModule.options.addon"),
683
- set: util.deprecate(function(value) {
684
- this.options.addon = value;
685
- }, "ContextModule.addon has been moved to ContextModule.options.addon")
686
- });
687
-
688
- // TODO remove in webpack 5
689
- Object.defineProperty(ContextModule.prototype, "async", {
690
- configurable: false,
691
- get: util.deprecate(function() {
692
- return this.options.mode;
693
- }, "ContextModule.async has been moved to ContextModule.options.mode"),
694
- set: util.deprecate(function(value) {
695
- this.options.mode = value;
696
- }, "ContextModule.async has been moved to ContextModule.options.mode")
697
- });
698
-
699
- // TODO remove in webpack 5
700
- Object.defineProperty(ContextModule.prototype, "chunkName", {
701
- configurable: false,
702
- get: util.deprecate(function() {
703
- return this.options.chunkName;
704
- }, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"),
705
- set: util.deprecate(function(value) {
706
- this.options.chunkName = value;
707
- }, "ContextModule.chunkName has been moved to ContextModule.options.chunkName")
708
- });
709
-
710
- module.exports = ContextModule;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+ const path = require("path");
7
+ const util = require("util");
8
+ const { OriginalSource, RawSource } = require("webpack-sources");
9
+ const Module = require("./Module");
10
+ const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
11
+ const Template = require("./Template");
12
+
13
+ class ContextModule extends Module {
14
+ // type ContextMode = "sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"
15
+ // type ContextOptions = { resource: string, recursive: boolean, regExp: RegExp, addon?: string, mode?: ContextMode, chunkName?: string, include?: RegExp, exclude?: RegExp, groupOptions?: Object }
16
+ // resolveDependencies: (fs: FS, options: ContextOptions, (err: Error?, dependencies: Dependency[]) => void) => void
17
+ // options: ContextOptions
18
+ constructor(resolveDependencies, options) {
19
+ let resource;
20
+ let resourceQuery;
21
+ const queryIdx = options.resource.indexOf("?");
22
+ if (queryIdx >= 0) {
23
+ resource = options.resource.substr(0, queryIdx);
24
+ resourceQuery = options.resource.substr(queryIdx);
25
+ } else {
26
+ resource = options.resource;
27
+ resourceQuery = "";
28
+ }
29
+
30
+ super("javascript/dynamic", resource);
31
+
32
+ // Info from Factory
33
+ this.resolveDependencies = resolveDependencies;
34
+ this.options = Object.assign({}, options, {
35
+ resource: resource,
36
+ resourceQuery: resourceQuery
37
+ });
38
+ if (options.resolveOptions !== undefined) {
39
+ this.resolveOptions = options.resolveOptions;
40
+ }
41
+
42
+ // Info from Build
43
+ this._contextDependencies = new Set([this.context]);
44
+
45
+ if (typeof options.mode !== "string") {
46
+ throw new Error("options.mode is a required option");
47
+ }
48
+
49
+ this._identifier = this._createIdentifier();
50
+ }
51
+
52
+ updateCacheModule(module) {
53
+ this.resolveDependencies = module.resolveDependencies;
54
+ this.options = module.options;
55
+ this.resolveOptions = module.resolveOptions;
56
+ }
57
+
58
+ prettyRegExp(regexString) {
59
+ // remove the "/" at the front and the beginning
60
+ // "/foo/" -> "foo"
61
+ return regexString.substring(1, regexString.length - 1);
62
+ }
63
+
64
+ contextify(context, request) {
65
+ return request
66
+ .split("!")
67
+ .map(subrequest => {
68
+ let rp = path.relative(context, subrequest);
69
+ if (path.sep === "\\") rp = rp.replace(/\\/g, "/");
70
+ if (rp.indexOf("../") !== 0) rp = "./" + rp;
71
+ return rp;
72
+ })
73
+ .join("!");
74
+ }
75
+
76
+ _createIdentifier() {
77
+ let identifier = this.context;
78
+ if (this.options.resourceQuery) {
79
+ identifier += ` ${this.options.resourceQuery}`;
80
+ }
81
+ if (this.options.mode) {
82
+ identifier += ` ${this.options.mode}`;
83
+ }
84
+ if (!this.options.recursive) {
85
+ identifier += " nonrecursive";
86
+ }
87
+ if (this.options.addon) {
88
+ identifier += ` ${this.options.addon}`;
89
+ }
90
+ if (this.options.regExp) {
91
+ identifier += ` ${this.options.regExp}`;
92
+ }
93
+ if (this.options.include) {
94
+ identifier += ` include: ${this.options.include}`;
95
+ }
96
+ if (this.options.exclude) {
97
+ identifier += ` exclude: ${this.options.exclude}`;
98
+ }
99
+ if (this.options.groupOptions) {
100
+ identifier += ` groupOptions: ${JSON.stringify(
101
+ this.options.groupOptions
102
+ )}`;
103
+ }
104
+ if (this.options.namespaceObject === "strict") {
105
+ identifier += " strict namespace object";
106
+ } else if (this.options.namespaceObject) {
107
+ identifier += " namespace object";
108
+ }
109
+
110
+ return identifier;
111
+ }
112
+
113
+ identifier() {
114
+ return this._identifier;
115
+ }
116
+
117
+ readableIdentifier(requestShortener) {
118
+ let identifier = requestShortener.shorten(this.context);
119
+ if (this.options.resourceQuery) {
120
+ identifier += ` ${this.options.resourceQuery}`;
121
+ }
122
+ if (this.options.mode) {
123
+ identifier += ` ${this.options.mode}`;
124
+ }
125
+ if (!this.options.recursive) {
126
+ identifier += " nonrecursive";
127
+ }
128
+ if (this.options.addon) {
129
+ identifier += ` ${requestShortener.shorten(this.options.addon)}`;
130
+ }
131
+ if (this.options.regExp) {
132
+ identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
133
+ }
134
+ if (this.options.include) {
135
+ identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
136
+ }
137
+ if (this.options.exclude) {
138
+ identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
139
+ }
140
+ if (this.options.groupOptions) {
141
+ const groupOptions = this.options.groupOptions;
142
+ for (const key of Object.keys(groupOptions)) {
143
+ identifier += ` ${key}: ${groupOptions[key]}`;
144
+ }
145
+ }
146
+ if (this.options.namespaceObject === "strict") {
147
+ identifier += " strict namespace object";
148
+ } else if (this.options.namespaceObject) {
149
+ identifier += " namespace object";
150
+ }
151
+
152
+ return identifier;
153
+ }
154
+
155
+ libIdent(options) {
156
+ let identifier = this.contextify(options.context, this.context);
157
+ if (this.options.mode) {
158
+ identifier += ` ${this.options.mode}`;
159
+ }
160
+ if (this.options.recursive) {
161
+ identifier += " recursive";
162
+ }
163
+ if (this.options.addon) {
164
+ identifier += ` ${this.contextify(options.context, this.options.addon)}`;
165
+ }
166
+ if (this.options.regExp) {
167
+ identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
168
+ }
169
+ if (this.options.include) {
170
+ identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
171
+ }
172
+ if (this.options.exclude) {
173
+ identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
174
+ }
175
+
176
+ return identifier;
177
+ }
178
+
179
+ needRebuild(fileTimestamps, contextTimestamps) {
180
+ const ts = contextTimestamps.get(this.context);
181
+ if (!ts) {
182
+ return true;
183
+ }
184
+
185
+ return ts >= this.buildInfo.builtTime;
186
+ }
187
+
188
+ build(options, compilation, resolver, fs, callback) {
189
+ this.built = true;
190
+ this.buildMeta = {};
191
+ this.buildInfo = {
192
+ builtTime: Date.now(),
193
+ contextDependencies: this._contextDependencies
194
+ };
195
+ this.resolveDependencies(fs, this.options, (err, dependencies) => {
196
+ if (err) return callback(err);
197
+
198
+ // abort if something failed
199
+ // this will create an empty context
200
+ if (!dependencies) {
201
+ callback();
202
+ return;
203
+ }
204
+
205
+ // enhance dependencies with meta info
206
+ for (const dep of dependencies) {
207
+ dep.loc = dep.userRequest;
208
+ dep.request = this.options.addon + dep.request;
209
+ }
210
+
211
+ if (this.options.mode === "sync" || this.options.mode === "eager") {
212
+ // if we have an sync or eager context
213
+ // just add all dependencies and continue
214
+ this.dependencies = dependencies;
215
+ } else if (this.options.mode === "lazy-once") {
216
+ // for the lazy-once mode create a new async dependency block
217
+ // and add that block to this context
218
+ if (dependencies.length > 0) {
219
+ const block = new AsyncDependenciesBlock(
220
+ Object.assign({}, this.options.groupOptions, {
221
+ name: this.options.chunkName
222
+ }),
223
+ this
224
+ );
225
+ for (const dep of dependencies) {
226
+ block.addDependency(dep);
227
+ }
228
+ this.addBlock(block);
229
+ }
230
+ } else if (
231
+ this.options.mode === "weak" ||
232
+ this.options.mode === "async-weak"
233
+ ) {
234
+ // we mark all dependencies as weak
235
+ for (const dep of dependencies) {
236
+ dep.weak = true;
237
+ }
238
+ this.dependencies = dependencies;
239
+ } else if (this.options.mode === "lazy") {
240
+ // if we are lazy create a new async dependency block per dependency
241
+ // and add all blocks to this context
242
+ let index = 0;
243
+ for (const dep of dependencies) {
244
+ let chunkName = this.options.chunkName;
245
+ if (chunkName) {
246
+ if (!/\[(index|request)\]/.test(chunkName)) {
247
+ chunkName += "[index]";
248
+ }
249
+ chunkName = chunkName.replace(/\[index\]/g, index++);
250
+ chunkName = chunkName.replace(
251
+ /\[request\]/g,
252
+ Template.toPath(dep.userRequest)
253
+ );
254
+ }
255
+ const block = new AsyncDependenciesBlock(
256
+ Object.assign({}, this.options.groupOptions, {
257
+ name: chunkName
258
+ }),
259
+ dep.module,
260
+ dep.loc,
261
+ dep.userRequest
262
+ );
263
+ block.addDependency(dep);
264
+ this.addBlock(block);
265
+ }
266
+ } else {
267
+ callback(
268
+ new Error(`Unsupported mode "${this.options.mode}" in context`)
269
+ );
270
+ return;
271
+ }
272
+ callback();
273
+ });
274
+ }
275
+
276
+ getUserRequestMap(dependencies) {
277
+ // if we filter first we get a new array
278
+ // therefor we dont need to create a clone of dependencies explicitly
279
+ // therefore the order of this is !important!
280
+ return dependencies
281
+ .filter(dependency => dependency.module)
282
+ .sort((a, b) => {
283
+ if (a.userRequest === b.userRequest) {
284
+ return 0;
285
+ }
286
+ return a.userRequest < b.userRequest ? -1 : 1;
287
+ })
288
+ .reduce((map, dep) => {
289
+ map[dep.userRequest] = dep.module.id;
290
+ return map;
291
+ }, Object.create(null));
292
+ }
293
+
294
+ getFakeMap(dependencies) {
295
+ if (!this.options.namespaceObject) {
296
+ return 9;
297
+ }
298
+ // if we filter first we get a new array
299
+ // therefor we dont need to create a clone of dependencies explicitly
300
+ // therefore the order of this is !important!
301
+ let hasNonHarmony = false;
302
+ let hasNamespace = false;
303
+ let hasNamed = false;
304
+ const fakeMap = dependencies
305
+ .filter(dependency => dependency.module)
306
+ .sort((a, b) => {
307
+ return b.module.id - a.module.id;
308
+ })
309
+ .reduce((map, dep) => {
310
+ const exportsType =
311
+ dep.module.buildMeta && dep.module.buildMeta.exportsType;
312
+ const id = dep.module.id;
313
+ if (!exportsType) {
314
+ map[id] = this.options.namespaceObject === "strict" ? 1 : 7;
315
+ hasNonHarmony = true;
316
+ } else if (exportsType === "namespace") {
317
+ map[id] = 9;
318
+ hasNamespace = true;
319
+ } else if (exportsType === "named") {
320
+ map[id] = 3;
321
+ hasNamed = true;
322
+ }
323
+ return map;
324
+ }, Object.create(null));
325
+ if (!hasNamespace && hasNonHarmony && !hasNamed) {
326
+ return this.options.namespaceObject === "strict" ? 1 : 7;
327
+ }
328
+ if (hasNamespace && !hasNonHarmony && !hasNamed) {
329
+ return 9;
330
+ }
331
+ if (!hasNamespace && !hasNonHarmony && hasNamed) {
332
+ return 3;
333
+ }
334
+ if (!hasNamespace && !hasNonHarmony && !hasNamed) {
335
+ return 9;
336
+ }
337
+ return fakeMap;
338
+ }
339
+
340
+ getFakeMapInitStatement(fakeMap) {
341
+ return typeof fakeMap === "object"
342
+ ? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
343
+ : "";
344
+ }
345
+
346
+ getReturn(type) {
347
+ if (type === 9) {
348
+ return "__webpack_require__(id)";
349
+ }
350
+ return `__webpack_require__.t(id, ${type})`;
351
+ }
352
+
353
+ getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
354
+ if (typeof fakeMap === "number") {
355
+ return `return ${this.getReturn(fakeMap)};`;
356
+ }
357
+ return `return __webpack_require__.t(id, ${fakeMapDataExpression})`;
358
+ }
359
+
360
+ getSyncSource(dependencies, id) {
361
+ const map = this.getUserRequestMap(dependencies);
362
+ const fakeMap = this.getFakeMap(dependencies);
363
+ const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
364
+
365
+ return `var map = ${JSON.stringify(map, null, "\t")};
366
+ ${this.getFakeMapInitStatement(fakeMap)}
367
+
368
+ function webpackContext(req) {
369
+ var id = webpackContextResolve(req);
370
+ ${returnModuleObject}
371
+ }
372
+ function webpackContextResolve(req) {
373
+ var id = map[req];
374
+ if(!(id + 1)) { // check for number or string
375
+ var e = new Error("Cannot find module '" + req + "'");
376
+ e.code = 'MODULE_NOT_FOUND';
377
+ throw e;
378
+ }
379
+ return id;
380
+ }
381
+ webpackContext.keys = function webpackContextKeys() {
382
+ return Object.keys(map);
383
+ };
384
+ webpackContext.resolve = webpackContextResolve;
385
+ module.exports = webpackContext;
386
+ webpackContext.id = ${JSON.stringify(id)};`;
387
+ }
388
+
389
+ getWeakSyncSource(dependencies, id) {
390
+ const map = this.getUserRequestMap(dependencies);
391
+ const fakeMap = this.getFakeMap(dependencies);
392
+ const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
393
+
394
+ return `var map = ${JSON.stringify(map, null, "\t")};
395
+ ${this.getFakeMapInitStatement(fakeMap)}
396
+
397
+ function webpackContext(req) {
398
+ var id = webpackContextResolve(req);
399
+ if(!__webpack_require__.m[id]) {
400
+ var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
401
+ e.code = 'MODULE_NOT_FOUND';
402
+ throw e;
403
+ }
404
+ ${returnModuleObject}
405
+ }
406
+ function webpackContextResolve(req) {
407
+ var id = map[req];
408
+ if(!(id + 1)) { // check for number or string
409
+ var e = new Error("Cannot find module '" + req + "'");
410
+ e.code = 'MODULE_NOT_FOUND';
411
+ throw e;
412
+ }
413
+ return id;
414
+ }
415
+ webpackContext.keys = function webpackContextKeys() {
416
+ return Object.keys(map);
417
+ };
418
+ webpackContext.resolve = webpackContextResolve;
419
+ webpackContext.id = ${JSON.stringify(id)};
420
+ module.exports = webpackContext;`;
421
+ }
422
+
423
+ getAsyncWeakSource(dependencies, id) {
424
+ const map = this.getUserRequestMap(dependencies);
425
+ const fakeMap = this.getFakeMap(dependencies);
426
+ const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
427
+
428
+ return `var map = ${JSON.stringify(map, null, "\t")};
429
+ ${this.getFakeMapInitStatement(fakeMap)}
430
+
431
+ function webpackAsyncContext(req) {
432
+ return webpackAsyncContextResolve(req).then(function(id) {
433
+ if(!__webpack_require__.m[id]) {
434
+ var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
435
+ e.code = 'MODULE_NOT_FOUND';
436
+ throw e;
437
+ }
438
+ ${returnModuleObject}
439
+ });
440
+ }
441
+ function webpackAsyncContextResolve(req) {
442
+ // Here Promise.resolve().then() is used instead of new Promise() to prevent
443
+ // uncaught exception popping up in devtools
444
+ return Promise.resolve().then(function() {
445
+ var id = map[req];
446
+ if(!(id + 1)) { // check for number or string
447
+ var e = new Error("Cannot find module '" + req + "'");
448
+ e.code = 'MODULE_NOT_FOUND';
449
+ throw e;
450
+ }
451
+ return id;
452
+ });
453
+ }
454
+ webpackAsyncContext.keys = function webpackAsyncContextKeys() {
455
+ return Object.keys(map);
456
+ };
457
+ webpackAsyncContext.resolve = webpackAsyncContextResolve;
458
+ webpackAsyncContext.id = ${JSON.stringify(id)};
459
+ module.exports = webpackAsyncContext;`;
460
+ }
461
+
462
+ getEagerSource(dependencies, id) {
463
+ const map = this.getUserRequestMap(dependencies);
464
+ const fakeMap = this.getFakeMap(dependencies);
465
+ const thenFunction =
466
+ fakeMap !== 9
467
+ ? `function(id) {
468
+ ${this.getReturnModuleObjectSource(fakeMap)}
469
+ }`
470
+ : "__webpack_require__";
471
+ return `var map = ${JSON.stringify(map, null, "\t")};
472
+ ${this.getFakeMapInitStatement(fakeMap)}
473
+
474
+ function webpackAsyncContext(req) {
475
+ return webpackAsyncContextResolve(req).then(${thenFunction});
476
+ }
477
+ function webpackAsyncContextResolve(req) {
478
+ // Here Promise.resolve().then() is used instead of new Promise() to prevent
479
+ // uncaught exception popping up in devtools
480
+ return Promise.resolve().then(function() {
481
+ var id = map[req];
482
+ if(!(id + 1)) { // check for number or string
483
+ var e = new Error("Cannot find module '" + req + "'");
484
+ e.code = 'MODULE_NOT_FOUND';
485
+ throw e;
486
+ }
487
+ return id;
488
+ });
489
+ }
490
+ webpackAsyncContext.keys = function webpackAsyncContextKeys() {
491
+ return Object.keys(map);
492
+ };
493
+ webpackAsyncContext.resolve = webpackAsyncContextResolve;
494
+ webpackAsyncContext.id = ${JSON.stringify(id)};
495
+ module.exports = webpackAsyncContext;`;
496
+ }
497
+
498
+ getLazyOnceSource(block, dependencies, id, runtimeTemplate) {
499
+ const promise = runtimeTemplate.blockPromise({
500
+ block,
501
+ message: "lazy-once context"
502
+ });
503
+ const map = this.getUserRequestMap(dependencies);
504
+ const fakeMap = this.getFakeMap(dependencies);
505
+ const thenFunction =
506
+ fakeMap !== 9
507
+ ? `function(id) {
508
+ ${this.getReturnModuleObjectSource(fakeMap)};
509
+ }`
510
+ : "__webpack_require__";
511
+
512
+ return `var map = ${JSON.stringify(map, null, "\t")};
513
+ ${this.getFakeMapInitStatement(fakeMap)}
514
+
515
+ function webpackAsyncContext(req) {
516
+ return webpackAsyncContextResolve(req).then(${thenFunction});
517
+ }
518
+ function webpackAsyncContextResolve(req) {
519
+ return ${promise}.then(function() {
520
+ var id = map[req];
521
+ if(!(id + 1)) { // check for number or string
522
+ var e = new Error("Cannot find module '" + req + "'");
523
+ e.code = 'MODULE_NOT_FOUND';
524
+ throw e;
525
+ }
526
+ return id;
527
+ });
528
+ }
529
+ webpackAsyncContext.keys = function webpackAsyncContextKeys() {
530
+ return Object.keys(map);
531
+ };
532
+ webpackAsyncContext.resolve = webpackAsyncContextResolve;
533
+ webpackAsyncContext.id = ${JSON.stringify(id)};
534
+ module.exports = webpackAsyncContext;`;
535
+ }
536
+
537
+ getLazySource(blocks, id) {
538
+ let hasMultipleOrNoChunks = false;
539
+ const fakeMap = this.getFakeMap(blocks.map(b => b.dependencies[0]));
540
+ const map = blocks
541
+ .filter(block => block.dependencies[0].module)
542
+ .map(block => ({
543
+ dependency: block.dependencies[0],
544
+ block: block,
545
+ userRequest: block.dependencies[0].userRequest
546
+ }))
547
+ .sort((a, b) => {
548
+ if (a.userRequest === b.userRequest) return 0;
549
+ return a.userRequest < b.userRequest ? -1 : 1;
550
+ })
551
+ .reduce((map, item) => {
552
+ const chunks =
553
+ (item.block.chunkGroup && item.block.chunkGroup.chunks) || [];
554
+ if (chunks.length !== 1) {
555
+ hasMultipleOrNoChunks = true;
556
+ }
557
+ const arrayStart = [item.dependency.module.id];
558
+ if (typeof fakeMap === "object") {
559
+ arrayStart.push(fakeMap[item.dependency.module.id]);
560
+ }
561
+ map[item.userRequest] = arrayStart.concat(
562
+ chunks.map(chunk => chunk.id)
563
+ );
564
+
565
+ return map;
566
+ }, Object.create(null));
567
+
568
+ const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1;
569
+ const requestPrefix = hasMultipleOrNoChunks
570
+ ? `Promise.all(ids.slice(${chunksStartPosition}).map(__webpack_require__.e))`
571
+ : `__webpack_require__.e(ids[${chunksStartPosition}])`;
572
+ const returnModuleObject = this.getReturnModuleObjectSource(
573
+ fakeMap,
574
+ "ids[1]"
575
+ );
576
+
577
+ return `var map = ${JSON.stringify(map, null, "\t")};
578
+ function webpackAsyncContext(req) {
579
+ var ids = map[req];
580
+ if(!ids) {
581
+ return Promise.resolve().then(function() {
582
+ var e = new Error("Cannot find module '" + req + "'");
583
+ e.code = 'MODULE_NOT_FOUND';
584
+ throw e;
585
+ });
586
+ }
587
+ return ${requestPrefix}.then(function() {
588
+ var id = ids[0];
589
+ ${returnModuleObject}
590
+ });
591
+ }
592
+ webpackAsyncContext.keys = function webpackAsyncContextKeys() {
593
+ return Object.keys(map);
594
+ };
595
+ webpackAsyncContext.id = ${JSON.stringify(id)};
596
+ module.exports = webpackAsyncContext;`;
597
+ }
598
+
599
+ getSourceForEmptyContext(id) {
600
+ return `function webpackEmptyContext(req) {
601
+ var e = new Error("Cannot find module '" + req + "'");
602
+ e.code = 'MODULE_NOT_FOUND';
603
+ throw e;
604
+ }
605
+ webpackEmptyContext.keys = function() { return []; };
606
+ webpackEmptyContext.resolve = webpackEmptyContext;
607
+ module.exports = webpackEmptyContext;
608
+ webpackEmptyContext.id = ${JSON.stringify(id)};`;
609
+ }
610
+
611
+ getSourceForEmptyAsyncContext(id) {
612
+ return `function webpackEmptyAsyncContext(req) {
613
+ // Here Promise.resolve().then() is used instead of new Promise() to prevent
614
+ // uncaught exception popping up in devtools
615
+ return Promise.resolve().then(function() {
616
+ var e = new Error("Cannot find module '" + req + "'");
617
+ e.code = 'MODULE_NOT_FOUND';
618
+ throw e;
619
+ });
620
+ }
621
+ webpackEmptyAsyncContext.keys = function() { return []; };
622
+ webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
623
+ module.exports = webpackEmptyAsyncContext;
624
+ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
625
+ }
626
+
627
+ getSourceString(asyncMode, runtimeTemplate) {
628
+ if (asyncMode === "lazy") {
629
+ if (this.blocks && this.blocks.length > 0) {
630
+ return this.getLazySource(this.blocks, this.id);
631
+ }
632
+ return this.getSourceForEmptyAsyncContext(this.id);
633
+ }
634
+ if (asyncMode === "eager") {
635
+ if (this.dependencies && this.dependencies.length > 0) {
636
+ return this.getEagerSource(this.dependencies, this.id);
637
+ }
638
+ return this.getSourceForEmptyAsyncContext(this.id);
639
+ }
640
+ if (asyncMode === "lazy-once") {
641
+ const block = this.blocks[0];
642
+ if (block) {
643
+ return this.getLazyOnceSource(
644
+ block,
645
+ block.dependencies,
646
+ this.id,
647
+ runtimeTemplate
648
+ );
649
+ }
650
+ return this.getSourceForEmptyAsyncContext(this.id);
651
+ }
652
+ if (asyncMode === "async-weak") {
653
+ if (this.dependencies && this.dependencies.length > 0) {
654
+ return this.getAsyncWeakSource(this.dependencies, this.id);
655
+ }
656
+ return this.getSourceForEmptyAsyncContext(this.id);
657
+ }
658
+ if (asyncMode === "weak") {
659
+ if (this.dependencies && this.dependencies.length > 0) {
660
+ return this.getWeakSyncSource(this.dependencies, this.id);
661
+ }
662
+ }
663
+ if (this.dependencies && this.dependencies.length > 0) {
664
+ return this.getSyncSource(this.dependencies, this.id);
665
+ }
666
+ return this.getSourceForEmptyContext(this.id);
667
+ }
668
+
669
+ getSource(sourceString) {
670
+ if (this.useSourceMap) {
671
+ return new OriginalSource(sourceString, this.identifier());
672
+ }
673
+ return new RawSource(sourceString);
674
+ }
675
+
676
+ source(dependencyTemplates, runtimeTemplate) {
677
+ return this.getSource(
678
+ this.getSourceString(this.options.mode, runtimeTemplate)
679
+ );
680
+ }
681
+
682
+ size() {
683
+ // base penalty
684
+ const initialSize = 160;
685
+
686
+ // if we dont have dependencies we stop here.
687
+ return this.dependencies.reduce(
688
+ (size, dependency) => size + 5 + dependency.userRequest.length,
689
+ initialSize
690
+ );
691
+ }
692
+ }
693
+
694
+ // TODO remove in webpack 5
695
+ Object.defineProperty(ContextModule.prototype, "recursive", {
696
+ configurable: false,
697
+ get: util.deprecate(function() {
698
+ return this.options.recursive;
699
+ }, "ContextModule.recursive has been moved to ContextModule.options.recursive"),
700
+ set: util.deprecate(function(value) {
701
+ this.options.recursive = value;
702
+ }, "ContextModule.recursive has been moved to ContextModule.options.recursive")
703
+ });
704
+
705
+ // TODO remove in webpack 5
706
+ Object.defineProperty(ContextModule.prototype, "regExp", {
707
+ configurable: false,
708
+ get: util.deprecate(function() {
709
+ return this.options.regExp;
710
+ }, "ContextModule.regExp has been moved to ContextModule.options.regExp"),
711
+ set: util.deprecate(function(value) {
712
+ this.options.regExp = value;
713
+ }, "ContextModule.regExp has been moved to ContextModule.options.regExp")
714
+ });
715
+
716
+ // TODO remove in webpack 5
717
+ Object.defineProperty(ContextModule.prototype, "addon", {
718
+ configurable: false,
719
+ get: util.deprecate(function() {
720
+ return this.options.addon;
721
+ }, "ContextModule.addon has been moved to ContextModule.options.addon"),
722
+ set: util.deprecate(function(value) {
723
+ this.options.addon = value;
724
+ }, "ContextModule.addon has been moved to ContextModule.options.addon")
725
+ });
726
+
727
+ // TODO remove in webpack 5
728
+ Object.defineProperty(ContextModule.prototype, "async", {
729
+ configurable: false,
730
+ get: util.deprecate(function() {
731
+ return this.options.mode;
732
+ }, "ContextModule.async has been moved to ContextModule.options.mode"),
733
+ set: util.deprecate(function(value) {
734
+ this.options.mode = value;
735
+ }, "ContextModule.async has been moved to ContextModule.options.mode")
736
+ });
737
+
738
+ // TODO remove in webpack 5
739
+ Object.defineProperty(ContextModule.prototype, "chunkName", {
740
+ configurable: false,
741
+ get: util.deprecate(function() {
742
+ return this.options.chunkName;
743
+ }, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"),
744
+ set: util.deprecate(function(value) {
745
+ this.options.chunkName = value;
746
+ }, "ContextModule.chunkName has been moved to ContextModule.options.chunkName")
747
+ });
748
+
749
+ module.exports = ContextModule;