| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-11 12:27:09 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 	AsyncSeriesBailHook, | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | 	SyncWaterfallHook, | 
					
						
							|  |  |  | 	SyncBailHook, | 
					
						
							|  |  |  | 	SyncHook, | 
					
						
							|  |  |  | 	HookMap | 
					
						
							|  |  |  | } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | const Module = require("./Module"); | 
					
						
							|  |  |  | const ModuleFactory = require("./ModuleFactory"); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | const NormalModule = require("./NormalModule"); | 
					
						
							|  |  |  | const RawModule = require("./RawModule"); | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin"); | 
					
						
							|  |  |  | const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin"); | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | const DescriptionDataMatcherRulePlugin = require("./rules/DescriptionDataMatcherRulePlugin"); | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | const RuleSetCompiler = require("./rules/RuleSetCompiler"); | 
					
						
							|  |  |  | const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin"); | 
					
						
							| 
									
										
										
										
											2019-08-07 15:54:43 +08:00
										 |  |  | const LazySet = require("./util/LazySet"); | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | const { getScheme } = require("./util/URLAbsoluteSpecifier"); | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const { join } = require("./util/fs"); | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | const { parseResource } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */ | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | /** @typedef {import("./Generator")} Generator */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ | 
					
						
							|  |  |  | /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | /** @typedef {import("./Parser")} Parser */ | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | /** @typedef {import("./ResolverFactory")} ResolverFactory */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */ | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ResolveData | 
					
						
							|  |  |  |  * @property {ModuleFactoryCreateData["contextInfo"]} contextInfo | 
					
						
							|  |  |  |  * @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions | 
					
						
							|  |  |  |  * @property {string} context | 
					
						
							|  |  |  |  * @property {string} request | 
					
						
							|  |  |  |  * @property {ModuleDependency[]} dependencies | 
					
						
							|  |  |  |  * @property {Object} createData | 
					
						
							| 
									
										
										
										
											2019-08-07 15:54:43 +08:00
										 |  |  |  * @property {LazySet<string>} fileDependencies | 
					
						
							|  |  |  |  * @property {LazySet<string>} missingDependencies | 
					
						
							|  |  |  |  * @property {LazySet<string>} contextDependencies | 
					
						
							| 
									
										
										
										
											2020-06-24 20:09:10 +08:00
										 |  |  |  * @property {boolean} cacheable allow to use the unsafe cache | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ResourceData | 
					
						
							|  |  |  |  * @property {string} resource | 
					
						
							|  |  |  |  * @property {string} path | 
					
						
							|  |  |  |  * @property {string} query | 
					
						
							|  |  |  |  * @property {string} fragment | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 02:01:06 +08:00
										 |  |  | const EMPTY_RESOLVE_OPTIONS = {}; | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | const MATCH_RESOURCE_REGEX = /^([^!]+)!=!/; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const loaderToIdent = data => { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 	if (!data.options) { | 
					
						
							|  |  |  | 		return data.loader; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (typeof data.options === "string") { | 
					
						
							|  |  |  | 		return data.loader + "?" + data.options; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (typeof data.options !== "object") { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 		throw new Error("loader options must be string or object"); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (data.ident) { | 
					
						
							|  |  |  | 		return data.loader + "??" + data.ident; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	return data.loader + "?" + JSON.stringify(data.options); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | const stringifyLoadersAndResource = (loaders, resource) => { | 
					
						
							|  |  |  | 	let str = ""; | 
					
						
							|  |  |  | 	for (const loader of loaders) { | 
					
						
							|  |  |  | 		str += loaderToIdent(loader) + "!"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return str + resource; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 19:22:37 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string} resultString resultString | 
					
						
							|  |  |  |  * @returns {{loader: string, options: string|undefined}} parsed loader request | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const identToLoaderRequest = resultString => { | 
					
						
							| 
									
										
										
										
											2017-04-04 16:26:16 +08:00
										 |  |  | 	const idx = resultString.indexOf("?"); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (idx >= 0) { | 
					
						
							| 
									
										
										
										
											2018-04-04 19:42:37 +08:00
										 |  |  | 		const loader = resultString.substr(0, idx); | 
					
						
							|  |  |  | 		const options = resultString.substr(idx + 1); | 
					
						
							| 
									
										
										
										
											2016-12-08 23:57:47 +08:00
										 |  |  | 		return { | 
					
						
							| 
									
										
										
										
											2018-04-04 19:42:37 +08:00
										 |  |  | 			loader, | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 			options | 
					
						
							| 
									
										
										
										
											2016-12-08 23:57:47 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return { | 
					
						
							| 
									
										
										
										
											2018-04-04 19:41:56 +08:00
										 |  |  | 			loader: resultString, | 
					
						
							| 
									
										
										
										
											2018-04-04 19:42:37 +08:00
										 |  |  | 			options: undefined | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-08 23:57:47 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-12-08 23:57:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | const needCalls = (times, callback) => { | 
					
						
							|  |  |  | 	return err => { | 
					
						
							|  |  |  | 		if (--times === 0) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (err && times > 0) { | 
					
						
							|  |  |  | 			times = NaN; | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | // TODO webpack 6 remove
 | 
					
						
							|  |  |  | const deprecationChangedHookMessage = name => | 
					
						
							|  |  |  | 	`NormalModuleFactory.${name} is no longer a waterfall hook, but a bailing hook instead. ` + | 
					
						
							|  |  |  | 	"Do not return the passed object, but modify it instead. " + | 
					
						
							|  |  |  | 	"Returning false will ignore the request and results in no module created."; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 19:42:18 +08:00
										 |  |  | const dependencyCache = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | const ruleSetCompiler = new RuleSetCompiler([ | 
					
						
							|  |  |  | 	new BasicMatcherRulePlugin("test", "resource"), | 
					
						
							| 
									
										
										
										
											2020-05-18 15:00:28 +08:00
										 |  |  | 	new BasicMatcherRulePlugin("mimetype"), | 
					
						
							| 
									
										
										
										
											2020-08-05 05:42:29 +08:00
										 |  |  | 	new BasicMatcherRulePlugin("dependency"), | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 	new BasicMatcherRulePlugin("include", "resource"), | 
					
						
							|  |  |  | 	new BasicMatcherRulePlugin("exclude", "resource", true), | 
					
						
							|  |  |  | 	new BasicMatcherRulePlugin("resource"), | 
					
						
							|  |  |  | 	new BasicMatcherRulePlugin("resourceQuery"), | 
					
						
							| 
									
										
										
										
											2020-07-03 23:03:15 +08:00
										 |  |  | 	new BasicMatcherRulePlugin("resourceFragment"), | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 	new BasicMatcherRulePlugin("realResource"), | 
					
						
							|  |  |  | 	new BasicMatcherRulePlugin("issuer"), | 
					
						
							|  |  |  | 	new BasicMatcherRulePlugin("compiler"), | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 	new DescriptionDataMatcherRulePlugin(), | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 	new BasicEffectRulePlugin("type"), | 
					
						
							|  |  |  | 	new BasicEffectRulePlugin("sideEffects"), | 
					
						
							|  |  |  | 	new BasicEffectRulePlugin("parser"), | 
					
						
							|  |  |  | 	new BasicEffectRulePlugin("resolve"), | 
					
						
							| 
									
										
										
										
											2019-11-16 00:27:36 +08:00
										 |  |  | 	new BasicEffectRulePlugin("generator"), | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 	new UseEffectRulePlugin() | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | class NormalModuleFactory extends ModuleFactory { | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Object} param params | 
					
						
							|  |  |  | 	 * @param {string=} param.context context | 
					
						
							|  |  |  | 	 * @param {InputFileSystem} param.fs file system | 
					
						
							|  |  |  | 	 * @param {ResolverFactory} param.resolverFactory resolverFactory | 
					
						
							|  |  |  | 	 * @param {ModuleOptions} param.options options | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | 	 * @param {Object=} param.associatedObjectForCache an object to which the cache will be attached | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | 	constructor({ | 
					
						
							|  |  |  | 		context, | 
					
						
							|  |  |  | 		fs, | 
					
						
							|  |  |  | 		resolverFactory, | 
					
						
							|  |  |  | 		options, | 
					
						
							|  |  |  | 		associatedObjectForCache | 
					
						
							|  |  |  | 	}) { | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		this.hooks = Object.freeze({ | 
					
						
							| 
									
										
										
										
											2019-05-10 17:06:25 +08:00
										 |  |  | 			/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			resolve: new AsyncSeriesBailHook(["resolveData"]), | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 			/** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */ | 
					
						
							|  |  |  | 			resolveForScheme: new HookMap( | 
					
						
							|  |  |  | 				() => new AsyncSeriesBailHook(["resourceData", "resolveData"]) | 
					
						
							|  |  |  | 			), | 
					
						
							| 
									
										
										
										
											2019-05-10 17:06:25 +08:00
										 |  |  | 			/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			factorize: new AsyncSeriesBailHook(["resolveData"]), | 
					
						
							| 
									
										
										
										
											2019-05-10 17:06:25 +08:00
										 |  |  | 			/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			beforeResolve: new AsyncSeriesBailHook(["resolveData"]), | 
					
						
							| 
									
										
										
										
											2019-05-10 17:06:25 +08:00
										 |  |  | 			/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			afterResolve: new AsyncSeriesBailHook(["resolveData"]), | 
					
						
							| 
									
										
										
										
											2020-06-13 20:45:37 +08:00
										 |  |  | 			/** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], TODO>} */ | 
					
						
							|  |  |  | 			createModule: new AsyncSeriesBailHook(["createData", "resolveData"]), | 
					
						
							| 
									
										
										
										
											2019-05-10 17:06:25 +08:00
										 |  |  | 			/** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], TODO>} */ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			module: new SyncWaterfallHook(["module", "createData", "resolveData"]), | 
					
						
							| 
									
										
										
										
											2017-11-28 16:54:24 +08:00
										 |  |  | 			createParser: new HookMap(() => new SyncBailHook(["parserOptions"])), | 
					
						
							|  |  |  | 			parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			createGenerator: new HookMap( | 
					
						
							|  |  |  | 				() => new SyncBailHook(["generatorOptions"]) | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			generator: new HookMap( | 
					
						
							|  |  |  | 				() => new SyncHook(["generator", "generatorOptions"]) | 
					
						
							|  |  |  | 			) | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.resolverFactory = resolverFactory; | 
					
						
							| 
									
										
										
										
											2019-06-04 17:32:46 +08:00
										 |  |  | 		this.ruleSet = ruleSetCompiler.compile([ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				rules: options.defaultRules | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				rules: options.rules | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		]); | 
					
						
							| 
									
										
										
										
											2018-10-31 17:11:08 +08:00
										 |  |  | 		this.unsafeCache = !!options.unsafeCache; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.cachePredicate = | 
					
						
							|  |  |  | 			typeof options.unsafeCache === "function" | 
					
						
							|  |  |  | 				? options.unsafeCache | 
					
						
							| 
									
										
										
										
											2018-10-31 17:11:08 +08:00
										 |  |  | 				: () => true; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 		this.context = context || ""; | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 		this.fs = fs; | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @type {Map<string, WeakMap<Object, TODO>>} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		this.parserCache = new Map(); | 
					
						
							|  |  |  | 		/** | 
					
						
							|  |  |  | 		 * @type {Map<string, WeakMap<Object, Generator>>} | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		this.generatorCache = new Map(); | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const cacheParseResource = parseResource.bindCache( | 
					
						
							|  |  |  | 			associatedObjectForCache | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		this.hooks.factorize.tapAsync( | 
					
						
							| 
									
										
										
										
											2019-11-08 18:13:16 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				name: "NormalModuleFactory", | 
					
						
							|  |  |  | 				stage: 100 | 
					
						
							| 
									
										
										
										
											2019-11-08 18:13:16 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			(resolveData, callback) => { | 
					
						
							|  |  |  | 				this.hooks.resolve.callAsync(resolveData, (err, result) => { | 
					
						
							|  |  |  | 					if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2015-05-13 06:15:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					// Ignored
 | 
					
						
							|  |  |  | 					if (result === false) return callback(); | 
					
						
							| 
									
										
										
										
											2015-05-13 06:15:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					// direct module
 | 
					
						
							|  |  |  | 					if (result instanceof Module) return callback(null, result); | 
					
						
							| 
									
										
										
										
											2015-05-13 06:15:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					if (typeof result === "object") | 
					
						
							|  |  |  | 						throw new Error( | 
					
						
							|  |  |  | 							deprecationChangedHookMessage("resolve") + | 
					
						
							|  |  |  | 								" Returning a Module object will result in this module used as result." | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2015-05-13 06:15:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					this.hooks.afterResolve.callAsync(resolveData, (err, result) => { | 
					
						
							|  |  |  | 						if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2016-02-10 02:32:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 						if (typeof result === "object") | 
					
						
							|  |  |  | 							throw new Error(deprecationChangedHookMessage("afterResolve")); | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 						// Ignored
 | 
					
						
							|  |  |  | 						if (result === false) return callback(); | 
					
						
							| 
									
										
										
										
											2015-05-17 00:27:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 						const createData = resolveData.createData; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 20:45:37 +08:00
										 |  |  | 						this.hooks.createModule.callAsync( | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 							createData, | 
					
						
							| 
									
										
										
										
											2020-06-13 20:45:37 +08:00
										 |  |  | 							resolveData, | 
					
						
							|  |  |  | 							(err, createdModule) => { | 
					
						
							|  |  |  | 								if (!createdModule) { | 
					
						
							|  |  |  | 									if (!resolveData.request) { | 
					
						
							|  |  |  | 										return callback(new Error("Empty dependency (no request)")); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 20:45:37 +08:00
										 |  |  | 									createdModule = new NormalModule(createData); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2015-05-13 06:15:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 20:45:37 +08:00
										 |  |  | 								createdModule = this.hooks.module.call( | 
					
						
							|  |  |  | 									createdModule, | 
					
						
							|  |  |  | 									createData, | 
					
						
							|  |  |  | 									resolveData | 
					
						
							|  |  |  | 								); | 
					
						
							| 
									
										
										
										
											2015-05-16 20:59:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 20:45:37 +08:00
										 |  |  | 								return callback(null, createdModule); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 						); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-07-24 17:54:58 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		this.hooks.resolve.tapAsync( | 
					
						
							| 
									
										
										
										
											2020-05-27 07:27:52 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				name: "NormalModuleFactory", | 
					
						
							|  |  |  | 				stage: 100 | 
					
						
							| 
									
										
										
										
											2020-05-27 07:27:52 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			(data, callback) => { | 
					
						
							|  |  |  | 				const { | 
					
						
							|  |  |  | 					contextInfo, | 
					
						
							|  |  |  | 					context, | 
					
						
							| 
									
										
										
										
											2020-05-27 07:27:52 +08:00
										 |  |  | 					dependencies, | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					request, | 
					
						
							| 
									
										
										
										
											2020-05-28 06:59:23 +08:00
										 |  |  | 					resolveOptions, | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					fileDependencies, | 
					
						
							|  |  |  | 					missingDependencies, | 
					
						
							|  |  |  | 					contextDependencies | 
					
						
							|  |  |  | 				} = data; | 
					
						
							| 
									
										
										
										
											2020-08-07 02:33:53 +08:00
										 |  |  | 				const dependencyType = | 
					
						
							| 
									
										
										
										
											2020-09-02 21:08:10 +08:00
										 |  |  | 					(dependencies.length > 0 && dependencies[0].category) || ""; | 
					
						
							| 
									
										
										
										
											2020-05-28 06:59:23 +08:00
										 |  |  | 				const loaderResolver = this.getResolver("loader"); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 				/** @type {ResourceData | undefined} */ | 
					
						
							|  |  |  | 				let matchResourceData = undefined; | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				/** @type {string} */ | 
					
						
							|  |  |  | 				let requestWithoutMatchResource = request; | 
					
						
							|  |  |  | 				const matchResourceMatch = MATCH_RESOURCE_REGEX.exec(request); | 
					
						
							|  |  |  | 				if (matchResourceMatch) { | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 					let matchResource = matchResourceMatch[1]; | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					if (matchResource.charCodeAt(0) === 46) { | 
					
						
							|  |  |  | 						// 46 === ".", 47 === "/"
 | 
					
						
							|  |  |  | 						const secondChar = matchResource.charCodeAt(1); | 
					
						
							|  |  |  | 						if ( | 
					
						
							|  |  |  | 							secondChar === 47 || | 
					
						
							|  |  |  | 							(secondChar === 46 && matchResource.charCodeAt(2) === 47) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							// if matchResources startsWith ../ or ./
 | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | 							matchResource = join(this.fs, context, matchResource); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 					matchResourceData = { | 
					
						
							|  |  |  | 						resource: matchResource, | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | 						...cacheParseResource(matchResource) | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 					}; | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					requestWithoutMatchResource = request.substr( | 
					
						
							|  |  |  | 						matchResourceMatch[0].length | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 				const firstChar = requestWithoutMatchResource.charCodeAt(0); | 
					
						
							|  |  |  | 				const secondChar = requestWithoutMatchResource.charCodeAt(1); | 
					
						
							|  |  |  | 				const noPreAutoLoaders = firstChar === 45 && secondChar === 33; // startsWith "-!"
 | 
					
						
							|  |  |  | 				const noAutoLoaders = noPreAutoLoaders || firstChar === 33; // startsWith "!"
 | 
					
						
							|  |  |  | 				const noPrePostAutoLoaders = firstChar === 33 && secondChar === 33; // startsWith "!!";
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				const rawElements = requestWithoutMatchResource | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					.slice( | 
					
						
							|  |  |  | 						noPreAutoLoaders || noPrePostAutoLoaders ? 2 : noAutoLoaders ? 1 : 0 | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 					.split(/!+/); | 
					
						
							|  |  |  | 				const unresolvedResource = rawElements.pop(); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				const elements = rawElements.map(identToLoaderRequest); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				const resolveContext = { | 
					
						
							|  |  |  | 					fileDependencies, | 
					
						
							|  |  |  | 					missingDependencies, | 
					
						
							|  |  |  | 					contextDependencies | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 				/** @type {ResourceDataWithData} */ | 
					
						
							|  |  |  | 				let resourceData; | 
					
						
							| 
									
										
										
										
											2020-06-26 05:14:50 +08:00
										 |  |  | 				/** @type {string | undefined} */ | 
					
						
							|  |  |  | 				const scheme = getScheme(unresolvedResource); | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 				let loaders; | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 				const continueCallback = needCalls(2, err => { | 
					
						
							|  |  |  | 					if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					// translate option idents
 | 
					
						
							|  |  |  | 					try { | 
					
						
							|  |  |  | 						for (const item of loaders) { | 
					
						
							|  |  |  | 							if (typeof item.options === "string" && item.options[0] === "?") { | 
					
						
							|  |  |  | 								const ident = item.options.substr(1); | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 								if (ident === "[[missing ident]]") { | 
					
						
							|  |  |  | 									throw new Error( | 
					
						
							|  |  |  | 										"No ident is provided by referenced loader. " + | 
					
						
							|  |  |  | 											"When using a function for Rule.use in config you need to " + | 
					
						
							|  |  |  | 											"provide an 'ident' property for referenced loader options." | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								item.options = this.ruleSet.references.get(ident); | 
					
						
							|  |  |  | 								if (item.options === undefined) { | 
					
						
							|  |  |  | 									throw new Error( | 
					
						
							|  |  |  | 										"Invalid ident is provided by referenced loader" | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 								item.ident = ident; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					} catch (e) { | 
					
						
							|  |  |  | 						return callback(e); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-07-24 17:54:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 					if (!resourceData) { | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						// ignored
 | 
					
						
							|  |  |  | 						return callback( | 
					
						
							|  |  |  | 							null, | 
					
						
							|  |  |  | 							new RawModule( | 
					
						
							|  |  |  | 								"/* (ignored) */", | 
					
						
							|  |  |  | 								`ignored|${request}`, | 
					
						
							|  |  |  | 								`${request} (ignored)` | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-07-24 17:54:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					const userRequest = | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 						(matchResourceData !== undefined | 
					
						
							|  |  |  | 							? `${matchResourceData.resource}!=!` | 
					
						
							|  |  |  | 							: "") + | 
					
						
							|  |  |  | 						stringifyLoadersAndResource(loaders, resourceData.resource); | 
					
						
							| 
									
										
										
										
											2017-07-24 17:54:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 					const resourceDataForRules = matchResourceData || resourceData; | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					const result = this.ruleSet.exec({ | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 						resource: resourceDataForRules.path, | 
					
						
							|  |  |  | 						realResource: resourceData.path, | 
					
						
							|  |  |  | 						resourceQuery: resourceDataForRules.query, | 
					
						
							|  |  |  | 						resourceFragment: resourceDataForRules.fragment, | 
					
						
							|  |  |  | 						mimetype: matchResourceData ? "" : resourceData.data.mimetype || "", | 
					
						
							| 
									
										
										
										
											2020-08-07 02:33:53 +08:00
										 |  |  | 						dependency: dependencyType, | 
					
						
							| 
									
										
										
										
											2020-07-17 16:27:48 +08:00
										 |  |  | 						descriptionData: matchResourceData | 
					
						
							|  |  |  | 							? undefined | 
					
						
							|  |  |  | 							: resourceData.data.descriptionFileData, | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						issuer: contextInfo.issuer, | 
					
						
							|  |  |  | 						compiler: contextInfo.compiler | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					const settings = {}; | 
					
						
							|  |  |  | 					const useLoadersPost = []; | 
					
						
							|  |  |  | 					const useLoaders = []; | 
					
						
							|  |  |  | 					const useLoadersPre = []; | 
					
						
							|  |  |  | 					for (const r of result) { | 
					
						
							|  |  |  | 						if (r.type === "use") { | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 							if (!noAutoLoaders && !noPrePostAutoLoaders) { | 
					
						
							|  |  |  | 								useLoaders.push(r.value); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} else if (r.type === "use-post") { | 
					
						
							|  |  |  | 							if (!noPrePostAutoLoaders) { | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 								useLoadersPost.push(r.value); | 
					
						
							| 
									
										
										
										
											2019-05-16 17:31:41 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} else if (r.type === "use-pre") { | 
					
						
							|  |  |  | 							if (!noPreAutoLoaders && !noPrePostAutoLoaders) { | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 								useLoadersPre.push(r.value); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						} else if ( | 
					
						
							|  |  |  | 							typeof r.value === "object" && | 
					
						
							|  |  |  | 							r.value !== null && | 
					
						
							|  |  |  | 							typeof settings[r.type] === "object" && | 
					
						
							|  |  |  | 							settings[r.type] !== null | 
					
						
							|  |  |  | 						) { | 
					
						
							| 
									
										
										
										
											2019-05-13 21:16:23 +08:00
										 |  |  | 							settings[r.type] = cachedCleverMerge(settings[r.type], r.value); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							settings[r.type] = r.value; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					let postLoaders, normalLoaders, preLoaders; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					const continueCallback = needCalls(3, err => { | 
					
						
							|  |  |  | 						if (err) { | 
					
						
							|  |  |  | 							return callback(err); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						const allLoaders = postLoaders; | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 						if (matchResourceData === undefined) { | 
					
						
							| 
									
										
										
										
											2019-07-01 17:15:52 +08:00
										 |  |  | 							for (const loader of loaders) allLoaders.push(loader); | 
					
						
							|  |  |  | 							for (const loader of normalLoaders) allLoaders.push(loader); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							for (const loader of normalLoaders) allLoaders.push(loader); | 
					
						
							|  |  |  | 							for (const loader of loaders) allLoaders.push(loader); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						for (const loader of preLoaders) allLoaders.push(loader); | 
					
						
							|  |  |  | 						const type = settings.type; | 
					
						
							|  |  |  | 						const resolveOptions = settings.resolve; | 
					
						
							|  |  |  | 						Object.assign(data.createData, { | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 							request: stringifyLoadersAndResource( | 
					
						
							|  |  |  | 								allLoaders, | 
					
						
							|  |  |  | 								resourceData.resource | 
					
						
							|  |  |  | 							), | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 							userRequest, | 
					
						
							|  |  |  | 							rawRequest: request, | 
					
						
							|  |  |  | 							loaders: allLoaders, | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 							resource: resourceData.resource, | 
					
						
							|  |  |  | 							matchResource: matchResourceData | 
					
						
							|  |  |  | 								? matchResourceData.resource | 
					
						
							|  |  |  | 								: undefined, | 
					
						
							|  |  |  | 							resourceResolveData: resourceData.data, | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 							settings, | 
					
						
							|  |  |  | 							type, | 
					
						
							|  |  |  | 							parser: this.getParser(type, settings.parser), | 
					
						
							|  |  |  | 							generator: this.getGenerator(type, settings.generator), | 
					
						
							|  |  |  | 							resolveOptions | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						callback(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					this.resolveRequestArray( | 
					
						
							|  |  |  | 						contextInfo, | 
					
						
							|  |  |  | 						this.context, | 
					
						
							|  |  |  | 						useLoadersPost, | 
					
						
							|  |  |  | 						loaderResolver, | 
					
						
							|  |  |  | 						resolveContext, | 
					
						
							|  |  |  | 						(err, result) => { | 
					
						
							|  |  |  | 							postLoaders = result; | 
					
						
							|  |  |  | 							continueCallback(err); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					this.resolveRequestArray( | 
					
						
							|  |  |  | 						contextInfo, | 
					
						
							|  |  |  | 						this.context, | 
					
						
							|  |  |  | 						useLoaders, | 
					
						
							|  |  |  | 						loaderResolver, | 
					
						
							|  |  |  | 						resolveContext, | 
					
						
							|  |  |  | 						(err, result) => { | 
					
						
							|  |  |  | 							normalLoaders = result; | 
					
						
							|  |  |  | 							continueCallback(err); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					this.resolveRequestArray( | 
					
						
							|  |  |  | 						contextInfo, | 
					
						
							|  |  |  | 						this.context, | 
					
						
							|  |  |  | 						useLoadersPre, | 
					
						
							|  |  |  | 						loaderResolver, | 
					
						
							|  |  |  | 						resolveContext, | 
					
						
							|  |  |  | 						(err, result) => { | 
					
						
							|  |  |  | 							preLoaders = result; | 
					
						
							|  |  |  | 							continueCallback(err); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.resolveRequestArray( | 
					
						
							|  |  |  | 					contextInfo, | 
					
						
							|  |  |  | 					context, | 
					
						
							|  |  |  | 					elements, | 
					
						
							|  |  |  | 					loaderResolver, | 
					
						
							|  |  |  | 					resolveContext, | 
					
						
							|  |  |  | 					(err, result) => { | 
					
						
							|  |  |  | 						if (err) return continueCallback(err); | 
					
						
							|  |  |  | 						loaders = result; | 
					
						
							|  |  |  | 						continueCallback(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 				// resource with scheme
 | 
					
						
							|  |  |  | 				if (scheme) { | 
					
						
							|  |  |  | 					resourceData = { | 
					
						
							|  |  |  | 						resource: unresolvedResource, | 
					
						
							|  |  |  | 						data: {}, | 
					
						
							|  |  |  | 						path: undefined, | 
					
						
							|  |  |  | 						query: undefined, | 
					
						
							|  |  |  | 						fragment: undefined | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 					this.hooks.resolveForScheme | 
					
						
							|  |  |  | 						.for(scheme) | 
					
						
							|  |  |  | 						.callAsync(resourceData, data, err => { | 
					
						
							|  |  |  | 							if (err) return continueCallback(err); | 
					
						
							|  |  |  | 							continueCallback(); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 				// resource without scheme and without path
 | 
					
						
							|  |  |  | 				else if (/^($|\?|#)/.test(unresolvedResource)) { | 
					
						
							|  |  |  | 					resourceData = { | 
					
						
							|  |  |  | 						resource: unresolvedResource, | 
					
						
							|  |  |  | 						data: {}, | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | 						...cacheParseResource(unresolvedResource) | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 					}; | 
					
						
							| 
									
										
										
										
											2020-05-17 21:28:15 +08:00
										 |  |  | 					continueCallback(); | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// resource without scheme and with path
 | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					const normalResolver = this.getResolver( | 
					
						
							|  |  |  | 						"normal", | 
					
						
							| 
									
										
										
										
											2020-08-06 07:08:06 +08:00
										 |  |  | 						dependencyType | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 							? cachedSetProperty( | 
					
						
							|  |  |  | 									resolveOptions || EMPTY_RESOLVE_OPTIONS, | 
					
						
							|  |  |  | 									"dependencyType", | 
					
						
							| 
									
										
										
										
											2020-08-06 07:08:06 +08:00
										 |  |  | 									dependencyType | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 							  ) | 
					
						
							|  |  |  | 							: resolveOptions | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2020-09-15 21:10:25 +08:00
										 |  |  | 					this.resolveResource( | 
					
						
							| 
									
										
										
										
											2020-05-17 21:28:15 +08:00
										 |  |  | 						contextInfo, | 
					
						
							|  |  |  | 						context, | 
					
						
							|  |  |  | 						unresolvedResource, | 
					
						
							| 
									
										
										
										
											2020-09-15 21:10:25 +08:00
										 |  |  | 						normalResolver, | 
					
						
							| 
									
										
										
										
											2020-05-17 21:28:15 +08:00
										 |  |  | 						resolveContext, | 
					
						
							|  |  |  | 						(err, resolvedResource, resolvedResourceResolveData) => { | 
					
						
							|  |  |  | 							if (err) return continueCallback(err); | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 							if (resolvedResource !== false) { | 
					
						
							|  |  |  | 								resourceData = { | 
					
						
							|  |  |  | 									resource: resolvedResource, | 
					
						
							|  |  |  | 									data: resolvedResourceResolveData, | 
					
						
							| 
									
										
										
										
											2020-07-06 23:39:52 +08:00
										 |  |  | 									...cacheParseResource(resolvedResource) | 
					
						
							| 
									
										
										
										
											2020-07-03 20:45:49 +08:00
										 |  |  | 								}; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2020-05-17 21:28:15 +08:00
										 |  |  | 							continueCallback(); | 
					
						
							| 
									
										
										
										
											2020-04-16 20:05:40 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-05-17 21:28:15 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ModuleFactoryCreateData} data data object | 
					
						
							|  |  |  | 	 * @param {function(Error=, ModuleFactoryResult=): void} callback callback | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 	create(data, callback) { | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		const dependencies = /** @type {ModuleDependency[]} */ (data.dependencies); | 
					
						
							| 
									
										
										
										
											2018-10-31 17:11:08 +08:00
										 |  |  | 		if (this.unsafeCache) { | 
					
						
							|  |  |  | 			const cacheEntry = dependencyCache.get(dependencies[0]); | 
					
						
							|  |  |  | 			if (cacheEntry) return callback(null, cacheEntry); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-04-04 16:26:16 +08:00
										 |  |  | 		const context = data.context || this.context; | 
					
						
							| 
									
										
										
										
											2020-06-17 02:01:06 +08:00
										 |  |  | 		const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS; | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		const dependency = dependencies[0]; | 
					
						
							|  |  |  | 		const request = dependency.request; | 
					
						
							|  |  |  | 		const contextInfo = data.contextInfo; | 
					
						
							| 
									
										
										
										
											2019-08-07 15:54:43 +08:00
										 |  |  | 		const fileDependencies = new LazySet(); | 
					
						
							|  |  |  | 		const missingDependencies = new LazySet(); | 
					
						
							|  |  |  | 		const contextDependencies = new LazySet(); | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		/** @type {ResolveData} */ | 
					
						
							|  |  |  | 		const resolveData = { | 
					
						
							|  |  |  | 			contextInfo, | 
					
						
							|  |  |  | 			resolveOptions, | 
					
						
							|  |  |  | 			context, | 
					
						
							|  |  |  | 			request, | 
					
						
							|  |  |  | 			dependencies, | 
					
						
							|  |  |  | 			fileDependencies, | 
					
						
							|  |  |  | 			missingDependencies, | 
					
						
							|  |  |  | 			contextDependencies, | 
					
						
							| 
									
										
										
										
											2020-06-24 20:09:10 +08:00
										 |  |  | 			createData: {}, | 
					
						
							|  |  |  | 			cacheable: true | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		this.hooks.beforeResolve.callAsync(resolveData, (err, result) => { | 
					
						
							| 
									
										
										
										
											2019-07-05 06:41:30 +08:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err, { | 
					
						
							|  |  |  | 					fileDependencies, | 
					
						
							|  |  |  | 					missingDependencies, | 
					
						
							|  |  |  | 					contextDependencies | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			// Ignored
 | 
					
						
							| 
									
										
										
										
											2019-07-05 06:41:30 +08:00
										 |  |  | 			if (result === false) { | 
					
						
							|  |  |  | 				return callback(null, { | 
					
						
							|  |  |  | 					fileDependencies, | 
					
						
							|  |  |  | 					missingDependencies, | 
					
						
							|  |  |  | 					contextDependencies | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			if (typeof result === "object") | 
					
						
							|  |  |  | 				throw new Error(deprecationChangedHookMessage("beforeResolve")); | 
					
						
							| 
									
										
										
										
											2013-11-06 01:19:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 			this.hooks.factorize.callAsync(resolveData, (err, module) => { | 
					
						
							| 
									
										
										
										
											2019-07-05 06:41:30 +08:00
										 |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return callback(err, { | 
					
						
							|  |  |  | 						fileDependencies, | 
					
						
							|  |  |  | 						missingDependencies, | 
					
						
							|  |  |  | 						contextDependencies | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-12-08 16:39:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				const factoryResult = { | 
					
						
							|  |  |  | 					module, | 
					
						
							|  |  |  | 					fileDependencies, | 
					
						
							|  |  |  | 					missingDependencies, | 
					
						
							|  |  |  | 					contextDependencies | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 20:09:10 +08:00
										 |  |  | 				if ( | 
					
						
							|  |  |  | 					this.unsafeCache && | 
					
						
							|  |  |  | 					resolveData.cacheable && | 
					
						
							|  |  |  | 					module && | 
					
						
							|  |  |  | 					this.cachePredicate(module) | 
					
						
							|  |  |  | 				) { | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					for (const d of dependencies) { | 
					
						
							|  |  |  | 						dependencyCache.set(d, factoryResult); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 				callback(null, factoryResult); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 21:10:25 +08:00
										 |  |  | 	resolveResource( | 
					
						
							|  |  |  | 		contextInfo, | 
					
						
							|  |  |  | 		context, | 
					
						
							|  |  |  | 		unresolvedResource, | 
					
						
							|  |  |  | 		resolver, | 
					
						
							|  |  |  | 		resolveContext, | 
					
						
							|  |  |  | 		callback | 
					
						
							|  |  |  | 	) { | 
					
						
							|  |  |  | 		resolver.resolve( | 
					
						
							|  |  |  | 			contextInfo, | 
					
						
							|  |  |  | 			context, | 
					
						
							|  |  |  | 			unresolvedResource, | 
					
						
							|  |  |  | 			resolveContext, | 
					
						
							|  |  |  | 			(err, resolvedResource, resolvedResourceResolveData) => { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					if (resolver.options.fullySpecified) { | 
					
						
							|  |  |  | 						resolver | 
					
						
							|  |  |  | 							.withOptions({ | 
					
						
							|  |  |  | 								fullySpecified: false | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 							.resolve( | 
					
						
							|  |  |  | 								contextInfo, | 
					
						
							|  |  |  | 								context, | 
					
						
							|  |  |  | 								unresolvedResource, | 
					
						
							|  |  |  | 								resolveContext, | 
					
						
							|  |  |  | 								(err2, resolvedResource) => { | 
					
						
							|  |  |  | 									if (!err2 && resolvedResource) { | 
					
						
							|  |  |  | 										const resource = parseResource( | 
					
						
							|  |  |  | 											resolvedResource | 
					
						
							|  |  |  | 										).path.replace(/^.*[\\/]/, ""); | 
					
						
							|  |  |  | 										err.message += `
 | 
					
						
							|  |  |  | Did you mean '${resource}'? | 
					
						
							|  |  |  | BREAKING CHANGE: The request '${unresolvedResource}' failed to resolve only because it was resolved as fully specified | 
					
						
							|  |  |  | (probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"'). | 
					
						
							|  |  |  | The extension in the request is mandatory for it to be fully specified. | 
					
						
							|  |  |  | Add the extension to the request.`;
 | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									callback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				callback(err, resolvedResource, resolvedResourceResolveData); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 	resolveRequestArray( | 
					
						
							|  |  |  | 		contextInfo, | 
					
						
							|  |  |  | 		context, | 
					
						
							|  |  |  | 		array, | 
					
						
							|  |  |  | 		resolver, | 
					
						
							|  |  |  | 		resolveContext, | 
					
						
							|  |  |  | 		callback | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 		if (array.length === 0) return callback(null, array); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		asyncLib.map( | 
					
						
							|  |  |  | 			array, | 
					
						
							|  |  |  | 			(item, callback) => { | 
					
						
							|  |  |  | 				resolver.resolve( | 
					
						
							|  |  |  | 					contextInfo, | 
					
						
							|  |  |  | 					context, | 
					
						
							|  |  |  | 					item.loader, | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 					resolveContext, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					(err, result) => { | 
					
						
							|  |  |  | 						if ( | 
					
						
							|  |  |  | 							err && | 
					
						
							|  |  |  | 							/^[^/]*$/.test(item.loader) && | 
					
						
							|  |  |  | 							!/-loader$/.test(item.loader) | 
					
						
							|  |  |  | 						) { | 
					
						
							|  |  |  | 							return resolver.resolve( | 
					
						
							|  |  |  | 								contextInfo, | 
					
						
							|  |  |  | 								context, | 
					
						
							|  |  |  | 								item.loader + "-loader", | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 								resolveContext, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								err2 => { | 
					
						
							|  |  |  | 									if (!err2) { | 
					
						
							|  |  |  | 										err.message = | 
					
						
							|  |  |  | 											err.message + | 
					
						
							|  |  |  | 											"\n" + | 
					
						
							|  |  |  | 											"BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" + | 
					
						
							| 
									
										
										
										
											2019-06-09 17:23:42 +08:00
										 |  |  | 											`                 You need to specify '${item.loader}-loader' instead of '${item.loader}',\n` + | 
					
						
							| 
									
										
										
										
											2018-05-24 22:05:56 +08:00
										 |  |  | 											"                 see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed"; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 									callback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 18:19:30 +08:00
										 |  |  | 						const parsedResult = identToLoaderRequest(result); | 
					
						
							|  |  |  | 						const resolved = { | 
					
						
							|  |  |  | 							loader: parsedResult.loader, | 
					
						
							|  |  |  | 							options: | 
					
						
							|  |  |  | 								item.options === undefined | 
					
						
							|  |  |  | 									? parsedResult.options | 
					
						
							|  |  |  | 									: item.options, | 
					
						
							|  |  |  | 							ident: item.options === undefined ? undefined : item.ident | 
					
						
							|  |  |  | 						}; | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:37 +08:00
										 |  |  | 						return callback(null, resolved); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			callback | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 02:01:06 +08:00
										 |  |  | 	getParser(type, parserOptions = EMPTY_RESOLVE_OPTIONS) { | 
					
						
							| 
									
										
										
										
											2019-11-19 01:01:54 +08:00
										 |  |  | 		let cache = this.parserCache.get(type); | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 01:01:54 +08:00
										 |  |  | 		if (cache === undefined) { | 
					
						
							|  |  |  | 			cache = new WeakMap(); | 
					
						
							|  |  |  | 			this.parserCache.set(type, cache); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 19:17:46 +08:00
										 |  |  | 		let parser = cache.get(parserOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (parser === undefined) { | 
					
						
							|  |  |  | 			parser = this.createParser(type, parserOptions); | 
					
						
							|  |  |  | 			cache.set(parserOptions, parser); | 
					
						
							| 
									
										
										
										
											2018-01-22 05:35:30 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 19:17:46 +08:00
										 |  |  | 		return parser; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} type type | 
					
						
							|  |  |  | 	 * @param {{[k: string]: any}} parserOptions parser options | 
					
						
							|  |  |  | 	 * @returns {Parser} parser | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 05:35:30 +08:00
										 |  |  | 	createParser(type, parserOptions = {}) { | 
					
						
							| 
									
										
										
										
											2017-11-28 16:54:24 +08:00
										 |  |  | 		const parser = this.hooks.createParser.for(type).call(parserOptions); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!parser) { | 
					
						
							| 
									
										
										
										
											2017-11-10 18:02:24 +08:00
										 |  |  | 			throw new Error(`No parser registered for ${type}`); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-28 16:54:24 +08:00
										 |  |  | 		this.hooks.parser.for(type).call(parser, parserOptions); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 		return parser; | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 02:01:06 +08:00
										 |  |  | 	getGenerator(type, generatorOptions = EMPTY_RESOLVE_OPTIONS) { | 
					
						
							| 
									
										
										
										
											2019-11-19 01:01:54 +08:00
										 |  |  | 		let cache = this.generatorCache.get(type); | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 01:01:54 +08:00
										 |  |  | 		if (cache === undefined) { | 
					
						
							|  |  |  | 			cache = new WeakMap(); | 
					
						
							|  |  |  | 			this.generatorCache.set(type, cache); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 19:17:46 +08:00
										 |  |  | 		let generator = cache.get(generatorOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (generator === undefined) { | 
					
						
							|  |  |  | 			generator = this.createGenerator(type, generatorOptions); | 
					
						
							|  |  |  | 			cache.set(generatorOptions, generator); | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-18 23:01:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 19:17:46 +08:00
										 |  |  | 		return generator; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	createGenerator(type, generatorOptions = {}) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const generator = this.hooks.createGenerator | 
					
						
							|  |  |  | 			.for(type) | 
					
						
							|  |  |  | 			.call(generatorOptions); | 
					
						
							|  |  |  | 		if (!generator) { | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 			throw new Error(`No generator registered for ${type}`); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.hooks.generator.for(type).call(generator, generatorOptions); | 
					
						
							|  |  |  | 		return generator; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 06:32:24 +08:00
										 |  |  | 	getResolver(type, resolveOptions) { | 
					
						
							| 
									
										
										
										
											2020-06-17 02:01:06 +08:00
										 |  |  | 		return this.resolverFactory.get(type, resolveOptions); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-04 05:28:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = NormalModuleFactory; |