@module-federation/dts-plugin 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,10 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
7
  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
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
9
  var __export = (target, all) => {
26
10
  for (var name in all)
@@ -78,27 +62,19 @@ module.exports = __toCommonJS(startBroker_exports);
78
62
  // packages/dts-plugin/src/server/broker/Broker.ts
79
63
  var import_http = require("http");
80
64
 
81
- // packages/dts-plugin/src/core/configurations/remotePlugin.ts
82
- var import_managers2 = require("@module-federation/managers");
83
- var import_typescript = __toESM(require("typescript"));
84
-
85
- // packages/dts-plugin/src/core/lib/utils.ts
86
- var import_axios = __toESM(require("axios"));
87
- var import_ansi_colors2 = __toESM(require("ansi-colors"));
88
-
89
- // packages/dts-plugin/src/core/lib/DTSManager.ts
90
- var import_ansi_colors = __toESM(require("ansi-colors"));
91
- var import_sdk5 = require("@module-federation/sdk");
92
- var import_lodash = __toESM(require("lodash.clonedeepwith"));
93
- var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
94
-
95
- // packages/dts-plugin/src/core/lib/archiveHandler.ts
96
- var import_adm_zip = __toESM(require("adm-zip"));
65
+ // packages/dts-plugin/src/server/constant.ts
66
+ var DEFAULT_WEB_SOCKET_PORT = 16322;
67
+ var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
68
+ var UpdateMode;
69
+ (function(UpdateMode2) {
70
+ UpdateMode2["POSITIVE"] = "POSITIVE";
71
+ UpdateMode2["PASSIVE"] = "PASSIVE";
72
+ })(UpdateMode || (UpdateMode = {}));
97
73
 
98
- // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
99
- var import_fs_extra = require("fs-extra");
100
- var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
101
- var import_sdk = require("@module-federation/sdk");
74
+ // packages/dts-plugin/src/server/broker/Broker.ts
75
+ var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
76
+ var import_node_schedule = __toESM(require("node-schedule"));
77
+ var import_url = require("url");
102
78
 
103
79
  // packages/dts-plugin/src/server/message/Message.ts
104
80
  var _Message = class _Message {
@@ -171,7 +147,7 @@ __name(_FetchTypesAPI, "FetchTypesAPI");
171
147
  var FetchTypesAPI = _FetchTypesAPI;
172
148
 
173
149
  // packages/dts-plugin/src/server/utils/index.ts
174
- var import_sdk3 = require("@module-federation/sdk");
150
+ var import_sdk2 = require("@module-federation/sdk");
175
151
 
176
152
  // packages/dts-plugin/src/server/utils/logTransform.ts
177
153
  var import_chalk = __toESM(require("chalk"));
@@ -210,18 +186,12 @@ __name(_BrokerExitLog, "BrokerExitLog");
210
186
  var BrokerExitLog = _BrokerExitLog;
211
187
 
212
188
  // packages/dts-plugin/src/server/utils/log.ts
213
- var import_sdk2 = require("@module-federation/sdk");
189
+ var import_sdk = require("@module-federation/sdk");
214
190
  var log4js = __toESM(require("log4js"));
215
191
  var import_chalk2 = __toESM(require("chalk"));
216
-
217
- // packages/dts-plugin/src/server/constant.ts
218
- var DEFAULT_WEB_SOCKET_PORT = 16322;
219
- var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
220
-
221
- // packages/dts-plugin/src/server/utils/log.ts
222
192
  function fileLog(msg, module2, level) {
223
- var _a2, _b;
224
- if (!((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2["FEDERATION_DEBUG"])) {
193
+ var _a, _b;
194
+ if (!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a["FEDERATION_DEBUG"])) {
225
195
  return;
226
196
  }
227
197
  log4js.configure({
@@ -265,7 +235,7 @@ __name(error, "error");
265
235
  // packages/dts-plugin/src/server/utils/index.ts
266
236
  function getIdentifier(options) {
267
237
  const { ip, name } = options;
268
- return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
238
+ return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
269
239
  }
270
240
  __name(getIdentifier, "getIdentifier");
271
241
 
@@ -359,9 +329,6 @@ var _Publisher = class _Publisher {
359
329
  __name(_Publisher, "Publisher");
360
330
  var Publisher = _Publisher;
361
331
 
362
- // packages/dts-plugin/src/server/DevServer.ts
363
- var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
364
-
365
332
  // packages/dts-plugin/src/server/message/Action/Action.ts
366
333
  var ActionKind;
367
334
  (function(ActionKind2) {
@@ -384,290 +351,7 @@ var UpdateKind;
384
351
  UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
385
352
  })(UpdateKind || (UpdateKind = {}));
386
353
 
387
- // packages/dts-plugin/src/core/constant.ts
388
- var UpdateMode;
389
- (function(UpdateMode2) {
390
- UpdateMode2["POSITIVE"] = "POSITIVE";
391
- UpdateMode2["PASSIVE"] = "PASSIVE";
392
- })(UpdateMode || (UpdateMode = {}));
393
-
394
- // packages/dts-plugin/src/server/createKoaServer.ts
395
- var import_fs_extra2 = __toESM(require("fs-extra"));
396
- var import_koa = __toESM(require("koa"));
397
-
398
- // packages/dts-plugin/src/core/configurations/hostPlugin.ts
399
- var import_sdk4 = require("@module-federation/sdk");
400
- var import_managers = require("@module-federation/managers");
401
- var defaultOptions = {
402
- typesFolder: "@mf-types",
403
- remoteTypesFolder: "@mf-types",
404
- deleteTypesFolder: true,
405
- maxRetries: 3,
406
- implementation: "",
407
- context: process.cwd(),
408
- abortOnError: true,
409
- consumeAPITypes: false
410
- };
411
-
412
- // packages/dts-plugin/src/core/configurations/remotePlugin.ts
413
- var defaultOptions2 = {
414
- tsConfigPath: "./tsconfig.json",
415
- typesFolder: "@mf-types",
416
- compiledTypesFolder: "compiled-types",
417
- hostRemoteTypesFolder: "@mf-types",
418
- deleteTypesFolder: true,
419
- additionalFilesToCompile: [],
420
- compilerInstance: "tsc",
421
- compileInChildProcess: false,
422
- implementation: "",
423
- generateAPITypes: false,
424
- context: process.cwd(),
425
- abortOnError: true,
426
- extractRemoteTypes: false,
427
- extractThirdParty: false
428
- };
429
-
430
- // packages/dts-plugin/src/core/lib/DtsWorker.ts
431
- var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
432
-
433
- // packages/dts-plugin/src/core/rpc/index.ts
434
- var rpc_exports = {};
435
- __export(rpc_exports, {
436
- RpcExitError: () => RpcExitError,
437
- RpcGMCallTypes: () => RpcGMCallTypes,
438
- createRpcWorker: () => createRpcWorker,
439
- exposeRpc: () => exposeRpc,
440
- getRpcWorkerData: () => getRpcWorkerData,
441
- wrapRpc: () => wrapRpc
442
- });
443
-
444
- // packages/dts-plugin/src/core/rpc/expose-rpc.ts
445
- var import_process = __toESM(require("process"));
446
-
447
- // packages/dts-plugin/src/core/rpc/types.ts
448
- var RpcGMCallTypes;
449
- (function(RpcGMCallTypes2) {
450
- RpcGMCallTypes2["CALL"] = "mf_call";
451
- RpcGMCallTypes2["RESOLVE"] = "mf_resolve";
452
- RpcGMCallTypes2["REJECT"] = "mf_reject";
453
- RpcGMCallTypes2["EXIT"] = "mf_exit";
454
- })(RpcGMCallTypes || (RpcGMCallTypes = {}));
455
-
456
- // packages/dts-plugin/src/core/rpc/expose-rpc.ts
457
- function exposeRpc(fn) {
458
- const sendMessage = /* @__PURE__ */ __name((message) => new Promise((resolve, reject) => {
459
- if (!import_process.default.send) {
460
- reject(new Error(`Process ${import_process.default.pid} doesn't have IPC channels`));
461
- } else if (!import_process.default.connected) {
462
- reject(new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`));
463
- } else {
464
- import_process.default.send(message, void 0, void 0, (error2) => {
465
- if (error2) {
466
- reject(error2);
467
- } else {
468
- resolve(void 0);
469
- }
470
- });
471
- }
472
- }), "sendMessage");
473
- const handleMessage = /* @__PURE__ */ __name((message) => __async(this, null, function* () {
474
- if (message.type === RpcGMCallTypes.CALL) {
475
- if (!import_process.default.send) {
476
- return;
477
- }
478
- let value, error2;
479
- try {
480
- value = yield fn(...message.args);
481
- } catch (fnError) {
482
- error2 = fnError;
483
- }
484
- try {
485
- if (error2) {
486
- yield sendMessage({
487
- type: RpcGMCallTypes.REJECT,
488
- id: message.id,
489
- error: error2
490
- });
491
- } else {
492
- yield sendMessage({
493
- type: RpcGMCallTypes.RESOLVE,
494
- id: message.id,
495
- value
496
- });
497
- }
498
- } catch (sendError) {
499
- if (error2) {
500
- if (error2 instanceof Error) {
501
- console.error(error2);
502
- }
503
- }
504
- console.error(sendError);
505
- }
506
- }
507
- }), "handleMessage");
508
- import_process.default.on("message", handleMessage);
509
- }
510
- __name(exposeRpc, "exposeRpc");
511
-
512
- // packages/dts-plugin/src/core/rpc/rpc-error.ts
513
- var _a;
514
- var RpcExitError = (_a = class extends Error {
515
- constructor(message, code, signal) {
516
- super(message);
517
- __publicField(this, "code");
518
- __publicField(this, "signal");
519
- this.code = code;
520
- this.signal = signal;
521
- this.name = "RpcExitError";
522
- }
523
- }, __name(_a, "RpcExitError"), _a);
524
-
525
- // packages/dts-plugin/src/core/rpc/wrap-rpc.ts
526
- function createControlledPromise() {
527
- let resolve = /* @__PURE__ */ __name(() => void 0, "resolve");
528
- let reject = /* @__PURE__ */ __name(() => void 0, "reject");
529
- const promise = new Promise((aResolve, aReject) => {
530
- resolve = aResolve;
531
- reject = aReject;
532
- });
533
- return {
534
- promise,
535
- resolve,
536
- reject
537
- };
538
- }
539
- __name(createControlledPromise, "createControlledPromise");
540
- function wrapRpc(childProcess, options) {
541
- return (...args) => __async(this, null, function* () {
542
- if (!childProcess.send) {
543
- throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
544
- } else if (!childProcess.connected) {
545
- throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
546
- }
547
- const { id, once } = options;
548
- const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
549
- const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
550
- const handleMessage = /* @__PURE__ */ __name((message) => {
551
- if ((message == null ? void 0 : message.id) === id) {
552
- if (message.type === RpcGMCallTypes.RESOLVE) {
553
- resolveResult(message.value);
554
- } else if (message.type === RpcGMCallTypes.REJECT) {
555
- rejectResult(message.error);
556
- }
557
- }
558
- if (once && (childProcess == null ? void 0 : childProcess.kill)) {
559
- childProcess.kill("SIGTERM");
560
- }
561
- }, "handleMessage");
562
- const handleClose = /* @__PURE__ */ __name((code, signal) => {
563
- rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
564
- removeHandlers();
565
- }, "handleClose");
566
- const removeHandlers = /* @__PURE__ */ __name(() => {
567
- childProcess.off("message", handleMessage);
568
- childProcess.off("close", handleClose);
569
- }, "removeHandlers");
570
- if (once) {
571
- childProcess.once("message", handleMessage);
572
- } else {
573
- childProcess.on("message", handleMessage);
574
- }
575
- childProcess.on("close", handleClose);
576
- childProcess.send({
577
- type: RpcGMCallTypes.CALL,
578
- id,
579
- args
580
- }, (error2) => {
581
- if (error2) {
582
- rejectSend(error2);
583
- removeHandlers();
584
- } else {
585
- resolveSend(void 0);
586
- }
587
- });
588
- return sendPromise.then(() => resultPromise);
589
- });
590
- }
591
- __name(wrapRpc, "wrapRpc");
592
-
593
- // packages/dts-plugin/src/core/rpc/rpc-worker.ts
594
- var child_process = __toESM(require("child_process"));
595
- var process3 = __toESM(require("process"));
596
- var import_crypto = require("crypto");
597
- var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
598
- function createRpcWorker(modulePath, data, memoryLimit, once) {
599
- const options = {
600
- env: __spreadProps(__spreadValues({}, process3.env), {
601
- [FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
602
- }),
603
- stdio: [
604
- "inherit",
605
- "inherit",
606
- "inherit",
607
- "ipc"
608
- ],
609
- serialization: "advanced"
610
- };
611
- if (memoryLimit) {
612
- options.execArgv = [
613
- `--max-old-space-size=${memoryLimit}`
614
- ];
615
- }
616
- let childProcess, remoteMethod;
617
- const id = (0, import_crypto.randomUUID)();
618
- const worker = {
619
- connect(...args) {
620
- if (childProcess && !childProcess.connected) {
621
- childProcess.send({
622
- type: RpcGMCallTypes.EXIT,
623
- id
624
- });
625
- childProcess = void 0;
626
- remoteMethod = void 0;
627
- }
628
- if (!(childProcess == null ? void 0 : childProcess.connected)) {
629
- childProcess = child_process.fork(modulePath, options);
630
- remoteMethod = wrapRpc(childProcess, {
631
- id,
632
- once
633
- });
634
- }
635
- if (!remoteMethod) {
636
- return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
637
- }
638
- return remoteMethod(...args);
639
- },
640
- terminate() {
641
- var _a2;
642
- (_a2 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a2.call(childProcess, {
643
- type: RpcGMCallTypes.EXIT,
644
- id
645
- });
646
- childProcess = void 0;
647
- remoteMethod = void 0;
648
- },
649
- get connected() {
650
- return Boolean(childProcess == null ? void 0 : childProcess.connected);
651
- },
652
- get process() {
653
- return childProcess;
654
- },
655
- get id() {
656
- return id;
657
- }
658
- };
659
- return worker;
660
- }
661
- __name(createRpcWorker, "createRpcWorker");
662
- function getRpcWorkerData() {
663
- return JSON.parse(process3.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
664
- }
665
- __name(getRpcWorkerData, "getRpcWorkerData");
666
-
667
354
  // packages/dts-plugin/src/server/broker/Broker.ts
668
- var import_isomorphic_ws2 = __toESM(require("isomorphic-ws"));
669
- var import_node_schedule = __toESM(require("node-schedule"));
670
- var import_url = require("url");
671
355
  var _Broker = class _Broker {
672
356
  constructor() {
673
357
  __publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
@@ -711,7 +395,7 @@ var _Broker = class _Broker {
711
395
  }
712
396
  }, "wsHandler");
713
397
  const server = (0, import_http.createServer)();
714
- this._webSocketServer = new import_isomorphic_ws2.default.Server({
398
+ this._webSocketServer = new import_isomorphic_ws.default.Server({
715
399
  noServer: true
716
400
  });
717
401
  this._webSocketServer.on("error", (err) => {
@@ -729,13 +413,13 @@ ${err.message}
729
413
  this._webSocketServer = void 0;
730
414
  });
731
415
  server.on("upgrade", (req, socket, head) => {
732
- var _a2;
416
+ var _a;
733
417
  if (req.url) {
734
418
  const { pathname } = (0, import_url.parse)(req.url);
735
419
  if (pathname === "/") {
736
- (_a2 = this._webSocketServer) == null ? void 0 : _a2.handleUpgrade(req, socket, head, (ws) => {
737
- var _a3;
738
- (_a3 = this._webSocketServer) == null ? void 0 : _a3.emit("connection", ws, req);
420
+ (_a = this._webSocketServer) == null ? void 0 : _a.handleUpgrade(req, socket, head, (ws) => {
421
+ var _a2;
422
+ (_a2 = this._webSocketServer) == null ? void 0 : _a2.emit("connection", ws, req);
739
423
  });
740
424
  }
741
425
  }
@@ -1120,8 +804,8 @@ ${err.message}
1120
804
  }
1121
805
  }
1122
806
  _getTmpSubScribers(publisherIdentifier) {
1123
- var _a2;
1124
- return (_a2 = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a2.subscribers;
807
+ var _a;
808
+ return (_a = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a.subscribers;
1125
809
  }
1126
810
  // after adding publisher, it will change the temp subscriber to regular subscriber
1127
811
  _consumeTmpSubScribers(publisher, tmpSubScribers) {
@@ -1226,9 +910,9 @@ ${err.message}
1226
910
  process.exit(0);
1227
911
  }
1228
912
  broadcast(message) {
1229
- var _a2, _b;
913
+ var _a, _b;
1230
914
  fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
1231
- (_a2 = this._webSocketServer) == null ? void 0 : _a2.clients.forEach((client) => {
915
+ (_a = this._webSocketServer) == null ? void 0 : _a.clients.forEach((client) => {
1232
916
  client.send(JSON.stringify(message));
1233
917
  });
1234
918
  (_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
@@ -1251,13 +935,13 @@ function getBroker() {
1251
935
  __name(getBroker, "getBroker");
1252
936
  function startBroker() {
1253
937
  return __async(this, null, function* () {
1254
- var _a2;
938
+ var _a;
1255
939
  if (getBroker()) {
1256
940
  return;
1257
941
  }
1258
942
  broker = new Broker();
1259
943
  yield broker.start();
1260
- (_a2 = process.send) == null ? void 0 : _a2.call(process, "ready");
944
+ (_a = process.send) == null ? void 0 : _a.call(process, "ready");
1261
945
  });
1262
946
  }
1263
947
  __name(startBroker, "startBroker");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/dts-plugin",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -55,9 +55,9 @@
55
55
  "log4js": "6.9.1",
56
56
  "node-schedule": "2.1.1",
57
57
  "ws": "8.17.1",
58
- "@module-federation/sdk": "0.2.7",
59
- "@module-federation/managers": "0.2.7",
60
- "@module-federation/third-party-dts-extractor": "0.2.7"
58
+ "@module-federation/sdk": "0.3.0",
59
+ "@module-federation/managers": "0.3.0",
60
+ "@module-federation/third-party-dts-extractor": "0.3.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/ws": "8.5.10",
@@ -66,7 +66,7 @@
66
66
  "vue": "^3.4.29",
67
67
  "@vue/tsconfig": "^0.5.1",
68
68
  "vue-tsc": "^2.0.26",
69
- "@module-federation/runtime": "0.2.7"
69
+ "@module-federation/runtime": "0.3.0"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "typescript": "^4.9.0 || ^5.0.0",