@module-federation/dts-plugin 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Action-CzhPMw2i.js +153 -0
- package/dist/Broker-DRlzScTT.js +800 -0
- package/dist/CHANGELOG.md +15 -0
- package/dist/DtsWorker-Dtem3-FM.d.ts +166 -0
- package/dist/constant-BwEkyidO.d.ts +42 -0
- package/dist/consumeTypes-AD2ig87l.js +237 -0
- package/dist/core.d.ts +3 -68
- package/dist/core.js +26 -2443
- package/dist/dynamic-remote-type-hints-plugin.d.ts +622 -3
- package/dist/dynamic-remote-type-hints-plugin.js +65 -187
- package/dist/esm/Action-DNNg2YDh.mjs +47 -0
- package/dist/esm/Broker-BU4gToNr.mjs +736 -0
- package/dist/esm/consumeTypes-D51rVbSt.mjs +204 -0
- package/dist/esm/core.mjs +5 -0
- package/dist/esm/dynamic-remote-type-hints-plugin.mjs +73 -0
- package/dist/esm/expose-rpc-DMhY1i8A.mjs +1301 -0
- package/dist/esm/fork-dev-worker.mjs +103 -0
- package/dist/esm/fork-generate-dts.mjs +14 -0
- package/dist/esm/index.mjs +465 -0
- package/dist/esm/start-broker.mjs +22 -0
- package/dist/esm/utils-CkPvDGOy.mjs +13 -0
- package/dist/expose-rpc-BLAH20uj.js +1415 -0
- package/dist/fork-dev-worker.d.ts +10 -9
- package/dist/fork-dev-worker.js +100 -2932
- package/dist/fork-generate-dts.d.ts +4 -8
- package/dist/fork-generate-dts.js +11 -2103
- package/dist/iife/launch-web-client.iife.js +117 -0
- package/dist/index.d.ts +57 -46
- package/dist/index.js +449 -3043
- package/dist/package.json +26 -11
- package/dist/start-broker.d.ts +41 -39
- package/dist/start-broker.js +17 -952
- package/dist/utils-7KqCZHbb.js +19 -0
- package/package.json +31 -16
- package/dist/DTSManager-b15Gfat3.d.ts +0 -53
- package/dist/DTSManagerOptions-QVchWb0x.d.ts +0 -32
- package/dist/DtsWorker-BrHsGz8C.d.ts +0 -56
- package/dist/core.d.mts +0 -68
- package/dist/dynamic-remote-type-hints-plugin.d.mts +0 -5
- package/dist/esm/chunk-647HGGGS.js +0 -241
- package/dist/esm/chunk-G65LOFTY.js +0 -24
- package/dist/esm/chunk-LJTUMI5K.js +0 -282
- package/dist/esm/chunk-MV6M4VFH.js +0 -1642
- package/dist/esm/chunk-WWV5RWOP.js +0 -902
- package/dist/esm/core.js +0 -44
- package/dist/esm/dynamic-remote-type-hints-plugin.js +0 -73
- package/dist/esm/fork-dev-worker.js +0 -145
- package/dist/esm/fork-generate-dts.js +0 -27
- package/dist/esm/index.js +0 -646
- package/dist/esm/start-broker.js +0 -36
- package/dist/fork-dev-worker.d.mts +0 -15
- package/dist/fork-generate-dts.d.mts +0 -10
- package/dist/iife/launch-web-client.js +0 -152
- package/dist/index.d.mts +0 -56
- package/dist/start-broker.d.mts +0 -42
- package/dist/utils-C4sQemLR.d.ts +0 -15
|
@@ -1,1642 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
APIKind,
|
|
3
|
-
Broker,
|
|
4
|
-
LogKind,
|
|
5
|
-
fib,
|
|
6
|
-
fileLog,
|
|
7
|
-
getFreePort,
|
|
8
|
-
getIPV4,
|
|
9
|
-
getIdentifier,
|
|
10
|
-
logger
|
|
11
|
-
} from "./chunk-WWV5RWOP.js";
|
|
12
|
-
import {
|
|
13
|
-
AddPublisherAction,
|
|
14
|
-
AddSubscriberAction,
|
|
15
|
-
DEFAULT_TAR_NAME,
|
|
16
|
-
ExitPublisherAction,
|
|
17
|
-
ExitSubscriberAction,
|
|
18
|
-
MF_SERVER_IDENTIFIER,
|
|
19
|
-
NotifyWebClientAction,
|
|
20
|
-
UpdateKind,
|
|
21
|
-
UpdateMode,
|
|
22
|
-
UpdatePublisherAction,
|
|
23
|
-
__async,
|
|
24
|
-
__name,
|
|
25
|
-
__objRest,
|
|
26
|
-
__publicField,
|
|
27
|
-
__require,
|
|
28
|
-
__spreadProps,
|
|
29
|
-
__spreadValues
|
|
30
|
-
} from "./chunk-647HGGGS.js";
|
|
31
|
-
|
|
32
|
-
// src/server/DevServer.ts
|
|
33
|
-
import WebSocket from "isomorphic-ws";
|
|
34
|
-
|
|
35
|
-
// src/server/broker/createBroker.ts
|
|
36
|
-
import { fork } from "child_process";
|
|
37
|
-
import path from "path";
|
|
38
|
-
function createBroker() {
|
|
39
|
-
const startBrokerPath = path.resolve(__dirname, "./start-broker.js");
|
|
40
|
-
const sub = fork(startBrokerPath, [], {
|
|
41
|
-
detached: true,
|
|
42
|
-
stdio: "ignore",
|
|
43
|
-
env: process.env
|
|
44
|
-
});
|
|
45
|
-
sub.send("start");
|
|
46
|
-
sub.unref();
|
|
47
|
-
return sub;
|
|
48
|
-
}
|
|
49
|
-
__name(createBroker, "createBroker");
|
|
50
|
-
|
|
51
|
-
// src/server/DevServer.ts
|
|
52
|
-
var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
53
|
-
constructor(ctx) {
|
|
54
|
-
__publicField(this, "_remotes");
|
|
55
|
-
__publicField(this, "_ip");
|
|
56
|
-
__publicField(this, "_name");
|
|
57
|
-
__publicField(this, "_remoteTypeTarPath");
|
|
58
|
-
__publicField(this, "_publishWebSocket", null);
|
|
59
|
-
__publicField(this, "_subscriberWebsocketMap", {});
|
|
60
|
-
__publicField(this, "_reconnect", true);
|
|
61
|
-
__publicField(this, "_reconnectTimes", 0);
|
|
62
|
-
__publicField(this, "_isConnected", false);
|
|
63
|
-
__publicField(this, "_isReconnecting", false);
|
|
64
|
-
__publicField(this, "_updateCallback", /* @__PURE__ */ __name(() => Promise.resolve(void 0), "_updateCallback"));
|
|
65
|
-
const { name, remotes, remoteTypeTarPath, updateCallback } = ctx;
|
|
66
|
-
this._ip = getIPV4();
|
|
67
|
-
this._name = name;
|
|
68
|
-
this._remotes = remotes;
|
|
69
|
-
this._remoteTypeTarPath = remoteTypeTarPath;
|
|
70
|
-
this._updateCallback = updateCallback;
|
|
71
|
-
this._stopWhenSIGTERMOrSIGINT();
|
|
72
|
-
this._handleUnexpectedExit();
|
|
73
|
-
this._connectPublishToServer();
|
|
74
|
-
}
|
|
75
|
-
_connectPublishToServer() {
|
|
76
|
-
if (!this._reconnect) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
fileLog(`Publisher:${this._name} Trying to connect to ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}...`, MF_SERVER_IDENTIFIER, "info");
|
|
80
|
-
this._publishWebSocket = new WebSocket(`ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${Broker.WEB_SOCKET_CONNECT_MAGIC_ID}`);
|
|
81
|
-
this._publishWebSocket.on("open", () => {
|
|
82
|
-
var _a2;
|
|
83
|
-
fileLog(`Current pid: ${process.pid}, publisher:${this._name} connected to ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}, starting service...`, MF_SERVER_IDENTIFIER, "info");
|
|
84
|
-
this._isConnected = true;
|
|
85
|
-
const addPublisherAction = new AddPublisherAction({
|
|
86
|
-
name: this._name,
|
|
87
|
-
ip: this._ip,
|
|
88
|
-
remoteTypeTarPath: this._remoteTypeTarPath
|
|
89
|
-
});
|
|
90
|
-
(_a2 = this._publishWebSocket) == null ? void 0 : _a2.send(JSON.stringify(addPublisherAction));
|
|
91
|
-
this._connectSubscribers();
|
|
92
|
-
});
|
|
93
|
-
this._publishWebSocket.on("message", (message) => __async(this, null, function* () {
|
|
94
|
-
var _a2, _b;
|
|
95
|
-
try {
|
|
96
|
-
const parsedMessage = JSON.parse(message.toString());
|
|
97
|
-
if (parsedMessage.type === "Log") {
|
|
98
|
-
if (parsedMessage.kind === LogKind.BrokerExitLog) {
|
|
99
|
-
fileLog(`Receive broker exit signal, ${this._name} service will exit...`, MF_SERVER_IDENTIFIER, "warn");
|
|
100
|
-
this._exit();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (parsedMessage.type === "API") {
|
|
104
|
-
if (parsedMessage.kind === APIKind.FETCH_TYPES) {
|
|
105
|
-
const { payload: { remoteInfo } } = parsedMessage;
|
|
106
|
-
fileLog(`${this._name} Receive broker FETCH_TYPES, payload as follows: ${JSON.stringify(remoteInfo, null, 2)}.`, MF_SERVER_IDENTIFIER, "info");
|
|
107
|
-
yield this.fetchDynamicRemoteTypes({
|
|
108
|
-
remoteInfo
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} catch (err) {
|
|
113
|
-
console.error(err);
|
|
114
|
-
const exitPublisher = new ExitPublisherAction({
|
|
115
|
-
name: this._name,
|
|
116
|
-
ip: this._ip
|
|
117
|
-
});
|
|
118
|
-
const exitSubscriber = new ExitSubscriberAction({
|
|
119
|
-
name: this._name,
|
|
120
|
-
ip: this._ip,
|
|
121
|
-
publishers: this._remotes.map((remote) => ({
|
|
122
|
-
name: remote.name,
|
|
123
|
-
ip: remote.ip
|
|
124
|
-
}))
|
|
125
|
-
});
|
|
126
|
-
(_a2 = this._publishWebSocket) == null ? void 0 : _a2.send(JSON.stringify(exitPublisher));
|
|
127
|
-
(_b = this._publishWebSocket) == null ? void 0 : _b.send(JSON.stringify(exitSubscriber));
|
|
128
|
-
fileLog("Parse messages error, ModuleFederationDevServer will exit...", MF_SERVER_IDENTIFIER, "fatal");
|
|
129
|
-
this._exit();
|
|
130
|
-
}
|
|
131
|
-
}));
|
|
132
|
-
this._publishWebSocket.on("close", (code) => {
|
|
133
|
-
fileLog(`Connection closed with code ${code}.`, MF_SERVER_IDENTIFIER, "warn");
|
|
134
|
-
this._publishWebSocket && this._publishWebSocket.close();
|
|
135
|
-
this._publishWebSocket = null;
|
|
136
|
-
if (!this._reconnect) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const reconnectTime = fib(++this._reconnectTimes);
|
|
140
|
-
fileLog(`start reconnecting to server after ${reconnectTime}s.`, MF_SERVER_IDENTIFIER, "info");
|
|
141
|
-
setTimeout(() => this._connectPublishToServer(), reconnectTime * 1e3);
|
|
142
|
-
});
|
|
143
|
-
this._publishWebSocket.on("error", this._tryCreateBackgroundBroker.bind(this));
|
|
144
|
-
}
|
|
145
|
-
// Associate the remotes(Subscriber) to the Broker
|
|
146
|
-
_connectSubscriberToServer(remote) {
|
|
147
|
-
const { name, ip } = remote;
|
|
148
|
-
fileLog(`remote module:${name} trying to connect to ws://${ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}...`, MF_SERVER_IDENTIFIER, "info");
|
|
149
|
-
const identifier = getIdentifier({
|
|
150
|
-
name,
|
|
151
|
-
ip
|
|
152
|
-
});
|
|
153
|
-
this._subscriberWebsocketMap[identifier] = new WebSocket(`ws://${ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${Broker.WEB_SOCKET_CONNECT_MAGIC_ID}`);
|
|
154
|
-
this._subscriberWebsocketMap[identifier].on("open", () => {
|
|
155
|
-
fileLog(`Current pid: ${process.pid} remote module: ${name} connected to ws://${ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}, starting service...`, MF_SERVER_IDENTIFIER, "info");
|
|
156
|
-
const addSubscriber = new AddSubscriberAction({
|
|
157
|
-
name: this._name,
|
|
158
|
-
ip: this._ip,
|
|
159
|
-
publishers: [
|
|
160
|
-
{
|
|
161
|
-
name,
|
|
162
|
-
ip
|
|
163
|
-
}
|
|
164
|
-
]
|
|
165
|
-
});
|
|
166
|
-
this._subscriberWebsocketMap[identifier].send(JSON.stringify(addSubscriber));
|
|
167
|
-
});
|
|
168
|
-
this._subscriberWebsocketMap[identifier].on("message", (message) => __async(this, null, function* () {
|
|
169
|
-
try {
|
|
170
|
-
const parsedMessage = JSON.parse(message.toString());
|
|
171
|
-
if (parsedMessage.type === "Log") {
|
|
172
|
-
if (parsedMessage.kind === LogKind.BrokerExitLog) {
|
|
173
|
-
fileLog(`${identifier}'s Server exit, thus ${identifier} will no longer has reload ability.`, MF_SERVER_IDENTIFIER, "warn");
|
|
174
|
-
this._exit();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (parsedMessage.type === "API") {
|
|
178
|
-
if (parsedMessage.kind === APIKind.UPDATE_SUBSCRIBER) {
|
|
179
|
-
const { payload: { updateKind, updateSourcePaths, name: subscribeName, remoteTypeTarPath, updateMode } } = parsedMessage;
|
|
180
|
-
yield this._updateSubscriber({
|
|
181
|
-
remoteTypeTarPath,
|
|
182
|
-
name: subscribeName,
|
|
183
|
-
updateKind,
|
|
184
|
-
updateMode,
|
|
185
|
-
updateSourcePaths
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
} catch (err) {
|
|
190
|
-
console.error(err);
|
|
191
|
-
const exitSubscriber = new ExitSubscriberAction({
|
|
192
|
-
name: this._name,
|
|
193
|
-
ip: this._ip,
|
|
194
|
-
publishers: [
|
|
195
|
-
{
|
|
196
|
-
name,
|
|
197
|
-
ip
|
|
198
|
-
}
|
|
199
|
-
]
|
|
200
|
-
});
|
|
201
|
-
this._subscriberWebsocketMap[identifier].send(JSON.stringify(exitSubscriber));
|
|
202
|
-
fileLog(`${identifier} exit,
|
|
203
|
-
error: ${err instanceof Error ? err.toString() : JSON.stringify(err)}
|
|
204
|
-
`, MF_SERVER_IDENTIFIER, "warn");
|
|
205
|
-
}
|
|
206
|
-
}));
|
|
207
|
-
this._subscriberWebsocketMap[identifier].on("close", (code) => {
|
|
208
|
-
var _a2;
|
|
209
|
-
fileLog(`Connection closed with code ${code}.`, MF_SERVER_IDENTIFIER, "warn");
|
|
210
|
-
(_a2 = this._subscriberWebsocketMap[identifier]) == null ? void 0 : _a2.close();
|
|
211
|
-
delete this._subscriberWebsocketMap[identifier];
|
|
212
|
-
});
|
|
213
|
-
this._subscriberWebsocketMap[identifier].on("error", (err) => {
|
|
214
|
-
var _a2;
|
|
215
|
-
if ("code" in err && err.code === "ETIMEDOUT") {
|
|
216
|
-
fileLog(`Can not connect ${JSON.stringify(remote)}, please make sure this remote is started locally.`, MF_SERVER_IDENTIFIER, "warn");
|
|
217
|
-
} else {
|
|
218
|
-
console.error(err);
|
|
219
|
-
}
|
|
220
|
-
(_a2 = this._subscriberWebsocketMap[identifier]) == null ? void 0 : _a2.close();
|
|
221
|
-
delete this._subscriberWebsocketMap[identifier];
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
_connectSubscribers() {
|
|
225
|
-
this._remotes.forEach((remote) => {
|
|
226
|
-
this._connectSubscriberToServer(remote);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
// app1 consumes provider1. And the function will be triggered when provider1 code change.
|
|
230
|
-
_updateSubscriber(options) {
|
|
231
|
-
return __async(this, null, function* () {
|
|
232
|
-
var _a2;
|
|
233
|
-
const { updateMode, updateKind, updateSourcePaths, name, remoteTypeTarPath, remoteInfo } = options;
|
|
234
|
-
fileLog(
|
|
235
|
-
// eslint-disable-next-line max-len
|
|
236
|
-
`[_updateSubscriber] run, options: ${JSON.stringify(options, null, 2)}`,
|
|
237
|
-
MF_SERVER_IDENTIFIER,
|
|
238
|
-
"warn"
|
|
239
|
-
);
|
|
240
|
-
if (updateMode === UpdateMode.PASSIVE && updateSourcePaths.includes(this._name)) {
|
|
241
|
-
fileLog(
|
|
242
|
-
// eslint-disable-next-line max-len
|
|
243
|
-
`[_updateSubscriber] run, updateSourcePaths:${updateSourcePaths} includes ${this._name}, update ignore!`,
|
|
244
|
-
MF_SERVER_IDENTIFIER,
|
|
245
|
-
"warn"
|
|
246
|
-
);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
if (updateSourcePaths.slice(-1)[0] === this._name) {
|
|
250
|
-
fileLog(`[_updateSubscriber] run, updateSourcePaths:${updateSourcePaths} ends is ${this._name}, update ignore!`, MF_SERVER_IDENTIFIER, "warn");
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
fileLog(
|
|
254
|
-
// eslint-disable-next-line max-len
|
|
255
|
-
`[_updateSubscriber] run, updateSourcePaths:${updateSourcePaths}, current module:${this._name}, update start...`,
|
|
256
|
-
MF_SERVER_IDENTIFIER,
|
|
257
|
-
"info"
|
|
258
|
-
);
|
|
259
|
-
yield this._updateCallback({
|
|
260
|
-
name,
|
|
261
|
-
updateMode,
|
|
262
|
-
updateKind,
|
|
263
|
-
updateSourcePaths,
|
|
264
|
-
remoteTypeTarPath,
|
|
265
|
-
remoteInfo
|
|
266
|
-
});
|
|
267
|
-
const newUpdateSourcePaths = updateSourcePaths.concat(this._name);
|
|
268
|
-
const updatePublisher = new UpdatePublisherAction({
|
|
269
|
-
name: this._name,
|
|
270
|
-
ip: this._ip,
|
|
271
|
-
updateMode: UpdateMode.PASSIVE,
|
|
272
|
-
updateKind,
|
|
273
|
-
updateSourcePaths: newUpdateSourcePaths,
|
|
274
|
-
remoteTypeTarPath: this._remoteTypeTarPath
|
|
275
|
-
});
|
|
276
|
-
fileLog(
|
|
277
|
-
// eslint-disable-next-line max-len
|
|
278
|
-
`[_updateSubscriber] run, updateSourcePaths:${newUpdateSourcePaths}, update publisher ${this._name} start...`,
|
|
279
|
-
MF_SERVER_IDENTIFIER,
|
|
280
|
-
"info"
|
|
281
|
-
);
|
|
282
|
-
(_a2 = this._publishWebSocket) == null ? void 0 : _a2.send(JSON.stringify(updatePublisher));
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
_tryCreateBackgroundBroker(err) {
|
|
286
|
-
if (!(((err == null ? void 0 : err.code) === "ECONNREFUSED" || (err == null ? void 0 : err.code) === "ETIMEDOUT") && err.port === Broker.DEFAULT_WEB_SOCKET_PORT)) {
|
|
287
|
-
fileLog(`websocket error: ${err.stack}`, MF_SERVER_IDENTIFIER, "fatal");
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
fileLog(`Failed to connect to ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}...`, MF_SERVER_IDENTIFIER, "fatal");
|
|
291
|
-
this._isReconnecting = true;
|
|
292
|
-
setTimeout(() => {
|
|
293
|
-
this._isReconnecting = false;
|
|
294
|
-
if (this._reconnect === false) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
fileLog("Creating new background broker...", MF_SERVER_IDENTIFIER, "warn");
|
|
298
|
-
const broker = createBroker();
|
|
299
|
-
broker.on("message", (message) => {
|
|
300
|
-
if (message === "ready") {
|
|
301
|
-
fileLog("background broker started.", MF_SERVER_IDENTIFIER, "info");
|
|
302
|
-
this._reconnectTimes = 1;
|
|
303
|
-
if (process.send) {
|
|
304
|
-
process.send("ready");
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}, Math.ceil(100 * Math.random()));
|
|
309
|
-
}
|
|
310
|
-
_stopWhenSIGTERMOrSIGINT() {
|
|
311
|
-
process.on("SIGTERM", () => {
|
|
312
|
-
fileLog(`Process(${process.pid}) SIGTERM, ModuleFederationDevServer will exit...`, MF_SERVER_IDENTIFIER, "warn");
|
|
313
|
-
this._exit();
|
|
314
|
-
});
|
|
315
|
-
process.on("SIGINT", () => {
|
|
316
|
-
fileLog(`Process(${process.pid}) SIGINT, ModuleFederationDevServer will exit...`, MF_SERVER_IDENTIFIER, "warn");
|
|
317
|
-
this._exit();
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
_handleUnexpectedExit() {
|
|
321
|
-
process.on("unhandledRejection", (error) => {
|
|
322
|
-
if (this._isReconnecting) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
console.error("Unhandled Rejection Error: ", error);
|
|
326
|
-
fileLog(`Process(${process.pid}) unhandledRejection, garfishModuleServer will exit...`, MF_SERVER_IDENTIFIER, "error");
|
|
327
|
-
this._exit();
|
|
328
|
-
});
|
|
329
|
-
process.on("uncaughtException", (error) => {
|
|
330
|
-
if (this._isReconnecting) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
console.error("Unhandled Exception Error: ", error);
|
|
334
|
-
fileLog(`Process(${process.pid}) uncaughtException, garfishModuleServer will exit...`, MF_SERVER_IDENTIFIER, "error");
|
|
335
|
-
this._exit();
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
_exit() {
|
|
339
|
-
this._reconnect = false;
|
|
340
|
-
if (this._publishWebSocket) {
|
|
341
|
-
const exitPublisher = new ExitPublisherAction({
|
|
342
|
-
name: this._name,
|
|
343
|
-
ip: this._ip
|
|
344
|
-
});
|
|
345
|
-
this._publishWebSocket.send(JSON.stringify(exitPublisher));
|
|
346
|
-
this._publishWebSocket.on("message", (message) => {
|
|
347
|
-
const parsedMessage = JSON.parse(message.toString());
|
|
348
|
-
fileLog(`[${parsedMessage.kind}]: ${JSON.stringify(parsedMessage)}`, MF_SERVER_IDENTIFIER, "info");
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
if (this._publishWebSocket) {
|
|
352
|
-
this._publishWebSocket.close();
|
|
353
|
-
this._publishWebSocket = null;
|
|
354
|
-
}
|
|
355
|
-
process.exit(0);
|
|
356
|
-
}
|
|
357
|
-
exit() {
|
|
358
|
-
this._exit();
|
|
359
|
-
}
|
|
360
|
-
update(options) {
|
|
361
|
-
if (!this._publishWebSocket || !this._isConnected) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
const { updateKind, updateMode, updateSourcePaths, clientName } = options;
|
|
365
|
-
fileLog(`update run, ${this._name} module update, updateKind: ${updateKind}, updateMode: ${updateMode}, updateSourcePaths: ${updateSourcePaths}`, MF_SERVER_IDENTIFIER, "info");
|
|
366
|
-
if (updateKind === UpdateKind.RELOAD_PAGE) {
|
|
367
|
-
const notifyWebClient = new NotifyWebClientAction({
|
|
368
|
-
name: clientName || this._name,
|
|
369
|
-
updateMode
|
|
370
|
-
});
|
|
371
|
-
this._publishWebSocket.send(JSON.stringify(notifyWebClient));
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
const updatePublisher = new UpdatePublisherAction({
|
|
375
|
-
name: this._name,
|
|
376
|
-
ip: this._ip,
|
|
377
|
-
updateMode,
|
|
378
|
-
updateKind,
|
|
379
|
-
updateSourcePaths: [
|
|
380
|
-
this._name
|
|
381
|
-
],
|
|
382
|
-
remoteTypeTarPath: this._remoteTypeTarPath
|
|
383
|
-
});
|
|
384
|
-
this._publishWebSocket.send(JSON.stringify(updatePublisher));
|
|
385
|
-
}
|
|
386
|
-
fetchDynamicRemoteTypes(options) {
|
|
387
|
-
return __async(this, null, function* () {
|
|
388
|
-
const { remoteInfo, once } = options;
|
|
389
|
-
const updateMode = UpdateMode.PASSIVE;
|
|
390
|
-
const updateKind = UpdateKind.UPDATE_TYPE;
|
|
391
|
-
fileLog(`fetchDynamicRemoteTypes: remoteInfo: ${JSON.stringify(remoteInfo)}`, MF_SERVER_IDENTIFIER, "info");
|
|
392
|
-
yield this._updateCallback({
|
|
393
|
-
name: this._name,
|
|
394
|
-
updateMode,
|
|
395
|
-
updateKind,
|
|
396
|
-
updateSourcePaths: [],
|
|
397
|
-
remoteTypeTarPath: "",
|
|
398
|
-
remoteInfo,
|
|
399
|
-
once
|
|
400
|
-
});
|
|
401
|
-
const updatePublisher = new UpdatePublisherAction({
|
|
402
|
-
name: this._name,
|
|
403
|
-
ip: this._ip,
|
|
404
|
-
updateMode,
|
|
405
|
-
updateKind,
|
|
406
|
-
updateSourcePaths: [
|
|
407
|
-
this._name
|
|
408
|
-
],
|
|
409
|
-
remoteTypeTarPath: this._remoteTypeTarPath
|
|
410
|
-
});
|
|
411
|
-
this._publishWebSocket.send(JSON.stringify(updatePublisher));
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
__name(_ModuleFederationDevServer, "ModuleFederationDevServer");
|
|
416
|
-
var ModuleFederationDevServer = _ModuleFederationDevServer;
|
|
417
|
-
|
|
418
|
-
// src/server/createKoaServer.ts
|
|
419
|
-
import fs from "fs-extra";
|
|
420
|
-
import Koa from "koa";
|
|
421
|
-
function createKoaServer(options) {
|
|
422
|
-
return __async(this, null, function* () {
|
|
423
|
-
const { typeTarPath } = options;
|
|
424
|
-
const freeport = yield getFreePort();
|
|
425
|
-
const app = new Koa();
|
|
426
|
-
app.use((ctx, next) => __async(this, null, function* () {
|
|
427
|
-
if (ctx.path === `/${DEFAULT_TAR_NAME}`) {
|
|
428
|
-
ctx.status = 200;
|
|
429
|
-
ctx.body = fs.createReadStream(typeTarPath);
|
|
430
|
-
ctx.response.type = "application/x-gzip";
|
|
431
|
-
} else {
|
|
432
|
-
yield next();
|
|
433
|
-
}
|
|
434
|
-
}));
|
|
435
|
-
app.listen(freeport);
|
|
436
|
-
return {
|
|
437
|
-
server: app,
|
|
438
|
-
serverAddress: `http://${getIPV4()}:${freeport}`
|
|
439
|
-
};
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
__name(createKoaServer, "createKoaServer");
|
|
443
|
-
|
|
444
|
-
// src/core/lib/typeScriptCompiler.ts
|
|
445
|
-
import { ensureDirSync, writeFileSync, existsSync } from "fs-extra";
|
|
446
|
-
import crypto from "crypto";
|
|
447
|
-
import { stat, readdir, writeFile, rm, readFile } from "fs/promises";
|
|
448
|
-
import { dirname, join, normalize, relative, resolve, sep, extname, isAbsolute } from "path";
|
|
449
|
-
import { getShortErrorMsg, TYPE_001, typeDescMap } from "@module-federation/error-codes";
|
|
450
|
-
import { ThirdPartyExtractor } from "@module-federation/third-party-dts-extractor";
|
|
451
|
-
import { execFile } from "child_process";
|
|
452
|
-
import util from "util";
|
|
453
|
-
import { TEMP_DIR } from "@module-federation/sdk";
|
|
454
|
-
var STARTS_WITH_SLASH = /^\//;
|
|
455
|
-
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
456
|
-
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
457
|
-
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
458
|
-
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => join(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
459
|
-
function writeTempTsConfig(tsConfig, context, name, cwd) {
|
|
460
|
-
const createHash = /* @__PURE__ */ __name((contents) => {
|
|
461
|
-
return crypto.createHash("md5").update(contents).digest("hex");
|
|
462
|
-
}, "createHash");
|
|
463
|
-
const hash = createHash(`${JSON.stringify(tsConfig)}${name}${Date.now()}`);
|
|
464
|
-
const tempTsConfigJsonPath = resolve(cwd != null ? cwd : context, "node_modules", TEMP_DIR, `tsconfig.${hash}.json`);
|
|
465
|
-
ensureDirSync(dirname(tempTsConfigJsonPath));
|
|
466
|
-
writeFileSync(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
467
|
-
return tempTsConfigJsonPath;
|
|
468
|
-
}
|
|
469
|
-
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
470
|
-
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
471
|
-
const vueExt = ".vue";
|
|
472
|
-
const ext = extname(f);
|
|
473
|
-
if (ext === vueExt) {
|
|
474
|
-
return f;
|
|
475
|
-
}
|
|
476
|
-
const regexPattern = new RegExp(`\\${ext}$`);
|
|
477
|
-
return f.replace(regexPattern, "");
|
|
478
|
-
}, "removeExt");
|
|
479
|
-
function getExposeKey(options) {
|
|
480
|
-
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
481
|
-
const relativeFilePath = relative(outDir, filePath.replace(new RegExp(`\\.d.ts$`), ""));
|
|
482
|
-
return mapExposeToEntry[relativeFilePath];
|
|
483
|
-
}
|
|
484
|
-
__name(getExposeKey, "getExposeKey");
|
|
485
|
-
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
486
|
-
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
487
|
-
if (!existsSync(filePath)) {
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
const stats = yield stat(filePath);
|
|
491
|
-
if (stats.isDirectory()) {
|
|
492
|
-
const files = yield readdir(filePath);
|
|
493
|
-
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
494
|
-
filePath: join(filePath, file)
|
|
495
|
-
}))));
|
|
496
|
-
} else if (filePath.endsWith(".d.ts")) {
|
|
497
|
-
const exposeKey = getExposeKey({
|
|
498
|
-
filePath,
|
|
499
|
-
rootDir,
|
|
500
|
-
outDir,
|
|
501
|
-
mapExposeToEntry
|
|
502
|
-
});
|
|
503
|
-
if (exposeKey) {
|
|
504
|
-
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
505
|
-
const mfeTypeEntry = join(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
506
|
-
const mfeTypeEntryDirectory = dirname(mfeTypeEntry);
|
|
507
|
-
const relativePathToOutput = relative(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(sep).join("/");
|
|
508
|
-
ensureDirSync(mfeTypeEntryDirectory);
|
|
509
|
-
yield writeFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
510
|
-
export { default } from './${relativePathToOutput}';`);
|
|
511
|
-
}
|
|
512
|
-
const content = yield readFile(filePath, "utf8");
|
|
513
|
-
cb(content);
|
|
514
|
-
}
|
|
515
|
-
}), "processTypesFile");
|
|
516
|
-
var getPMFromUserAgent = /* @__PURE__ */ __name(() => {
|
|
517
|
-
const userAgent = process.env["npm_config_user_agent"];
|
|
518
|
-
if (userAgent == null) {
|
|
519
|
-
return "null";
|
|
520
|
-
}
|
|
521
|
-
const name = userAgent.split("/")[0];
|
|
522
|
-
return name;
|
|
523
|
-
}, "getPMFromUserAgent");
|
|
524
|
-
var resolvePackageManagerExecutable = /* @__PURE__ */ __name(() => {
|
|
525
|
-
const pm = getPMFromUserAgent();
|
|
526
|
-
switch (pm) {
|
|
527
|
-
case "yarn":
|
|
528
|
-
return "yarn";
|
|
529
|
-
case "npm":
|
|
530
|
-
case "pnpm":
|
|
531
|
-
default:
|
|
532
|
-
return "npx";
|
|
533
|
-
}
|
|
534
|
-
}, "resolvePackageManagerExecutable");
|
|
535
|
-
var splitCommandArgs = /* @__PURE__ */ __name((value) => {
|
|
536
|
-
const args = [];
|
|
537
|
-
let current = "";
|
|
538
|
-
let quote = null;
|
|
539
|
-
let escaped = false;
|
|
540
|
-
for (const char of value) {
|
|
541
|
-
if (escaped) {
|
|
542
|
-
current += char;
|
|
543
|
-
escaped = false;
|
|
544
|
-
continue;
|
|
545
|
-
}
|
|
546
|
-
if (char === "\\") {
|
|
547
|
-
escaped = true;
|
|
548
|
-
continue;
|
|
549
|
-
}
|
|
550
|
-
if (quote) {
|
|
551
|
-
if (char === quote) {
|
|
552
|
-
quote = null;
|
|
553
|
-
} else {
|
|
554
|
-
current += char;
|
|
555
|
-
}
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
if (char === '"' || char === "'") {
|
|
559
|
-
quote = char;
|
|
560
|
-
continue;
|
|
561
|
-
}
|
|
562
|
-
if (char.trim() === "") {
|
|
563
|
-
if (current) {
|
|
564
|
-
args.push(current);
|
|
565
|
-
current = "";
|
|
566
|
-
}
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
current += char;
|
|
570
|
-
}
|
|
571
|
-
if (current) {
|
|
572
|
-
args.push(current);
|
|
573
|
-
}
|
|
574
|
-
return args;
|
|
575
|
-
}, "splitCommandArgs");
|
|
576
|
-
var formatCommandForDisplay = /* @__PURE__ */ __name((executable, args) => {
|
|
577
|
-
const formatArg = /* @__PURE__ */ __name((arg) => {
|
|
578
|
-
if (/[\s'"]/.test(arg)) {
|
|
579
|
-
return JSON.stringify(arg);
|
|
580
|
-
}
|
|
581
|
-
return arg;
|
|
582
|
-
}, "formatArg");
|
|
583
|
-
return [
|
|
584
|
-
executable,
|
|
585
|
-
...args
|
|
586
|
-
].map(formatArg).join(" ");
|
|
587
|
-
}, "formatCommandForDisplay");
|
|
588
|
-
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
589
|
-
var _a2, _b, _c, _d;
|
|
590
|
-
if (!Object.keys(mapComponentsToExpose).length) {
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
const { compilerOptions } = tsConfig;
|
|
594
|
-
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf", typeof remoteOptions.moduleFederationConfig.dts !== "boolean" ? (_b = (_a2 = remoteOptions.moduleFederationConfig.dts) == null ? void 0 : _a2.cwd) != null ? _b : void 0 : void 0);
|
|
595
|
-
logger.debug(`tempTsConfigJsonPath: ${tempTsConfigJsonPath}`);
|
|
596
|
-
try {
|
|
597
|
-
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
598
|
-
const thirdPartyExtractor = new ThirdPartyExtractor({
|
|
599
|
-
destDir: resolve(mfTypePath, "node_modules"),
|
|
600
|
-
context: remoteOptions.context,
|
|
601
|
-
exclude: typeof remoteOptions.extractThirdParty === "object" ? remoteOptions.extractThirdParty.exclude : void 0
|
|
602
|
-
});
|
|
603
|
-
const execPromise = util.promisify(execFile);
|
|
604
|
-
const pmExecutable = resolvePackageManagerExecutable();
|
|
605
|
-
const compilerArgs = splitCommandArgs(remoteOptions.compilerInstance);
|
|
606
|
-
const resolvedCompilerArgs = compilerArgs.length > 0 ? compilerArgs : [
|
|
607
|
-
remoteOptions.compilerInstance
|
|
608
|
-
];
|
|
609
|
-
const cmdArgs = [
|
|
610
|
-
...resolvedCompilerArgs,
|
|
611
|
-
"--project",
|
|
612
|
-
tempTsConfigJsonPath
|
|
613
|
-
];
|
|
614
|
-
const cmd = formatCommandForDisplay(pmExecutable, cmdArgs);
|
|
615
|
-
try {
|
|
616
|
-
yield execPromise(pmExecutable, cmdArgs, {
|
|
617
|
-
cwd: typeof remoteOptions.moduleFederationConfig.dts !== "boolean" ? (_d = (_c = remoteOptions.moduleFederationConfig.dts) == null ? void 0 : _c.cwd) != null ? _d : void 0 : void 0,
|
|
618
|
-
shell: process.platform === "win32"
|
|
619
|
-
});
|
|
620
|
-
} catch (err) {
|
|
621
|
-
if (compilerOptions.tsBuildInfoFile) {
|
|
622
|
-
try {
|
|
623
|
-
yield rm(compilerOptions.tsBuildInfoFile);
|
|
624
|
-
} catch (e) {
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
throw new Error(getShortErrorMsg(TYPE_001, typeDescMap, {
|
|
628
|
-
cmd
|
|
629
|
-
}));
|
|
630
|
-
}
|
|
631
|
-
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
632
|
-
const normalizedFileName = normalize(filename);
|
|
633
|
-
let relativeFileName = "";
|
|
634
|
-
if (isAbsolute(normalizedFileName)) {
|
|
635
|
-
relativeFileName = relative(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
636
|
-
} else {
|
|
637
|
-
relativeFileName = relative(tsConfig.compilerOptions.rootDir, resolve(remoteOptions.context, normalizedFileName));
|
|
638
|
-
}
|
|
639
|
-
return [
|
|
640
|
-
removeExt(relativeFileName),
|
|
641
|
-
exposed
|
|
642
|
-
];
|
|
643
|
-
}));
|
|
644
|
-
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
645
|
-
yield processTypesFile({
|
|
646
|
-
outDir: compilerOptions.outDir,
|
|
647
|
-
filePath: compilerOptions.outDir,
|
|
648
|
-
rootDir: compilerOptions.rootDir,
|
|
649
|
-
mfTypePath,
|
|
650
|
-
cb,
|
|
651
|
-
mapExposeToEntry
|
|
652
|
-
});
|
|
653
|
-
if (remoteOptions.extractThirdParty) {
|
|
654
|
-
yield thirdPartyExtractor.copyDts();
|
|
655
|
-
}
|
|
656
|
-
if (remoteOptions.deleteTsConfig) {
|
|
657
|
-
yield rm(tempTsConfigJsonPath);
|
|
658
|
-
}
|
|
659
|
-
} catch (err) {
|
|
660
|
-
throw err;
|
|
661
|
-
}
|
|
662
|
-
}), "compileTs");
|
|
663
|
-
|
|
664
|
-
// src/core/lib/archiveHandler.ts
|
|
665
|
-
import AdmZip from "adm-zip";
|
|
666
|
-
import { resolve as resolve3, join as join3 } from "path";
|
|
667
|
-
import { rm as rm3 } from "fs/promises";
|
|
668
|
-
|
|
669
|
-
// src/core/lib/utils.ts
|
|
670
|
-
import fs3 from "fs";
|
|
671
|
-
import path3 from "path";
|
|
672
|
-
import axios from "axios";
|
|
673
|
-
import http from "http";
|
|
674
|
-
import https from "https";
|
|
675
|
-
import { getProcessEnv } from "@module-federation/sdk";
|
|
676
|
-
import ansiColors from "ansi-colors";
|
|
677
|
-
|
|
678
|
-
// src/core/configurations/remotePlugin.ts
|
|
679
|
-
import { existsSync as existsSync2 } from "fs";
|
|
680
|
-
import { dirname as dirname2, join as join2, resolve as resolve2, extname as extname2 } from "path";
|
|
681
|
-
import { utils } from "@module-federation/managers";
|
|
682
|
-
import typescript from "typescript";
|
|
683
|
-
var defaultOptions = {
|
|
684
|
-
tsConfigPath: "./tsconfig.json",
|
|
685
|
-
typesFolder: "@mf-types",
|
|
686
|
-
compiledTypesFolder: "compiled-types",
|
|
687
|
-
hostRemoteTypesFolder: "@mf-types",
|
|
688
|
-
deleteTypesFolder: true,
|
|
689
|
-
additionalFilesToCompile: [],
|
|
690
|
-
compilerInstance: "tsc",
|
|
691
|
-
compileInChildProcess: false,
|
|
692
|
-
implementation: "",
|
|
693
|
-
generateAPITypes: false,
|
|
694
|
-
context: process.cwd(),
|
|
695
|
-
abortOnError: true,
|
|
696
|
-
extractRemoteTypes: false,
|
|
697
|
-
extractThirdParty: false,
|
|
698
|
-
outputDir: "",
|
|
699
|
-
deleteTsConfig: true
|
|
700
|
-
};
|
|
701
|
-
function getEffectiveRootDir(parsedCommandLine) {
|
|
702
|
-
const compilerOptions = parsedCommandLine.options;
|
|
703
|
-
if (compilerOptions.rootDir) {
|
|
704
|
-
return compilerOptions.rootDir;
|
|
705
|
-
}
|
|
706
|
-
const files = parsedCommandLine.fileNames;
|
|
707
|
-
if (files.length > 0) {
|
|
708
|
-
const commonRoot = files.map((file) => dirname2(file)).reduce((commonPath, fileDir) => {
|
|
709
|
-
while (!fileDir.startsWith(commonPath)) {
|
|
710
|
-
commonPath = dirname2(commonPath);
|
|
711
|
-
}
|
|
712
|
-
return commonPath;
|
|
713
|
-
}, files[0]);
|
|
714
|
-
return commonRoot;
|
|
715
|
-
}
|
|
716
|
-
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
717
|
-
}
|
|
718
|
-
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
719
|
-
var getDependentFiles = /* @__PURE__ */ __name((rootFiles, configContent, rootDir) => {
|
|
720
|
-
const program = typescript.createProgram(rootFiles, configContent.options);
|
|
721
|
-
const sourceFiles = program.getSourceFiles();
|
|
722
|
-
const dependentFiles = sourceFiles.map((file) => file.fileName).filter((file) => !file.endsWith(".d.ts") && file.startsWith(rootDir));
|
|
723
|
-
return dependentFiles.length ? dependentFiles : rootFiles;
|
|
724
|
-
}, "getDependentFiles");
|
|
725
|
-
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir }, mapComponentsToExpose) => {
|
|
726
|
-
const resolvedTsConfigPath = resolve2(context, tsConfigPath);
|
|
727
|
-
const readResult = typescript.readConfigFile(resolvedTsConfigPath, typescript.sys.readFile);
|
|
728
|
-
if (readResult.error) {
|
|
729
|
-
throw new Error(readResult.error.messageText.toString());
|
|
730
|
-
}
|
|
731
|
-
const rawTsConfigJson = readResult.config;
|
|
732
|
-
const configContent = typescript.parseJsonConfigFileContent(rawTsConfigJson, typescript.sys, dirname2(resolvedTsConfigPath));
|
|
733
|
-
const rootDir = getEffectiveRootDir(configContent);
|
|
734
|
-
const outDir = resolve2(context, outputDir || configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
735
|
-
const defaultCompilerOptions = {
|
|
736
|
-
rootDir,
|
|
737
|
-
emitDeclarationOnly: true,
|
|
738
|
-
noEmit: false,
|
|
739
|
-
declaration: true,
|
|
740
|
-
outDir
|
|
741
|
-
};
|
|
742
|
-
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
743
|
-
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({
|
|
744
|
-
incremental: true,
|
|
745
|
-
tsBuildInfoFile: resolve2(context, "node_modules/.cache/mf-types/.tsbuildinfo")
|
|
746
|
-
}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
747
|
-
const _a2 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a2, restCompilerOptions = __objRest(_a2, ["paths", "baseUrl"]);
|
|
748
|
-
rawTsConfigJson.compilerOptions = restCompilerOptions;
|
|
749
|
-
const outDirWithoutTypesFolder = resolve2(context, outputDir || configContent.options.outDir || "dist");
|
|
750
|
-
const excludeExtensions = [
|
|
751
|
-
".mdx",
|
|
752
|
-
".md"
|
|
753
|
-
];
|
|
754
|
-
const rootFiles = [
|
|
755
|
-
...Object.values(mapComponentsToExpose),
|
|
756
|
-
...additionalFilesToCompile
|
|
757
|
-
].filter((filename) => !excludeExtensions.some((ext) => filename.endsWith(ext)));
|
|
758
|
-
const filesToCompile = [
|
|
759
|
-
...getDependentFiles(rootFiles, configContent, rootDir),
|
|
760
|
-
...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts") && !filename.startsWith(outDirWithoutTypesFolder))
|
|
761
|
-
];
|
|
762
|
-
rawTsConfigJson.include = [];
|
|
763
|
-
rawTsConfigJson.files = [
|
|
764
|
-
...new Set(filesToCompile)
|
|
765
|
-
];
|
|
766
|
-
rawTsConfigJson.exclude = [];
|
|
767
|
-
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
768
|
-
rawTsConfigJson.extends = resolvedTsConfigPath;
|
|
769
|
-
if (rawTsConfigJson.compilerOptions.declarationDir) {
|
|
770
|
-
delete rawTsConfigJson.compilerOptions.declarationDir;
|
|
771
|
-
}
|
|
772
|
-
return rawTsConfigJson;
|
|
773
|
-
}, "readTsConfig");
|
|
774
|
-
var TS_EXTENSIONS = [
|
|
775
|
-
"ts",
|
|
776
|
-
"tsx",
|
|
777
|
-
"vue",
|
|
778
|
-
"svelte"
|
|
779
|
-
];
|
|
780
|
-
var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
|
|
781
|
-
if (extname2(exposedPath)) {
|
|
782
|
-
return resolve2(context, exposedPath);
|
|
783
|
-
}
|
|
784
|
-
for (const extension of TS_EXTENSIONS) {
|
|
785
|
-
const exposedPathWithExtension = resolve2(context, `${exposedPath}.${extension}`);
|
|
786
|
-
if (existsSync2(exposedPathWithExtension)) {
|
|
787
|
-
return exposedPathWithExtension;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
return void 0;
|
|
791
|
-
}, "resolveWithExtension");
|
|
792
|
-
var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
|
|
793
|
-
const parsedOptions = utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
|
|
794
|
-
exposePath: Array.isArray(item) ? item[0] : item,
|
|
795
|
-
key
|
|
796
|
-
}), (item, key) => ({
|
|
797
|
-
exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
|
|
798
|
-
key
|
|
799
|
-
}));
|
|
800
|
-
return parsedOptions.reduce((accumulator, item) => {
|
|
801
|
-
const { exposePath, key } = item[1];
|
|
802
|
-
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(join2(exposePath, "index"), remoteOptions.context) || exposePath;
|
|
803
|
-
return accumulator;
|
|
804
|
-
}, {});
|
|
805
|
-
}, "resolveExposes");
|
|
806
|
-
var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
807
|
-
validateOptions(options);
|
|
808
|
-
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
809
|
-
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
810
|
-
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
811
|
-
if (tsConfig.compilerOptions.incremental && tsConfig.compilerOptions.tsBuildInfoFile && options.deleteTypesFolder !== true) {
|
|
812
|
-
remoteOptions.deleteTypesFolder = false;
|
|
813
|
-
}
|
|
814
|
-
return {
|
|
815
|
-
tsConfig,
|
|
816
|
-
mapComponentsToExpose,
|
|
817
|
-
remoteOptions
|
|
818
|
-
};
|
|
819
|
-
}, "retrieveRemoteConfig");
|
|
820
|
-
|
|
821
|
-
// src/core/lib/DTSManager.ts
|
|
822
|
-
import path2 from "path";
|
|
823
|
-
import { rm as rm2 } from "fs/promises";
|
|
824
|
-
import fs2 from "fs";
|
|
825
|
-
import fse from "fs-extra";
|
|
826
|
-
import { MANIFEST_EXT, inferAutoPublicPath } from "@module-federation/sdk";
|
|
827
|
-
import { ThirdPartyExtractor as ThirdPartyExtractor2 } from "@module-federation/third-party-dts-extractor";
|
|
828
|
-
|
|
829
|
-
// src/core/configurations/hostPlugin.ts
|
|
830
|
-
import { parseEntry, ENCODE_NAME_PREFIX, decodeName } from "@module-federation/sdk";
|
|
831
|
-
import { utils as utils2 } from "@module-federation/managers";
|
|
832
|
-
var defaultOptions2 = {
|
|
833
|
-
typesFolder: "@mf-types",
|
|
834
|
-
remoteTypesFolder: "@mf-types",
|
|
835
|
-
deleteTypesFolder: true,
|
|
836
|
-
maxRetries: 3,
|
|
837
|
-
implementation: "",
|
|
838
|
-
context: process.cwd(),
|
|
839
|
-
abortOnError: true,
|
|
840
|
-
consumeAPITypes: false,
|
|
841
|
-
runtimePkgs: [],
|
|
842
|
-
remoteTypeUrls: {},
|
|
843
|
-
timeout: 6e4,
|
|
844
|
-
typesOnBuild: false,
|
|
845
|
-
family: 4
|
|
846
|
-
};
|
|
847
|
-
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
848
|
-
const remoteUrl = new URL(url, "file:");
|
|
849
|
-
const pathnameWithoutEntry = remoteUrl.pathname.split("/").slice(0, -1).join("/");
|
|
850
|
-
remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
|
|
851
|
-
return remoteUrl.protocol === "file:" ? remoteUrl.pathname : remoteUrl.href;
|
|
852
|
-
}, "buildZipUrl");
|
|
853
|
-
var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
854
|
-
if (!zipUrl) {
|
|
855
|
-
return void 0;
|
|
856
|
-
}
|
|
857
|
-
return zipUrl.replace(".zip", ".d.ts");
|
|
858
|
-
}, "buildApiTypeUrl");
|
|
859
|
-
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
860
|
-
const { hostOptions, remoteAlias, remote } = options;
|
|
861
|
-
const { remoteTypeUrls } = hostOptions;
|
|
862
|
-
let decodedRemote = remote;
|
|
863
|
-
if (decodedRemote.startsWith(ENCODE_NAME_PREFIX)) {
|
|
864
|
-
decodedRemote = decodeName(decodedRemote, ENCODE_NAME_PREFIX);
|
|
865
|
-
}
|
|
866
|
-
const parsedInfo = parseEntry(decodedRemote, void 0, "@");
|
|
867
|
-
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
868
|
-
let zipUrl = "";
|
|
869
|
-
let apiTypeUrl = "";
|
|
870
|
-
const name = parsedInfo.name || remoteAlias;
|
|
871
|
-
if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
|
|
872
|
-
zipUrl = remoteTypeUrls[name].zip;
|
|
873
|
-
apiTypeUrl = remoteTypeUrls[name].api;
|
|
874
|
-
}
|
|
875
|
-
if (!zipUrl && url) {
|
|
876
|
-
zipUrl = buildZipUrl(hostOptions, url);
|
|
877
|
-
}
|
|
878
|
-
if (!apiTypeUrl && zipUrl) {
|
|
879
|
-
apiTypeUrl = buildApiTypeUrl(zipUrl);
|
|
880
|
-
}
|
|
881
|
-
return {
|
|
882
|
-
name,
|
|
883
|
-
url,
|
|
884
|
-
zipUrl,
|
|
885
|
-
apiTypeUrl,
|
|
886
|
-
alias: remoteAlias
|
|
887
|
-
};
|
|
888
|
-
}, "retrieveRemoteInfo");
|
|
889
|
-
var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
890
|
-
var _a2;
|
|
891
|
-
const parsedOptions = utils2.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
|
|
892
|
-
remote: Array.isArray(item) ? item[0] : item,
|
|
893
|
-
key
|
|
894
|
-
}), (item, key) => ({
|
|
895
|
-
remote: Array.isArray(item.external) ? item.external[0] : item.external,
|
|
896
|
-
key
|
|
897
|
-
}));
|
|
898
|
-
const remoteTypeUrls = (_a2 = hostOptions.remoteTypeUrls) != null ? _a2 : {};
|
|
899
|
-
if (typeof remoteTypeUrls !== "object") {
|
|
900
|
-
throw new Error("remoteTypeUrls must be consumed before resolveRemotes");
|
|
901
|
-
}
|
|
902
|
-
const remoteInfos = Object.keys(remoteTypeUrls).reduce((sum, remoteName) => {
|
|
903
|
-
const { zip, api, alias } = remoteTypeUrls[remoteName];
|
|
904
|
-
sum[alias] = {
|
|
905
|
-
name: remoteName,
|
|
906
|
-
url: "",
|
|
907
|
-
zipUrl: zip,
|
|
908
|
-
apiTypeUrl: api,
|
|
909
|
-
alias: alias || remoteName
|
|
910
|
-
};
|
|
911
|
-
return sum;
|
|
912
|
-
}, {});
|
|
913
|
-
return parsedOptions.reduce((accumulator, item) => {
|
|
914
|
-
const { key, remote } = item[1];
|
|
915
|
-
const res = retrieveRemoteInfo({
|
|
916
|
-
hostOptions,
|
|
917
|
-
remoteAlias: key,
|
|
918
|
-
remote
|
|
919
|
-
});
|
|
920
|
-
if (accumulator[key]) {
|
|
921
|
-
accumulator[key] = __spreadProps(__spreadValues({}, accumulator[key]), {
|
|
922
|
-
url: res.url,
|
|
923
|
-
apiTypeUrl: accumulator[key].apiTypeUrl || res.apiTypeUrl
|
|
924
|
-
});
|
|
925
|
-
return accumulator;
|
|
926
|
-
}
|
|
927
|
-
accumulator[key] = res;
|
|
928
|
-
return accumulator;
|
|
929
|
-
}, remoteInfos);
|
|
930
|
-
}, "resolveRemotes");
|
|
931
|
-
var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
932
|
-
validateOptions(options);
|
|
933
|
-
const hostOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
934
|
-
const mapRemotesToDownload = resolveRemotes(hostOptions);
|
|
935
|
-
return {
|
|
936
|
-
hostOptions,
|
|
937
|
-
mapRemotesToDownload
|
|
938
|
-
};
|
|
939
|
-
}, "retrieveHostConfig");
|
|
940
|
-
|
|
941
|
-
// src/core/constant.ts
|
|
942
|
-
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
943
|
-
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
944
|
-
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
945
|
-
|
|
946
|
-
// src/core/lib/DTSManager.ts
|
|
947
|
-
var _a;
|
|
948
|
-
var DTSManager = (_a = class {
|
|
949
|
-
constructor(options) {
|
|
950
|
-
__publicField(this, "options");
|
|
951
|
-
__publicField(this, "runtimePkgs");
|
|
952
|
-
__publicField(this, "remoteAliasMap");
|
|
953
|
-
__publicField(this, "loadedRemoteAPIAlias");
|
|
954
|
-
__publicField(this, "extraOptions");
|
|
955
|
-
__publicField(this, "updatedRemoteInfos");
|
|
956
|
-
this.options = cloneDeepOptions(options);
|
|
957
|
-
this.runtimePkgs = [
|
|
958
|
-
"@module-federation/runtime",
|
|
959
|
-
"@module-federation/enhanced/runtime",
|
|
960
|
-
"@module-federation/runtime-tools"
|
|
961
|
-
];
|
|
962
|
-
this.loadedRemoteAPIAlias = /* @__PURE__ */ new Set();
|
|
963
|
-
this.remoteAliasMap = {};
|
|
964
|
-
this.extraOptions = (options == null ? void 0 : options.extraOptions) || {};
|
|
965
|
-
this.updatedRemoteInfos = {};
|
|
966
|
-
}
|
|
967
|
-
generateAPITypes(mapComponentsToExpose) {
|
|
968
|
-
const exposePaths = /* @__PURE__ */ new Set();
|
|
969
|
-
const packageType = Object.keys(mapComponentsToExpose).reduce((sum, exposeKey) => {
|
|
970
|
-
const exposePath = path2.join(REMOTE_ALIAS_IDENTIFIER, exposeKey).split(path2.sep).join("/");
|
|
971
|
-
exposePaths.add(`'${exposePath}'`);
|
|
972
|
-
const curType = `T extends '${exposePath}' ? typeof import('${exposePath}') :`;
|
|
973
|
-
sum = curType + sum;
|
|
974
|
-
return sum;
|
|
975
|
-
}, "any;");
|
|
976
|
-
const exposePathKeys = [
|
|
977
|
-
...exposePaths
|
|
978
|
-
].join(" | ");
|
|
979
|
-
return `
|
|
980
|
-
export type RemoteKeys = ${exposePathKeys};
|
|
981
|
-
type PackageType<T> = ${packageType}`;
|
|
982
|
-
}
|
|
983
|
-
extractRemoteTypes(options) {
|
|
984
|
-
return __async(this, null, function* () {
|
|
985
|
-
var _a2;
|
|
986
|
-
const { remoteOptions, tsConfig } = options;
|
|
987
|
-
if (!remoteOptions.extractRemoteTypes) {
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
let hasRemotes = false;
|
|
991
|
-
const remotes = remoteOptions.moduleFederationConfig.remotes;
|
|
992
|
-
if (remotes) {
|
|
993
|
-
if (Array.isArray(remotes)) {
|
|
994
|
-
hasRemotes = Boolean(remotes.length);
|
|
995
|
-
} else if (typeof remotes === "object") {
|
|
996
|
-
hasRemotes = Boolean(Object.keys(remotes).length);
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1000
|
-
if (hasRemotes && this.options.host) {
|
|
1001
|
-
try {
|
|
1002
|
-
const { hostOptions } = retrieveHostConfig(this.options.host);
|
|
1003
|
-
const remoteTypesFolder = path2.resolve(hostOptions.context, hostOptions.typesFolder);
|
|
1004
|
-
const targetDir = path2.join(mfTypesPath, "node_modules");
|
|
1005
|
-
if (fs2.existsSync(remoteTypesFolder)) {
|
|
1006
|
-
const targetFolder = path2.resolve(remoteOptions.context, targetDir);
|
|
1007
|
-
yield fse.ensureDir(targetFolder);
|
|
1008
|
-
yield fse.copy(remoteTypesFolder, targetFolder, {
|
|
1009
|
-
overwrite: true
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
} catch (err) {
|
|
1013
|
-
if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1014
|
-
fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
|
|
1015
|
-
} else {
|
|
1016
|
-
throw err;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
// it must execute after consumeTypes
|
|
1023
|
-
generateTypes() {
|
|
1024
|
-
return __async(this, null, function* () {
|
|
1025
|
-
var _a2, _b;
|
|
1026
|
-
try {
|
|
1027
|
-
const { options } = this;
|
|
1028
|
-
if (!options.remote) {
|
|
1029
|
-
throw new Error("options.remote is required if you want to generateTypes");
|
|
1030
|
-
}
|
|
1031
|
-
const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
|
|
1032
|
-
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
if (!((_a2 = tsConfig.files) == null ? void 0 : _a2.length)) {
|
|
1036
|
-
logger.info("No type files to compile, skip");
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
if (tsConfig.compilerOptions.tsBuildInfoFile) {
|
|
1040
|
-
try {
|
|
1041
|
-
const tsBuildInfoFile = path2.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
|
|
1042
|
-
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1043
|
-
if (!fs2.existsSync(mfTypesPath)) {
|
|
1044
|
-
fs2.rmSync(tsBuildInfoFile, {
|
|
1045
|
-
force: true
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
} catch (e) {
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
yield this.extractRemoteTypes({
|
|
1052
|
-
remoteOptions,
|
|
1053
|
-
tsConfig,
|
|
1054
|
-
mapComponentsToExpose
|
|
1055
|
-
});
|
|
1056
|
-
yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1057
|
-
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1058
|
-
let apiTypesPath = "";
|
|
1059
|
-
if (remoteOptions.generateAPITypes) {
|
|
1060
|
-
const apiTypes = this.generateAPITypes(mapComponentsToExpose);
|
|
1061
|
-
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1062
|
-
fs2.writeFileSync(apiTypesPath, apiTypes);
|
|
1063
|
-
}
|
|
1064
|
-
try {
|
|
1065
|
-
if (remoteOptions.deleteTypesFolder) {
|
|
1066
|
-
yield rm2(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1067
|
-
recursive: true,
|
|
1068
|
-
force: true
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
} catch (err) {
|
|
1072
|
-
if (isDebugMode()) {
|
|
1073
|
-
console.error(err);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
logger.success("Federated types created correctly");
|
|
1077
|
-
} catch (error) {
|
|
1078
|
-
if (((_b = this.options.remote) == null ? void 0 : _b.abortOnError) === false) {
|
|
1079
|
-
if (this.options.displayErrorInTerminal) {
|
|
1080
|
-
logger.error(error);
|
|
1081
|
-
}
|
|
1082
|
-
} else {
|
|
1083
|
-
throw error;
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
requestRemoteManifest(remoteInfo, hostOptions) {
|
|
1089
|
-
return __async(this, null, function* () {
|
|
1090
|
-
try {
|
|
1091
|
-
if (!remoteInfo.url.includes(MANIFEST_EXT)) {
|
|
1092
|
-
return remoteInfo;
|
|
1093
|
-
}
|
|
1094
|
-
if (remoteInfo.zipUrl) {
|
|
1095
|
-
return remoteInfo;
|
|
1096
|
-
}
|
|
1097
|
-
const url = remoteInfo.url;
|
|
1098
|
-
const res = yield axiosGet(url, {
|
|
1099
|
-
timeout: hostOptions.timeout,
|
|
1100
|
-
family: hostOptions.family
|
|
1101
|
-
});
|
|
1102
|
-
const manifestJson = res.data;
|
|
1103
|
-
if (!manifestJson.metaData.types.zip) {
|
|
1104
|
-
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1105
|
-
}
|
|
1106
|
-
const addProtocol = /* @__PURE__ */ __name((u) => {
|
|
1107
|
-
if (u.startsWith("//")) {
|
|
1108
|
-
return `https:${u}`;
|
|
1109
|
-
}
|
|
1110
|
-
return u;
|
|
1111
|
-
}, "addProtocol");
|
|
1112
|
-
let publicPath;
|
|
1113
|
-
if ("publicPath" in manifestJson.metaData) {
|
|
1114
|
-
publicPath = manifestJson.metaData.publicPath;
|
|
1115
|
-
} else {
|
|
1116
|
-
const getPublicPath = new Function(manifestJson.metaData.getPublicPath);
|
|
1117
|
-
if (manifestJson.metaData.getPublicPath.startsWith("function")) {
|
|
1118
|
-
publicPath = getPublicPath()();
|
|
1119
|
-
} else {
|
|
1120
|
-
publicPath = getPublicPath();
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
if (publicPath === "auto") {
|
|
1124
|
-
publicPath = inferAutoPublicPath(remoteInfo.url);
|
|
1125
|
-
}
|
|
1126
|
-
remoteInfo.zipUrl = new URL(path2.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1127
|
-
if (!manifestJson.metaData.types.api) {
|
|
1128
|
-
console.warn(`Can not get ${remoteInfo.name}'s api types url!`);
|
|
1129
|
-
remoteInfo.apiTypeUrl = "";
|
|
1130
|
-
return remoteInfo;
|
|
1131
|
-
}
|
|
1132
|
-
remoteInfo.apiTypeUrl = new URL(path2.join(addProtocol(publicPath), manifestJson.metaData.types.api)).href;
|
|
1133
|
-
return remoteInfo;
|
|
1134
|
-
} catch (_err) {
|
|
1135
|
-
fileLog(`fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`, "requestRemoteManifest", "error");
|
|
1136
|
-
return remoteInfo;
|
|
1137
|
-
}
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
consumeTargetRemotes(hostOptions, remoteInfo) {
|
|
1141
|
-
return __async(this, null, function* () {
|
|
1142
|
-
if (!remoteInfo.zipUrl) {
|
|
1143
|
-
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1144
|
-
}
|
|
1145
|
-
const typesDownloader = downloadTypesArchive(hostOptions);
|
|
1146
|
-
return typesDownloader([
|
|
1147
|
-
remoteInfo.alias,
|
|
1148
|
-
remoteInfo.zipUrl
|
|
1149
|
-
]);
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
downloadAPITypes(remoteInfo, destinationPath, hostOptions) {
|
|
1153
|
-
return __async(this, null, function* () {
|
|
1154
|
-
const { apiTypeUrl } = remoteInfo;
|
|
1155
|
-
if (!apiTypeUrl) {
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
try {
|
|
1159
|
-
const url = apiTypeUrl;
|
|
1160
|
-
const res = yield axiosGet(url, {
|
|
1161
|
-
timeout: hostOptions.timeout,
|
|
1162
|
-
family: hostOptions.family
|
|
1163
|
-
});
|
|
1164
|
-
let apiTypeFile = res.data;
|
|
1165
|
-
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1166
|
-
const filePath = path2.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1167
|
-
fs2.writeFileSync(filePath, apiTypeFile);
|
|
1168
|
-
const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
|
|
1169
|
-
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1170
|
-
fileLog(`success`, "downloadAPITypes", "info");
|
|
1171
|
-
return existed;
|
|
1172
|
-
} catch (err) {
|
|
1173
|
-
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
1174
|
-
}
|
|
1175
|
-
});
|
|
1176
|
-
}
|
|
1177
|
-
consumeAPITypes(hostOptions) {
|
|
1178
|
-
const apiTypeFileName = path2.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME);
|
|
1179
|
-
try {
|
|
1180
|
-
const existedFile = fs2.readFileSync(apiTypeFileName, "utf-8");
|
|
1181
|
-
const existedImports = new ThirdPartyExtractor2({
|
|
1182
|
-
destDir: ""
|
|
1183
|
-
}).collectTypeImports(existedFile);
|
|
1184
|
-
existedImports.forEach((existedImport) => {
|
|
1185
|
-
const alias = existedImport.split("./").slice(1).join("./").replace("/apis.d.ts", "");
|
|
1186
|
-
this.loadedRemoteAPIAlias.add(alias);
|
|
1187
|
-
});
|
|
1188
|
-
} catch (err) {
|
|
1189
|
-
}
|
|
1190
|
-
if (!this.loadedRemoteAPIAlias.size) {
|
|
1191
|
-
return;
|
|
1192
|
-
}
|
|
1193
|
-
const packageTypes = [];
|
|
1194
|
-
const remoteKeys = [];
|
|
1195
|
-
const importTypeStr = [
|
|
1196
|
-
...this.loadedRemoteAPIAlias
|
|
1197
|
-
].sort().map((alias, index) => {
|
|
1198
|
-
const remoteKey = `RemoteKeys_${index}`;
|
|
1199
|
-
const packageType = `PackageType_${index}`;
|
|
1200
|
-
packageTypes.push(`T extends ${remoteKey} ? ${packageType}<T>`);
|
|
1201
|
-
remoteKeys.push(remoteKey);
|
|
1202
|
-
return `import type { PackageType as ${packageType},RemoteKeys as ${remoteKey} } from './${alias}/apis.d.ts';`;
|
|
1203
|
-
}).join("\n");
|
|
1204
|
-
const remoteKeysStr = `type RemoteKeys = ${remoteKeys.join(" | ")};`;
|
|
1205
|
-
const packageTypesStr = `type PackageType<T, Y=any> = ${[
|
|
1206
|
-
...packageTypes,
|
|
1207
|
-
"Y"
|
|
1208
|
-
].join(" :\n")} ;`;
|
|
1209
|
-
const runtimePkgs = /* @__PURE__ */ new Set();
|
|
1210
|
-
[
|
|
1211
|
-
...this.runtimePkgs,
|
|
1212
|
-
...hostOptions.runtimePkgs
|
|
1213
|
-
].forEach((pkg) => {
|
|
1214
|
-
runtimePkgs.add(pkg);
|
|
1215
|
-
});
|
|
1216
|
-
const pkgsDeclareStr = [
|
|
1217
|
-
...runtimePkgs
|
|
1218
|
-
].map((pkg) => {
|
|
1219
|
-
return `declare module "${pkg}" {
|
|
1220
|
-
${remoteKeysStr}
|
|
1221
|
-
${packageTypesStr}
|
|
1222
|
-
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
|
|
1223
|
-
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
|
|
1224
|
-
}`;
|
|
1225
|
-
}).join("\n");
|
|
1226
|
-
const fileStr = `${importTypeStr}
|
|
1227
|
-
${pkgsDeclareStr}
|
|
1228
|
-
`;
|
|
1229
|
-
fs2.writeFileSync(path2.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME), fileStr);
|
|
1230
|
-
}
|
|
1231
|
-
consumeArchiveTypes(options) {
|
|
1232
|
-
return __async(this, null, function* () {
|
|
1233
|
-
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1234
|
-
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1235
|
-
const remoteInfo = item[1];
|
|
1236
|
-
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1237
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1238
|
-
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1239
|
-
}
|
|
1240
|
-
return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
1241
|
-
}));
|
|
1242
|
-
const downloadPromisesResult = yield Promise.allSettled(downloadPromises);
|
|
1243
|
-
return {
|
|
1244
|
-
hostOptions,
|
|
1245
|
-
downloadPromisesResult
|
|
1246
|
-
};
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
consumeTypes() {
|
|
1250
|
-
return __async(this, null, function* () {
|
|
1251
|
-
var _a2;
|
|
1252
|
-
try {
|
|
1253
|
-
const { options } = this;
|
|
1254
|
-
if (!options.host) {
|
|
1255
|
-
throw new Error("options.host is required if you want to consumeTypes");
|
|
1256
|
-
}
|
|
1257
|
-
const { mapRemotesToDownload } = retrieveHostConfig(options.host);
|
|
1258
|
-
if (!Object.keys(mapRemotesToDownload).length) {
|
|
1259
|
-
return;
|
|
1260
|
-
}
|
|
1261
|
-
const { downloadPromisesResult, hostOptions } = yield this.consumeArchiveTypes(options.host);
|
|
1262
|
-
if (hostOptions.consumeAPITypes) {
|
|
1263
|
-
yield Promise.all(downloadPromisesResult.map((item) => __async(this, null, function* () {
|
|
1264
|
-
if (item.status === "rejected" || !item.value) {
|
|
1265
|
-
return;
|
|
1266
|
-
}
|
|
1267
|
-
const [alias, destinationPath] = item.value;
|
|
1268
|
-
const remoteInfo = this.remoteAliasMap[alias];
|
|
1269
|
-
if (!remoteInfo) {
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
yield this.downloadAPITypes(remoteInfo, destinationPath, hostOptions);
|
|
1273
|
-
})));
|
|
1274
|
-
this.consumeAPITypes(hostOptions);
|
|
1275
|
-
}
|
|
1276
|
-
logger.success("Federated types extraction completed");
|
|
1277
|
-
} catch (err) {
|
|
1278
|
-
if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1279
|
-
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
1280
|
-
} else {
|
|
1281
|
-
throw err;
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
});
|
|
1285
|
-
}
|
|
1286
|
-
updateTypes(options) {
|
|
1287
|
-
return __async(this, null, function* () {
|
|
1288
|
-
var _a2, _b, _c;
|
|
1289
|
-
try {
|
|
1290
|
-
const { remoteName, updateMode, remoteTarPath, remoteInfo: updatedRemoteInfo, once } = options;
|
|
1291
|
-
const hostName = (_c = (_b = (_a2 = this.options) == null ? void 0 : _a2.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
|
|
1292
|
-
fileLog(`options: ${JSON.stringify(options, null, 2)};
|
|
1293
|
-
hostName: ${hostName}`, "updateTypes", "info");
|
|
1294
|
-
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
|
|
1295
|
-
if (!this.options.remote) {
|
|
1296
|
-
return;
|
|
1297
|
-
}
|
|
1298
|
-
yield this.generateTypes();
|
|
1299
|
-
} else {
|
|
1300
|
-
const { remoteAliasMap } = this;
|
|
1301
|
-
if (!this.options.host) {
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1305
|
-
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1306
|
-
const consumeTypes = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
1307
|
-
fileLog(`consumeTypes start`, "updateTypes", "info");
|
|
1308
|
-
if (!requiredRemoteInfo.zipUrl) {
|
|
1309
|
-
throw new Error(`Can not get ${requiredRemoteInfo.name}'s types archive url!`);
|
|
1310
|
-
}
|
|
1311
|
-
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, __spreadProps(__spreadValues({}, requiredRemoteInfo), {
|
|
1312
|
-
// use remoteTarPath first
|
|
1313
|
-
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
1314
|
-
}));
|
|
1315
|
-
const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath, hostOptions);
|
|
1316
|
-
if (addNew) {
|
|
1317
|
-
this.consumeAPITypes(hostOptions);
|
|
1318
|
-
}
|
|
1319
|
-
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
1320
|
-
}), "consumeTypes");
|
|
1321
|
-
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
1322
|
-
if (!loadedRemoteInfo) {
|
|
1323
|
-
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
1324
|
-
return item.name === remoteName;
|
|
1325
|
-
});
|
|
1326
|
-
fileLog(`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`, "updateTypes", "info");
|
|
1327
|
-
if (remoteInfo) {
|
|
1328
|
-
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1329
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1330
|
-
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1331
|
-
}
|
|
1332
|
-
yield consumeTypes(this.remoteAliasMap[remoteInfo.alias]);
|
|
1333
|
-
} else if (updatedRemoteInfo) {
|
|
1334
|
-
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1335
|
-
yield consumeTypes(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1336
|
-
}), "consumeDynamicRemoteTypes");
|
|
1337
|
-
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1338
|
-
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
1339
|
-
hostOptions,
|
|
1340
|
-
remoteAlias: updatedRemoteInfo.alias || updatedRemoteInfo.name,
|
|
1341
|
-
remote: updatedRemoteInfo.url
|
|
1342
|
-
});
|
|
1343
|
-
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
1344
|
-
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo, hostOptions);
|
|
1345
|
-
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "updateTypes", "info");
|
|
1346
|
-
yield consumeDynamicRemoteTypes();
|
|
1347
|
-
}
|
|
1348
|
-
if (!once && this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1349
|
-
yield consumeDynamicRemoteTypes();
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
} else {
|
|
1353
|
-
yield consumeTypes(loadedRemoteInfo);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
} catch (err) {
|
|
1357
|
-
fileLog(`updateTypes fail, ${err}`, "updateTypes", "error");
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
}, __name(_a, "DTSManager"), _a);
|
|
1362
|
-
|
|
1363
|
-
// src/core/lib/utils.ts
|
|
1364
|
-
import cloneDeepWith from "lodash.clonedeepwith";
|
|
1365
|
-
function getDTSManagerConstructor(implementation) {
|
|
1366
|
-
if (implementation) {
|
|
1367
|
-
const NewConstructor = __require(implementation);
|
|
1368
|
-
return NewConstructor.default ? NewConstructor.default : NewConstructor;
|
|
1369
|
-
}
|
|
1370
|
-
return DTSManager;
|
|
1371
|
-
}
|
|
1372
|
-
__name(getDTSManagerConstructor, "getDTSManagerConstructor");
|
|
1373
|
-
var validateOptions = /* @__PURE__ */ __name((options) => {
|
|
1374
|
-
if (!options.moduleFederationConfig) {
|
|
1375
|
-
throw new Error("moduleFederationConfig is required");
|
|
1376
|
-
}
|
|
1377
|
-
}, "validateOptions");
|
|
1378
|
-
function retrieveTypesAssetsInfo(options) {
|
|
1379
|
-
let apiTypesPath = "";
|
|
1380
|
-
let zipTypesPath = "";
|
|
1381
|
-
try {
|
|
1382
|
-
const { tsConfig, remoteOptions, mapComponentsToExpose } = retrieveRemoteConfig(options);
|
|
1383
|
-
if (!Object.keys(mapComponentsToExpose).length || !tsConfig.files.length) {
|
|
1384
|
-
return {
|
|
1385
|
-
apiTypesPath,
|
|
1386
|
-
zipTypesPath,
|
|
1387
|
-
zipName: "",
|
|
1388
|
-
apiFileName: ""
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1392
|
-
zipTypesPath = retrieveTypesZipPath(mfTypesPath, remoteOptions);
|
|
1393
|
-
if (remoteOptions.generateAPITypes) {
|
|
1394
|
-
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1395
|
-
}
|
|
1396
|
-
return {
|
|
1397
|
-
apiTypesPath,
|
|
1398
|
-
zipTypesPath,
|
|
1399
|
-
zipName: path3.basename(zipTypesPath),
|
|
1400
|
-
apiFileName: path3.basename(apiTypesPath)
|
|
1401
|
-
};
|
|
1402
|
-
} catch (err) {
|
|
1403
|
-
console.error(ansiColors.red(`Unable to compile federated types, ${err}`));
|
|
1404
|
-
return {
|
|
1405
|
-
apiTypesPath: "",
|
|
1406
|
-
zipTypesPath: "",
|
|
1407
|
-
zipName: "",
|
|
1408
|
-
apiFileName: ""
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
__name(retrieveTypesAssetsInfo, "retrieveTypesAssetsInfo");
|
|
1413
|
-
function isDebugMode() {
|
|
1414
|
-
return Boolean(process.env["FEDERATION_DEBUG"]) || process.env["NODE_ENV"] === "test";
|
|
1415
|
-
}
|
|
1416
|
-
__name(isDebugMode, "isDebugMode");
|
|
1417
|
-
var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) => {
|
|
1418
|
-
if (dtsOptions === false) {
|
|
1419
|
-
return false;
|
|
1420
|
-
}
|
|
1421
|
-
try {
|
|
1422
|
-
let filepath = "";
|
|
1423
|
-
if (typeof dtsOptions === "object" && dtsOptions.tsConfigPath) {
|
|
1424
|
-
filepath = dtsOptions.tsConfigPath;
|
|
1425
|
-
} else {
|
|
1426
|
-
filepath = path3.resolve(context, "./tsconfig.json");
|
|
1427
|
-
}
|
|
1428
|
-
if (!path3.isAbsolute(filepath)) {
|
|
1429
|
-
filepath = path3.resolve(context, filepath);
|
|
1430
|
-
}
|
|
1431
|
-
return fs3.existsSync(filepath);
|
|
1432
|
-
} catch (err) {
|
|
1433
|
-
return false;
|
|
1434
|
-
}
|
|
1435
|
-
}, "isTSProject");
|
|
1436
|
-
function cloneDeepOptions(options) {
|
|
1437
|
-
const excludeKeys = [
|
|
1438
|
-
"manifest",
|
|
1439
|
-
"async"
|
|
1440
|
-
];
|
|
1441
|
-
return cloneDeepWith(options, (value, key) => {
|
|
1442
|
-
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1443
|
-
return false;
|
|
1444
|
-
}
|
|
1445
|
-
if (typeof value === "function") {
|
|
1446
|
-
return false;
|
|
1447
|
-
}
|
|
1448
|
-
if (key === "extractThirdParty" && Array.isArray(value)) {
|
|
1449
|
-
return value.map((item) => {
|
|
1450
|
-
return item.toString();
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
});
|
|
1454
|
-
}
|
|
1455
|
-
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
1456
|
-
var getEnvHeaders = /* @__PURE__ */ __name(() => {
|
|
1457
|
-
const headersStr = getProcessEnv()["MF_ENV_HEADERS"] || "{}";
|
|
1458
|
-
return __spreadValues({}, JSON.parse(headersStr));
|
|
1459
|
-
}, "getEnvHeaders");
|
|
1460
|
-
function axiosGet(url, config) {
|
|
1461
|
-
return __async(this, null, function* () {
|
|
1462
|
-
var _a2, _b;
|
|
1463
|
-
const httpAgent = new http.Agent({
|
|
1464
|
-
family: (_a2 = config == null ? void 0 : config.family) != null ? _a2 : 4
|
|
1465
|
-
});
|
|
1466
|
-
const httpsAgent = new https.Agent({
|
|
1467
|
-
family: (_b = config == null ? void 0 : config.family) != null ? _b : 4
|
|
1468
|
-
});
|
|
1469
|
-
return axios.get(url, __spreadProps(__spreadValues(__spreadValues({
|
|
1470
|
-
httpAgent,
|
|
1471
|
-
httpsAgent
|
|
1472
|
-
}, {
|
|
1473
|
-
headers: getEnvHeaders()
|
|
1474
|
-
}), config), {
|
|
1475
|
-
timeout: (config == null ? void 0 : config.timeout) || 6e4
|
|
1476
|
-
}));
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
__name(axiosGet, "axiosGet");
|
|
1480
|
-
|
|
1481
|
-
// src/core/lib/archiveHandler.ts
|
|
1482
|
-
var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => join3(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
|
|
1483
|
-
var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
1484
|
-
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1485
|
-
const zip = new AdmZip();
|
|
1486
|
-
zip.addLocalFolder(mfTypesPath);
|
|
1487
|
-
return zip.writeZipPromise(retrieveTypesZipPath(mfTypesPath, remoteOptions));
|
|
1488
|
-
}), "createTypesArchive");
|
|
1489
|
-
var downloadErrorLogger = /* @__PURE__ */ __name((destinationFolder, fileToDownload) => (reason) => {
|
|
1490
|
-
throw __spreadProps(__spreadValues({}, reason), {
|
|
1491
|
-
message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`
|
|
1492
|
-
});
|
|
1493
|
-
}, "downloadErrorLogger");
|
|
1494
|
-
var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, destinationFolder) => {
|
|
1495
|
-
return resolve3(hostOptions.context, hostOptions.typesFolder, destinationFolder);
|
|
1496
|
-
}, "retrieveTypesArchiveDestinationPath");
|
|
1497
|
-
var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
1498
|
-
let retries = 0;
|
|
1499
|
-
return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
|
|
1500
|
-
var _a2;
|
|
1501
|
-
const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
|
|
1502
|
-
while (retries++ < hostOptions.maxRetries) {
|
|
1503
|
-
try {
|
|
1504
|
-
const url = new URL(fileToDownload).href;
|
|
1505
|
-
const response = yield axiosGet(url, {
|
|
1506
|
-
responseType: "arraybuffer",
|
|
1507
|
-
timeout: hostOptions.timeout,
|
|
1508
|
-
family: hostOptions.family
|
|
1509
|
-
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1510
|
-
if (typeof ((_a2 = response.headers) == null ? void 0 : _a2["content-type"]) === "string" && response.headers["content-type"].includes("text/html")) {
|
|
1511
|
-
throw new Error(`${url} receives invalid content-type: ${response.headers["content-type"]}`);
|
|
1512
|
-
}
|
|
1513
|
-
try {
|
|
1514
|
-
if (hostOptions.deleteTypesFolder) {
|
|
1515
|
-
yield rm3(destinationPath, {
|
|
1516
|
-
recursive: true,
|
|
1517
|
-
force: true
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
|
-
} catch (error) {
|
|
1521
|
-
fileLog(`Unable to remove types folder, ${error}`, "downloadTypesArchive", "error");
|
|
1522
|
-
}
|
|
1523
|
-
const zip = new AdmZip(Buffer.from(response.data));
|
|
1524
|
-
zip.extractAllTo(destinationPath, true);
|
|
1525
|
-
fileLog(`zip.extractAllTo success destinationPath: ${destinationPath}; url: ${url}`, "downloadTypesArchive", "info");
|
|
1526
|
-
return [
|
|
1527
|
-
destinationFolder,
|
|
1528
|
-
destinationPath
|
|
1529
|
-
];
|
|
1530
|
-
} catch (error) {
|
|
1531
|
-
fileLog(`Error during types archive download: ${(error == null ? void 0 : error.message) || "unknown error"}`, "downloadTypesArchive", "error");
|
|
1532
|
-
if (retries >= hostOptions.maxRetries) {
|
|
1533
|
-
logger.error(`Failed to download types archive from "${fileToDownload}". Set FEDERATION_DEBUG=true for details.`);
|
|
1534
|
-
if (hostOptions.abortOnError !== false) {
|
|
1535
|
-
throw error;
|
|
1536
|
-
}
|
|
1537
|
-
return void 0;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
});
|
|
1542
|
-
}, "downloadTypesArchive");
|
|
1543
|
-
|
|
1544
|
-
// src/core/lib/generateTypes.ts
|
|
1545
|
-
function generateTypes(options) {
|
|
1546
|
-
return __async(this, null, function* () {
|
|
1547
|
-
var _a2;
|
|
1548
|
-
const DTSManagerConstructor = getDTSManagerConstructor((_a2 = options.remote) == null ? void 0 : _a2.implementation);
|
|
1549
|
-
const dtsManager = new DTSManagerConstructor(options);
|
|
1550
|
-
return dtsManager.generateTypes();
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
__name(generateTypes, "generateTypes");
|
|
1554
|
-
|
|
1555
|
-
// src/core/rpc/types.ts
|
|
1556
|
-
var RpcGMCallTypes;
|
|
1557
|
-
(function(RpcGMCallTypes2) {
|
|
1558
|
-
RpcGMCallTypes2["CALL"] = "mf_call";
|
|
1559
|
-
RpcGMCallTypes2["RESOLVE"] = "mf_resolve";
|
|
1560
|
-
RpcGMCallTypes2["REJECT"] = "mf_reject";
|
|
1561
|
-
RpcGMCallTypes2["EXIT"] = "mf_exit";
|
|
1562
|
-
})(RpcGMCallTypes || (RpcGMCallTypes = {}));
|
|
1563
|
-
|
|
1564
|
-
// src/core/rpc/expose-rpc.ts
|
|
1565
|
-
import process2 from "process";
|
|
1566
|
-
function exposeRpc(fn) {
|
|
1567
|
-
const sendMessage = /* @__PURE__ */ __name((message) => new Promise((resolve4, reject) => {
|
|
1568
|
-
if (!process2.send) {
|
|
1569
|
-
reject(new Error(`Process ${process2.pid} doesn't have IPC channels`));
|
|
1570
|
-
} else if (!process2.connected) {
|
|
1571
|
-
reject(new Error(`Process ${process2.pid} doesn't have open IPC channels`));
|
|
1572
|
-
} else {
|
|
1573
|
-
process2.send(message, void 0, void 0, (error) => {
|
|
1574
|
-
if (error) {
|
|
1575
|
-
reject(error);
|
|
1576
|
-
} else {
|
|
1577
|
-
resolve4(void 0);
|
|
1578
|
-
}
|
|
1579
|
-
});
|
|
1580
|
-
}
|
|
1581
|
-
}), "sendMessage");
|
|
1582
|
-
const handleMessage = /* @__PURE__ */ __name((message) => __async(this, null, function* () {
|
|
1583
|
-
if (message.type === RpcGMCallTypes.CALL) {
|
|
1584
|
-
if (!process2.send) {
|
|
1585
|
-
return;
|
|
1586
|
-
}
|
|
1587
|
-
let value, error;
|
|
1588
|
-
try {
|
|
1589
|
-
value = yield fn(...message.args);
|
|
1590
|
-
} catch (fnError) {
|
|
1591
|
-
error = fnError;
|
|
1592
|
-
}
|
|
1593
|
-
try {
|
|
1594
|
-
if (error) {
|
|
1595
|
-
yield sendMessage({
|
|
1596
|
-
type: RpcGMCallTypes.REJECT,
|
|
1597
|
-
id: message.id,
|
|
1598
|
-
error
|
|
1599
|
-
});
|
|
1600
|
-
} else {
|
|
1601
|
-
yield sendMessage({
|
|
1602
|
-
type: RpcGMCallTypes.RESOLVE,
|
|
1603
|
-
id: message.id,
|
|
1604
|
-
value
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
|
-
} catch (sendError) {
|
|
1608
|
-
if (error) {
|
|
1609
|
-
if (error instanceof Error) {
|
|
1610
|
-
console.error(error);
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
console.error(sendError);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
}), "handleMessage");
|
|
1617
|
-
process2.on("message", handleMessage);
|
|
1618
|
-
}
|
|
1619
|
-
__name(exposeRpc, "exposeRpc");
|
|
1620
|
-
|
|
1621
|
-
export {
|
|
1622
|
-
ModuleFederationDevServer,
|
|
1623
|
-
createKoaServer,
|
|
1624
|
-
retrieveMfTypesPath,
|
|
1625
|
-
retrieveOriginalOutDir,
|
|
1626
|
-
retrieveTypesZipPath,
|
|
1627
|
-
retrieveHostConfig,
|
|
1628
|
-
REMOTE_ALIAS_IDENTIFIER,
|
|
1629
|
-
REMOTE_API_TYPES_FILE_NAME,
|
|
1630
|
-
HOST_API_TYPES_FILE_NAME,
|
|
1631
|
-
DTSManager,
|
|
1632
|
-
getDTSManagerConstructor,
|
|
1633
|
-
validateOptions,
|
|
1634
|
-
retrieveTypesAssetsInfo,
|
|
1635
|
-
isDebugMode,
|
|
1636
|
-
isTSProject,
|
|
1637
|
-
cloneDeepOptions,
|
|
1638
|
-
retrieveRemoteConfig,
|
|
1639
|
-
generateTypes,
|
|
1640
|
-
RpcGMCallTypes,
|
|
1641
|
-
exposeRpc
|
|
1642
|
-
};
|