1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { RawSource } = require("webpack-sources");
|
9 | const Module = require("../Module");
|
10 | const RuntimeGlobals = require("../RuntimeGlobals");
|
11 | const makeSerializable = require("../util/makeSerializable");
|
12 | const FallbackDependency = require("./FallbackDependency");
|
13 | const RemoteToExternalDependency = require("./RemoteToExternalDependency");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const TYPES = new Set(["remote", "share-init"]);
|
30 | const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
31 |
|
32 | class RemoteModule extends Module {
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | constructor(request, externalRequests, internalRequest, shareScope) {
|
40 | super("remote-module");
|
41 | this.request = request;
|
42 | this.externalRequests = externalRequests;
|
43 | this.internalRequest = internalRequest;
|
44 | this.shareScope = shareScope;
|
45 | this._identifier = `remote (${shareScope}) ${this.externalRequests.join(
|
46 | " "
|
47 | )} ${this.internalRequest}`;
|
48 | }
|
49 |
|
50 | |
51 |
|
52 |
|
53 | identifier() {
|
54 | return this._identifier;
|
55 | }
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 | readableIdentifier(requestShortener) {
|
62 | return `remote ${this.request}`;
|
63 | }
|
64 |
|
65 | |
66 |
|
67 |
|
68 |
|
69 | libIdent(options) {
|
70 | return `${this.layer ? `(${this.layer})/` : ""}webpack/container/remote/${
|
71 | this.request
|
72 | }`;
|
73 | }
|
74 |
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 | needBuild(context, callback) {
|
81 | callback(null, !this.buildInfo);
|
82 | }
|
83 |
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | build(options, compilation, resolver, fs, callback) {
|
93 | this.buildMeta = {};
|
94 | this.buildInfo = {
|
95 | strict: true
|
96 | };
|
97 |
|
98 | this.clearDependenciesAndBlocks();
|
99 | if (this.externalRequests.length === 1) {
|
100 | this.addDependency(
|
101 | new RemoteToExternalDependency(this.externalRequests[0])
|
102 | );
|
103 | } else {
|
104 | this.addDependency(new FallbackDependency(this.externalRequests));
|
105 | }
|
106 |
|
107 | callback();
|
108 | }
|
109 |
|
110 | |
111 |
|
112 |
|
113 |
|
114 | size(type) {
|
115 | return 6;
|
116 | }
|
117 |
|
118 | |
119 |
|
120 |
|
121 | getSourceTypes() {
|
122 | return TYPES;
|
123 | }
|
124 |
|
125 | |
126 |
|
127 |
|
128 | nameForCondition() {
|
129 | return this.request;
|
130 | }
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 | codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
|
137 | const module = moduleGraph.getModule(this.dependencies[0]);
|
138 | const id = module && chunkGraph.getModuleId(module);
|
139 | const sources = new Map();
|
140 | sources.set("remote", new RawSource(""));
|
141 | const data = new Map();
|
142 | data.set("share-init", [
|
143 | {
|
144 | shareScope: this.shareScope,
|
145 | initStage: 20,
|
146 | init: id === undefined ? "" : `initExternal(${JSON.stringify(id)});`
|
147 | }
|
148 | ]);
|
149 | return { sources, data, runtimeRequirements: RUNTIME_REQUIREMENTS };
|
150 | }
|
151 |
|
152 | serialize(context) {
|
153 | const { write } = context;
|
154 | write(this.request);
|
155 | write(this.externalRequests);
|
156 | write(this.internalRequest);
|
157 | write(this.shareScope);
|
158 | super.serialize(context);
|
159 | }
|
160 |
|
161 | static deserialize(context) {
|
162 | const { read } = context;
|
163 | const obj = new RemoteModule(read(), read(), read(), read());
|
164 | obj.deserialize(context);
|
165 | return obj;
|
166 | }
|
167 | }
|
168 |
|
169 | makeSerializable(RemoteModule, "webpack/lib/container/RemoteModule");
|
170 |
|
171 | module.exports = RemoteModule;
|