@module-federation/dts-plugin 0.8.7 → 0.8.9

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.
@@ -159,6 +159,7 @@ __name(exposeRpc, "exposeRpc");
159
159
  var import_axios = __toESM(require("axios"));
160
160
  var import_http2 = __toESM(require("http"));
161
161
  var import_https = __toESM(require("https"));
162
+ var import_sdk6 = require("@module-federation/sdk");
162
163
  var import_ansi_colors = __toESM(require("ansi-colors"));
163
164
 
164
165
  // packages/dts-plugin/src/core/configurations/remotePlugin.ts
@@ -309,7 +310,7 @@ function writeTempTsConfig(tsConfig, context, name) {
309
310
  const createHash = /* @__PURE__ */ __name((contents) => {
310
311
  return import_crypto.default.createHash("md5").update(contents).digest("hex");
311
312
  }, "createHash");
312
- const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
313
+ const hash = createHash(`${JSON.stringify(tsConfig)}${name}${Date.now()}`);
313
314
  const tempTsConfigJsonPath = (0, import_path2.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
314
315
  (0, import_fs_extra.ensureDirSync)((0, import_path2.dirname)(tempTsConfigJsonPath));
315
316
  (0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
@@ -1309,6 +1310,7 @@ var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, d
1309
1310
  var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1310
1311
  let retries = 0;
1311
1312
  return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
1313
+ var _a2;
1312
1314
  const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
1313
1315
  while (retries++ < hostOptions.maxRetries) {
1314
1316
  try {
@@ -1316,6 +1318,9 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1316
1318
  const response = yield axiosGet(url, {
1317
1319
  responseType: "arraybuffer"
1318
1320
  }).catch(downloadErrorLogger(destinationFolder, url));
1321
+ if (typeof ((_a2 = response.headers) == null ? void 0 : _a2["content-type"]) === "string" && response.headers["content-type"].includes("text/html")) {
1322
+ throw new Error(`${url} receives invalid content-type: ${response.headers["content-type"]}`);
1323
+ }
1319
1324
  try {
1320
1325
  if (hostOptions.deleteTypesFolder) {
1321
1326
  yield (0, import_promises2.rm)(destinationPath, {
@@ -1328,6 +1333,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1328
1333
  }
1329
1334
  const zip = new import_adm_zip.default(Buffer.from(response.data));
1330
1335
  zip.extractAllTo(destinationPath, true);
1336
+ fileLog(`zip.extractAllTo success destinationPath: ${destinationPath}; url: ${url}`, "downloadTypesArchive", "info");
1331
1337
  return [
1332
1338
  destinationFolder,
1333
1339
  destinationPath
@@ -1528,7 +1534,9 @@ var DTSManager = (_a = class {
1528
1534
  logger.success("Federated types created correctly");
1529
1535
  } catch (error2) {
1530
1536
  if (((_a2 = this.options.remote) == null ? void 0 : _a2.abortOnError) === false) {
1531
- logger.error(`Unable to compile federated types, ${error2}`);
1537
+ if (this.options.displayErrorInTerminal) {
1538
+ logger.error(`Unable to compile federated types${error2}`);
1539
+ }
1532
1540
  } else {
1533
1541
  throw error2;
1534
1542
  }
@@ -1607,8 +1615,9 @@ var DTSManager = (_a = class {
1607
1615
  const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
1608
1616
  import_fs2.default.writeFileSync(filePath, apiTypeFile);
1609
1617
  this.loadedRemoteAPIAlias.add(remoteInfo.alias);
1618
+ fileLog(`success`, "downloadAPITypes", "info");
1610
1619
  } catch (err) {
1611
- fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "consumeTargetRemotes", "error");
1620
+ fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
1612
1621
  }
1613
1622
  });
1614
1623
  }
@@ -1723,9 +1732,10 @@ var DTSManager = (_a = class {
1723
1732
  return __async(this, null, function* () {
1724
1733
  var _a2, _b, _c;
1725
1734
  try {
1726
- const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
1735
+ const { remoteName, updateMode, remoteTarPath, remoteInfo: updatedRemoteInfo, once } = options;
1727
1736
  const hostName = (_c = (_b = (_a2 = this.options) == null ? void 0 : _a2.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
1728
- fileLog(`updateTypes options:, ${JSON.stringify(options, null, 2)}`, "consumeTypes", "info");
1737
+ fileLog(`options: ${JSON.stringify(options, null, 2)};
1738
+ hostName: ${hostName}`, "updateTypes", "info");
1729
1739
  if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
1730
1740
  if (!this.options.remote) {
1731
1741
  return;
@@ -1739,13 +1749,23 @@ var DTSManager = (_a = class {
1739
1749
  const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
1740
1750
  const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
1741
1751
  const consumeTypes = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
1742
- const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, requiredRemoteInfo);
1752
+ fileLog(`consumeTypes start`, "updateTypes", "info");
1753
+ if (!requiredRemoteInfo.zipUrl) {
1754
+ throw new Error(`Can not get ${requiredRemoteInfo.name}'s types archive url!`);
1755
+ }
1756
+ const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, __spreadProps(__spreadValues({}, requiredRemoteInfo), {
1757
+ // use remoteTarPath first
1758
+ zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
1759
+ }));
1743
1760
  yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
1761
+ fileLog(`consumeTypes end`, "updateTypes", "info");
1744
1762
  }), "consumeTypes");
1763
+ fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
1745
1764
  if (!loadedRemoteInfo) {
1746
1765
  const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
1747
1766
  return item.name === remoteName;
1748
1767
  });
1768
+ fileLog(`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`, "updateTypes", "info");
1749
1769
  if (remoteInfo) {
1750
1770
  if (!this.remoteAliasMap[remoteInfo.alias]) {
1751
1771
  const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
@@ -1765,7 +1785,7 @@ var DTSManager = (_a = class {
1765
1785
  });
1766
1786
  fileLog(`start request manifest`, "consumeTypes", "info");
1767
1787
  this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
1768
- fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "consumeTypes", "info");
1788
+ fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "updateTypes", "info");
1769
1789
  yield consumeDynamicRemoteTypes();
1770
1790
  }
1771
1791
  if (!once && this.updatedRemoteInfos[updatedRemoteInfo.name]) {
@@ -1814,6 +1834,10 @@ function cloneDeepOptions(options) {
1814
1834
  });
1815
1835
  }
1816
1836
  __name(cloneDeepOptions, "cloneDeepOptions");
1837
+ var getEnvHeaders = /* @__PURE__ */ __name(() => {
1838
+ const headersStr = (0, import_sdk6.getProcessEnv)()["MF_ENV_HEADERS"] || "{}";
1839
+ return __spreadValues({}, JSON.parse(headersStr));
1840
+ }, "getEnvHeaders");
1817
1841
  function axiosGet(url, config) {
1818
1842
  return __async(this, null, function* () {
1819
1843
  const httpAgent = new import_http2.default.Agent({
@@ -1822,10 +1846,12 @@ function axiosGet(url, config) {
1822
1846
  const httpsAgent = new import_https.default.Agent({
1823
1847
  family: 4
1824
1848
  });
1825
- return import_axios.default.get(url, __spreadValues({
1849
+ return import_axios.default.get(url, __spreadValues(__spreadValues({
1826
1850
  httpAgent,
1827
1851
  httpsAgent
1828
- }, config));
1852
+ }, {
1853
+ headers: getEnvHeaders()
1854
+ }), config));
1829
1855
  });
1830
1856
  }
1831
1857
  __name(axiosGet, "axiosGet");
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { WebpackPluginInstance, Compiler } from 'webpack';
2
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
+ import { WebpackPluginInstance, Compiler } from 'webpack';
3
3
 
4
4
  declare class DtsPlugin implements WebpackPluginInstance {
5
5
  options: moduleFederationPlugin.ModuleFederationPluginOptions;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { WebpackPluginInstance, Compiler } from 'webpack';
2
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
+ import { WebpackPluginInstance, Compiler } from 'webpack';
3
3
 
4
4
  declare class DtsPlugin implements WebpackPluginInstance {
5
5
  options: moduleFederationPlugin.ModuleFederationPluginOptions;