@module-federation/dts-plugin 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/Action-CzhPMw2i.js +153 -0
  2. package/dist/Broker-DRlzScTT.js +800 -0
  3. package/dist/CHANGELOG.md +15 -0
  4. package/dist/DtsWorker-Dtem3-FM.d.ts +166 -0
  5. package/dist/constant-BwEkyidO.d.ts +42 -0
  6. package/dist/consumeTypes-AD2ig87l.js +237 -0
  7. package/dist/core.d.ts +3 -68
  8. package/dist/core.js +26 -2443
  9. package/dist/dynamic-remote-type-hints-plugin.d.ts +622 -3
  10. package/dist/dynamic-remote-type-hints-plugin.js +65 -187
  11. package/dist/esm/Action-DNNg2YDh.mjs +47 -0
  12. package/dist/esm/Broker-BU4gToNr.mjs +736 -0
  13. package/dist/esm/consumeTypes-D51rVbSt.mjs +204 -0
  14. package/dist/esm/core.mjs +5 -0
  15. package/dist/esm/dynamic-remote-type-hints-plugin.mjs +73 -0
  16. package/dist/esm/expose-rpc-DMhY1i8A.mjs +1301 -0
  17. package/dist/esm/fork-dev-worker.mjs +103 -0
  18. package/dist/esm/fork-generate-dts.mjs +14 -0
  19. package/dist/esm/index.mjs +465 -0
  20. package/dist/esm/start-broker.mjs +22 -0
  21. package/dist/esm/utils-CkPvDGOy.mjs +13 -0
  22. package/dist/expose-rpc-BLAH20uj.js +1415 -0
  23. package/dist/fork-dev-worker.d.ts +10 -9
  24. package/dist/fork-dev-worker.js +100 -2932
  25. package/dist/fork-generate-dts.d.ts +4 -8
  26. package/dist/fork-generate-dts.js +11 -2103
  27. package/dist/iife/launch-web-client.iife.js +117 -0
  28. package/dist/index.d.ts +57 -46
  29. package/dist/index.js +449 -3043
  30. package/dist/package.json +26 -11
  31. package/dist/start-broker.d.ts +41 -39
  32. package/dist/start-broker.js +17 -952
  33. package/dist/utils-7KqCZHbb.js +19 -0
  34. package/package.json +31 -16
  35. package/dist/DTSManager-b15Gfat3.d.ts +0 -53
  36. package/dist/DTSManagerOptions-QVchWb0x.d.ts +0 -32
  37. package/dist/DtsWorker-BrHsGz8C.d.ts +0 -56
  38. package/dist/core.d.mts +0 -68
  39. package/dist/dynamic-remote-type-hints-plugin.d.mts +0 -5
  40. package/dist/esm/chunk-647HGGGS.js +0 -241
  41. package/dist/esm/chunk-G65LOFTY.js +0 -24
  42. package/dist/esm/chunk-LJTUMI5K.js +0 -282
  43. package/dist/esm/chunk-MV6M4VFH.js +0 -1642
  44. package/dist/esm/chunk-WWV5RWOP.js +0 -902
  45. package/dist/esm/core.js +0 -44
  46. package/dist/esm/dynamic-remote-type-hints-plugin.js +0 -73
  47. package/dist/esm/fork-dev-worker.js +0 -145
  48. package/dist/esm/fork-generate-dts.js +0 -27
  49. package/dist/esm/index.js +0 -646
  50. package/dist/esm/start-broker.js +0 -36
  51. package/dist/fork-dev-worker.d.mts +0 -15
  52. package/dist/fork-generate-dts.d.mts +0 -10
  53. package/dist/iife/launch-web-client.js +0 -152
  54. package/dist/index.d.mts +0 -56
  55. package/dist/start-broker.d.mts +0 -42
  56. package/dist/utils-C4sQemLR.d.ts +0 -15
@@ -0,0 +1,204 @@
1
+ import { a as cloneDeepOptions, n as RpcGMCallTypes, o as getDTSManagerConstructor, s as isDebugMode, t as exposeRpc, x as __exportAll } from "./expose-rpc-DMhY1i8A.mjs";
2
+ import path from "path";
3
+ import { randomUUID } from "crypto";
4
+ import * as child_process from "child_process";
5
+ import * as process$2 from "process";
6
+
7
+ //#region src/core/rpc/rpc-error.ts
8
+ var RpcExitError = class extends Error {
9
+ constructor(message, code, signal) {
10
+ super(message);
11
+ this.code = code;
12
+ this.signal = signal;
13
+ this.name = "RpcExitError";
14
+ }
15
+ };
16
+
17
+ //#endregion
18
+ //#region src/core/rpc/wrap-rpc.ts
19
+ function createControlledPromise() {
20
+ let resolve = () => void 0;
21
+ let reject = () => void 0;
22
+ return {
23
+ promise: new Promise((aResolve, aReject) => {
24
+ resolve = aResolve;
25
+ reject = aReject;
26
+ }),
27
+ resolve,
28
+ reject
29
+ };
30
+ }
31
+ function wrapRpc(childProcess, options) {
32
+ return (async (...args) => {
33
+ if (!childProcess.send) throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
34
+ else if (!childProcess.connected) throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
35
+ const { id, once } = options;
36
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
37
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
38
+ const handleMessage = (message) => {
39
+ if (message?.id === id) {
40
+ if (message.type === RpcGMCallTypes.RESOLVE) resolveResult(message.value);
41
+ else if (message.type === RpcGMCallTypes.REJECT) rejectResult(message.error);
42
+ }
43
+ if (once && childProcess?.kill) childProcess.kill("SIGTERM");
44
+ };
45
+ const handleClose = (code, signal) => {
46
+ rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
47
+ removeHandlers();
48
+ };
49
+ const removeHandlers = () => {
50
+ childProcess.off("message", handleMessage);
51
+ childProcess.off("close", handleClose);
52
+ };
53
+ if (once) childProcess.once("message", handleMessage);
54
+ else childProcess.on("message", handleMessage);
55
+ childProcess.on("close", handleClose);
56
+ childProcess.send({
57
+ type: RpcGMCallTypes.CALL,
58
+ id,
59
+ args
60
+ }, (error) => {
61
+ if (error) {
62
+ rejectSend(error);
63
+ removeHandlers();
64
+ } else resolveSend(void 0);
65
+ });
66
+ return sendPromise.then(() => resultPromise);
67
+ });
68
+ }
69
+
70
+ //#endregion
71
+ //#region src/core/rpc/rpc-worker.ts
72
+ const FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
73
+ function createRpcWorker(modulePath, data, memoryLimit, once) {
74
+ const options = {
75
+ env: {
76
+ ...process$2.env,
77
+ [FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
78
+ },
79
+ stdio: [
80
+ "inherit",
81
+ "inherit",
82
+ "inherit",
83
+ "ipc"
84
+ ],
85
+ serialization: "advanced"
86
+ };
87
+ if (memoryLimit) options.execArgv = [`--max-old-space-size=${memoryLimit}`];
88
+ let childProcess, remoteMethod;
89
+ const id = randomUUID();
90
+ return {
91
+ connect(...args) {
92
+ if (childProcess && !childProcess.connected) {
93
+ childProcess.send({
94
+ type: RpcGMCallTypes.EXIT,
95
+ id
96
+ });
97
+ childProcess = void 0;
98
+ remoteMethod = void 0;
99
+ }
100
+ if (!childProcess?.connected) {
101
+ childProcess = child_process.fork(modulePath, options);
102
+ remoteMethod = wrapRpc(childProcess, {
103
+ id,
104
+ once
105
+ });
106
+ }
107
+ if (!remoteMethod) return Promise.reject(/* @__PURE__ */ new Error("Worker is not connected - cannot perform RPC."));
108
+ return remoteMethod(...args);
109
+ },
110
+ terminate() {
111
+ try {
112
+ if (childProcess.connected) childProcess.send({
113
+ type: RpcGMCallTypes.EXIT,
114
+ id
115
+ }, (err) => {
116
+ if (err) console.error("Error sending message:", err);
117
+ });
118
+ } catch (error) {
119
+ if (error.code === "EPIPE") console.error("Pipe closed before message could be sent:", error);
120
+ else console.error("Unexpected error:", error);
121
+ }
122
+ childProcess = void 0;
123
+ remoteMethod = void 0;
124
+ },
125
+ get connected() {
126
+ return Boolean(childProcess?.connected);
127
+ },
128
+ get process() {
129
+ return childProcess;
130
+ },
131
+ get id() {
132
+ return id;
133
+ }
134
+ };
135
+ }
136
+ function getRpcWorkerData() {
137
+ return JSON.parse(process$2.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
138
+ }
139
+
140
+ //#endregion
141
+ //#region src/core/rpc/index.ts
142
+ var rpc_exports = /* @__PURE__ */ __exportAll({
143
+ RpcExitError: () => RpcExitError,
144
+ RpcGMCallTypes: () => RpcGMCallTypes,
145
+ createRpcWorker: () => createRpcWorker,
146
+ exposeRpc: () => exposeRpc,
147
+ getRpcWorkerData: () => getRpcWorkerData,
148
+ wrapRpc: () => wrapRpc
149
+ });
150
+
151
+ //#endregion
152
+ //#region src/core/lib/DtsWorker.ts
153
+ var DtsWorker = class {
154
+ constructor(options) {
155
+ this._options = cloneDeepOptions(options);
156
+ this.removeUnSerializationOptions();
157
+ this.rpcWorker = createRpcWorker(path.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
158
+ this._res = this.rpcWorker.connect(this._options);
159
+ }
160
+ removeUnSerializationOptions() {
161
+ if (this._options.remote?.moduleFederationConfig?.manifest) delete this._options.remote?.moduleFederationConfig?.manifest;
162
+ if (this._options.host?.moduleFederationConfig?.manifest) delete this._options.host?.moduleFederationConfig?.manifest;
163
+ }
164
+ get controlledPromise() {
165
+ const ensureChildProcessExit = () => {
166
+ try {
167
+ const pid = this.rpcWorker.process?.pid;
168
+ const rootPid = process.pid;
169
+ if (pid && rootPid !== pid) process.kill(pid, 0);
170
+ } catch (error) {
171
+ if (isDebugMode()) console.error(error);
172
+ }
173
+ };
174
+ return Promise.resolve(this._res).then(() => {
175
+ this.exit();
176
+ ensureChildProcessExit();
177
+ }).catch((err) => {
178
+ if (isDebugMode()) console.error(err);
179
+ ensureChildProcessExit();
180
+ });
181
+ }
182
+ exit() {
183
+ try {
184
+ this.rpcWorker?.terminate();
185
+ } catch (err) {
186
+ if (isDebugMode()) console.error(err);
187
+ }
188
+ }
189
+ };
190
+
191
+ //#endregion
192
+ //#region src/core/lib/generateTypesInChildProcess.ts
193
+ async function generateTypesInChildProcess(options) {
194
+ return new DtsWorker(options).controlledPromise;
195
+ }
196
+
197
+ //#endregion
198
+ //#region src/core/lib/consumeTypes.ts
199
+ async function consumeTypes(options) {
200
+ await new (getDTSManagerConstructor(options.host?.implementation))(options).consumeTypes();
201
+ }
202
+
203
+ //#endregion
204
+ export { createRpcWorker as a, rpc_exports as i, generateTypesInChildProcess as n, DtsWorker as r, consumeTypes as t };
@@ -0,0 +1,5 @@
1
+ import { _ as retrieveMfTypesPath, c as isTSProject, d as DTSManager, f as HOST_API_TYPES_FILE_NAME, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, l as retrieveTypesAssetsInfo, m as REMOTE_API_TYPES_FILE_NAME, o as getDTSManagerConstructor, p as REMOTE_ALIAS_IDENTIFIER, r as generateTypes, u as validateOptions, v as retrieveOriginalOutDir } from "./expose-rpc-DMhY1i8A.mjs";
2
+ import "./Broker-BU4gToNr.mjs";
3
+ import { i as rpc_exports, n as generateTypesInChildProcess, r as DtsWorker, t as consumeTypes } from "./consumeTypes-D51rVbSt.mjs";
4
+
5
+ export { DTSManager, DtsWorker, HOST_API_TYPES_FILE_NAME, REMOTE_ALIAS_IDENTIFIER, REMOTE_API_TYPES_FILE_NAME, consumeTypes, generateTypes, generateTypesInChildProcess, getDTSManagerConstructor, isTSProject, retrieveHostConfig, retrieveMfTypesPath, retrieveOriginalOutDir, retrieveRemoteConfig, retrieveTypesAssetsInfo, retrieveTypesZipPath, rpc_exports as rpc, validateOptions };
@@ -0,0 +1,73 @@
1
+ import { c as WEB_SOCKET_CONNECT_MAGIC_ID, i as DEFAULT_WEB_SOCKET_PORT, n as ActionKind, t as Action } from "./Action-DNNg2YDh.mjs";
2
+ import { t as getIpFromEntry } from "./utils-CkPvDGOy.mjs";
3
+ import WebSocket from "isomorphic-ws";
4
+
5
+ //#region src/server/message/Action/FetchTypes.ts
6
+ var FetchTypesAction = class extends Action {
7
+ constructor(payload) {
8
+ super({ payload }, ActionKind.FETCH_TYPES);
9
+ }
10
+ };
11
+
12
+ //#endregion
13
+ //#region src/server/message/Action/AddDynamicRemote.ts
14
+ var AddDynamicRemoteAction = class extends Action {
15
+ constructor(payload) {
16
+ super({ payload }, ActionKind.ADD_DYNAMIC_REMOTE);
17
+ }
18
+ };
19
+
20
+ //#endregion
21
+ //#region src/server/createWebsocket.ts
22
+ function createWebsocket() {
23
+ return new WebSocket(`ws://127.0.0.1:${DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${WEB_SOCKET_CONNECT_MAGIC_ID}`);
24
+ }
25
+
26
+ //#endregion
27
+ //#region src/runtime-plugins/dynamic-remote-type-hints-plugin.ts
28
+ const PLUGIN_NAME = "dynamic-remote-type-hints-plugin";
29
+ function dynamicRemoteTypeHintsPlugin() {
30
+ let ws = createWebsocket();
31
+ let isConnected = false;
32
+ ws.onopen = () => {
33
+ isConnected = true;
34
+ };
35
+ ws.onerror = (err) => {
36
+ console.error(`[ ${PLUGIN_NAME} ] err: ${err}`);
37
+ };
38
+ return {
39
+ name: "dynamic-remote-type-hints-plugin",
40
+ registerRemote(args) {
41
+ const { remote, origin } = args;
42
+ try {
43
+ if (!isConnected) return args;
44
+ if (!("entry" in remote)) return args;
45
+ const defaultIpV4 = typeof FEDERATION_IPV4 === "string" ? FEDERATION_IPV4 : "127.0.0.1";
46
+ const remoteIp = getIpFromEntry(remote.entry, defaultIpV4);
47
+ const remoteInfo = {
48
+ name: remote.name,
49
+ url: remote.entry,
50
+ alias: remote.alias || remote.name
51
+ };
52
+ if (remoteIp) ws.send(JSON.stringify(new AddDynamicRemoteAction({
53
+ remoteIp,
54
+ remoteInfo,
55
+ name: origin.name,
56
+ ip: defaultIpV4
57
+ })));
58
+ ws.send(JSON.stringify(new FetchTypesAction({
59
+ name: origin.name,
60
+ ip: defaultIpV4,
61
+ remoteInfo
62
+ })));
63
+ return args;
64
+ } catch (err) {
65
+ console.error(new Error(err));
66
+ return args;
67
+ }
68
+ }
69
+ };
70
+ }
71
+
72
+ //#endregion
73
+ export { dynamicRemoteTypeHintsPlugin as default };