@module-federation/dts-plugin 0.2.8 → 0.3.0

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);
@@ -346,6 +348,11 @@ var import_chalk2 = __toESM(require("chalk"));
346
348
  var DEFAULT_WEB_SOCKET_PORT = 16322;
347
349
  var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
348
350
  var WEB_CLIENT_OPTIONS_IDENTIFIER = "__WEB_CLIENT_OPTIONS__";
351
+ var UpdateMode;
352
+ (function(UpdateMode2) {
353
+ UpdateMode2["POSITIVE"] = "POSITIVE";
354
+ UpdateMode2["PASSIVE"] = "PASSIVE";
355
+ })(UpdateMode || (UpdateMode = {}));
349
356
 
350
357
  // packages/dts-plugin/src/server/utils/log.ts
351
358
  function fileLog(msg, module2, level) {
@@ -547,16 +554,6 @@ var UpdateKind;
547
554
  UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
548
555
  })(UpdateKind || (UpdateKind = {}));
549
556
 
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
557
  // packages/dts-plugin/src/server/broker/Broker.ts
561
558
  var _Broker = class _Broker {
562
559
  constructor() {
@@ -1203,7 +1200,8 @@ var defaultOptions = {
1203
1200
  implementation: "",
1204
1201
  context: process.cwd(),
1205
1202
  abortOnError: true,
1206
- consumeAPITypes: false
1203
+ consumeAPITypes: false,
1204
+ runtimePkgs: []
1207
1205
  };
1208
1206
  var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1209
1207
  const remoteUrl = new URL(url, "file:");
@@ -1262,6 +1260,11 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
1262
1260
  };
1263
1261
  }, "retrieveHostConfig");
1264
1262
 
1263
+ // packages/dts-plugin/src/core/constant.ts
1264
+ var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
1265
+ var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
1266
+ var HOST_API_TYPES_FILE_NAME = "index.d.ts";
1267
+
1265
1268
  // packages/dts-plugin/src/core/lib/DTSManager.ts
1266
1269
  var _a;
1267
1270
  var DTSManager = (_a = class {
@@ -1272,11 +1275,7 @@ var DTSManager = (_a = class {
1272
1275
  __publicField(this, "loadedRemoteAPIAlias");
1273
1276
  __publicField(this, "extraOptions");
1274
1277
  __publicField(this, "updatedRemoteInfos");
1275
- this.options = (0, import_lodash.default)(options, (_value, key) => {
1276
- if (key === "manifest") {
1277
- return false;
1278
- }
1279
- });
1278
+ this.options = cloneDeepOptions(options);
1280
1279
  this.runtimePkgs = [
1281
1280
  "@module-federation/runtime",
1282
1281
  "@module-federation/enhanced/runtime",
@@ -1487,7 +1486,16 @@ var DTSManager = (_a = class {
1487
1486
  ...packageTypes,
1488
1487
  "Y"
1489
1488
  ].join(" :\n")} ;`;
1490
- const pkgsDeclareStr = this.runtimePkgs.map((pkg) => {
1489
+ const runtimePkgs = /* @__PURE__ */ new Set();
1490
+ [
1491
+ ...this.runtimePkgs,
1492
+ ...hostOptions.runtimePkgs
1493
+ ].forEach((pkg) => {
1494
+ runtimePkgs.add(pkg);
1495
+ });
1496
+ const pkgsDeclareStr = [
1497
+ ...runtimePkgs
1498
+ ].map((pkg) => {
1491
1499
  return `declare module "${pkg}" {
1492
1500
  ${remoteKeysStr}
1493
1501
  ${packageTypesStr}
@@ -1620,6 +1628,7 @@ var DTSManager = (_a = class {
1620
1628
  }, __name(_a, "DTSManager"), _a);
1621
1629
 
1622
1630
  // packages/dts-plugin/src/core/lib/utils.ts
1631
+ var import_lodash = __toESM(require("lodash.clonedeepwith"));
1623
1632
  function getDTSManagerConstructor(implementation) {
1624
1633
  if (implementation) {
1625
1634
  const NewConstructor = require(implementation);
@@ -1691,6 +1700,18 @@ var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) =
1691
1700
  return false;
1692
1701
  }
1693
1702
  }, "isTSProject");
1703
+ function cloneDeepOptions(options) {
1704
+ const excludeKeys = [
1705
+ "manifest",
1706
+ "async"
1707
+ ];
1708
+ return (0, import_lodash.default)(options, (_value, key) => {
1709
+ if (typeof key === "string" && excludeKeys.includes(key)) {
1710
+ return false;
1711
+ }
1712
+ });
1713
+ }
1714
+ __name(cloneDeepOptions, "cloneDeepOptions");
1694
1715
  function axiosGet(url, config) {
1695
1716
  return __async(this, null, function* () {
1696
1717
  const httpAgent = new import_http2.default.Agent({
@@ -1743,6 +1764,7 @@ function getEffectiveRootDir(parsedCommandLine) {
1743
1764
  }
1744
1765
  __name(getEffectiveRootDir, "getEffectiveRootDir");
1745
1766
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
1767
+ var _a4;
1746
1768
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1747
1769
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
1748
1770
  if (readResult.error) {
@@ -1761,6 +1783,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1761
1783
  };
1762
1784
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
1763
1785
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
1786
+ (_a4 = rawTsConfigJson.compilerOptions) == null ? true : delete _a4.paths;
1764
1787
  const filesToCompile = [
1765
1788
  ...Object.values(mapComponentsToExpose),
1766
1789
  ...additionalFilesToCompile
@@ -1769,10 +1792,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1769
1792
  rawTsConfigJson.files = filesToCompile;
1770
1793
  rawTsConfigJson.exclude = [];
1771
1794
  "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
- }
1795
+ rawTsConfigJson.extends = resolvedTsConfigPath;
1776
1796
  return rawTsConfigJson;
1777
1797
  }, "readTsConfig");
1778
1798
  var TS_EXTENSIONS = [
@@ -1832,7 +1852,6 @@ __name(generateTypes, "generateTypes");
1832
1852
 
1833
1853
  // packages/dts-plugin/src/core/lib/DtsWorker.ts
1834
1854
  var import_path6 = __toESM(require("path"));
1835
- var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
1836
1855
 
1837
1856
  // packages/dts-plugin/src/core/rpc/index.ts
1838
1857
  var rpc_exports = {};
@@ -2042,11 +2061,24 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
2042
2061
  return remoteMethod(...args);
2043
2062
  },
2044
2063
  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
- });
2064
+ try {
2065
+ if (childProcess.connected) {
2066
+ childProcess.send({
2067
+ type: RpcGMCallTypes.EXIT,
2068
+ id
2069
+ }, (err) => {
2070
+ if (err) {
2071
+ console.error("Error sending message:", err);
2072
+ }
2073
+ });
2074
+ }
2075
+ } catch (error2) {
2076
+ if (error2.code === "EPIPE") {
2077
+ console.error("Pipe closed before message could be sent:", error2);
2078
+ } else {
2079
+ console.error("Unexpected error:", error2);
2080
+ }
2081
+ }
2050
2082
  childProcess = void 0;
2051
2083
  remoteMethod = void 0;
2052
2084
  },
@@ -2074,11 +2106,7 @@ var _DtsWorker = class _DtsWorker {
2074
2106
  __publicField(this, "rpcWorker");
2075
2107
  __publicField(this, "_options");
2076
2108
  __publicField(this, "_res");
2077
- this._options = (0, import_lodash2.default)(options, (_value, key) => {
2078
- if (key === "manifest") {
2079
- return false;
2080
- }
2081
- });
2109
+ this._options = cloneDeepOptions(options);
2082
2110
  this.removeUnSerializationOptions();
2083
2111
  this.rpcWorker = createRpcWorker(import_path6.default.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
2084
2112
  this._res = this.rpcWorker.connect(this._options);
@@ -2119,7 +2147,13 @@ var _DtsWorker = class _DtsWorker {
2119
2147
  }
2120
2148
  exit() {
2121
2149
  var _a4;
2122
- (_a4 = this.rpcWorker) == null ? void 0 : _a4.terminate();
2150
+ try {
2151
+ (_a4 = this.rpcWorker) == null ? void 0 : _a4.terminate();
2152
+ } catch (err) {
2153
+ if (isDebugMode()) {
2154
+ console.error(err);
2155
+ }
2156
+ }
2123
2157
  }
2124
2158
  };
2125
2159
  __name(_DtsWorker, "DtsWorker");
@@ -2151,11 +2185,7 @@ var _DevWorker = class _DevWorker {
2151
2185
  __publicField(this, "_rpcWorker");
2152
2186
  __publicField(this, "_options");
2153
2187
  __publicField(this, "_res");
2154
- this._options = (0, import_lodash3.default)(options, (_value, key) => {
2155
- if (key === "manifest") {
2156
- return false;
2157
- }
2158
- });
2188
+ this._options = cloneDeepOptions(options);
2159
2189
  this.removeUnSerializationOptions();
2160
2190
  this._rpcWorker = rpc_exports.createRpcWorker(import_path7.default.resolve(__dirname, "./fork-dev-worker.js"), {}, void 0, false);
2161
2191
  this._res = this._rpcWorker.connect(this._options);
@@ -2302,14 +2332,17 @@ var _DevPlugin = class _DevPlugin {
2302
2332
  if (!normalizedDev.disableLiveReload) {
2303
2333
  const TEMP_DIR2 = import_path8.default.join(`${process.cwd()}/node_modules`, import_sdk6.TEMP_DIR);
2304
2334
  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, {
2335
+ if (typeof compiler.options.entry === "object") {
2336
+ _DevPlugin.ensureLiveReloadEntry({
2310
2337
  name
2311
- }).apply(compiler);
2312
- });
2338
+ }, filepath);
2339
+ Object.keys(compiler.options.entry).forEach((entry) => {
2340
+ const normalizedEntry = compiler.options.entry[entry];
2341
+ if (typeof normalizedEntry === "object" && Array.isArray(normalizedEntry.import)) {
2342
+ normalizedEntry.import.unshift(filepath);
2343
+ }
2344
+ });
2345
+ }
2313
2346
  }
2314
2347
  const defaultGenerateTypes = {
2315
2348
  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.0",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",