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