@module-federation/dts-plugin 0.1.20 → 0.2.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/CHANGELOG.md +25 -0
- package/dist/core.js +87 -29
- package/dist/esm/{chunk-AJO6KMSF.js → chunk-DQ2CDTSN.js} +88 -30
- package/dist/esm/core.js +1 -1
- package/dist/esm/fork-dev-worker.js +1 -1
- package/dist/esm/fork-generate-dts.js +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/start-broker.js +1 -1
- package/dist/fork-dev-worker.js +68 -28
- package/dist/fork-generate-dts.js +68 -28
- package/dist/iife/launch-web-client.js +1 -1
- package/dist/index.js +88 -30
- package/dist/package.json +2 -2
- package/dist/start-broker.js +4 -7
- package/package.json +6 -6
package/dist/fork-dev-worker.js
CHANGED
|
@@ -81,10 +81,16 @@ var import_path5 = require("path");
|
|
|
81
81
|
var import_managers2 = require("@module-federation/managers");
|
|
82
82
|
var import_typescript2 = __toESM(require("typescript"));
|
|
83
83
|
|
|
84
|
+
// packages/dts-plugin/src/core/lib/utils.ts
|
|
85
|
+
var import_axios = __toESM(require("axios"));
|
|
86
|
+
var import_http2 = __toESM(require("http"));
|
|
87
|
+
var import_https = __toESM(require("https"));
|
|
88
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
89
|
+
|
|
84
90
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
85
91
|
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
86
92
|
var import_path4 = __toESM(require("path"));
|
|
87
|
-
var
|
|
93
|
+
var import_promises2 = require("fs/promises");
|
|
88
94
|
var import_fs = __toESM(require("fs"));
|
|
89
95
|
var import_sdk4 = require("@module-federation/sdk");
|
|
90
96
|
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
@@ -92,8 +98,8 @@ var import_third_party_dts_extractor2 = require("@module-federation/third-party-
|
|
|
92
98
|
|
|
93
99
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
94
100
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
95
|
-
var import_axios = __toESM(require("axios"));
|
|
96
101
|
var import_path3 = require("path");
|
|
102
|
+
var import_promises = require("fs/promises");
|
|
97
103
|
|
|
98
104
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
99
105
|
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
@@ -121,7 +127,10 @@ var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remote
|
|
|
121
127
|
host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
|
|
122
128
|
originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
|
|
123
129
|
for (const sourceFile of sourceFiles || []) {
|
|
124
|
-
|
|
130
|
+
let sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
|
|
131
|
+
if (sourceEntry === ".") {
|
|
132
|
+
sourceEntry = "index";
|
|
133
|
+
}
|
|
125
134
|
if (sourceEntry) {
|
|
126
135
|
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
127
136
|
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
@@ -1601,9 +1610,19 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1601
1610
|
while (retries++ < hostOptions.maxRetries) {
|
|
1602
1611
|
try {
|
|
1603
1612
|
const url = fileToDownload;
|
|
1604
|
-
const response = yield
|
|
1613
|
+
const response = yield axiosGet(url, {
|
|
1605
1614
|
responseType: "arraybuffer"
|
|
1606
1615
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1616
|
+
try {
|
|
1617
|
+
if (hostOptions.deleteTypesFolder) {
|
|
1618
|
+
yield (0, import_promises.rm)(destinationPath, {
|
|
1619
|
+
recursive: true,
|
|
1620
|
+
force: true
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
} catch (error2) {
|
|
1624
|
+
fileLog(`Unable to remove types folder, ${error2}`, "downloadTypesArchive", "error");
|
|
1625
|
+
}
|
|
1607
1626
|
const zip = new import_adm_zip.default(Buffer.from(response.data));
|
|
1608
1627
|
zip.extractAllTo(destinationPath, true);
|
|
1609
1628
|
return [
|
|
@@ -1650,8 +1669,12 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1650
1669
|
}, "buildApiTypeUrl");
|
|
1651
1670
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1652
1671
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1653
|
-
|
|
1654
|
-
|
|
1672
|
+
let decodedRemote = remote;
|
|
1673
|
+
if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
|
|
1674
|
+
decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
|
|
1675
|
+
}
|
|
1676
|
+
const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
|
|
1677
|
+
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1655
1678
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1656
1679
|
return {
|
|
1657
1680
|
name: parsedInfo.name || remoteAlias,
|
|
@@ -1690,7 +1713,6 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
|
1690
1713
|
}, "retrieveHostConfig");
|
|
1691
1714
|
|
|
1692
1715
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1693
|
-
var import_axios2 = __toESM(require("axios"));
|
|
1694
1716
|
var _a;
|
|
1695
1717
|
var DTSManager = (_a = class {
|
|
1696
1718
|
constructor(options) {
|
|
@@ -1786,11 +1808,17 @@ var DTSManager = (_a = class {
|
|
|
1786
1808
|
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1787
1809
|
import_fs.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1788
1810
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1811
|
+
try {
|
|
1812
|
+
if (remoteOptions.deleteTypesFolder) {
|
|
1813
|
+
yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1814
|
+
recursive: true,
|
|
1815
|
+
force: true
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
} catch (err) {
|
|
1819
|
+
if (isDebugMode()) {
|
|
1820
|
+
console.error(err);
|
|
1821
|
+
}
|
|
1794
1822
|
}
|
|
1795
1823
|
console.log(import_ansi_colors2.default.green("Federated types created correctly"));
|
|
1796
1824
|
} catch (error2) {
|
|
@@ -1809,10 +1837,7 @@ var DTSManager = (_a = class {
|
|
|
1809
1837
|
return remoteInfo;
|
|
1810
1838
|
}
|
|
1811
1839
|
const url = remoteInfo.url;
|
|
1812
|
-
const res = yield (
|
|
1813
|
-
method: "get",
|
|
1814
|
-
url
|
|
1815
|
-
});
|
|
1840
|
+
const res = yield axiosGet(url);
|
|
1816
1841
|
const manifestJson = res.data;
|
|
1817
1842
|
if (!manifestJson.metaData.types.zip) {
|
|
1818
1843
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
@@ -1861,7 +1886,7 @@ var DTSManager = (_a = class {
|
|
|
1861
1886
|
}
|
|
1862
1887
|
try {
|
|
1863
1888
|
const url = apiTypeUrl;
|
|
1864
|
-
const res = yield
|
|
1889
|
+
const res = yield axiosGet(url);
|
|
1865
1890
|
let apiTypeFile = res.data;
|
|
1866
1891
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1867
1892
|
const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
@@ -1918,12 +1943,6 @@ var DTSManager = (_a = class {
|
|
|
1918
1943
|
consumeArchiveTypes(options) {
|
|
1919
1944
|
return __async(this, null, function* () {
|
|
1920
1945
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1921
|
-
if (hostOptions.deleteTypesFolder) {
|
|
1922
|
-
yield (0, import_promises.rm)(hostOptions.typesFolder, {
|
|
1923
|
-
recursive: true,
|
|
1924
|
-
force: true
|
|
1925
|
-
}).catch((error2) => fileLog(`Unable to remove types folder, ${error2}`, "consumeArchiveTypes", "error"));
|
|
1926
|
-
}
|
|
1927
1946
|
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1928
1947
|
const remoteInfo = item[1];
|
|
1929
1948
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
@@ -1995,6 +2014,10 @@ var DTSManager = (_a = class {
|
|
|
1995
2014
|
}
|
|
1996
2015
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1997
2016
|
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
2017
|
+
const consumeTypes2 = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
2018
|
+
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, requiredRemoteInfo);
|
|
2019
|
+
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
2020
|
+
}), "consumeTypes");
|
|
1998
2021
|
if (!loadedRemoteInfo) {
|
|
1999
2022
|
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
2000
2023
|
return item.name === remoteName;
|
|
@@ -2004,11 +2027,10 @@ var DTSManager = (_a = class {
|
|
|
2004
2027
|
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
2005
2028
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
2006
2029
|
}
|
|
2007
|
-
yield
|
|
2030
|
+
yield consumeTypes2(this.remoteAliasMap[remoteInfo.alias]);
|
|
2008
2031
|
} else if (updatedRemoteInfo) {
|
|
2009
2032
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
2010
|
-
|
|
2011
|
-
yield this.downloadAPITypes(this.updatedRemoteInfos[updatedRemoteInfo.name], destinationPath);
|
|
2033
|
+
yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
2012
2034
|
this.consumeAPITypes(hostOptions);
|
|
2013
2035
|
}), "consumeDynamicRemoteTypes");
|
|
2014
2036
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
@@ -2027,7 +2049,7 @@ var DTSManager = (_a = class {
|
|
|
2027
2049
|
}
|
|
2028
2050
|
}
|
|
2029
2051
|
} else {
|
|
2030
|
-
yield
|
|
2052
|
+
yield consumeTypes2(loadedRemoteInfo);
|
|
2031
2053
|
}
|
|
2032
2054
|
}
|
|
2033
2055
|
} catch (err) {
|
|
@@ -2038,7 +2060,6 @@ var DTSManager = (_a = class {
|
|
|
2038
2060
|
}, __name(_a, "DTSManager"), _a);
|
|
2039
2061
|
|
|
2040
2062
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
2041
|
-
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
2042
2063
|
function getDTSManagerConstructor(implementation) {
|
|
2043
2064
|
if (implementation) {
|
|
2044
2065
|
const NewConstructor = require(implementation);
|
|
@@ -2052,6 +2073,25 @@ var validateOptions = /* @__PURE__ */ __name((options) => {
|
|
|
2052
2073
|
throw new Error("moduleFederationConfig is required");
|
|
2053
2074
|
}
|
|
2054
2075
|
}, "validateOptions");
|
|
2076
|
+
function isDebugMode() {
|
|
2077
|
+
return Boolean(process.env["FEDERATION_DEBUG"]) || process.env["NODE_ENV"] === "test";
|
|
2078
|
+
}
|
|
2079
|
+
__name(isDebugMode, "isDebugMode");
|
|
2080
|
+
function axiosGet(url, config) {
|
|
2081
|
+
return __async(this, null, function* () {
|
|
2082
|
+
const httpAgent = new import_http2.default.Agent({
|
|
2083
|
+
family: 4
|
|
2084
|
+
});
|
|
2085
|
+
const httpsAgent = new import_https.default.Agent({
|
|
2086
|
+
family: 4
|
|
2087
|
+
});
|
|
2088
|
+
return import_axios.default.get(url, __spreadValues({
|
|
2089
|
+
httpAgent,
|
|
2090
|
+
httpsAgent
|
|
2091
|
+
}, config));
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
__name(axiosGet, "axiosGet");
|
|
2055
2095
|
|
|
2056
2096
|
// packages/dts-plugin/src/core/configurations/remotePlugin.ts
|
|
2057
2097
|
var defaultOptions2 = {
|
|
@@ -143,6 +143,12 @@ function exposeRpc(fn) {
|
|
|
143
143
|
}
|
|
144
144
|
__name(exposeRpc, "exposeRpc");
|
|
145
145
|
|
|
146
|
+
// packages/dts-plugin/src/core/lib/utils.ts
|
|
147
|
+
var import_axios = __toESM(require("axios"));
|
|
148
|
+
var import_http2 = __toESM(require("http"));
|
|
149
|
+
var import_https = __toESM(require("https"));
|
|
150
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
151
|
+
|
|
146
152
|
// packages/dts-plugin/src/core/configurations/remotePlugin.ts
|
|
147
153
|
var import_fs = require("fs");
|
|
148
154
|
var import_path = require("path");
|
|
@@ -226,7 +232,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
226
232
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
227
233
|
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
228
234
|
var import_path4 = __toESM(require("path"));
|
|
229
|
-
var
|
|
235
|
+
var import_promises2 = require("fs/promises");
|
|
230
236
|
var import_fs2 = __toESM(require("fs"));
|
|
231
237
|
var import_sdk4 = require("@module-federation/sdk");
|
|
232
238
|
var import_lodash2 = __toESM(require("lodash.clonedeepwith"));
|
|
@@ -234,8 +240,8 @@ var import_third_party_dts_extractor2 = require("@module-federation/third-party-
|
|
|
234
240
|
|
|
235
241
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
236
242
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
237
|
-
var import_axios = __toESM(require("axios"));
|
|
238
243
|
var import_path3 = require("path");
|
|
244
|
+
var import_promises = require("fs/promises");
|
|
239
245
|
|
|
240
246
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
241
247
|
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
@@ -263,7 +269,10 @@ var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remote
|
|
|
263
269
|
host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
|
|
264
270
|
originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
|
|
265
271
|
for (const sourceFile of sourceFiles || []) {
|
|
266
|
-
|
|
272
|
+
let sourceEntry = mapExposeToEntry[(0, import_path2.normalize)(sourceFile.fileName)];
|
|
273
|
+
if (sourceEntry === ".") {
|
|
274
|
+
sourceEntry = "index";
|
|
275
|
+
}
|
|
267
276
|
if (sourceEntry) {
|
|
268
277
|
const mfeTypeEntry = (0, import_path2.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
269
278
|
const mfeTypeEntryDirectory = (0, import_path2.dirname)(mfeTypeEntry);
|
|
@@ -600,8 +609,12 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
600
609
|
}, "buildApiTypeUrl");
|
|
601
610
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
602
611
|
const { hostOptions, remoteAlias, remote } = options;
|
|
603
|
-
|
|
604
|
-
|
|
612
|
+
let decodedRemote = remote;
|
|
613
|
+
if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
|
|
614
|
+
decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
|
|
615
|
+
}
|
|
616
|
+
const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
|
|
617
|
+
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
605
618
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
606
619
|
return {
|
|
607
620
|
name: parsedInfo.name || remoteAlias,
|
|
@@ -1449,9 +1462,19 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1449
1462
|
while (retries++ < hostOptions.maxRetries) {
|
|
1450
1463
|
try {
|
|
1451
1464
|
const url = fileToDownload;
|
|
1452
|
-
const response = yield
|
|
1465
|
+
const response = yield axiosGet(url, {
|
|
1453
1466
|
responseType: "arraybuffer"
|
|
1454
1467
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1468
|
+
try {
|
|
1469
|
+
if (hostOptions.deleteTypesFolder) {
|
|
1470
|
+
yield (0, import_promises.rm)(destinationPath, {
|
|
1471
|
+
recursive: true,
|
|
1472
|
+
force: true
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
} catch (error2) {
|
|
1476
|
+
fileLog(`Unable to remove types folder, ${error2}`, "downloadTypesArchive", "error");
|
|
1477
|
+
}
|
|
1455
1478
|
const zip = new import_adm_zip.default(Buffer.from(response.data));
|
|
1456
1479
|
zip.extractAllTo(destinationPath, true);
|
|
1457
1480
|
return [
|
|
@@ -1472,7 +1495,6 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1472
1495
|
}, "downloadTypesArchive");
|
|
1473
1496
|
|
|
1474
1497
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1475
|
-
var import_axios2 = __toESM(require("axios"));
|
|
1476
1498
|
var _a2;
|
|
1477
1499
|
var DTSManager = (_a2 = class {
|
|
1478
1500
|
constructor(options) {
|
|
@@ -1568,11 +1590,17 @@ var DTSManager = (_a2 = class {
|
|
|
1568
1590
|
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1569
1591
|
import_fs2.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1570
1592
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1593
|
+
try {
|
|
1594
|
+
if (remoteOptions.deleteTypesFolder) {
|
|
1595
|
+
yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1596
|
+
recursive: true,
|
|
1597
|
+
force: true
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
} catch (err) {
|
|
1601
|
+
if (isDebugMode()) {
|
|
1602
|
+
console.error(err);
|
|
1603
|
+
}
|
|
1576
1604
|
}
|
|
1577
1605
|
console.log(import_ansi_colors2.default.green("Federated types created correctly"));
|
|
1578
1606
|
} catch (error2) {
|
|
@@ -1591,10 +1619,7 @@ var DTSManager = (_a2 = class {
|
|
|
1591
1619
|
return remoteInfo;
|
|
1592
1620
|
}
|
|
1593
1621
|
const url = remoteInfo.url;
|
|
1594
|
-
const res = yield (
|
|
1595
|
-
method: "get",
|
|
1596
|
-
url
|
|
1597
|
-
});
|
|
1622
|
+
const res = yield axiosGet(url);
|
|
1598
1623
|
const manifestJson = res.data;
|
|
1599
1624
|
if (!manifestJson.metaData.types.zip) {
|
|
1600
1625
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
@@ -1643,7 +1668,7 @@ var DTSManager = (_a2 = class {
|
|
|
1643
1668
|
}
|
|
1644
1669
|
try {
|
|
1645
1670
|
const url = apiTypeUrl;
|
|
1646
|
-
const res = yield
|
|
1671
|
+
const res = yield axiosGet(url);
|
|
1647
1672
|
let apiTypeFile = res.data;
|
|
1648
1673
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1649
1674
|
const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
@@ -1700,12 +1725,6 @@ var DTSManager = (_a2 = class {
|
|
|
1700
1725
|
consumeArchiveTypes(options) {
|
|
1701
1726
|
return __async(this, null, function* () {
|
|
1702
1727
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1703
|
-
if (hostOptions.deleteTypesFolder) {
|
|
1704
|
-
yield (0, import_promises.rm)(hostOptions.typesFolder, {
|
|
1705
|
-
recursive: true,
|
|
1706
|
-
force: true
|
|
1707
|
-
}).catch((error2) => fileLog(`Unable to remove types folder, ${error2}`, "consumeArchiveTypes", "error"));
|
|
1708
|
-
}
|
|
1709
1728
|
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1710
1729
|
const remoteInfo = item[1];
|
|
1711
1730
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
@@ -1777,6 +1796,10 @@ var DTSManager = (_a2 = class {
|
|
|
1777
1796
|
}
|
|
1778
1797
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1779
1798
|
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1799
|
+
const consumeTypes2 = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
1800
|
+
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, requiredRemoteInfo);
|
|
1801
|
+
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1802
|
+
}), "consumeTypes");
|
|
1780
1803
|
if (!loadedRemoteInfo) {
|
|
1781
1804
|
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
1782
1805
|
return item.name === remoteName;
|
|
@@ -1786,11 +1809,10 @@ var DTSManager = (_a2 = class {
|
|
|
1786
1809
|
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1787
1810
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1788
1811
|
}
|
|
1789
|
-
yield
|
|
1812
|
+
yield consumeTypes2(this.remoteAliasMap[remoteInfo.alias]);
|
|
1790
1813
|
} else if (updatedRemoteInfo) {
|
|
1791
1814
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1792
|
-
|
|
1793
|
-
yield this.downloadAPITypes(this.updatedRemoteInfos[updatedRemoteInfo.name], destinationPath);
|
|
1815
|
+
yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1794
1816
|
this.consumeAPITypes(hostOptions);
|
|
1795
1817
|
}), "consumeDynamicRemoteTypes");
|
|
1796
1818
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
@@ -1809,7 +1831,7 @@ var DTSManager = (_a2 = class {
|
|
|
1809
1831
|
}
|
|
1810
1832
|
}
|
|
1811
1833
|
} else {
|
|
1812
|
-
yield
|
|
1834
|
+
yield consumeTypes2(loadedRemoteInfo);
|
|
1813
1835
|
}
|
|
1814
1836
|
}
|
|
1815
1837
|
} catch (err) {
|
|
@@ -1820,7 +1842,6 @@ var DTSManager = (_a2 = class {
|
|
|
1820
1842
|
}, __name(_a2, "DTSManager"), _a2);
|
|
1821
1843
|
|
|
1822
1844
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
1823
|
-
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
1824
1845
|
function getDTSManagerConstructor(implementation) {
|
|
1825
1846
|
if (implementation) {
|
|
1826
1847
|
const NewConstructor = require(implementation);
|
|
@@ -1834,6 +1855,25 @@ var validateOptions = /* @__PURE__ */ __name((options) => {
|
|
|
1834
1855
|
throw new Error("moduleFederationConfig is required");
|
|
1835
1856
|
}
|
|
1836
1857
|
}, "validateOptions");
|
|
1858
|
+
function isDebugMode() {
|
|
1859
|
+
return Boolean(process.env["FEDERATION_DEBUG"]) || process.env["NODE_ENV"] === "test";
|
|
1860
|
+
}
|
|
1861
|
+
__name(isDebugMode, "isDebugMode");
|
|
1862
|
+
function axiosGet(url, config) {
|
|
1863
|
+
return __async(this, null, function* () {
|
|
1864
|
+
const httpAgent = new import_http2.default.Agent({
|
|
1865
|
+
family: 4
|
|
1866
|
+
});
|
|
1867
|
+
const httpsAgent = new import_https.default.Agent({
|
|
1868
|
+
family: 4
|
|
1869
|
+
});
|
|
1870
|
+
return import_axios.default.get(url, __spreadValues({
|
|
1871
|
+
httpAgent,
|
|
1872
|
+
httpsAgent
|
|
1873
|
+
}, config));
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
__name(axiosGet, "axiosGet");
|
|
1837
1877
|
|
|
1838
1878
|
// packages/dts-plugin/src/core/lib/generateTypes.ts
|
|
1839
1879
|
function generateTypes(options) {
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
84
84
|
})(APIKind || (APIKind = {}));
|
|
85
85
|
|
|
86
|
-
// node_modules/.pnpm/isomorphic-ws@5.0.0_ws@8.17.
|
|
86
|
+
// node_modules/.pnpm/isomorphic-ws@5.0.0_ws@8.17.1/node_modules/isomorphic-ws/browser.js
|
|
87
87
|
var ws = null;
|
|
88
88
|
if (typeof WebSocket !== "undefined") {
|
|
89
89
|
ws = WebSocket;
|
package/dist/index.js
CHANGED
|
@@ -94,12 +94,17 @@ var import_managers2 = require("@module-federation/managers");
|
|
|
94
94
|
var import_typescript2 = __toESM(require("typescript"));
|
|
95
95
|
|
|
96
96
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
97
|
+
var import_fs2 = __toESM(require("fs"));
|
|
97
98
|
var import_path4 = __toESM(require("path"));
|
|
99
|
+
var import_axios = __toESM(require("axios"));
|
|
100
|
+
var import_http2 = __toESM(require("http"));
|
|
101
|
+
var import_https = __toESM(require("https"));
|
|
102
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
98
103
|
|
|
99
104
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
100
105
|
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
101
106
|
var import_path3 = __toESM(require("path"));
|
|
102
|
-
var
|
|
107
|
+
var import_promises2 = require("fs/promises");
|
|
103
108
|
var import_fs = __toESM(require("fs"));
|
|
104
109
|
var import_sdk4 = require("@module-federation/sdk");
|
|
105
110
|
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
@@ -107,8 +112,8 @@ var import_third_party_dts_extractor2 = require("@module-federation/third-party-
|
|
|
107
112
|
|
|
108
113
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
109
114
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
110
|
-
var import_axios = __toESM(require("axios"));
|
|
111
115
|
var import_path2 = require("path");
|
|
116
|
+
var import_promises = require("fs/promises");
|
|
112
117
|
|
|
113
118
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
114
119
|
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
@@ -136,7 +141,10 @@ var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remote
|
|
|
136
141
|
host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
|
|
137
142
|
originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
|
|
138
143
|
for (const sourceFile of sourceFiles || []) {
|
|
139
|
-
|
|
144
|
+
let sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
|
|
145
|
+
if (sourceEntry === ".") {
|
|
146
|
+
sourceEntry = "index";
|
|
147
|
+
}
|
|
140
148
|
if (sourceEntry) {
|
|
141
149
|
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
142
150
|
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
@@ -1116,9 +1124,19 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1116
1124
|
while (retries++ < hostOptions.maxRetries) {
|
|
1117
1125
|
try {
|
|
1118
1126
|
const url = fileToDownload;
|
|
1119
|
-
const response = yield
|
|
1127
|
+
const response = yield axiosGet(url, {
|
|
1120
1128
|
responseType: "arraybuffer"
|
|
1121
1129
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1130
|
+
try {
|
|
1131
|
+
if (hostOptions.deleteTypesFolder) {
|
|
1132
|
+
yield (0, import_promises.rm)(destinationPath, {
|
|
1133
|
+
recursive: true,
|
|
1134
|
+
force: true
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
} catch (error2) {
|
|
1138
|
+
fileLog(`Unable to remove types folder, ${error2}`, "downloadTypesArchive", "error");
|
|
1139
|
+
}
|
|
1122
1140
|
const zip = new import_adm_zip.default(Buffer.from(response.data));
|
|
1123
1141
|
zip.extractAllTo(destinationPath, true);
|
|
1124
1142
|
return [
|
|
@@ -1165,8 +1183,12 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1165
1183
|
}, "buildApiTypeUrl");
|
|
1166
1184
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1167
1185
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1168
|
-
|
|
1169
|
-
|
|
1186
|
+
let decodedRemote = remote;
|
|
1187
|
+
if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
|
|
1188
|
+
decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
|
|
1189
|
+
}
|
|
1190
|
+
const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
|
|
1191
|
+
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1170
1192
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1171
1193
|
return {
|
|
1172
1194
|
name: parsedInfo.name || remoteAlias,
|
|
@@ -1205,7 +1227,6 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
|
1205
1227
|
}, "retrieveHostConfig");
|
|
1206
1228
|
|
|
1207
1229
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1208
|
-
var import_axios2 = __toESM(require("axios"));
|
|
1209
1230
|
var _a;
|
|
1210
1231
|
var DTSManager = (_a = class {
|
|
1211
1232
|
constructor(options) {
|
|
@@ -1301,11 +1322,17 @@ var DTSManager = (_a = class {
|
|
|
1301
1322
|
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1302
1323
|
import_fs.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1303
1324
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1325
|
+
try {
|
|
1326
|
+
if (remoteOptions.deleteTypesFolder) {
|
|
1327
|
+
yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1328
|
+
recursive: true,
|
|
1329
|
+
force: true
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
} catch (err) {
|
|
1333
|
+
if (isDebugMode()) {
|
|
1334
|
+
console.error(err);
|
|
1335
|
+
}
|
|
1309
1336
|
}
|
|
1310
1337
|
console.log(import_ansi_colors2.default.green("Federated types created correctly"));
|
|
1311
1338
|
} catch (error2) {
|
|
@@ -1324,10 +1351,7 @@ var DTSManager = (_a = class {
|
|
|
1324
1351
|
return remoteInfo;
|
|
1325
1352
|
}
|
|
1326
1353
|
const url = remoteInfo.url;
|
|
1327
|
-
const res = yield (
|
|
1328
|
-
method: "get",
|
|
1329
|
-
url
|
|
1330
|
-
});
|
|
1354
|
+
const res = yield axiosGet(url);
|
|
1331
1355
|
const manifestJson = res.data;
|
|
1332
1356
|
if (!manifestJson.metaData.types.zip) {
|
|
1333
1357
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
@@ -1376,7 +1400,7 @@ var DTSManager = (_a = class {
|
|
|
1376
1400
|
}
|
|
1377
1401
|
try {
|
|
1378
1402
|
const url = apiTypeUrl;
|
|
1379
|
-
const res = yield
|
|
1403
|
+
const res = yield axiosGet(url);
|
|
1380
1404
|
let apiTypeFile = res.data;
|
|
1381
1405
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1382
1406
|
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
@@ -1433,12 +1457,6 @@ var DTSManager = (_a = class {
|
|
|
1433
1457
|
consumeArchiveTypes(options) {
|
|
1434
1458
|
return __async(this, null, function* () {
|
|
1435
1459
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1436
|
-
if (hostOptions.deleteTypesFolder) {
|
|
1437
|
-
yield (0, import_promises.rm)(hostOptions.typesFolder, {
|
|
1438
|
-
recursive: true,
|
|
1439
|
-
force: true
|
|
1440
|
-
}).catch((error2) => fileLog(`Unable to remove types folder, ${error2}`, "consumeArchiveTypes", "error"));
|
|
1441
|
-
}
|
|
1442
1460
|
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1443
1461
|
const remoteInfo = item[1];
|
|
1444
1462
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
@@ -1510,6 +1528,10 @@ var DTSManager = (_a = class {
|
|
|
1510
1528
|
}
|
|
1511
1529
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1512
1530
|
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1531
|
+
const consumeTypes2 = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
1532
|
+
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, requiredRemoteInfo);
|
|
1533
|
+
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1534
|
+
}), "consumeTypes");
|
|
1513
1535
|
if (!loadedRemoteInfo) {
|
|
1514
1536
|
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
1515
1537
|
return item.name === remoteName;
|
|
@@ -1519,11 +1541,10 @@ var DTSManager = (_a = class {
|
|
|
1519
1541
|
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1520
1542
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1521
1543
|
}
|
|
1522
|
-
yield
|
|
1544
|
+
yield consumeTypes2(this.remoteAliasMap[remoteInfo.alias]);
|
|
1523
1545
|
} else if (updatedRemoteInfo) {
|
|
1524
1546
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1525
|
-
|
|
1526
|
-
yield this.downloadAPITypes(this.updatedRemoteInfos[updatedRemoteInfo.name], destinationPath);
|
|
1547
|
+
yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1527
1548
|
this.consumeAPITypes(hostOptions);
|
|
1528
1549
|
}), "consumeDynamicRemoteTypes");
|
|
1529
1550
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
@@ -1542,7 +1563,7 @@ var DTSManager = (_a = class {
|
|
|
1542
1563
|
}
|
|
1543
1564
|
}
|
|
1544
1565
|
} else {
|
|
1545
|
-
yield
|
|
1566
|
+
yield consumeTypes2(loadedRemoteInfo);
|
|
1546
1567
|
}
|
|
1547
1568
|
}
|
|
1548
1569
|
} catch (err) {
|
|
@@ -1553,8 +1574,6 @@ var DTSManager = (_a = class {
|
|
|
1553
1574
|
}, __name(_a, "DTSManager"), _a);
|
|
1554
1575
|
|
|
1555
1576
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
1556
|
-
var import_fs2 = __toESM(require("fs"));
|
|
1557
|
-
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
1558
1577
|
function getDTSManagerConstructor(implementation) {
|
|
1559
1578
|
if (implementation) {
|
|
1560
1579
|
const NewConstructor = require(implementation);
|
|
@@ -1603,6 +1622,10 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1603
1622
|
}
|
|
1604
1623
|
}
|
|
1605
1624
|
__name(retrieveTypesAssetsInfo, "retrieveTypesAssetsInfo");
|
|
1625
|
+
function isDebugMode() {
|
|
1626
|
+
return Boolean(process.env["FEDERATION_DEBUG"]) || process.env["NODE_ENV"] === "test";
|
|
1627
|
+
}
|
|
1628
|
+
__name(isDebugMode, "isDebugMode");
|
|
1606
1629
|
var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) => {
|
|
1607
1630
|
if (dtsOptions === false) {
|
|
1608
1631
|
return false;
|
|
@@ -1622,6 +1645,21 @@ var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) =
|
|
|
1622
1645
|
return false;
|
|
1623
1646
|
}
|
|
1624
1647
|
}, "isTSProject");
|
|
1648
|
+
function axiosGet(url, config) {
|
|
1649
|
+
return __async(this, null, function* () {
|
|
1650
|
+
const httpAgent = new import_http2.default.Agent({
|
|
1651
|
+
family: 4
|
|
1652
|
+
});
|
|
1653
|
+
const httpsAgent = new import_https.default.Agent({
|
|
1654
|
+
family: 4
|
|
1655
|
+
});
|
|
1656
|
+
return import_axios.default.get(url, __spreadValues({
|
|
1657
|
+
httpAgent,
|
|
1658
|
+
httpsAgent
|
|
1659
|
+
}, config));
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
__name(axiosGet, "axiosGet");
|
|
1625
1663
|
|
|
1626
1664
|
// packages/dts-plugin/src/core/configurations/remotePlugin.ts
|
|
1627
1665
|
var defaultOptions2 = {
|
|
@@ -1973,8 +2011,28 @@ var _DtsWorker = class _DtsWorker {
|
|
|
1973
2011
|
}
|
|
1974
2012
|
}
|
|
1975
2013
|
get controlledPromise() {
|
|
2014
|
+
const ensureChildProcessExit = /* @__PURE__ */ __name(() => {
|
|
2015
|
+
var _a4;
|
|
2016
|
+
try {
|
|
2017
|
+
const pid = (_a4 = this.rpcWorker.process) == null ? void 0 : _a4.pid;
|
|
2018
|
+
const rootPid = process.pid;
|
|
2019
|
+
if (pid && rootPid !== pid) {
|
|
2020
|
+
process.kill(pid, 0);
|
|
2021
|
+
}
|
|
2022
|
+
} catch (error2) {
|
|
2023
|
+
if (isDebugMode()) {
|
|
2024
|
+
console.error(error2);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
}, "ensureChildProcessExit");
|
|
1976
2028
|
return Promise.resolve(this._res).then(() => {
|
|
1977
2029
|
this.exit();
|
|
2030
|
+
ensureChildProcessExit();
|
|
2031
|
+
}).catch((err) => {
|
|
2032
|
+
if (isDebugMode()) {
|
|
2033
|
+
console.error(err);
|
|
2034
|
+
}
|
|
2035
|
+
ensureChildProcessExit();
|
|
1978
2036
|
});
|
|
1979
2037
|
}
|
|
1980
2038
|
exit() {
|
|
@@ -2197,7 +2255,7 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2197
2255
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2198
2256
|
context: compiler.context,
|
|
2199
2257
|
moduleFederationConfig: this._options,
|
|
2200
|
-
typesFolder: "@mf-types",
|
|
2258
|
+
typesFolder: normalizedConsumeTypes.typesFolder || "@mf-types",
|
|
2201
2259
|
abortOnError: false
|
|
2202
2260
|
}, normalizedConsumeTypes);
|
|
2203
2261
|
const extraOptions = normalizedDtsOptions ? normalizedDtsOptions.extraOptions || {} : {};
|