@module-federation/dts-plugin 0.9.0 → 0.9.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.
@@ -104,6 +104,7 @@ var import_ansi_colors = __toESM(require("ansi-colors"));
104
104
  var import_path4 = __toESM(require("path"));
105
105
  var import_promises3 = require("fs/promises");
106
106
  var import_fs = __toESM(require("fs"));
107
+ var import_fs_extra3 = __toESM(require("fs-extra"));
107
108
  var import_sdk5 = require("@module-federation/sdk");
108
109
  var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
109
110
 
@@ -1723,7 +1724,8 @@ var defaultOptions = {
1723
1724
  context: process.cwd(),
1724
1725
  abortOnError: true,
1725
1726
  consumeAPITypes: false,
1726
- runtimePkgs: []
1727
+ runtimePkgs: [],
1728
+ remoteTypeUrls: {}
1727
1729
  };
1728
1730
  var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1729
1731
  const remoteUrl = new URL(url, "file:");
@@ -1739,18 +1741,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
1739
1741
  }, "buildApiTypeUrl");
1740
1742
  var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
1741
1743
  const { hostOptions, remoteAlias, remote } = options;
1744
+ const { remoteTypeUrls } = hostOptions;
1742
1745
  let decodedRemote = remote;
1743
1746
  if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
1744
1747
  decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
1745
1748
  }
1746
1749
  const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
1747
1750
  const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
1748
- const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
1751
+ let zipUrl = "";
1752
+ let apiTypeUrl = "";
1753
+ const name = parsedInfo.name || remoteAlias;
1754
+ if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
1755
+ zipUrl = remoteTypeUrls[name].zip;
1756
+ apiTypeUrl = remoteTypeUrls[name].api;
1757
+ }
1758
+ if (!zipUrl && url) {
1759
+ zipUrl = buildZipUrl(hostOptions, url);
1760
+ }
1761
+ if (!apiTypeUrl && zipUrl) {
1762
+ apiTypeUrl = buildApiTypeUrl(zipUrl);
1763
+ }
1749
1764
  return {
1750
- name: parsedInfo.name || remoteAlias,
1765
+ name,
1751
1766
  url,
1752
1767
  zipUrl,
1753
- apiTypeUrl: buildApiTypeUrl(zipUrl),
1768
+ apiTypeUrl,
1754
1769
  alias: remoteAlias
1755
1770
  };
1756
1771
  }, "retrieveRemoteInfo");
@@ -1826,6 +1841,7 @@ var DTSManager = (_a = class {
1826
1841
  }
1827
1842
  extractRemoteTypes(options) {
1828
1843
  return __async(this, null, function* () {
1844
+ var _a3;
1829
1845
  const { remoteOptions, tsConfig } = options;
1830
1846
  if (!remoteOptions.extractRemoteTypes) {
1831
1847
  return;
@@ -1840,20 +1856,29 @@ var DTSManager = (_a = class {
1840
1856
  }
1841
1857
  }
1842
1858
  const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1843
- if (hasRemotes) {
1844
- const tempHostOptions = {
1845
- moduleFederationConfig: remoteOptions.moduleFederationConfig,
1846
- typesFolder: import_path4.default.join(mfTypesPath, "node_modules"),
1847
- remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
1848
- deleteTypesFolder: true,
1849
- context: remoteOptions.context,
1850
- implementation: remoteOptions.implementation,
1851
- abortOnError: false
1852
- };
1853
- yield this.consumeArchiveTypes(tempHostOptions);
1859
+ if (hasRemotes && this.options.host) {
1860
+ try {
1861
+ const { hostOptions } = retrieveHostConfig(this.options.host);
1862
+ const remoteTypesFolder = import_path4.default.resolve(hostOptions.context, hostOptions.typesFolder);
1863
+ const targetDir = import_path4.default.join(mfTypesPath, "node_modules");
1864
+ if (import_fs.default.existsSync(remoteTypesFolder)) {
1865
+ const targetFolder = import_path4.default.resolve(remoteOptions.context, targetDir);
1866
+ yield import_fs_extra3.default.ensureDir(targetFolder);
1867
+ yield import_fs_extra3.default.copy(remoteTypesFolder, targetFolder, {
1868
+ overwrite: true
1869
+ });
1870
+ }
1871
+ } catch (err) {
1872
+ if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
1873
+ fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
1874
+ } else {
1875
+ throw err;
1876
+ }
1877
+ }
1854
1878
  }
1855
1879
  });
1856
1880
  }
1881
+ // it must execute after consumeTypes
1857
1882
  generateTypes() {
1858
1883
  return __async(this, null, function* () {
1859
1884
  var _a3;
@@ -1866,6 +1891,18 @@ var DTSManager = (_a = class {
1866
1891
  if (!Object.keys(mapComponentsToExpose).length) {
1867
1892
  return;
1868
1893
  }
1894
+ if (tsConfig.compilerOptions.tsBuildInfoFile) {
1895
+ try {
1896
+ const tsBuildInfoFile = import_path4.default.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
1897
+ const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1898
+ if (!import_fs.default.existsSync(mfTypesPath)) {
1899
+ import_fs.default.rmSync(tsBuildInfoFile, {
1900
+ force: true
1901
+ });
1902
+ }
1903
+ } catch (e) {
1904
+ }
1905
+ }
1869
1906
  yield this.extractRemoteTypes({
1870
1907
  remoteOptions,
1871
1908
  tsConfig,
@@ -1895,7 +1932,7 @@ var DTSManager = (_a = class {
1895
1932
  } catch (error2) {
1896
1933
  if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
1897
1934
  if (this.options.displayErrorInTerminal) {
1898
- logger.error(`Unable to compile federated types${error2}`);
1935
+ logger.error(`Unable to compile federated types ${error2}`);
1899
1936
  }
1900
1937
  } else {
1901
1938
  throw error2;
@@ -1909,6 +1946,9 @@ var DTSManager = (_a = class {
1909
1946
  if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
1910
1947
  return remoteInfo;
1911
1948
  }
1949
+ if (remoteInfo.zipUrl) {
1950
+ return remoteInfo;
1951
+ }
1912
1952
  const url = remoteInfo.url;
1913
1953
  const res = yield axiosGet(url);
1914
1954
  const manifestJson = res.data;
@@ -1974,8 +2014,10 @@ var DTSManager = (_a = class {
1974
2014
  apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
1975
2015
  const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
1976
2016
  import_fs.default.writeFileSync(filePath, apiTypeFile);
2017
+ const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
1977
2018
  this.loadedRemoteAPIAlias.add(remoteInfo.alias);
1978
2019
  fileLog(`success`, "downloadAPITypes", "info");
2020
+ return existed;
1979
2021
  } catch (err) {
1980
2022
  fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
1981
2023
  }
@@ -2117,7 +2159,10 @@ hostName: ${hostName}`, "updateTypes", "info");
2117
2159
  // use remoteTarPath first
2118
2160
  zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
2119
2161
  }));
2120
- yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
2162
+ const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
2163
+ if (addNew) {
2164
+ this.consumeAPITypes(hostOptions);
2165
+ }
2121
2166
  fileLog(`consumeTypes end`, "updateTypes", "info");
2122
2167
  }), "consumeTypes");
2123
2168
  fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
@@ -2135,7 +2180,6 @@ hostName: ${hostName}`, "updateTypes", "info");
2135
2180
  } else if (updatedRemoteInfo) {
2136
2181
  const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
2137
2182
  yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
2138
- this.consumeAPITypes(hostOptions);
2139
2183
  }), "consumeDynamicRemoteTypes");
2140
2184
  if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
2141
2185
  const parsedRemoteInfo = retrieveRemoteInfo({
@@ -2187,10 +2231,13 @@ function cloneDeepOptions(options) {
2187
2231
  "manifest",
2188
2232
  "async"
2189
2233
  ];
2190
- return (0, import_lodash.default)(options, (_value, key) => {
2234
+ return (0, import_lodash.default)(options, (value, key) => {
2191
2235
  if (typeof key === "string" && excludeKeys.includes(key)) {
2192
2236
  return false;
2193
2237
  }
2238
+ if (typeof value === "function") {
2239
+ return false;
2240
+ }
2194
2241
  });
2195
2242
  }
2196
2243
  __name(cloneDeepOptions, "cloneDeepOptions");
@@ -1,4 +1,4 @@
1
- import { k as DtsWorkerOptions } from './DtsWorker-484d9f4a.js';
1
+ import { k as DtsWorkerOptions } from './DtsWorker-edc3f145.js';
2
2
  import 'child_process';
3
3
  import './DTSManagerOptions-c74c59ed.js';
4
4
  import '@module-federation/sdk';
@@ -1,4 +1,4 @@
1
- import { k as DtsWorkerOptions } from './DtsWorker-484d9f4a.js';
1
+ import { k as DtsWorkerOptions } from './DtsWorker-edc3f145.js';
2
2
  import 'child_process';
3
3
  import './DTSManagerOptions-c74c59ed.js';
4
4
  import '@module-federation/sdk';
@@ -289,6 +289,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
289
289
  var import_path4 = __toESM(require("path"));
290
290
  var import_promises3 = require("fs/promises");
291
291
  var import_fs2 = __toESM(require("fs"));
292
+ var import_fs_extra3 = __toESM(require("fs-extra"));
292
293
  var import_sdk5 = require("@module-federation/sdk");
293
294
  var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
294
295
 
@@ -1369,7 +1370,8 @@ var defaultOptions2 = {
1369
1370
  context: process.cwd(),
1370
1371
  abortOnError: true,
1371
1372
  consumeAPITypes: false,
1372
- runtimePkgs: []
1373
+ runtimePkgs: [],
1374
+ remoteTypeUrls: {}
1373
1375
  };
1374
1376
  var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
1375
1377
  const remoteUrl = new URL(url, "file:");
@@ -1385,18 +1387,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
1385
1387
  }, "buildApiTypeUrl");
1386
1388
  var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
1387
1389
  const { hostOptions, remoteAlias, remote } = options;
1390
+ const { remoteTypeUrls } = hostOptions;
1388
1391
  let decodedRemote = remote;
1389
1392
  if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
1390
1393
  decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
1391
1394
  }
1392
1395
  const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
1393
1396
  const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
1394
- const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
1397
+ let zipUrl = "";
1398
+ let apiTypeUrl = "";
1399
+ const name = parsedInfo.name || remoteAlias;
1400
+ if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
1401
+ zipUrl = remoteTypeUrls[name].zip;
1402
+ apiTypeUrl = remoteTypeUrls[name].api;
1403
+ }
1404
+ if (!zipUrl && url) {
1405
+ zipUrl = buildZipUrl(hostOptions, url);
1406
+ }
1407
+ if (!apiTypeUrl && zipUrl) {
1408
+ apiTypeUrl = buildApiTypeUrl(zipUrl);
1409
+ }
1395
1410
  return {
1396
- name: parsedInfo.name || remoteAlias,
1411
+ name,
1397
1412
  url,
1398
1413
  zipUrl,
1399
- apiTypeUrl: buildApiTypeUrl(zipUrl),
1414
+ apiTypeUrl,
1400
1415
  alias: remoteAlias
1401
1416
  };
1402
1417
  }, "retrieveRemoteInfo");
@@ -1472,6 +1487,7 @@ var DTSManager = (_a = class {
1472
1487
  }
1473
1488
  extractRemoteTypes(options) {
1474
1489
  return __async(this, null, function* () {
1490
+ var _a2;
1475
1491
  const { remoteOptions, tsConfig } = options;
1476
1492
  if (!remoteOptions.extractRemoteTypes) {
1477
1493
  return;
@@ -1486,20 +1502,29 @@ var DTSManager = (_a = class {
1486
1502
  }
1487
1503
  }
1488
1504
  const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1489
- if (hasRemotes) {
1490
- const tempHostOptions = {
1491
- moduleFederationConfig: remoteOptions.moduleFederationConfig,
1492
- typesFolder: import_path4.default.join(mfTypesPath, "node_modules"),
1493
- remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
1494
- deleteTypesFolder: true,
1495
- context: remoteOptions.context,
1496
- implementation: remoteOptions.implementation,
1497
- abortOnError: false
1498
- };
1499
- yield this.consumeArchiveTypes(tempHostOptions);
1505
+ if (hasRemotes && this.options.host) {
1506
+ try {
1507
+ const { hostOptions } = retrieveHostConfig(this.options.host);
1508
+ const remoteTypesFolder = import_path4.default.resolve(hostOptions.context, hostOptions.typesFolder);
1509
+ const targetDir = import_path4.default.join(mfTypesPath, "node_modules");
1510
+ if (import_fs2.default.existsSync(remoteTypesFolder)) {
1511
+ const targetFolder = import_path4.default.resolve(remoteOptions.context, targetDir);
1512
+ yield import_fs_extra3.default.ensureDir(targetFolder);
1513
+ yield import_fs_extra3.default.copy(remoteTypesFolder, targetFolder, {
1514
+ overwrite: true
1515
+ });
1516
+ }
1517
+ } catch (err) {
1518
+ if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
1519
+ fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
1520
+ } else {
1521
+ throw err;
1522
+ }
1523
+ }
1500
1524
  }
1501
1525
  });
1502
1526
  }
1527
+ // it must execute after consumeTypes
1503
1528
  generateTypes() {
1504
1529
  return __async(this, null, function* () {
1505
1530
  var _a2;
@@ -1512,6 +1537,18 @@ var DTSManager = (_a = class {
1512
1537
  if (!Object.keys(mapComponentsToExpose).length) {
1513
1538
  return;
1514
1539
  }
1540
+ if (tsConfig.compilerOptions.tsBuildInfoFile) {
1541
+ try {
1542
+ const tsBuildInfoFile = import_path4.default.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
1543
+ const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1544
+ if (!import_fs2.default.existsSync(mfTypesPath)) {
1545
+ import_fs2.default.rmSync(tsBuildInfoFile, {
1546
+ force: true
1547
+ });
1548
+ }
1549
+ } catch (e) {
1550
+ }
1551
+ }
1515
1552
  yield this.extractRemoteTypes({
1516
1553
  remoteOptions,
1517
1554
  tsConfig,
@@ -1541,7 +1578,7 @@ var DTSManager = (_a = class {
1541
1578
  } catch (error2) {
1542
1579
  if (((_a2 = this.options.remote) == null ? void 0 : _a2.abortOnError) === false) {
1543
1580
  if (this.options.displayErrorInTerminal) {
1544
- logger.error(`Unable to compile federated types${error2}`);
1581
+ logger.error(`Unable to compile federated types ${error2}`);
1545
1582
  }
1546
1583
  } else {
1547
1584
  throw error2;
@@ -1555,6 +1592,9 @@ var DTSManager = (_a = class {
1555
1592
  if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
1556
1593
  return remoteInfo;
1557
1594
  }
1595
+ if (remoteInfo.zipUrl) {
1596
+ return remoteInfo;
1597
+ }
1558
1598
  const url = remoteInfo.url;
1559
1599
  const res = yield axiosGet(url);
1560
1600
  const manifestJson = res.data;
@@ -1620,8 +1660,10 @@ var DTSManager = (_a = class {
1620
1660
  apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
1621
1661
  const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
1622
1662
  import_fs2.default.writeFileSync(filePath, apiTypeFile);
1663
+ const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
1623
1664
  this.loadedRemoteAPIAlias.add(remoteInfo.alias);
1624
1665
  fileLog(`success`, "downloadAPITypes", "info");
1666
+ return existed;
1625
1667
  } catch (err) {
1626
1668
  fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
1627
1669
  }
@@ -1763,7 +1805,10 @@ hostName: ${hostName}`, "updateTypes", "info");
1763
1805
  // use remoteTarPath first
1764
1806
  zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
1765
1807
  }));
1766
- yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
1808
+ const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
1809
+ if (addNew) {
1810
+ this.consumeAPITypes(hostOptions);
1811
+ }
1767
1812
  fileLog(`consumeTypes end`, "updateTypes", "info");
1768
1813
  }), "consumeTypes");
1769
1814
  fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
@@ -1781,7 +1826,6 @@ hostName: ${hostName}`, "updateTypes", "info");
1781
1826
  } else if (updatedRemoteInfo) {
1782
1827
  const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
1783
1828
  yield consumeTypes(this.updatedRemoteInfos[updatedRemoteInfo.name]);
1784
- this.consumeAPITypes(hostOptions);
1785
1829
  }), "consumeDynamicRemoteTypes");
1786
1830
  if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
1787
1831
  const parsedRemoteInfo = retrieveRemoteInfo({
@@ -1833,10 +1877,13 @@ function cloneDeepOptions(options) {
1833
1877
  "manifest",
1834
1878
  "async"
1835
1879
  ];
1836
- return (0, import_lodash.default)(options, (_value, key) => {
1880
+ return (0, import_lodash.default)(options, (value, key) => {
1837
1881
  if (typeof key === "string" && excludeKeys.includes(key)) {
1838
1882
  return false;
1839
1883
  }
1884
+ if (typeof value === "function") {
1885
+ return false;
1886
+ }
1840
1887
  });
1841
1888
  }
1842
1889
  __name(cloneDeepOptions, "cloneDeepOptions");