@module-federation/dts-plugin 0.2.8 → 0.3.1

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,283 @@
1
+ import {
2
+ RpcGMCallTypes,
3
+ cloneDeepOptions,
4
+ exposeRpc,
5
+ getDTSManagerConstructor,
6
+ isDebugMode
7
+ } from "./chunk-7AXI7WOP.js";
8
+ import {
9
+ __async,
10
+ __export,
11
+ __name,
12
+ __publicField,
13
+ __spreadProps,
14
+ __spreadValues
15
+ } from "./chunk-6DND574L.js";
16
+
17
+ // packages/dts-plugin/src/core/lib/DtsWorker.ts
18
+ import path from "path";
19
+
20
+ // packages/dts-plugin/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
+ // packages/dts-plugin/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;
39
+ this.signal = signal;
40
+ this.name = "RpcExitError";
41
+ }
42
+ }, __name(_a, "RpcExitError"), _a);
43
+
44
+ // packages/dts-plugin/src/core/rpc/wrap-rpc.ts
45
+ function createControlledPromise() {
46
+ let resolve = /* @__PURE__ */ __name(() => void 0, "resolve");
47
+ let reject = /* @__PURE__ */ __name(() => void 0, "reject");
48
+ const promise = new Promise((aResolve, aReject) => {
49
+ resolve = aResolve;
50
+ reject = aReject;
51
+ });
52
+ return {
53
+ promise,
54
+ resolve,
55
+ reject
56
+ };
57
+ }
58
+ __name(createControlledPromise, "createControlledPromise");
59
+ function wrapRpc(childProcess, options) {
60
+ return (...args) => __async(this, null, function* () {
61
+ if (!childProcess.send) {
62
+ throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
63
+ } else if (!childProcess.connected) {
64
+ throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
65
+ }
66
+ const { id, once } = options;
67
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
68
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
69
+ const handleMessage = /* @__PURE__ */ __name((message) => {
70
+ if ((message == null ? void 0 : message.id) === id) {
71
+ if (message.type === RpcGMCallTypes.RESOLVE) {
72
+ resolveResult(message.value);
73
+ } else if (message.type === RpcGMCallTypes.REJECT) {
74
+ rejectResult(message.error);
75
+ }
76
+ }
77
+ if (once && (childProcess == null ? void 0 : childProcess.kill)) {
78
+ childProcess.kill("SIGTERM");
79
+ }
80
+ }, "handleMessage");
81
+ const handleClose = /* @__PURE__ */ __name((code, signal) => {
82
+ rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
83
+ removeHandlers();
84
+ }, "handleClose");
85
+ const removeHandlers = /* @__PURE__ */ __name(() => {
86
+ childProcess.off("message", handleMessage);
87
+ childProcess.off("close", handleClose);
88
+ }, "removeHandlers");
89
+ if (once) {
90
+ childProcess.once("message", handleMessage);
91
+ } else {
92
+ childProcess.on("message", handleMessage);
93
+ }
94
+ childProcess.on("close", handleClose);
95
+ childProcess.send({
96
+ type: RpcGMCallTypes.CALL,
97
+ id,
98
+ args
99
+ }, (error) => {
100
+ if (error) {
101
+ rejectSend(error);
102
+ removeHandlers();
103
+ } else {
104
+ resolveSend(void 0);
105
+ }
106
+ });
107
+ return sendPromise.then(() => resultPromise);
108
+ });
109
+ }
110
+ __name(wrapRpc, "wrapRpc");
111
+
112
+ // packages/dts-plugin/src/core/rpc/rpc-worker.ts
113
+ import * as child_process from "child_process";
114
+ import * as process2 from "process";
115
+ import { randomUUID } from "crypto";
116
+ var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
117
+ function createRpcWorker(modulePath, data, memoryLimit, once) {
118
+ const options = {
119
+ env: __spreadProps(__spreadValues({}, process2.env), {
120
+ [FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
121
+ }),
122
+ stdio: [
123
+ "inherit",
124
+ "inherit",
125
+ "inherit",
126
+ "ipc"
127
+ ],
128
+ serialization: "advanced"
129
+ };
130
+ if (memoryLimit) {
131
+ options.execArgv = [
132
+ `--max-old-space-size=${memoryLimit}`
133
+ ];
134
+ }
135
+ let childProcess, remoteMethod;
136
+ const id = randomUUID();
137
+ const worker = {
138
+ connect(...args) {
139
+ if (childProcess && !childProcess.connected) {
140
+ childProcess.send({
141
+ type: RpcGMCallTypes.EXIT,
142
+ id
143
+ });
144
+ childProcess = void 0;
145
+ remoteMethod = void 0;
146
+ }
147
+ if (!(childProcess == null ? void 0 : childProcess.connected)) {
148
+ childProcess = child_process.fork(modulePath, options);
149
+ remoteMethod = wrapRpc(childProcess, {
150
+ id,
151
+ once
152
+ });
153
+ }
154
+ if (!remoteMethod) {
155
+ return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
156
+ }
157
+ return remoteMethod(...args);
158
+ },
159
+ terminate() {
160
+ try {
161
+ if (childProcess.connected) {
162
+ childProcess.send({
163
+ type: RpcGMCallTypes.EXIT,
164
+ id
165
+ }, (err) => {
166
+ if (err) {
167
+ console.error("Error sending message:", err);
168
+ }
169
+ });
170
+ }
171
+ } catch (error) {
172
+ if (error.code === "EPIPE") {
173
+ console.error("Pipe closed before message could be sent:", error);
174
+ } else {
175
+ console.error("Unexpected error:", error);
176
+ }
177
+ }
178
+ childProcess = void 0;
179
+ remoteMethod = void 0;
180
+ },
181
+ get connected() {
182
+ return Boolean(childProcess == null ? void 0 : childProcess.connected);
183
+ },
184
+ get process() {
185
+ return childProcess;
186
+ },
187
+ get id() {
188
+ return id;
189
+ }
190
+ };
191
+ return worker;
192
+ }
193
+ __name(createRpcWorker, "createRpcWorker");
194
+ function getRpcWorkerData() {
195
+ return JSON.parse(process2.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
196
+ }
197
+ __name(getRpcWorkerData, "getRpcWorkerData");
198
+
199
+ // packages/dts-plugin/src/core/lib/DtsWorker.ts
200
+ var _DtsWorker = class _DtsWorker {
201
+ constructor(options) {
202
+ __publicField(this, "rpcWorker");
203
+ __publicField(this, "_options");
204
+ __publicField(this, "_res");
205
+ this._options = cloneDeepOptions(options);
206
+ this.removeUnSerializationOptions();
207
+ this.rpcWorker = createRpcWorker(path.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
208
+ this._res = this.rpcWorker.connect(this._options);
209
+ }
210
+ removeUnSerializationOptions() {
211
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
212
+ if ((_b = (_a2 = this._options.remote) == null ? void 0 : _a2.moduleFederationConfig) == null ? void 0 : _b.manifest) {
213
+ (_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
214
+ }
215
+ if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
216
+ (_h = (_g = this._options.host) == null ? void 0 : _g.moduleFederationConfig) == null ? true : delete _h.manifest;
217
+ }
218
+ }
219
+ get controlledPromise() {
220
+ const ensureChildProcessExit = /* @__PURE__ */ __name(() => {
221
+ var _a2;
222
+ try {
223
+ const pid = (_a2 = this.rpcWorker.process) == null ? void 0 : _a2.pid;
224
+ const rootPid = process.pid;
225
+ if (pid && rootPid !== pid) {
226
+ process.kill(pid, 0);
227
+ }
228
+ } catch (error) {
229
+ if (isDebugMode()) {
230
+ console.error(error);
231
+ }
232
+ }
233
+ }, "ensureChildProcessExit");
234
+ return Promise.resolve(this._res).then(() => {
235
+ this.exit();
236
+ ensureChildProcessExit();
237
+ }).catch((err) => {
238
+ if (isDebugMode()) {
239
+ console.error(err);
240
+ }
241
+ ensureChildProcessExit();
242
+ });
243
+ }
244
+ exit() {
245
+ var _a2;
246
+ try {
247
+ (_a2 = this.rpcWorker) == null ? void 0 : _a2.terminate();
248
+ } catch (err) {
249
+ if (isDebugMode()) {
250
+ console.error(err);
251
+ }
252
+ }
253
+ }
254
+ };
255
+ __name(_DtsWorker, "DtsWorker");
256
+ var DtsWorker = _DtsWorker;
257
+
258
+ // packages/dts-plugin/src/core/lib/generateTypesInChildProcess.ts
259
+ function generateTypesInChildProcess(options) {
260
+ return __async(this, null, function* () {
261
+ const dtsWorker = new DtsWorker(options);
262
+ return dtsWorker.controlledPromise;
263
+ });
264
+ }
265
+ __name(generateTypesInChildProcess, "generateTypesInChildProcess");
266
+
267
+ // packages/dts-plugin/src/core/lib/consumeTypes.ts
268
+ function consumeTypes(options) {
269
+ return __async(this, null, function* () {
270
+ var _a2;
271
+ const DTSManagerConstructor = getDTSManagerConstructor((_a2 = options.host) == null ? void 0 : _a2.implementation);
272
+ const dtsManager = new DTSManagerConstructor(options);
273
+ yield dtsManager.consumeTypes();
274
+ });
275
+ }
276
+ __name(consumeTypes, "consumeTypes");
277
+
278
+ export {
279
+ rpc_exports,
280
+ DtsWorker,
281
+ generateTypesInChildProcess,
282
+ consumeTypes
283
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __name
3
- } from "./chunk-MQRIERJP.js";
3
+ } from "./chunk-6DND574L.js";
4
4
 
5
5
  // packages/dts-plugin/src/dev-worker/utils.ts
6
6
  var DEFAULT_LOCAL_IPS = [
package/dist/esm/core.js CHANGED
@@ -1,9 +1,15 @@
1
1
  import {
2
- DTSManager,
3
2
  DtsWorker,
4
3
  consumeTypes,
5
- generateTypes,
6
4
  generateTypesInChildProcess,
5
+ rpc_exports
6
+ } from "./chunk-VFGWGY54.js";
7
+ import {
8
+ DTSManager,
9
+ HOST_API_TYPES_FILE_NAME,
10
+ REMOTE_ALIAS_IDENTIFIER,
11
+ REMOTE_API_TYPES_FILE_NAME,
12
+ generateTypes,
7
13
  getDTSManagerConstructor,
8
14
  isTSProject,
9
15
  retrieveHostConfig,
@@ -12,22 +18,16 @@ import {
12
18
  retrieveRemoteConfig,
13
19
  retrieveTypesAssetsInfo,
14
20
  retrieveTypesZipPath,
15
- rpc_exports,
16
21
  validateOptions
17
- } from "./chunk-2RCHPGBO.js";
18
- import {
19
- HOST_API_TYPES_FILE_NAME,
20
- REMOTE_ALIAS_IDENTIFIER,
21
- REMOTE_API_TYPES_FILE_NAME,
22
- UpdateMode
23
- } from "./chunk-MQRIERJP.js";
22
+ } from "./chunk-7AXI7WOP.js";
23
+ import "./chunk-HKRTV6ZH.js";
24
+ import "./chunk-6DND574L.js";
24
25
  export {
25
26
  DTSManager,
26
27
  DtsWorker,
27
28
  HOST_API_TYPES_FILE_NAME,
28
29
  REMOTE_ALIAS_IDENTIFIER,
29
30
  REMOTE_API_TYPES_FILE_NAME,
30
- UpdateMode,
31
31
  consumeTypes,
32
32
  generateTypes,
33
33
  generateTypesInChildProcess,
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  getIpFromEntry
3
- } from "./chunk-G7ONFBMA.js";
3
+ } from "./chunk-XKCIYRDL.js";
4
4
  import {
5
5
  AddDynamicRemoteAction,
6
6
  DEFAULT_WEB_SOCKET_PORT,
7
7
  FetchTypesAction,
8
8
  WEB_SOCKET_CONNECT_MAGIC_ID,
9
9
  __name
10
- } from "./chunk-MQRIERJP.js";
10
+ } from "./chunk-6DND574L.js";
11
11
 
12
12
  // packages/dts-plugin/src/server/createWebsocket.ts
13
13
  import WebSocket from "isomorphic-ws";
@@ -1,25 +1,29 @@
1
+ import {
2
+ rpc_exports
3
+ } from "./chunk-VFGWGY54.js";
1
4
  import {
2
5
  ModuleFederationDevServer,
3
6
  createKoaServer,
4
- fileLog,
5
7
  getDTSManagerConstructor,
6
- getIPV4,
7
8
  retrieveHostConfig,
8
9
  retrieveMfTypesPath,
9
10
  retrieveRemoteConfig,
10
- retrieveTypesZipPath,
11
- rpc_exports
12
- } from "./chunk-2RCHPGBO.js";
11
+ retrieveTypesZipPath
12
+ } from "./chunk-7AXI7WOP.js";
13
+ import {
14
+ fileLog,
15
+ getIPV4
16
+ } from "./chunk-HKRTV6ZH.js";
13
17
  import {
14
18
  getIpFromEntry
15
- } from "./chunk-G7ONFBMA.js";
19
+ } from "./chunk-XKCIYRDL.js";
16
20
  import {
17
21
  DEFAULT_TAR_NAME,
18
22
  UpdateKind,
19
23
  UpdateMode,
20
24
  __async,
21
25
  __name
22
- } from "./chunk-MQRIERJP.js";
26
+ } from "./chunk-6DND574L.js";
23
27
 
24
28
  // packages/dts-plugin/src/dev-worker/forkDevWorker.ts
25
29
  import { decodeName } from "@module-federation/sdk";
@@ -2,11 +2,12 @@ import {
2
2
  RpcGMCallTypes,
3
3
  exposeRpc,
4
4
  generateTypes
5
- } from "./chunk-2RCHPGBO.js";
5
+ } from "./chunk-7AXI7WOP.js";
6
+ import "./chunk-HKRTV6ZH.js";
6
7
  import {
7
8
  __async,
8
9
  __name
9
- } from "./chunk-MQRIERJP.js";
10
+ } from "./chunk-6DND574L.js";
10
11
 
11
12
  // packages/dts-plugin/src/core/lib/forkGenerateDts.ts
12
13
  function forkGenerateDts(options) {
package/dist/esm/index.js CHANGED
@@ -1,13 +1,18 @@
1
1
  import {
2
2
  consumeTypes,
3
- generateTypes,
4
3
  generateTypesInChildProcess,
5
- getIPV4,
4
+ rpc_exports
5
+ } from "./chunk-VFGWGY54.js";
6
+ import {
7
+ cloneDeepOptions,
8
+ generateTypes,
6
9
  isTSProject,
7
10
  retrieveTypesAssetsInfo,
8
- rpc_exports,
9
11
  validateOptions
10
- } from "./chunk-2RCHPGBO.js";
12
+ } from "./chunk-7AXI7WOP.js";
13
+ import {
14
+ getIPV4
15
+ } from "./chunk-HKRTV6ZH.js";
11
16
  import {
12
17
  WEB_CLIENT_OPTIONS_IDENTIFIER,
13
18
  __async,
@@ -15,7 +20,7 @@ import {
15
20
  __publicField,
16
21
  __spreadProps,
17
22
  __spreadValues
18
- } from "./chunk-MQRIERJP.js";
23
+ } from "./chunk-6DND574L.js";
19
24
 
20
25
  // packages/dts-plugin/src/plugins/DevPlugin.ts
21
26
  import fs from "fs-extra";
@@ -27,17 +32,12 @@ import * as fse from "fs-extra";
27
32
 
28
33
  // packages/dts-plugin/src/dev-worker/DevWorker.ts
29
34
  import path from "path";
30
- import cloneDeepWith from "lodash.clonedeepwith";
31
35
  var _DevWorker = class _DevWorker {
32
36
  constructor(options) {
33
37
  __publicField(this, "_rpcWorker");
34
38
  __publicField(this, "_options");
35
39
  __publicField(this, "_res");
36
- this._options = cloneDeepWith(options, (_value, key) => {
37
- if (key === "manifest") {
38
- return false;
39
- }
40
- });
40
+ this._options = cloneDeepOptions(options);
41
41
  this.removeUnSerializationOptions();
42
42
  this._rpcWorker = rpc_exports.createRpcWorker(path.resolve(__dirname, "./fork-dev-worker.js"), {}, void 0, false);
43
43
  this._res = this._rpcWorker.connect(this._options);
@@ -184,14 +184,17 @@ var _DevPlugin = class _DevPlugin {
184
184
  if (!normalizedDev.disableLiveReload) {
185
185
  const TEMP_DIR = path3.join(`${process.cwd()}/node_modules`, BasicTempDir);
186
186
  const filepath = path3.join(TEMP_DIR, `live-reload.js`);
187
- _DevPlugin.ensureLiveReloadEntry({
188
- name
189
- }, filepath);
190
- compiler.hooks.afterPlugins.tap("MFDevPlugin", () => {
191
- new compiler.webpack.EntryPlugin(compiler.context, filepath, {
187
+ if (typeof compiler.options.entry === "object") {
188
+ _DevPlugin.ensureLiveReloadEntry({
192
189
  name
193
- }).apply(compiler);
194
- });
190
+ }, filepath);
191
+ Object.keys(compiler.options.entry).forEach((entry) => {
192
+ const normalizedEntry = compiler.options.entry[entry];
193
+ if (typeof normalizedEntry === "object" && Array.isArray(normalizedEntry.import)) {
194
+ normalizedEntry.import.unshift(filepath);
195
+ }
196
+ });
197
+ }
195
198
  }
196
199
  const defaultGenerateTypes = {
197
200
  compileInChildProcess: true
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  Broker,
3
3
  fileLog
4
- } from "./chunk-2RCHPGBO.js";
4
+ } from "./chunk-HKRTV6ZH.js";
5
5
  import {
6
6
  __async,
7
7
  __name
8
- } from "./chunk-MQRIERJP.js";
8
+ } from "./chunk-6DND574L.js";
9
9
 
10
10
  // packages/dts-plugin/src/server/broker/startBroker.ts
11
11
  var broker;
@@ -1,4 +1,4 @@
1
- import { D as DTSManagerOptions } from './DTSManagerOptions-c0728719.js';
1
+ import { D as DTSManagerOptions } from './DTSManagerOptions-7109e8ac.js';
2
2
  import '@module-federation/sdk';
3
3
 
4
4
  interface DevWorkerOptions extends DTSManagerOptions {
@@ -1,4 +1,4 @@
1
- import { D as DTSManagerOptions } from './DTSManagerOptions-c0728719.js';
1
+ import { D as DTSManagerOptions } from './DTSManagerOptions-7109e8ac.js';
2
2
  import '@module-federation/sdk';
3
3
 
4
4
  interface DevWorkerOptions extends DTSManagerOptions {