@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.
package/dist/index.js CHANGED
@@ -85,7 +85,6 @@ var fse = __toESM(require("fs-extra"));
85
85
 
86
86
  // packages/dts-plugin/src/dev-worker/DevWorker.ts
87
87
  var import_path7 = __toESM(require("path"));
88
- var import_lodash3 = __toESM(require("lodash.clonedeepwith"));
89
88
 
90
89
  // packages/dts-plugin/src/core/configurations/remotePlugin.ts
91
90
  var import_fs3 = require("fs");
@@ -107,7 +106,6 @@ var import_path3 = __toESM(require("path"));
107
106
  var import_promises3 = require("fs/promises");
108
107
  var import_fs = __toESM(require("fs"));
109
108
  var import_sdk5 = require("@module-federation/sdk");
110
- var import_lodash = __toESM(require("lodash.clonedeepwith"));
111
109
  var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
112
110
 
113
111
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
@@ -117,8 +115,8 @@ var import_promises2 = require("fs/promises");
117
115
 
118
116
  // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
119
117
  var import_fs_extra = require("fs-extra");
118
+ var import_crypto = __toESM(require("crypto"));
120
119
  var import_promises = require("fs/promises");
121
- var import_crypto = require("crypto");
122
120
  var import_path = require("path");
123
121
  var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
124
122
  var import_child_process = require("child_process");
@@ -129,8 +127,12 @@ var DEFINITION_FILE_EXTENSION = ".d.ts";
129
127
  var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
130
128
  var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
131
129
  var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
132
- function writeTempTsConfig(tsConfig, context) {
133
- const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${(0, import_crypto.randomUUID)()}.json`);
130
+ function writeTempTsConfig(tsConfig, context, name) {
131
+ const createHash = /* @__PURE__ */ __name((contents) => {
132
+ return import_crypto.default.createHash("md5").update(contents).digest("hex");
133
+ }, "createHash");
134
+ const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
135
+ const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
134
136
  (0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
135
137
  (0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
136
138
  return tempTsConfigJsonPath;
@@ -183,7 +185,7 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
183
185
  return;
184
186
  }
185
187
  const { compilerOptions } = tsConfig;
186
- const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
188
+ const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
187
189
  try {
188
190
  const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
189
191
  const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
@@ -221,9 +223,6 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
221
223
  }
222
224
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
223
225
  } catch (err) {
224
- if (isDebugMode()) {
225
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
226
- }
227
226
  throw err;
228
227
  }
229
228
  }), "compileTs");
@@ -346,6 +345,11 @@ var import_chalk2 = __toESM(require("chalk"));
346
345
  var DEFAULT_WEB_SOCKET_PORT = 16322;
347
346
  var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
348
347
  var WEB_CLIENT_OPTIONS_IDENTIFIER = "__WEB_CLIENT_OPTIONS__";
348
+ var UpdateMode;
349
+ (function(UpdateMode2) {
350
+ UpdateMode2["POSITIVE"] = "POSITIVE";
351
+ UpdateMode2["PASSIVE"] = "PASSIVE";
352
+ })(UpdateMode || (UpdateMode = {}));
349
353
 
350
354
  // packages/dts-plugin/src/server/utils/log.ts
351
355
  function fileLog(msg, module2, level) {
@@ -547,16 +551,6 @@ var UpdateKind;
547
551
  UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
548
552
  })(UpdateKind || (UpdateKind = {}));
549
553
 
550
- // packages/dts-plugin/src/core/constant.ts
551
- var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
552
- var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
553
- var HOST_API_TYPES_FILE_NAME = "index.d.ts";
554
- var UpdateMode;
555
- (function(UpdateMode2) {
556
- UpdateMode2["POSITIVE"] = "POSITIVE";
557
- UpdateMode2["PASSIVE"] = "PASSIVE";
558
- })(UpdateMode || (UpdateMode = {}));
559
-
560
554
  // packages/dts-plugin/src/server/broker/Broker.ts
561
555
  var _Broker = class _Broker {
562
556
  constructor() {
@@ -1203,7 +1197,8 @@ var defaultOptions = {
1203
1197
  implementation: "",
1204
1198
  context: process.cwd(),
1205
1199
  abortOnError: true,
1206
- consumeAPITypes: false
1200
+ consumeAPITypes: false,
1201
+ runtimePkgs: []
1207
1202
  };
1208
1203
  var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1209
1204
  const remoteUrl = new URL(url, "file:");
@@ -1262,6 +1257,11 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
1262
1257
  };
1263
1258
  }, "retrieveHostConfig");
1264
1259
 
1260
+ // packages/dts-plugin/src/core/constant.ts
1261
+ var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
1262
+ var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
1263
+ var HOST_API_TYPES_FILE_NAME = "index.d.ts";
1264
+
1265
1265
  // packages/dts-plugin/src/core/lib/DTSManager.ts
1266
1266
  var _a;
1267
1267
  var DTSManager = (_a = class {
@@ -1272,11 +1272,7 @@ var DTSManager = (_a = class {
1272
1272
  __publicField(this, "loadedRemoteAPIAlias");
1273
1273
  __publicField(this, "extraOptions");
1274
1274
  __publicField(this, "updatedRemoteInfos");
1275
- this.options = (0, import_lodash.default)(options, (_value, key) => {
1276
- if (key === "manifest") {
1277
- return false;
1278
- }
1279
- });
1275
+ this.options = cloneDeepOptions(options);
1280
1276
  this.runtimePkgs = [
1281
1277
  "@module-federation/runtime",
1282
1278
  "@module-federation/enhanced/runtime",
@@ -1487,7 +1483,16 @@ var DTSManager = (_a = class {
1487
1483
  ...packageTypes,
1488
1484
  "Y"
1489
1485
  ].join(" :\n")} ;`;
1490
- const pkgsDeclareStr = this.runtimePkgs.map((pkg) => {
1486
+ const runtimePkgs = /* @__PURE__ */ new Set();
1487
+ [
1488
+ ...this.runtimePkgs,
1489
+ ...hostOptions.runtimePkgs
1490
+ ].forEach((pkg) => {
1491
+ runtimePkgs.add(pkg);
1492
+ });
1493
+ const pkgsDeclareStr = [
1494
+ ...runtimePkgs
1495
+ ].map((pkg) => {
1491
1496
  return `declare module "${pkg}" {
1492
1497
  ${remoteKeysStr}
1493
1498
  ${packageTypesStr}
@@ -1620,6 +1625,7 @@ var DTSManager = (_a = class {
1620
1625
  }, __name(_a, "DTSManager"), _a);
1621
1626
 
1622
1627
  // packages/dts-plugin/src/core/lib/utils.ts
1628
+ var import_lodash = __toESM(require("lodash.clonedeepwith"));
1623
1629
  function getDTSManagerConstructor(implementation) {
1624
1630
  if (implementation) {
1625
1631
  const NewConstructor = require(implementation);
@@ -1691,6 +1697,18 @@ var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) =
1691
1697
  return false;
1692
1698
  }
1693
1699
  }, "isTSProject");
1700
+ function cloneDeepOptions(options) {
1701
+ const excludeKeys = [
1702
+ "manifest",
1703
+ "async"
1704
+ ];
1705
+ return (0, import_lodash.default)(options, (_value, key) => {
1706
+ if (typeof key === "string" && excludeKeys.includes(key)) {
1707
+ return false;
1708
+ }
1709
+ });
1710
+ }
1711
+ __name(cloneDeepOptions, "cloneDeepOptions");
1694
1712
  function axiosGet(url, config) {
1695
1713
  return __async(this, null, function* () {
1696
1714
  const httpAgent = new import_http2.default.Agent({
@@ -1743,6 +1761,7 @@ function getEffectiveRootDir(parsedCommandLine) {
1743
1761
  }
1744
1762
  __name(getEffectiveRootDir, "getEffectiveRootDir");
1745
1763
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
1764
+ var _a4;
1746
1765
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1747
1766
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
1748
1767
  if (readResult.error) {
@@ -1761,6 +1780,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1761
1780
  };
1762
1781
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
1763
1782
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
1783
+ (_a4 = rawTsConfigJson.compilerOptions) == null ? true : delete _a4.paths;
1764
1784
  const filesToCompile = [
1765
1785
  ...Object.values(mapComponentsToExpose),
1766
1786
  ...additionalFilesToCompile
@@ -1769,10 +1789,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1769
1789
  rawTsConfigJson.files = filesToCompile;
1770
1790
  rawTsConfigJson.exclude = [];
1771
1791
  "references" in rawTsConfigJson && delete rawTsConfigJson.references;
1772
- const extendsPath = rawTsConfigJson.extends;
1773
- if (extendsPath && extendsPath.startsWith(".")) {
1774
- rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
1775
- }
1792
+ rawTsConfigJson.extends = resolvedTsConfigPath;
1776
1793
  return rawTsConfigJson;
1777
1794
  }, "readTsConfig");
1778
1795
  var TS_EXTENSIONS = [
@@ -1832,7 +1849,6 @@ __name(generateTypes, "generateTypes");
1832
1849
 
1833
1850
  // packages/dts-plugin/src/core/lib/DtsWorker.ts
1834
1851
  var import_path6 = __toESM(require("path"));
1835
- var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
1836
1852
 
1837
1853
  // packages/dts-plugin/src/core/rpc/index.ts
1838
1854
  var rpc_exports = {};
@@ -2042,11 +2058,24 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
2042
2058
  return remoteMethod(...args);
2043
2059
  },
2044
2060
  terminate() {
2045
- var _a4;
2046
- (_a4 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a4.call(childProcess, {
2047
- type: RpcGMCallTypes.EXIT,
2048
- id
2049
- });
2061
+ try {
2062
+ if (childProcess.connected) {
2063
+ childProcess.send({
2064
+ type: RpcGMCallTypes.EXIT,
2065
+ id
2066
+ }, (err) => {
2067
+ if (err) {
2068
+ console.error("Error sending message:", err);
2069
+ }
2070
+ });
2071
+ }
2072
+ } catch (error2) {
2073
+ if (error2.code === "EPIPE") {
2074
+ console.error("Pipe closed before message could be sent:", error2);
2075
+ } else {
2076
+ console.error("Unexpected error:", error2);
2077
+ }
2078
+ }
2050
2079
  childProcess = void 0;
2051
2080
  remoteMethod = void 0;
2052
2081
  },
@@ -2074,11 +2103,7 @@ var _DtsWorker = class _DtsWorker {
2074
2103
  __publicField(this, "rpcWorker");
2075
2104
  __publicField(this, "_options");
2076
2105
  __publicField(this, "_res");
2077
- this._options = (0, import_lodash2.default)(options, (_value, key) => {
2078
- if (key === "manifest") {
2079
- return false;
2080
- }
2081
- });
2106
+ this._options = cloneDeepOptions(options);
2082
2107
  this.removeUnSerializationOptions();
2083
2108
  this.rpcWorker = createRpcWorker(import_path6.default.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
2084
2109
  this._res = this.rpcWorker.connect(this._options);
@@ -2119,7 +2144,13 @@ var _DtsWorker = class _DtsWorker {
2119
2144
  }
2120
2145
  exit() {
2121
2146
  var _a4;
2122
- (_a4 = this.rpcWorker) == null ? void 0 : _a4.terminate();
2147
+ try {
2148
+ (_a4 = this.rpcWorker) == null ? void 0 : _a4.terminate();
2149
+ } catch (err) {
2150
+ if (isDebugMode()) {
2151
+ console.error(err);
2152
+ }
2153
+ }
2123
2154
  }
2124
2155
  };
2125
2156
  __name(_DtsWorker, "DtsWorker");
@@ -2151,11 +2182,7 @@ var _DevWorker = class _DevWorker {
2151
2182
  __publicField(this, "_rpcWorker");
2152
2183
  __publicField(this, "_options");
2153
2184
  __publicField(this, "_res");
2154
- this._options = (0, import_lodash3.default)(options, (_value, key) => {
2155
- if (key === "manifest") {
2156
- return false;
2157
- }
2158
- });
2185
+ this._options = cloneDeepOptions(options);
2159
2186
  this.removeUnSerializationOptions();
2160
2187
  this._rpcWorker = rpc_exports.createRpcWorker(import_path7.default.resolve(__dirname, "./fork-dev-worker.js"), {}, void 0, false);
2161
2188
  this._res = this._rpcWorker.connect(this._options);
@@ -2302,14 +2329,17 @@ var _DevPlugin = class _DevPlugin {
2302
2329
  if (!normalizedDev.disableLiveReload) {
2303
2330
  const TEMP_DIR2 = import_path8.default.join(`${process.cwd()}/node_modules`, import_sdk6.TEMP_DIR);
2304
2331
  const filepath = import_path8.default.join(TEMP_DIR2, `live-reload.js`);
2305
- _DevPlugin.ensureLiveReloadEntry({
2306
- name
2307
- }, filepath);
2308
- compiler.hooks.afterPlugins.tap("MFDevPlugin", () => {
2309
- new compiler.webpack.EntryPlugin(compiler.context, filepath, {
2332
+ if (typeof compiler.options.entry === "object") {
2333
+ _DevPlugin.ensureLiveReloadEntry({
2310
2334
  name
2311
- }).apply(compiler);
2312
- });
2335
+ }, filepath);
2336
+ Object.keys(compiler.options.entry).forEach((entry) => {
2337
+ const normalizedEntry = compiler.options.entry[entry];
2338
+ if (typeof normalizedEntry === "object" && Array.isArray(normalizedEntry.import)) {
2339
+ normalizedEntry.import.unshift(filepath);
2340
+ }
2341
+ });
2342
+ }
2313
2343
  }
2314
2344
  const defaultGenerateTypes = {
2315
2345
  compileInChildProcess: true
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/dts-plugin",
3
- "version": "0.2.8",
3
+ "version": "0.3.1",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",