@module-federation/dts-plugin 0.9.0 → 0.10.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 +27 -0
- package/dist/{DtsWorker-484d9f4a.d.ts → DtsWorker-bfe21fe7.d.ts} +2 -2
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +85 -30
- package/dist/esm/{chunk-UK7YFESF.js → chunk-IPO3NMOQ.js} +1 -1
- package/dist/esm/{chunk-XXMD5NAZ.js → chunk-TKO3UU5B.js} +85 -30
- package/dist/esm/core.js +2 -2
- package/dist/esm/fork-dev-worker.js +2 -2
- package/dist/esm/fork-generate-dts.js +1 -1
- package/dist/esm/index.js +56 -30
- package/dist/fork-dev-worker.js +85 -30
- package/dist/fork-generate-dts.d.mts +1 -1
- package/dist/fork-generate-dts.d.ts +1 -1
- package/dist/fork-generate-dts.js +85 -30
- package/dist/index.js +149 -68
- package/dist/package.json +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -88,12 +88,12 @@ __export(src_exports, {
|
|
|
88
88
|
module.exports = __toCommonJS(src_exports);
|
|
89
89
|
|
|
90
90
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
91
|
-
var
|
|
91
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
92
92
|
var import_path9 = __toESM(require("path"));
|
|
93
93
|
|
|
94
94
|
// packages/dts-plugin/src/dev-worker/createDevWorker.ts
|
|
95
95
|
var path5 = __toESM(require("path"));
|
|
96
|
-
var
|
|
96
|
+
var fse2 = __toESM(require("fs-extra"));
|
|
97
97
|
|
|
98
98
|
// packages/dts-plugin/src/dev-worker/DevWorker.ts
|
|
99
99
|
var import_path7 = __toESM(require("path"));
|
|
@@ -117,6 +117,7 @@ var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
|
117
117
|
var import_path3 = __toESM(require("path"));
|
|
118
118
|
var import_promises3 = require("fs/promises");
|
|
119
119
|
var import_fs = __toESM(require("fs"));
|
|
120
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
120
121
|
var import_sdk5 = require("@module-federation/sdk");
|
|
121
122
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
122
123
|
|
|
@@ -1179,7 +1180,8 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1179
1180
|
try {
|
|
1180
1181
|
const url = fileToDownload;
|
|
1181
1182
|
const response = yield axiosGet(url, {
|
|
1182
|
-
responseType: "arraybuffer"
|
|
1183
|
+
responseType: "arraybuffer",
|
|
1184
|
+
timeout: hostOptions.timeout
|
|
1183
1185
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1184
1186
|
if (typeof ((_a3 = response.headers) == null ? void 0 : _a3["content-type"]) === "string" && response.headers["content-type"].includes("text/html")) {
|
|
1185
1187
|
throw new Error(`${url} receives invalid content-type: ${response.headers["content-type"]}`);
|
|
@@ -1226,7 +1228,9 @@ var defaultOptions = {
|
|
|
1226
1228
|
context: process.cwd(),
|
|
1227
1229
|
abortOnError: true,
|
|
1228
1230
|
consumeAPITypes: false,
|
|
1229
|
-
runtimePkgs: []
|
|
1231
|
+
runtimePkgs: [],
|
|
1232
|
+
remoteTypeUrls: {},
|
|
1233
|
+
timeout: 6e4
|
|
1230
1234
|
};
|
|
1231
1235
|
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1232
1236
|
const remoteUrl = new URL(url, "file:");
|
|
@@ -1242,18 +1246,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1242
1246
|
}, "buildApiTypeUrl");
|
|
1243
1247
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1244
1248
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1249
|
+
const { remoteTypeUrls } = hostOptions;
|
|
1245
1250
|
let decodedRemote = remote;
|
|
1246
1251
|
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1247
1252
|
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1248
1253
|
}
|
|
1249
1254
|
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1250
1255
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1251
|
-
|
|
1256
|
+
let zipUrl = "";
|
|
1257
|
+
let apiTypeUrl = "";
|
|
1258
|
+
const name = parsedInfo.name || remoteAlias;
|
|
1259
|
+
if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
|
|
1260
|
+
zipUrl = remoteTypeUrls[name].zip;
|
|
1261
|
+
apiTypeUrl = remoteTypeUrls[name].api;
|
|
1262
|
+
}
|
|
1263
|
+
if (!zipUrl && url) {
|
|
1264
|
+
zipUrl = buildZipUrl(hostOptions, url);
|
|
1265
|
+
}
|
|
1266
|
+
if (!apiTypeUrl && zipUrl) {
|
|
1267
|
+
apiTypeUrl = buildApiTypeUrl(zipUrl);
|
|
1268
|
+
}
|
|
1252
1269
|
return {
|
|
1253
|
-
name
|
|
1270
|
+
name,
|
|
1254
1271
|
url,
|
|
1255
1272
|
zipUrl,
|
|
1256
|
-
apiTypeUrl
|
|
1273
|
+
apiTypeUrl,
|
|
1257
1274
|
alias: remoteAlias
|
|
1258
1275
|
};
|
|
1259
1276
|
}, "retrieveRemoteInfo");
|
|
@@ -1329,6 +1346,7 @@ var DTSManager = (_a = class {
|
|
|
1329
1346
|
}
|
|
1330
1347
|
extractRemoteTypes(options) {
|
|
1331
1348
|
return __async(this, null, function* () {
|
|
1349
|
+
var _a3;
|
|
1332
1350
|
const { remoteOptions, tsConfig } = options;
|
|
1333
1351
|
if (!remoteOptions.extractRemoteTypes) {
|
|
1334
1352
|
return;
|
|
@@ -1343,20 +1361,29 @@ var DTSManager = (_a = class {
|
|
|
1343
1361
|
}
|
|
1344
1362
|
}
|
|
1345
1363
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1346
|
-
if (hasRemotes) {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1364
|
+
if (hasRemotes && this.options.host) {
|
|
1365
|
+
try {
|
|
1366
|
+
const { hostOptions } = retrieveHostConfig(this.options.host);
|
|
1367
|
+
const remoteTypesFolder = import_path3.default.resolve(hostOptions.context, hostOptions.typesFolder);
|
|
1368
|
+
const targetDir = import_path3.default.join(mfTypesPath, "node_modules");
|
|
1369
|
+
if (import_fs.default.existsSync(remoteTypesFolder)) {
|
|
1370
|
+
const targetFolder = import_path3.default.resolve(remoteOptions.context, targetDir);
|
|
1371
|
+
yield import_fs_extra3.default.ensureDir(targetFolder);
|
|
1372
|
+
yield import_fs_extra3.default.copy(remoteTypesFolder, targetFolder, {
|
|
1373
|
+
overwrite: true
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
} catch (err) {
|
|
1377
|
+
if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1378
|
+
fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
|
|
1379
|
+
} else {
|
|
1380
|
+
throw err;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1357
1383
|
}
|
|
1358
1384
|
});
|
|
1359
1385
|
}
|
|
1386
|
+
// it must execute after consumeTypes
|
|
1360
1387
|
generateTypes() {
|
|
1361
1388
|
return __async(this, null, function* () {
|
|
1362
1389
|
var _a3;
|
|
@@ -1369,6 +1396,18 @@ var DTSManager = (_a = class {
|
|
|
1369
1396
|
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1370
1397
|
return;
|
|
1371
1398
|
}
|
|
1399
|
+
if (tsConfig.compilerOptions.tsBuildInfoFile) {
|
|
1400
|
+
try {
|
|
1401
|
+
const tsBuildInfoFile = import_path3.default.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
|
|
1402
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1403
|
+
if (!import_fs.default.existsSync(mfTypesPath)) {
|
|
1404
|
+
import_fs.default.rmSync(tsBuildInfoFile, {
|
|
1405
|
+
force: true
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
} catch (e) {
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1372
1411
|
yield this.extractRemoteTypes({
|
|
1373
1412
|
remoteOptions,
|
|
1374
1413
|
tsConfig,
|
|
@@ -1398,7 +1437,7 @@ var DTSManager = (_a = class {
|
|
|
1398
1437
|
} catch (error2) {
|
|
1399
1438
|
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1400
1439
|
if (this.options.displayErrorInTerminal) {
|
|
1401
|
-
logger.error(`Unable to compile federated types${error2}`);
|
|
1440
|
+
logger.error(`Unable to compile federated types ${error2}`);
|
|
1402
1441
|
}
|
|
1403
1442
|
} else {
|
|
1404
1443
|
throw error2;
|
|
@@ -1406,14 +1445,19 @@ var DTSManager = (_a = class {
|
|
|
1406
1445
|
}
|
|
1407
1446
|
});
|
|
1408
1447
|
}
|
|
1409
|
-
requestRemoteManifest(remoteInfo) {
|
|
1448
|
+
requestRemoteManifest(remoteInfo, hostOptions) {
|
|
1410
1449
|
return __async(this, null, function* () {
|
|
1411
1450
|
try {
|
|
1412
1451
|
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1413
1452
|
return remoteInfo;
|
|
1414
1453
|
}
|
|
1454
|
+
if (remoteInfo.zipUrl) {
|
|
1455
|
+
return remoteInfo;
|
|
1456
|
+
}
|
|
1415
1457
|
const url = remoteInfo.url;
|
|
1416
|
-
const res = yield axiosGet(url
|
|
1458
|
+
const res = yield axiosGet(url, {
|
|
1459
|
+
timeout: hostOptions.timeout
|
|
1460
|
+
});
|
|
1417
1461
|
const manifestJson = res.data;
|
|
1418
1462
|
if (!manifestJson.metaData.types.zip) {
|
|
1419
1463
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
@@ -1464,7 +1508,7 @@ var DTSManager = (_a = class {
|
|
|
1464
1508
|
]);
|
|
1465
1509
|
});
|
|
1466
1510
|
}
|
|
1467
|
-
downloadAPITypes(remoteInfo, destinationPath) {
|
|
1511
|
+
downloadAPITypes(remoteInfo, destinationPath, hostOptions) {
|
|
1468
1512
|
return __async(this, null, function* () {
|
|
1469
1513
|
const { apiTypeUrl } = remoteInfo;
|
|
1470
1514
|
if (!apiTypeUrl) {
|
|
@@ -1472,13 +1516,17 @@ var DTSManager = (_a = class {
|
|
|
1472
1516
|
}
|
|
1473
1517
|
try {
|
|
1474
1518
|
const url = apiTypeUrl;
|
|
1475
|
-
const res = yield axiosGet(url
|
|
1519
|
+
const res = yield axiosGet(url, {
|
|
1520
|
+
timeout: hostOptions.timeout
|
|
1521
|
+
});
|
|
1476
1522
|
let apiTypeFile = res.data;
|
|
1477
1523
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1478
1524
|
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1479
1525
|
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1526
|
+
const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
|
|
1480
1527
|
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1481
1528
|
fileLog(`success`, "downloadAPITypes", "info");
|
|
1529
|
+
return existed;
|
|
1482
1530
|
} catch (err) {
|
|
1483
1531
|
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
1484
1532
|
}
|
|
@@ -1542,7 +1590,7 @@ var DTSManager = (_a = class {
|
|
|
1542
1590
|
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1543
1591
|
const remoteInfo = item[1];
|
|
1544
1592
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1545
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1593
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1546
1594
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1547
1595
|
}
|
|
1548
1596
|
return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
@@ -1577,7 +1625,7 @@ var DTSManager = (_a = class {
|
|
|
1577
1625
|
if (!remoteInfo) {
|
|
1578
1626
|
return;
|
|
1579
1627
|
}
|
|
1580
|
-
yield this.downloadAPITypes(remoteInfo, destinationPath);
|
|
1628
|
+
yield this.downloadAPITypes(remoteInfo, destinationPath, hostOptions);
|
|
1581
1629
|
})));
|
|
1582
1630
|
this.consumeAPITypes(hostOptions);
|
|
1583
1631
|
}
|
|
@@ -1620,7 +1668,10 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1620
1668
|
// use remoteTarPath first
|
|
1621
1669
|
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
1622
1670
|
}));
|
|
1623
|
-
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1671
|
+
const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath, hostOptions);
|
|
1672
|
+
if (addNew) {
|
|
1673
|
+
this.consumeAPITypes(hostOptions);
|
|
1674
|
+
}
|
|
1624
1675
|
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
1625
1676
|
}), "consumeTypes");
|
|
1626
1677
|
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
@@ -1631,14 +1682,13 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1631
1682
|
fileLog(`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`, "updateTypes", "info");
|
|
1632
1683
|
if (remoteInfo) {
|
|
1633
1684
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1634
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1685
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1635
1686
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1636
1687
|
}
|
|
1637
1688
|
yield consumeTypes2(this.remoteAliasMap[remoteInfo.alias]);
|
|
1638
1689
|
} else if (updatedRemoteInfo) {
|
|
1639
1690
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1640
1691
|
yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1641
|
-
this.consumeAPITypes(hostOptions);
|
|
1642
1692
|
}), "consumeDynamicRemoteTypes");
|
|
1643
1693
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1644
1694
|
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
@@ -1647,7 +1697,7 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1647
1697
|
remote: updatedRemoteInfo.url
|
|
1648
1698
|
});
|
|
1649
1699
|
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
1650
|
-
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
|
|
1700
|
+
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo, hostOptions);
|
|
1651
1701
|
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "updateTypes", "info");
|
|
1652
1702
|
yield consumeDynamicRemoteTypes();
|
|
1653
1703
|
}
|
|
@@ -1756,10 +1806,13 @@ function cloneDeepOptions(options) {
|
|
|
1756
1806
|
"manifest",
|
|
1757
1807
|
"async"
|
|
1758
1808
|
];
|
|
1759
|
-
return (0, import_lodash.default)(options, (
|
|
1809
|
+
return (0, import_lodash.default)(options, (value, key) => {
|
|
1760
1810
|
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1761
1811
|
return false;
|
|
1762
1812
|
}
|
|
1813
|
+
if (typeof value === "function") {
|
|
1814
|
+
return false;
|
|
1815
|
+
}
|
|
1763
1816
|
});
|
|
1764
1817
|
}
|
|
1765
1818
|
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
@@ -1775,12 +1828,14 @@ function axiosGet(url, config) {
|
|
|
1775
1828
|
const httpsAgent = new import_https.default.Agent({
|
|
1776
1829
|
family: 4
|
|
1777
1830
|
});
|
|
1778
|
-
return import_axios.default.get(url, __spreadValues(__spreadValues({
|
|
1831
|
+
return import_axios.default.get(url, __spreadProps(__spreadValues(__spreadValues({
|
|
1779
1832
|
httpAgent,
|
|
1780
1833
|
httpsAgent
|
|
1781
1834
|
}, {
|
|
1782
1835
|
headers: getEnvHeaders()
|
|
1783
|
-
}), config)
|
|
1836
|
+
}), config), {
|
|
1837
|
+
timeout: (config == null ? void 0 : config.timeout) || 6e4
|
|
1838
|
+
}));
|
|
1784
1839
|
});
|
|
1785
1840
|
}
|
|
1786
1841
|
__name(axiosGet, "axiosGet");
|
|
@@ -2287,7 +2342,7 @@ function removeLogFile() {
|
|
|
2287
2342
|
return __async(this, null, function* () {
|
|
2288
2343
|
try {
|
|
2289
2344
|
const logDir = path5.resolve(process.cwd(), ".mf/typesGenerate.log");
|
|
2290
|
-
yield
|
|
2345
|
+
yield fse2.remove(logDir);
|
|
2291
2346
|
} catch (err) {
|
|
2292
2347
|
console.error("removeLogFile error", "forkDevWorker", err);
|
|
2293
2348
|
}
|
|
@@ -2331,27 +2386,29 @@ var PROCESS_EXIT_CODE;
|
|
|
2331
2386
|
function ensureTempDir(filePath) {
|
|
2332
2387
|
try {
|
|
2333
2388
|
const dir = import_path9.default.dirname(filePath);
|
|
2334
|
-
|
|
2389
|
+
import_fs_extra4.default.ensureDirSync(dir);
|
|
2335
2390
|
} catch (_err) {
|
|
2336
2391
|
}
|
|
2337
2392
|
}
|
|
2338
2393
|
__name(ensureTempDir, "ensureTempDir");
|
|
2339
2394
|
var _DevPlugin = class _DevPlugin {
|
|
2340
|
-
constructor(options, dtsOptions,
|
|
2395
|
+
constructor(options, dtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise) {
|
|
2341
2396
|
__publicField(this, "name", "MFDevPlugin");
|
|
2342
2397
|
__publicField(this, "_options");
|
|
2343
2398
|
__publicField(this, "_devWorker");
|
|
2344
2399
|
__publicField(this, "dtsOptions");
|
|
2345
|
-
__publicField(this, "
|
|
2400
|
+
__publicField(this, "generateTypesPromise");
|
|
2401
|
+
__publicField(this, "fetchRemoteTypeUrlsPromise");
|
|
2346
2402
|
this._options = options;
|
|
2347
|
-
this.
|
|
2403
|
+
this.generateTypesPromise = generateTypesPromise;
|
|
2348
2404
|
this.dtsOptions = dtsOptions;
|
|
2405
|
+
this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
|
|
2349
2406
|
}
|
|
2350
2407
|
static ensureLiveReloadEntry(options, filePath) {
|
|
2351
2408
|
ensureTempDir(filePath);
|
|
2352
|
-
const liveReloadEntry =
|
|
2409
|
+
const liveReloadEntry = import_fs_extra4.default.readFileSync(import_path9.default.join(__dirname, "./iife/launch-web-client.js")).toString("utf-8");
|
|
2353
2410
|
const liveReloadEntryWithOptions = liveReloadEntry.replace(WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
|
|
2354
|
-
|
|
2411
|
+
import_fs_extra4.default.writeFileSync(filePath, liveReloadEntryWithOptions);
|
|
2355
2412
|
}
|
|
2356
2413
|
_stopWhenSIGTERMOrSIGINT() {
|
|
2357
2414
|
process.on("SIGTERM", () => {
|
|
@@ -2463,11 +2520,16 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2463
2520
|
if (remote && !(remote == null ? void 0 : remote.tsConfigPath) && typeof normalizedDtsOptions === "object" && normalizedDtsOptions.tsConfigPath) {
|
|
2464
2521
|
remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
|
|
2465
2522
|
}
|
|
2466
|
-
|
|
2523
|
+
Promise.all([
|
|
2524
|
+
this.generateTypesPromise,
|
|
2525
|
+
this.fetchRemoteTypeUrlsPromise
|
|
2526
|
+
]).then(([_, remoteTypeUrls]) => {
|
|
2467
2527
|
this._devWorker = createDevWorker({
|
|
2468
2528
|
name,
|
|
2469
2529
|
remote,
|
|
2470
|
-
host,
|
|
2530
|
+
host: __spreadProps(__spreadValues({}, host), {
|
|
2531
|
+
remoteTypeUrls
|
|
2532
|
+
}),
|
|
2471
2533
|
extraOptions,
|
|
2472
2534
|
disableLiveReload: normalizedDev.disableHotTypesReload,
|
|
2473
2535
|
disableHotTypesReload: normalizedDev.disableHotTypesReload
|
|
@@ -2482,30 +2544,32 @@ __name(_DevPlugin, "DevPlugin");
|
|
|
2482
2544
|
var DevPlugin = _DevPlugin;
|
|
2483
2545
|
|
|
2484
2546
|
// packages/dts-plugin/src/plugins/DtsPlugin.ts
|
|
2485
|
-
var
|
|
2547
|
+
var import_sdk11 = require("@module-federation/sdk");
|
|
2486
2548
|
|
|
2487
2549
|
// packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
|
|
2488
2550
|
var import_sdk8 = require("@module-federation/sdk");
|
|
2551
|
+
var import_sdk9 = require("@module-federation/sdk");
|
|
2489
2552
|
var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
2490
|
-
constructor(pluginOptions, dtsOptions, defaultOptions3,
|
|
2553
|
+
constructor(pluginOptions, dtsOptions, defaultOptions3, fetchRemoteTypeUrlsResolve) {
|
|
2491
2554
|
__publicField(this, "pluginOptions");
|
|
2492
2555
|
__publicField(this, "dtsOptions");
|
|
2493
2556
|
__publicField(this, "defaultOptions");
|
|
2494
2557
|
__publicField(this, "callback");
|
|
2558
|
+
__publicField(this, "fetchRemoteTypeUrlsResolve");
|
|
2495
2559
|
this.pluginOptions = pluginOptions;
|
|
2496
2560
|
this.dtsOptions = dtsOptions;
|
|
2497
2561
|
this.defaultOptions = defaultOptions3;
|
|
2498
|
-
this.
|
|
2562
|
+
this.fetchRemoteTypeUrlsResolve = fetchRemoteTypeUrlsResolve;
|
|
2499
2563
|
}
|
|
2500
2564
|
apply(compiler) {
|
|
2501
|
-
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions,
|
|
2565
|
+
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
|
|
2502
2566
|
if (isPrd()) {
|
|
2503
|
-
|
|
2567
|
+
fetchRemoteTypeUrlsResolve(void 0);
|
|
2504
2568
|
return;
|
|
2505
2569
|
}
|
|
2506
|
-
const normalizedConsumeTypes = (0,
|
|
2570
|
+
const normalizedConsumeTypes = (0, import_sdk9.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
2507
2571
|
if (!normalizedConsumeTypes) {
|
|
2508
|
-
|
|
2572
|
+
fetchRemoteTypeUrlsResolve(void 0);
|
|
2509
2573
|
return;
|
|
2510
2574
|
}
|
|
2511
2575
|
const finalOptions = {
|
|
@@ -2518,10 +2582,18 @@ var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
|
2518
2582
|
displayErrorInTerminal: dtsOptions.displayErrorInTerminal
|
|
2519
2583
|
};
|
|
2520
2584
|
validateOptions(finalOptions.host);
|
|
2521
|
-
const
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2585
|
+
const fetchRemoteTypeUrlsPromise = typeof normalizedConsumeTypes.remoteTypeUrls === "function" ? normalizedConsumeTypes.remoteTypeUrls() : Promise.resolve(normalizedConsumeTypes.remoteTypeUrls);
|
|
2586
|
+
import_sdk8.logger.debug("start fetching remote types...");
|
|
2587
|
+
const promise = fetchRemoteTypeUrlsPromise.then((remoteTypeUrls) => {
|
|
2588
|
+
consumeTypes(__spreadProps(__spreadValues({}, finalOptions), {
|
|
2589
|
+
host: __spreadProps(__spreadValues({}, finalOptions.host), {
|
|
2590
|
+
remoteTypeUrls
|
|
2591
|
+
})
|
|
2592
|
+
})).then(() => {
|
|
2593
|
+
fetchRemoteTypeUrlsResolve(remoteTypeUrls);
|
|
2594
|
+
}).catch(() => {
|
|
2595
|
+
fetchRemoteTypeUrlsResolve(remoteTypeUrls);
|
|
2596
|
+
});
|
|
2525
2597
|
});
|
|
2526
2598
|
compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
|
|
2527
2599
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -2532,6 +2604,7 @@ var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
|
2532
2604
|
)
|
|
2533
2605
|
}, () => __async(this, null, function* () {
|
|
2534
2606
|
yield promise;
|
|
2607
|
+
import_sdk8.logger.debug("fetch remote types success!");
|
|
2535
2608
|
}));
|
|
2536
2609
|
});
|
|
2537
2610
|
}
|
|
@@ -2542,27 +2615,28 @@ var ConsumeTypesPlugin = _ConsumeTypesPlugin;
|
|
|
2542
2615
|
// packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
|
|
2543
2616
|
var import_fs4 = __toESM(require("fs"));
|
|
2544
2617
|
var import_path10 = __toESM(require("path"));
|
|
2545
|
-
var
|
|
2618
|
+
var import_sdk10 = require("@module-federation/sdk");
|
|
2546
2619
|
var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
2547
|
-
constructor(pluginOptions, dtsOptions, defaultOptions3,
|
|
2620
|
+
constructor(pluginOptions, dtsOptions, defaultOptions3, fetchRemoteTypeUrlsPromise, callback) {
|
|
2548
2621
|
__publicField(this, "pluginOptions");
|
|
2549
2622
|
__publicField(this, "dtsOptions");
|
|
2550
2623
|
__publicField(this, "defaultOptions");
|
|
2551
|
-
__publicField(this, "
|
|
2624
|
+
__publicField(this, "fetchRemoteTypeUrlsPromise");
|
|
2552
2625
|
__publicField(this, "callback");
|
|
2553
2626
|
this.pluginOptions = pluginOptions;
|
|
2554
2627
|
this.dtsOptions = dtsOptions;
|
|
2555
2628
|
this.defaultOptions = defaultOptions3;
|
|
2556
|
-
this.
|
|
2629
|
+
this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
|
|
2557
2630
|
this.callback = callback;
|
|
2558
2631
|
}
|
|
2559
2632
|
apply(compiler) {
|
|
2560
|
-
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions,
|
|
2561
|
-
const normalizedGenerateTypes = (0,
|
|
2633
|
+
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions, fetchRemoteTypeUrlsPromise, callback } = this;
|
|
2634
|
+
const normalizedGenerateTypes = (0, import_sdk10.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
|
|
2562
2635
|
if (!normalizedGenerateTypes) {
|
|
2563
2636
|
callback();
|
|
2564
2637
|
return;
|
|
2565
2638
|
}
|
|
2639
|
+
const normalizedConsumeTypes = (0, import_sdk10.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
2566
2640
|
const finalOptions = {
|
|
2567
2641
|
remote: __spreadValues({
|
|
2568
2642
|
implementation: dtsOptions.implementation,
|
|
@@ -2570,6 +2644,10 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2570
2644
|
outputDir: getCompilerOutputDir(compiler),
|
|
2571
2645
|
moduleFederationConfig: pluginOptions
|
|
2572
2646
|
}, normalizedGenerateTypes),
|
|
2647
|
+
host: normalizedConsumeTypes === false ? void 0 : __spreadValues({
|
|
2648
|
+
context: compiler.context,
|
|
2649
|
+
moduleFederationConfig: pluginOptions
|
|
2650
|
+
}, normalizedGenerateTypes),
|
|
2573
2651
|
extraOptions: dtsOptions.extraOptions || {},
|
|
2574
2652
|
displayErrorInTerminal: dtsOptions.displayErrorInTerminal
|
|
2575
2653
|
};
|
|
@@ -2598,7 +2676,9 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2598
2676
|
callback();
|
|
2599
2677
|
return;
|
|
2600
2678
|
}
|
|
2679
|
+
import_sdk10.logger.debug("start generating types...");
|
|
2601
2680
|
yield generateTypesFn(finalOptions);
|
|
2681
|
+
import_sdk10.logger.debug("generate types success!");
|
|
2602
2682
|
const config = finalOptions.remote.moduleFederationConfig;
|
|
2603
2683
|
let zipPrefix = "";
|
|
2604
2684
|
if (typeof config.manifest === "object" && config.manifest.filePath) {
|
|
@@ -2667,6 +2747,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2667
2747
|
if (finalOptions.displayErrorInTerminal) {
|
|
2668
2748
|
console.error("Error in mf:generateTypes processAssets hook:", err);
|
|
2669
2749
|
}
|
|
2750
|
+
import_sdk10.logger.debug("generate types fail!");
|
|
2670
2751
|
}
|
|
2671
2752
|
}), "emitTypesFiles");
|
|
2672
2753
|
compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
|
|
@@ -2677,7 +2758,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2677
2758
|
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
2678
2759
|
)
|
|
2679
2760
|
}, () => __async(this, null, function* () {
|
|
2680
|
-
yield
|
|
2761
|
+
yield fetchRemoteTypeUrlsPromise;
|
|
2681
2762
|
const emitTypesFilesPromise = emitTypesFiles(compilation);
|
|
2682
2763
|
if (isProd) {
|
|
2683
2764
|
yield emitTypesFilesPromise;
|
|
@@ -2701,14 +2782,14 @@ var _DtsPlugin = class _DtsPlugin {
|
|
|
2701
2782
|
generateAPITypes: true,
|
|
2702
2783
|
compileInChildProcess: true,
|
|
2703
2784
|
abortOnError: false,
|
|
2704
|
-
extractThirdParty:
|
|
2705
|
-
extractRemoteTypes:
|
|
2785
|
+
extractThirdParty: false,
|
|
2786
|
+
extractRemoteTypes: false
|
|
2706
2787
|
};
|
|
2707
2788
|
const defaultConsumeTypes = {
|
|
2708
2789
|
abortOnError: false,
|
|
2709
2790
|
consumeAPITypes: true
|
|
2710
2791
|
};
|
|
2711
|
-
const normalizedDtsOptions = (0,
|
|
2792
|
+
const normalizedDtsOptions = (0, import_sdk11.normalizeOptions)(isTSProject(options.dts, compiler.context), {
|
|
2712
2793
|
generateTypes: defaultGenerateTypes,
|
|
2713
2794
|
consumeTypes: defaultConsumeTypes,
|
|
2714
2795
|
extraOptions: {},
|
|
@@ -2717,17 +2798,17 @@ var _DtsPlugin = class _DtsPlugin {
|
|
|
2717
2798
|
if (typeof normalizedDtsOptions !== "object") {
|
|
2718
2799
|
return;
|
|
2719
2800
|
}
|
|
2720
|
-
let
|
|
2721
|
-
const
|
|
2722
|
-
|
|
2801
|
+
let fetchRemoteTypeUrlsResolve;
|
|
2802
|
+
const fetchRemoteTypeUrlsPromise = new Promise((resolve5) => {
|
|
2803
|
+
fetchRemoteTypeUrlsResolve = resolve5;
|
|
2723
2804
|
});
|
|
2724
2805
|
let generateTypesPromiseResolve;
|
|
2725
2806
|
const generateTypesPromise = new Promise((resolve5) => {
|
|
2726
2807
|
generateTypesPromiseResolve = resolve5;
|
|
2727
2808
|
});
|
|
2728
|
-
new DevPlugin(options, normalizedDtsOptions, generateTypesPromise).apply(compiler);
|
|
2729
|
-
new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes,
|
|
2730
|
-
new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes,
|
|
2809
|
+
new DevPlugin(options, normalizedDtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise).apply(compiler);
|
|
2810
|
+
new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes, fetchRemoteTypeUrlsPromise, generateTypesPromiseResolve).apply(compiler);
|
|
2811
|
+
new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes, fetchRemoteTypeUrlsResolve).apply(compiler);
|
|
2731
2812
|
}
|
|
2732
2813
|
};
|
|
2733
2814
|
__name(_DtsPlugin, "DtsPlugin");
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/dts-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"log4js": "6.9.1",
|
|
61
61
|
"node-schedule": "2.1.1",
|
|
62
62
|
"ws": "8.18.0",
|
|
63
|
-
"@module-federation/sdk": "0.
|
|
64
|
-
"@module-federation/managers": "0.
|
|
65
|
-
"@module-federation/third-party-dts-extractor": "0.
|
|
66
|
-
"@module-federation/error-codes": "0.
|
|
63
|
+
"@module-federation/sdk": "0.10.0",
|
|
64
|
+
"@module-federation/managers": "0.10.0",
|
|
65
|
+
"@module-federation/third-party-dts-extractor": "0.10.0",
|
|
66
|
+
"@module-federation/error-codes": "0.10.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/ws": "8.5.12",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@vue/tsconfig": "^0.5.1",
|
|
74
74
|
"vue-tsc": "^2.0.26",
|
|
75
75
|
"rimraf": "~3.0.2",
|
|
76
|
-
"@module-federation/runtime": "0.
|
|
76
|
+
"@module-federation/runtime": "0.10.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"typescript": "^4.9.0 || ^5.0.0",
|