@module-federation/dts-plugin 0.0.0-chore-bump-node-22-20260710161714

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.
@@ -0,0 +1,208 @@
1
+ import { a as cloneDeepOptions, n as RpcGMCallTypes, o as getDTSManagerConstructor, s as isDebugMode, t as exposeRpc, x as __exportAll } from "./expose-rpc-CDdqA9PX.mjs";
2
+ import { fileURLToPath } from "url";
3
+ import path from "path";
4
+ import { randomUUID } from "crypto";
5
+ import * as child_process from "child_process";
6
+ import * as process$2 from "process";
7
+
8
+ //#region src/core/rpc/rpc-error.ts
9
+ var RpcExitError = class extends Error {
10
+ constructor(message, code, signal) {
11
+ super(message);
12
+ this.code = code;
13
+ this.signal = signal;
14
+ this.name = "RpcExitError";
15
+ }
16
+ };
17
+
18
+ //#endregion
19
+ //#region src/core/rpc/wrap-rpc.ts
20
+ function createControlledPromise() {
21
+ let resolve = () => void 0;
22
+ let reject = () => void 0;
23
+ return {
24
+ promise: new Promise((aResolve, aReject) => {
25
+ resolve = aResolve;
26
+ reject = aReject;
27
+ }),
28
+ resolve,
29
+ reject
30
+ };
31
+ }
32
+ function wrapRpc(childProcess, options) {
33
+ return (async (...args) => {
34
+ if (!childProcess.send) throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
35
+ else if (!childProcess.connected) throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
36
+ const { id, once } = options;
37
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
38
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
39
+ const handleMessage = (message) => {
40
+ if (message?.id === id) {
41
+ if (message.type === RpcGMCallTypes.RESOLVE) resolveResult(message.value);
42
+ else if (message.type === RpcGMCallTypes.REJECT) rejectResult(message.error);
43
+ }
44
+ if (once && childProcess?.kill) childProcess.kill("SIGTERM");
45
+ };
46
+ const handleClose = (code, signal) => {
47
+ rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
48
+ removeHandlers();
49
+ };
50
+ const removeHandlers = () => {
51
+ childProcess.off("message", handleMessage);
52
+ childProcess.off("close", handleClose);
53
+ };
54
+ if (once) childProcess.once("message", handleMessage);
55
+ else childProcess.on("message", handleMessage);
56
+ childProcess.on("close", handleClose);
57
+ childProcess.send({
58
+ type: RpcGMCallTypes.CALL,
59
+ id,
60
+ args
61
+ }, (error) => {
62
+ if (error) {
63
+ rejectSend(error);
64
+ removeHandlers();
65
+ } else resolveSend(void 0);
66
+ });
67
+ return sendPromise.then(() => resultPromise);
68
+ });
69
+ }
70
+
71
+ //#endregion
72
+ //#region src/core/rpc/rpc-worker.ts
73
+ const FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
74
+ function createRpcWorker(modulePath, data, memoryLimit, once) {
75
+ const options = {
76
+ env: {
77
+ ...process$2.env,
78
+ [FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
79
+ },
80
+ stdio: [
81
+ "inherit",
82
+ "inherit",
83
+ "inherit",
84
+ "ipc"
85
+ ],
86
+ serialization: "advanced"
87
+ };
88
+ if (memoryLimit) options.execArgv = [`--max-old-space-size=${memoryLimit}`];
89
+ let childProcess, remoteMethod;
90
+ const id = randomUUID();
91
+ return {
92
+ connect(...args) {
93
+ if (childProcess && !childProcess.connected) {
94
+ childProcess.send({
95
+ type: RpcGMCallTypes.EXIT,
96
+ id
97
+ });
98
+ childProcess = void 0;
99
+ remoteMethod = void 0;
100
+ }
101
+ if (!childProcess?.connected) {
102
+ childProcess = child_process.fork(modulePath, options);
103
+ remoteMethod = wrapRpc(childProcess, {
104
+ id,
105
+ once
106
+ });
107
+ }
108
+ if (!remoteMethod) return Promise.reject(/* @__PURE__ */ new Error("Worker is not connected - cannot perform RPC."));
109
+ return remoteMethod(...args);
110
+ },
111
+ terminate() {
112
+ try {
113
+ if (childProcess.connected) childProcess.send({
114
+ type: RpcGMCallTypes.EXIT,
115
+ id
116
+ }, (err) => {
117
+ if (err) console.error("Error sending message:", err);
118
+ });
119
+ } catch (error) {
120
+ if (error.code === "EPIPE") console.error("Pipe closed before message could be sent:", error);
121
+ else console.error("Unexpected error:", error);
122
+ }
123
+ childProcess = void 0;
124
+ remoteMethod = void 0;
125
+ },
126
+ get connected() {
127
+ return Boolean(childProcess?.connected);
128
+ },
129
+ get process() {
130
+ return childProcess;
131
+ },
132
+ get id() {
133
+ return id;
134
+ }
135
+ };
136
+ }
137
+ function getRpcWorkerData() {
138
+ return JSON.parse(process$2.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
139
+ }
140
+
141
+ //#endregion
142
+ //#region src/core/rpc/index.ts
143
+ var rpc_exports = /* @__PURE__ */ __exportAll({
144
+ RpcExitError: () => RpcExitError,
145
+ RpcGMCallTypes: () => RpcGMCallTypes,
146
+ createRpcWorker: () => createRpcWorker,
147
+ exposeRpc: () => exposeRpc,
148
+ getRpcWorkerData: () => getRpcWorkerData,
149
+ wrapRpc: () => wrapRpc
150
+ });
151
+
152
+ //#endregion
153
+ //#region src/core/lib/DtsWorker.ts
154
+ const __filename = fileURLToPath(import.meta.url);
155
+ const __dirname = path.dirname(__filename);
156
+ const __extname = path.extname(__filename);
157
+ var DtsWorker = class {
158
+ constructor(options) {
159
+ this._options = cloneDeepOptions(options);
160
+ this.removeUnSerializationOptions();
161
+ this.rpcWorker = createRpcWorker(path.resolve(__dirname, `./fork-generate-dts${__extname}`), {}, void 0, true);
162
+ this._res = this.rpcWorker.connect(this._options);
163
+ }
164
+ removeUnSerializationOptions() {
165
+ if (this._options.remote?.moduleFederationConfig?.manifest) delete this._options.remote?.moduleFederationConfig?.manifest;
166
+ if (this._options.host?.moduleFederationConfig?.manifest) delete this._options.host?.moduleFederationConfig?.manifest;
167
+ }
168
+ get controlledPromise() {
169
+ const ensureChildProcessExit = () => {
170
+ try {
171
+ const pid = this.rpcWorker.process?.pid;
172
+ const rootPid = process.pid;
173
+ if (pid && rootPid !== pid) process.kill(pid, 0);
174
+ } catch (error) {
175
+ if (isDebugMode()) console.error(error);
176
+ }
177
+ };
178
+ return Promise.resolve(this._res).then(() => {
179
+ this.exit();
180
+ ensureChildProcessExit();
181
+ }).catch((err) => {
182
+ if (isDebugMode()) console.error(err);
183
+ ensureChildProcessExit();
184
+ });
185
+ }
186
+ exit() {
187
+ try {
188
+ this.rpcWorker?.terminate();
189
+ } catch (err) {
190
+ if (isDebugMode()) console.error(err);
191
+ }
192
+ }
193
+ };
194
+
195
+ //#endregion
196
+ //#region src/core/lib/generateTypesInChildProcess.ts
197
+ async function generateTypesInChildProcess(options) {
198
+ return new DtsWorker(options).controlledPromise;
199
+ }
200
+
201
+ //#endregion
202
+ //#region src/core/lib/consumeTypes.ts
203
+ async function consumeTypes(options) {
204
+ await new (getDTSManagerConstructor(options.host?.implementation))(options).consumeTypes();
205
+ }
206
+
207
+ //#endregion
208
+ 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-CDdqA9PX.mjs";
2
+ import "./Broker-Cmbh_XVO.mjs";
3
+ import { i as rpc_exports, n as generateTypesInChildProcess, r as DtsWorker, t as consumeTypes } from "./consumeTypes-3S4eCiRK.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 };