@module-federation/dts-plugin 0.1.19 → 0.1.21

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 (35) hide show
  1. package/dist/CHANGELOG.md +27 -0
  2. package/dist/{DtsWorker-d731dc2b.d.ts → DtsWorker-7113d2b0.d.ts} +6 -3
  3. package/dist/core.d.mts +85 -0
  4. package/dist/core.d.ts +5 -5
  5. package/dist/core.js +1105 -1008
  6. package/dist/dynamic-remote-type-hints-plugin.d.mts +5 -0
  7. package/dist/dynamic-remote-type-hints-plugin.d.ts +5 -0
  8. package/dist/dynamic-remote-type-hints-plugin.js +198 -0
  9. package/dist/esm/chunk-55BKSNZ4.js +2372 -0
  10. package/dist/esm/chunk-G7ONFBMA.js +24 -0
  11. package/dist/esm/chunk-MQRIERJP.js +236 -0
  12. package/dist/esm/core.js +44 -0
  13. package/dist/esm/dynamic-remote-type-hints-plugin.js +73 -0
  14. package/dist/esm/fork-dev-worker.js +141 -0
  15. package/dist/esm/fork-generate-dts.js +26 -0
  16. package/dist/esm/index.js +406 -0
  17. package/dist/esm/start-broker.js +36 -0
  18. package/dist/fork-dev-worker.d.ts +15 -0
  19. package/dist/fork-dev-worker.js +2543 -0
  20. package/dist/{forkGenerateDts.d.ts → fork-generate-dts.d.mts} +1 -1
  21. package/dist/fork-generate-dts.d.ts +9 -0
  22. package/dist/fork-generate-dts.js +1902 -0
  23. package/dist/iife/launch-web-client.js +91 -42
  24. package/dist/index.d.mts +10 -0
  25. package/dist/index.js +1287 -1181
  26. package/dist/package.json +11 -2
  27. package/dist/{startBroker.d.ts → start-broker.d.mts} +2 -0
  28. package/dist/start-broker.d.ts +42 -0
  29. package/dist/start-broker.js +1273 -0
  30. package/package.json +14 -5
  31. package/dist/forkDevWorker.js +0 -2523
  32. package/dist/forkGenerateDts.js +0 -1618
  33. package/dist/launch-web-client.d.ts +0 -2
  34. package/dist/startBroker.js +0 -902
  35. /package/dist/{forkDevWorker.d.ts → fork-dev-worker.d.mts} +0 -0
package/dist/core.js CHANGED
@@ -1,10 +1,27 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
8
  var __getProtoOf = Object.getPrototypeOf;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
25
  var __export = (target, all) => {
9
26
  for (var name in all)
10
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +43,30 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
43
  mod
27
44
  ));
28
45
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __publicField = (obj, key, value) => {
47
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
48
+ return value;
49
+ };
50
+ var __async = (__this, __arguments, generator) => {
51
+ return new Promise((resolve4, reject) => {
52
+ var fulfilled = (value) => {
53
+ try {
54
+ step(generator.next(value));
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ };
59
+ var rejected = (value) => {
60
+ try {
61
+ step(generator.throw(value));
62
+ } catch (e) {
63
+ reject(e);
64
+ }
65
+ };
66
+ var step = (x) => x.done ? resolve4(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
67
+ step((generator = generator.apply(__this, __arguments)).next());
68
+ });
69
+ };
29
70
 
30
71
  // packages/dts-plugin/src/core/index.ts
31
72
  var core_exports = {};
@@ -59,20 +100,26 @@ var import_managers2 = require("@module-federation/managers");
59
100
  var import_typescript2 = __toESM(require("typescript"));
60
101
 
61
102
  // packages/dts-plugin/src/core/lib/utils.ts
103
+ var import_fs2 = __toESM(require("fs"));
62
104
  var import_path4 = __toESM(require("path"));
105
+ var import_axios = __toESM(require("axios"));
106
+ var import_http2 = __toESM(require("http"));
107
+ var import_https = __toESM(require("https"));
108
+ var import_ansi_colors3 = __toESM(require("ansi-colors"));
63
109
 
64
110
  // packages/dts-plugin/src/core/lib/DTSManager.ts
65
111
  var import_ansi_colors2 = __toESM(require("ansi-colors"));
66
112
  var import_path3 = __toESM(require("path"));
67
- var import_promises = require("fs/promises");
113
+ var import_promises2 = require("fs/promises");
68
114
  var import_fs = __toESM(require("fs"));
69
115
  var import_sdk4 = require("@module-federation/sdk");
70
116
  var import_lodash = __toESM(require("lodash.clonedeepwith"));
117
+ var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
71
118
 
72
119
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
73
120
  var import_adm_zip = __toESM(require("adm-zip"));
74
- var import_axios = __toESM(require("axios"));
75
121
  var import_path2 = require("path");
122
+ var import_promises = require("fs/promises");
76
123
 
77
124
  // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
78
125
  var import_ansi_colors = __toESM(require("ansi-colors"));
@@ -81,77 +128,46 @@ var import_typescript = __toESM(require("typescript"));
81
128
  var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
82
129
  var STARTS_WITH_SLASH = /^\//;
83
130
  var DEFINITION_FILE_EXTENSION = ".d.ts";
84
- var reportCompileDiagnostic = (diagnostic) => {
85
- const { line } = diagnostic.file.getLineAndCharacterOfPosition(
86
- diagnostic.start
87
- );
88
- console.error(
89
- import_ansi_colors.default.red(
90
- `TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(
91
- diagnostic.messageText,
92
- import_typescript.default.sys.newLine
93
- )}`
94
- )
95
- );
96
- console.error(
97
- import_ansi_colors.default.red(
98
- ` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`
99
- )
100
- );
101
- };
102
- var retrieveMfTypesPath = (tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, ""));
103
- var retrieveOriginalOutDir = (tsConfig, remoteOptions) => (0, import_path.normalize)(
104
- tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")
105
- );
106
- var retrieveMfAPITypesPath = (tsConfig, remoteOptions) => (0, import_path.join)(
107
- retrieveOriginalOutDir(tsConfig, remoteOptions),
108
- `${remoteOptions.typesFolder}.d.ts`
109
- );
110
- var createHost = (mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
131
+ var reportCompileDiagnostic = /* @__PURE__ */ __name((diagnostic) => {
132
+ const { line } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
133
+ console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
134
+ console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
135
+ }, "reportCompileDiagnostic");
136
+ var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
137
+ var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
138
+ var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
139
+ var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
111
140
  const host = import_typescript.default.createCompilerHost(tsConfig);
112
141
  const originalWriteFile = host.writeFile;
113
- const mapExposeToEntry = Object.fromEntries(
114
- Object.entries(mapComponentsToExpose).map(([exposed, filename]) => [
115
- (0, import_path.normalize)(filename),
116
- exposed
117
- ])
118
- );
142
+ const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => [
143
+ (0, import_path.normalize)(filename),
144
+ exposed
145
+ ]));
119
146
  const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
120
147
  host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
121
- originalWriteFile(
122
- filepath,
123
- text,
124
- writeOrderByteMark,
125
- onError,
126
- sourceFiles,
127
- data
128
- );
148
+ originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
129
149
  for (const sourceFile of sourceFiles || []) {
130
- const sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
150
+ let sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
151
+ if (sourceEntry === ".") {
152
+ sourceEntry = "index";
153
+ }
131
154
  if (sourceEntry) {
132
- const mfeTypeEntry = (0, import_path.join)(
133
- mfTypePath,
134
- `${sourceEntry}${DEFINITION_FILE_EXTENSION}`
135
- );
155
+ const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
136
156
  const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
137
157
  const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filepath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
138
- originalWriteFile(
139
- mfeTypeEntry,
140
- `export * from './${relativePathToOutput}';
141
- export { default } from './${relativePathToOutput}';`,
142
- writeOrderByteMark
143
- );
158
+ originalWriteFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
159
+ export { default } from './${relativePathToOutput}';`, writeOrderByteMark);
144
160
  }
145
161
  }
146
162
  cb(text);
147
163
  };
148
164
  return host;
149
- };
150
- var createVueTscProgram = (programOptions) => {
165
+ }, "createHost");
166
+ var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
151
167
  const vueTypescript = require("vue-tsc");
152
168
  return vueTypescript.createProgram(programOptions);
153
- };
154
- var createProgram = (remoteOptions, programOptions) => {
169
+ }, "createVueTscProgram");
170
+ var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
155
171
  switch (remoteOptions.compilerInstance) {
156
172
  case "vue-tsc":
157
173
  return createVueTscProgram(programOptions);
@@ -159,13 +175,10 @@ var createProgram = (remoteOptions, programOptions) => {
159
175
  default:
160
176
  return import_typescript.default.createProgram(programOptions);
161
177
  }
162
- };
163
- var compileTs = (mapComponentsToExpose, tsConfig, remoteOptions) => {
178
+ }, "createProgram");
179
+ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
164
180
  const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
165
- const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor(
166
- (0, import_path.resolve)(mfTypePath, "node_modules"),
167
- remoteOptions.context
168
- );
181
+ const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
169
182
  const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
170
183
  const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
171
184
  const filesToCompile = [
@@ -183,52 +196,77 @@ var compileTs = (mapComponentsToExpose, tsConfig, remoteOptions) => {
183
196
  if (remoteOptions.extractThirdParty) {
184
197
  thirdPartyExtractor.copyDts();
185
198
  }
186
- };
199
+ }, "compileTs");
187
200
 
188
201
  // packages/dts-plugin/src/server/message/Message.ts
189
- var Message = class {
202
+ var _Message = class _Message {
190
203
  constructor(type, kind) {
204
+ __publicField(this, "type");
205
+ __publicField(this, "kind");
206
+ __publicField(this, "time");
191
207
  this.type = type;
192
208
  this.kind = kind;
193
209
  this.time = Date.now();
194
210
  }
195
211
  };
212
+ __name(_Message, "Message");
213
+ var Message = _Message;
196
214
 
197
215
  // packages/dts-plugin/src/server/message/API/API.ts
198
- var API = class extends Message {
216
+ var APIKind;
217
+ (function(APIKind2) {
218
+ APIKind2["UPDATE_SUBSCRIBER"] = "UPDATE_SUBSCRIBER";
219
+ APIKind2["RELOAD_WEB_CLIENT"] = "RELOAD_WEB_CLIENT";
220
+ APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
221
+ })(APIKind || (APIKind = {}));
222
+ var _API = class _API extends Message {
199
223
  constructor(content, kind) {
200
224
  super("API", kind);
225
+ __publicField(this, "code");
226
+ __publicField(this, "payload");
201
227
  const { code, payload } = content;
202
228
  this.code = code;
203
229
  this.payload = payload;
204
230
  }
205
231
  };
232
+ __name(_API, "API");
233
+ var API = _API;
206
234
 
207
235
  // packages/dts-plugin/src/server/message/API/UpdateSubscriber.ts
208
- var UpdateSubscriberAPI = class extends API {
236
+ var _UpdateSubscriberAPI = class _UpdateSubscriberAPI extends API {
209
237
  constructor(payload) {
210
- super(
211
- {
212
- code: 0,
213
- payload
214
- },
215
- "UPDATE_SUBSCRIBER" /* UPDATE_SUBSCRIBER */
216
- );
238
+ super({
239
+ code: 0,
240
+ payload
241
+ }, APIKind.UPDATE_SUBSCRIBER);
217
242
  }
218
243
  };
244
+ __name(_UpdateSubscriberAPI, "UpdateSubscriberAPI");
245
+ var UpdateSubscriberAPI = _UpdateSubscriberAPI;
219
246
 
220
247
  // packages/dts-plugin/src/server/message/API/ReloadWebClient.ts
221
- var ReloadWebClientAPI = class extends API {
248
+ var _ReloadWebClientAPI = class _ReloadWebClientAPI extends API {
222
249
  constructor(payload) {
223
- super(
224
- {
225
- code: 0,
226
- payload
227
- },
228
- "RELOAD_WEB_CLIENT" /* RELOAD_WEB_CLIENT */
229
- );
250
+ super({
251
+ code: 0,
252
+ payload
253
+ }, APIKind.RELOAD_WEB_CLIENT);
230
254
  }
231
255
  };
256
+ __name(_ReloadWebClientAPI, "ReloadWebClientAPI");
257
+ var ReloadWebClientAPI = _ReloadWebClientAPI;
258
+
259
+ // packages/dts-plugin/src/server/message/API/FetchTypes.ts
260
+ var _FetchTypesAPI = class _FetchTypesAPI extends API {
261
+ constructor(payload) {
262
+ super({
263
+ code: 0,
264
+ payload
265
+ }, APIKind.FETCH_TYPES);
266
+ }
267
+ };
268
+ __name(_FetchTypesAPI, "FetchTypesAPI");
269
+ var FetchTypesAPI = _FetchTypesAPI;
232
270
 
233
271
  // packages/dts-plugin/src/server/utils/index.ts
234
272
  var import_sdk2 = require("@module-federation/sdk");
@@ -237,21 +275,37 @@ var import_sdk2 = require("@module-federation/sdk");
237
275
  var import_chalk = __toESM(require("chalk"));
238
276
 
239
277
  // packages/dts-plugin/src/server/message/Log/Log.ts
240
- var Log = class extends Message {
278
+ var LogLevel;
279
+ (function(LogLevel2) {
280
+ LogLevel2["LOG"] = "LOG";
281
+ LogLevel2["WARN"] = "WARN";
282
+ LogLevel2["ERROR"] = "ERROR";
283
+ })(LogLevel || (LogLevel = {}));
284
+ var LogKind;
285
+ (function(LogKind2) {
286
+ LogKind2["BrokerExitLog"] = "BrokerExitLog";
287
+ LogKind2["PublisherRegisteredLog"] = "PublisherRegisteredLog";
288
+ })(LogKind || (LogKind = {}));
289
+ var _Log = class _Log extends Message {
241
290
  constructor(level, kind, ignoreVerbose = false) {
242
291
  super("Log", kind);
243
- this.ignoreVerbose = false;
292
+ __publicField(this, "level");
293
+ __publicField(this, "ignoreVerbose", false);
244
294
  this.level = level;
245
295
  this.ignoreVerbose = ignoreVerbose;
246
296
  }
247
297
  };
298
+ __name(_Log, "Log");
299
+ var Log = _Log;
248
300
 
249
301
  // packages/dts-plugin/src/server/message/Log/BrokerExitLog.ts
250
- var BrokerExitLog = class extends Log {
302
+ var _BrokerExitLog = class _BrokerExitLog extends Log {
251
303
  constructor() {
252
- super("LOG" /* LOG */, "BrokerExitLog" /* BrokerExitLog */);
304
+ super(LogLevel.LOG, LogKind.BrokerExitLog);
253
305
  }
254
306
  };
307
+ __name(_BrokerExitLog, "BrokerExitLog");
308
+ var BrokerExitLog = _BrokerExitLog;
255
309
 
256
310
  // packages/dts-plugin/src/server/utils/log.ts
257
311
  var import_sdk = require("@module-federation/sdk");
@@ -264,43 +318,70 @@ var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
264
318
 
265
319
  // packages/dts-plugin/src/server/utils/log.ts
266
320
  function fileLog(msg, module2, level) {
267
- var _a, _b;
268
- if (!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a["FEDERATION_DEBUG"])) {
321
+ var _a3, _b;
322
+ if (!((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3["FEDERATION_DEBUG"])) {
269
323
  return;
270
324
  }
271
325
  log4js.configure({
272
326
  appenders: {
273
- [module2]: { type: "file", filename: ".mf/typesGenerate.log" },
274
- default: { type: "file", filename: ".mf/typesGenerate.log" }
327
+ [module2]: {
328
+ type: "file",
329
+ filename: ".mf/typesGenerate.log"
330
+ },
331
+ default: {
332
+ type: "file",
333
+ filename: ".mf/typesGenerate.log"
334
+ }
275
335
  },
276
336
  categories: {
277
- [module2]: { appenders: [module2], level: "error" },
278
- default: { appenders: ["default"], level: "trace" }
337
+ [module2]: {
338
+ appenders: [
339
+ module2
340
+ ],
341
+ level: "error"
342
+ },
343
+ default: {
344
+ appenders: [
345
+ "default"
346
+ ],
347
+ level: "trace"
348
+ }
279
349
  }
280
350
  });
281
351
  const logger4 = log4js.getLogger(module2);
282
352
  logger4.level = "debug";
283
353
  (_b = logger4[level]) == null ? void 0 : _b.call(logger4, msg);
284
354
  }
355
+ __name(fileLog, "fileLog");
285
356
  function error(error2, action, from) {
286
357
  const err = error2 instanceof Error ? error2 : new Error(`${action} error`);
287
358
  fileLog(`[${action}] error: ${err}`, from, "fatal");
288
359
  return err.toString();
289
360
  }
361
+ __name(error, "error");
290
362
 
291
363
  // packages/dts-plugin/src/server/utils/index.ts
292
364
  function getIdentifier(options) {
293
365
  const { ip, name } = options;
294
366
  return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
295
367
  }
368
+ __name(getIdentifier, "getIdentifier");
296
369
 
297
370
  // packages/dts-plugin/src/server/Publisher.ts
298
- var Publisher = class {
371
+ var _Publisher = class _Publisher {
299
372
  constructor(ctx) {
373
+ __publicField(this, "_ip");
374
+ __publicField(this, "_name");
375
+ __publicField(this, "_remoteTypeTarPath");
376
+ __publicField(this, "_subscribers");
377
+ __publicField(this, "_ws");
378
+ __publicField(this, "dynamicRemoteMap");
300
379
  this._name = ctx.name;
301
380
  this._ip = ctx.ip;
302
381
  this._remoteTypeTarPath = ctx.remoteTypeTarPath;
303
382
  this._subscribers = /* @__PURE__ */ new Map();
383
+ this._ws = ctx.ws;
384
+ this.dynamicRemoteMap = /* @__PURE__ */ new Map();
304
385
  }
305
386
  get identifier() {
306
387
  return getIdentifier({
@@ -329,33 +410,27 @@ var Publisher = class {
329
410
  }
330
411
  removeSubscriber(identifier) {
331
412
  if (this._subscribers.has(identifier)) {
332
- fileLog(
333
- `${this.name} removeSubscriber: ${identifier}`,
334
- "Publisher",
335
- "warn"
336
- );
413
+ fileLog(`${this.name} removeSubscriber: ${identifier}`, "Publisher", "warn");
337
414
  this._subscribers.delete(identifier);
338
415
  }
339
416
  }
340
417
  notifySubscriber(subscriberIdentifier, options) {
341
418
  const subscriber = this._subscribers.get(subscriberIdentifier);
342
419
  if (!subscriber) {
343
- fileLog(
344
- `[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`,
345
- "Publisher",
346
- "error"
347
- );
420
+ fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`, "Publisher", "error");
348
421
  return;
349
422
  }
350
423
  const api = new UpdateSubscriberAPI(options);
351
424
  subscriber.send(JSON.stringify(api));
352
- fileLog(
353
- `[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(
354
- subscriberIdentifier
355
- )}, message: ${JSON.stringify(api)}`,
356
- "Publisher",
357
- "info"
358
- );
425
+ fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(subscriberIdentifier)}, message: ${JSON.stringify(api)}`, "Publisher", "info");
426
+ }
427
+ fetchRemoteTypes(options) {
428
+ fileLog(`[fetchRemoteTypes] ${this.name} fetchRemoteTypes, options: ${JSON.stringify(options)}, ws: ${Boolean(this._ws)}`, "Publisher", "info");
429
+ if (!this._ws) {
430
+ return;
431
+ }
432
+ const api = new FetchTypesAPI(options);
433
+ this._ws.send(JSON.stringify(api));
359
434
  }
360
435
  notifySubscribers(options) {
361
436
  const api = new UpdateSubscriberAPI(options);
@@ -364,32 +439,23 @@ var Publisher = class {
364
439
  broadcast(message) {
365
440
  if (this.hasSubscribes) {
366
441
  this._subscribers.forEach((subscriber, key) => {
367
- fileLog(
368
- `[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`,
369
- "Publisher",
370
- "info"
371
- );
442
+ fileLog(`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`, "Publisher", "info");
372
443
  subscriber.send(JSON.stringify(message));
373
444
  });
374
445
  } else {
375
- fileLog(
376
- `[BroadCast] ${this.name}'s subscribe is empty`,
377
- "Publisher",
378
- "warn"
379
- );
446
+ fileLog(`[BroadCast] ${this.name}'s subscribe is empty`, "Publisher", "warn");
380
447
  }
381
448
  }
382
449
  close() {
450
+ this._ws = void 0;
383
451
  this._subscribers.forEach((_subscriber, identifier) => {
384
- fileLog(
385
- `[BroadCast] close ${this.name} remove: ${identifier}`,
386
- "Publisher",
387
- "warn"
388
- );
452
+ fileLog(`[BroadCast] close ${this.name} remove: ${identifier}`, "Publisher", "warn");
389
453
  this.removeSubscriber(identifier);
390
454
  });
391
455
  }
392
456
  };
457
+ __name(_Publisher, "Publisher");
458
+ var Publisher = _Publisher;
393
459
 
394
460
  // packages/dts-plugin/src/server/DevServer.ts
395
461
  var import_isomorphic_ws2 = __toESM(require("isomorphic-ws"));
@@ -399,13 +465,48 @@ var import_http = require("http");
399
465
  var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
400
466
  var import_node_schedule = __toESM(require("node-schedule"));
401
467
  var import_url = require("url");
468
+
469
+ // packages/dts-plugin/src/server/message/Action/Action.ts
470
+ var ActionKind;
471
+ (function(ActionKind2) {
472
+ ActionKind2["ADD_SUBSCRIBER"] = "ADD_SUBSCRIBER";
473
+ ActionKind2["EXIT_SUBSCRIBER"] = "EXIT_SUBSCRIBER";
474
+ ActionKind2["ADD_PUBLISHER"] = "ADD_PUBLISHER";
475
+ ActionKind2["UPDATE_PUBLISHER"] = "UPDATE_PUBLISHER";
476
+ ActionKind2["NOTIFY_SUBSCRIBER"] = "NOTIFY_SUBSCRIBER";
477
+ ActionKind2["EXIT_PUBLISHER"] = "EXIT_PUBLISHER";
478
+ ActionKind2["ADD_WEB_CLIENT"] = "ADD_WEB_CLIENT";
479
+ ActionKind2["NOTIFY_WEB_CLIENT"] = "NOTIFY_WEB_CLIENT";
480
+ ActionKind2["FETCH_TYPES"] = "FETCH_TYPES";
481
+ ActionKind2["ADD_DYNAMIC_REMOTE"] = "ADD_DYNAMIC_REMOTE";
482
+ })(ActionKind || (ActionKind = {}));
483
+
484
+ // packages/dts-plugin/src/server/message/Action/Update.ts
485
+ var UpdateKind;
486
+ (function(UpdateKind2) {
487
+ UpdateKind2["UPDATE_TYPE"] = "UPDATE_TYPE";
488
+ UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
489
+ })(UpdateKind || (UpdateKind = {}));
490
+
491
+ // packages/dts-plugin/src/core/constant.ts
492
+ var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
493
+ var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
494
+ var HOST_API_TYPES_FILE_NAME = "index.d.ts";
495
+ var UpdateMode;
496
+ (function(UpdateMode2) {
497
+ UpdateMode2["POSITIVE"] = "POSITIVE";
498
+ UpdateMode2["PASSIVE"] = "PASSIVE";
499
+ })(UpdateMode || (UpdateMode = {}));
500
+
501
+ // packages/dts-plugin/src/server/broker/Broker.ts
402
502
  var _Broker = class _Broker {
403
503
  constructor() {
404
- // 1.5h
405
- this._publisherMap = /* @__PURE__ */ new Map();
406
- this._webClientMap = /* @__PURE__ */ new Map();
407
- this._tmpSubscriberShelter = /* @__PURE__ */ new Map();
408
- this._scheduleJob = null;
504
+ __publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
505
+ __publicField(this, "_webClientMap", /* @__PURE__ */ new Map());
506
+ __publicField(this, "_webSocketServer");
507
+ __publicField(this, "_secureWebSocketServer");
508
+ __publicField(this, "_tmpSubscriberShelter", /* @__PURE__ */ new Map());
509
+ __publicField(this, "_scheduleJob", null);
409
510
  this._setSchedule();
410
511
  this._startWsServer();
411
512
  this._stopWhenSIGTERMOrSIGINT();
@@ -414,389 +515,407 @@ var _Broker = class _Broker {
414
515
  get hasPublishers() {
415
516
  return Boolean(this._publisherMap.size);
416
517
  }
417
- async _startWsServer() {
418
- const wsHandler = (ws, req) => {
419
- const { url: reqUrl = "" } = req;
420
- const { query } = (0, import_url.parse)(reqUrl, true);
421
- const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
422
- if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
423
- ws.on("message", (message) => {
424
- try {
425
- const text = message.toString();
426
- const action = JSON.parse(text);
427
- fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
428
- this._takeAction(action, ws);
429
- } catch (error2) {
430
- fileLog(`parse action message error: ${error2}`, "Broker", "error");
431
- }
432
- });
433
- ws.on("error", (e) => {
434
- fileLog(`parse action message error: ${e}`, "Broker", "error");
435
- });
436
- } else {
437
- ws.send("Invalid CONNECT ID.");
438
- fileLog("Invalid CONNECT ID.", "Broker", "warn");
439
- ws.close();
440
- }
441
- };
442
- const server = (0, import_http.createServer)();
443
- this._webSocketServer = new import_isomorphic_ws.default.Server({ noServer: true });
444
- this._webSocketServer.on("error", (err) => {
445
- fileLog(`ws error:
518
+ _startWsServer() {
519
+ return __async(this, null, function* () {
520
+ const wsHandler = /* @__PURE__ */ __name((ws, req) => {
521
+ const { url: reqUrl = "" } = req;
522
+ const { query } = (0, import_url.parse)(reqUrl, true);
523
+ const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
524
+ if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
525
+ ws.on("message", (message) => {
526
+ try {
527
+ const text = message.toString();
528
+ const action = JSON.parse(text);
529
+ fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
530
+ this._takeAction(action, ws);
531
+ } catch (error2) {
532
+ fileLog(`parse action message error: ${error2}`, "Broker", "error");
533
+ }
534
+ });
535
+ ws.on("error", (e) => {
536
+ fileLog(`parse action message error: ${e}`, "Broker", "error");
537
+ });
538
+ } else {
539
+ ws.send("Invalid CONNECT ID.");
540
+ fileLog("Invalid CONNECT ID.", "Broker", "warn");
541
+ ws.close();
542
+ }
543
+ }, "wsHandler");
544
+ const server = (0, import_http.createServer)();
545
+ this._webSocketServer = new import_isomorphic_ws.default.Server({
546
+ noServer: true
547
+ });
548
+ this._webSocketServer.on("error", (err) => {
549
+ fileLog(`ws error:
446
550
  ${err.message}
447
551
  ${err.stack}`, "Broker", "error");
552
+ });
553
+ this._webSocketServer.on("listening", () => {
554
+ fileLog(`WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`, "Broker", "info");
555
+ });
556
+ this._webSocketServer.on("connection", wsHandler);
557
+ this._webSocketServer.on("close", (code) => {
558
+ fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
559
+ this._webSocketServer && this._webSocketServer.close();
560
+ this._webSocketServer = void 0;
561
+ });
562
+ server.on("upgrade", (req, socket, head) => {
563
+ var _a3;
564
+ if (req.url) {
565
+ const { pathname } = (0, import_url.parse)(req.url);
566
+ if (pathname === "/") {
567
+ (_a3 = this._webSocketServer) == null ? void 0 : _a3.handleUpgrade(req, socket, head, (ws) => {
568
+ var _a4;
569
+ (_a4 = this._webSocketServer) == null ? void 0 : _a4.emit("connection", ws, req);
570
+ });
571
+ }
572
+ }
573
+ });
574
+ server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
448
575
  });
449
- this._webSocketServer.on("listening", () => {
450
- fileLog(
451
- `WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`,
452
- "Broker",
453
- "info"
454
- );
455
- });
456
- this._webSocketServer.on("connection", wsHandler);
457
- this._webSocketServer.on("close", (code) => {
458
- fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
459
- this._webSocketServer && this._webSocketServer.close();
460
- this._webSocketServer = void 0;
576
+ }
577
+ _takeAction(action, client) {
578
+ return __async(this, null, function* () {
579
+ const { kind, payload } = action;
580
+ if (kind === ActionKind.ADD_PUBLISHER) {
581
+ yield this._addPublisher(payload, client);
582
+ }
583
+ if (kind === ActionKind.UPDATE_PUBLISHER) {
584
+ yield this._updatePublisher(payload, client);
585
+ }
586
+ if (kind === ActionKind.ADD_SUBSCRIBER) {
587
+ yield this._addSubscriber(payload, client);
588
+ }
589
+ if (kind === ActionKind.EXIT_SUBSCRIBER) {
590
+ yield this._removeSubscriber(payload, client);
591
+ }
592
+ if (kind === ActionKind.EXIT_PUBLISHER) {
593
+ yield this._removePublisher(payload, client);
594
+ }
595
+ if (kind === ActionKind.ADD_WEB_CLIENT) {
596
+ yield this._addWebClient(payload, client);
597
+ }
598
+ if (kind === ActionKind.NOTIFY_WEB_CLIENT) {
599
+ yield this._notifyWebClient(payload, client);
600
+ }
601
+ if (kind === ActionKind.FETCH_TYPES) {
602
+ yield this._fetchTypes(payload, client);
603
+ }
604
+ if (kind === ActionKind.ADD_DYNAMIC_REMOTE) {
605
+ this._addDynamicRemote(payload);
606
+ }
461
607
  });
462
- server.on("upgrade", (req, socket, head) => {
463
- var _a;
464
- if (req.url) {
465
- const { pathname } = (0, import_url.parse)(req.url);
466
- if (pathname === "/") {
467
- (_a = this._webSocketServer) == null ? void 0 : _a.handleUpgrade(req, socket, head, (ws) => {
468
- var _a2;
469
- (_a2 = this._webSocketServer) == null ? void 0 : _a2.emit("connection", ws, req);
470
- });
608
+ }
609
+ _addPublisher(context, client) {
610
+ return __async(this, null, function* () {
611
+ const { name, ip, remoteTypeTarPath } = context != null ? context : {};
612
+ const identifier = getIdentifier({
613
+ name,
614
+ ip
615
+ });
616
+ if (this._publisherMap.has(identifier)) {
617
+ fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} has been added, this action will be ignored`, "Broker", "warn");
618
+ return;
619
+ }
620
+ try {
621
+ const publisher = new Publisher({
622
+ name,
623
+ ip,
624
+ remoteTypeTarPath,
625
+ ws: client
626
+ });
627
+ this._publisherMap.set(identifier, publisher);
628
+ fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} Adding Publisher Succeed`, "Broker", "info");
629
+ const tmpSubScribers = this._getTmpSubScribers(identifier);
630
+ if (tmpSubScribers) {
631
+ fileLog(`[${ActionKind.ADD_PUBLISHER}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `, "Broker", "info");
632
+ this._consumeTmpSubScribers(publisher, tmpSubScribers);
633
+ this._clearTmpSubScriberRelation(identifier);
471
634
  }
635
+ } catch (err) {
636
+ const msg = error(err, ActionKind.ADD_PUBLISHER, "Broker");
637
+ client.send(msg);
638
+ client.close();
472
639
  }
473
640
  });
474
- server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
475
- }
476
- async _takeAction(action, client) {
477
- const { kind, payload } = action;
478
- if (kind === "ADD_PUBLISHER" /* ADD_PUBLISHER */) {
479
- await this._addPublisher(payload, client);
480
- }
481
- if (kind === "UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */) {
482
- await this._updatePublisher(
483
- payload,
484
- client
485
- );
486
- }
487
- if (kind === "ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */) {
488
- await this._addSubscriber(payload, client);
489
- }
490
- if (kind === "EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */) {
491
- await this._removeSubscriber(
492
- payload,
493
- client
494
- );
495
- }
496
- if (kind === "EXIT_PUBLISHER" /* EXIT_PUBLISHER */) {
497
- await this._removePublisher(payload, client);
498
- }
499
- if (kind === "ADD_WEB_CLIENT" /* ADD_WEB_CLIENT */) {
500
- await this._addWebClient(payload, client);
501
- }
502
- if (kind === "NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */) {
503
- await this._notifyWebClient(
504
- payload,
505
- client
506
- );
507
- }
508
641
  }
509
- async _addPublisher(context, client) {
510
- const { name, ip, remoteTypeTarPath } = context ?? {};
511
- const identifier = getIdentifier({ name, ip });
512
- if (this._publisherMap.has(identifier)) {
513
- fileLog(
514
- `[${"ADD_PUBLISHER" /* ADD_PUBLISHER */}] ${identifier} has been added, this action will be ignored`,
515
- "Broker",
516
- "warn"
517
- );
518
- return;
519
- }
520
- try {
521
- const publisher = new Publisher({ name, ip, remoteTypeTarPath });
522
- this._publisherMap.set(identifier, publisher);
523
- fileLog(
524
- `[${"ADD_PUBLISHER" /* ADD_PUBLISHER */}] ${identifier} Adding Publisher Succeed`,
525
- "Broker",
526
- "info"
527
- );
528
- const tmpSubScribers = this._getTmpSubScribers(identifier);
529
- if (tmpSubScribers) {
642
+ _updatePublisher(context, client) {
643
+ return __async(this, null, function* () {
644
+ const { name, updateMode, updateKind, updateSourcePaths, remoteTypeTarPath, ip } = context != null ? context : {};
645
+ const identifier = getIdentifier({
646
+ name,
647
+ ip
648
+ });
649
+ if (!this._publisherMap.has(identifier)) {
650
+ fileLog(`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} has not been started, this action will be ignored
651
+ this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
652
+ `, "Broker", "warn");
653
+ return;
654
+ }
655
+ try {
656
+ const publisher = this._publisherMap.get(identifier);
530
657
  fileLog(
531
- `[${"ADD_PUBLISHER" /* ADD_PUBLISHER */}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `,
658
+ // eslint-disable-next-line max-len
659
+ `[${ActionKind.UPDATE_PUBLISHER}] ${identifier} update, and notify subscribers to update`,
532
660
  "Broker",
533
661
  "info"
534
662
  );
535
- this._consumeTmpSubScribers(publisher, tmpSubScribers);
536
- this._clearTmpSubScriberRelation(identifier);
663
+ if (publisher) {
664
+ publisher.notifySubscribers({
665
+ remoteTypeTarPath,
666
+ name,
667
+ updateMode,
668
+ updateKind,
669
+ updateSourcePaths: updateSourcePaths || []
670
+ });
671
+ this._publisherMap.forEach((p) => {
672
+ if (p.name === publisher.name) {
673
+ return;
674
+ }
675
+ const dynamicRemoteInfo = p.dynamicRemoteMap.get(identifier);
676
+ if (dynamicRemoteInfo) {
677
+ fileLog(
678
+ // eslint-disable-next-line max-len
679
+ `dynamicRemoteInfo: ${JSON.stringify(dynamicRemoteInfo)}, identifier:${identifier} publish: ${p.name}`,
680
+ "Broker",
681
+ "info"
682
+ );
683
+ p.fetchRemoteTypes({
684
+ remoteInfo: dynamicRemoteInfo,
685
+ once: false
686
+ });
687
+ }
688
+ });
689
+ }
690
+ } catch (err) {
691
+ const msg = error(err, ActionKind.UPDATE_PUBLISHER, "Broker");
692
+ client.send(msg);
693
+ client.close();
537
694
  }
538
- } catch (err) {
539
- const msg = error(err, "ADD_PUBLISHER" /* ADD_PUBLISHER */, "Broker");
540
- client.send(msg);
541
- client.close();
542
- }
695
+ });
543
696
  }
544
- async _updatePublisher(context, client) {
545
- const {
697
+ _fetchTypes(context, _client) {
698
+ return __async(this, null, function* () {
699
+ const { name, ip, remoteInfo } = context != null ? context : {};
700
+ const identifier = getIdentifier({
701
+ name,
702
+ ip
703
+ });
704
+ try {
705
+ const publisher = this._publisherMap.get(identifier);
706
+ fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types`, "Broker", "info");
707
+ if (publisher) {
708
+ publisher.fetchRemoteTypes({
709
+ remoteInfo,
710
+ once: true
711
+ });
712
+ }
713
+ } catch (err) {
714
+ fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types fail , error info: ${err}`, "Broker", "error");
715
+ }
716
+ });
717
+ }
718
+ _addDynamicRemote(context) {
719
+ const { name, ip, remoteInfo, remoteIp } = context != null ? context : {};
720
+ const identifier = getIdentifier({
546
721
  name,
547
- updateMode,
548
- updateKind,
549
- updateSourcePaths,
550
- remoteTypeTarPath,
551
722
  ip
552
- } = context ?? {};
553
- const identifier = getIdentifier({ name, ip });
554
- if (!this._publisherMap.has(identifier)) {
555
- fileLog(
556
- `[${"UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */}] ${identifier} has not been started, this action will be ignored
557
- this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
558
- `,
559
- "Broker",
560
- "warn"
561
- );
723
+ });
724
+ const publisher = this._publisherMap.get(identifier);
725
+ const remoteId = getIdentifier({
726
+ name: remoteInfo.name,
727
+ ip: remoteIp
728
+ });
729
+ fileLog(`[${ActionKind.ADD_DYNAMIC_REMOTE}] identifier:${identifier},publisher: ${publisher.name}, remoteId:${remoteId}`, "Broker", "error");
730
+ if (!publisher || publisher.dynamicRemoteMap.has(remoteId)) {
562
731
  return;
563
732
  }
564
- try {
565
- const publisher = this._publisherMap.get(identifier);
566
- fileLog(
567
- // eslint-disable-next-line max-len
568
- `[${"UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */}] ${identifier} update, and notify subscribers to update`,
569
- "Broker",
570
- "info"
571
- );
572
- if (publisher) {
573
- publisher.notifySubscribers({
574
- remoteTypeTarPath,
575
- name,
576
- updateMode,
577
- updateKind,
578
- updateSourcePaths: updateSourcePaths || []
579
- });
580
- }
581
- } catch (err) {
582
- const msg = error(err, "UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */, "Broker");
583
- client.send(msg);
584
- client.close();
585
- }
733
+ publisher.dynamicRemoteMap.set(remoteId, remoteInfo);
586
734
  }
587
735
  // app1 consumes provider1,provider2. Dependencies at this time: publishers: [provider1, provider2], subscriberName: app1
588
736
  // provider1 is app1's remote
589
- async _addSubscriber(context, client) {
590
- const { publishers, name: subscriberName } = context ?? {};
591
- publishers.forEach((publisher) => {
592
- const { name, ip } = publisher;
593
- const identifier = getIdentifier({ name, ip });
594
- if (!this._publisherMap.has(identifier)) {
595
- fileLog(
596
- `[${"ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`,
597
- "Broker",
598
- "warn"
599
- );
600
- this._addTmpSubScriberRelation(
601
- {
737
+ _addSubscriber(context, client) {
738
+ return __async(this, null, function* () {
739
+ const { publishers, name: subscriberName } = context != null ? context : {};
740
+ publishers.forEach((publisher) => {
741
+ const { name, ip } = publisher;
742
+ const identifier = getIdentifier({
743
+ name,
744
+ ip
745
+ });
746
+ if (!this._publisherMap.has(identifier)) {
747
+ fileLog(`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`, "Broker", "warn");
748
+ this._addTmpSubScriberRelation({
602
749
  name: getIdentifier({
603
750
  name: context.name,
604
751
  ip: context.ip
605
752
  }),
606
753
  client
607
- },
608
- publisher
609
- );
610
- return;
611
- }
612
- try {
613
- const registeredPublisher = this._publisherMap.get(identifier);
614
- if (registeredPublisher) {
615
- registeredPublisher.addSubscriber(
616
- getIdentifier({
754
+ }, publisher);
755
+ return;
756
+ }
757
+ try {
758
+ const registeredPublisher = this._publisherMap.get(identifier);
759
+ if (registeredPublisher) {
760
+ registeredPublisher.addSubscriber(getIdentifier({
617
761
  name: subscriberName,
618
762
  ip: context.ip
619
- }),
620
- client
621
- );
622
- fileLog(
623
- // eslint-disable-next-line @ies/eden/max-calls-in-template
624
- `[${"ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(
625
- Array.from(this._publisherMap.entries())
626
- )}`,
627
- "Broker",
628
- "info"
629
- );
630
- registeredPublisher.notifySubscriber(
631
- getIdentifier({
763
+ }), client);
764
+ fileLog(
765
+ // eslint-disable-next-line @ies/eden/max-calls-in-template
766
+ `[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(Array.from(this._publisherMap.entries()))}`,
767
+ "Broker",
768
+ "info"
769
+ );
770
+ registeredPublisher.notifySubscriber(getIdentifier({
632
771
  name: subscriberName,
633
772
  ip: context.ip
634
- }),
635
- {
636
- updateKind: "UPDATE_TYPE" /* UPDATE_TYPE */,
637
- updateMode: "PASSIVE" /* PASSIVE */,
638
- updateSourcePaths: [registeredPublisher.name],
773
+ }), {
774
+ updateKind: UpdateKind.UPDATE_TYPE,
775
+ updateMode: UpdateMode.PASSIVE,
776
+ updateSourcePaths: [
777
+ registeredPublisher.name
778
+ ],
639
779
  remoteTypeTarPath: registeredPublisher.remoteTypeTarPath,
640
780
  name: registeredPublisher.name
641
- }
642
- );
643
- fileLog(
644
- // eslint-disable-next-line @ies/eden/max-calls-in-template
645
- `[${"ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
646
- "Broker",
647
- "info"
648
- );
781
+ });
782
+ fileLog(
783
+ // eslint-disable-next-line @ies/eden/max-calls-in-template
784
+ `[${ActionKind.ADD_SUBSCRIBER}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
785
+ "Broker",
786
+ "info"
787
+ );
788
+ }
789
+ } catch (err) {
790
+ const msg = error(err, ActionKind.ADD_SUBSCRIBER, "Broker");
791
+ client.send(msg);
792
+ client.close();
649
793
  }
650
- } catch (err) {
651
- const msg = error(err, "ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */, "Broker");
652
- client.send(msg);
653
- client.close();
654
- }
794
+ });
655
795
  });
656
796
  }
657
797
  // Trigger while consumer exit
658
- async _removeSubscriber(context, client) {
659
- const { publishers } = context ?? {};
660
- const subscriberIdentifier = getIdentifier({
661
- name: context == null ? void 0 : context.name,
662
- ip: context == null ? void 0 : context.ip
798
+ _removeSubscriber(context, client) {
799
+ return __async(this, null, function* () {
800
+ const { publishers } = context != null ? context : {};
801
+ const subscriberIdentifier = getIdentifier({
802
+ name: context == null ? void 0 : context.name,
803
+ ip: context == null ? void 0 : context.ip
804
+ });
805
+ publishers.forEach((publisher) => {
806
+ const { name, ip } = publisher;
807
+ const identifier = getIdentifier({
808
+ name,
809
+ ip
810
+ });
811
+ const registeredPublisher = this._publisherMap.get(identifier);
812
+ if (!registeredPublisher) {
813
+ fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} does not exit `, "Broker", "warn");
814
+ return;
815
+ }
816
+ try {
817
+ fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} will exit `, "Broker", "INFO");
818
+ registeredPublisher.removeSubscriber(subscriberIdentifier);
819
+ this._clearTmpSubScriberRelation(identifier);
820
+ if (!registeredPublisher.hasSubscribes) {
821
+ this._publisherMap.delete(identifier);
822
+ }
823
+ if (!this.hasPublishers) {
824
+ this.exit();
825
+ }
826
+ } catch (err) {
827
+ const msg = error(err, ActionKind.EXIT_SUBSCRIBER, "Broker");
828
+ client.send(msg);
829
+ client.close();
830
+ }
831
+ });
663
832
  });
664
- publishers.forEach((publisher) => {
665
- const { name, ip } = publisher;
833
+ }
834
+ _removePublisher(context, client) {
835
+ return __async(this, null, function* () {
836
+ const { name, ip } = context != null ? context : {};
666
837
  const identifier = getIdentifier({
667
838
  name,
668
839
  ip
669
840
  });
670
- const registeredPublisher = this._publisherMap.get(identifier);
671
- if (!registeredPublisher) {
672
- fileLog(
673
- `[${"EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */}], ${identifier} does not exit `,
674
- "Broker",
675
- "warn"
676
- );
841
+ const publisher = this._publisherMap.get(identifier);
842
+ if (!publisher) {
843
+ fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier}} has not been added, this action will be ingored`, "Broker", "warn");
677
844
  return;
678
845
  }
679
846
  try {
680
- fileLog(
681
- `[${"EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */}], ${identifier} will exit `,
682
- "Broker",
683
- "INFO"
684
- );
685
- registeredPublisher.removeSubscriber(subscriberIdentifier);
686
- this._clearTmpSubScriberRelation(identifier);
687
- if (!registeredPublisher.hasSubscribes) {
688
- this._publisherMap.delete(identifier);
689
- }
690
- if (!this.hasPublishers) {
691
- this.exit();
692
- }
693
- } catch (err) {
694
- const msg = error(err, "EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */, "Broker");
695
- client.send(msg);
696
- client.close();
697
- }
698
- });
699
- }
700
- async _removePublisher(context, client) {
701
- const { name, ip } = context ?? {};
702
- const identifier = getIdentifier({
703
- name,
704
- ip
705
- });
706
- const publisher = this._publisherMap.get(identifier);
707
- if (!publisher) {
708
- fileLog(
709
- `[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier}} has not been added, this action will be ingored`,
710
- "Broker",
711
- "warn"
712
- );
713
- return;
714
- }
715
- try {
716
- const { subscribers } = publisher;
717
- subscribers.forEach((subscriber, subscriberIdentifier) => {
718
- this._addTmpSubScriberRelation(
719
- {
847
+ const { subscribers } = publisher;
848
+ subscribers.forEach((subscriber, subscriberIdentifier) => {
849
+ this._addTmpSubScriberRelation({
720
850
  name: subscriberIdentifier,
721
851
  client: subscriber
722
- },
723
- { name: publisher.name, ip: publisher.ip }
724
- );
725
- fileLog(
726
- // eslint-disable-next-line max-len
727
- `[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
728
- "Broker",
729
- "info"
730
- );
731
- });
732
- this._publisherMap.delete(identifier);
733
- fileLog(
734
- `[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier} is removed `,
735
- "Broker",
736
- "info"
737
- );
738
- if (!this.hasPublishers) {
739
- fileLog(
740
- `[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: _publisherMap is empty, all server will exit `,
741
- "Broker",
742
- "warn"
743
- );
744
- this.exit();
852
+ }, {
853
+ name: publisher.name,
854
+ ip: publisher.ip
855
+ });
856
+ fileLog(
857
+ // eslint-disable-next-line max-len
858
+ `[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
859
+ "Broker",
860
+ "info"
861
+ );
862
+ });
863
+ this._publisherMap.delete(identifier);
864
+ fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removed `, "Broker", "info");
865
+ if (!this.hasPublishers) {
866
+ fileLog(`[${ActionKind.EXIT_PUBLISHER}]: _publisherMap is empty, all server will exit `, "Broker", "warn");
867
+ this.exit();
868
+ }
869
+ } catch (err) {
870
+ const msg = error(err, ActionKind.EXIT_PUBLISHER, "Broker");
871
+ client.send(msg);
872
+ client.close();
745
873
  }
746
- } catch (err) {
747
- const msg = error(err, "EXIT_PUBLISHER" /* EXIT_PUBLISHER */, "Broker");
748
- client.send(msg);
749
- client.close();
750
- }
874
+ });
751
875
  }
752
- async _addWebClient(context, client) {
753
- const { name } = context ?? {};
754
- const identifier = getIdentifier({
755
- name
876
+ _addWebClient(context, client) {
877
+ return __async(this, null, function* () {
878
+ const { name } = context != null ? context : {};
879
+ const identifier = getIdentifier({
880
+ name
881
+ });
882
+ if (this._webClientMap.has(identifier)) {
883
+ fileLog(`${identifier}} has been added, this action will override prev WebClient`, "Broker", "warn");
884
+ }
885
+ try {
886
+ this._webClientMap.set(identifier, client);
887
+ fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
888
+ } catch (err) {
889
+ const msg = error(err, ActionKind.ADD_WEB_CLIENT, "Broker");
890
+ client.send(msg);
891
+ client.close();
892
+ }
756
893
  });
757
- if (this._webClientMap.has(identifier)) {
758
- fileLog(
759
- `${identifier}} has been added, this action will override prev WebClient`,
760
- "Broker",
761
- "warn"
762
- );
763
- }
764
- try {
765
- this._webClientMap.set(identifier, client);
766
- fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
767
- } catch (err) {
768
- const msg = error(err, "ADD_WEB_CLIENT" /* ADD_WEB_CLIENT */, "Broker");
769
- client.send(msg);
770
- client.close();
771
- }
772
894
  }
773
- async _notifyWebClient(context, client) {
774
- const { name, updateMode } = context ?? {};
775
- const identifier = getIdentifier({
776
- name
895
+ _notifyWebClient(context, client) {
896
+ return __async(this, null, function* () {
897
+ const { name, updateMode } = context != null ? context : {};
898
+ const identifier = getIdentifier({
899
+ name
900
+ });
901
+ const webClient = this._webClientMap.get(identifier);
902
+ if (!webClient) {
903
+ fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] ${identifier} has not been added, this action will be ignored`, "Broker", "warn");
904
+ return;
905
+ }
906
+ try {
907
+ const api = new ReloadWebClientAPI({
908
+ name,
909
+ updateMode
910
+ });
911
+ webClient.send(JSON.stringify(api));
912
+ fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] Notify ${name} WebClient Succeed`, "Broker", "info");
913
+ } catch (err) {
914
+ const msg = error(err, ActionKind.NOTIFY_WEB_CLIENT, "Broker");
915
+ client.send(msg);
916
+ client.close();
917
+ }
777
918
  });
778
- const webClient = this._webClientMap.get(identifier);
779
- if (!webClient) {
780
- fileLog(
781
- `[${"NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */}] ${identifier} has not been added, this action will be ignored`,
782
- "Broker",
783
- "warn"
784
- );
785
- return;
786
- }
787
- try {
788
- const api = new ReloadWebClientAPI({ name, updateMode });
789
- webClient.send(JSON.stringify(api));
790
- fileLog(
791
- `[${"NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */}] Notify ${name} WebClient Succeed`,
792
- "Broker",
793
- "info"
794
- );
795
- } catch (err) {
796
- const msg = error(err, "NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */, "Broker");
797
- client.send(msg);
798
- client.close();
799
- }
800
919
  }
801
920
  // app1 consumes provider1, and provider1 not launch. this._tmpSubscriberShelter at this time: {provider1: Map{subscribers: Map{app1: app1+ip+client'}, timestamp: 'xx'} }
802
921
  _addTmpSubScriberRelation(subscriber, publisher) {
@@ -813,20 +932,12 @@ ${err.message}
813
932
  subscribers: map,
814
933
  timestamp: Date.now()
815
934
  });
816
- fileLog(
817
- `[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `,
818
- "Broker",
819
- "info"
820
- );
935
+ fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `, "Broker", "info");
821
936
  return;
822
937
  }
823
938
  const tmpSubScriberShelterSubscriber = shelter.subscribers.get(subscriberIdentifier);
824
939
  if (tmpSubScriberShelterSubscriber) {
825
- fileLog(
826
- `[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`,
827
- "Broker",
828
- "warn"
829
- );
940
+ fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`, "Broker", "warn");
830
941
  shelter.subscribers.set(subscriberIdentifier, subscriber);
831
942
  shelter.timestamp = Date.now();
832
943
  } else {
@@ -840,22 +951,20 @@ ${err.message}
840
951
  }
841
952
  }
842
953
  _getTmpSubScribers(publisherIdentifier) {
843
- var _a;
844
- return (_a = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a.subscribers;
954
+ var _a3;
955
+ return (_a3 = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a3.subscribers;
845
956
  }
846
957
  // after adding publisher, it will change the temp subscriber to regular subscriber
847
958
  _consumeTmpSubScribers(publisher, tmpSubScribers) {
848
959
  tmpSubScribers.forEach((tmpSubScriber, identifier) => {
849
- fileLog(
850
- `notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `,
851
- "Broker",
852
- "warn"
853
- );
960
+ fileLog(`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `, "Broker", "warn");
854
961
  publisher.addSubscriber(identifier, tmpSubScriber.client);
855
962
  publisher.notifySubscriber(identifier, {
856
- updateKind: "UPDATE_TYPE" /* UPDATE_TYPE */,
857
- updateMode: "PASSIVE" /* PASSIVE */,
858
- updateSourcePaths: [publisher.name],
963
+ updateKind: UpdateKind.UPDATE_TYPE,
964
+ updateMode: UpdateMode.PASSIVE,
965
+ updateSourcePaths: [
966
+ publisher.name
967
+ ],
859
968
  remoteTypeTarPath: publisher.remoteTypeTarPath,
860
969
  name: publisher.name
861
970
  });
@@ -885,17 +994,21 @@ ${err.message}
885
994
  rule.second = second;
886
995
  } else {
887
996
  rule.second = 0;
888
- rule.hour = [0, 3, 6, 9, 12, 15, 18];
997
+ rule.hour = [
998
+ 0,
999
+ 3,
1000
+ 6,
1001
+ 9,
1002
+ 12,
1003
+ 15,
1004
+ 18
1005
+ ];
889
1006
  rule.minute = 0;
890
1007
  }
891
1008
  const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
892
1009
  this._scheduleJob = import_node_schedule.default.scheduleJob(rule, () => {
893
1010
  this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
894
- fileLog(
895
- ` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`,
896
- "Broker",
897
- "info"
898
- );
1011
+ fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
899
1012
  if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)) {
900
1013
  this._clearTmpSubScriberRelation(identifier);
901
1014
  }
@@ -929,7 +1042,9 @@ ${err.message}
929
1042
  process.exit(1);
930
1043
  });
931
1044
  }
932
- async start() {
1045
+ start() {
1046
+ return __async(this, null, function* () {
1047
+ });
933
1048
  }
934
1049
  exit() {
935
1050
  const brokerExitLog = new BrokerExitLog();
@@ -942,13 +1057,9 @@ ${err.message}
942
1057
  process.exit(0);
943
1058
  }
944
1059
  broadcast(message) {
945
- var _a, _b;
946
- fileLog(
947
- `[broadcast] exit info : ${JSON.stringify(message)}`,
948
- "Broker",
949
- "warn"
950
- );
951
- (_a = this._webSocketServer) == null ? void 0 : _a.clients.forEach((client) => {
1060
+ var _a3, _b;
1061
+ fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
1062
+ (_a3 = this._webSocketServer) == null ? void 0 : _a3.clients.forEach((client) => {
952
1063
  client.send(JSON.stringify(message));
953
1064
  });
954
1065
  (_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
@@ -956,10 +1067,11 @@ ${err.message}
956
1067
  });
957
1068
  }
958
1069
  };
959
- _Broker.WEB_SOCKET_CONNECT_MAGIC_ID = WEB_SOCKET_CONNECT_MAGIC_ID;
960
- _Broker.DEFAULT_WEB_SOCKET_PORT = DEFAULT_WEB_SOCKET_PORT;
961
- _Broker.DEFAULT_SECURE_WEB_SOCKET_PORT = 16324;
962
- _Broker.DEFAULT_WAITING_TIME = 1.5 * 60 * 60 * 1e3;
1070
+ __name(_Broker, "Broker");
1071
+ __publicField(_Broker, "WEB_SOCKET_CONNECT_MAGIC_ID", WEB_SOCKET_CONNECT_MAGIC_ID);
1072
+ __publicField(_Broker, "DEFAULT_WEB_SOCKET_PORT", DEFAULT_WEB_SOCKET_PORT);
1073
+ __publicField(_Broker, "DEFAULT_SECURE_WEB_SOCKET_PORT", 16324);
1074
+ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
963
1075
  var Broker = _Broker;
964
1076
 
965
1077
  // packages/dts-plugin/src/server/createKoaServer.ts
@@ -967,49 +1079,49 @@ var import_fs_extra = __toESM(require("fs-extra"));
967
1079
  var import_koa = __toESM(require("koa"));
968
1080
 
969
1081
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
970
- var retrieveTypesZipPath = (mfTypesPath, remoteOptions) => (0, import_path2.join)(
971
- mfTypesPath.replace(remoteOptions.typesFolder, ""),
972
- `${remoteOptions.typesFolder}.zip`
973
- );
974
- var createTypesArchive = async (tsConfig, remoteOptions) => {
1082
+ var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => (0, import_path2.join)(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
1083
+ var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
975
1084
  const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
976
1085
  const zip = new import_adm_zip.default();
977
1086
  zip.addLocalFolder(mfTypesPath);
978
1087
  return zip.writeZipPromise(retrieveTypesZipPath(mfTypesPath, remoteOptions));
979
- };
980
- var downloadErrorLogger = (destinationFolder, fileToDownload) => (reason) => {
981
- throw {
982
- ...reason,
1088
+ }), "createTypesArchive");
1089
+ var downloadErrorLogger = /* @__PURE__ */ __name((destinationFolder, fileToDownload) => (reason) => {
1090
+ throw __spreadProps(__spreadValues({}, reason), {
983
1091
  message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`
984
- };
985
- };
986
- var retrieveTypesArchiveDestinationPath = (hostOptions, destinationFolder) => {
987
- return (0, import_path2.resolve)(
988
- hostOptions.context,
989
- hostOptions.typesFolder,
990
- destinationFolder
991
- );
992
- };
993
- var downloadTypesArchive = (hostOptions) => {
1092
+ });
1093
+ }, "downloadErrorLogger");
1094
+ var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, destinationFolder) => {
1095
+ return (0, import_path2.resolve)(hostOptions.context, hostOptions.typesFolder, destinationFolder);
1096
+ }, "retrieveTypesArchiveDestinationPath");
1097
+ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
994
1098
  let retries = 0;
995
- return async ([destinationFolder, fileToDownload]) => {
996
- const destinationPath = retrieveTypesArchiveDestinationPath(
997
- hostOptions,
998
- destinationFolder
999
- );
1099
+ return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
1100
+ const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
1000
1101
  while (retries++ < hostOptions.maxRetries) {
1001
1102
  try {
1002
1103
  const url = fileToDownload;
1003
- const response = await import_axios.default.get(url, { responseType: "arraybuffer" }).catch(downloadErrorLogger(destinationFolder, url));
1104
+ const response = yield axiosGet(url, {
1105
+ responseType: "arraybuffer"
1106
+ }).catch(downloadErrorLogger(destinationFolder, url));
1107
+ try {
1108
+ if (hostOptions.deleteTypesFolder) {
1109
+ yield (0, import_promises.rm)(destinationPath, {
1110
+ recursive: true,
1111
+ force: true
1112
+ });
1113
+ }
1114
+ } catch (error2) {
1115
+ fileLog(`Unable to remove types folder, ${error2}`, "downloadTypesArchive", "error");
1116
+ }
1004
1117
  const zip = new import_adm_zip.default(Buffer.from(response.data));
1005
1118
  zip.extractAllTo(destinationPath, true);
1006
- return [destinationFolder, destinationPath];
1119
+ return [
1120
+ destinationFolder,
1121
+ destinationPath
1122
+ ];
1007
1123
  } catch (error2) {
1008
- fileLog(
1009
- `Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`,
1010
- "downloadTypesArchive",
1011
- "error"
1012
- );
1124
+ fileLog(`Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`, "downloadTypesArchive", "error");
1013
1125
  if (retries >= hostOptions.maxRetries) {
1014
1126
  if (hostOptions.abortOnError !== false) {
1015
1127
  throw error2;
@@ -1018,8 +1130,8 @@ var downloadTypesArchive = (hostOptions) => {
1018
1130
  }
1019
1131
  }
1020
1132
  }
1021
- };
1022
- };
1133
+ });
1134
+ }, "downloadTypesArchive");
1023
1135
 
1024
1136
  // packages/dts-plugin/src/core/configurations/hostPlugin.ts
1025
1137
  var import_sdk3 = require("@module-federation/sdk");
@@ -1034,22 +1146,26 @@ var defaultOptions = {
1034
1146
  abortOnError: true,
1035
1147
  consumeAPITypes: false
1036
1148
  };
1037
- var buildZipUrl = (hostOptions, url) => {
1038
- const remoteUrl = new URL(url);
1149
+ var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1150
+ const remoteUrl = new URL(url, "file:");
1039
1151
  const pathnameWithoutEntry = remoteUrl.pathname.split("/").slice(0, -1).join("/");
1040
1152
  remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
1041
- return remoteUrl.href;
1042
- };
1043
- var buildApiTypeUrl = (zipUrl) => {
1153
+ return remoteUrl.protocol === "file:" ? remoteUrl.pathname : remoteUrl.href;
1154
+ }, "buildZipUrl");
1155
+ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
1044
1156
  if (!zipUrl) {
1045
1157
  return void 0;
1046
1158
  }
1047
1159
  return zipUrl.replace(".zip", ".d.ts");
1048
- };
1049
- var retrieveRemoteInfo = (options) => {
1160
+ }, "buildApiTypeUrl");
1161
+ var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
1050
1162
  const { hostOptions, remoteAlias, remote } = options;
1051
- const parsedInfo = (0, import_sdk3.parseEntry)(remote, void 0, "@");
1052
- const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === remote ? remote : "";
1163
+ let decodedRemote = remote;
1164
+ if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
1165
+ decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
1166
+ }
1167
+ const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
1168
+ const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
1053
1169
  const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
1054
1170
  return {
1055
1171
  name: parsedInfo.name || remoteAlias,
@@ -1058,56 +1174,45 @@ var retrieveRemoteInfo = (options) => {
1058
1174
  apiTypeUrl: buildApiTypeUrl(zipUrl),
1059
1175
  alias: remoteAlias
1060
1176
  };
1061
- };
1062
- var resolveRemotes = (hostOptions) => {
1063
- const parsedOptions = import_managers.utils.parseOptions(
1064
- hostOptions.moduleFederationConfig.remotes || {},
1065
- (item, key) => ({
1066
- remote: Array.isArray(item) ? item[0] : item,
1067
- key
1068
- }),
1069
- (item, key) => ({
1070
- remote: Array.isArray(item.external) ? item.external[0] : item.external,
1071
- key
1072
- })
1073
- );
1074
- return parsedOptions.reduce(
1075
- (accumulator, item) => {
1076
- const { key, remote } = item[1];
1077
- accumulator[key] = retrieveRemoteInfo({
1078
- hostOptions,
1079
- remoteAlias: key,
1080
- remote
1081
- });
1082
- return accumulator;
1083
- },
1084
- {}
1085
- );
1086
- };
1087
- var retrieveHostConfig = (options) => {
1177
+ }, "retrieveRemoteInfo");
1178
+ var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
1179
+ const parsedOptions = import_managers.utils.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
1180
+ remote: Array.isArray(item) ? item[0] : item,
1181
+ key
1182
+ }), (item, key) => ({
1183
+ remote: Array.isArray(item.external) ? item.external[0] : item.external,
1184
+ key
1185
+ }));
1186
+ return parsedOptions.reduce((accumulator, item) => {
1187
+ const { key, remote } = item[1];
1188
+ accumulator[key] = retrieveRemoteInfo({
1189
+ hostOptions,
1190
+ remoteAlias: key,
1191
+ remote
1192
+ });
1193
+ return accumulator;
1194
+ }, {});
1195
+ }, "resolveRemotes");
1196
+ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
1088
1197
  validateOptions(options);
1089
- const hostOptions = { ...defaultOptions, ...options };
1198
+ const hostOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
1090
1199
  const mapRemotesToDownload = resolveRemotes(hostOptions);
1091
1200
  return {
1092
1201
  hostOptions,
1093
1202
  mapRemotesToDownload
1094
1203
  };
1095
- };
1096
-
1097
- // packages/dts-plugin/src/core/constant.ts
1098
- var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
1099
- var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
1100
- var HOST_API_TYPES_FILE_NAME = "index.d.ts";
1101
- var UpdateMode = /* @__PURE__ */ ((UpdateMode2) => {
1102
- UpdateMode2["POSITIVE"] = "POSITIVE";
1103
- UpdateMode2["PASSIVE"] = "PASSIVE";
1104
- return UpdateMode2;
1105
- })(UpdateMode || {});
1204
+ }, "retrieveHostConfig");
1106
1205
 
1107
1206
  // packages/dts-plugin/src/core/lib/DTSManager.ts
1108
- var import_axios2 = __toESM(require("axios"));
1109
- var DTSManager = class {
1207
+ var _a;
1208
+ var DTSManager = (_a = class {
1110
1209
  constructor(options) {
1210
+ __publicField(this, "options");
1211
+ __publicField(this, "runtimePkgs");
1212
+ __publicField(this, "remoteAliasMap");
1213
+ __publicField(this, "loadedRemoteAPIAlias");
1214
+ __publicField(this, "extraOptions");
1215
+ __publicField(this, "updatedRemoteInfos");
1111
1216
  this.options = (0, import_lodash.default)(options, (_value, key) => {
1112
1217
  if (key === "manifest") {
1113
1218
  return false;
@@ -1118,181 +1223,190 @@ var DTSManager = class {
1118
1223
  "@module-federation/enhanced/runtime",
1119
1224
  "@module-federation/runtime-tools"
1120
1225
  ];
1121
- this.loadedRemoteAPIAlias = [];
1226
+ this.loadedRemoteAPIAlias = /* @__PURE__ */ new Set();
1122
1227
  this.remoteAliasMap = {};
1123
1228
  this.extraOptions = (options == null ? void 0 : options.extraOptions) || {};
1229
+ this.updatedRemoteInfos = {};
1124
1230
  }
1125
1231
  generateAPITypes(mapComponentsToExpose) {
1126
1232
  const exposePaths = /* @__PURE__ */ new Set();
1127
- const packageType = Object.keys(mapComponentsToExpose).reduce(
1128
- (sum, exposeKey) => {
1129
- const exposePath = import_path3.default.join(REMOTE_ALIAS_IDENTIFIER, exposeKey).split(import_path3.default.sep).join("/");
1130
- exposePaths.add(`'${exposePath}'`);
1131
- const curType = `T extends '${exposePath}' ? typeof import('${exposePath}') :`;
1132
- sum = curType + sum;
1133
- return sum;
1134
- },
1135
- "any;"
1136
- );
1137
- const exposePathKeys = [...exposePaths].join(" | ");
1233
+ const packageType = Object.keys(mapComponentsToExpose).reduce((sum, exposeKey) => {
1234
+ const exposePath = import_path3.default.join(REMOTE_ALIAS_IDENTIFIER, exposeKey).split(import_path3.default.sep).join("/");
1235
+ exposePaths.add(`'${exposePath}'`);
1236
+ const curType = `T extends '${exposePath}' ? typeof import('${exposePath}') :`;
1237
+ sum = curType + sum;
1238
+ return sum;
1239
+ }, "any;");
1240
+ const exposePathKeys = [
1241
+ ...exposePaths
1242
+ ].join(" | ");
1138
1243
  return `
1139
1244
  export type RemoteKeys = ${exposePathKeys};
1140
1245
  type PackageType<T> = ${packageType}`;
1141
1246
  }
1142
- async extractRemoteTypes(options) {
1143
- const { remoteOptions, tsConfig } = options;
1144
- if (!remoteOptions.extractRemoteTypes) {
1145
- return;
1146
- }
1147
- let hasRemotes = false;
1148
- const remotes = remoteOptions.moduleFederationConfig.remotes;
1149
- if (remotes) {
1150
- if (Array.isArray(remotes)) {
1151
- hasRemotes = Boolean(remotes.length);
1152
- } else if (typeof remotes === "object") {
1153
- hasRemotes = Boolean(Object.keys(remotes).length);
1154
- }
1155
- }
1156
- const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1157
- if (hasRemotes) {
1158
- const tempHostOptions = {
1159
- moduleFederationConfig: remoteOptions.moduleFederationConfig,
1160
- typesFolder: import_path3.default.join(mfTypesPath, "node_modules"),
1161
- remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
1162
- deleteTypesFolder: true,
1163
- context: remoteOptions.context,
1164
- implementation: remoteOptions.implementation,
1165
- abortOnError: false
1166
- };
1167
- await this.consumeArchiveTypes(tempHostOptions);
1168
- }
1169
- }
1170
- async generateTypes() {
1171
- var _a;
1172
- try {
1173
- const { options } = this;
1174
- if (!options.remote) {
1175
- throw new Error(
1176
- "options.remote is required if you want to generateTypes"
1177
- );
1178
- }
1179
- const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
1180
- if (!Object.keys(mapComponentsToExpose).length) {
1247
+ extractRemoteTypes(options) {
1248
+ return __async(this, null, function* () {
1249
+ const { remoteOptions, tsConfig } = options;
1250
+ if (!remoteOptions.extractRemoteTypes) {
1181
1251
  return;
1182
1252
  }
1183
- this.extractRemoteTypes({
1184
- remoteOptions,
1185
- tsConfig,
1186
- mapComponentsToExpose
1187
- });
1188
- compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
1189
- await createTypesArchive(tsConfig, remoteOptions);
1190
- let apiTypesPath = "";
1191
- if (remoteOptions.generateAPITypes) {
1192
- const apiTypes = this.generateAPITypes(mapComponentsToExpose);
1193
- apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
1194
- import_fs.default.writeFileSync(apiTypesPath, apiTypes);
1253
+ let hasRemotes = false;
1254
+ const remotes = remoteOptions.moduleFederationConfig.remotes;
1255
+ if (remotes) {
1256
+ if (Array.isArray(remotes)) {
1257
+ hasRemotes = Boolean(remotes.length);
1258
+ } else if (typeof remotes === "object") {
1259
+ hasRemotes = Boolean(Object.keys(remotes).length);
1260
+ }
1195
1261
  }
1196
- if (remoteOptions.deleteTypesFolder) {
1197
- await (0, import_promises.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
1198
- recursive: true,
1199
- force: true
1200
- });
1262
+ const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1263
+ if (hasRemotes) {
1264
+ const tempHostOptions = {
1265
+ moduleFederationConfig: remoteOptions.moduleFederationConfig,
1266
+ typesFolder: import_path3.default.join(mfTypesPath, "node_modules"),
1267
+ remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
1268
+ deleteTypesFolder: true,
1269
+ context: remoteOptions.context,
1270
+ implementation: remoteOptions.implementation,
1271
+ abortOnError: false
1272
+ };
1273
+ yield this.consumeArchiveTypes(tempHostOptions);
1201
1274
  }
1202
- console.log(import_ansi_colors2.default.green("Federated types created correctly"));
1203
- } catch (error2) {
1204
- if (((_a = this.options.remote) == null ? void 0 : _a.abortOnError) === false) {
1205
- console.error(
1206
- import_ansi_colors2.default.red(`Unable to compile federated types, ${error2}`)
1207
- );
1208
- } else {
1209
- throw error2;
1275
+ });
1276
+ }
1277
+ generateTypes() {
1278
+ return __async(this, null, function* () {
1279
+ var _a3;
1280
+ try {
1281
+ const { options } = this;
1282
+ if (!options.remote) {
1283
+ throw new Error("options.remote is required if you want to generateTypes");
1284
+ }
1285
+ const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
1286
+ if (!Object.keys(mapComponentsToExpose).length) {
1287
+ return;
1288
+ }
1289
+ this.extractRemoteTypes({
1290
+ remoteOptions,
1291
+ tsConfig,
1292
+ mapComponentsToExpose
1293
+ });
1294
+ compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
1295
+ yield createTypesArchive(tsConfig, remoteOptions);
1296
+ let apiTypesPath = "";
1297
+ if (remoteOptions.generateAPITypes) {
1298
+ const apiTypes = this.generateAPITypes(mapComponentsToExpose);
1299
+ apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
1300
+ import_fs.default.writeFileSync(apiTypesPath, apiTypes);
1301
+ }
1302
+ try {
1303
+ if (remoteOptions.deleteTypesFolder) {
1304
+ yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
1305
+ recursive: true,
1306
+ force: true
1307
+ });
1308
+ }
1309
+ } catch (err) {
1310
+ if (isDebugMode()) {
1311
+ console.error(err);
1312
+ }
1313
+ }
1314
+ console.log(import_ansi_colors2.default.green("Federated types created correctly"));
1315
+ } catch (error2) {
1316
+ if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
1317
+ console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${error2}`));
1318
+ } else {
1319
+ throw error2;
1320
+ }
1210
1321
  }
1211
- }
1322
+ });
1212
1323
  }
1213
- async requestRemoteManifest(remoteInfo) {
1214
- try {
1215
- if (!remoteInfo.url.includes(import_sdk4.MANIFEST_EXT)) {
1324
+ requestRemoteManifest(remoteInfo) {
1325
+ return __async(this, null, function* () {
1326
+ try {
1327
+ if (!remoteInfo.url.includes(import_sdk4.MANIFEST_EXT)) {
1328
+ return remoteInfo;
1329
+ }
1330
+ const url = remoteInfo.url;
1331
+ const res = yield axiosGet(url);
1332
+ const manifestJson = res.data;
1333
+ if (!manifestJson.metaData.types.zip) {
1334
+ throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
1335
+ }
1336
+ const addProtocol = /* @__PURE__ */ __name((u) => {
1337
+ if (u.startsWith("//")) {
1338
+ return `https:${u}`;
1339
+ }
1340
+ return u;
1341
+ }, "addProtocol");
1342
+ let publicPath = "publicPath" in manifestJson.metaData ? manifestJson.metaData.publicPath : new Function(manifestJson.metaData.getPublicPath)();
1343
+ if (publicPath === "auto") {
1344
+ publicPath = (0, import_sdk4.inferAutoPublicPath)(remoteInfo.url);
1345
+ }
1346
+ remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
1347
+ if (!manifestJson.metaData.types.api) {
1348
+ console.warn(`Can not get ${remoteInfo.name}'s api types url!`);
1349
+ remoteInfo.apiTypeUrl = "";
1350
+ return remoteInfo;
1351
+ }
1352
+ remoteInfo.apiTypeUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.api)).href;
1353
+ return remoteInfo;
1354
+ } catch (_err) {
1355
+ fileLog(`fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`, "requestRemoteManifest", "error");
1216
1356
  return remoteInfo;
1217
1357
  }
1218
- const url = remoteInfo.url;
1219
- const res = await (0, import_axios2.default)({
1220
- method: "get",
1221
- url
1222
- });
1223
- const manifestJson = res.data;
1224
- if (!manifestJson.metaData.types.zip) {
1358
+ });
1359
+ }
1360
+ consumeTargetRemotes(hostOptions, remoteInfo) {
1361
+ return __async(this, null, function* () {
1362
+ if (!remoteInfo.zipUrl) {
1225
1363
  throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
1226
1364
  }
1227
- const addProtocol = (u) => {
1228
- if (u.startsWith("//")) {
1229
- return `https:${u}`;
1230
- }
1231
- return u;
1232
- };
1233
- let publicPath = "publicPath" in manifestJson.metaData ? manifestJson.metaData.publicPath : new Function(manifestJson.metaData.getPublicPath)();
1234
- if (publicPath === "auto") {
1235
- publicPath = (0, import_sdk4.inferAutoPublicPath)(remoteInfo.url);
1365
+ const typesDownloader = downloadTypesArchive(hostOptions);
1366
+ return typesDownloader([
1367
+ remoteInfo.alias,
1368
+ remoteInfo.zipUrl
1369
+ ]);
1370
+ });
1371
+ }
1372
+ downloadAPITypes(remoteInfo, destinationPath) {
1373
+ return __async(this, null, function* () {
1374
+ const { apiTypeUrl } = remoteInfo;
1375
+ if (!apiTypeUrl) {
1376
+ return;
1236
1377
  }
1237
- remoteInfo.zipUrl = new URL(
1238
- import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)
1239
- ).href;
1240
- if (!manifestJson.metaData.types.api) {
1241
- console.warn(`Can not get ${remoteInfo.name}'s api types url!`);
1242
- remoteInfo.apiTypeUrl = "";
1243
- return remoteInfo;
1378
+ try {
1379
+ const url = apiTypeUrl;
1380
+ const res = yield axiosGet(url);
1381
+ let apiTypeFile = res.data;
1382
+ apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
1383
+ const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
1384
+ import_fs.default.writeFileSync(filePath, apiTypeFile);
1385
+ this.loadedRemoteAPIAlias.add(remoteInfo.alias);
1386
+ } catch (err) {
1387
+ fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "consumeTargetRemotes", "error");
1244
1388
  }
1245
- remoteInfo.apiTypeUrl = new URL(
1246
- import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.api)
1247
- ).href;
1248
- return remoteInfo;
1249
- } catch (_err) {
1250
- fileLog(
1251
- `fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`,
1252
- "requestRemoteManifest",
1253
- "error"
1254
- );
1255
- return remoteInfo;
1256
- }
1257
- }
1258
- async consumeTargetRemotes(hostOptions, remoteInfo) {
1259
- if (!remoteInfo.zipUrl) {
1260
- throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
1261
- }
1262
- const typesDownloader = downloadTypesArchive(hostOptions);
1263
- return typesDownloader([remoteInfo.alias, remoteInfo.zipUrl]);
1389
+ });
1264
1390
  }
1265
- async downloadAPITypes(remoteInfo, destinationPath) {
1266
- const { apiTypeUrl } = remoteInfo;
1267
- if (!apiTypeUrl) {
1268
- return;
1269
- }
1391
+ consumeAPITypes(hostOptions) {
1392
+ const apiTypeFileName = import_path3.default.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME);
1270
1393
  try {
1271
- const url = apiTypeUrl;
1272
- const res = await import_axios2.default.get(url);
1273
- let apiTypeFile = res.data;
1274
- apiTypeFile = apiTypeFile.replaceAll(
1275
- REMOTE_ALIAS_IDENTIFIER,
1276
- remoteInfo.alias
1277
- );
1278
- const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
1279
- import_fs.default.writeFileSync(filePath, apiTypeFile);
1280
- this.loadedRemoteAPIAlias.push(remoteInfo.alias);
1394
+ const existedFile = import_fs.default.readFileSync(apiTypeFileName, "utf-8");
1395
+ const existedImports = new import_third_party_dts_extractor2.ThirdPartyExtractor("").collectTypeImports(existedFile);
1396
+ existedImports.forEach((existedImport) => {
1397
+ const alias = existedImport.split("./").slice(1).join("./").replace("/apis.d.ts", "");
1398
+ this.loadedRemoteAPIAlias.add(alias);
1399
+ });
1281
1400
  } catch (err) {
1282
- fileLog(
1283
- `Unable to download "${remoteInfo.name}" api types, ${err}`,
1284
- "consumeTargetRemotes",
1285
- "error"
1286
- );
1287
1401
  }
1288
- }
1289
- consumeAPITypes(hostOptions) {
1290
- if (!this.loadedRemoteAPIAlias.length) {
1402
+ if (!this.loadedRemoteAPIAlias.size) {
1291
1403
  return;
1292
1404
  }
1293
1405
  const packageTypes = [];
1294
1406
  const remoteKeys = [];
1295
- const importTypeStr = this.loadedRemoteAPIAlias.sort().map((alias, index) => {
1407
+ const importTypeStr = [
1408
+ ...this.loadedRemoteAPIAlias
1409
+ ].sort().map((alias, index) => {
1296
1410
  const remoteKey = `RemoteKeys_${index}`;
1297
1411
  const packageType = `PackageType_${index}`;
1298
1412
  packageTypes.push(`T extends ${remoteKey} ? ${packageType}<T>`);
@@ -1315,63 +1429,41 @@ var DTSManager = class {
1315
1429
  const fileStr = `${importTypeStr}
1316
1430
  ${pkgsDeclareStr}
1317
1431
  `;
1318
- import_fs.default.writeFileSync(
1319
- import_path3.default.join(
1320
- hostOptions.context,
1321
- hostOptions.typesFolder,
1322
- HOST_API_TYPES_FILE_NAME
1323
- ),
1324
- fileStr
1325
- );
1326
- }
1327
- async consumeArchiveTypes(options) {
1328
- const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
1329
- if (hostOptions.deleteTypesFolder) {
1330
- await (0, import_promises.rm)(hostOptions.typesFolder, {
1331
- recursive: true,
1332
- force: true
1333
- }).catch(
1334
- (error2) => fileLog(
1335
- `Unable to remove types folder, ${error2}`,
1336
- "consumeArchiveTypes",
1337
- "error"
1338
- )
1339
- );
1340
- }
1341
- const downloadPromises = Object.entries(mapRemotesToDownload).map(
1342
- async (item) => {
1432
+ import_fs.default.writeFileSync(import_path3.default.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME), fileStr);
1433
+ }
1434
+ consumeArchiveTypes(options) {
1435
+ return __async(this, null, function* () {
1436
+ const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
1437
+ const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
1343
1438
  const remoteInfo = item[1];
1344
1439
  if (!this.remoteAliasMap[remoteInfo.alias]) {
1345
- const requiredRemoteInfo = await this.requestRemoteManifest(remoteInfo);
1440
+ const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
1346
1441
  this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
1347
1442
  }
1348
- return this.consumeTargetRemotes(
1349
- hostOptions,
1350
- this.remoteAliasMap[remoteInfo.alias]
1351
- );
1352
- }
1353
- );
1354
- const downloadPromisesResult = await Promise.allSettled(downloadPromises);
1355
- return {
1356
- hostOptions,
1357
- downloadPromisesResult
1358
- };
1443
+ return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
1444
+ }));
1445
+ const downloadPromisesResult = yield Promise.allSettled(downloadPromises);
1446
+ return {
1447
+ hostOptions,
1448
+ downloadPromisesResult
1449
+ };
1450
+ });
1359
1451
  }
1360
- async consumeTypes() {
1361
- var _a;
1362
- try {
1363
- const { options } = this;
1364
- if (!options.host) {
1365
- throw new Error("options.host is required if you want to consumeTypes");
1366
- }
1367
- const { mapRemotesToDownload } = retrieveHostConfig(options.host);
1368
- if (!Object.keys(mapRemotesToDownload).length) {
1369
- return;
1370
- }
1371
- const { downloadPromisesResult, hostOptions } = await this.consumeArchiveTypes(options.host);
1372
- if (hostOptions.consumeAPITypes) {
1373
- await Promise.all(
1374
- downloadPromisesResult.map(async (item) => {
1452
+ consumeTypes() {
1453
+ return __async(this, null, function* () {
1454
+ var _a3;
1455
+ try {
1456
+ const { options } = this;
1457
+ if (!options.host) {
1458
+ throw new Error("options.host is required if you want to consumeTypes");
1459
+ }
1460
+ const { mapRemotesToDownload } = retrieveHostConfig(options.host);
1461
+ if (!Object.keys(mapRemotesToDownload).length) {
1462
+ return;
1463
+ }
1464
+ const { downloadPromisesResult, hostOptions } = yield this.consumeArchiveTypes(options.host);
1465
+ if (hostOptions.consumeAPITypes) {
1466
+ yield Promise.all(downloadPromisesResult.map((item) => __async(this, null, function* () {
1375
1467
  if (item.status === "rejected" || !item.value) {
1376
1468
  return;
1377
1469
  }
@@ -1380,68 +1472,82 @@ var DTSManager = class {
1380
1472
  if (!remoteInfo) {
1381
1473
  return;
1382
1474
  }
1383
- await this.downloadAPITypes(remoteInfo, destinationPath);
1384
- })
1385
- );
1386
- this.consumeAPITypes(hostOptions);
1387
- }
1388
- console.log(import_ansi_colors2.default.green("Federated types extraction completed"));
1389
- } catch (err) {
1390
- if (((_a = this.options.host) == null ? void 0 : _a.abortOnError) === false) {
1391
- fileLog(
1392
- `Unable to consume federated types, ${err}`,
1393
- "consumeTypes",
1394
- "error"
1395
- );
1396
- } else {
1397
- throw err;
1475
+ yield this.downloadAPITypes(remoteInfo, destinationPath);
1476
+ })));
1477
+ this.consumeAPITypes(hostOptions);
1478
+ }
1479
+ console.log(import_ansi_colors2.default.green("Federated types extraction completed"));
1480
+ } catch (err) {
1481
+ if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
1482
+ fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
1483
+ } else {
1484
+ throw err;
1485
+ }
1398
1486
  }
1399
- }
1487
+ });
1400
1488
  }
1401
- async updateTypes(options) {
1402
- var _a, _b, _c;
1403
- const { remoteName, updateMode } = options;
1404
- const hostName = (_c = (_b = (_a = this.options) == null ? void 0 : _a.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
1405
- if (updateMode === "POSITIVE" /* POSITIVE */ && remoteName === hostName) {
1406
- if (!this.options.remote) {
1407
- return;
1408
- }
1409
- this.generateTypes();
1410
- } else {
1411
- const { remoteAliasMap } = this;
1412
- if (!this.options.host) {
1413
- return;
1414
- }
1415
- const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(
1416
- this.options.host
1417
- );
1418
- const loadedRemoteInfo = Object.values(remoteAliasMap).find(
1419
- (i) => i.name === remoteName
1420
- );
1421
- if (!loadedRemoteInfo) {
1422
- const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
1423
- return item.name === remoteName;
1424
- });
1425
- if (remoteInfo) {
1426
- if (!this.remoteAliasMap[remoteInfo.alias]) {
1427
- const requiredRemoteInfo = await this.requestRemoteManifest(remoteInfo);
1428
- this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
1489
+ updateTypes(options) {
1490
+ return __async(this, null, function* () {
1491
+ var _a3, _b, _c;
1492
+ try {
1493
+ const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
1494
+ const hostName = (_c = (_b = (_a3 = this.options) == null ? void 0 : _a3.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
1495
+ fileLog(`updateTypes options:, ${JSON.stringify(options, null, 2)}`, "consumeTypes", "info");
1496
+ if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
1497
+ if (!this.options.remote) {
1498
+ return;
1499
+ }
1500
+ this.generateTypes();
1501
+ } else {
1502
+ const { remoteAliasMap } = this;
1503
+ if (!this.options.host) {
1504
+ return;
1505
+ }
1506
+ const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
1507
+ const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
1508
+ if (!loadedRemoteInfo) {
1509
+ const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
1510
+ return item.name === remoteName;
1511
+ });
1512
+ if (remoteInfo) {
1513
+ if (!this.remoteAliasMap[remoteInfo.alias]) {
1514
+ const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
1515
+ this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
1516
+ }
1517
+ yield this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
1518
+ } else if (updatedRemoteInfo) {
1519
+ const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
1520
+ const [_destinationFolder, destinationPath] = yield this.consumeTargetRemotes(hostOptions, this.updatedRemoteInfos[updatedRemoteInfo.name]);
1521
+ yield this.downloadAPITypes(this.updatedRemoteInfos[updatedRemoteInfo.name], destinationPath);
1522
+ this.consumeAPITypes(hostOptions);
1523
+ }), "consumeDynamicRemoteTypes");
1524
+ if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
1525
+ const parsedRemoteInfo = retrieveRemoteInfo({
1526
+ hostOptions,
1527
+ remoteAlias: updatedRemoteInfo.alias || updatedRemoteInfo.name,
1528
+ remote: updatedRemoteInfo.url
1529
+ });
1530
+ fileLog(`start request manifest`, "consumeTypes", "info");
1531
+ this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
1532
+ fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "consumeTypes", "info");
1533
+ yield consumeDynamicRemoteTypes();
1534
+ }
1535
+ if (!once && this.updatedRemoteInfos[updatedRemoteInfo.name]) {
1536
+ yield consumeDynamicRemoteTypes();
1537
+ }
1538
+ }
1539
+ } else {
1540
+ yield this.consumeTargetRemotes(hostOptions, loadedRemoteInfo);
1429
1541
  }
1430
- await this.consumeTargetRemotes(
1431
- hostOptions,
1432
- this.remoteAliasMap[remoteInfo.alias]
1433
- );
1434
1542
  }
1435
- } else {
1436
- await this.consumeTargetRemotes(hostOptions, loadedRemoteInfo);
1543
+ } catch (err) {
1544
+ fileLog(`updateTypes fail, ${err}`, "updateTypes", "error");
1437
1545
  }
1438
- }
1546
+ });
1439
1547
  }
1440
- };
1548
+ }, __name(_a, "DTSManager"), _a);
1441
1549
 
1442
1550
  // packages/dts-plugin/src/core/lib/utils.ts
1443
- var import_fs2 = __toESM(require("fs"));
1444
- var import_ansi_colors3 = __toESM(require("ansi-colors"));
1445
1551
  function getDTSManagerConstructor(implementation) {
1446
1552
  if (implementation) {
1447
1553
  const NewConstructor = require(implementation);
@@ -1449,11 +1555,12 @@ function getDTSManagerConstructor(implementation) {
1449
1555
  }
1450
1556
  return DTSManager;
1451
1557
  }
1452
- var validateOptions = (options) => {
1558
+ __name(getDTSManagerConstructor, "getDTSManagerConstructor");
1559
+ var validateOptions = /* @__PURE__ */ __name((options) => {
1453
1560
  if (!options.moduleFederationConfig) {
1454
1561
  throw new Error("moduleFederationConfig is required");
1455
1562
  }
1456
- };
1563
+ }, "validateOptions");
1457
1564
  function retrieveTypesAssetsInfo(options) {
1458
1565
  let apiTypesPath = "";
1459
1566
  let zipTypesPath = "";
@@ -1488,7 +1595,12 @@ function retrieveTypesAssetsInfo(options) {
1488
1595
  };
1489
1596
  }
1490
1597
  }
1491
- var isTSProject = (dtsOptions, context = process.cwd()) => {
1598
+ __name(retrieveTypesAssetsInfo, "retrieveTypesAssetsInfo");
1599
+ function isDebugMode() {
1600
+ return Boolean(process.env["FEDERATION_DEBUG"]);
1601
+ }
1602
+ __name(isDebugMode, "isDebugMode");
1603
+ var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) => {
1492
1604
  if (dtsOptions === false) {
1493
1605
  return false;
1494
1606
  }
@@ -1506,7 +1618,22 @@ var isTSProject = (dtsOptions, context = process.cwd()) => {
1506
1618
  } catch (err) {
1507
1619
  return false;
1508
1620
  }
1509
- };
1621
+ }, "isTSProject");
1622
+ function axiosGet(url, config) {
1623
+ return __async(this, null, function* () {
1624
+ const httpAgent = new import_http2.default.Agent({
1625
+ family: 4
1626
+ });
1627
+ const httpsAgent = new import_https.default.Agent({
1628
+ family: 4
1629
+ });
1630
+ return import_axios.default.get(url, __spreadValues({
1631
+ httpAgent,
1632
+ httpsAgent
1633
+ }, config));
1634
+ });
1635
+ }
1636
+ __name(axiosGet, "axiosGet");
1510
1637
 
1511
1638
  // packages/dts-plugin/src/core/configurations/remotePlugin.ts
1512
1639
  var defaultOptions2 = {
@@ -1525,85 +1652,56 @@ var defaultOptions2 = {
1525
1652
  extractRemoteTypes: false,
1526
1653
  extractThirdParty: false
1527
1654
  };
1528
- var readTsConfig = ({
1529
- tsConfigPath,
1530
- typesFolder,
1531
- compiledTypesFolder,
1532
- context
1533
- }) => {
1655
+ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context }) => {
1534
1656
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1535
- const readResult = import_typescript2.default.readConfigFile(
1536
- resolvedTsConfigPath,
1537
- import_typescript2.default.sys.readFile
1538
- );
1657
+ const readResult = import_typescript2.default.readConfigFile(resolvedTsConfigPath, import_typescript2.default.sys.readFile);
1539
1658
  if (readResult.error) {
1540
1659
  throw new Error(readResult.error.messageText.toString());
1541
1660
  }
1542
- const configContent = import_typescript2.default.parseJsonConfigFileContent(
1543
- readResult.config,
1544
- import_typescript2.default.sys,
1545
- (0, import_path5.dirname)(resolvedTsConfigPath)
1546
- );
1547
- const outDir = (0, import_path5.resolve)(
1548
- context,
1549
- configContent.options.outDir || "dist",
1550
- typesFolder,
1551
- compiledTypesFolder
1552
- );
1553
- return {
1554
- ...configContent.options,
1661
+ const configContent = import_typescript2.default.parseJsonConfigFileContent(readResult.config, import_typescript2.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
1662
+ const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
1663
+ return __spreadProps(__spreadValues({}, configContent.options), {
1555
1664
  emitDeclarationOnly: true,
1556
1665
  noEmit: false,
1557
1666
  declaration: true,
1558
1667
  outDir
1559
- };
1560
- };
1561
- var TS_EXTENSIONS = ["ts", "tsx", "vue", "svelte"];
1562
- var resolveWithExtension = (exposedPath, context) => {
1668
+ });
1669
+ }, "readTsConfig");
1670
+ var TS_EXTENSIONS = [
1671
+ "ts",
1672
+ "tsx",
1673
+ "vue",
1674
+ "svelte"
1675
+ ];
1676
+ var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
1563
1677
  if ((0, import_path5.extname)(exposedPath)) {
1564
1678
  return (0, import_path5.resolve)(context, exposedPath);
1565
1679
  }
1566
1680
  for (const extension of TS_EXTENSIONS) {
1567
- const exposedPathWithExtension = (0, import_path5.resolve)(
1568
- context,
1569
- `${exposedPath}.${extension}`
1570
- );
1681
+ const exposedPathWithExtension = (0, import_path5.resolve)(context, `${exposedPath}.${extension}`);
1571
1682
  if ((0, import_fs3.existsSync)(exposedPathWithExtension)) {
1572
1683
  return exposedPathWithExtension;
1573
1684
  }
1574
1685
  }
1575
1686
  return void 0;
1576
- };
1577
- var resolveExposes = (remoteOptions) => {
1578
- const parsedOptions = import_managers2.utils.parseOptions(
1579
- remoteOptions.moduleFederationConfig.exposes || {},
1580
- (item, key) => ({
1581
- exposePath: Array.isArray(item) ? item[0] : item,
1582
- key
1583
- }),
1584
- (item, key) => ({
1585
- exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
1586
- key
1587
- })
1588
- );
1589
- return parsedOptions.reduce(
1590
- (accumulator, item) => {
1591
- const { exposePath, key } = item[1];
1592
- accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(
1593
- (0, import_path5.join)(exposePath, "index"),
1594
- remoteOptions.context
1595
- ) || exposePath;
1596
- return accumulator;
1597
- },
1598
- {}
1599
- );
1600
- };
1601
- var retrieveRemoteConfig = (options) => {
1687
+ }, "resolveWithExtension");
1688
+ var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
1689
+ const parsedOptions = import_managers2.utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
1690
+ exposePath: Array.isArray(item) ? item[0] : item,
1691
+ key
1692
+ }), (item, key) => ({
1693
+ exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
1694
+ key
1695
+ }));
1696
+ return parsedOptions.reduce((accumulator, item) => {
1697
+ const { exposePath, key } = item[1];
1698
+ accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension((0, import_path5.join)(exposePath, "index"), remoteOptions.context) || exposePath;
1699
+ return accumulator;
1700
+ }, {});
1701
+ }, "resolveExposes");
1702
+ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
1602
1703
  validateOptions(options);
1603
- const remoteOptions = {
1604
- ...defaultOptions2,
1605
- ...options
1606
- };
1704
+ const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
1607
1705
  const mapComponentsToExpose = resolveExposes(remoteOptions);
1608
1706
  const tsConfig = readTsConfig(remoteOptions);
1609
1707
  return {
@@ -1611,17 +1709,18 @@ var retrieveRemoteConfig = (options) => {
1611
1709
  mapComponentsToExpose,
1612
1710
  remoteOptions
1613
1711
  };
1614
- };
1712
+ }, "retrieveRemoteConfig");
1615
1713
 
1616
1714
  // packages/dts-plugin/src/core/lib/generateTypes.ts
1617
- async function generateTypes(options) {
1618
- var _a;
1619
- const DTSManagerConstructor = getDTSManagerConstructor(
1620
- (_a = options.remote) == null ? void 0 : _a.implementation
1621
- );
1622
- const dtsManager = new DTSManagerConstructor(options);
1623
- return dtsManager.generateTypes();
1715
+ function generateTypes(options) {
1716
+ return __async(this, null, function* () {
1717
+ var _a3;
1718
+ const DTSManagerConstructor = getDTSManagerConstructor((_a3 = options.remote) == null ? void 0 : _a3.implementation);
1719
+ const dtsManager = new DTSManagerConstructor(options);
1720
+ return dtsManager.generateTypes();
1721
+ });
1624
1722
  }
1723
+ __name(generateTypes, "generateTypes");
1625
1724
 
1626
1725
  // packages/dts-plugin/src/core/lib/DtsWorker.ts
1627
1726
  var import_path6 = __toESM(require("path"));
@@ -1642,23 +1741,21 @@ __export(rpc_exports, {
1642
1741
  var import_process = __toESM(require("process"));
1643
1742
 
1644
1743
  // packages/dts-plugin/src/core/rpc/types.ts
1645
- var RpcGMCallTypes = /* @__PURE__ */ ((RpcGMCallTypes2) => {
1744
+ var RpcGMCallTypes;
1745
+ (function(RpcGMCallTypes2) {
1646
1746
  RpcGMCallTypes2["CALL"] = "mf_call";
1647
1747
  RpcGMCallTypes2["RESOLVE"] = "mf_resolve";
1648
1748
  RpcGMCallTypes2["REJECT"] = "mf_reject";
1649
1749
  RpcGMCallTypes2["EXIT"] = "mf_exit";
1650
- return RpcGMCallTypes2;
1651
- })(RpcGMCallTypes || {});
1750
+ })(RpcGMCallTypes || (RpcGMCallTypes = {}));
1652
1751
 
1653
1752
  // packages/dts-plugin/src/core/rpc/expose-rpc.ts
1654
1753
  function exposeRpc(fn) {
1655
- const sendMessage = (message) => new Promise((resolve4, reject) => {
1754
+ const sendMessage = /* @__PURE__ */ __name((message) => new Promise((resolve4, reject) => {
1656
1755
  if (!import_process.default.send) {
1657
1756
  reject(new Error(`Process ${import_process.default.pid} doesn't have IPC channels`));
1658
1757
  } else if (!import_process.default.connected) {
1659
- reject(
1660
- new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`)
1661
- );
1758
+ reject(new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`));
1662
1759
  } else {
1663
1760
  import_process.default.send(message, void 0, void 0, (error2) => {
1664
1761
  if (error2) {
@@ -1668,28 +1765,28 @@ function exposeRpc(fn) {
1668
1765
  }
1669
1766
  });
1670
1767
  }
1671
- });
1672
- const handleMessage = async (message) => {
1673
- if (message.type === "mf_call" /* CALL */) {
1768
+ }), "sendMessage");
1769
+ const handleMessage = /* @__PURE__ */ __name((message) => __async(this, null, function* () {
1770
+ if (message.type === RpcGMCallTypes.CALL) {
1674
1771
  if (!import_process.default.send) {
1675
1772
  return;
1676
1773
  }
1677
1774
  let value, error2;
1678
1775
  try {
1679
- value = await fn(...message.args);
1776
+ value = yield fn(...message.args);
1680
1777
  } catch (fnError) {
1681
1778
  error2 = fnError;
1682
1779
  }
1683
1780
  try {
1684
1781
  if (error2) {
1685
- await sendMessage({
1686
- type: "mf_reject" /* REJECT */,
1782
+ yield sendMessage({
1783
+ type: RpcGMCallTypes.REJECT,
1687
1784
  id: message.id,
1688
1785
  error: error2
1689
1786
  });
1690
1787
  } else {
1691
- await sendMessage({
1692
- type: "mf_resolve" /* RESOLVE */,
1788
+ yield sendMessage({
1789
+ type: RpcGMCallTypes.RESOLVE,
1693
1790
  id: message.id,
1694
1791
  value
1695
1792
  });
@@ -1703,24 +1800,28 @@ function exposeRpc(fn) {
1703
1800
  console.error(sendError);
1704
1801
  }
1705
1802
  }
1706
- };
1803
+ }), "handleMessage");
1707
1804
  import_process.default.on("message", handleMessage);
1708
1805
  }
1806
+ __name(exposeRpc, "exposeRpc");
1709
1807
 
1710
1808
  // packages/dts-plugin/src/core/rpc/rpc-error.ts
1711
- var RpcExitError = class extends Error {
1809
+ var _a2;
1810
+ var RpcExitError = (_a2 = class extends Error {
1712
1811
  constructor(message, code, signal) {
1713
1812
  super(message);
1813
+ __publicField(this, "code");
1814
+ __publicField(this, "signal");
1714
1815
  this.code = code;
1715
1816
  this.signal = signal;
1716
1817
  this.name = "RpcExitError";
1717
1818
  }
1718
- };
1819
+ }, __name(_a2, "RpcExitError"), _a2);
1719
1820
 
1720
1821
  // packages/dts-plugin/src/core/rpc/wrap-rpc.ts
1721
1822
  function createControlledPromise() {
1722
- let resolve4 = () => void 0;
1723
- let reject = () => void 0;
1823
+ let resolve4 = /* @__PURE__ */ __name(() => void 0, "resolve");
1824
+ let reject = /* @__PURE__ */ __name(() => void 0, "reject");
1724
1825
  const promise = new Promise((aResolve, aReject) => {
1725
1826
  resolve4 = aResolve;
1726
1827
  reject = aReject;
@@ -1731,76 +1832,59 @@ function createControlledPromise() {
1731
1832
  reject
1732
1833
  };
1733
1834
  }
1835
+ __name(createControlledPromise, "createControlledPromise");
1734
1836
  function wrapRpc(childProcess, options) {
1735
- return async (...args) => {
1837
+ return (...args) => __async(this, null, function* () {
1736
1838
  if (!childProcess.send) {
1737
1839
  throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
1738
1840
  } else if (!childProcess.connected) {
1739
- throw new Error(
1740
- `Process ${childProcess.pid} doesn't have open IPC channels`
1741
- );
1841
+ throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
1742
1842
  }
1743
1843
  const { id, once } = options;
1744
- const {
1745
- promise: resultPromise,
1746
- resolve: resolveResult,
1747
- reject: rejectResult
1748
- } = createControlledPromise();
1749
- const {
1750
- promise: sendPromise,
1751
- resolve: resolveSend,
1752
- reject: rejectSend
1753
- } = createControlledPromise();
1754
- const handleMessage = (message) => {
1844
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
1845
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
1846
+ const handleMessage = /* @__PURE__ */ __name((message) => {
1755
1847
  if ((message == null ? void 0 : message.id) === id) {
1756
- if (message.type === "mf_resolve" /* RESOLVE */) {
1848
+ if (message.type === RpcGMCallTypes.RESOLVE) {
1757
1849
  resolveResult(message.value);
1758
- } else if (message.type === "mf_reject" /* REJECT */) {
1850
+ } else if (message.type === RpcGMCallTypes.REJECT) {
1759
1851
  rejectResult(message.error);
1760
1852
  }
1761
1853
  }
1762
1854
  if (once && (childProcess == null ? void 0 : childProcess.kill)) {
1763
1855
  childProcess.kill("SIGTERM");
1764
1856
  }
1765
- };
1766
- const handleClose = (code, signal) => {
1767
- rejectResult(
1768
- new RpcExitError(
1769
- code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`,
1770
- code,
1771
- signal
1772
- )
1773
- );
1857
+ }, "handleMessage");
1858
+ const handleClose = /* @__PURE__ */ __name((code, signal) => {
1859
+ rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
1774
1860
  removeHandlers();
1775
- };
1776
- const removeHandlers = () => {
1861
+ }, "handleClose");
1862
+ const removeHandlers = /* @__PURE__ */ __name(() => {
1777
1863
  childProcess.off("message", handleMessage);
1778
1864
  childProcess.off("close", handleClose);
1779
- };
1865
+ }, "removeHandlers");
1780
1866
  if (once) {
1781
1867
  childProcess.once("message", handleMessage);
1782
1868
  } else {
1783
1869
  childProcess.on("message", handleMessage);
1784
1870
  }
1785
1871
  childProcess.on("close", handleClose);
1786
- childProcess.send(
1787
- {
1788
- type: "mf_call" /* CALL */,
1789
- id,
1790
- args
1791
- },
1792
- (error2) => {
1793
- if (error2) {
1794
- rejectSend(error2);
1795
- removeHandlers();
1796
- } else {
1797
- resolveSend(void 0);
1798
- }
1872
+ childProcess.send({
1873
+ type: RpcGMCallTypes.CALL,
1874
+ id,
1875
+ args
1876
+ }, (error2) => {
1877
+ if (error2) {
1878
+ rejectSend(error2);
1879
+ removeHandlers();
1880
+ } else {
1881
+ resolveSend(void 0);
1799
1882
  }
1800
- );
1883
+ });
1801
1884
  return sendPromise.then(() => resultPromise);
1802
- };
1885
+ });
1803
1886
  }
1887
+ __name(wrapRpc, "wrapRpc");
1804
1888
 
1805
1889
  // packages/dts-plugin/src/core/rpc/rpc-worker.ts
1806
1890
  var child_process = __toESM(require("child_process"));
@@ -1809,15 +1893,21 @@ var import_crypto = require("crypto");
1809
1893
  var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
1810
1894
  function createRpcWorker(modulePath, data, memoryLimit, once) {
1811
1895
  const options = {
1812
- env: {
1813
- ...process3.env,
1896
+ env: __spreadProps(__spreadValues({}, process3.env), {
1814
1897
  [FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
1815
- },
1816
- stdio: ["inherit", "inherit", "inherit", "ipc"],
1898
+ }),
1899
+ stdio: [
1900
+ "inherit",
1901
+ "inherit",
1902
+ "inherit",
1903
+ "ipc"
1904
+ ],
1817
1905
  serialization: "advanced"
1818
1906
  };
1819
1907
  if (memoryLimit) {
1820
- options.execArgv = [`--max-old-space-size=${memoryLimit}`];
1908
+ options.execArgv = [
1909
+ `--max-old-space-size=${memoryLimit}`
1910
+ ];
1821
1911
  }
1822
1912
  let childProcess, remoteMethod;
1823
1913
  const id = (0, import_crypto.randomUUID)();
@@ -1825,7 +1915,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
1825
1915
  connect(...args) {
1826
1916
  if (childProcess && !childProcess.connected) {
1827
1917
  childProcess.send({
1828
- type: "mf_exit" /* EXIT */,
1918
+ type: RpcGMCallTypes.EXIT,
1829
1919
  id
1830
1920
  });
1831
1921
  childProcess = void 0;
@@ -1833,19 +1923,20 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
1833
1923
  }
1834
1924
  if (!(childProcess == null ? void 0 : childProcess.connected)) {
1835
1925
  childProcess = child_process.fork(modulePath, options);
1836
- remoteMethod = wrapRpc(childProcess, { id, once });
1926
+ remoteMethod = wrapRpc(childProcess, {
1927
+ id,
1928
+ once
1929
+ });
1837
1930
  }
1838
1931
  if (!remoteMethod) {
1839
- return Promise.reject(
1840
- new Error("Worker is not connected - cannot perform RPC.")
1841
- );
1932
+ return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
1842
1933
  }
1843
1934
  return remoteMethod(...args);
1844
1935
  },
1845
1936
  terminate() {
1846
- var _a;
1847
- (_a = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a.call(childProcess, {
1848
- type: "mf_exit" /* EXIT */,
1937
+ var _a3;
1938
+ (_a3 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a3.call(childProcess, {
1939
+ type: RpcGMCallTypes.EXIT,
1849
1940
  id
1850
1941
  });
1851
1942
  childProcess = void 0;
@@ -1863,30 +1954,30 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
1863
1954
  };
1864
1955
  return worker;
1865
1956
  }
1957
+ __name(createRpcWorker, "createRpcWorker");
1866
1958
  function getRpcWorkerData() {
1867
1959
  return JSON.parse(process3.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
1868
1960
  }
1961
+ __name(getRpcWorkerData, "getRpcWorkerData");
1869
1962
 
1870
1963
  // packages/dts-plugin/src/core/lib/DtsWorker.ts
1871
- var DtsWorker = class {
1964
+ var _DtsWorker = class _DtsWorker {
1872
1965
  constructor(options) {
1966
+ __publicField(this, "rpcWorker");
1967
+ __publicField(this, "_options");
1968
+ __publicField(this, "_res");
1873
1969
  this._options = (0, import_lodash2.default)(options, (_value, key) => {
1874
1970
  if (key === "manifest") {
1875
1971
  return false;
1876
1972
  }
1877
1973
  });
1878
1974
  this.removeUnSerializationOptions();
1879
- this.rpcWorker = createRpcWorker(
1880
- import_path6.default.resolve(__dirname, "./forkGenerateDts.js"),
1881
- {},
1882
- void 0,
1883
- true
1884
- );
1975
+ this.rpcWorker = createRpcWorker(import_path6.default.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
1885
1976
  this._res = this.rpcWorker.connect(this._options);
1886
1977
  }
1887
1978
  removeUnSerializationOptions() {
1888
- var _a, _b, _c, _d, _e, _f, _g, _h;
1889
- if ((_b = (_a = this._options.remote) == null ? void 0 : _a.moduleFederationConfig) == null ? void 0 : _b.manifest) {
1979
+ var _a3, _b, _c, _d, _e, _f, _g, _h;
1980
+ if ((_b = (_a3 = this._options.remote) == null ? void 0 : _a3.moduleFederationConfig) == null ? void 0 : _b.manifest) {
1890
1981
  (_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
1891
1982
  }
1892
1983
  if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
@@ -1899,26 +1990,32 @@ var DtsWorker = class {
1899
1990
  });
1900
1991
  }
1901
1992
  exit() {
1902
- var _a;
1903
- (_a = this.rpcWorker) == null ? void 0 : _a.terminate();
1993
+ var _a3;
1994
+ (_a3 = this.rpcWorker) == null ? void 0 : _a3.terminate();
1904
1995
  }
1905
1996
  };
1997
+ __name(_DtsWorker, "DtsWorker");
1998
+ var DtsWorker = _DtsWorker;
1906
1999
 
1907
2000
  // packages/dts-plugin/src/core/lib/generateTypesInChildProcess.ts
1908
- async function generateTypesInChildProcess(options) {
1909
- const dtsWorker = new DtsWorker(options);
1910
- return dtsWorker.controlledPromise;
2001
+ function generateTypesInChildProcess(options) {
2002
+ return __async(this, null, function* () {
2003
+ const dtsWorker = new DtsWorker(options);
2004
+ return dtsWorker.controlledPromise;
2005
+ });
1911
2006
  }
2007
+ __name(generateTypesInChildProcess, "generateTypesInChildProcess");
1912
2008
 
1913
2009
  // packages/dts-plugin/src/core/lib/consumeTypes.ts
1914
- async function consumeTypes(options) {
1915
- var _a;
1916
- const DTSManagerConstructor = getDTSManagerConstructor(
1917
- (_a = options.host) == null ? void 0 : _a.implementation
1918
- );
1919
- const dtsManager = new DTSManagerConstructor(options);
1920
- await dtsManager.consumeTypes();
2010
+ function consumeTypes(options) {
2011
+ return __async(this, null, function* () {
2012
+ var _a3;
2013
+ const DTSManagerConstructor = getDTSManagerConstructor((_a3 = options.host) == null ? void 0 : _a3.implementation);
2014
+ const dtsManager = new DTSManagerConstructor(options);
2015
+ yield dtsManager.consumeTypes();
2016
+ });
1921
2017
  }
2018
+ __name(consumeTypes, "consumeTypes");
1922
2019
  // Annotate the CommonJS export names for ESM import in node:
1923
2020
  0 && (module.exports = {
1924
2021
  DTSManager,