Module.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const util = require("util");
  7. const ChunkGraph = require("./ChunkGraph");
  8. const DependenciesBlock = require("./DependenciesBlock");
  9. const ModuleGraph = require("./ModuleGraph");
  10. const {
  11. JAVASCRIPT_TYPE,
  12. UNKNOWN_TYPE
  13. } = require("./ModuleSourceTypeConstants");
  14. const { JAVASCRIPT_TYPES } = require("./ModuleSourceTypeConstants");
  15. const RuntimeGlobals = require("./RuntimeGlobals");
  16. const { first } = require("./util/SetHelpers");
  17. const { compareChunksById } = require("./util/comparators");
  18. const makeSerializable = require("./util/makeSerializable");
  19. /** @typedef {import("webpack-sources").Source} Source */
  20. /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
  21. /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
  22. /** @typedef {import("./Chunk")} Chunk */
  23. /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
  24. /** @typedef {import("./ChunkGroup")} ChunkGroup */
  25. /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
  26. /** @typedef {import("./Compilation")} Compilation */
  27. /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
  28. /** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
  29. /** @typedef {import("./Compilation").UnsafeCacheData} UnsafeCacheData */
  30. /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
  31. /** @typedef {import("./Dependency")} Dependency */
  32. /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
  33. /** @typedef {import("./DependencyTemplate").CssData} CssData */
  34. /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
  35. /** @typedef {import("./ModuleSourceTypeConstants").AllTypes} AllTypes */
  36. /** @typedef {import("./FileSystemInfo")} FileSystemInfo */
  37. /** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
  38. /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
  39. /** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
  40. /** @typedef {import("./ModuleGraph").OptimizationBailouts} OptimizationBailouts */
  41. /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
  42. /** @typedef {import("./RequestShortener")} RequestShortener */
  43. /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
  44. /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
  45. /** @typedef {import("../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
  46. /**
  47. * @template T
  48. * @typedef {import("./InitFragment")<T>} InitFragment
  49. */
  50. /** @typedef {import("./WebpackError")} WebpackError */
  51. /** @typedef {import("./json/JsonData")} JsonData */
  52. /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  53. /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  54. /** @typedef {import("./util/Hash")} Hash */
  55. /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
  56. /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
  57. /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
  58. /** @typedef {"namespace" | "default-only" | "default-with-named" | "dynamic"} ExportsType */
  59. /**
  60. * @template T
  61. * @typedef {import("./util/LazySet")<T>} LazySet<T>
  62. */
  63. /**
  64. * @typedef {object} SourceContext
  65. * @property {DependencyTemplates} dependencyTemplates the dependency templates
  66. * @property {RuntimeTemplate} runtimeTemplate the runtime template
  67. * @property {ModuleGraph} moduleGraph the module graph
  68. * @property {ChunkGraph} chunkGraph the chunk graph
  69. * @property {RuntimeSpec} runtime the runtimes code should be generated for
  70. * @property {string=} type the type of source that should be generated
  71. */
  72. /** @typedef {AllTypes} KnownSourceType */
  73. /** @typedef {KnownSourceType | string} SourceType */
  74. /** @typedef {ReadonlySet<SourceType>} SourceTypes */
  75. /** @typedef {ReadonlySet<typeof JAVASCRIPT_TYPE | string>} BasicSourceTypes */
  76. // TODO webpack 6: compilation will be required in CodeGenerationContext
  77. /**
  78. * @typedef {object} CodeGenerationContext
  79. * @property {DependencyTemplates} dependencyTemplates the dependency templates
  80. * @property {RuntimeTemplate} runtimeTemplate the runtime template
  81. * @property {ModuleGraph} moduleGraph the module graph
  82. * @property {ChunkGraph} chunkGraph the chunk graph
  83. * @property {RuntimeSpec} runtime the runtimes code should be generated for
  84. * @property {RuntimeSpec[]} runtimes all runtimes code should be generated for
  85. * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
  86. * @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
  87. * @property {Compilation=} compilation the compilation
  88. * @property {SourceTypes=} sourceTypes source types
  89. */
  90. /**
  91. * @typedef {object} ConcatenationBailoutReasonContext
  92. * @property {ModuleGraph} moduleGraph the module graph
  93. * @property {ChunkGraph} chunkGraph the chunk graph
  94. */
  95. /** @typedef {Set<string>} RuntimeRequirements */
  96. /** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
  97. /**
  98. * @typedef {object} AllCodeGenerationSchemas
  99. * @property {Set<string>} topLevelDeclarations top level declarations for javascript modules
  100. * @property {InitFragment<EXPECTED_ANY>[]} chunkInitFragments chunk init fragments for javascript modules
  101. * @property {{ javascript?: string, ["css-url"]?: string }} url url for css and javascript modules
  102. * @property {string} filename a filename for asset modules
  103. * @property {AssetInfo} assetInfo an asset info for asset modules
  104. * @property {string} fullContentHash a full content hash for asset modules
  105. * @property {[{ shareScope: string, initStage: number, init: string }]} share-init share-init for modules federation
  106. */
  107. /* eslint-disable jsdoc/type-formatting */
  108. /**
  109. * @template {string} K
  110. * @typedef {K extends keyof AllCodeGenerationSchemas ? AllCodeGenerationSchemas[K] : EXPECTED_ANY} CodeGenValue
  111. */
  112. /* eslint-enable jsdoc/type-formatting */
  113. /* eslint-disable jsdoc/require-template */
  114. /**
  115. * @typedef {object} CodeGenMapOverloads
  116. * @property {<K extends string>(key: K) => CodeGenValue<K> | undefined} get
  117. * @property {<K extends string>(key: K, value: CodeGenValue<K>) => CodeGenerationResultData} set
  118. * @property {<K extends string>(key: K) => boolean} has
  119. * @property {<K extends string>(key: K) => boolean} delete
  120. */
  121. /**
  122. * @typedef {Omit<Map<string, EXPECTED_ANY>, "get" | "set" | "has" | "delete"> & CodeGenMapOverloads} CodeGenerationResultData
  123. */
  124. /** @typedef {Map<SourceType, Source>} Sources */
  125. /**
  126. * @typedef {object} CodeGenerationResult
  127. * @property {Sources} sources the resulting sources for all source types
  128. * @property {CodeGenerationResultData=} data the resulting data for all source types
  129. * @property {ReadOnlyRuntimeRequirements | null} runtimeRequirements the runtime requirements
  130. * @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
  131. */
  132. /**
  133. * @typedef {object} LibIdentOptions
  134. * @property {string} context absolute context path to which lib ident is relative to
  135. * @property {AssociatedObjectForCache=} associatedObjectForCache object for caching
  136. */
  137. /**
  138. * @typedef {object} KnownBuildMeta
  139. * @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
  140. * @property {CssParserExportType=} exportType
  141. * @property {(false | "redirect" | "redirect-warn")=} defaultObject
  142. * @property {boolean=} strictHarmonyModule
  143. * @property {boolean=} treatAsCommonJs
  144. * @property {boolean=} async
  145. * @property {boolean=} sideEffectFree
  146. * @property {boolean=} isCSSModule
  147. * @property {Record<string, string>=} jsIncompatibleExports
  148. * @property {Map<string, Record<string, string>>=} exportsFinalNameByRuntime
  149. * @property {Map<string, string>=} exportsSourceByRuntime
  150. */
  151. /**
  152. * @typedef {object} KnownBuildInfo
  153. * @property {boolean=} cacheable
  154. * @property {boolean=} parsed
  155. * @property {boolean=} strict
  156. * @property {string=} moduleArgument using in AMD
  157. * @property {string=} exportsArgument using in AMD
  158. * @property {string=} moduleConcatenationBailout using in CommonJs
  159. * @property {boolean=} needCreateRequire using in APIPlugin
  160. * @property {string=} resourceIntegrity using in HttpUriPlugin
  161. * @property {FileSystemDependencies=} fileDependencies using in NormalModule
  162. * @property {FileSystemDependencies=} contextDependencies using in NormalModule
  163. * @property {FileSystemDependencies=} missingDependencies using in NormalModule
  164. * @property {FileSystemDependencies=} buildDependencies using in NormalModule
  165. * @property {ValueCacheVersions=} valueDependencies using in NormalModule
  166. * @property {Record<string, Source>=} assets using in NormalModule
  167. * @property {Map<string, AssetInfo | undefined>=} assetsInfo using in NormalModule
  168. * @property {string=} hash using in NormalModule
  169. * @property {(Snapshot | null)=} snapshot using in ContextModule
  170. * @property {string=} fullContentHash for assets modules
  171. * @property {string=} filename for assets modules
  172. * @property {boolean=} dataUrl for assets modules
  173. * @property {AssetInfo=} assetInfo for assets modules
  174. * @property {boolean=} javascriptModule for external modules
  175. * @property {boolean=} active for lazy compilation modules
  176. * @property {CssData=} cssData for css modules
  177. * @property {JsonData=} jsonData for json modules
  178. * @property {Set<string>=} topLevelDeclarations top level declaration names
  179. */
  180. /** @typedef {string | Set<string>} ValueCacheVersion */
  181. /** @typedef {Map<string, ValueCacheVersion>} ValueCacheVersions */
  182. /**
  183. * @typedef {object} NeedBuildContext
  184. * @property {Compilation} compilation
  185. * @property {FileSystemInfo} fileSystemInfo
  186. * @property {ValueCacheVersions} valueCacheVersions
  187. */
  188. /** @typedef {(err?: WebpackError | null, needBuild?: boolean) => void} NeedBuildCallback */
  189. /** @typedef {(err?: WebpackError) => void} BuildCallback */
  190. /** @typedef {KnownBuildMeta & Record<string, EXPECTED_ANY>} BuildMeta */
  191. /** @typedef {KnownBuildInfo & Record<string, EXPECTED_ANY>} BuildInfo */
  192. /**
  193. * @typedef {object} FactoryMeta
  194. * @property {boolean=} sideEffectFree
  195. */
  196. const EMPTY_RESOLVE_OPTIONS = {};
  197. let debugId = 1000;
  198. /** @type {SourceTypes} */
  199. const DEFAULT_TYPES_UNKNOWN = new Set([UNKNOWN_TYPE]);
  200. const deprecatedNeedRebuild = util.deprecate(
  201. /**
  202. * @param {Module} module the module
  203. * @param {NeedBuildContext} context context info
  204. * @returns {boolean} true, when rebuild is needed
  205. */
  206. (module, context) =>
  207. module.needRebuild(
  208. context.fileSystemInfo.getDeprecatedFileTimestamps(),
  209. context.fileSystemInfo.getDeprecatedContextTimestamps()
  210. ),
  211. "Module.needRebuild is deprecated in favor of Module.needBuild",
  212. "DEP_WEBPACK_MODULE_NEED_REBUILD"
  213. );
  214. /** @typedef {string} LibIdent */
  215. /** @typedef {string} NameForCondition */
  216. /** @typedef {(requestShortener: RequestShortener) => string} OptimizationBailoutFunction */
  217. class Module extends DependenciesBlock {
  218. /**
  219. * @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
  220. * @param {(string | null)=} context an optional context
  221. * @param {(string | null)=} layer an optional layer in which the module is
  222. */
  223. constructor(type, context = null, layer = null) {
  224. super();
  225. /** @type {ModuleTypes} */
  226. this.type = type;
  227. /** @type {string | null} */
  228. this.context = context;
  229. /** @type {string | null} */
  230. this.layer = layer;
  231. /** @type {boolean} */
  232. this.needId = true;
  233. // Unique Id
  234. /** @type {number} */
  235. this.debugId = debugId++;
  236. // Info from Factory
  237. /** @type {ResolveOptions | undefined} */
  238. this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
  239. /** @type {FactoryMeta | undefined} */
  240. this.factoryMeta = undefined;
  241. // TODO refactor this -> options object filled from Factory
  242. // TODO webpack 6: use an enum
  243. /** @type {boolean} */
  244. this.useSourceMap = false;
  245. /** @type {boolean} */
  246. this.useSimpleSourceMap = false;
  247. // Is in hot context, i.e. HotModuleReplacementPlugin.js enabled
  248. // TODO do we need hot here?
  249. /** @type {boolean} */
  250. this.hot = false;
  251. // Info from Build
  252. /** @type {WebpackError[] | undefined} */
  253. this._warnings = undefined;
  254. /** @type {WebpackError[] | undefined} */
  255. this._errors = undefined;
  256. /** @type {BuildMeta | undefined} */
  257. this.buildMeta = undefined;
  258. /** @type {BuildInfo | undefined} */
  259. this.buildInfo = undefined;
  260. /** @type {Dependency[] | undefined} */
  261. this.presentationalDependencies = undefined;
  262. /** @type {Dependency[] | undefined} */
  263. this.codeGenerationDependencies = undefined;
  264. }
  265. // TODO remove in webpack 6
  266. // BACKWARD-COMPAT START
  267. /**
  268. * @returns {ModuleId | null} module id
  269. */
  270. get id() {
  271. return ChunkGraph.getChunkGraphForModule(
  272. this,
  273. "Module.id",
  274. "DEP_WEBPACK_MODULE_ID"
  275. ).getModuleId(this);
  276. }
  277. /**
  278. * @param {ModuleId} value value
  279. */
  280. set id(value) {
  281. if (value === "") {
  282. this.needId = false;
  283. return;
  284. }
  285. ChunkGraph.getChunkGraphForModule(
  286. this,
  287. "Module.id",
  288. "DEP_WEBPACK_MODULE_ID"
  289. ).setModuleId(this, value);
  290. }
  291. /**
  292. * @returns {string} the hash of the module
  293. */
  294. get hash() {
  295. return ChunkGraph.getChunkGraphForModule(
  296. this,
  297. "Module.hash",
  298. "DEP_WEBPACK_MODULE_HASH"
  299. ).getModuleHash(this, undefined);
  300. }
  301. /**
  302. * @returns {string} the shortened hash of the module
  303. */
  304. get renderedHash() {
  305. return ChunkGraph.getChunkGraphForModule(
  306. this,
  307. "Module.renderedHash",
  308. "DEP_WEBPACK_MODULE_RENDERED_HASH"
  309. ).getRenderedModuleHash(this, undefined);
  310. }
  311. get profile() {
  312. return ModuleGraph.getModuleGraphForModule(
  313. this,
  314. "Module.profile",
  315. "DEP_WEBPACK_MODULE_PROFILE"
  316. ).getProfile(this);
  317. }
  318. set profile(value) {
  319. ModuleGraph.getModuleGraphForModule(
  320. this,
  321. "Module.profile",
  322. "DEP_WEBPACK_MODULE_PROFILE"
  323. ).setProfile(this, value);
  324. }
  325. /**
  326. * @returns {number | null} the pre order index
  327. */
  328. get index() {
  329. return ModuleGraph.getModuleGraphForModule(
  330. this,
  331. "Module.index",
  332. "DEP_WEBPACK_MODULE_INDEX"
  333. ).getPreOrderIndex(this);
  334. }
  335. /**
  336. * @param {number} value the pre order index
  337. */
  338. set index(value) {
  339. ModuleGraph.getModuleGraphForModule(
  340. this,
  341. "Module.index",
  342. "DEP_WEBPACK_MODULE_INDEX"
  343. ).setPreOrderIndex(this, value);
  344. }
  345. /**
  346. * @returns {number | null} the post order index
  347. */
  348. get index2() {
  349. return ModuleGraph.getModuleGraphForModule(
  350. this,
  351. "Module.index2",
  352. "DEP_WEBPACK_MODULE_INDEX2"
  353. ).getPostOrderIndex(this);
  354. }
  355. /**
  356. * @param {number} value the post order index
  357. */
  358. set index2(value) {
  359. ModuleGraph.getModuleGraphForModule(
  360. this,
  361. "Module.index2",
  362. "DEP_WEBPACK_MODULE_INDEX2"
  363. ).setPostOrderIndex(this, value);
  364. }
  365. /**
  366. * @returns {number | null} the depth
  367. */
  368. get depth() {
  369. return ModuleGraph.getModuleGraphForModule(
  370. this,
  371. "Module.depth",
  372. "DEP_WEBPACK_MODULE_DEPTH"
  373. ).getDepth(this);
  374. }
  375. /**
  376. * @param {number} value the depth
  377. */
  378. set depth(value) {
  379. ModuleGraph.getModuleGraphForModule(
  380. this,
  381. "Module.depth",
  382. "DEP_WEBPACK_MODULE_DEPTH"
  383. ).setDepth(this, value);
  384. }
  385. /**
  386. * @returns {Module | null | undefined} issuer
  387. */
  388. get issuer() {
  389. return ModuleGraph.getModuleGraphForModule(
  390. this,
  391. "Module.issuer",
  392. "DEP_WEBPACK_MODULE_ISSUER"
  393. ).getIssuer(this);
  394. }
  395. /**
  396. * @param {Module | null} value issuer
  397. */
  398. set issuer(value) {
  399. ModuleGraph.getModuleGraphForModule(
  400. this,
  401. "Module.issuer",
  402. "DEP_WEBPACK_MODULE_ISSUER"
  403. ).setIssuer(this, value);
  404. }
  405. get usedExports() {
  406. return ModuleGraph.getModuleGraphForModule(
  407. this,
  408. "Module.usedExports",
  409. "DEP_WEBPACK_MODULE_USED_EXPORTS"
  410. ).getUsedExports(this, undefined);
  411. }
  412. /**
  413. * @deprecated
  414. * @returns {OptimizationBailouts} list
  415. */
  416. get optimizationBailout() {
  417. return ModuleGraph.getModuleGraphForModule(
  418. this,
  419. "Module.optimizationBailout",
  420. "DEP_WEBPACK_MODULE_OPTIMIZATION_BAILOUT"
  421. ).getOptimizationBailout(this);
  422. }
  423. get optional() {
  424. return this.isOptional(
  425. ModuleGraph.getModuleGraphForModule(
  426. this,
  427. "Module.optional",
  428. "DEP_WEBPACK_MODULE_OPTIONAL"
  429. )
  430. );
  431. }
  432. /**
  433. * @param {Chunk} chunk the chunk
  434. * @returns {boolean} true, when the module was added
  435. */
  436. addChunk(chunk) {
  437. const chunkGraph = ChunkGraph.getChunkGraphForModule(
  438. this,
  439. "Module.addChunk",
  440. "DEP_WEBPACK_MODULE_ADD_CHUNK"
  441. );
  442. if (chunkGraph.isModuleInChunk(this, chunk)) return false;
  443. chunkGraph.connectChunkAndModule(chunk, this);
  444. return true;
  445. }
  446. /**
  447. * @param {Chunk} chunk the chunk
  448. * @returns {void}
  449. */
  450. removeChunk(chunk) {
  451. return ChunkGraph.getChunkGraphForModule(
  452. this,
  453. "Module.removeChunk",
  454. "DEP_WEBPACK_MODULE_REMOVE_CHUNK"
  455. ).disconnectChunkAndModule(chunk, this);
  456. }
  457. /**
  458. * @param {Chunk} chunk the chunk
  459. * @returns {boolean} true, when the module is in the chunk
  460. */
  461. isInChunk(chunk) {
  462. return ChunkGraph.getChunkGraphForModule(
  463. this,
  464. "Module.isInChunk",
  465. "DEP_WEBPACK_MODULE_IS_IN_CHUNK"
  466. ).isModuleInChunk(this, chunk);
  467. }
  468. isEntryModule() {
  469. return ChunkGraph.getChunkGraphForModule(
  470. this,
  471. "Module.isEntryModule",
  472. "DEP_WEBPACK_MODULE_IS_ENTRY_MODULE"
  473. ).isEntryModule(this);
  474. }
  475. getChunks() {
  476. return ChunkGraph.getChunkGraphForModule(
  477. this,
  478. "Module.getChunks",
  479. "DEP_WEBPACK_MODULE_GET_CHUNKS"
  480. ).getModuleChunks(this);
  481. }
  482. getNumberOfChunks() {
  483. return ChunkGraph.getChunkGraphForModule(
  484. this,
  485. "Module.getNumberOfChunks",
  486. "DEP_WEBPACK_MODULE_GET_NUMBER_OF_CHUNKS"
  487. ).getNumberOfModuleChunks(this);
  488. }
  489. get chunksIterable() {
  490. return ChunkGraph.getChunkGraphForModule(
  491. this,
  492. "Module.chunksIterable",
  493. "DEP_WEBPACK_MODULE_CHUNKS_ITERABLE"
  494. ).getOrderedModuleChunksIterable(this, compareChunksById);
  495. }
  496. /**
  497. * @param {string} exportName a name of an export
  498. * @returns {boolean | null} true, if the export is provided why the module.
  499. * null, if it's unknown.
  500. * false, if it's not provided.
  501. */
  502. isProvided(exportName) {
  503. return ModuleGraph.getModuleGraphForModule(
  504. this,
  505. "Module.usedExports",
  506. "DEP_WEBPACK_MODULE_USED_EXPORTS"
  507. ).isExportProvided(this, exportName);
  508. }
  509. // BACKWARD-COMPAT END
  510. /**
  511. * @returns {string} name of the exports argument
  512. */
  513. get exportsArgument() {
  514. return (this.buildInfo && this.buildInfo.exportsArgument) || "exports";
  515. }
  516. /**
  517. * @returns {string} name of the module argument
  518. */
  519. get moduleArgument() {
  520. return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
  521. }
  522. /**
  523. * @param {ModuleGraph} moduleGraph the module graph
  524. * @param {boolean | undefined} strict the importing module is strict
  525. * @returns {ExportsType} export type
  526. * "namespace": Exports is already a namespace object. namespace = exports.
  527. * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
  528. * "default-only": Provide a namespace object with only default export. namespace = { default: exports }
  529. * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
  530. */
  531. getExportsType(moduleGraph, strict) {
  532. switch (this.buildMeta && this.buildMeta.exportsType) {
  533. case "flagged":
  534. return strict ? "default-with-named" : "namespace";
  535. case "namespace":
  536. return "namespace";
  537. case "default":
  538. switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
  539. case "redirect":
  540. return "default-with-named";
  541. case "redirect-warn":
  542. return strict ? "default-only" : "default-with-named";
  543. default:
  544. return "default-only";
  545. }
  546. case "dynamic": {
  547. if (strict) return "default-with-named";
  548. // Try to figure out value of __esModule by following reexports
  549. const handleDefault = () => {
  550. switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
  551. case "redirect":
  552. case "redirect-warn":
  553. return "default-with-named";
  554. default:
  555. return "default-only";
  556. }
  557. };
  558. const exportInfo = moduleGraph.getReadOnlyExportInfo(
  559. this,
  560. "__esModule"
  561. );
  562. if (exportInfo.provided === false) {
  563. return handleDefault();
  564. }
  565. const target = exportInfo.getTarget(moduleGraph);
  566. if (
  567. !target ||
  568. !target.export ||
  569. target.export.length !== 1 ||
  570. target.export[0] !== "__esModule"
  571. ) {
  572. return "dynamic";
  573. }
  574. switch (
  575. target.module.buildMeta &&
  576. target.module.buildMeta.exportsType
  577. ) {
  578. case "flagged":
  579. case "namespace":
  580. return "namespace";
  581. case "default":
  582. return handleDefault();
  583. default:
  584. return "dynamic";
  585. }
  586. }
  587. default:
  588. return strict ? "default-with-named" : "dynamic";
  589. }
  590. }
  591. /**
  592. * @param {Dependency} presentationalDependency dependency being tied to module.
  593. * This is a Dependency without edge in the module graph. It's only for presentation.
  594. * @returns {void}
  595. */
  596. addPresentationalDependency(presentationalDependency) {
  597. if (this.presentationalDependencies === undefined) {
  598. this.presentationalDependencies = [];
  599. }
  600. this.presentationalDependencies.push(presentationalDependency);
  601. }
  602. /**
  603. * @param {Dependency} codeGenerationDependency dependency being tied to module.
  604. * This is a Dependency where the code generation result of the referenced module is needed during code generation.
  605. * The Dependency should also be added to normal dependencies via addDependency.
  606. * @returns {void}
  607. */
  608. addCodeGenerationDependency(codeGenerationDependency) {
  609. if (this.codeGenerationDependencies === undefined) {
  610. this.codeGenerationDependencies = [];
  611. }
  612. this.codeGenerationDependencies.push(codeGenerationDependency);
  613. }
  614. /**
  615. * Removes all dependencies and blocks
  616. * @returns {void}
  617. */
  618. clearDependenciesAndBlocks() {
  619. if (this.presentationalDependencies !== undefined) {
  620. this.presentationalDependencies.length = 0;
  621. }
  622. if (this.codeGenerationDependencies !== undefined) {
  623. this.codeGenerationDependencies.length = 0;
  624. }
  625. super.clearDependenciesAndBlocks();
  626. }
  627. /**
  628. * @param {WebpackError} warning the warning
  629. * @returns {void}
  630. */
  631. addWarning(warning) {
  632. if (this._warnings === undefined) {
  633. this._warnings = [];
  634. }
  635. this._warnings.push(warning);
  636. }
  637. /**
  638. * @returns {Iterable<WebpackError> | undefined} list of warnings if any
  639. */
  640. getWarnings() {
  641. return this._warnings;
  642. }
  643. /**
  644. * @returns {number} number of warnings
  645. */
  646. getNumberOfWarnings() {
  647. return this._warnings !== undefined ? this._warnings.length : 0;
  648. }
  649. /**
  650. * @param {WebpackError} error the error
  651. * @returns {void}
  652. */
  653. addError(error) {
  654. if (this._errors === undefined) {
  655. this._errors = [];
  656. }
  657. this._errors.push(error);
  658. }
  659. /**
  660. * @returns {Iterable<WebpackError> | undefined} list of errors if any
  661. */
  662. getErrors() {
  663. return this._errors;
  664. }
  665. /**
  666. * @returns {number} number of errors
  667. */
  668. getNumberOfErrors() {
  669. return this._errors !== undefined ? this._errors.length : 0;
  670. }
  671. /**
  672. * removes all warnings and errors
  673. * @returns {void}
  674. */
  675. clearWarningsAndErrors() {
  676. if (this._warnings !== undefined) {
  677. this._warnings.length = 0;
  678. }
  679. if (this._errors !== undefined) {
  680. this._errors.length = 0;
  681. }
  682. }
  683. /**
  684. * @param {ModuleGraph} moduleGraph the module graph
  685. * @returns {boolean} true, if the module is optional
  686. */
  687. isOptional(moduleGraph) {
  688. let hasConnections = false;
  689. for (const r of moduleGraph.getIncomingConnections(this)) {
  690. if (
  691. !r.dependency ||
  692. !r.dependency.optional ||
  693. !r.isTargetActive(undefined)
  694. ) {
  695. return false;
  696. }
  697. hasConnections = true;
  698. }
  699. return hasConnections;
  700. }
  701. /**
  702. * @param {ChunkGraph} chunkGraph the chunk graph
  703. * @param {Chunk} chunk a chunk
  704. * @param {Chunk=} ignoreChunk chunk to be ignored
  705. * @returns {boolean} true, if the module is accessible from "chunk" when ignoring "ignoreChunk"
  706. */
  707. isAccessibleInChunk(chunkGraph, chunk, ignoreChunk) {
  708. // Check if module is accessible in ALL chunk groups
  709. for (const chunkGroup of chunk.groupsIterable) {
  710. if (!this.isAccessibleInChunkGroup(chunkGraph, chunkGroup)) return false;
  711. }
  712. return true;
  713. }
  714. /**
  715. * @param {ChunkGraph} chunkGraph the chunk graph
  716. * @param {ChunkGroup} chunkGroup a chunk group
  717. * @param {Chunk=} ignoreChunk chunk to be ignored
  718. * @returns {boolean} true, if the module is accessible from "chunkGroup" when ignoring "ignoreChunk"
  719. */
  720. isAccessibleInChunkGroup(chunkGraph, chunkGroup, ignoreChunk) {
  721. const queue = new Set([chunkGroup]);
  722. // Check if module is accessible from all items of the queue
  723. queueFor: for (const cg of queue) {
  724. // 1. If module is in one of the chunks of the group we can continue checking the next items
  725. // because it's accessible.
  726. for (const chunk of cg.chunks) {
  727. if (chunk !== ignoreChunk && chunkGraph.isModuleInChunk(this, chunk)) {
  728. continue queueFor;
  729. }
  730. }
  731. // 2. If the chunk group is initial, we can break here because it's not accessible.
  732. if (chunkGroup.isInitial()) return false;
  733. // 3. Enqueue all parents because it must be accessible from ALL parents
  734. for (const parent of chunkGroup.parentsIterable) queue.add(parent);
  735. }
  736. // When we processed through the whole list and we didn't bailout, the module is accessible
  737. return true;
  738. }
  739. /**
  740. * @param {Chunk} chunk a chunk
  741. * @param {ModuleGraph} moduleGraph the module graph
  742. * @param {ChunkGraph} chunkGraph the chunk graph
  743. * @returns {boolean} true, if the module has any reason why "chunk" should be included
  744. */
  745. hasReasonForChunk(chunk, moduleGraph, chunkGraph) {
  746. // check for each reason if we need the chunk
  747. for (const [
  748. fromModule,
  749. connections
  750. ] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
  751. if (!connections.some((c) => c.isTargetActive(chunk.runtime))) continue;
  752. for (const originChunk of chunkGraph.getModuleChunksIterable(
  753. /** @type {Module} */ (fromModule)
  754. )) {
  755. // return true if module this is not reachable from originChunk when ignoring chunk
  756. if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk)) {
  757. return true;
  758. }
  759. }
  760. }
  761. return false;
  762. }
  763. /**
  764. * @param {ModuleGraph} moduleGraph the module graph
  765. * @param {RuntimeSpec} runtime the runtime
  766. * @returns {boolean} true if at least one other module depends on this module
  767. */
  768. hasReasons(moduleGraph, runtime) {
  769. for (const c of moduleGraph.getIncomingConnections(this)) {
  770. if (c.isTargetActive(runtime)) return true;
  771. }
  772. return false;
  773. }
  774. /**
  775. * @returns {string} for debugging
  776. */
  777. toString() {
  778. return `Module[${this.debugId}: ${this.identifier()}]`;
  779. }
  780. /**
  781. * @param {NeedBuildContext} context context info
  782. * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
  783. * @returns {void}
  784. */
  785. needBuild(context, callback) {
  786. callback(
  787. null,
  788. !this.buildMeta ||
  789. this.needRebuild === Module.prototype.needRebuild ||
  790. deprecatedNeedRebuild(this, context)
  791. );
  792. }
  793. /**
  794. * @deprecated Use needBuild instead
  795. * @param {Map<string, number | null>} fileTimestamps timestamps of files
  796. * @param {Map<string, number | null>} contextTimestamps timestamps of directories
  797. * @returns {boolean} true, if the module needs a rebuild
  798. */
  799. needRebuild(fileTimestamps, contextTimestamps) {
  800. return true;
  801. }
  802. /**
  803. * @param {Hash} hash the hash used to track dependencies
  804. * @param {UpdateHashContext} context context
  805. * @returns {void}
  806. */
  807. updateHash(
  808. hash,
  809. context = {
  810. chunkGraph: ChunkGraph.getChunkGraphForModule(
  811. this,
  812. "Module.updateHash",
  813. "DEP_WEBPACK_MODULE_UPDATE_HASH"
  814. ),
  815. runtime: undefined
  816. }
  817. ) {
  818. const { chunkGraph, runtime } = context;
  819. hash.update(chunkGraph.getModuleGraphHash(this, runtime));
  820. if (this.presentationalDependencies !== undefined) {
  821. for (const dep of this.presentationalDependencies) {
  822. dep.updateHash(hash, context);
  823. }
  824. }
  825. super.updateHash(hash, context);
  826. }
  827. /**
  828. * @returns {void}
  829. */
  830. invalidateBuild() {
  831. // should be overridden to support this feature
  832. }
  833. /* istanbul ignore next */
  834. /**
  835. * @abstract
  836. * @returns {string} a unique identifier of the module
  837. */
  838. identifier() {
  839. const AbstractMethodError = require("./AbstractMethodError");
  840. throw new AbstractMethodError();
  841. }
  842. /* istanbul ignore next */
  843. /**
  844. * @abstract
  845. * @param {RequestShortener} requestShortener the request shortener
  846. * @returns {string} a user readable identifier of the module
  847. */
  848. readableIdentifier(requestShortener) {
  849. const AbstractMethodError = require("./AbstractMethodError");
  850. throw new AbstractMethodError();
  851. }
  852. /* istanbul ignore next */
  853. /**
  854. * @abstract
  855. * @param {WebpackOptions} options webpack options
  856. * @param {Compilation} compilation the compilation
  857. * @param {ResolverWithOptions} resolver the resolver
  858. * @param {InputFileSystem} fs the file system
  859. * @param {BuildCallback} callback callback function
  860. * @returns {void}
  861. */
  862. build(options, compilation, resolver, fs, callback) {
  863. const AbstractMethodError = require("./AbstractMethodError");
  864. throw new AbstractMethodError();
  865. }
  866. /**
  867. * @abstract
  868. * @returns {SourceTypes} types available (do not mutate)
  869. */
  870. getSourceTypes() {
  871. // Better override this method to return the correct types
  872. if (this.source === Module.prototype.source) {
  873. return DEFAULT_TYPES_UNKNOWN;
  874. }
  875. return JAVASCRIPT_TYPES;
  876. }
  877. /**
  878. * Basic source types are high-level categories like javascript, css, webassembly, etc.
  879. * We only have built-in knowledge about the javascript basic type here; other basic types may be
  880. * added or changed over time by generators and do not need to be handled or detected here.
  881. *
  882. * Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
  883. * from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
  884. * @returns {BasicSourceTypes} types available (do not mutate)
  885. */
  886. getSourceBasicTypes() {
  887. return this.getSourceTypes();
  888. }
  889. /**
  890. * @abstract
  891. * @deprecated Use codeGeneration() instead
  892. * @param {DependencyTemplates} dependencyTemplates the dependency templates
  893. * @param {RuntimeTemplate} runtimeTemplate the runtime template
  894. * @param {SourceType=} type the type of source that should be generated
  895. * @returns {Source} generated source
  896. */
  897. source(dependencyTemplates, runtimeTemplate, type = JAVASCRIPT_TYPE) {
  898. if (this.codeGeneration === Module.prototype.codeGeneration) {
  899. const AbstractMethodError = require("./AbstractMethodError");
  900. throw new AbstractMethodError();
  901. }
  902. const chunkGraph = ChunkGraph.getChunkGraphForModule(
  903. this,
  904. "Module.source() is deprecated. Use Compilation.codeGenerationResults.getSource(module, runtime, type) instead",
  905. "DEP_WEBPACK_MODULE_SOURCE"
  906. );
  907. /** @type {CodeGenerationContext} */
  908. const codeGenContext = {
  909. dependencyTemplates,
  910. runtimeTemplate,
  911. moduleGraph: chunkGraph.moduleGraph,
  912. chunkGraph,
  913. runtime: undefined,
  914. runtimes: [],
  915. codeGenerationResults: undefined
  916. };
  917. const sources = this.codeGeneration(codeGenContext).sources;
  918. return /** @type {Source} */ (
  919. type
  920. ? sources.get(type)
  921. : sources.get(/** @type {SourceType} */ (first(this.getSourceTypes())))
  922. );
  923. }
  924. /* istanbul ignore next */
  925. /**
  926. * @abstract
  927. * @param {string=} type the source type for which the size should be estimated
  928. * @returns {number} the estimated size of the module (must be non-zero)
  929. */
  930. size(type) {
  931. const AbstractMethodError = require("./AbstractMethodError");
  932. throw new AbstractMethodError();
  933. }
  934. /**
  935. * @param {LibIdentOptions} options options
  936. * @returns {LibIdent | null} an identifier for library inclusion
  937. */
  938. libIdent(options) {
  939. return null;
  940. }
  941. /**
  942. * @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
  943. */
  944. nameForCondition() {
  945. return null;
  946. }
  947. /**
  948. * @param {ConcatenationBailoutReasonContext} context context
  949. * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
  950. */
  951. getConcatenationBailoutReason(context) {
  952. return `Module Concatenation is not implemented for ${this.constructor.name}`;
  953. }
  954. /**
  955. * @param {ModuleGraph} moduleGraph the module graph
  956. * @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
  957. */
  958. getSideEffectsConnectionState(moduleGraph) {
  959. return true;
  960. }
  961. /**
  962. * @param {CodeGenerationContext} context context for code generation
  963. * @returns {CodeGenerationResult} result
  964. */
  965. codeGeneration(context) {
  966. // Best override this method
  967. /** @type {Sources} */
  968. const sources = new Map();
  969. for (const type of this.getSourceTypes()) {
  970. if (type !== UNKNOWN_TYPE) {
  971. sources.set(
  972. type,
  973. this.source(
  974. context.dependencyTemplates,
  975. context.runtimeTemplate,
  976. type
  977. )
  978. );
  979. }
  980. }
  981. return {
  982. sources,
  983. runtimeRequirements: new Set([
  984. RuntimeGlobals.module,
  985. RuntimeGlobals.exports,
  986. RuntimeGlobals.require
  987. ])
  988. };
  989. }
  990. /**
  991. * @param {Chunk} chunk the chunk which condition should be checked
  992. * @param {Compilation} compilation the compilation
  993. * @returns {boolean} true, if the chunk is ok for the module
  994. */
  995. chunkCondition(chunk, compilation) {
  996. return true;
  997. }
  998. hasChunkCondition() {
  999. return this.chunkCondition !== Module.prototype.chunkCondition;
  1000. }
  1001. /**
  1002. * Assuming this module is in the cache. Update the (cached) module with
  1003. * the fresh module from the factory. Usually updates internal references
  1004. * and properties.
  1005. * @param {Module} module fresh module
  1006. * @returns {void}
  1007. */
  1008. updateCacheModule(module) {
  1009. this.type = module.type;
  1010. this.layer = module.layer;
  1011. this.context = module.context;
  1012. this.factoryMeta = module.factoryMeta;
  1013. this.resolveOptions = module.resolveOptions;
  1014. }
  1015. /**
  1016. * Module should be unsafe cached. Get data that's needed for that.
  1017. * This data will be passed to restoreFromUnsafeCache later.
  1018. * @returns {UnsafeCacheData} cached data
  1019. */
  1020. getUnsafeCacheData() {
  1021. return {
  1022. factoryMeta: this.factoryMeta,
  1023. resolveOptions: this.resolveOptions
  1024. };
  1025. }
  1026. /**
  1027. * restore unsafe cache data
  1028. * @param {UnsafeCacheData} unsafeCacheData data from getUnsafeCacheData
  1029. * @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
  1030. */
  1031. _restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
  1032. this.factoryMeta = unsafeCacheData.factoryMeta;
  1033. this.resolveOptions = unsafeCacheData.resolveOptions;
  1034. }
  1035. /**
  1036. * Assuming this module is in the cache. Remove internal references to allow freeing some memory.
  1037. */
  1038. cleanupForCache() {
  1039. this.factoryMeta = undefined;
  1040. this.resolveOptions = undefined;
  1041. }
  1042. /**
  1043. * @returns {Source | null} the original source for the module before webpack transformation
  1044. */
  1045. originalSource() {
  1046. return null;
  1047. }
  1048. /**
  1049. * @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
  1050. * @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
  1051. * @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
  1052. * @param {FileSystemDependencies} buildDependencies set where build dependencies are added to
  1053. */
  1054. addCacheDependencies(
  1055. fileDependencies,
  1056. contextDependencies,
  1057. missingDependencies,
  1058. buildDependencies
  1059. ) {}
  1060. /**
  1061. * @param {ObjectSerializerContext} context context
  1062. */
  1063. serialize(context) {
  1064. const { write } = context;
  1065. write(this.type);
  1066. write(this.layer);
  1067. write(this.context);
  1068. write(this.resolveOptions);
  1069. write(this.factoryMeta);
  1070. write(this.useSourceMap);
  1071. write(this.useSimpleSourceMap);
  1072. write(this.hot);
  1073. write(
  1074. this._warnings !== undefined && this._warnings.length === 0
  1075. ? undefined
  1076. : this._warnings
  1077. );
  1078. write(
  1079. this._errors !== undefined && this._errors.length === 0
  1080. ? undefined
  1081. : this._errors
  1082. );
  1083. write(this.buildMeta);
  1084. write(this.buildInfo);
  1085. write(this.presentationalDependencies);
  1086. write(this.codeGenerationDependencies);
  1087. super.serialize(context);
  1088. }
  1089. /**
  1090. * @param {ObjectDeserializerContext} context context
  1091. */
  1092. deserialize(context) {
  1093. const { read } = context;
  1094. this.type = read();
  1095. this.layer = read();
  1096. this.context = read();
  1097. this.resolveOptions = read();
  1098. this.factoryMeta = read();
  1099. this.useSourceMap = read();
  1100. this.useSimpleSourceMap = read();
  1101. this.hot = read();
  1102. this._warnings = read();
  1103. this._errors = read();
  1104. this.buildMeta = read();
  1105. this.buildInfo = read();
  1106. this.presentationalDependencies = read();
  1107. this.codeGenerationDependencies = read();
  1108. super.deserialize(context);
  1109. }
  1110. }
  1111. makeSerializable(Module, "webpack/lib/Module");
  1112. // TODO remove in webpack 6
  1113. Object.defineProperty(Module.prototype, "hasEqualsChunks", {
  1114. /**
  1115. * @deprecated
  1116. * @returns {EXPECTED_ANY} throw an error
  1117. */
  1118. get() {
  1119. throw new Error(
  1120. "Module.hasEqualsChunks was renamed (use hasEqualChunks instead)"
  1121. );
  1122. }
  1123. });
  1124. // TODO remove in webpack 6
  1125. Object.defineProperty(Module.prototype, "isUsed", {
  1126. /**
  1127. * @deprecated
  1128. * @returns {EXPECTED_ANY} throw an error
  1129. */
  1130. get() {
  1131. throw new Error(
  1132. "Module.isUsed was renamed (use getUsedName, isExportUsed or isModuleUsed instead)"
  1133. );
  1134. }
  1135. });
  1136. // TODO remove in webpack 6
  1137. Object.defineProperty(Module.prototype, "errors", {
  1138. /**
  1139. * @deprecated
  1140. * @returns {WebpackError[]} errors
  1141. */
  1142. get: util.deprecate(
  1143. /**
  1144. * @this {Module}
  1145. * @returns {WebpackError[]} errors
  1146. */
  1147. function errors() {
  1148. if (this._errors === undefined) {
  1149. this._errors = [];
  1150. }
  1151. return this._errors;
  1152. },
  1153. "Module.errors was removed (use getErrors instead)",
  1154. "DEP_WEBPACK_MODULE_ERRORS"
  1155. )
  1156. });
  1157. // TODO remove in webpack 6
  1158. Object.defineProperty(Module.prototype, "warnings", {
  1159. /**
  1160. * @deprecated
  1161. * @returns {WebpackError[]} warnings
  1162. */
  1163. get: util.deprecate(
  1164. /**
  1165. * @this {Module}
  1166. * @returns {WebpackError[]} warnings
  1167. */
  1168. function warnings() {
  1169. if (this._warnings === undefined) {
  1170. this._warnings = [];
  1171. }
  1172. return this._warnings;
  1173. },
  1174. "Module.warnings was removed (use getWarnings instead)",
  1175. "DEP_WEBPACK_MODULE_WARNINGS"
  1176. )
  1177. });
  1178. // TODO remove in webpack 6
  1179. Object.defineProperty(Module.prototype, "used", {
  1180. /**
  1181. * @deprecated
  1182. * @returns {EXPECTED_ANY} throw an error
  1183. */
  1184. get() {
  1185. throw new Error(
  1186. "Module.used was refactored (use ModuleGraph.getUsedExports instead)"
  1187. );
  1188. },
  1189. /**
  1190. * @param {EXPECTED_ANY} value value
  1191. */
  1192. set(value) {
  1193. throw new Error(
  1194. "Module.used was refactored (use ModuleGraph.setUsedExports instead)"
  1195. );
  1196. }
  1197. });
  1198. module.exports = Module;