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