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,483 +1,501 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const asyncLib = require("neo-async");
8
- const {
9
- Tapable,
10
- AsyncSeriesWaterfallHook,
11
- SyncWaterfallHook,
12
- SyncBailHook,
13
- SyncHook,
14
- HookMap
15
- } = require("tapable");
16
- const NormalModule = require("./NormalModule");
17
- const RawModule = require("./RawModule");
18
- const RuleSet = require("./RuleSet");
19
- const cachedMerge = require("./util/cachedMerge");
20
-
21
- const EMPTY_RESOLVE_OPTIONS = {};
22
-
23
- const loaderToIdent = data => {
24
- if (!data.options) return data.loader;
25
- if (typeof data.options === "string") return data.loader + "?" + data.options;
26
- if (typeof data.options !== "object")
27
- throw new Error("loader options must be string or object");
28
- if (data.ident) return data.loader + "??" + data.ident;
29
- return data.loader + "?" + JSON.stringify(data.options);
30
- };
31
-
32
- const identToLoaderRequest = resultString => {
33
- const idx = resultString.indexOf("?");
34
- if (idx >= 0) {
35
- const loader = resultString.substr(0, idx);
36
- const options = resultString.substr(idx + 1);
37
- return {
38
- loader,
39
- options
40
- };
41
- } else {
42
- return {
43
- loader: resultString,
44
- options: undefined
45
- };
46
- }
47
- };
48
-
49
- const dependencyCache = new WeakMap();
50
-
51
- class NormalModuleFactory extends Tapable {
52
- constructor(context, resolverFactory, options) {
53
- super();
54
- this.hooks = {
55
- resolver: new SyncWaterfallHook(["resolver"]),
56
- factory: new SyncWaterfallHook(["factory"]),
57
- beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
58
- afterResolve: new AsyncSeriesWaterfallHook(["data"]),
59
- createModule: new SyncBailHook(["data"]),
60
- module: new SyncWaterfallHook(["module", "data"]),
61
- createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
62
- parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
63
- createGenerator: new HookMap(
64
- () => new SyncBailHook(["generatorOptions"])
65
- ),
66
- generator: new HookMap(
67
- () => new SyncHook(["generator", "generatorOptions"])
68
- )
69
- };
70
- this._pluginCompat.tap("NormalModuleFactory", options => {
71
- switch (options.name) {
72
- case "before-resolve":
73
- case "after-resolve":
74
- options.async = true;
75
- break;
76
- case "parser":
77
- this.hooks.parser
78
- .for("javascript/auto")
79
- .tap(options.fn.name || "unnamed compat plugin", options.fn);
80
- return true;
81
- }
82
- let match;
83
- match = /^parser (.+)$/.exec(options.name);
84
- if (match) {
85
- this.hooks.parser
86
- .for(match[1])
87
- .tap(
88
- options.fn.name || "unnamed compat plugin",
89
- options.fn.bind(this)
90
- );
91
- return true;
92
- }
93
- match = /^create-parser (.+)$/.exec(options.name);
94
- if (match) {
95
- this.hooks.createParser
96
- .for(match[1])
97
- .tap(
98
- options.fn.name || "unnamed compat plugin",
99
- options.fn.bind(this)
100
- );
101
- return true;
102
- }
103
- });
104
- this.resolverFactory = resolverFactory;
105
- this.ruleSet = new RuleSet(options.defaultRules.concat(options.rules));
106
- this.cachePredicate =
107
- typeof options.unsafeCache === "function"
108
- ? options.unsafeCache
109
- : Boolean.bind(null, options.unsafeCache);
110
- this.context = context || "";
111
- this.parserCache = Object.create(null);
112
- this.generatorCache = Object.create(null);
113
- this.hooks.factory.tap("NormalModuleFactory", () => (result, callback) => {
114
- let resolver = this.hooks.resolver.call(null);
115
-
116
- // Ignored
117
- if (!resolver) return callback();
118
-
119
- resolver(result, (err, data) => {
120
- if (err) return callback(err);
121
-
122
- // Ignored
123
- if (!data) return callback();
124
-
125
- // direct module
126
- if (typeof data.source === "function") return callback(null, data);
127
-
128
- this.hooks.afterResolve.callAsync(data, (err, result) => {
129
- if (err) return callback(err);
130
-
131
- // Ignored
132
- if (!result) return callback();
133
-
134
- let createdModule = this.hooks.createModule.call(result);
135
- if (!createdModule) {
136
- if (!result.request) {
137
- return callback(new Error("Empty dependency (no request)"));
138
- }
139
-
140
- createdModule = new NormalModule(result);
141
- }
142
-
143
- createdModule = this.hooks.module.call(createdModule, result);
144
-
145
- return callback(null, createdModule);
146
- });
147
- });
148
- });
149
- this.hooks.resolver.tap("NormalModuleFactory", () => (data, callback) => {
150
- const contextInfo = data.contextInfo;
151
- const context = data.context;
152
- const request = data.request;
153
-
154
- const noPreAutoLoaders = request.startsWith("-!");
155
- const noAutoLoaders = noPreAutoLoaders || request.startsWith("!");
156
- const noPrePostAutoLoaders = request.startsWith("!!");
157
- let elements = request
158
- .replace(/^-?!+/, "")
159
- .replace(/!!+/g, "!")
160
- .split("!");
161
- let resource = elements.pop();
162
- elements = elements.map(identToLoaderRequest);
163
-
164
- const loaderResolver = this.getResolver("loader");
165
- const normalResolver = this.getResolver("normal", data.resolveOptions);
166
-
167
- asyncLib.parallel(
168
- [
169
- callback =>
170
- this.resolveRequestArray(
171
- contextInfo,
172
- context,
173
- elements,
174
- loaderResolver,
175
- callback
176
- ),
177
- callback => {
178
- if (resource === "" || resource[0] === "?") {
179
- return callback(null, {
180
- resource
181
- });
182
- }
183
-
184
- normalResolver.resolve(
185
- contextInfo,
186
- context,
187
- resource,
188
- {},
189
- (err, resource, resourceResolveData) => {
190
- if (err) return callback(err);
191
- callback(null, {
192
- resourceResolveData,
193
- resource
194
- });
195
- }
196
- );
197
- }
198
- ],
199
- (err, results) => {
200
- if (err) return callback(err);
201
- let loaders = results[0];
202
- const resourceResolveData = results[1].resourceResolveData;
203
- resource = results[1].resource;
204
-
205
- // translate option idents
206
- try {
207
- for (const item of loaders) {
208
- if (typeof item.options === "string" && item.options[0] === "?") {
209
- const ident = item.options.substr(1);
210
- item.options = this.ruleSet.findOptionsByIdent(ident);
211
- item.ident = ident;
212
- }
213
- }
214
- } catch (e) {
215
- return callback(e);
216
- }
217
-
218
- if (resource === false) {
219
- // ignored
220
- return callback(
221
- null,
222
- new RawModule(
223
- "/* (ignored) */",
224
- `ignored ${context} ${request}`,
225
- `${request} (ignored)`
226
- )
227
- );
228
- }
229
-
230
- const userRequest = loaders
231
- .map(loaderToIdent)
232
- .concat([resource])
233
- .join("!");
234
-
235
- let resourcePath = resource;
236
- let resourceQuery = "";
237
- const queryIndex = resourcePath.indexOf("?");
238
- if (queryIndex >= 0) {
239
- resourceQuery = resourcePath.substr(queryIndex);
240
- resourcePath = resourcePath.substr(0, queryIndex);
241
- }
242
-
243
- const result = this.ruleSet.exec({
244
- resource: resourcePath,
245
- resourceQuery,
246
- issuer: contextInfo.issuer,
247
- compiler: contextInfo.compiler
248
- });
249
- const settings = {};
250
- const useLoadersPost = [];
251
- const useLoaders = [];
252
- const useLoadersPre = [];
253
- for (const r of result) {
254
- if (r.type === "use") {
255
- if (r.enforce === "post" && !noPrePostAutoLoaders)
256
- useLoadersPost.push(r.value);
257
- else if (
258
- r.enforce === "pre" &&
259
- !noPreAutoLoaders &&
260
- !noPrePostAutoLoaders
261
- )
262
- useLoadersPre.push(r.value);
263
- else if (!r.enforce && !noAutoLoaders && !noPrePostAutoLoaders)
264
- useLoaders.push(r.value);
265
- } else if (
266
- typeof r.value === "object" &&
267
- r.value !== null &&
268
- typeof settings[r.type] === "object" &&
269
- settings[r.type] !== null
270
- ) {
271
- settings[r.type] = cachedMerge(settings[r.type], r.value);
272
- } else {
273
- settings[r.type] = r.value;
274
- }
275
- }
276
- asyncLib.parallel(
277
- [
278
- this.resolveRequestArray.bind(
279
- this,
280
- contextInfo,
281
- this.context,
282
- useLoadersPost,
283
- loaderResolver
284
- ),
285
- this.resolveRequestArray.bind(
286
- this,
287
- contextInfo,
288
- this.context,
289
- useLoaders,
290
- loaderResolver
291
- ),
292
- this.resolveRequestArray.bind(
293
- this,
294
- contextInfo,
295
- this.context,
296
- useLoadersPre,
297
- loaderResolver
298
- )
299
- ],
300
- (err, results) => {
301
- if (err) return callback(err);
302
- loaders = results[0].concat(loaders, results[1], results[2]);
303
- process.nextTick(() => {
304
- const type = settings.type;
305
- const resolveOptions = settings.resolve;
306
- callback(null, {
307
- context: context,
308
- request: loaders
309
- .map(loaderToIdent)
310
- .concat([resource])
311
- .join("!"),
312
- dependencies: data.dependencies,
313
- userRequest,
314
- rawRequest: request,
315
- loaders,
316
- resource,
317
- resourceResolveData,
318
- settings,
319
- type,
320
- parser: this.getParser(type, settings.parser),
321
- generator: this.getGenerator(type, settings.generator),
322
- resolveOptions
323
- });
324
- });
325
- }
326
- );
327
- }
328
- );
329
- });
330
- }
331
-
332
- create(data, callback) {
333
- const dependencies = data.dependencies;
334
- const cacheEntry = dependencyCache.get(dependencies[0]);
335
- if (cacheEntry) return callback(null, cacheEntry);
336
- const context = data.context || this.context;
337
- const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
338
- const request = dependencies[0].request;
339
- const contextInfo = data.contextInfo || {};
340
- this.hooks.beforeResolve.callAsync(
341
- {
342
- contextInfo,
343
- resolveOptions,
344
- context,
345
- request,
346
- dependencies
347
- },
348
- (err, result) => {
349
- if (err) return callback(err);
350
-
351
- // Ignored
352
- if (!result) return callback();
353
-
354
- const factory = this.hooks.factory.call(null);
355
-
356
- // Ignored
357
- if (!factory) return callback();
358
-
359
- factory(result, (err, module) => {
360
- if (err) return callback(err);
361
-
362
- if (module && this.cachePredicate(module)) {
363
- for (const d of dependencies) {
364
- dependencyCache.set(d, module);
365
- }
366
- }
367
-
368
- callback(null, module);
369
- });
370
- }
371
- );
372
- }
373
-
374
- resolveRequestArray(contextInfo, context, array, resolver, callback) {
375
- if (array.length === 0) return callback(null, []);
376
- asyncLib.map(
377
- array,
378
- (item, callback) => {
379
- resolver.resolve(
380
- contextInfo,
381
- context,
382
- item.loader,
383
- {},
384
- (err, result) => {
385
- if (
386
- err &&
387
- /^[^/]*$/.test(item.loader) &&
388
- !/-loader$/.test(item.loader)
389
- ) {
390
- return resolver.resolve(
391
- contextInfo,
392
- context,
393
- item.loader + "-loader",
394
- {},
395
- err2 => {
396
- if (!err2) {
397
- err.message =
398
- err.message +
399
- "\n" +
400
- "BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
401
- ` You need to specify '${
402
- item.loader
403
- }-loader' instead of '${item.loader}',\n` +
404
- " see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed";
405
- }
406
- callback(err);
407
- }
408
- );
409
- }
410
- if (err) return callback(err);
411
-
412
- const optionsOnly = item.options
413
- ? {
414
- options: item.options
415
- }
416
- : undefined;
417
- return callback(
418
- null,
419
- Object.assign({}, item, identToLoaderRequest(result), optionsOnly)
420
- );
421
- }
422
- );
423
- },
424
- callback
425
- );
426
- }
427
-
428
- getParser(type, parserOptions) {
429
- let ident = type;
430
- if (parserOptions) {
431
- if (parserOptions.ident) ident = `${type}|${parserOptions.ident}`;
432
- else ident = JSON.stringify([type, parserOptions]);
433
- }
434
- if (ident in this.parserCache) {
435
- return this.parserCache[ident];
436
- }
437
- return (this.parserCache[ident] = this.createParser(type, parserOptions));
438
- }
439
-
440
- createParser(type, parserOptions = {}) {
441
- const parser = this.hooks.createParser.for(type).call(parserOptions);
442
- if (!parser) {
443
- throw new Error(`No parser registered for ${type}`);
444
- }
445
- this.hooks.parser.for(type).call(parser, parserOptions);
446
- return parser;
447
- }
448
-
449
- getGenerator(type, generatorOptions) {
450
- let ident = type;
451
- if (generatorOptions) {
452
- if (generatorOptions.ident) ident = `${type}|${generatorOptions.ident}`;
453
- else ident = JSON.stringify([type, generatorOptions]);
454
- }
455
- if (ident in this.generatorCache) {
456
- return this.generatorCache[ident];
457
- }
458
- return (this.generatorCache[ident] = this.createGenerator(
459
- type,
460
- generatorOptions
461
- ));
462
- }
463
-
464
- createGenerator(type, generatorOptions = {}) {
465
- const generator = this.hooks.createGenerator
466
- .for(type)
467
- .call(generatorOptions);
468
- if (!generator) {
469
- throw new Error(`No generator registered for ${type}`);
470
- }
471
- this.hooks.generator.for(type).call(generator, generatorOptions);
472
- return generator;
473
- }
474
-
475
- getResolver(type, resolveOptions) {
476
- return this.resolverFactory.get(
477
- type,
478
- resolveOptions || EMPTY_RESOLVE_OPTIONS
479
- );
480
- }
481
- }
482
-
483
- module.exports = NormalModuleFactory;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const asyncLib = require("neo-async");
8
+ const {
9
+ Tapable,
10
+ AsyncSeriesWaterfallHook,
11
+ SyncWaterfallHook,
12
+ SyncBailHook,
13
+ SyncHook,
14
+ HookMap
15
+ } = require("tapable");
16
+ const NormalModule = require("./NormalModule");
17
+ const RawModule = require("./RawModule");
18
+ const RuleSet = require("./RuleSet");
19
+ const cachedMerge = require("./util/cachedMerge");
20
+
21
+ const EMPTY_RESOLVE_OPTIONS = {};
22
+
23
+ const loaderToIdent = data => {
24
+ if (!data.options) {
25
+ return data.loader;
26
+ }
27
+ if (typeof data.options === "string") {
28
+ return data.loader + "?" + data.options;
29
+ }
30
+ if (typeof data.options !== "object") {
31
+ throw new Error("loader options must be string or object");
32
+ }
33
+ if (data.ident) {
34
+ return data.loader + "??" + data.ident;
35
+ }
36
+ return data.loader + "?" + JSON.stringify(data.options);
37
+ };
38
+
39
+ const identToLoaderRequest = resultString => {
40
+ const idx = resultString.indexOf("?");
41
+ if (idx >= 0) {
42
+ const loader = resultString.substr(0, idx);
43
+ const options = resultString.substr(idx + 1);
44
+ return {
45
+ loader,
46
+ options
47
+ };
48
+ } else {
49
+ return {
50
+ loader: resultString,
51
+ options: undefined
52
+ };
53
+ }
54
+ };
55
+
56
+ const dependencyCache = new WeakMap();
57
+
58
+ class NormalModuleFactory extends Tapable {
59
+ constructor(context, resolverFactory, options) {
60
+ super();
61
+ this.hooks = {
62
+ resolver: new SyncWaterfallHook(["resolver"]),
63
+ factory: new SyncWaterfallHook(["factory"]),
64
+ beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
65
+ afterResolve: new AsyncSeriesWaterfallHook(["data"]),
66
+ createModule: new SyncBailHook(["data"]),
67
+ module: new SyncWaterfallHook(["module", "data"]),
68
+ createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
69
+ parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
70
+ createGenerator: new HookMap(
71
+ () => new SyncBailHook(["generatorOptions"])
72
+ ),
73
+ generator: new HookMap(
74
+ () => new SyncHook(["generator", "generatorOptions"])
75
+ )
76
+ };
77
+ this._pluginCompat.tap("NormalModuleFactory", options => {
78
+ switch (options.name) {
79
+ case "before-resolve":
80
+ case "after-resolve":
81
+ options.async = true;
82
+ break;
83
+ case "parser":
84
+ this.hooks.parser
85
+ .for("javascript/auto")
86
+ .tap(options.fn.name || "unnamed compat plugin", options.fn);
87
+ return true;
88
+ }
89
+ let match;
90
+ match = /^parser (.+)$/.exec(options.name);
91
+ if (match) {
92
+ this.hooks.parser
93
+ .for(match[1])
94
+ .tap(
95
+ options.fn.name || "unnamed compat plugin",
96
+ options.fn.bind(this)
97
+ );
98
+ return true;
99
+ }
100
+ match = /^create-parser (.+)$/.exec(options.name);
101
+ if (match) {
102
+ this.hooks.createParser
103
+ .for(match[1])
104
+ .tap(
105
+ options.fn.name || "unnamed compat plugin",
106
+ options.fn.bind(this)
107
+ );
108
+ return true;
109
+ }
110
+ });
111
+ this.resolverFactory = resolverFactory;
112
+ this.ruleSet = new RuleSet(options.defaultRules.concat(options.rules));
113
+ this.cachePredicate =
114
+ typeof options.unsafeCache === "function"
115
+ ? options.unsafeCache
116
+ : Boolean.bind(null, options.unsafeCache);
117
+ this.context = context || "";
118
+ this.parserCache = Object.create(null);
119
+ this.generatorCache = Object.create(null);
120
+ this.hooks.factory.tap("NormalModuleFactory", () => (result, callback) => {
121
+ let resolver = this.hooks.resolver.call(null);
122
+
123
+ // Ignored
124
+ if (!resolver) return callback();
125
+
126
+ resolver(result, (err, data) => {
127
+ if (err) return callback(err);
128
+
129
+ // Ignored
130
+ if (!data) return callback();
131
+
132
+ // direct module
133
+ if (typeof data.source === "function") return callback(null, data);
134
+
135
+ this.hooks.afterResolve.callAsync(data, (err, result) => {
136
+ if (err) return callback(err);
137
+
138
+ // Ignored
139
+ if (!result) return callback();
140
+
141
+ let createdModule = this.hooks.createModule.call(result);
142
+ if (!createdModule) {
143
+ if (!result.request) {
144
+ return callback(new Error("Empty dependency (no request)"));
145
+ }
146
+
147
+ createdModule = new NormalModule(result);
148
+ }
149
+
150
+ createdModule = this.hooks.module.call(createdModule, result);
151
+
152
+ return callback(null, createdModule);
153
+ });
154
+ });
155
+ });
156
+ this.hooks.resolver.tap("NormalModuleFactory", () => (data, callback) => {
157
+ const contextInfo = data.contextInfo;
158
+ const context = data.context;
159
+ const request = data.request;
160
+
161
+ const noPreAutoLoaders = request.startsWith("-!");
162
+ const noAutoLoaders = noPreAutoLoaders || request.startsWith("!");
163
+ const noPrePostAutoLoaders = request.startsWith("!!");
164
+ let elements = request
165
+ .replace(/^-?!+/, "")
166
+ .replace(/!!+/g, "!")
167
+ .split("!");
168
+ let resource = elements.pop();
169
+ elements = elements.map(identToLoaderRequest);
170
+
171
+ const loaderResolver = this.getResolver("loader");
172
+ const normalResolver = this.getResolver("normal", data.resolveOptions);
173
+
174
+ asyncLib.parallel(
175
+ [
176
+ callback =>
177
+ this.resolveRequestArray(
178
+ contextInfo,
179
+ context,
180
+ elements,
181
+ loaderResolver,
182
+ callback
183
+ ),
184
+ callback => {
185
+ if (resource === "" || resource[0] === "?") {
186
+ return callback(null, {
187
+ resource
188
+ });
189
+ }
190
+
191
+ normalResolver.resolve(
192
+ contextInfo,
193
+ context,
194
+ resource,
195
+ {},
196
+ (err, resource, resourceResolveData) => {
197
+ if (err) return callback(err);
198
+ callback(null, {
199
+ resourceResolveData,
200
+ resource
201
+ });
202
+ }
203
+ );
204
+ }
205
+ ],
206
+ (err, results) => {
207
+ if (err) return callback(err);
208
+ let loaders = results[0];
209
+ const resourceResolveData = results[1].resourceResolveData;
210
+ resource = results[1].resource;
211
+
212
+ // translate option idents
213
+ try {
214
+ for (const item of loaders) {
215
+ if (typeof item.options === "string" && item.options[0] === "?") {
216
+ const ident = item.options.substr(1);
217
+ item.options = this.ruleSet.findOptionsByIdent(ident);
218
+ item.ident = ident;
219
+ }
220
+ }
221
+ } catch (e) {
222
+ return callback(e);
223
+ }
224
+
225
+ if (resource === false) {
226
+ // ignored
227
+ return callback(
228
+ null,
229
+ new RawModule(
230
+ "/* (ignored) */",
231
+ `ignored ${context} ${request}`,
232
+ `${request} (ignored)`
233
+ )
234
+ );
235
+ }
236
+
237
+ const userRequest = loaders
238
+ .map(loaderToIdent)
239
+ .concat([resource])
240
+ .join("!");
241
+
242
+ let resourcePath = resource;
243
+ let resourceQuery = "";
244
+ const queryIndex = resourcePath.indexOf("?");
245
+ if (queryIndex >= 0) {
246
+ resourceQuery = resourcePath.substr(queryIndex);
247
+ resourcePath = resourcePath.substr(0, queryIndex);
248
+ }
249
+
250
+ const result = this.ruleSet.exec({
251
+ resource: resourcePath,
252
+ resourceQuery,
253
+ issuer: contextInfo.issuer,
254
+ compiler: contextInfo.compiler
255
+ });
256
+ const settings = {};
257
+ const useLoadersPost = [];
258
+ const useLoaders = [];
259
+ const useLoadersPre = [];
260
+ for (const r of result) {
261
+ if (r.type === "use") {
262
+ if (r.enforce === "post" && !noPrePostAutoLoaders) {
263
+ useLoadersPost.push(r.value);
264
+ } else if (
265
+ r.enforce === "pre" &&
266
+ !noPreAutoLoaders &&
267
+ !noPrePostAutoLoaders
268
+ ) {
269
+ useLoadersPre.push(r.value);
270
+ } else if (
271
+ !r.enforce &&
272
+ !noAutoLoaders &&
273
+ !noPrePostAutoLoaders
274
+ ) {
275
+ useLoaders.push(r.value);
276
+ }
277
+ } else if (
278
+ typeof r.value === "object" &&
279
+ r.value !== null &&
280
+ typeof settings[r.type] === "object" &&
281
+ settings[r.type] !== null
282
+ ) {
283
+ settings[r.type] = cachedMerge(settings[r.type], r.value);
284
+ } else {
285
+ settings[r.type] = r.value;
286
+ }
287
+ }
288
+ asyncLib.parallel(
289
+ [
290
+ this.resolveRequestArray.bind(
291
+ this,
292
+ contextInfo,
293
+ this.context,
294
+ useLoadersPost,
295
+ loaderResolver
296
+ ),
297
+ this.resolveRequestArray.bind(
298
+ this,
299
+ contextInfo,
300
+ this.context,
301
+ useLoaders,
302
+ loaderResolver
303
+ ),
304
+ this.resolveRequestArray.bind(
305
+ this,
306
+ contextInfo,
307
+ this.context,
308
+ useLoadersPre,
309
+ loaderResolver
310
+ )
311
+ ],
312
+ (err, results) => {
313
+ if (err) return callback(err);
314
+ loaders = results[0].concat(loaders, results[1], results[2]);
315
+ process.nextTick(() => {
316
+ const type = settings.type;
317
+ const resolveOptions = settings.resolve;
318
+ callback(null, {
319
+ context: context,
320
+ request: loaders
321
+ .map(loaderToIdent)
322
+ .concat([resource])
323
+ .join("!"),
324
+ dependencies: data.dependencies,
325
+ userRequest,
326
+ rawRequest: request,
327
+ loaders,
328
+ resource,
329
+ resourceResolveData,
330
+ settings,
331
+ type,
332
+ parser: this.getParser(type, settings.parser),
333
+ generator: this.getGenerator(type, settings.generator),
334
+ resolveOptions
335
+ });
336
+ });
337
+ }
338
+ );
339
+ }
340
+ );
341
+ });
342
+ }
343
+
344
+ create(data, callback) {
345
+ const dependencies = data.dependencies;
346
+ const cacheEntry = dependencyCache.get(dependencies[0]);
347
+ if (cacheEntry) return callback(null, cacheEntry);
348
+ const context = data.context || this.context;
349
+ const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
350
+ const request = dependencies[0].request;
351
+ const contextInfo = data.contextInfo || {};
352
+ this.hooks.beforeResolve.callAsync(
353
+ {
354
+ contextInfo,
355
+ resolveOptions,
356
+ context,
357
+ request,
358
+ dependencies
359
+ },
360
+ (err, result) => {
361
+ if (err) return callback(err);
362
+
363
+ // Ignored
364
+ if (!result) return callback();
365
+
366
+ const factory = this.hooks.factory.call(null);
367
+
368
+ // Ignored
369
+ if (!factory) return callback();
370
+
371
+ factory(result, (err, module) => {
372
+ if (err) return callback(err);
373
+
374
+ if (module && this.cachePredicate(module)) {
375
+ for (const d of dependencies) {
376
+ dependencyCache.set(d, module);
377
+ }
378
+ }
379
+
380
+ callback(null, module);
381
+ });
382
+ }
383
+ );
384
+ }
385
+
386
+ resolveRequestArray(contextInfo, context, array, resolver, callback) {
387
+ if (array.length === 0) return callback(null, []);
388
+ asyncLib.map(
389
+ array,
390
+ (item, callback) => {
391
+ resolver.resolve(
392
+ contextInfo,
393
+ context,
394
+ item.loader,
395
+ {},
396
+ (err, result) => {
397
+ if (
398
+ err &&
399
+ /^[^/]*$/.test(item.loader) &&
400
+ !/-loader$/.test(item.loader)
401
+ ) {
402
+ return resolver.resolve(
403
+ contextInfo,
404
+ context,
405
+ item.loader + "-loader",
406
+ {},
407
+ err2 => {
408
+ if (!err2) {
409
+ err.message =
410
+ err.message +
411
+ "\n" +
412
+ "BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
413
+ ` You need to specify '${
414
+ item.loader
415
+ }-loader' instead of '${item.loader}',\n` +
416
+ " see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed";
417
+ }
418
+ callback(err);
419
+ }
420
+ );
421
+ }
422
+ if (err) return callback(err);
423
+
424
+ const optionsOnly = item.options
425
+ ? {
426
+ options: item.options
427
+ }
428
+ : undefined;
429
+ return callback(
430
+ null,
431
+ Object.assign({}, item, identToLoaderRequest(result), optionsOnly)
432
+ );
433
+ }
434
+ );
435
+ },
436
+ callback
437
+ );
438
+ }
439
+
440
+ getParser(type, parserOptions) {
441
+ let ident = type;
442
+ if (parserOptions) {
443
+ if (parserOptions.ident) {
444
+ ident = `${type}|${parserOptions.ident}`;
445
+ } else {
446
+ ident = JSON.stringify([type, parserOptions]);
447
+ }
448
+ }
449
+ if (ident in this.parserCache) {
450
+ return this.parserCache[ident];
451
+ }
452
+ return (this.parserCache[ident] = this.createParser(type, parserOptions));
453
+ }
454
+
455
+ createParser(type, parserOptions = {}) {
456
+ const parser = this.hooks.createParser.for(type).call(parserOptions);
457
+ if (!parser) {
458
+ throw new Error(`No parser registered for ${type}`);
459
+ }
460
+ this.hooks.parser.for(type).call(parser, parserOptions);
461
+ return parser;
462
+ }
463
+
464
+ getGenerator(type, generatorOptions) {
465
+ let ident = type;
466
+ if (generatorOptions) {
467
+ if (generatorOptions.ident) {
468
+ ident = `${type}|${generatorOptions.ident}`;
469
+ } else {
470
+ ident = JSON.stringify([type, generatorOptions]);
471
+ }
472
+ }
473
+ if (ident in this.generatorCache) {
474
+ return this.generatorCache[ident];
475
+ }
476
+ return (this.generatorCache[ident] = this.createGenerator(
477
+ type,
478
+ generatorOptions
479
+ ));
480
+ }
481
+
482
+ createGenerator(type, generatorOptions = {}) {
483
+ const generator = this.hooks.createGenerator
484
+ .for(type)
485
+ .call(generatorOptions);
486
+ if (!generator) {
487
+ throw new Error(`No generator registered for ${type}`);
488
+ }
489
+ this.hooks.generator.for(type).call(generator, generatorOptions);
490
+ return generator;
491
+ }
492
+
493
+ getResolver(type, resolveOptions) {
494
+ return this.resolverFactory.get(
495
+ type,
496
+ resolveOptions || EMPTY_RESOLVE_OPTIONS
497
+ );
498
+ }
499
+ }
500
+
501
+ module.exports = NormalModuleFactory;