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