ContextModule.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const { OriginalSource, RawSource } = require("webpack-sources");
  7. const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
  8. const { makeWebpackError } = require("./HookWebpackError");
  9. const Module = require("./Module");
  10. const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
  11. const RuntimeGlobals = require("./RuntimeGlobals");
  12. const Template = require("./Template");
  13. const WebpackError = require("./WebpackError");
  14. const {
  15. compareLocations,
  16. concatComparators,
  17. compareSelect,
  18. keepOriginalOrder,
  19. compareModulesById
  20. } = require("./util/comparators");
  21. const {
  22. contextify,
  23. parseResource,
  24. makePathsRelative
  25. } = require("./util/identifier");
  26. const makeSerializable = require("./util/makeSerializable");
  27. /** @typedef {import("webpack-sources").Source} Source */
  28. /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
  29. /** @typedef {import("./Chunk")} Chunk */
  30. /** @typedef {import("./ChunkGraph")} ChunkGraph */
  31. /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
  32. /** @typedef {import("./ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
  33. /** @typedef {import("./Compilation")} Compilation */
  34. /** @typedef {import("./Dependency")} Dependency */
  35. /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
  36. /** @typedef {import("./Module").BuildInfo} BuildInfo */
  37. /** @typedef {import("./Module").BuildMeta} BuildMeta */
  38. /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
  39. /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
  40. /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
  41. /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
  42. /** @typedef {import("./Module").SourceTypes} SourceTypes */
  43. /** @typedef {import("./ModuleGraph")} ModuleGraph */
  44. /** @typedef {import("./RequestShortener")} RequestShortener */
  45. /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
  46. /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
  47. /** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
  48. /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
  49. /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  50. /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  51. /** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
  52. /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
  53. /** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
  54. /**
  55. * @typedef {object} ContextOptions
  56. * @property {ContextMode} mode
  57. * @property {boolean} recursive
  58. * @property {RegExp} regExp
  59. * @property {"strict"|boolean=} namespaceObject
  60. * @property {string=} addon
  61. * @property {string=} chunkName
  62. * @property {RegExp=} include
  63. * @property {RegExp=} exclude
  64. * @property {RawChunkGroupOptions=} groupOptions
  65. * @property {string=} typePrefix
  66. * @property {string=} category
  67. * @property {(string[][] | null)=} referencedExports exports referenced from modules (won't be mangled)
  68. * @property {string=} layer
  69. * @property {ImportAttributes=} attributes
  70. */
  71. /**
  72. * @typedef {object} ContextModuleOptionsExtras
  73. * @property {false|string|string[]} resource
  74. * @property {string=} resourceQuery
  75. * @property {string=} resourceFragment
  76. * @property {TODO} resolveOptions
  77. */
  78. /** @typedef {ContextOptions & ContextModuleOptionsExtras} ContextModuleOptions */
  79. /**
  80. * @callback ResolveDependenciesCallback
  81. * @param {(Error | null)=} err
  82. * @param {ContextElementDependency[]=} dependencies
  83. */
  84. /**
  85. * @callback ResolveDependencies
  86. * @param {InputFileSystem} fs
  87. * @param {ContextModuleOptions} options
  88. * @param {ResolveDependenciesCallback} callback
  89. */
  90. /** @typedef {1 | 3 | 7 | 9} FakeMapType */
  91. /** @typedef {Map<string, string | number> | FakeMapType} FakeMap */
  92. const SNAPSHOT_OPTIONS = { timestamp: true };
  93. const TYPES = new Set(["javascript"]);
  94. class ContextModule extends Module {
  95. /**
  96. * @param {ResolveDependencies} resolveDependencies function to get dependencies in this context
  97. * @param {ContextModuleOptions} options options object
  98. */
  99. constructor(resolveDependencies, options) {
  100. if (!options || typeof options.resource === "string") {
  101. const parsed = parseResource(
  102. options ? /** @type {string} */ (options.resource) : ""
  103. );
  104. const resource = parsed.path;
  105. const resourceQuery = (options && options.resourceQuery) || parsed.query;
  106. const resourceFragment =
  107. (options && options.resourceFragment) || parsed.fragment;
  108. const layer = options && options.layer;
  109. super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource, layer);
  110. /** @type {ContextModuleOptions} */
  111. this.options = {
  112. ...options,
  113. resource,
  114. resourceQuery,
  115. resourceFragment
  116. };
  117. } else {
  118. super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, undefined, options.layer);
  119. /** @type {ContextModuleOptions} */
  120. this.options = {
  121. ...options,
  122. resource: options.resource,
  123. resourceQuery: options.resourceQuery || "",
  124. resourceFragment: options.resourceFragment || ""
  125. };
  126. }
  127. // Info from Factory
  128. /** @type {ResolveDependencies | undefined} */
  129. this.resolveDependencies = resolveDependencies;
  130. if (options && options.resolveOptions !== undefined) {
  131. this.resolveOptions = options.resolveOptions;
  132. }
  133. if (options && typeof options.mode !== "string") {
  134. throw new Error("options.mode is a required option");
  135. }
  136. this._identifier = this._createIdentifier();
  137. this._forceBuild = true;
  138. }
  139. /**
  140. * @returns {SourceTypes} types available (do not mutate)
  141. */
  142. getSourceTypes() {
  143. return TYPES;
  144. }
  145. /**
  146. * Assuming this module is in the cache. Update the (cached) module with
  147. * the fresh module from the factory. Usually updates internal references
  148. * and properties.
  149. * @param {Module} module fresh module
  150. * @returns {void}
  151. */
  152. updateCacheModule(module) {
  153. const m = /** @type {ContextModule} */ (module);
  154. this.resolveDependencies = m.resolveDependencies;
  155. this.options = m.options;
  156. }
  157. /**
  158. * Assuming this module is in the cache. Remove internal references to allow freeing some memory.
  159. */
  160. cleanupForCache() {
  161. super.cleanupForCache();
  162. this.resolveDependencies = undefined;
  163. }
  164. /**
  165. * @private
  166. * @param {RegExp} regexString RegExp as a string
  167. * @param {boolean=} stripSlash do we need to strip a slsh
  168. * @returns {string} pretty RegExp
  169. */
  170. _prettyRegExp(regexString, stripSlash = true) {
  171. const str = stripSlash
  172. ? regexString.source + regexString.flags
  173. : regexString + "";
  174. return str.replace(/!/g, "%21").replace(/\|/g, "%7C");
  175. }
  176. _createIdentifier() {
  177. let identifier =
  178. this.context ||
  179. (typeof this.options.resource === "string" ||
  180. this.options.resource === false
  181. ? `${this.options.resource}`
  182. : this.options.resource.join("|"));
  183. if (this.options.resourceQuery) {
  184. identifier += `|${this.options.resourceQuery}`;
  185. }
  186. if (this.options.resourceFragment) {
  187. identifier += `|${this.options.resourceFragment}`;
  188. }
  189. if (this.options.mode) {
  190. identifier += `|${this.options.mode}`;
  191. }
  192. if (!this.options.recursive) {
  193. identifier += "|nonrecursive";
  194. }
  195. if (this.options.addon) {
  196. identifier += `|${this.options.addon}`;
  197. }
  198. if (this.options.regExp) {
  199. identifier += `|${this._prettyRegExp(this.options.regExp, false)}`;
  200. }
  201. if (this.options.include) {
  202. identifier += `|include: ${this._prettyRegExp(
  203. this.options.include,
  204. false
  205. )}`;
  206. }
  207. if (this.options.exclude) {
  208. identifier += `|exclude: ${this._prettyRegExp(
  209. this.options.exclude,
  210. false
  211. )}`;
  212. }
  213. if (this.options.referencedExports) {
  214. identifier += `|referencedExports: ${JSON.stringify(
  215. this.options.referencedExports
  216. )}`;
  217. }
  218. if (this.options.chunkName) {
  219. identifier += `|chunkName: ${this.options.chunkName}`;
  220. }
  221. if (this.options.groupOptions) {
  222. identifier += `|groupOptions: ${JSON.stringify(
  223. this.options.groupOptions
  224. )}`;
  225. }
  226. if (this.options.namespaceObject === "strict") {
  227. identifier += "|strict namespace object";
  228. } else if (this.options.namespaceObject) {
  229. identifier += "|namespace object";
  230. }
  231. if (this.layer) {
  232. identifier += `|layer: ${this.layer}`;
  233. }
  234. return identifier;
  235. }
  236. /**
  237. * @returns {string} a unique identifier of the module
  238. */
  239. identifier() {
  240. return this._identifier;
  241. }
  242. /**
  243. * @param {RequestShortener} requestShortener the request shortener
  244. * @returns {string} a user readable identifier of the module
  245. */
  246. readableIdentifier(requestShortener) {
  247. let identifier;
  248. if (this.context) {
  249. identifier = requestShortener.shorten(this.context) + "/";
  250. } else if (
  251. typeof this.options.resource === "string" ||
  252. this.options.resource === false
  253. ) {
  254. identifier = requestShortener.shorten(`${this.options.resource}`) + "/";
  255. } else {
  256. identifier = this.options.resource
  257. .map(r => requestShortener.shorten(r) + "/")
  258. .join(" ");
  259. }
  260. if (this.options.resourceQuery) {
  261. identifier += ` ${this.options.resourceQuery}`;
  262. }
  263. if (this.options.mode) {
  264. identifier += ` ${this.options.mode}`;
  265. }
  266. if (!this.options.recursive) {
  267. identifier += " nonrecursive";
  268. }
  269. if (this.options.addon) {
  270. identifier += ` ${requestShortener.shorten(this.options.addon)}`;
  271. }
  272. if (this.options.regExp) {
  273. identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
  274. }
  275. if (this.options.include) {
  276. identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
  277. }
  278. if (this.options.exclude) {
  279. identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
  280. }
  281. if (this.options.referencedExports) {
  282. identifier += ` referencedExports: ${this.options.referencedExports
  283. .map(e => e.join("."))
  284. .join(", ")}`;
  285. }
  286. if (this.options.chunkName) {
  287. identifier += ` chunkName: ${this.options.chunkName}`;
  288. }
  289. if (this.options.groupOptions) {
  290. const groupOptions = this.options.groupOptions;
  291. for (const key of Object.keys(groupOptions)) {
  292. identifier += ` ${key}: ${
  293. groupOptions[/** @type {keyof RawChunkGroupOptions} */ (key)]
  294. }`;
  295. }
  296. }
  297. if (this.options.namespaceObject === "strict") {
  298. identifier += " strict namespace object";
  299. } else if (this.options.namespaceObject) {
  300. identifier += " namespace object";
  301. }
  302. return identifier;
  303. }
  304. /**
  305. * @param {LibIdentOptions} options options
  306. * @returns {string | null} an identifier for library inclusion
  307. */
  308. libIdent(options) {
  309. let identifier;
  310. if (this.context) {
  311. identifier = contextify(
  312. options.context,
  313. this.context,
  314. options.associatedObjectForCache
  315. );
  316. } else if (typeof this.options.resource === "string") {
  317. identifier = contextify(
  318. options.context,
  319. this.options.resource,
  320. options.associatedObjectForCache
  321. );
  322. } else if (this.options.resource === false) {
  323. identifier = "false";
  324. } else {
  325. identifier = this.options.resource
  326. .map(res =>
  327. contextify(options.context, res, options.associatedObjectForCache)
  328. )
  329. .join(" ");
  330. }
  331. if (this.layer) identifier = `(${this.layer})/${identifier}`;
  332. if (this.options.mode) {
  333. identifier += ` ${this.options.mode}`;
  334. }
  335. if (this.options.recursive) {
  336. identifier += " recursive";
  337. }
  338. if (this.options.addon) {
  339. identifier += ` ${contextify(
  340. options.context,
  341. this.options.addon,
  342. options.associatedObjectForCache
  343. )}`;
  344. }
  345. if (this.options.regExp) {
  346. identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
  347. }
  348. if (this.options.include) {
  349. identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
  350. }
  351. if (this.options.exclude) {
  352. identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
  353. }
  354. if (this.options.referencedExports) {
  355. identifier += ` referencedExports: ${this.options.referencedExports
  356. .map(e => e.join("."))
  357. .join(", ")}`;
  358. }
  359. return identifier;
  360. }
  361. /**
  362. * @returns {void}
  363. */
  364. invalidateBuild() {
  365. this._forceBuild = true;
  366. }
  367. /**
  368. * @param {NeedBuildContext} context context info
  369. * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
  370. * @returns {void}
  371. */
  372. needBuild({ fileSystemInfo }, callback) {
  373. // build if enforced
  374. if (this._forceBuild) return callback(null, true);
  375. const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
  376. // always build when we have no snapshot and context
  377. if (!buildInfo.snapshot)
  378. return callback(null, Boolean(this.context || this.options.resource));
  379. fileSystemInfo.checkSnapshotValid(buildInfo.snapshot, (err, valid) => {
  380. callback(err, !valid);
  381. });
  382. }
  383. /**
  384. * @param {WebpackOptions} options webpack options
  385. * @param {Compilation} compilation the compilation
  386. * @param {ResolverWithOptions} resolver the resolver
  387. * @param {InputFileSystem} fs the file system
  388. * @param {function(WebpackError=): void} callback callback function
  389. * @returns {void}
  390. */
  391. build(options, compilation, resolver, fs, callback) {
  392. this._forceBuild = false;
  393. /** @type {BuildMeta} */
  394. this.buildMeta = {
  395. exportsType: "default",
  396. defaultObject: "redirect-warn"
  397. };
  398. this.buildInfo = {
  399. snapshot: undefined
  400. };
  401. this.dependencies.length = 0;
  402. this.blocks.length = 0;
  403. const startTime = Date.now();
  404. /** @type {ResolveDependencies} */
  405. (this.resolveDependencies)(fs, this.options, (err, dependencies) => {
  406. if (err) {
  407. return callback(
  408. makeWebpackError(err, "ContextModule.resolveDependencies")
  409. );
  410. }
  411. // abort if something failed
  412. // this will create an empty context
  413. if (!dependencies) {
  414. callback();
  415. return;
  416. }
  417. // enhance dependencies with meta info
  418. for (const dep of dependencies) {
  419. dep.loc = {
  420. name: dep.userRequest
  421. };
  422. dep.request = this.options.addon + dep.request;
  423. }
  424. dependencies.sort(
  425. concatComparators(
  426. compareSelect(a => a.loc, compareLocations),
  427. keepOriginalOrder(this.dependencies)
  428. )
  429. );
  430. if (this.options.mode === "sync" || this.options.mode === "eager") {
  431. // if we have an sync or eager context
  432. // just add all dependencies and continue
  433. this.dependencies = dependencies;
  434. } else if (this.options.mode === "lazy-once") {
  435. // for the lazy-once mode create a new async dependency block
  436. // and add that block to this context
  437. if (dependencies.length > 0) {
  438. const block = new AsyncDependenciesBlock({
  439. ...this.options.groupOptions,
  440. name: this.options.chunkName
  441. });
  442. for (const dep of dependencies) {
  443. block.addDependency(dep);
  444. }
  445. this.addBlock(block);
  446. }
  447. } else if (
  448. this.options.mode === "weak" ||
  449. this.options.mode === "async-weak"
  450. ) {
  451. // we mark all dependencies as weak
  452. for (const dep of dependencies) {
  453. dep.weak = true;
  454. }
  455. this.dependencies = dependencies;
  456. } else if (this.options.mode === "lazy") {
  457. // if we are lazy create a new async dependency block per dependency
  458. // and add all blocks to this context
  459. let index = 0;
  460. for (const dep of dependencies) {
  461. let chunkName = this.options.chunkName;
  462. if (chunkName) {
  463. if (!/\[(index|request)\]/.test(chunkName)) {
  464. chunkName += "[index]";
  465. }
  466. chunkName = chunkName.replace(/\[index\]/g, `${index++}`);
  467. chunkName = chunkName.replace(
  468. /\[request\]/g,
  469. Template.toPath(dep.userRequest)
  470. );
  471. }
  472. const block = new AsyncDependenciesBlock(
  473. {
  474. ...this.options.groupOptions,
  475. name: chunkName
  476. },
  477. dep.loc,
  478. dep.userRequest
  479. );
  480. block.addDependency(dep);
  481. this.addBlock(block);
  482. }
  483. } else {
  484. callback(
  485. new WebpackError(`Unsupported mode "${this.options.mode}" in context`)
  486. );
  487. return;
  488. }
  489. if (!this.context && !this.options.resource) return callback();
  490. compilation.fileSystemInfo.createSnapshot(
  491. startTime,
  492. null,
  493. this.context
  494. ? [this.context]
  495. : typeof this.options.resource === "string"
  496. ? [this.options.resource]
  497. : /** @type {string[]} */ (this.options.resource),
  498. null,
  499. SNAPSHOT_OPTIONS,
  500. (err, snapshot) => {
  501. if (err) return callback(err);
  502. /** @type {BuildInfo} */
  503. (this.buildInfo).snapshot = snapshot;
  504. callback();
  505. }
  506. );
  507. });
  508. }
  509. /**
  510. * @param {LazySet<string>} fileDependencies set where file dependencies are added to
  511. * @param {LazySet<string>} contextDependencies set where context dependencies are added to
  512. * @param {LazySet<string>} missingDependencies set where missing dependencies are added to
  513. * @param {LazySet<string>} buildDependencies set where build dependencies are added to
  514. */
  515. addCacheDependencies(
  516. fileDependencies,
  517. contextDependencies,
  518. missingDependencies,
  519. buildDependencies
  520. ) {
  521. if (this.context) {
  522. contextDependencies.add(this.context);
  523. } else if (typeof this.options.resource === "string") {
  524. contextDependencies.add(this.options.resource);
  525. } else if (this.options.resource === false) {
  526. return;
  527. } else {
  528. for (const res of this.options.resource) contextDependencies.add(res);
  529. }
  530. }
  531. /**
  532. * @param {Dependency[]} dependencies all dependencies
  533. * @param {ChunkGraph} chunkGraph chunk graph
  534. * @returns {Map<string, string | number>} map with user requests
  535. */
  536. getUserRequestMap(dependencies, chunkGraph) {
  537. const moduleGraph = chunkGraph.moduleGraph;
  538. // if we filter first we get a new array
  539. // therefore we don't need to create a clone of dependencies explicitly
  540. // therefore the order of this is !important!
  541. const sortedDependencies =
  542. /** @type {ContextElementDependency[]} */
  543. (dependencies)
  544. .filter(dependency => moduleGraph.getModule(dependency))
  545. .sort((a, b) => {
  546. if (a.userRequest === b.userRequest) {
  547. return 0;
  548. }
  549. return a.userRequest < b.userRequest ? -1 : 1;
  550. });
  551. const map = Object.create(null);
  552. for (const dep of sortedDependencies) {
  553. const module = /** @type {Module} */ (moduleGraph.getModule(dep));
  554. map[dep.userRequest] = chunkGraph.getModuleId(module);
  555. }
  556. return map;
  557. }
  558. /**
  559. * @param {Dependency[]} dependencies all dependencies
  560. * @param {ChunkGraph} chunkGraph chunk graph
  561. * @returns {FakeMap} fake map
  562. */
  563. getFakeMap(dependencies, chunkGraph) {
  564. if (!this.options.namespaceObject) {
  565. return 9;
  566. }
  567. const moduleGraph = chunkGraph.moduleGraph;
  568. // bitfield
  569. let hasType = 0;
  570. const comparator = compareModulesById(chunkGraph);
  571. // if we filter first we get a new array
  572. // therefore we don't need to create a clone of dependencies explicitly
  573. // therefore the order of this is !important!
  574. const sortedModules = dependencies
  575. .map(
  576. dependency => /** @type {Module} */ (moduleGraph.getModule(dependency))
  577. )
  578. .filter(Boolean)
  579. .sort(comparator);
  580. const fakeMap = Object.create(null);
  581. for (const module of sortedModules) {
  582. const exportsType = module.getExportsType(
  583. moduleGraph,
  584. this.options.namespaceObject === "strict"
  585. );
  586. const id = chunkGraph.getModuleId(module);
  587. switch (exportsType) {
  588. case "namespace":
  589. fakeMap[id] = 9;
  590. hasType |= 1;
  591. break;
  592. case "dynamic":
  593. fakeMap[id] = 7;
  594. hasType |= 2;
  595. break;
  596. case "default-only":
  597. fakeMap[id] = 1;
  598. hasType |= 4;
  599. break;
  600. case "default-with-named":
  601. fakeMap[id] = 3;
  602. hasType |= 8;
  603. break;
  604. default:
  605. throw new Error(`Unexpected exports type ${exportsType}`);
  606. }
  607. }
  608. if (hasType === 1) {
  609. return 9;
  610. }
  611. if (hasType === 2) {
  612. return 7;
  613. }
  614. if (hasType === 4) {
  615. return 1;
  616. }
  617. if (hasType === 8) {
  618. return 3;
  619. }
  620. if (hasType === 0) {
  621. return 9;
  622. }
  623. return fakeMap;
  624. }
  625. /**
  626. * @param {FakeMap} fakeMap fake map
  627. * @returns {string} fake map init statement
  628. */
  629. getFakeMapInitStatement(fakeMap) {
  630. return typeof fakeMap === "object"
  631. ? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
  632. : "";
  633. }
  634. /**
  635. * @param {FakeMapType} type type
  636. * @param {boolean=} asyncModule is async module
  637. * @returns {string} return result
  638. */
  639. getReturn(type, asyncModule) {
  640. if (type === 9) {
  641. return `${RuntimeGlobals.require}(id)`;
  642. }
  643. return `${RuntimeGlobals.createFakeNamespaceObject}(id, ${type}${
  644. asyncModule ? " | 16" : ""
  645. })`;
  646. }
  647. /**
  648. * @param {FakeMap} fakeMap fake map
  649. * @param {boolean=} asyncModule us async module
  650. * @param {string=} fakeMapDataExpression fake map data expression
  651. * @returns {string} module object source
  652. */
  653. getReturnModuleObjectSource(
  654. fakeMap,
  655. asyncModule,
  656. fakeMapDataExpression = "fakeMap[id]"
  657. ) {
  658. if (typeof fakeMap === "number") {
  659. return `return ${this.getReturn(fakeMap, asyncModule)};`;
  660. }
  661. return `return ${
  662. RuntimeGlobals.createFakeNamespaceObject
  663. }(id, ${fakeMapDataExpression}${asyncModule ? " | 16" : ""})`;
  664. }
  665. /**
  666. * @param {Dependency[]} dependencies dependencies
  667. * @param {ModuleId} id module id
  668. * @param {ChunkGraph} chunkGraph the chunk graph
  669. * @returns {string} source code
  670. */
  671. getSyncSource(dependencies, id, chunkGraph) {
  672. const map = this.getUserRequestMap(dependencies, chunkGraph);
  673. const fakeMap = this.getFakeMap(dependencies, chunkGraph);
  674. const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
  675. return `var map = ${JSON.stringify(map, null, "\t")};
  676. ${this.getFakeMapInitStatement(fakeMap)}
  677. function webpackContext(req) {
  678. var id = webpackContextResolve(req);
  679. ${returnModuleObject}
  680. }
  681. function webpackContextResolve(req) {
  682. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  683. var e = new Error("Cannot find module '" + req + "'");
  684. e.code = 'MODULE_NOT_FOUND';
  685. throw e;
  686. }
  687. return map[req];
  688. }
  689. webpackContext.keys = function webpackContextKeys() {
  690. return Object.keys(map);
  691. };
  692. webpackContext.resolve = webpackContextResolve;
  693. module.exports = webpackContext;
  694. webpackContext.id = ${JSON.stringify(id)};`;
  695. }
  696. /**
  697. * @param {Dependency[]} dependencies dependencies
  698. * @param {ModuleId} id module id
  699. * @param {ChunkGraph} chunkGraph the chunk graph
  700. * @returns {string} source code
  701. */
  702. getWeakSyncSource(dependencies, id, chunkGraph) {
  703. const map = this.getUserRequestMap(dependencies, chunkGraph);
  704. const fakeMap = this.getFakeMap(dependencies, chunkGraph);
  705. const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
  706. return `var map = ${JSON.stringify(map, null, "\t")};
  707. ${this.getFakeMapInitStatement(fakeMap)}
  708. function webpackContext(req) {
  709. var id = webpackContextResolve(req);
  710. if(!${RuntimeGlobals.moduleFactories}[id]) {
  711. var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
  712. e.code = 'MODULE_NOT_FOUND';
  713. throw e;
  714. }
  715. ${returnModuleObject}
  716. }
  717. function webpackContextResolve(req) {
  718. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  719. var e = new Error("Cannot find module '" + req + "'");
  720. e.code = 'MODULE_NOT_FOUND';
  721. throw e;
  722. }
  723. return map[req];
  724. }
  725. webpackContext.keys = function webpackContextKeys() {
  726. return Object.keys(map);
  727. };
  728. webpackContext.resolve = webpackContextResolve;
  729. webpackContext.id = ${JSON.stringify(id)};
  730. module.exports = webpackContext;`;
  731. }
  732. /**
  733. * @param {Dependency[]} dependencies dependencies
  734. * @param {ModuleId} id module id
  735. * @param {object} context context
  736. * @param {ChunkGraph} context.chunkGraph the chunk graph
  737. * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
  738. * @returns {string} source code
  739. */
  740. getAsyncWeakSource(dependencies, id, { chunkGraph, runtimeTemplate }) {
  741. const arrow = runtimeTemplate.supportsArrowFunction();
  742. const map = this.getUserRequestMap(dependencies, chunkGraph);
  743. const fakeMap = this.getFakeMap(dependencies, chunkGraph);
  744. const returnModuleObject = this.getReturnModuleObjectSource(fakeMap, true);
  745. return `var map = ${JSON.stringify(map, null, "\t")};
  746. ${this.getFakeMapInitStatement(fakeMap)}
  747. function webpackAsyncContext(req) {
  748. return webpackAsyncContextResolve(req).then(${
  749. arrow ? "id =>" : "function(id)"
  750. } {
  751. if(!${RuntimeGlobals.moduleFactories}[id]) {
  752. var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
  753. e.code = 'MODULE_NOT_FOUND';
  754. throw e;
  755. }
  756. ${returnModuleObject}
  757. });
  758. }
  759. function webpackAsyncContextResolve(req) {
  760. // Here Promise.resolve().then() is used instead of new Promise() to prevent
  761. // uncaught exception popping up in devtools
  762. return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
  763. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  764. var e = new Error("Cannot find module '" + req + "'");
  765. e.code = 'MODULE_NOT_FOUND';
  766. throw e;
  767. }
  768. return map[req];
  769. });
  770. }
  771. webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
  772. "Object.keys(map)"
  773. )};
  774. webpackAsyncContext.resolve = webpackAsyncContextResolve;
  775. webpackAsyncContext.id = ${JSON.stringify(id)};
  776. module.exports = webpackAsyncContext;`;
  777. }
  778. /**
  779. * @param {Dependency[]} dependencies dependencies
  780. * @param {ModuleId} id module id
  781. * @param {object} context context
  782. * @param {ChunkGraph} context.chunkGraph the chunk graph
  783. * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
  784. * @returns {string} source code
  785. */
  786. getEagerSource(dependencies, id, { chunkGraph, runtimeTemplate }) {
  787. const arrow = runtimeTemplate.supportsArrowFunction();
  788. const map = this.getUserRequestMap(dependencies, chunkGraph);
  789. const fakeMap = this.getFakeMap(dependencies, chunkGraph);
  790. const thenFunction =
  791. fakeMap !== 9
  792. ? `${arrow ? "id =>" : "function(id)"} {
  793. ${this.getReturnModuleObjectSource(fakeMap, true)}
  794. }`
  795. : RuntimeGlobals.require;
  796. return `var map = ${JSON.stringify(map, null, "\t")};
  797. ${this.getFakeMapInitStatement(fakeMap)}
  798. function webpackAsyncContext(req) {
  799. return webpackAsyncContextResolve(req).then(${thenFunction});
  800. }
  801. function webpackAsyncContextResolve(req) {
  802. // Here Promise.resolve().then() is used instead of new Promise() to prevent
  803. // uncaught exception popping up in devtools
  804. return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
  805. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  806. var e = new Error("Cannot find module '" + req + "'");
  807. e.code = 'MODULE_NOT_FOUND';
  808. throw e;
  809. }
  810. return map[req];
  811. });
  812. }
  813. webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
  814. "Object.keys(map)"
  815. )};
  816. webpackAsyncContext.resolve = webpackAsyncContextResolve;
  817. webpackAsyncContext.id = ${JSON.stringify(id)};
  818. module.exports = webpackAsyncContext;`;
  819. }
  820. /**
  821. * @param {AsyncDependenciesBlock} block block
  822. * @param {Dependency[]} dependencies dependencies
  823. * @param {ModuleId} id module id
  824. * @param {object} options options object
  825. * @param {RuntimeTemplate} options.runtimeTemplate the runtime template
  826. * @param {ChunkGraph} options.chunkGraph the chunk graph
  827. * @returns {string} source code
  828. */
  829. getLazyOnceSource(block, dependencies, id, { runtimeTemplate, chunkGraph }) {
  830. const promise = runtimeTemplate.blockPromise({
  831. chunkGraph,
  832. block,
  833. message: "lazy-once context",
  834. runtimeRequirements: new Set()
  835. });
  836. const arrow = runtimeTemplate.supportsArrowFunction();
  837. const map = this.getUserRequestMap(dependencies, chunkGraph);
  838. const fakeMap = this.getFakeMap(dependencies, chunkGraph);
  839. const thenFunction =
  840. fakeMap !== 9
  841. ? `${arrow ? "id =>" : "function(id)"} {
  842. ${this.getReturnModuleObjectSource(fakeMap, true)};
  843. }`
  844. : RuntimeGlobals.require;
  845. return `var map = ${JSON.stringify(map, null, "\t")};
  846. ${this.getFakeMapInitStatement(fakeMap)}
  847. function webpackAsyncContext(req) {
  848. return webpackAsyncContextResolve(req).then(${thenFunction});
  849. }
  850. function webpackAsyncContextResolve(req) {
  851. return ${promise}.then(${arrow ? "() =>" : "function()"} {
  852. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  853. var e = new Error("Cannot find module '" + req + "'");
  854. e.code = 'MODULE_NOT_FOUND';
  855. throw e;
  856. }
  857. return map[req];
  858. });
  859. }
  860. webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
  861. "Object.keys(map)"
  862. )};
  863. webpackAsyncContext.resolve = webpackAsyncContextResolve;
  864. webpackAsyncContext.id = ${JSON.stringify(id)};
  865. module.exports = webpackAsyncContext;`;
  866. }
  867. /**
  868. * @param {AsyncDependenciesBlock[]} blocks blocks
  869. * @param {ModuleId} id module id
  870. * @param {object} context context
  871. * @param {ChunkGraph} context.chunkGraph the chunk graph
  872. * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
  873. * @returns {string} source code
  874. */
  875. getLazySource(blocks, id, { chunkGraph, runtimeTemplate }) {
  876. const moduleGraph = chunkGraph.moduleGraph;
  877. const arrow = runtimeTemplate.supportsArrowFunction();
  878. let hasMultipleOrNoChunks = false;
  879. let hasNoChunk = true;
  880. const fakeMap = this.getFakeMap(
  881. blocks.map(b => b.dependencies[0]),
  882. chunkGraph
  883. );
  884. const hasFakeMap = typeof fakeMap === "object";
  885. const items = blocks
  886. .map(block => {
  887. const dependency =
  888. /** @type {ContextElementDependency} */
  889. (block.dependencies[0]);
  890. return {
  891. dependency: dependency,
  892. module: /** @type {Module} */ (moduleGraph.getModule(dependency)),
  893. block: block,
  894. userRequest: dependency.userRequest,
  895. chunks: undefined
  896. };
  897. })
  898. .filter(item => item.module);
  899. for (const item of items) {
  900. const chunkGroup = chunkGraph.getBlockChunkGroup(item.block);
  901. const chunks = (chunkGroup && chunkGroup.chunks) || [];
  902. item.chunks = chunks;
  903. if (chunks.length > 0) {
  904. hasNoChunk = false;
  905. }
  906. if (chunks.length !== 1) {
  907. hasMultipleOrNoChunks = true;
  908. }
  909. }
  910. const shortMode = hasNoChunk && !hasFakeMap;
  911. const sortedItems = items.sort((a, b) => {
  912. if (a.userRequest === b.userRequest) return 0;
  913. return a.userRequest < b.userRequest ? -1 : 1;
  914. });
  915. const map = Object.create(null);
  916. for (const item of sortedItems) {
  917. const moduleId = chunkGraph.getModuleId(item.module);
  918. if (shortMode) {
  919. map[item.userRequest] = moduleId;
  920. } else {
  921. const arrayStart = [moduleId];
  922. if (hasFakeMap) {
  923. arrayStart.push(fakeMap[moduleId]);
  924. }
  925. map[item.userRequest] = arrayStart.concat(
  926. item.chunks.map(chunk => chunk.id)
  927. );
  928. }
  929. }
  930. const chunksStartPosition = hasFakeMap ? 2 : 1;
  931. const requestPrefix = hasNoChunk
  932. ? "Promise.resolve()"
  933. : hasMultipleOrNoChunks
  934. ? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
  935. : `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
  936. const returnModuleObject = this.getReturnModuleObjectSource(
  937. fakeMap,
  938. true,
  939. shortMode ? "invalid" : "ids[1]"
  940. );
  941. const webpackAsyncContext =
  942. requestPrefix === "Promise.resolve()"
  943. ? `
  944. function webpackAsyncContext(req) {
  945. return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
  946. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  947. var e = new Error("Cannot find module '" + req + "'");
  948. e.code = 'MODULE_NOT_FOUND';
  949. throw e;
  950. }
  951. ${shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];"}
  952. ${returnModuleObject}
  953. });
  954. }`
  955. : `function webpackAsyncContext(req) {
  956. if(!${RuntimeGlobals.hasOwnProperty}(map, req)) {
  957. return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
  958. var e = new Error("Cannot find module '" + req + "'");
  959. e.code = 'MODULE_NOT_FOUND';
  960. throw e;
  961. });
  962. }
  963. var ids = map[req], id = ids[0];
  964. return ${requestPrefix}.then(${arrow ? "() =>" : "function()"} {
  965. ${returnModuleObject}
  966. });
  967. }`;
  968. return `var map = ${JSON.stringify(map, null, "\t")};
  969. ${webpackAsyncContext}
  970. webpackAsyncContext.keys = ${runtimeTemplate.returningFunction(
  971. "Object.keys(map)"
  972. )};
  973. webpackAsyncContext.id = ${JSON.stringify(id)};
  974. module.exports = webpackAsyncContext;`;
  975. }
  976. /**
  977. * @param {ModuleId} id module id
  978. * @param {RuntimeTemplate} runtimeTemplate runtime template
  979. * @returns {string} source for empty async context
  980. */
  981. getSourceForEmptyContext(id, runtimeTemplate) {
  982. return `function webpackEmptyContext(req) {
  983. var e = new Error("Cannot find module '" + req + "'");
  984. e.code = 'MODULE_NOT_FOUND';
  985. throw e;
  986. }
  987. webpackEmptyContext.keys = ${runtimeTemplate.returningFunction("[]")};
  988. webpackEmptyContext.resolve = webpackEmptyContext;
  989. webpackEmptyContext.id = ${JSON.stringify(id)};
  990. module.exports = webpackEmptyContext;`;
  991. }
  992. /**
  993. * @param {ModuleId} id module id
  994. * @param {RuntimeTemplate} runtimeTemplate runtime template
  995. * @returns {string} source for empty async context
  996. */
  997. getSourceForEmptyAsyncContext(id, runtimeTemplate) {
  998. const arrow = runtimeTemplate.supportsArrowFunction();
  999. return `function webpackEmptyAsyncContext(req) {
  1000. // Here Promise.resolve().then() is used instead of new Promise() to prevent
  1001. // uncaught exception popping up in devtools
  1002. return Promise.resolve().then(${arrow ? "() =>" : "function()"} {
  1003. var e = new Error("Cannot find module '" + req + "'");
  1004. e.code = 'MODULE_NOT_FOUND';
  1005. throw e;
  1006. });
  1007. }
  1008. webpackEmptyAsyncContext.keys = ${runtimeTemplate.returningFunction("[]")};
  1009. webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
  1010. webpackEmptyAsyncContext.id = ${JSON.stringify(id)};
  1011. module.exports = webpackEmptyAsyncContext;`;
  1012. }
  1013. /**
  1014. * @param {string} asyncMode module mode
  1015. * @param {CodeGenerationContext} context context info
  1016. * @returns {string} the source code
  1017. */
  1018. getSourceString(asyncMode, { runtimeTemplate, chunkGraph }) {
  1019. const id = chunkGraph.getModuleId(this);
  1020. if (asyncMode === "lazy") {
  1021. if (this.blocks && this.blocks.length > 0) {
  1022. return this.getLazySource(this.blocks, id, {
  1023. runtimeTemplate,
  1024. chunkGraph
  1025. });
  1026. }
  1027. return this.getSourceForEmptyAsyncContext(id, runtimeTemplate);
  1028. }
  1029. if (asyncMode === "eager") {
  1030. if (this.dependencies && this.dependencies.length > 0) {
  1031. return this.getEagerSource(this.dependencies, id, {
  1032. chunkGraph,
  1033. runtimeTemplate
  1034. });
  1035. }
  1036. return this.getSourceForEmptyAsyncContext(id, runtimeTemplate);
  1037. }
  1038. if (asyncMode === "lazy-once") {
  1039. const block = this.blocks[0];
  1040. if (block) {
  1041. return this.getLazyOnceSource(block, block.dependencies, id, {
  1042. runtimeTemplate,
  1043. chunkGraph
  1044. });
  1045. }
  1046. return this.getSourceForEmptyAsyncContext(id, runtimeTemplate);
  1047. }
  1048. if (asyncMode === "async-weak") {
  1049. if (this.dependencies && this.dependencies.length > 0) {
  1050. return this.getAsyncWeakSource(this.dependencies, id, {
  1051. chunkGraph,
  1052. runtimeTemplate
  1053. });
  1054. }
  1055. return this.getSourceForEmptyAsyncContext(id, runtimeTemplate);
  1056. }
  1057. if (asyncMode === "weak") {
  1058. if (this.dependencies && this.dependencies.length > 0) {
  1059. return this.getWeakSyncSource(this.dependencies, id, chunkGraph);
  1060. }
  1061. }
  1062. if (this.dependencies && this.dependencies.length > 0) {
  1063. return this.getSyncSource(this.dependencies, id, chunkGraph);
  1064. }
  1065. return this.getSourceForEmptyContext(id, runtimeTemplate);
  1066. }
  1067. /**
  1068. * @param {string} sourceString source content
  1069. * @param {Compilation=} compilation the compilation
  1070. * @returns {Source} generated source
  1071. */
  1072. getSource(sourceString, compilation) {
  1073. if (this.useSourceMap || this.useSimpleSourceMap) {
  1074. return new OriginalSource(
  1075. sourceString,
  1076. `webpack://${makePathsRelative(
  1077. (compilation && compilation.compiler.context) || "",
  1078. this.identifier(),
  1079. compilation && compilation.compiler.root
  1080. )}`
  1081. );
  1082. }
  1083. return new RawSource(sourceString);
  1084. }
  1085. /**
  1086. * @param {CodeGenerationContext} context context for code generation
  1087. * @returns {CodeGenerationResult} result
  1088. */
  1089. codeGeneration(context) {
  1090. const { chunkGraph, compilation } = context;
  1091. const sources = new Map();
  1092. sources.set(
  1093. "javascript",
  1094. this.getSource(
  1095. this.getSourceString(this.options.mode, context),
  1096. compilation
  1097. )
  1098. );
  1099. const set = new Set();
  1100. const allDeps =
  1101. this.dependencies.length > 0
  1102. ? /** @type {ContextElementDependency[]} */ (this.dependencies).slice()
  1103. : [];
  1104. for (const block of this.blocks)
  1105. for (const dep of block.dependencies)
  1106. allDeps.push(/** @type {ContextElementDependency} */ (dep));
  1107. set.add(RuntimeGlobals.module);
  1108. set.add(RuntimeGlobals.hasOwnProperty);
  1109. if (allDeps.length > 0) {
  1110. const asyncMode = this.options.mode;
  1111. set.add(RuntimeGlobals.require);
  1112. if (asyncMode === "weak") {
  1113. set.add(RuntimeGlobals.moduleFactories);
  1114. } else if (asyncMode === "async-weak") {
  1115. set.add(RuntimeGlobals.moduleFactories);
  1116. set.add(RuntimeGlobals.ensureChunk);
  1117. } else if (asyncMode === "lazy" || asyncMode === "lazy-once") {
  1118. set.add(RuntimeGlobals.ensureChunk);
  1119. }
  1120. if (this.getFakeMap(allDeps, chunkGraph) !== 9) {
  1121. set.add(RuntimeGlobals.createFakeNamespaceObject);
  1122. }
  1123. }
  1124. return {
  1125. sources,
  1126. runtimeRequirements: set
  1127. };
  1128. }
  1129. /**
  1130. * @param {string=} type the source type for which the size should be estimated
  1131. * @returns {number} the estimated size of the module (must be non-zero)
  1132. */
  1133. size(type) {
  1134. // base penalty
  1135. let size = 160;
  1136. // if we don't have dependencies we stop here.
  1137. for (const dependency of this.dependencies) {
  1138. const element = /** @type {ContextElementDependency} */ (dependency);
  1139. size += 5 + element.userRequest.length;
  1140. }
  1141. return size;
  1142. }
  1143. /**
  1144. * @param {ObjectSerializerContext} context context
  1145. */
  1146. serialize(context) {
  1147. const { write } = context;
  1148. write(this._identifier);
  1149. write(this._forceBuild);
  1150. super.serialize(context);
  1151. }
  1152. /**
  1153. * @param {ObjectDeserializerContext} context context
  1154. */
  1155. deserialize(context) {
  1156. const { read } = context;
  1157. this._identifier = read();
  1158. this._forceBuild = read();
  1159. super.deserialize(context);
  1160. }
  1161. }
  1162. makeSerializable(ContextModule, "webpack/lib/ContextModule");
  1163. module.exports = ContextModule;