@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @module-federation/dts-plugin
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 22fcccd: perf(dts-plugin): add fetch timeout and add log
|
|
8
|
+
- Updated dependencies [0f71cbc]
|
|
9
|
+
- Updated dependencies [22fcccd]
|
|
10
|
+
- @module-federation/sdk@0.10.0
|
|
11
|
+
- @module-federation/managers@0.10.0
|
|
12
|
+
- @module-federation/third-party-dts-extractor@0.10.0
|
|
13
|
+
- @module-federation/error-codes@0.10.0
|
|
14
|
+
|
|
15
|
+
## 0.9.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 35d925b: feat(dts-plugin): support remoteTypeUrls option which allow user to specify the remote types url
|
|
20
|
+
- 35d925b: fix(dts-plugin): support parse @scope@manifest-url.json entry
|
|
21
|
+
- 7a37360: fix(dts-plugin): consume api types if adding new one
|
|
22
|
+
- Updated dependencies [35d925b]
|
|
23
|
+
- Updated dependencies [35d925b]
|
|
24
|
+
- Updated dependencies [8acd217]
|
|
25
|
+
- @module-federation/sdk@0.9.1
|
|
26
|
+
- @module-federation/managers@0.9.1
|
|
27
|
+
- @module-federation/third-party-dts-extractor@0.9.1
|
|
28
|
+
- @module-federation/error-codes@0.9.1
|
|
29
|
+
|
|
3
30
|
## 0.9.0
|
|
4
31
|
|
|
5
32
|
### Minor Changes
|
|
@@ -39,9 +39,9 @@ declare class DTSManager {
|
|
|
39
39
|
generateAPITypes(mapComponentsToExpose: Record<string, string>): string;
|
|
40
40
|
extractRemoteTypes(options: ReturnType<typeof retrieveRemoteConfig>): Promise<void>;
|
|
41
41
|
generateTypes(): Promise<void>;
|
|
42
|
-
requestRemoteManifest(remoteInfo: RemoteInfo): Promise<Required<RemoteInfo>>;
|
|
42
|
+
requestRemoteManifest(remoteInfo: RemoteInfo, hostOptions: Required<HostOptions>): Promise<Required<RemoteInfo>>;
|
|
43
43
|
consumeTargetRemotes(hostOptions: Required<HostOptions>, remoteInfo: Required<RemoteInfo>): Promise<[string, string]>;
|
|
44
|
-
downloadAPITypes(remoteInfo: Required<RemoteInfo>, destinationPath: string): Promise<
|
|
44
|
+
downloadAPITypes(remoteInfo: Required<RemoteInfo>, destinationPath: string, hostOptions: Required<HostOptions>): Promise<boolean>;
|
|
45
45
|
consumeAPITypes(hostOptions: Required<HostOptions>): void;
|
|
46
46
|
consumeArchiveTypes(options: HostOptions): Promise<{
|
|
47
47
|
hostOptions: Required<HostOptions>;
|
package/dist/core.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DTSManager, T as TsConfigJson, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-
|
|
2
|
-
export { j as DtsWorker, r as retrieveRemoteConfig } from './DtsWorker-
|
|
1
|
+
import { D as DTSManager, T as TsConfigJson, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-bfe21fe7.js';
|
|
2
|
+
export { j as DtsWorker, r as retrieveRemoteConfig } from './DtsWorker-bfe21fe7.js';
|
|
3
3
|
import { H as HostOptions, R as RemoteInfo, a as RemoteOptions, D as DTSManagerOptions } from './DTSManagerOptions-c74c59ed.js';
|
|
4
4
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
5
5
|
import { ChildProcess } from 'child_process';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DTSManager, T as TsConfigJson, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-
|
|
2
|
-
export { j as DtsWorker, r as retrieveRemoteConfig } from './DtsWorker-
|
|
1
|
+
import { D as DTSManager, T as TsConfigJson, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-bfe21fe7.js';
|
|
2
|
+
export { j as DtsWorker, r as retrieveRemoteConfig } from './DtsWorker-bfe21fe7.js';
|
|
3
3
|
import { H as HostOptions, R as RemoteInfo, a as RemoteOptions, D as DTSManagerOptions } from './DTSManagerOptions-c74c59ed.js';
|
|
4
4
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
5
5
|
import { ChildProcess } from 'child_process';
|
package/dist/core.js
CHANGED
|
@@ -123,6 +123,7 @@ var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
|
123
123
|
var import_path3 = __toESM(require("path"));
|
|
124
124
|
var import_promises3 = require("fs/promises");
|
|
125
125
|
var import_fs = __toESM(require("fs"));
|
|
126
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
126
127
|
var import_sdk5 = require("@module-federation/sdk");
|
|
127
128
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
128
129
|
|
|
@@ -1156,7 +1157,8 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1156
1157
|
try {
|
|
1157
1158
|
const url = fileToDownload;
|
|
1158
1159
|
const response = yield axiosGet(url, {
|
|
1159
|
-
responseType: "arraybuffer"
|
|
1160
|
+
responseType: "arraybuffer",
|
|
1161
|
+
timeout: hostOptions.timeout
|
|
1160
1162
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1161
1163
|
if (typeof ((_a3 = response.headers) == null ? void 0 : _a3["content-type"]) === "string" && response.headers["content-type"].includes("text/html")) {
|
|
1162
1164
|
throw new Error(`${url} receives invalid content-type: ${response.headers["content-type"]}`);
|
|
@@ -1203,7 +1205,9 @@ var defaultOptions = {
|
|
|
1203
1205
|
context: process.cwd(),
|
|
1204
1206
|
abortOnError: true,
|
|
1205
1207
|
consumeAPITypes: false,
|
|
1206
|
-
runtimePkgs: []
|
|
1208
|
+
runtimePkgs: [],
|
|
1209
|
+
remoteTypeUrls: {},
|
|
1210
|
+
timeout: 6e4
|
|
1207
1211
|
};
|
|
1208
1212
|
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1209
1213
|
const remoteUrl = new URL(url, "file:");
|
|
@@ -1219,18 +1223,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1219
1223
|
}, "buildApiTypeUrl");
|
|
1220
1224
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1221
1225
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1226
|
+
const { remoteTypeUrls } = hostOptions;
|
|
1222
1227
|
let decodedRemote = remote;
|
|
1223
1228
|
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1224
1229
|
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1225
1230
|
}
|
|
1226
1231
|
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1227
1232
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1228
|
-
|
|
1233
|
+
let zipUrl = "";
|
|
1234
|
+
let apiTypeUrl = "";
|
|
1235
|
+
const name = parsedInfo.name || remoteAlias;
|
|
1236
|
+
if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
|
|
1237
|
+
zipUrl = remoteTypeUrls[name].zip;
|
|
1238
|
+
apiTypeUrl = remoteTypeUrls[name].api;
|
|
1239
|
+
}
|
|
1240
|
+
if (!zipUrl && url) {
|
|
1241
|
+
zipUrl = buildZipUrl(hostOptions, url);
|
|
1242
|
+
}
|
|
1243
|
+
if (!apiTypeUrl && zipUrl) {
|
|
1244
|
+
apiTypeUrl = buildApiTypeUrl(zipUrl);
|
|
1245
|
+
}
|
|
1229
1246
|
return {
|
|
1230
|
-
name
|
|
1247
|
+
name,
|
|
1231
1248
|
url,
|
|
1232
1249
|
zipUrl,
|
|
1233
|
-
apiTypeUrl
|
|
1250
|
+
apiTypeUrl,
|
|
1234
1251
|
alias: remoteAlias
|
|
1235
1252
|
};
|
|
1236
1253
|
}, "retrieveRemoteInfo");
|
|
@@ -1306,6 +1323,7 @@ var DTSManager = (_a = class {
|
|
|
1306
1323
|
}
|
|
1307
1324
|
extractRemoteTypes(options) {
|
|
1308
1325
|
return __async(this, null, function* () {
|
|
1326
|
+
var _a3;
|
|
1309
1327
|
const { remoteOptions, tsConfig } = options;
|
|
1310
1328
|
if (!remoteOptions.extractRemoteTypes) {
|
|
1311
1329
|
return;
|
|
@@ -1320,20 +1338,29 @@ var DTSManager = (_a = class {
|
|
|
1320
1338
|
}
|
|
1321
1339
|
}
|
|
1322
1340
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1323
|
-
if (hasRemotes) {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1341
|
+
if (hasRemotes && this.options.host) {
|
|
1342
|
+
try {
|
|
1343
|
+
const { hostOptions } = retrieveHostConfig(this.options.host);
|
|
1344
|
+
const remoteTypesFolder = import_path3.default.resolve(hostOptions.context, hostOptions.typesFolder);
|
|
1345
|
+
const targetDir = import_path3.default.join(mfTypesPath, "node_modules");
|
|
1346
|
+
if (import_fs.default.existsSync(remoteTypesFolder)) {
|
|
1347
|
+
const targetFolder = import_path3.default.resolve(remoteOptions.context, targetDir);
|
|
1348
|
+
yield import_fs_extra3.default.ensureDir(targetFolder);
|
|
1349
|
+
yield import_fs_extra3.default.copy(remoteTypesFolder, targetFolder, {
|
|
1350
|
+
overwrite: true
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1355
|
+
fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
|
|
1356
|
+
} else {
|
|
1357
|
+
throw err;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1334
1360
|
}
|
|
1335
1361
|
});
|
|
1336
1362
|
}
|
|
1363
|
+
// it must execute after consumeTypes
|
|
1337
1364
|
generateTypes() {
|
|
1338
1365
|
return __async(this, null, function* () {
|
|
1339
1366
|
var _a3;
|
|
@@ -1346,6 +1373,18 @@ var DTSManager = (_a = class {
|
|
|
1346
1373
|
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1347
1374
|
return;
|
|
1348
1375
|
}
|
|
1376
|
+
if (tsConfig.compilerOptions.tsBuildInfoFile) {
|
|
1377
|
+
try {
|
|
1378
|
+
const tsBuildInfoFile = import_path3.default.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
|
|
1379
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1380
|
+
if (!import_fs.default.existsSync(mfTypesPath)) {
|
|
1381
|
+
import_fs.default.rmSync(tsBuildInfoFile, {
|
|
1382
|
+
force: true
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
} catch (e) {
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1349
1388
|
yield this.extractRemoteTypes({
|
|
1350
1389
|
remoteOptions,
|
|
1351
1390
|
tsConfig,
|
|
@@ -1375,7 +1414,7 @@ var DTSManager = (_a = class {
|
|
|
1375
1414
|
} catch (error2) {
|
|
1376
1415
|
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1377
1416
|
if (this.options.displayErrorInTerminal) {
|
|
1378
|
-
logger.error(`Unable to compile federated types${error2}`);
|
|
1417
|
+
logger.error(`Unable to compile federated types ${error2}`);
|
|
1379
1418
|
}
|
|
1380
1419
|
} else {
|
|
1381
1420
|
throw error2;
|
|
@@ -1383,14 +1422,19 @@ var DTSManager = (_a = class {
|
|
|
1383
1422
|
}
|
|
1384
1423
|
});
|
|
1385
1424
|
}
|
|
1386
|
-
requestRemoteManifest(remoteInfo) {
|
|
1425
|
+
requestRemoteManifest(remoteInfo, hostOptions) {
|
|
1387
1426
|
return __async(this, null, function* () {
|
|
1388
1427
|
try {
|
|
1389
1428
|
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1390
1429
|
return remoteInfo;
|
|
1391
1430
|
}
|
|
1431
|
+
if (remoteInfo.zipUrl) {
|
|
1432
|
+
return remoteInfo;
|
|
1433
|
+
}
|
|
1392
1434
|
const url = remoteInfo.url;
|
|
1393
|
-
const res = yield axiosGet(url
|
|
1435
|
+
const res = yield axiosGet(url, {
|
|
1436
|
+
timeout: hostOptions.timeout
|
|
1437
|
+
});
|
|
1394
1438
|
const manifestJson = res.data;
|
|
1395
1439
|
if (!manifestJson.metaData.types.zip) {
|
|
1396
1440
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
@@ -1441,7 +1485,7 @@ var DTSManager = (_a = class {
|
|
|
1441
1485
|
]);
|
|
1442
1486
|
});
|
|
1443
1487
|
}
|
|
1444
|
-
downloadAPITypes(remoteInfo, destinationPath) {
|
|
1488
|
+
downloadAPITypes(remoteInfo, destinationPath, hostOptions) {
|
|
1445
1489
|
return __async(this, null, function* () {
|
|
1446
1490
|
const { apiTypeUrl } = remoteInfo;
|
|
1447
1491
|
if (!apiTypeUrl) {
|
|
@@ -1449,13 +1493,17 @@ var DTSManager = (_a = class {
|
|
|
1449
1493
|
}
|
|
1450
1494
|
try {
|
|
1451
1495
|
const url = apiTypeUrl;
|
|
1452
|
-
const res = yield axiosGet(url
|
|
1496
|
+
const res = yield axiosGet(url, {
|
|
1497
|
+
timeout: hostOptions.timeout
|
|
1498
|
+
});
|
|
1453
1499
|
let apiTypeFile = res.data;
|
|
1454
1500
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1455
1501
|
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1456
1502
|
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1503
|
+
const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
|
|
1457
1504
|
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1458
1505
|
fileLog(`success`, "downloadAPITypes", "info");
|
|
1506
|
+
return existed;
|
|
1459
1507
|
} catch (err) {
|
|
1460
1508
|
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
1461
1509
|
}
|
|
@@ -1519,7 +1567,7 @@ var DTSManager = (_a = class {
|
|
|
1519
1567
|
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1520
1568
|
const remoteInfo = item[1];
|
|
1521
1569
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1522
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1570
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1523
1571
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1524
1572
|
}
|
|
1525
1573
|
return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
@@ -1554,7 +1602,7 @@ var DTSManager = (_a = class {
|
|
|
1554
1602
|
if (!remoteInfo) {
|
|
1555
1603
|
return;
|
|
1556
1604
|
}
|
|
1557
|
-
yield this.downloadAPITypes(remoteInfo, destinationPath);
|
|
1605
|
+
yield this.downloadAPITypes(remoteInfo, destinationPath, hostOptions);
|
|
1558
1606
|
})));
|
|
1559
1607
|
this.consumeAPITypes(hostOptions);
|
|
1560
1608
|
}
|
|
@@ -1597,7 +1645,10 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1597
1645
|
// use remoteTarPath first
|
|
1598
1646
|
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
1599
1647
|
}));
|
|
1600
|
-
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1648
|
+
const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath, hostOptions);
|
|
1649
|
+
if (addNew) {
|
|
1650
|
+
this.consumeAPITypes(hostOptions);
|
|
1651
|
+
}
|
|
1601
1652
|
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
1602
1653
|
}), "consumeTypes");
|
|
1603
1654
|
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
@@ -1608,14 +1659,13 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1608
1659
|
fileLog(`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`, "updateTypes", "info");
|
|
1609
1660
|
if (remoteInfo) {
|
|
1610
1661
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1611
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1662
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1612
1663
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1613
1664
|
}
|
|
1614
1665
|
yield consumeTypes2(this.remoteAliasMap[remoteInfo.alias]);
|
|
1615
1666
|
} else if (updatedRemoteInfo) {
|
|
1616
1667
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1617
1668
|
yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1618
|
-
this.consumeAPITypes(hostOptions);
|
|
1619
1669
|
}), "consumeDynamicRemoteTypes");
|
|
1620
1670
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1621
1671
|
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
@@ -1624,7 +1674,7 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1624
1674
|
remote: updatedRemoteInfo.url
|
|
1625
1675
|
});
|
|
1626
1676
|
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
1627
|
-
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
|
|
1677
|
+
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo, hostOptions);
|
|
1628
1678
|
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "updateTypes", "info");
|
|
1629
1679
|
yield consumeDynamicRemoteTypes();
|
|
1630
1680
|
}
|
|
@@ -1733,10 +1783,13 @@ function cloneDeepOptions(options) {
|
|
|
1733
1783
|
"manifest",
|
|
1734
1784
|
"async"
|
|
1735
1785
|
];
|
|
1736
|
-
return (0, import_lodash.default)(options, (
|
|
1786
|
+
return (0, import_lodash.default)(options, (value, key) => {
|
|
1737
1787
|
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1738
1788
|
return false;
|
|
1739
1789
|
}
|
|
1790
|
+
if (typeof value === "function") {
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1740
1793
|
});
|
|
1741
1794
|
}
|
|
1742
1795
|
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
@@ -1752,12 +1805,14 @@ function axiosGet(url, config) {
|
|
|
1752
1805
|
const httpsAgent = new import_https.default.Agent({
|
|
1753
1806
|
family: 4
|
|
1754
1807
|
});
|
|
1755
|
-
return import_axios.default.get(url, __spreadValues(__spreadValues({
|
|
1808
|
+
return import_axios.default.get(url, __spreadProps(__spreadValues(__spreadValues({
|
|
1756
1809
|
httpAgent,
|
|
1757
1810
|
httpsAgent
|
|
1758
1811
|
}, {
|
|
1759
1812
|
headers: getEnvHeaders()
|
|
1760
|
-
}), config)
|
|
1813
|
+
}), config), {
|
|
1814
|
+
timeout: (config == null ? void 0 : config.timeout) || 6e4
|
|
1815
|
+
}));
|
|
1761
1816
|
});
|
|
1762
1817
|
}
|
|
1763
1818
|
__name(axiosGet, "axiosGet");
|
|
@@ -706,6 +706,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
706
706
|
import path2 from "path";
|
|
707
707
|
import { rm as rm2 } from "fs/promises";
|
|
708
708
|
import fs2 from "fs";
|
|
709
|
+
import fse from "fs-extra";
|
|
709
710
|
import { MANIFEST_EXT, inferAutoPublicPath } from "@module-federation/sdk";
|
|
710
711
|
import { ThirdPartyExtractor as ThirdPartyExtractor2 } from "@module-federation/third-party-dts-extractor";
|
|
711
712
|
|
|
@@ -721,7 +722,9 @@ var defaultOptions2 = {
|
|
|
721
722
|
context: process.cwd(),
|
|
722
723
|
abortOnError: true,
|
|
723
724
|
consumeAPITypes: false,
|
|
724
|
-
runtimePkgs: []
|
|
725
|
+
runtimePkgs: [],
|
|
726
|
+
remoteTypeUrls: {},
|
|
727
|
+
timeout: 6e4
|
|
725
728
|
};
|
|
726
729
|
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
727
730
|
const remoteUrl = new URL(url, "file:");
|
|
@@ -737,18 +740,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
737
740
|
}, "buildApiTypeUrl");
|
|
738
741
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
739
742
|
const { hostOptions, remoteAlias, remote } = options;
|
|
743
|
+
const { remoteTypeUrls } = hostOptions;
|
|
740
744
|
let decodedRemote = remote;
|
|
741
745
|
if (decodedRemote.startsWith(ENCODE_NAME_PREFIX)) {
|
|
742
746
|
decodedRemote = decodeName(decodedRemote, ENCODE_NAME_PREFIX);
|
|
743
747
|
}
|
|
744
748
|
const parsedInfo = parseEntry(decodedRemote, void 0, "@");
|
|
745
749
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
746
|
-
|
|
750
|
+
let zipUrl = "";
|
|
751
|
+
let apiTypeUrl = "";
|
|
752
|
+
const name = parsedInfo.name || remoteAlias;
|
|
753
|
+
if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
|
|
754
|
+
zipUrl = remoteTypeUrls[name].zip;
|
|
755
|
+
apiTypeUrl = remoteTypeUrls[name].api;
|
|
756
|
+
}
|
|
757
|
+
if (!zipUrl && url) {
|
|
758
|
+
zipUrl = buildZipUrl(hostOptions, url);
|
|
759
|
+
}
|
|
760
|
+
if (!apiTypeUrl && zipUrl) {
|
|
761
|
+
apiTypeUrl = buildApiTypeUrl(zipUrl);
|
|
762
|
+
}
|
|
747
763
|
return {
|
|
748
|
-
name
|
|
764
|
+
name,
|
|
749
765
|
url,
|
|
750
766
|
zipUrl,
|
|
751
|
-
apiTypeUrl
|
|
767
|
+
apiTypeUrl,
|
|
752
768
|
alias: remoteAlias
|
|
753
769
|
};
|
|
754
770
|
}, "retrieveRemoteInfo");
|
|
@@ -824,6 +840,7 @@ var DTSManager = (_a = class {
|
|
|
824
840
|
}
|
|
825
841
|
extractRemoteTypes(options) {
|
|
826
842
|
return __async(this, null, function* () {
|
|
843
|
+
var _a2;
|
|
827
844
|
const { remoteOptions, tsConfig } = options;
|
|
828
845
|
if (!remoteOptions.extractRemoteTypes) {
|
|
829
846
|
return;
|
|
@@ -838,20 +855,29 @@ var DTSManager = (_a = class {
|
|
|
838
855
|
}
|
|
839
856
|
}
|
|
840
857
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
841
|
-
if (hasRemotes) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
858
|
+
if (hasRemotes && this.options.host) {
|
|
859
|
+
try {
|
|
860
|
+
const { hostOptions } = retrieveHostConfig(this.options.host);
|
|
861
|
+
const remoteTypesFolder = path2.resolve(hostOptions.context, hostOptions.typesFolder);
|
|
862
|
+
const targetDir = path2.join(mfTypesPath, "node_modules");
|
|
863
|
+
if (fs2.existsSync(remoteTypesFolder)) {
|
|
864
|
+
const targetFolder = path2.resolve(remoteOptions.context, targetDir);
|
|
865
|
+
yield fse.ensureDir(targetFolder);
|
|
866
|
+
yield fse.copy(remoteTypesFolder, targetFolder, {
|
|
867
|
+
overwrite: true
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
} catch (err) {
|
|
871
|
+
if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
|
|
872
|
+
fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
|
|
873
|
+
} else {
|
|
874
|
+
throw err;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
852
877
|
}
|
|
853
878
|
});
|
|
854
879
|
}
|
|
880
|
+
// it must execute after consumeTypes
|
|
855
881
|
generateTypes() {
|
|
856
882
|
return __async(this, null, function* () {
|
|
857
883
|
var _a2;
|
|
@@ -864,6 +890,18 @@ var DTSManager = (_a = class {
|
|
|
864
890
|
if (!Object.keys(mapComponentsToExpose).length) {
|
|
865
891
|
return;
|
|
866
892
|
}
|
|
893
|
+
if (tsConfig.compilerOptions.tsBuildInfoFile) {
|
|
894
|
+
try {
|
|
895
|
+
const tsBuildInfoFile = path2.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
|
|
896
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
897
|
+
if (!fs2.existsSync(mfTypesPath)) {
|
|
898
|
+
fs2.rmSync(tsBuildInfoFile, {
|
|
899
|
+
force: true
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
} catch (e) {
|
|
903
|
+
}
|
|
904
|
+
}
|
|
867
905
|
yield this.extractRemoteTypes({
|
|
868
906
|
remoteOptions,
|
|
869
907
|
tsConfig,
|
|
@@ -893,7 +931,7 @@ var DTSManager = (_a = class {
|
|
|
893
931
|
} catch (error) {
|
|
894
932
|
if (((_a2 = this.options.remote) == null ? void 0 : _a2.abortOnError) === false) {
|
|
895
933
|
if (this.options.displayErrorInTerminal) {
|
|
896
|
-
logger.error(`Unable to compile federated types${error}`);
|
|
934
|
+
logger.error(`Unable to compile federated types ${error}`);
|
|
897
935
|
}
|
|
898
936
|
} else {
|
|
899
937
|
throw error;
|
|
@@ -901,14 +939,19 @@ var DTSManager = (_a = class {
|
|
|
901
939
|
}
|
|
902
940
|
});
|
|
903
941
|
}
|
|
904
|
-
requestRemoteManifest(remoteInfo) {
|
|
942
|
+
requestRemoteManifest(remoteInfo, hostOptions) {
|
|
905
943
|
return __async(this, null, function* () {
|
|
906
944
|
try {
|
|
907
945
|
if (!remoteInfo.url.includes(MANIFEST_EXT)) {
|
|
908
946
|
return remoteInfo;
|
|
909
947
|
}
|
|
948
|
+
if (remoteInfo.zipUrl) {
|
|
949
|
+
return remoteInfo;
|
|
950
|
+
}
|
|
910
951
|
const url = remoteInfo.url;
|
|
911
|
-
const res = yield axiosGet(url
|
|
952
|
+
const res = yield axiosGet(url, {
|
|
953
|
+
timeout: hostOptions.timeout
|
|
954
|
+
});
|
|
912
955
|
const manifestJson = res.data;
|
|
913
956
|
if (!manifestJson.metaData.types.zip) {
|
|
914
957
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
@@ -959,7 +1002,7 @@ var DTSManager = (_a = class {
|
|
|
959
1002
|
]);
|
|
960
1003
|
});
|
|
961
1004
|
}
|
|
962
|
-
downloadAPITypes(remoteInfo, destinationPath) {
|
|
1005
|
+
downloadAPITypes(remoteInfo, destinationPath, hostOptions) {
|
|
963
1006
|
return __async(this, null, function* () {
|
|
964
1007
|
const { apiTypeUrl } = remoteInfo;
|
|
965
1008
|
if (!apiTypeUrl) {
|
|
@@ -967,13 +1010,17 @@ var DTSManager = (_a = class {
|
|
|
967
1010
|
}
|
|
968
1011
|
try {
|
|
969
1012
|
const url = apiTypeUrl;
|
|
970
|
-
const res = yield axiosGet(url
|
|
1013
|
+
const res = yield axiosGet(url, {
|
|
1014
|
+
timeout: hostOptions.timeout
|
|
1015
|
+
});
|
|
971
1016
|
let apiTypeFile = res.data;
|
|
972
1017
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
973
1018
|
const filePath = path2.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
974
1019
|
fs2.writeFileSync(filePath, apiTypeFile);
|
|
1020
|
+
const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
|
|
975
1021
|
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
976
1022
|
fileLog(`success`, "downloadAPITypes", "info");
|
|
1023
|
+
return existed;
|
|
977
1024
|
} catch (err) {
|
|
978
1025
|
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
979
1026
|
}
|
|
@@ -1037,7 +1084,7 @@ var DTSManager = (_a = class {
|
|
|
1037
1084
|
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1038
1085
|
const remoteInfo = item[1];
|
|
1039
1086
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1040
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1087
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1041
1088
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1042
1089
|
}
|
|
1043
1090
|
return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
@@ -1072,7 +1119,7 @@ var DTSManager = (_a = class {
|
|
|
1072
1119
|
if (!remoteInfo) {
|
|
1073
1120
|
return;
|
|
1074
1121
|
}
|
|
1075
|
-
yield this.downloadAPITypes(remoteInfo, destinationPath);
|
|
1122
|
+
yield this.downloadAPITypes(remoteInfo, destinationPath, hostOptions);
|
|
1076
1123
|
})));
|
|
1077
1124
|
this.consumeAPITypes(hostOptions);
|
|
1078
1125
|
}
|
|
@@ -1115,7 +1162,10 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1115
1162
|
// use remoteTarPath first
|
|
1116
1163
|
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
1117
1164
|
}));
|
|
1118
|
-
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1165
|
+
const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath, hostOptions);
|
|
1166
|
+
if (addNew) {
|
|
1167
|
+
this.consumeAPITypes(hostOptions);
|
|
1168
|
+
}
|
|
1119
1169
|
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
1120
1170
|
}), "consumeTypes");
|
|
1121
1171
|
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
@@ -1126,14 +1176,13 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1126
1176
|
fileLog(`remoteInfo: ${JSON.stringify(remoteInfo, null, 2)}`, "updateTypes", "info");
|
|
1127
1177
|
if (remoteInfo) {
|
|
1128
1178
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1129
|
-
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1179
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo, hostOptions);
|
|
1130
1180
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1131
1181
|
}
|
|
1132
1182
|
yield consumeTypes(this.remoteAliasMap[remoteInfo.alias]);
|
|
1133
1183
|
} else if (updatedRemoteInfo) {
|
|
1134
1184
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1135
1185
|
yield consumeTypes(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1136
|
-
this.consumeAPITypes(hostOptions);
|
|
1137
1186
|
}), "consumeDynamicRemoteTypes");
|
|
1138
1187
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1139
1188
|
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
@@ -1142,7 +1191,7 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1142
1191
|
remote: updatedRemoteInfo.url
|
|
1143
1192
|
});
|
|
1144
1193
|
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
1145
|
-
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
|
|
1194
|
+
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo, hostOptions);
|
|
1146
1195
|
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "updateTypes", "info");
|
|
1147
1196
|
yield consumeDynamicRemoteTypes();
|
|
1148
1197
|
}
|
|
@@ -1251,10 +1300,13 @@ function cloneDeepOptions(options) {
|
|
|
1251
1300
|
"manifest",
|
|
1252
1301
|
"async"
|
|
1253
1302
|
];
|
|
1254
|
-
return cloneDeepWith(options, (
|
|
1303
|
+
return cloneDeepWith(options, (value, key) => {
|
|
1255
1304
|
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1256
1305
|
return false;
|
|
1257
1306
|
}
|
|
1307
|
+
if (typeof value === "function") {
|
|
1308
|
+
return false;
|
|
1309
|
+
}
|
|
1258
1310
|
});
|
|
1259
1311
|
}
|
|
1260
1312
|
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
@@ -1270,12 +1322,14 @@ function axiosGet(url, config) {
|
|
|
1270
1322
|
const httpsAgent = new https.Agent({
|
|
1271
1323
|
family: 4
|
|
1272
1324
|
});
|
|
1273
|
-
return axios.get(url, __spreadValues(__spreadValues({
|
|
1325
|
+
return axios.get(url, __spreadProps(__spreadValues(__spreadValues({
|
|
1274
1326
|
httpAgent,
|
|
1275
1327
|
httpsAgent
|
|
1276
1328
|
}, {
|
|
1277
1329
|
headers: getEnvHeaders()
|
|
1278
|
-
}), config)
|
|
1330
|
+
}), config), {
|
|
1331
|
+
timeout: (config == null ? void 0 : config.timeout) || 6e4
|
|
1332
|
+
}));
|
|
1279
1333
|
});
|
|
1280
1334
|
}
|
|
1281
1335
|
__name(axiosGet, "axiosGet");
|
|
@@ -1305,7 +1359,8 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1305
1359
|
try {
|
|
1306
1360
|
const url = fileToDownload;
|
|
1307
1361
|
const response = yield axiosGet(url, {
|
|
1308
|
-
responseType: "arraybuffer"
|
|
1362
|
+
responseType: "arraybuffer",
|
|
1363
|
+
timeout: hostOptions.timeout
|
|
1309
1364
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1310
1365
|
if (typeof ((_a2 = response.headers) == null ? void 0 : _a2["content-type"]) === "string" && response.headers["content-type"].includes("text/html")) {
|
|
1311
1366
|
throw new Error(`${url} receives invalid content-type: ${response.headers["content-type"]}`);
|
package/dist/esm/core.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
consumeTypes,
|
|
4
4
|
generateTypesInChildProcess,
|
|
5
5
|
rpc_exports
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-IPO3NMOQ.js";
|
|
7
7
|
import {
|
|
8
8
|
DTSManager,
|
|
9
9
|
HOST_API_TYPES_FILE_NAME,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
retrieveTypesAssetsInfo,
|
|
20
20
|
retrieveTypesZipPath,
|
|
21
21
|
validateOptions
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-TKO3UU5B.js";
|
|
23
23
|
import "./chunk-KCWHOFI6.js";
|
|
24
24
|
import "./chunk-4CSLH7II.js";
|
|
25
25
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
rpc_exports
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IPO3NMOQ.js";
|
|
4
4
|
import {
|
|
5
5
|
ModuleFederationDevServer,
|
|
6
6
|
createKoaServer,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
retrieveMfTypesPath,
|
|
10
10
|
retrieveRemoteConfig,
|
|
11
11
|
retrieveTypesZipPath
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-TKO3UU5B.js";
|
|
13
13
|
import {
|
|
14
14
|
fileLog,
|
|
15
15
|
getIPV4
|