@module-federation/dts-plugin 0.0.0-feat-support-bridge-react-router-v7-20251015102312

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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/CHANGELOG.md +1065 -0
  4. package/dist/DTSManager-b15Gfat3.d.ts +53 -0
  5. package/dist/DTSManagerOptions-QVchWb0x.d.ts +32 -0
  6. package/dist/DtsWorker-BrHsGz8C.d.ts +56 -0
  7. package/dist/README.md +1 -0
  8. package/dist/core.d.mts +68 -0
  9. package/dist/core.d.ts +68 -0
  10. package/dist/core.js +2365 -0
  11. package/dist/dynamic-remote-type-hints-plugin.d.mts +5 -0
  12. package/dist/dynamic-remote-type-hints-plugin.d.ts +5 -0
  13. package/dist/dynamic-remote-type-hints-plugin.js +196 -0
  14. package/dist/esm/chunk-2GDMDG2O.js +282 -0
  15. package/dist/esm/chunk-647HGGGS.js +241 -0
  16. package/dist/esm/chunk-ETMHGGQH.js +1564 -0
  17. package/dist/esm/chunk-G65LOFTY.js +24 -0
  18. package/dist/esm/chunk-WWV5RWOP.js +902 -0
  19. package/dist/esm/core.js +44 -0
  20. package/dist/esm/dynamic-remote-type-hints-plugin.js +73 -0
  21. package/dist/esm/fork-dev-worker.js +145 -0
  22. package/dist/esm/fork-generate-dts.js +27 -0
  23. package/dist/esm/index.js +655 -0
  24. package/dist/esm/start-broker.js +36 -0
  25. package/dist/fork-dev-worker.d.mts +15 -0
  26. package/dist/fork-dev-worker.d.ts +15 -0
  27. package/dist/fork-dev-worker.js +2844 -0
  28. package/dist/fork-generate-dts.d.mts +10 -0
  29. package/dist/fork-generate-dts.d.ts +10 -0
  30. package/dist/fork-generate-dts.js +2015 -0
  31. package/dist/iife/launch-web-client.js +152 -0
  32. package/dist/index.d.mts +56 -0
  33. package/dist/index.d.ts +56 -0
  34. package/dist/index.js +2996 -0
  35. package/dist/package.json +87 -0
  36. package/dist/start-broker.d.mts +42 -0
  37. package/dist/start-broker.d.ts +42 -0
  38. package/dist/start-broker.js +958 -0
  39. package/dist/utils-BjKKtOcx.d.ts +16 -0
  40. package/package.json +87 -0
@@ -0,0 +1,5 @@
1
+ import { ModuleFederationRuntimePlugin } from '@module-federation/runtime/types';
2
+
3
+ declare function dynamicRemoteTypeHintsPlugin(): ModuleFederationRuntimePlugin;
4
+
5
+ export { dynamicRemoteTypeHintsPlugin as default };
@@ -0,0 +1,5 @@
1
+ import { ModuleFederationRuntimePlugin } from '@module-federation/runtime/types';
2
+
3
+ declare function dynamicRemoteTypeHintsPlugin(): ModuleFederationRuntimePlugin;
4
+
5
+ export { dynamicRemoteTypeHintsPlugin as default };
@@ -0,0 +1,196 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
34
+
35
+ // src/runtime-plugins/dynamic-remote-type-hints-plugin.ts
36
+ var dynamic_remote_type_hints_plugin_exports = {};
37
+ __export(dynamic_remote_type_hints_plugin_exports, {
38
+ default: () => dynamic_remote_type_hints_plugin_default
39
+ });
40
+ module.exports = __toCommonJS(dynamic_remote_type_hints_plugin_exports);
41
+
42
+ // src/server/createWebsocket.ts
43
+ var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
44
+
45
+ // src/server/constant.ts
46
+ var DEFAULT_WEB_SOCKET_PORT = 16322;
47
+ var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
48
+ var UpdateMode;
49
+ (function(UpdateMode2) {
50
+ UpdateMode2["POSITIVE"] = "POSITIVE";
51
+ UpdateMode2["PASSIVE"] = "PASSIVE";
52
+ })(UpdateMode || (UpdateMode = {}));
53
+
54
+ // src/server/createWebsocket.ts
55
+ function createWebsocket() {
56
+ return new import_isomorphic_ws.default(`ws://127.0.0.1:${DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${WEB_SOCKET_CONNECT_MAGIC_ID}`);
57
+ }
58
+ __name(createWebsocket, "createWebsocket");
59
+
60
+ // src/server/message/Message.ts
61
+ var _Message = class _Message {
62
+ constructor(type, kind) {
63
+ __publicField(this, "type");
64
+ __publicField(this, "kind");
65
+ __publicField(this, "time");
66
+ this.type = type;
67
+ this.kind = kind;
68
+ this.time = Date.now();
69
+ }
70
+ };
71
+ __name(_Message, "Message");
72
+ var Message = _Message;
73
+
74
+ // src/server/message/Action/Action.ts
75
+ var ActionKind;
76
+ (function(ActionKind2) {
77
+ ActionKind2["ADD_SUBSCRIBER"] = "ADD_SUBSCRIBER";
78
+ ActionKind2["EXIT_SUBSCRIBER"] = "EXIT_SUBSCRIBER";
79
+ ActionKind2["ADD_PUBLISHER"] = "ADD_PUBLISHER";
80
+ ActionKind2["UPDATE_PUBLISHER"] = "UPDATE_PUBLISHER";
81
+ ActionKind2["NOTIFY_SUBSCRIBER"] = "NOTIFY_SUBSCRIBER";
82
+ ActionKind2["EXIT_PUBLISHER"] = "EXIT_PUBLISHER";
83
+ ActionKind2["ADD_WEB_CLIENT"] = "ADD_WEB_CLIENT";
84
+ ActionKind2["NOTIFY_WEB_CLIENT"] = "NOTIFY_WEB_CLIENT";
85
+ ActionKind2["FETCH_TYPES"] = "FETCH_TYPES";
86
+ ActionKind2["ADD_DYNAMIC_REMOTE"] = "ADD_DYNAMIC_REMOTE";
87
+ })(ActionKind || (ActionKind = {}));
88
+ var _Action = class _Action extends Message {
89
+ constructor(content, kind) {
90
+ super("Action", kind);
91
+ __publicField(this, "payload");
92
+ const { payload } = content;
93
+ this.payload = payload;
94
+ }
95
+ };
96
+ __name(_Action, "Action");
97
+ var Action = _Action;
98
+
99
+ // src/server/message/Action/Update.ts
100
+ var UpdateKind;
101
+ (function(UpdateKind2) {
102
+ UpdateKind2["UPDATE_TYPE"] = "UPDATE_TYPE";
103
+ UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
104
+ })(UpdateKind || (UpdateKind = {}));
105
+
106
+ // src/server/message/Action/FetchTypes.ts
107
+ var _FetchTypesAction = class _FetchTypesAction extends Action {
108
+ constructor(payload) {
109
+ super({
110
+ payload
111
+ }, ActionKind.FETCH_TYPES);
112
+ }
113
+ };
114
+ __name(_FetchTypesAction, "FetchTypesAction");
115
+ var FetchTypesAction = _FetchTypesAction;
116
+
117
+ // src/server/message/Action/AddDynamicRemote.ts
118
+ var _AddDynamicRemoteAction = class _AddDynamicRemoteAction extends Action {
119
+ constructor(payload) {
120
+ super({
121
+ payload
122
+ }, ActionKind.ADD_DYNAMIC_REMOTE);
123
+ }
124
+ };
125
+ __name(_AddDynamicRemoteAction, "AddDynamicRemoteAction");
126
+ var AddDynamicRemoteAction = _AddDynamicRemoteAction;
127
+
128
+ // src/dev-worker/utils.ts
129
+ var DEFAULT_LOCAL_IPS = [
130
+ "localhost",
131
+ "127.0.0.1"
132
+ ];
133
+ function getIpFromEntry(entry, ipv4) {
134
+ let ip;
135
+ entry.replace(/https?:\/\/([0-9|.]+|localhost):/, (str, matched) => {
136
+ ip = matched;
137
+ return str;
138
+ });
139
+ if (ip) {
140
+ return DEFAULT_LOCAL_IPS.includes(ip) ? ipv4 : ip;
141
+ }
142
+ }
143
+ __name(getIpFromEntry, "getIpFromEntry");
144
+
145
+ // src/runtime-plugins/dynamic-remote-type-hints-plugin.ts
146
+ var PLUGIN_NAME = "dynamic-remote-type-hints-plugin";
147
+ function dynamicRemoteTypeHintsPlugin() {
148
+ let ws = createWebsocket();
149
+ let isConnected = false;
150
+ ws.onopen = () => {
151
+ isConnected = true;
152
+ };
153
+ ws.onerror = (err) => {
154
+ console.error(`[ ${PLUGIN_NAME} ] err: ${err}`);
155
+ };
156
+ return {
157
+ name: "dynamic-remote-type-hints-plugin",
158
+ registerRemote(args) {
159
+ const { remote, origin } = args;
160
+ try {
161
+ if (!isConnected) {
162
+ return args;
163
+ }
164
+ if (!("entry" in remote)) {
165
+ return args;
166
+ }
167
+ const defaultIpV4 = typeof FEDERATION_IPV4 === "string" ? FEDERATION_IPV4 : "127.0.0.1";
168
+ const remoteIp = getIpFromEntry(remote.entry, defaultIpV4);
169
+ const remoteInfo = {
170
+ name: remote.name,
171
+ url: remote.entry,
172
+ alias: remote.alias || remote.name
173
+ };
174
+ if (remoteIp) {
175
+ ws.send(JSON.stringify(new AddDynamicRemoteAction({
176
+ remoteIp,
177
+ remoteInfo,
178
+ name: origin.name,
179
+ ip: defaultIpV4
180
+ })));
181
+ }
182
+ ws.send(JSON.stringify(new FetchTypesAction({
183
+ name: origin.name,
184
+ ip: defaultIpV4,
185
+ remoteInfo
186
+ })));
187
+ return args;
188
+ } catch (err) {
189
+ console.error(new Error(err));
190
+ return args;
191
+ }
192
+ }
193
+ };
194
+ }
195
+ __name(dynamicRemoteTypeHintsPlugin, "dynamicRemoteTypeHintsPlugin");
196
+ var dynamic_remote_type_hints_plugin_default = dynamicRemoteTypeHintsPlugin;
@@ -0,0 +1,282 @@
1
+ import {
2
+ RpcGMCallTypes,
3
+ cloneDeepOptions,
4
+ exposeRpc,
5
+ getDTSManagerConstructor,
6
+ isDebugMode
7
+ } from "./chunk-ETMHGGQH.js";
8
+ import {
9
+ __async,
10
+ __export,
11
+ __name,
12
+ __publicField,
13
+ __spreadProps,
14
+ __spreadValues
15
+ } from "./chunk-647HGGGS.js";
16
+
17
+ // src/core/lib/DtsWorker.ts
18
+ import path from "path";
19
+
20
+ // src/core/rpc/index.ts
21
+ var rpc_exports = {};
22
+ __export(rpc_exports, {
23
+ RpcExitError: () => RpcExitError,
24
+ RpcGMCallTypes: () => RpcGMCallTypes,
25
+ createRpcWorker: () => createRpcWorker,
26
+ exposeRpc: () => exposeRpc,
27
+ getRpcWorkerData: () => getRpcWorkerData,
28
+ wrapRpc: () => wrapRpc
29
+ });
30
+
31
+ // src/core/rpc/rpc-error.ts
32
+ var _a;
33
+ var RpcExitError = (_a = class extends Error {
34
+ constructor(message, code, signal) {
35
+ super(message);
36
+ __publicField(this, "code");
37
+ __publicField(this, "signal");
38
+ this.code = code, this.signal = signal;
39
+ this.name = "RpcExitError";
40
+ }
41
+ }, __name(_a, "RpcExitError"), _a);
42
+
43
+ // src/core/rpc/wrap-rpc.ts
44
+ function createControlledPromise() {
45
+ let resolve = /* @__PURE__ */ __name(() => void 0, "resolve");
46
+ let reject = /* @__PURE__ */ __name(() => void 0, "reject");
47
+ const promise = new Promise((aResolve, aReject) => {
48
+ resolve = aResolve;
49
+ reject = aReject;
50
+ });
51
+ return {
52
+ promise,
53
+ resolve,
54
+ reject
55
+ };
56
+ }
57
+ __name(createControlledPromise, "createControlledPromise");
58
+ function wrapRpc(childProcess, options) {
59
+ return (...args) => __async(this, null, function* () {
60
+ if (!childProcess.send) {
61
+ throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
62
+ } else if (!childProcess.connected) {
63
+ throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
64
+ }
65
+ const { id, once } = options;
66
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
67
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
68
+ const handleMessage = /* @__PURE__ */ __name((message) => {
69
+ if ((message == null ? void 0 : message.id) === id) {
70
+ if (message.type === RpcGMCallTypes.RESOLVE) {
71
+ resolveResult(message.value);
72
+ } else if (message.type === RpcGMCallTypes.REJECT) {
73
+ rejectResult(message.error);
74
+ }
75
+ }
76
+ if (once && (childProcess == null ? void 0 : childProcess.kill)) {
77
+ childProcess.kill("SIGTERM");
78
+ }
79
+ }, "handleMessage");
80
+ const handleClose = /* @__PURE__ */ __name((code, signal) => {
81
+ rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
82
+ removeHandlers();
83
+ }, "handleClose");
84
+ const removeHandlers = /* @__PURE__ */ __name(() => {
85
+ childProcess.off("message", handleMessage);
86
+ childProcess.off("close", handleClose);
87
+ }, "removeHandlers");
88
+ if (once) {
89
+ childProcess.once("message", handleMessage);
90
+ } else {
91
+ childProcess.on("message", handleMessage);
92
+ }
93
+ childProcess.on("close", handleClose);
94
+ childProcess.send({
95
+ type: RpcGMCallTypes.CALL,
96
+ id,
97
+ args
98
+ }, (error) => {
99
+ if (error) {
100
+ rejectSend(error);
101
+ removeHandlers();
102
+ } else {
103
+ resolveSend(void 0);
104
+ }
105
+ });
106
+ return sendPromise.then(() => resultPromise);
107
+ });
108
+ }
109
+ __name(wrapRpc, "wrapRpc");
110
+
111
+ // src/core/rpc/rpc-worker.ts
112
+ import * as child_process from "child_process";
113
+ import * as process2 from "process";
114
+ import { randomUUID } from "crypto";
115
+ var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
116
+ function createRpcWorker(modulePath, data, memoryLimit, once) {
117
+ const options = {
118
+ env: __spreadProps(__spreadValues({}, process2.env), {
119
+ [FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
120
+ }),
121
+ stdio: [
122
+ "inherit",
123
+ "inherit",
124
+ "inherit",
125
+ "ipc"
126
+ ],
127
+ serialization: "advanced"
128
+ };
129
+ if (memoryLimit) {
130
+ options.execArgv = [
131
+ `--max-old-space-size=${memoryLimit}`
132
+ ];
133
+ }
134
+ let childProcess, remoteMethod;
135
+ const id = randomUUID();
136
+ const worker = {
137
+ connect(...args) {
138
+ if (childProcess && !childProcess.connected) {
139
+ childProcess.send({
140
+ type: RpcGMCallTypes.EXIT,
141
+ id
142
+ });
143
+ childProcess = void 0;
144
+ remoteMethod = void 0;
145
+ }
146
+ if (!(childProcess == null ? void 0 : childProcess.connected)) {
147
+ childProcess = child_process.fork(modulePath, options);
148
+ remoteMethod = wrapRpc(childProcess, {
149
+ id,
150
+ once
151
+ });
152
+ }
153
+ if (!remoteMethod) {
154
+ return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
155
+ }
156
+ return remoteMethod(...args);
157
+ },
158
+ terminate() {
159
+ try {
160
+ if (childProcess.connected) {
161
+ childProcess.send({
162
+ type: RpcGMCallTypes.EXIT,
163
+ id
164
+ }, (err) => {
165
+ if (err) {
166
+ console.error("Error sending message:", err);
167
+ }
168
+ });
169
+ }
170
+ } catch (error) {
171
+ if (error.code === "EPIPE") {
172
+ console.error("Pipe closed before message could be sent:", error);
173
+ } else {
174
+ console.error("Unexpected error:", error);
175
+ }
176
+ }
177
+ childProcess = void 0;
178
+ remoteMethod = void 0;
179
+ },
180
+ get connected() {
181
+ return Boolean(childProcess == null ? void 0 : childProcess.connected);
182
+ },
183
+ get process() {
184
+ return childProcess;
185
+ },
186
+ get id() {
187
+ return id;
188
+ }
189
+ };
190
+ return worker;
191
+ }
192
+ __name(createRpcWorker, "createRpcWorker");
193
+ function getRpcWorkerData() {
194
+ return JSON.parse(process2.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
195
+ }
196
+ __name(getRpcWorkerData, "getRpcWorkerData");
197
+
198
+ // src/core/lib/DtsWorker.ts
199
+ var _DtsWorker = class _DtsWorker {
200
+ constructor(options) {
201
+ __publicField(this, "rpcWorker");
202
+ __publicField(this, "_options");
203
+ __publicField(this, "_res");
204
+ this._options = cloneDeepOptions(options);
205
+ this.removeUnSerializationOptions();
206
+ this.rpcWorker = createRpcWorker(path.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
207
+ this._res = this.rpcWorker.connect(this._options);
208
+ }
209
+ removeUnSerializationOptions() {
210
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
211
+ if ((_b = (_a2 = this._options.remote) == null ? void 0 : _a2.moduleFederationConfig) == null ? void 0 : _b.manifest) {
212
+ (_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
213
+ }
214
+ if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
215
+ (_h = (_g = this._options.host) == null ? void 0 : _g.moduleFederationConfig) == null ? true : delete _h.manifest;
216
+ }
217
+ }
218
+ get controlledPromise() {
219
+ const ensureChildProcessExit = /* @__PURE__ */ __name(() => {
220
+ var _a2;
221
+ try {
222
+ const pid = (_a2 = this.rpcWorker.process) == null ? void 0 : _a2.pid;
223
+ const rootPid = process.pid;
224
+ if (pid && rootPid !== pid) {
225
+ process.kill(pid, 0);
226
+ }
227
+ } catch (error) {
228
+ if (isDebugMode()) {
229
+ console.error(error);
230
+ }
231
+ }
232
+ }, "ensureChildProcessExit");
233
+ return Promise.resolve(this._res).then(() => {
234
+ this.exit();
235
+ ensureChildProcessExit();
236
+ }).catch((err) => {
237
+ if (isDebugMode()) {
238
+ console.error(err);
239
+ }
240
+ ensureChildProcessExit();
241
+ });
242
+ }
243
+ exit() {
244
+ var _a2;
245
+ try {
246
+ (_a2 = this.rpcWorker) == null ? void 0 : _a2.terminate();
247
+ } catch (err) {
248
+ if (isDebugMode()) {
249
+ console.error(err);
250
+ }
251
+ }
252
+ }
253
+ };
254
+ __name(_DtsWorker, "DtsWorker");
255
+ var DtsWorker = _DtsWorker;
256
+
257
+ // src/core/lib/generateTypesInChildProcess.ts
258
+ function generateTypesInChildProcess(options) {
259
+ return __async(this, null, function* () {
260
+ const dtsWorker = new DtsWorker(options);
261
+ return dtsWorker.controlledPromise;
262
+ });
263
+ }
264
+ __name(generateTypesInChildProcess, "generateTypesInChildProcess");
265
+
266
+ // src/core/lib/consumeTypes.ts
267
+ function consumeTypes(options) {
268
+ return __async(this, null, function* () {
269
+ var _a2;
270
+ const DTSManagerConstructor = getDTSManagerConstructor((_a2 = options.host) == null ? void 0 : _a2.implementation);
271
+ const dtsManager = new DTSManagerConstructor(options);
272
+ yield dtsManager.consumeTypes();
273
+ });
274
+ }
275
+ __name(consumeTypes, "consumeTypes");
276
+
277
+ export {
278
+ rpc_exports,
279
+ DtsWorker,
280
+ generateTypesInChildProcess,
281
+ consumeTypes
282
+ };