@module-federation/dts-plugin 0.2.7 → 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;
@@ -170,6 +172,7 @@ var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null,
170
172
  const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
171
173
  const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
172
174
  const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
175
+ (0, import_fs_extra.ensureDirSync)(mfeTypeEntryDirectory);
173
176
  yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
174
177
  export { default } from './${relativePathToOutput}';`);
175
178
  }
@@ -182,7 +185,7 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
182
185
  return;
183
186
  }
184
187
  const { compilerOptions } = tsConfig;
185
- const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
188
+ const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
186
189
  try {
187
190
  const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
188
191
  const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
@@ -220,6 +223,9 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
220
223
  }
221
224
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
222
225
  } catch (err) {
226
+ if (isDebugMode()) {
227
+ console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
228
+ }
223
229
  throw err;
224
230
  }
225
231
  }), "compileTs");
@@ -342,6 +348,11 @@ var import_chalk2 = __toESM(require("chalk"));
342
348
  var DEFAULT_WEB_SOCKET_PORT = 16322;
343
349
  var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
344
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 = {}));
345
356
 
346
357
  // packages/dts-plugin/src/server/utils/log.ts
347
358
  function fileLog(msg, module2, level) {
@@ -543,16 +554,6 @@ var UpdateKind;
543
554
  UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
544
555
  })(UpdateKind || (UpdateKind = {}));
545
556
 
546
- // packages/dts-plugin/src/core/constant.ts
547
- var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
548
- var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
549
- var HOST_API_TYPES_FILE_NAME = "index.d.ts";
550
- var UpdateMode;
551
- (function(UpdateMode2) {
552
- UpdateMode2["POSITIVE"] = "POSITIVE";
553
- UpdateMode2["PASSIVE"] = "PASSIVE";
554
- })(UpdateMode || (UpdateMode = {}));
555
-
556
557
  // packages/dts-plugin/src/server/broker/Broker.ts
557
558
  var _Broker = class _Broker {
558
559
  constructor() {
@@ -1199,7 +1200,8 @@ var defaultOptions = {
1199
1200
  implementation: "",
1200
1201
  context: process.cwd(),
1201
1202
  abortOnError: true,
1202
- consumeAPITypes: false
1203
+ consumeAPITypes: false,
1204
+ runtimePkgs: []
1203
1205
  };
1204
1206
  var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1205
1207
  const remoteUrl = new URL(url, "file:");
@@ -1258,6 +1260,11 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
1258
1260
  };
1259
1261
  }, "retrieveHostConfig");
1260
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
+
1261
1268
  // packages/dts-plugin/src/core/lib/DTSManager.ts
1262
1269
  var _a;
1263
1270
  var DTSManager = (_a = class {
@@ -1268,11 +1275,7 @@ var DTSManager = (_a = class {
1268
1275
  __publicField(this, "loadedRemoteAPIAlias");
1269
1276
  __publicField(this, "extraOptions");
1270
1277
  __publicField(this, "updatedRemoteInfos");
1271
- this.options = (0, import_lodash.default)(options, (_value, key) => {
1272
- if (key === "manifest") {
1273
- return false;
1274
- }
1275
- });
1278
+ this.options = cloneDeepOptions(options);
1276
1279
  this.runtimePkgs = [
1277
1280
  "@module-federation/runtime",
1278
1281
  "@module-federation/enhanced/runtime",
@@ -1341,7 +1344,7 @@ var DTSManager = (_a = class {
1341
1344
  if (!Object.keys(mapComponentsToExpose).length) {
1342
1345
  return;
1343
1346
  }
1344
- this.extractRemoteTypes({
1347
+ yield this.extractRemoteTypes({
1345
1348
  remoteOptions,
1346
1349
  tsConfig,
1347
1350
  mapComponentsToExpose
@@ -1483,7 +1486,16 @@ var DTSManager = (_a = class {
1483
1486
  ...packageTypes,
1484
1487
  "Y"
1485
1488
  ].join(" :\n")} ;`;
1486
- 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) => {
1487
1499
  return `declare module "${pkg}" {
1488
1500
  ${remoteKeysStr}
1489
1501
  ${packageTypesStr}
@@ -1616,6 +1628,7 @@ var DTSManager = (_a = class {
1616
1628
  }, __name(_a, "DTSManager"), _a);
1617
1629
 
1618
1630
  // packages/dts-plugin/src/core/lib/utils.ts
1631
+ var import_lodash = __toESM(require("lodash.clonedeepwith"));
1619
1632
  function getDTSManagerConstructor(implementation) {
1620
1633
  if (implementation) {
1621
1634
  const NewConstructor = require(implementation);
@@ -1687,6 +1700,18 @@ var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) =
1687
1700
  return false;
1688
1701
  }
1689
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");
1690
1715
  function axiosGet(url, config) {
1691
1716
  return __async(this, null, function* () {
1692
1717
  const httpAgent = new import_http2.default.Agent({
@@ -1739,6 +1764,7 @@ function getEffectiveRootDir(parsedCommandLine) {
1739
1764
  }
1740
1765
  __name(getEffectiveRootDir, "getEffectiveRootDir");
1741
1766
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
1767
+ var _a4;
1742
1768
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1743
1769
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
1744
1770
  if (readResult.error) {
@@ -1757,6 +1783,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1757
1783
  };
1758
1784
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
1759
1785
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
1786
+ (_a4 = rawTsConfigJson.compilerOptions) == null ? true : delete _a4.paths;
1760
1787
  const filesToCompile = [
1761
1788
  ...Object.values(mapComponentsToExpose),
1762
1789
  ...additionalFilesToCompile
@@ -1765,10 +1792,7 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1765
1792
  rawTsConfigJson.files = filesToCompile;
1766
1793
  rawTsConfigJson.exclude = [];
1767
1794
  "references" in rawTsConfigJson && delete rawTsConfigJson.references;
1768
- const extendsPath = rawTsConfigJson.extends;
1769
- if (extendsPath && extendsPath.startsWith(".")) {
1770
- rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
1771
- }
1795
+ rawTsConfigJson.extends = resolvedTsConfigPath;
1772
1796
  return rawTsConfigJson;
1773
1797
  }, "readTsConfig");
1774
1798
  var TS_EXTENSIONS = [
@@ -1828,7 +1852,6 @@ __name(generateTypes, "generateTypes");
1828
1852
 
1829
1853
  // packages/dts-plugin/src/core/lib/DtsWorker.ts
1830
1854
  var import_path6 = __toESM(require("path"));
1831
- var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
1832
1855
 
1833
1856
  // packages/dts-plugin/src/core/rpc/index.ts
1834
1857
  var rpc_exports = {};
@@ -2038,11 +2061,24 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
2038
2061
  return remoteMethod(...args);
2039
2062
  },
2040
2063
  terminate() {
2041
- var _a4;
2042
- (_a4 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a4.call(childProcess, {
2043
- type: RpcGMCallTypes.EXIT,
2044
- id
2045
- });
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
+ }
2046
2082
  childProcess = void 0;
2047
2083
  remoteMethod = void 0;
2048
2084
  },
@@ -2070,11 +2106,7 @@ var _DtsWorker = class _DtsWorker {
2070
2106
  __publicField(this, "rpcWorker");
2071
2107
  __publicField(this, "_options");
2072
2108
  __publicField(this, "_res");
2073
- this._options = (0, import_lodash2.default)(options, (_value, key) => {
2074
- if (key === "manifest") {
2075
- return false;
2076
- }
2077
- });
2109
+ this._options = cloneDeepOptions(options);
2078
2110
  this.removeUnSerializationOptions();
2079
2111
  this.rpcWorker = createRpcWorker(import_path6.default.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
2080
2112
  this._res = this.rpcWorker.connect(this._options);
@@ -2115,7 +2147,13 @@ var _DtsWorker = class _DtsWorker {
2115
2147
  }
2116
2148
  exit() {
2117
2149
  var _a4;
2118
- (_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
+ }
2119
2157
  }
2120
2158
  };
2121
2159
  __name(_DtsWorker, "DtsWorker");
@@ -2147,11 +2185,7 @@ var _DevWorker = class _DevWorker {
2147
2185
  __publicField(this, "_rpcWorker");
2148
2186
  __publicField(this, "_options");
2149
2187
  __publicField(this, "_res");
2150
- this._options = (0, import_lodash3.default)(options, (_value, key) => {
2151
- if (key === "manifest") {
2152
- return false;
2153
- }
2154
- });
2188
+ this._options = cloneDeepOptions(options);
2155
2189
  this.removeUnSerializationOptions();
2156
2190
  this._rpcWorker = rpc_exports.createRpcWorker(import_path7.default.resolve(__dirname, "./fork-dev-worker.js"), {}, void 0, false);
2157
2191
  this._res = this._rpcWorker.connect(this._options);
@@ -2298,14 +2332,17 @@ var _DevPlugin = class _DevPlugin {
2298
2332
  if (!normalizedDev.disableLiveReload) {
2299
2333
  const TEMP_DIR2 = import_path8.default.join(`${process.cwd()}/node_modules`, import_sdk6.TEMP_DIR);
2300
2334
  const filepath = import_path8.default.join(TEMP_DIR2, `live-reload.js`);
2301
- _DevPlugin.ensureLiveReloadEntry({
2302
- name
2303
- }, filepath);
2304
- compiler.hooks.afterPlugins.tap("MFDevPlugin", () => {
2305
- new compiler.webpack.EntryPlugin(compiler.context, filepath, {
2335
+ if (typeof compiler.options.entry === "object") {
2336
+ _DevPlugin.ensureLiveReloadEntry({
2306
2337
  name
2307
- }).apply(compiler);
2308
- });
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
+ }
2309
2346
  }
2310
2347
  const defaultGenerateTypes = {
2311
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.7",
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",