1 |
|
2 |
|
3 |
|
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 RuntimeGlobals = require("./RuntimeGlobals");
|
13 | const { first } = require("./util/SetHelpers");
|
14 | const { compareChunksById } = require("./util/comparators");
|
15 | const makeSerializable = require("./util/makeSerializable");
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | const EMPTY_RESOLVE_OPTIONS = {};
|
104 |
|
105 | let debugId = 1000;
|
106 |
|
107 | const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
|
108 | const DEFAULT_TYPES_JS = new Set(["javascript"]);
|
109 |
|
110 | const deprecatedNeedRebuild = util.deprecate(
|
111 | (module, context) => {
|
112 | return module.needRebuild(
|
113 | context.fileSystemInfo.getDeprecatedFileTimestamps(),
|
114 | context.fileSystemInfo.getDeprecatedContextTimestamps()
|
115 | );
|
116 | },
|
117 | "Module.needRebuild is deprecated in favor of Module.needBuild",
|
118 | "DEP_WEBPACK_MODULE_NEED_REBUILD"
|
119 | );
|
120 |
|
121 |
|
122 |
|
123 | class Module extends DependenciesBlock {
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 | constructor(type, context = null, layer = null) {
|
130 | super();
|
131 |
|
132 |
|
133 | this.type = type;
|
134 |
|
135 | this.context = context;
|
136 |
|
137 | this.layer = layer;
|
138 |
|
139 | this.needId = true;
|
140 |
|
141 |
|
142 |
|
143 | this.debugId = debugId++;
|
144 |
|
145 |
|
146 |
|
147 | this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
148 |
|
149 | this.factoryMeta = undefined;
|
150 |
|
151 |
|
152 |
|
153 | this.useSourceMap = false;
|
154 |
|
155 | this.useSimpleSourceMap = false;
|
156 |
|
157 |
|
158 |
|
159 | this._warnings = undefined;
|
160 |
|
161 | this._errors = undefined;
|
162 |
|
163 | this.buildMeta = undefined;
|
164 |
|
165 | this.buildInfo = undefined;
|
166 |
|
167 | this.presentationalDependencies = undefined;
|
168 | }
|
169 |
|
170 |
|
171 |
|
172 | get id() {
|
173 | return ChunkGraph.getChunkGraphForModule(
|
174 | this,
|
175 | "Module.id",
|
176 | "DEP_WEBPACK_MODULE_ID"
|
177 | ).getModuleId(this);
|
178 | }
|
179 |
|
180 | set id(value) {
|
181 | if (value === "") {
|
182 | this.needId = false;
|
183 | return;
|
184 | }
|
185 | ChunkGraph.getChunkGraphForModule(
|
186 | this,
|
187 | "Module.id",
|
188 | "DEP_WEBPACK_MODULE_ID"
|
189 | ).setModuleId(this, value);
|
190 | }
|
191 |
|
192 | |
193 |
|
194 |
|
195 | get hash() {
|
196 | return ChunkGraph.getChunkGraphForModule(
|
197 | this,
|
198 | "Module.hash",
|
199 | "DEP_WEBPACK_MODULE_HASH"
|
200 | ).getModuleHash(this, undefined);
|
201 | }
|
202 |
|
203 | |
204 |
|
205 |
|
206 | get renderedHash() {
|
207 | return ChunkGraph.getChunkGraphForModule(
|
208 | this,
|
209 | "Module.renderedHash",
|
210 | "DEP_WEBPACK_MODULE_RENDERED_HASH"
|
211 | ).getRenderedModuleHash(this, undefined);
|
212 | }
|
213 |
|
214 | get profile() {
|
215 | return ModuleGraph.getModuleGraphForModule(
|
216 | this,
|
217 | "Module.profile",
|
218 | "DEP_WEBPACK_MODULE_PROFILE"
|
219 | ).getProfile(this);
|
220 | }
|
221 |
|
222 | set profile(value) {
|
223 | ModuleGraph.getModuleGraphForModule(
|
224 | this,
|
225 | "Module.profile",
|
226 | "DEP_WEBPACK_MODULE_PROFILE"
|
227 | ).setProfile(this, value);
|
228 | }
|
229 |
|
230 | get index() {
|
231 | return ModuleGraph.getModuleGraphForModule(
|
232 | this,
|
233 | "Module.index",
|
234 | "DEP_WEBPACK_MODULE_INDEX"
|
235 | ).getPreOrderIndex(this);
|
236 | }
|
237 |
|
238 | set index(value) {
|
239 | ModuleGraph.getModuleGraphForModule(
|
240 | this,
|
241 | "Module.index",
|
242 | "DEP_WEBPACK_MODULE_INDEX"
|
243 | ).setPreOrderIndex(this, value);
|
244 | }
|
245 |
|
246 | get index2() {
|
247 | return ModuleGraph.getModuleGraphForModule(
|
248 | this,
|
249 | "Module.index2",
|
250 | "DEP_WEBPACK_MODULE_INDEX2"
|
251 | ).getPostOrderIndex(this);
|
252 | }
|
253 |
|
254 | set index2(value) {
|
255 | ModuleGraph.getModuleGraphForModule(
|
256 | this,
|
257 | "Module.index2",
|
258 | "DEP_WEBPACK_MODULE_INDEX2"
|
259 | ).setPostOrderIndex(this, value);
|
260 | }
|
261 |
|
262 | get depth() {
|
263 | return ModuleGraph.getModuleGraphForModule(
|
264 | this,
|
265 | "Module.depth",
|
266 | "DEP_WEBPACK_MODULE_DEPTH"
|
267 | ).getDepth(this);
|
268 | }
|
269 |
|
270 | set depth(value) {
|
271 | ModuleGraph.getModuleGraphForModule(
|
272 | this,
|
273 | "Module.depth",
|
274 | "DEP_WEBPACK_MODULE_DEPTH"
|
275 | ).setDepth(this, value);
|
276 | }
|
277 |
|
278 | get issuer() {
|
279 | return ModuleGraph.getModuleGraphForModule(
|
280 | this,
|
281 | "Module.issuer",
|
282 | "DEP_WEBPACK_MODULE_ISSUER"
|
283 | ).getIssuer(this);
|
284 | }
|
285 |
|
286 | set issuer(value) {
|
287 | ModuleGraph.getModuleGraphForModule(
|
288 | this,
|
289 | "Module.issuer",
|
290 | "DEP_WEBPACK_MODULE_ISSUER"
|
291 | ).setIssuer(this, value);
|
292 | }
|
293 |
|
294 | get usedExports() {
|
295 | return ModuleGraph.getModuleGraphForModule(
|
296 | this,
|
297 | "Module.usedExports",
|
298 | "DEP_WEBPACK_MODULE_USED_EXPORTS"
|
299 | ).getUsedExports(this, undefined);
|
300 | }
|
301 |
|
302 | |
303 |
|
304 |
|
305 |
|
306 | get optimizationBailout() {
|
307 | return ModuleGraph.getModuleGraphForModule(
|
308 | this,
|
309 | "Module.optimizationBailout",
|
310 | "DEP_WEBPACK_MODULE_OPTIMIZATION_BAILOUT"
|
311 | ).getOptimizationBailout(this);
|
312 | }
|
313 |
|
314 | get optional() {
|
315 | return this.isOptional(
|
316 | ModuleGraph.getModuleGraphForModule(
|
317 | this,
|
318 | "Module.optional",
|
319 | "DEP_WEBPACK_MODULE_OPTIONAL"
|
320 | )
|
321 | );
|
322 | }
|
323 |
|
324 | addChunk(chunk) {
|
325 | const chunkGraph = ChunkGraph.getChunkGraphForModule(
|
326 | this,
|
327 | "Module.addChunk",
|
328 | "DEP_WEBPACK_MODULE_ADD_CHUNK"
|
329 | );
|
330 | if (chunkGraph.isModuleInChunk(this, chunk)) return false;
|
331 | chunkGraph.connectChunkAndModule(chunk, this);
|
332 | return true;
|
333 | }
|
334 |
|
335 | removeChunk(chunk) {
|
336 | return ChunkGraph.getChunkGraphForModule(
|
337 | this,
|
338 | "Module.removeChunk",
|
339 | "DEP_WEBPACK_MODULE_REMOVE_CHUNK"
|
340 | ).disconnectChunkAndModule(chunk, this);
|
341 | }
|
342 |
|
343 | isInChunk(chunk) {
|
344 | return ChunkGraph.getChunkGraphForModule(
|
345 | this,
|
346 | "Module.isInChunk",
|
347 | "DEP_WEBPACK_MODULE_IS_IN_CHUNK"
|
348 | ).isModuleInChunk(this, chunk);
|
349 | }
|
350 |
|
351 | isEntryModule() {
|
352 | return ChunkGraph.getChunkGraphForModule(
|
353 | this,
|
354 | "Module.isEntryModule",
|
355 | "DEP_WEBPACK_MODULE_IS_ENTRY_MODULE"
|
356 | ).isEntryModule(this);
|
357 | }
|
358 |
|
359 | getChunks() {
|
360 | return ChunkGraph.getChunkGraphForModule(
|
361 | this,
|
362 | "Module.getChunks",
|
363 | "DEP_WEBPACK_MODULE_GET_CHUNKS"
|
364 | ).getModuleChunks(this);
|
365 | }
|
366 |
|
367 | getNumberOfChunks() {
|
368 | return ChunkGraph.getChunkGraphForModule(
|
369 | this,
|
370 | "Module.getNumberOfChunks",
|
371 | "DEP_WEBPACK_MODULE_GET_NUMBER_OF_CHUNKS"
|
372 | ).getNumberOfModuleChunks(this);
|
373 | }
|
374 |
|
375 | get chunksIterable() {
|
376 | return ChunkGraph.getChunkGraphForModule(
|
377 | this,
|
378 | "Module.chunksIterable",
|
379 | "DEP_WEBPACK_MODULE_CHUNKS_ITERABLE"
|
380 | ).getOrderedModuleChunksIterable(this, compareChunksById);
|
381 | }
|
382 |
|
383 | |
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | isProvided(exportName) {
|
390 | return ModuleGraph.getModuleGraphForModule(
|
391 | this,
|
392 | "Module.usedExports",
|
393 | "DEP_WEBPACK_MODULE_USED_EXPORTS"
|
394 | ).isExportProvided(this, exportName);
|
395 | }
|
396 |
|
397 |
|
398 | |
399 |
|
400 |
|
401 |
|
402 | get exportsArgument() {
|
403 | return (this.buildInfo && this.buildInfo.exportsArgument) || "exports";
|
404 | }
|
405 |
|
406 | |
407 |
|
408 |
|
409 |
|
410 | get moduleArgument() {
|
411 | return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
|
412 | }
|
413 |
|
414 | |
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 | getExportsType(moduleGraph, strict) {
|
424 | switch (this.buildMeta && this.buildMeta.exportsType) {
|
425 | case "flagged":
|
426 | return strict ? "default-with-named" : "namespace";
|
427 | case "namespace":
|
428 | return "namespace";
|
429 | case "default":
|
430 | switch (this.buildMeta.defaultObject) {
|
431 | case "redirect":
|
432 | return "default-with-named";
|
433 | case "redirect-warn":
|
434 | return strict ? "default-only" : "default-with-named";
|
435 | default:
|
436 | return "default-only";
|
437 | }
|
438 | case "dynamic": {
|
439 | if (strict) return "default-with-named";
|
440 |
|
441 | const handleDefault = () => {
|
442 | switch (this.buildMeta.defaultObject) {
|
443 | case "redirect":
|
444 | case "redirect-warn":
|
445 | return "default-with-named";
|
446 | default:
|
447 | return "default-only";
|
448 | }
|
449 | };
|
450 | const exportInfo = moduleGraph.getReadOnlyExportInfo(
|
451 | this,
|
452 | "__esModule"
|
453 | );
|
454 | if (exportInfo.provided === false) {
|
455 | return handleDefault();
|
456 | }
|
457 | const target = exportInfo.getTarget(moduleGraph);
|
458 | if (
|
459 | !target ||
|
460 | !target.export ||
|
461 | target.export.length !== 1 ||
|
462 | target.export[0] !== "__esModule"
|
463 | ) {
|
464 | return "dynamic";
|
465 | }
|
466 | switch (
|
467 | target.module.buildMeta &&
|
468 | target.module.buildMeta.exportsType
|
469 | ) {
|
470 | case "flagged":
|
471 | case "namespace":
|
472 | return "namespace";
|
473 | case "default":
|
474 | return handleDefault();
|
475 | default:
|
476 | return "dynamic";
|
477 | }
|
478 | }
|
479 | default:
|
480 | return strict ? "default-with-named" : "dynamic";
|
481 | }
|
482 | }
|
483 |
|
484 | |
485 |
|
486 |
|
487 |
|
488 |
|
489 | addPresentationalDependency(presentationalDependency) {
|
490 | if (this.presentationalDependencies === undefined) {
|
491 | this.presentationalDependencies = [];
|
492 | }
|
493 | this.presentationalDependencies.push(presentationalDependency);
|
494 | }
|
495 |
|
496 | |
497 |
|
498 |
|
499 |
|
500 | clearDependenciesAndBlocks() {
|
501 | if (this.presentationalDependencies !== undefined) {
|
502 | this.presentationalDependencies.length = 0;
|
503 | }
|
504 | super.clearDependenciesAndBlocks();
|
505 | }
|
506 |
|
507 | |
508 |
|
509 |
|
510 |
|
511 | addWarning(warning) {
|
512 | if (this._warnings === undefined) {
|
513 | this._warnings = [];
|
514 | }
|
515 | this._warnings.push(warning);
|
516 | }
|
517 |
|
518 | |
519 |
|
520 |
|
521 | getWarnings() {
|
522 | return this._warnings;
|
523 | }
|
524 |
|
525 | |
526 |
|
527 |
|
528 | getNumberOfWarnings() {
|
529 | return this._warnings !== undefined ? this._warnings.length : 0;
|
530 | }
|
531 |
|
532 | |
533 |
|
534 |
|
535 |
|
536 | addError(error) {
|
537 | if (this._errors === undefined) {
|
538 | this._errors = [];
|
539 | }
|
540 | this._errors.push(error);
|
541 | }
|
542 |
|
543 | |
544 |
|
545 |
|
546 | getErrors() {
|
547 | return this._errors;
|
548 | }
|
549 |
|
550 | |
551 |
|
552 |
|
553 | getNumberOfErrors() {
|
554 | return this._errors !== undefined ? this._errors.length : 0;
|
555 | }
|
556 |
|
557 | |
558 |
|
559 |
|
560 |
|
561 | clearWarningsAndErrors() {
|
562 | if (this._warnings !== undefined) {
|
563 | this._warnings.length = 0;
|
564 | }
|
565 | if (this._errors !== undefined) {
|
566 | this._errors.length = 0;
|
567 | }
|
568 | }
|
569 |
|
570 | |
571 |
|
572 |
|
573 |
|
574 | isOptional(moduleGraph) {
|
575 | let hasConnections = false;
|
576 | for (const r of moduleGraph.getIncomingConnections(this)) {
|
577 | if (
|
578 | !r.dependency ||
|
579 | !r.dependency.optional ||
|
580 | !r.isTargetActive(undefined)
|
581 | ) {
|
582 | return false;
|
583 | }
|
584 | hasConnections = true;
|
585 | }
|
586 | return hasConnections;
|
587 | }
|
588 |
|
589 | |
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 | isAccessibleInChunk(chunkGraph, chunk, ignoreChunk) {
|
596 |
|
597 | for (const chunkGroup of chunk.groupsIterable) {
|
598 | if (!this.isAccessibleInChunkGroup(chunkGraph, chunkGroup)) return false;
|
599 | }
|
600 | return true;
|
601 | }
|
602 |
|
603 | |
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 | isAccessibleInChunkGroup(chunkGraph, chunkGroup, ignoreChunk) {
|
610 | const queue = new Set([chunkGroup]);
|
611 |
|
612 |
|
613 | queueFor: for (const cg of queue) {
|
614 |
|
615 |
|
616 | for (const chunk of cg.chunks) {
|
617 | if (chunk !== ignoreChunk && chunkGraph.isModuleInChunk(this, chunk))
|
618 | continue queueFor;
|
619 | }
|
620 |
|
621 | if (chunkGroup.isInitial()) return false;
|
622 |
|
623 | for (const parent of chunkGroup.parentsIterable) queue.add(parent);
|
624 | }
|
625 |
|
626 | return true;
|
627 | }
|
628 |
|
629 | |
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 | hasReasonForChunk(chunk, moduleGraph, chunkGraph) {
|
636 |
|
637 | for (const [
|
638 | fromModule,
|
639 | connections
|
640 | ] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
|
641 | if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
|
642 | for (const originChunk of chunkGraph.getModuleChunksIterable(
|
643 | fromModule
|
644 | )) {
|
645 |
|
646 | if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))
|
647 | return true;
|
648 | }
|
649 | }
|
650 | return false;
|
651 | }
|
652 |
|
653 | |
654 |
|
655 |
|
656 |
|
657 |
|
658 | hasReasons(moduleGraph, runtime) {
|
659 | for (const c of moduleGraph.getIncomingConnections(this)) {
|
660 | if (c.isTargetActive(runtime)) return true;
|
661 | }
|
662 | return false;
|
663 | }
|
664 |
|
665 | |
666 |
|
667 |
|
668 | toString() {
|
669 | return `Module[${this.debugId}: ${this.identifier()}]`;
|
670 | }
|
671 |
|
672 | |
673 |
|
674 |
|
675 |
|
676 |
|
677 | needBuild(context, callback) {
|
678 | callback(
|
679 | null,
|
680 | !this.buildMeta ||
|
681 | this.needRebuild === Module.prototype.needRebuild ||
|
682 | deprecatedNeedRebuild(this, context)
|
683 | );
|
684 | }
|
685 |
|
686 | |
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 | needRebuild(fileTimestamps, contextTimestamps) {
|
693 | return true;
|
694 | }
|
695 |
|
696 | |
697 |
|
698 |
|
699 |
|
700 |
|
701 | updateHash(
|
702 | hash,
|
703 | context = {
|
704 | chunkGraph: ChunkGraph.getChunkGraphForModule(
|
705 | this,
|
706 | "Module.updateHash",
|
707 | "DEP_WEBPACK_MODULE_UPDATE_HASH"
|
708 | ),
|
709 | runtime: undefined
|
710 | }
|
711 | ) {
|
712 | const { chunkGraph, runtime } = context;
|
713 | hash.update(chunkGraph.getModuleGraphHash(this, runtime));
|
714 | if (this.presentationalDependencies !== undefined) {
|
715 | for (const dep of this.presentationalDependencies) {
|
716 | dep.updateHash(hash, context);
|
717 | }
|
718 | }
|
719 | super.updateHash(hash, context);
|
720 | }
|
721 |
|
722 | |
723 |
|
724 |
|
725 | invalidateBuild() {
|
726 |
|
727 | }
|
728 |
|
729 |
|
730 | |
731 |
|
732 |
|
733 |
|
734 | identifier() {
|
735 | const AbstractMethodError = require("./AbstractMethodError");
|
736 | throw new AbstractMethodError();
|
737 | }
|
738 |
|
739 |
|
740 | |
741 |
|
742 |
|
743 |
|
744 |
|
745 | readableIdentifier(requestShortener) {
|
746 | const AbstractMethodError = require("./AbstractMethodError");
|
747 | throw new AbstractMethodError();
|
748 | }
|
749 |
|
750 |
|
751 | |
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 | build(options, compilation, resolver, fs, callback) {
|
761 | const AbstractMethodError = require("./AbstractMethodError");
|
762 | throw new AbstractMethodError();
|
763 | }
|
764 |
|
765 | |
766 |
|
767 |
|
768 |
|
769 | getSourceTypes() {
|
770 |
|
771 | if (this.source === Module.prototype.source) {
|
772 | return DEFAULT_TYPES_UNKNOWN;
|
773 | } else {
|
774 | return DEFAULT_TYPES_JS;
|
775 | }
|
776 | }
|
777 |
|
778 | |
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 | source(dependencyTemplates, runtimeTemplate, type = "javascript") {
|
787 | if (this.codeGeneration === Module.prototype.codeGeneration) {
|
788 | const AbstractMethodError = require("./AbstractMethodError");
|
789 | throw new AbstractMethodError();
|
790 | }
|
791 | const chunkGraph = ChunkGraph.getChunkGraphForModule(
|
792 | this,
|
793 | "Module.source() is deprecated. Use Compilation.codeGenerationResults.getSource(module, runtime, type) instead",
|
794 | "DEP_WEBPACK_MODULE_SOURCE"
|
795 | );
|
796 |
|
797 | const codeGenContext = {
|
798 | dependencyTemplates,
|
799 | runtimeTemplate,
|
800 | moduleGraph: chunkGraph.moduleGraph,
|
801 | chunkGraph,
|
802 | runtime: undefined
|
803 | };
|
804 | const sources = this.codeGeneration(codeGenContext).sources;
|
805 | return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
|
806 | }
|
807 |
|
808 |
|
809 | |
810 |
|
811 |
|
812 |
|
813 |
|
814 | size(type) {
|
815 | const AbstractMethodError = require("./AbstractMethodError");
|
816 | throw new AbstractMethodError();
|
817 | }
|
818 |
|
819 | |
820 |
|
821 |
|
822 |
|
823 | libIdent(options) {
|
824 | return null;
|
825 | }
|
826 |
|
827 | |
828 |
|
829 |
|
830 | nameForCondition() {
|
831 | return null;
|
832 | }
|
833 |
|
834 | |
835 |
|
836 |
|
837 |
|
838 | getConcatenationBailoutReason(context) {
|
839 | return `Module Concatenation is not implemented for ${this.constructor.name}`;
|
840 | }
|
841 |
|
842 | |
843 |
|
844 |
|
845 |
|
846 | getSideEffectsConnectionState(moduleGraph) {
|
847 | return true;
|
848 | }
|
849 |
|
850 | |
851 |
|
852 |
|
853 |
|
854 | codeGeneration(context) {
|
855 |
|
856 | const sources = new Map();
|
857 | for (const type of this.getSourceTypes()) {
|
858 | if (type !== "unknown") {
|
859 | sources.set(
|
860 | type,
|
861 | this.source(
|
862 | context.dependencyTemplates,
|
863 | context.runtimeTemplate,
|
864 | type
|
865 | )
|
866 | );
|
867 | }
|
868 | }
|
869 | return {
|
870 | sources,
|
871 | runtimeRequirements: new Set([
|
872 | RuntimeGlobals.module,
|
873 | RuntimeGlobals.exports,
|
874 | RuntimeGlobals.require
|
875 | ])
|
876 | };
|
877 | }
|
878 |
|
879 | |
880 |
|
881 |
|
882 |
|
883 |
|
884 | chunkCondition(chunk, compilation) {
|
885 | return true;
|
886 | }
|
887 |
|
888 | hasChunkCondition() {
|
889 | return this.chunkCondition !== Module.prototype.chunkCondition;
|
890 | }
|
891 |
|
892 | |
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 | updateCacheModule(module) {
|
900 | this.type = module.type;
|
901 | this.layer = module.layer;
|
902 | this.context = module.context;
|
903 | this.factoryMeta = module.factoryMeta;
|
904 | this.resolveOptions = module.resolveOptions;
|
905 | }
|
906 |
|
907 | |
908 |
|
909 |
|
910 |
|
911 |
|
912 | getUnsafeCacheData() {
|
913 | return {
|
914 | factoryMeta: this.factoryMeta,
|
915 | resolveOptions: this.resolveOptions
|
916 | };
|
917 | }
|
918 |
|
919 | |
920 |
|
921 |
|
922 |
|
923 |
|
924 | _restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
925 | this.factoryMeta = unsafeCacheData.factoryMeta;
|
926 | this.resolveOptions = unsafeCacheData.resolveOptions;
|
927 | }
|
928 |
|
929 | |
930 |
|
931 |
|
932 | cleanupForCache() {
|
933 | this.factoryMeta = undefined;
|
934 | this.resolveOptions = undefined;
|
935 | }
|
936 |
|
937 | |
938 |
|
939 |
|
940 | originalSource() {
|
941 | return null;
|
942 | }
|
943 |
|
944 | |
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 | addCacheDependencies(
|
951 | fileDependencies,
|
952 | contextDependencies,
|
953 | missingDependencies,
|
954 | buildDependencies
|
955 | ) {}
|
956 |
|
957 | serialize(context) {
|
958 | const { write } = context;
|
959 | write(this.type);
|
960 | write(this.layer);
|
961 | write(this.context);
|
962 | write(this.resolveOptions);
|
963 | write(this.factoryMeta);
|
964 | write(this.useSourceMap);
|
965 | write(this.useSimpleSourceMap);
|
966 | write(
|
967 | this._warnings !== undefined && this._warnings.length === 0
|
968 | ? undefined
|
969 | : this._warnings
|
970 | );
|
971 | write(
|
972 | this._errors !== undefined && this._errors.length === 0
|
973 | ? undefined
|
974 | : this._errors
|
975 | );
|
976 | write(this.buildMeta);
|
977 | write(this.buildInfo);
|
978 | write(this.presentationalDependencies);
|
979 | super.serialize(context);
|
980 | }
|
981 |
|
982 | deserialize(context) {
|
983 | const { read } = context;
|
984 | this.type = read();
|
985 | this.layer = read();
|
986 | this.context = read();
|
987 | this.resolveOptions = read();
|
988 | this.factoryMeta = read();
|
989 | this.useSourceMap = read();
|
990 | this.useSimpleSourceMap = read();
|
991 | this._warnings = read();
|
992 | this._errors = read();
|
993 | this.buildMeta = read();
|
994 | this.buildInfo = read();
|
995 | this.presentationalDependencies = read();
|
996 | super.deserialize(context);
|
997 | }
|
998 | }
|
999 |
|
1000 | makeSerializable(Module, "webpack/lib/Module");
|
1001 |
|
1002 |
|
1003 | Object.defineProperty(Module.prototype, "hasEqualsChunks", {
|
1004 | get() {
|
1005 | throw new Error(
|
1006 | "Module.hasEqualsChunks was renamed (use hasEqualChunks instead)"
|
1007 | );
|
1008 | }
|
1009 | });
|
1010 |
|
1011 |
|
1012 | Object.defineProperty(Module.prototype, "isUsed", {
|
1013 | get() {
|
1014 | throw new Error(
|
1015 | "Module.isUsed was renamed (use getUsedName, isExportUsed or isModuleUsed instead)"
|
1016 | );
|
1017 | }
|
1018 | });
|
1019 |
|
1020 |
|
1021 | Object.defineProperty(Module.prototype, "errors", {
|
1022 | get: util.deprecate(
|
1023 | /**
|
1024 | * @this {Module}
|
1025 | * @returns {WebpackError[]} array
|
1026 | */
|
1027 | function () {
|
1028 | if (this._errors === undefined) {
|
1029 | this._errors = [];
|
1030 | }
|
1031 | return this._errors;
|
1032 | },
|
1033 | "Module.errors was removed (use getErrors instead)",
|
1034 | "DEP_WEBPACK_MODULE_ERRORS"
|
1035 | )
|
1036 | });
|
1037 |
|
1038 |
|
1039 | Object.defineProperty(Module.prototype, "warnings", {
|
1040 | get: util.deprecate(
|
1041 | /**
|
1042 | * @this {Module}
|
1043 | * @returns {WebpackError[]} array
|
1044 | */
|
1045 | function () {
|
1046 | if (this._warnings === undefined) {
|
1047 | this._warnings = [];
|
1048 | }
|
1049 | return this._warnings;
|
1050 | },
|
1051 | "Module.warnings was removed (use getWarnings instead)",
|
1052 | "DEP_WEBPACK_MODULE_WARNINGS"
|
1053 | )
|
1054 | });
|
1055 |
|
1056 |
|
1057 | Object.defineProperty(Module.prototype, "used", {
|
1058 | get() {
|
1059 | throw new Error(
|
1060 | "Module.used was refactored (use ModuleGraph.getUsedExports instead)"
|
1061 | );
|
1062 | },
|
1063 | set(value) {
|
1064 | throw new Error(
|
1065 | "Module.used was refactored (use ModuleGraph.setUsedExports instead)"
|
1066 | );
|
1067 | }
|
1068 | });
|
1069 |
|
1070 | module.exports = Module;
|