@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.
@@ -93,7 +93,6 @@ var import_path4 = __toESM(require("path"));
93
93
  var import_promises3 = require("fs/promises");
94
94
  var import_fs = __toESM(require("fs"));
95
95
  var import_sdk5 = require("@module-federation/sdk");
96
- var import_lodash = __toESM(require("lodash.clonedeepwith"));
97
96
  var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
98
97
 
99
98
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
@@ -103,8 +102,8 @@ var import_promises2 = require("fs/promises");
103
102
 
104
103
  // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
105
104
  var import_fs_extra = require("fs-extra");
105
+ var import_crypto = __toESM(require("crypto"));
106
106
  var import_promises = require("fs/promises");
107
- var import_crypto = require("crypto");
108
107
  var import_path = require("path");
109
108
  var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
110
109
  var import_child_process = require("child_process");
@@ -115,8 +114,12 @@ var DEFINITION_FILE_EXTENSION = ".d.ts";
115
114
  var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
116
115
  var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
117
116
  var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
118
- function writeTempTsConfig(tsConfig, context) {
119
- const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${(0, import_crypto.randomUUID)()}.json`);
117
+ function writeTempTsConfig(tsConfig, context, name) {
118
+ const createHash = /* @__PURE__ */ __name((contents) => {
119
+ return import_crypto.default.createHash("md5").update(contents).digest("hex");
120
+ }, "createHash");
121
+ const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
122
+ const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
120
123
  (0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
121
124
  (0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
122
125
  return tempTsConfigJsonPath;
@@ -169,7 +172,7 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
169
172
  return;
170
173
  }
171
174
  const { compilerOptions } = tsConfig;
172
- const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
175
+ const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
173
176
  try {
174
177
  const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
175
178
  const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
@@ -207,9 +210,6 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
207
210
  }
208
211
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
209
212
  } catch (err) {
210
- if (isDebugMode()) {
211
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
212
- }
213
213
  throw err;
214
214
  }
215
215
  }), "compileTs");
@@ -334,6 +334,11 @@ var DEFAULT_WEB_SOCKET_PORT = 16322;
334
334
  var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
335
335
  var MF_SERVER_IDENTIFIER = "Module Federation Dev Server";
336
336
  var DEFAULT_TAR_NAME = "@mf-types.zip";
337
+ var UpdateMode;
338
+ (function(UpdateMode2) {
339
+ UpdateMode2["POSITIVE"] = "POSITIVE";
340
+ UpdateMode2["PASSIVE"] = "PASSIVE";
341
+ })(UpdateMode || (UpdateMode = {}));
337
342
 
338
343
  // packages/dts-plugin/src/server/utils/log.ts
339
344
  function fileLog(msg, module2, level) {
@@ -639,16 +644,6 @@ var _UpdatePublisherAction = class _UpdatePublisherAction extends Action {
639
644
  __name(_UpdatePublisherAction, "UpdatePublisherAction");
640
645
  var UpdatePublisherAction = _UpdatePublisherAction;
641
646
 
642
- // packages/dts-plugin/src/core/constant.ts
643
- var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
644
- var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
645
- var HOST_API_TYPES_FILE_NAME = "index.d.ts";
646
- var UpdateMode;
647
- (function(UpdateMode2) {
648
- UpdateMode2["POSITIVE"] = "POSITIVE";
649
- UpdateMode2["PASSIVE"] = "PASSIVE";
650
- })(UpdateMode || (UpdateMode = {}));
651
-
652
647
  // packages/dts-plugin/src/server/broker/Broker.ts
653
648
  var _Broker = class _Broker {
654
649
  constructor() {
@@ -1275,12 +1270,12 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
1275
1270
  var _a3;
1276
1271
  fileLog(`Current pid: ${process.pid}, publisher:${this._name} connected to ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}, starting service...`, MF_SERVER_IDENTIFIER, "info");
1277
1272
  this._isConnected = true;
1278
- const startGarfishModule = new AddPublisherAction({
1273
+ const addPublisherAction = new AddPublisherAction({
1279
1274
  name: this._name,
1280
1275
  ip: this._ip,
1281
1276
  remoteTypeTarPath: this._remoteTypeTarPath
1282
1277
  });
1283
- (_a3 = this._publishWebSocket) == null ? void 0 : _a3.send(JSON.stringify(startGarfishModule));
1278
+ (_a3 = this._publishWebSocket) == null ? void 0 : _a3.send(JSON.stringify(addPublisherAction));
1284
1279
  this._connectSubscribers();
1285
1280
  });
1286
1281
  this._publishWebSocket.on("message", (message) => __async(this, null, function* () {
@@ -1543,11 +1538,11 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
1543
1538
  if (!this._publishWebSocket || !this._isConnected) {
1544
1539
  return;
1545
1540
  }
1546
- const { updateKind, updateMode, updateSourcePaths } = options;
1541
+ const { updateKind, updateMode, updateSourcePaths, clientName } = options;
1547
1542
  fileLog(`update run, ${this._name} module update, updateKind: ${updateKind}, updateMode: ${updateMode}, updateSourcePaths: ${updateSourcePaths}`, MF_SERVER_IDENTIFIER, "info");
1548
1543
  if (updateKind === UpdateKind.RELOAD_PAGE) {
1549
1544
  const notifyWebClient = new NotifyWebClientAction({
1550
- name: this._name,
1545
+ name: clientName || this._name,
1551
1546
  updateMode
1552
1547
  });
1553
1548
  this._publishWebSocket.send(JSON.stringify(notifyWebClient));
@@ -1689,7 +1684,8 @@ var defaultOptions = {
1689
1684
  implementation: "",
1690
1685
  context: process.cwd(),
1691
1686
  abortOnError: true,
1692
- consumeAPITypes: false
1687
+ consumeAPITypes: false,
1688
+ runtimePkgs: []
1693
1689
  };
1694
1690
  var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1695
1691
  const remoteUrl = new URL(url, "file:");
@@ -1748,6 +1744,11 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
1748
1744
  };
1749
1745
  }, "retrieveHostConfig");
1750
1746
 
1747
+ // packages/dts-plugin/src/core/constant.ts
1748
+ var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
1749
+ var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
1750
+ var HOST_API_TYPES_FILE_NAME = "index.d.ts";
1751
+
1751
1752
  // packages/dts-plugin/src/core/lib/DTSManager.ts
1752
1753
  var _a;
1753
1754
  var DTSManager = (_a = class {
@@ -1758,11 +1759,7 @@ var DTSManager = (_a = class {
1758
1759
  __publicField(this, "loadedRemoteAPIAlias");
1759
1760
  __publicField(this, "extraOptions");
1760
1761
  __publicField(this, "updatedRemoteInfos");
1761
- this.options = (0, import_lodash.default)(options, (_value, key) => {
1762
- if (key === "manifest") {
1763
- return false;
1764
- }
1765
- });
1762
+ this.options = cloneDeepOptions(options);
1766
1763
  this.runtimePkgs = [
1767
1764
  "@module-federation/runtime",
1768
1765
  "@module-federation/enhanced/runtime",
@@ -1973,7 +1970,16 @@ var DTSManager = (_a = class {
1973
1970
  ...packageTypes,
1974
1971
  "Y"
1975
1972
  ].join(" :\n")} ;`;
1976
- const pkgsDeclareStr = this.runtimePkgs.map((pkg) => {
1973
+ const runtimePkgs = /* @__PURE__ */ new Set();
1974
+ [
1975
+ ...this.runtimePkgs,
1976
+ ...hostOptions.runtimePkgs
1977
+ ].forEach((pkg) => {
1978
+ runtimePkgs.add(pkg);
1979
+ });
1980
+ const pkgsDeclareStr = [
1981
+ ...runtimePkgs
1982
+ ].map((pkg) => {
1977
1983
  return `declare module "${pkg}" {
1978
1984
  ${remoteKeysStr}
1979
1985
  ${packageTypesStr}
@@ -2106,6 +2112,7 @@ var DTSManager = (_a = class {
2106
2112
  }, __name(_a, "DTSManager"), _a);
2107
2113
 
2108
2114
  // packages/dts-plugin/src/core/lib/utils.ts
2115
+ var import_lodash = __toESM(require("lodash.clonedeepwith"));
2109
2116
  function getDTSManagerConstructor(implementation) {
2110
2117
  if (implementation) {
2111
2118
  const NewConstructor = require(implementation);
@@ -2123,6 +2130,18 @@ function isDebugMode() {
2123
2130
  return Boolean(process.env["FEDERATION_DEBUG"]) || process.env["NODE_ENV"] === "test";
2124
2131
  }
2125
2132
  __name(isDebugMode, "isDebugMode");
2133
+ function cloneDeepOptions(options) {
2134
+ const excludeKeys = [
2135
+ "manifest",
2136
+ "async"
2137
+ ];
2138
+ return (0, import_lodash.default)(options, (_value, key) => {
2139
+ if (typeof key === "string" && excludeKeys.includes(key)) {
2140
+ return false;
2141
+ }
2142
+ });
2143
+ }
2144
+ __name(cloneDeepOptions, "cloneDeepOptions");
2126
2145
  function axiosGet(url, config) {
2127
2146
  return __async(this, null, function* () {
2128
2147
  const httpAgent = new import_http2.default.Agent({
@@ -2175,6 +2194,7 @@ function getEffectiveRootDir(parsedCommandLine) {
2175
2194
  }
2176
2195
  __name(getEffectiveRootDir, "getEffectiveRootDir");
2177
2196
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
2197
+ var _a3;
2178
2198
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
2179
2199
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
2180
2200
  if (readResult.error) {
@@ -2193,6 +2213,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
2193
2213
  };
2194
2214
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
2195
2215
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
2216
+ (_a3 = rawTsConfigJson.compilerOptions) == null ? true : delete _a3.paths;
2196
2217
  const filesToCompile = [
2197
2218
  ...Object.values(mapComponentsToExpose),
2198
2219
  ...additionalFilesToCompile
@@ -2201,10 +2222,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
2201
2222
  rawTsConfigJson.files = filesToCompile;
2202
2223
  rawTsConfigJson.exclude = [];
2203
2224
  "references" in rawTsConfigJson && delete rawTsConfigJson.references;
2204
- const extendsPath = rawTsConfigJson.extends;
2205
- if (extendsPath && extendsPath.startsWith(".")) {
2206
- rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
2207
- }
2225
+ rawTsConfigJson.extends = resolvedTsConfigPath;
2208
2226
  return rawTsConfigJson;
2209
2227
  }, "readTsConfig");
2210
2228
  var TS_EXTENSIONS = [
@@ -2251,9 +2269,6 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
2251
2269
  };
2252
2270
  }, "retrieveRemoteConfig");
2253
2271
 
2254
- // packages/dts-plugin/src/core/lib/DtsWorker.ts
2255
- var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
2256
-
2257
2272
  // packages/dts-plugin/src/core/rpc/index.ts
2258
2273
  var rpc_exports = {};
2259
2274
  __export(rpc_exports, {
@@ -2462,11 +2477,24 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
2462
2477
  return remoteMethod(...args);
2463
2478
  },
2464
2479
  terminate() {
2465
- var _a3;
2466
- (_a3 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a3.call(childProcess, {
2467
- type: RpcGMCallTypes.EXIT,
2468
- id
2469
- });
2480
+ try {
2481
+ if (childProcess.connected) {
2482
+ childProcess.send({
2483
+ type: RpcGMCallTypes.EXIT,
2484
+ id
2485
+ }, (err) => {
2486
+ if (err) {
2487
+ console.error("Error sending message:", err);
2488
+ }
2489
+ });
2490
+ }
2491
+ } catch (error2) {
2492
+ if (error2.code === "EPIPE") {
2493
+ console.error("Pipe closed before message could be sent:", error2);
2494
+ } else {
2495
+ console.error("Unexpected error:", error2);
2496
+ }
2497
+ }
2470
2498
  childProcess = void 0;
2471
2499
  remoteMethod = void 0;
2472
2500
  },
@@ -1,6 +1,6 @@
1
- import { m as DtsWorkerOptions } from './DtsWorker-90454949.js';
1
+ import { k as DtsWorkerOptions } from './DtsWorker-17de6ba4.js';
2
2
  import 'child_process';
3
- import './DTSManagerOptions-c0728719.js';
3
+ import './DTSManagerOptions-7109e8ac.js';
4
4
  import '@module-federation/sdk';
5
5
  import 'typescript';
6
6
 
@@ -1,6 +1,6 @@
1
- import { m as DtsWorkerOptions } from './DtsWorker-90454949.js';
1
+ import { k as DtsWorkerOptions } from './DtsWorker-17de6ba4.js';
2
2
  import 'child_process';
3
- import './DTSManagerOptions-c0728719.js';
3
+ import './DTSManagerOptions-7109e8ac.js';
4
4
  import '@module-federation/sdk';
5
5
  import 'typescript';
6
6