@module-federation/dts-plugin 0.8.12 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.md +29 -0
- package/dist/{DtsWorker-484d9f4a.d.ts → DtsWorker-edc3f145.d.ts} +1 -1
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +74 -21
- package/dist/esm/{chunk-2B3WPOMZ.js → chunk-LHN7ASHT.js} +1 -1
- package/dist/esm/{chunk-7XB7PFWZ.js → chunk-ZU4UW7EP.js} +74 -21
- 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 +49 -29
- package/dist/fork-dev-worker.js +74 -21
- package/dist/fork-generate-dts.d.mts +1 -1
- package/dist/fork-generate-dts.d.ts +1 -1
- package/dist/fork-generate-dts.js +74 -21
- package/dist/index.js +127 -54
- package/dist/package.json +4 -3
- package/package.json +8 -7
package/dist/esm/index.js
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
consumeTypes,
|
|
3
3
|
generateTypesInChildProcess,
|
|
4
4
|
rpc_exports
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-LHN7ASHT.js";
|
|
6
6
|
import {
|
|
7
7
|
cloneDeepOptions,
|
|
8
8
|
generateTypes,
|
|
9
9
|
isTSProject,
|
|
10
10
|
retrieveTypesAssetsInfo,
|
|
11
11
|
validateOptions
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZU4UW7EP.js";
|
|
13
13
|
import {
|
|
14
14
|
getIPV4,
|
|
15
15
|
logger
|
|
@@ -126,15 +126,17 @@ function ensureTempDir(filePath) {
|
|
|
126
126
|
}
|
|
127
127
|
__name(ensureTempDir, "ensureTempDir");
|
|
128
128
|
var _DevPlugin = class _DevPlugin {
|
|
129
|
-
constructor(options, dtsOptions,
|
|
129
|
+
constructor(options, dtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise) {
|
|
130
130
|
__publicField(this, "name", "MFDevPlugin");
|
|
131
131
|
__publicField(this, "_options");
|
|
132
132
|
__publicField(this, "_devWorker");
|
|
133
133
|
__publicField(this, "dtsOptions");
|
|
134
|
-
__publicField(this, "
|
|
134
|
+
__publicField(this, "generateTypesPromise");
|
|
135
|
+
__publicField(this, "fetchRemoteTypeUrlsPromise");
|
|
135
136
|
this._options = options;
|
|
136
|
-
this.
|
|
137
|
+
this.generateTypesPromise = generateTypesPromise;
|
|
137
138
|
this.dtsOptions = dtsOptions;
|
|
139
|
+
this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
|
|
138
140
|
}
|
|
139
141
|
static ensureLiveReloadEntry(options, filePath) {
|
|
140
142
|
ensureTempDir(filePath);
|
|
@@ -252,11 +254,16 @@ var _DevPlugin = class _DevPlugin {
|
|
|
252
254
|
if (remote && !(remote == null ? void 0 : remote.tsConfigPath) && typeof normalizedDtsOptions === "object" && normalizedDtsOptions.tsConfigPath) {
|
|
253
255
|
remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
|
|
254
256
|
}
|
|
255
|
-
|
|
257
|
+
Promise.all([
|
|
258
|
+
this.generateTypesPromise,
|
|
259
|
+
this.fetchRemoteTypeUrlsPromise
|
|
260
|
+
]).then(([_, remoteTypeUrls]) => {
|
|
256
261
|
this._devWorker = createDevWorker({
|
|
257
262
|
name,
|
|
258
263
|
remote,
|
|
259
|
-
host,
|
|
264
|
+
host: __spreadProps(__spreadValues({}, host), {
|
|
265
|
+
remoteTypeUrls
|
|
266
|
+
}),
|
|
260
267
|
extraOptions,
|
|
261
268
|
disableLiveReload: normalizedDev.disableHotTypesReload,
|
|
262
269
|
disableHotTypesReload: normalizedDev.disableHotTypesReload
|
|
@@ -276,25 +283,26 @@ import { normalizeOptions as normalizeOptions4 } from "@module-federation/sdk";
|
|
|
276
283
|
// packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
|
|
277
284
|
import { normalizeOptions as normalizeOptions2 } from "@module-federation/sdk";
|
|
278
285
|
var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
279
|
-
constructor(pluginOptions, dtsOptions, defaultOptions,
|
|
286
|
+
constructor(pluginOptions, dtsOptions, defaultOptions, fetchRemoteTypeUrlsResolve) {
|
|
280
287
|
__publicField(this, "pluginOptions");
|
|
281
288
|
__publicField(this, "dtsOptions");
|
|
282
289
|
__publicField(this, "defaultOptions");
|
|
283
290
|
__publicField(this, "callback");
|
|
291
|
+
__publicField(this, "fetchRemoteTypeUrlsResolve");
|
|
284
292
|
this.pluginOptions = pluginOptions;
|
|
285
293
|
this.dtsOptions = dtsOptions;
|
|
286
294
|
this.defaultOptions = defaultOptions;
|
|
287
|
-
this.
|
|
295
|
+
this.fetchRemoteTypeUrlsResolve = fetchRemoteTypeUrlsResolve;
|
|
288
296
|
}
|
|
289
297
|
apply(compiler) {
|
|
290
|
-
const { dtsOptions, defaultOptions, pluginOptions,
|
|
298
|
+
const { dtsOptions, defaultOptions, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
|
|
291
299
|
if (isPrd()) {
|
|
292
|
-
|
|
300
|
+
fetchRemoteTypeUrlsResolve(void 0);
|
|
293
301
|
return;
|
|
294
302
|
}
|
|
295
303
|
const normalizedConsumeTypes = normalizeOptions2(true, defaultOptions, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
296
304
|
if (!normalizedConsumeTypes) {
|
|
297
|
-
|
|
305
|
+
fetchRemoteTypeUrlsResolve(void 0);
|
|
298
306
|
return;
|
|
299
307
|
}
|
|
300
308
|
const finalOptions = {
|
|
@@ -307,10 +315,17 @@ var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
|
307
315
|
displayErrorInTerminal: dtsOptions.displayErrorInTerminal
|
|
308
316
|
};
|
|
309
317
|
validateOptions(finalOptions.host);
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
318
|
+
const fetchRemoteTypeUrlsPromise = typeof normalizedConsumeTypes.remoteTypeUrls === "function" ? normalizedConsumeTypes.remoteTypeUrls() : Promise.resolve(normalizedConsumeTypes.remoteTypeUrls);
|
|
319
|
+
const promise = fetchRemoteTypeUrlsPromise.then((remoteTypeUrls) => {
|
|
320
|
+
consumeTypes(__spreadProps(__spreadValues({}, finalOptions), {
|
|
321
|
+
host: __spreadProps(__spreadValues({}, finalOptions.host), {
|
|
322
|
+
remoteTypeUrls
|
|
323
|
+
})
|
|
324
|
+
})).then(() => {
|
|
325
|
+
fetchRemoteTypeUrlsResolve(remoteTypeUrls);
|
|
326
|
+
}).catch(() => {
|
|
327
|
+
fetchRemoteTypeUrlsResolve(remoteTypeUrls);
|
|
328
|
+
});
|
|
314
329
|
});
|
|
315
330
|
compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
|
|
316
331
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -333,25 +348,26 @@ import fs2 from "fs";
|
|
|
333
348
|
import path5 from "path";
|
|
334
349
|
import { normalizeOptions as normalizeOptions3 } from "@module-federation/sdk";
|
|
335
350
|
var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
336
|
-
constructor(pluginOptions, dtsOptions, defaultOptions,
|
|
351
|
+
constructor(pluginOptions, dtsOptions, defaultOptions, fetchRemoteTypeUrlsPromise, callback) {
|
|
337
352
|
__publicField(this, "pluginOptions");
|
|
338
353
|
__publicField(this, "dtsOptions");
|
|
339
354
|
__publicField(this, "defaultOptions");
|
|
340
|
-
__publicField(this, "
|
|
355
|
+
__publicField(this, "fetchRemoteTypeUrlsPromise");
|
|
341
356
|
__publicField(this, "callback");
|
|
342
357
|
this.pluginOptions = pluginOptions;
|
|
343
358
|
this.dtsOptions = dtsOptions;
|
|
344
359
|
this.defaultOptions = defaultOptions;
|
|
345
|
-
this.
|
|
360
|
+
this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
|
|
346
361
|
this.callback = callback;
|
|
347
362
|
}
|
|
348
363
|
apply(compiler) {
|
|
349
|
-
const { dtsOptions, defaultOptions, pluginOptions,
|
|
364
|
+
const { dtsOptions, defaultOptions, pluginOptions, fetchRemoteTypeUrlsPromise, callback } = this;
|
|
350
365
|
const normalizedGenerateTypes = normalizeOptions3(true, defaultOptions, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
|
|
351
366
|
if (!normalizedGenerateTypes) {
|
|
352
367
|
callback();
|
|
353
368
|
return;
|
|
354
369
|
}
|
|
370
|
+
const normalizedConsumeTypes = normalizeOptions3(true, defaultOptions, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
355
371
|
const finalOptions = {
|
|
356
372
|
remote: __spreadValues({
|
|
357
373
|
implementation: dtsOptions.implementation,
|
|
@@ -359,6 +375,10 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
359
375
|
outputDir: getCompilerOutputDir(compiler),
|
|
360
376
|
moduleFederationConfig: pluginOptions
|
|
361
377
|
}, normalizedGenerateTypes),
|
|
378
|
+
host: normalizedConsumeTypes === false ? void 0 : __spreadValues({
|
|
379
|
+
context: compiler.context,
|
|
380
|
+
moduleFederationConfig: pluginOptions
|
|
381
|
+
}, normalizedGenerateTypes),
|
|
362
382
|
extraOptions: dtsOptions.extraOptions || {},
|
|
363
383
|
displayErrorInTerminal: dtsOptions.displayErrorInTerminal
|
|
364
384
|
};
|
|
@@ -466,7 +486,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
466
486
|
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
467
487
|
)
|
|
468
488
|
}, () => __async(this, null, function* () {
|
|
469
|
-
yield
|
|
489
|
+
yield fetchRemoteTypeUrlsPromise;
|
|
470
490
|
const emitTypesFilesPromise = emitTypesFiles(compilation);
|
|
471
491
|
if (isProd) {
|
|
472
492
|
yield emitTypesFilesPromise;
|
|
@@ -490,8 +510,8 @@ var _DtsPlugin = class _DtsPlugin {
|
|
|
490
510
|
generateAPITypes: true,
|
|
491
511
|
compileInChildProcess: true,
|
|
492
512
|
abortOnError: false,
|
|
493
|
-
extractThirdParty:
|
|
494
|
-
extractRemoteTypes:
|
|
513
|
+
extractThirdParty: false,
|
|
514
|
+
extractRemoteTypes: false
|
|
495
515
|
};
|
|
496
516
|
const defaultConsumeTypes = {
|
|
497
517
|
abortOnError: false,
|
|
@@ -506,17 +526,17 @@ var _DtsPlugin = class _DtsPlugin {
|
|
|
506
526
|
if (typeof normalizedDtsOptions !== "object") {
|
|
507
527
|
return;
|
|
508
528
|
}
|
|
509
|
-
let
|
|
510
|
-
const
|
|
511
|
-
|
|
529
|
+
let fetchRemoteTypeUrlsResolve;
|
|
530
|
+
const fetchRemoteTypeUrlsPromise = new Promise((resolve2) => {
|
|
531
|
+
fetchRemoteTypeUrlsResolve = resolve2;
|
|
512
532
|
});
|
|
513
533
|
let generateTypesPromiseResolve;
|
|
514
534
|
const generateTypesPromise = new Promise((resolve2) => {
|
|
515
535
|
generateTypesPromiseResolve = resolve2;
|
|
516
536
|
});
|
|
517
|
-
new DevPlugin(options, normalizedDtsOptions, generateTypesPromise).apply(compiler);
|
|
518
|
-
new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes,
|
|
519
|
-
new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes,
|
|
537
|
+
new DevPlugin(options, normalizedDtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise).apply(compiler);
|
|
538
|
+
new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes, fetchRemoteTypeUrlsPromise, generateTypesPromiseResolve).apply(compiler);
|
|
539
|
+
new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes, fetchRemoteTypeUrlsResolve).apply(compiler);
|
|
520
540
|
}
|
|
521
541
|
};
|
|
522
542
|
__name(_DtsPlugin, "DtsPlugin");
|
package/dist/fork-dev-worker.js
CHANGED
|
@@ -104,6 +104,7 @@ var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
|
104
104
|
var import_path4 = __toESM(require("path"));
|
|
105
105
|
var import_promises3 = require("fs/promises");
|
|
106
106
|
var import_fs = __toESM(require("fs"));
|
|
107
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
107
108
|
var import_sdk5 = require("@module-federation/sdk");
|
|
108
109
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
109
110
|
|
|
@@ -1723,7 +1724,8 @@ var defaultOptions = {
|
|
|
1723
1724
|
context: process.cwd(),
|
|
1724
1725
|
abortOnError: true,
|
|
1725
1726
|
consumeAPITypes: false,
|
|
1726
|
-
runtimePkgs: []
|
|
1727
|
+
runtimePkgs: [],
|
|
1728
|
+
remoteTypeUrls: {}
|
|
1727
1729
|
};
|
|
1728
1730
|
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1729
1731
|
const remoteUrl = new URL(url, "file:");
|
|
@@ -1739,18 +1741,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1739
1741
|
}, "buildApiTypeUrl");
|
|
1740
1742
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1741
1743
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1744
|
+
const { remoteTypeUrls } = hostOptions;
|
|
1742
1745
|
let decodedRemote = remote;
|
|
1743
1746
|
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1744
1747
|
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1745
1748
|
}
|
|
1746
1749
|
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1747
1750
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1748
|
-
|
|
1751
|
+
let zipUrl = "";
|
|
1752
|
+
let apiTypeUrl = "";
|
|
1753
|
+
const name = parsedInfo.name || remoteAlias;
|
|
1754
|
+
if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
|
|
1755
|
+
zipUrl = remoteTypeUrls[name].zip;
|
|
1756
|
+
apiTypeUrl = remoteTypeUrls[name].api;
|
|
1757
|
+
}
|
|
1758
|
+
if (!zipUrl && url) {
|
|
1759
|
+
zipUrl = buildZipUrl(hostOptions, url);
|
|
1760
|
+
}
|
|
1761
|
+
if (!apiTypeUrl && zipUrl) {
|
|
1762
|
+
apiTypeUrl = buildApiTypeUrl(zipUrl);
|
|
1763
|
+
}
|
|
1749
1764
|
return {
|
|
1750
|
-
name
|
|
1765
|
+
name,
|
|
1751
1766
|
url,
|
|
1752
1767
|
zipUrl,
|
|
1753
|
-
apiTypeUrl
|
|
1768
|
+
apiTypeUrl,
|
|
1754
1769
|
alias: remoteAlias
|
|
1755
1770
|
};
|
|
1756
1771
|
}, "retrieveRemoteInfo");
|
|
@@ -1826,6 +1841,7 @@ var DTSManager = (_a = class {
|
|
|
1826
1841
|
}
|
|
1827
1842
|
extractRemoteTypes(options) {
|
|
1828
1843
|
return __async(this, null, function* () {
|
|
1844
|
+
var _a3;
|
|
1829
1845
|
const { remoteOptions, tsConfig } = options;
|
|
1830
1846
|
if (!remoteOptions.extractRemoteTypes) {
|
|
1831
1847
|
return;
|
|
@@ -1840,20 +1856,29 @@ var DTSManager = (_a = class {
|
|
|
1840
1856
|
}
|
|
1841
1857
|
}
|
|
1842
1858
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1843
|
-
if (hasRemotes) {
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1859
|
+
if (hasRemotes && this.options.host) {
|
|
1860
|
+
try {
|
|
1861
|
+
const { hostOptions } = retrieveHostConfig(this.options.host);
|
|
1862
|
+
const remoteTypesFolder = import_path4.default.resolve(hostOptions.context, hostOptions.typesFolder);
|
|
1863
|
+
const targetDir = import_path4.default.join(mfTypesPath, "node_modules");
|
|
1864
|
+
if (import_fs.default.existsSync(remoteTypesFolder)) {
|
|
1865
|
+
const targetFolder = import_path4.default.resolve(remoteOptions.context, targetDir);
|
|
1866
|
+
yield import_fs_extra3.default.ensureDir(targetFolder);
|
|
1867
|
+
yield import_fs_extra3.default.copy(remoteTypesFolder, targetFolder, {
|
|
1868
|
+
overwrite: true
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
} catch (err) {
|
|
1872
|
+
if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1873
|
+
fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
|
|
1874
|
+
} else {
|
|
1875
|
+
throw err;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1854
1878
|
}
|
|
1855
1879
|
});
|
|
1856
1880
|
}
|
|
1881
|
+
// it must execute after consumeTypes
|
|
1857
1882
|
generateTypes() {
|
|
1858
1883
|
return __async(this, null, function* () {
|
|
1859
1884
|
var _a3;
|
|
@@ -1866,6 +1891,18 @@ var DTSManager = (_a = class {
|
|
|
1866
1891
|
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1867
1892
|
return;
|
|
1868
1893
|
}
|
|
1894
|
+
if (tsConfig.compilerOptions.tsBuildInfoFile) {
|
|
1895
|
+
try {
|
|
1896
|
+
const tsBuildInfoFile = import_path4.default.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
|
|
1897
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1898
|
+
if (!import_fs.default.existsSync(mfTypesPath)) {
|
|
1899
|
+
import_fs.default.rmSync(tsBuildInfoFile, {
|
|
1900
|
+
force: true
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
} catch (e) {
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1869
1906
|
yield this.extractRemoteTypes({
|
|
1870
1907
|
remoteOptions,
|
|
1871
1908
|
tsConfig,
|
|
@@ -1895,7 +1932,7 @@ var DTSManager = (_a = class {
|
|
|
1895
1932
|
} catch (error2) {
|
|
1896
1933
|
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1897
1934
|
if (this.options.displayErrorInTerminal) {
|
|
1898
|
-
logger.error(`Unable to compile federated types${error2}`);
|
|
1935
|
+
logger.error(`Unable to compile federated types ${error2}`);
|
|
1899
1936
|
}
|
|
1900
1937
|
} else {
|
|
1901
1938
|
throw error2;
|
|
@@ -1909,6 +1946,9 @@ var DTSManager = (_a = class {
|
|
|
1909
1946
|
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1910
1947
|
return remoteInfo;
|
|
1911
1948
|
}
|
|
1949
|
+
if (remoteInfo.zipUrl) {
|
|
1950
|
+
return remoteInfo;
|
|
1951
|
+
}
|
|
1912
1952
|
const url = remoteInfo.url;
|
|
1913
1953
|
const res = yield axiosGet(url);
|
|
1914
1954
|
const manifestJson = res.data;
|
|
@@ -1974,8 +2014,10 @@ var DTSManager = (_a = class {
|
|
|
1974
2014
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1975
2015
|
const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1976
2016
|
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
2017
|
+
const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
|
|
1977
2018
|
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1978
2019
|
fileLog(`success`, "downloadAPITypes", "info");
|
|
2020
|
+
return existed;
|
|
1979
2021
|
} catch (err) {
|
|
1980
2022
|
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
1981
2023
|
}
|
|
@@ -2117,7 +2159,10 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
2117
2159
|
// use remoteTarPath first
|
|
2118
2160
|
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
2119
2161
|
}));
|
|
2120
|
-
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
2162
|
+
const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
2163
|
+
if (addNew) {
|
|
2164
|
+
this.consumeAPITypes(hostOptions);
|
|
2165
|
+
}
|
|
2121
2166
|
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
2122
2167
|
}), "consumeTypes");
|
|
2123
2168
|
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
@@ -2135,7 +2180,6 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
2135
2180
|
} else if (updatedRemoteInfo) {
|
|
2136
2181
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
2137
2182
|
yield consumeTypes2(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
2138
|
-
this.consumeAPITypes(hostOptions);
|
|
2139
2183
|
}), "consumeDynamicRemoteTypes");
|
|
2140
2184
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
2141
2185
|
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
@@ -2187,10 +2231,13 @@ function cloneDeepOptions(options) {
|
|
|
2187
2231
|
"manifest",
|
|
2188
2232
|
"async"
|
|
2189
2233
|
];
|
|
2190
|
-
return (0, import_lodash.default)(options, (
|
|
2234
|
+
return (0, import_lodash.default)(options, (value, key) => {
|
|
2191
2235
|
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
2192
2236
|
return false;
|
|
2193
2237
|
}
|
|
2238
|
+
if (typeof value === "function") {
|
|
2239
|
+
return false;
|
|
2240
|
+
}
|
|
2194
2241
|
});
|
|
2195
2242
|
}
|
|
2196
2243
|
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
@@ -2252,7 +2299,7 @@ function getEffectiveRootDir(parsedCommandLine) {
|
|
|
2252
2299
|
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
2253
2300
|
}
|
|
2254
2301
|
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
2255
|
-
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir }, mapComponentsToExpose) => {
|
|
2302
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir, moduleFederationConfig }, mapComponentsToExpose) => {
|
|
2256
2303
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
2257
2304
|
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
2258
2305
|
if (readResult.error) {
|
|
@@ -2270,7 +2317,10 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
|
|
|
2270
2317
|
outDir
|
|
2271
2318
|
};
|
|
2272
2319
|
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
2273
|
-
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({
|
|
2320
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({
|
|
2321
|
+
incremental: true,
|
|
2322
|
+
tsBuildInfoFile: (0, import_path5.resolve)(context, "node_modules/.cache/mf-types/.tsbuildinfo")
|
|
2323
|
+
}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
2274
2324
|
const _a3 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a3, restCompilerOptions = __objRest(_a3, ["paths", "baseUrl"]);
|
|
2275
2325
|
rawTsConfigJson.compilerOptions = restCompilerOptions;
|
|
2276
2326
|
const filesToCompile = [
|
|
@@ -2322,6 +2372,9 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
2322
2372
|
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
2323
2373
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
2324
2374
|
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
2375
|
+
if (tsConfig.compilerOptions.incremental && tsConfig.compilerOptions.tsBuildInfoFile && options.deleteTypesFolder !== true) {
|
|
2376
|
+
remoteOptions.deleteTypesFolder = false;
|
|
2377
|
+
}
|
|
2325
2378
|
return {
|
|
2326
2379
|
tsConfig,
|
|
2327
2380
|
mapComponentsToExpose,
|
|
@@ -202,7 +202,7 @@ function getEffectiveRootDir(parsedCommandLine) {
|
|
|
202
202
|
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
203
203
|
}
|
|
204
204
|
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
205
|
-
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir }, mapComponentsToExpose) => {
|
|
205
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir, moduleFederationConfig }, mapComponentsToExpose) => {
|
|
206
206
|
const resolvedTsConfigPath = (0, import_path.resolve)(context, tsConfigPath);
|
|
207
207
|
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
208
208
|
if (readResult.error) {
|
|
@@ -220,7 +220,10 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
|
|
|
220
220
|
outDir
|
|
221
221
|
};
|
|
222
222
|
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
223
|
-
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({
|
|
223
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({
|
|
224
|
+
incremental: true,
|
|
225
|
+
tsBuildInfoFile: (0, import_path.resolve)(context, "node_modules/.cache/mf-types/.tsbuildinfo")
|
|
226
|
+
}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
224
227
|
const _a2 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a2, restCompilerOptions = __objRest(_a2, ["paths", "baseUrl"]);
|
|
225
228
|
rawTsConfigJson.compilerOptions = restCompilerOptions;
|
|
226
229
|
const filesToCompile = [
|
|
@@ -272,6 +275,9 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
272
275
|
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
273
276
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
274
277
|
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
278
|
+
if (tsConfig.compilerOptions.incremental && tsConfig.compilerOptions.tsBuildInfoFile && options.deleteTypesFolder !== true) {
|
|
279
|
+
remoteOptions.deleteTypesFolder = false;
|
|
280
|
+
}
|
|
275
281
|
return {
|
|
276
282
|
tsConfig,
|
|
277
283
|
mapComponentsToExpose,
|
|
@@ -283,6 +289,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
283
289
|
var import_path4 = __toESM(require("path"));
|
|
284
290
|
var import_promises3 = require("fs/promises");
|
|
285
291
|
var import_fs2 = __toESM(require("fs"));
|
|
292
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
286
293
|
var import_sdk5 = require("@module-federation/sdk");
|
|
287
294
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
288
295
|
|
|
@@ -1363,7 +1370,8 @@ var defaultOptions2 = {
|
|
|
1363
1370
|
context: process.cwd(),
|
|
1364
1371
|
abortOnError: true,
|
|
1365
1372
|
consumeAPITypes: false,
|
|
1366
|
-
runtimePkgs: []
|
|
1373
|
+
runtimePkgs: [],
|
|
1374
|
+
remoteTypeUrls: {}
|
|
1367
1375
|
};
|
|
1368
1376
|
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1369
1377
|
const remoteUrl = new URL(url, "file:");
|
|
@@ -1379,18 +1387,31 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1379
1387
|
}, "buildApiTypeUrl");
|
|
1380
1388
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1381
1389
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1390
|
+
const { remoteTypeUrls } = hostOptions;
|
|
1382
1391
|
let decodedRemote = remote;
|
|
1383
1392
|
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1384
1393
|
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1385
1394
|
}
|
|
1386
1395
|
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1387
1396
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1388
|
-
|
|
1397
|
+
let zipUrl = "";
|
|
1398
|
+
let apiTypeUrl = "";
|
|
1399
|
+
const name = parsedInfo.name || remoteAlias;
|
|
1400
|
+
if (typeof remoteTypeUrls === "object" && remoteTypeUrls[name]) {
|
|
1401
|
+
zipUrl = remoteTypeUrls[name].zip;
|
|
1402
|
+
apiTypeUrl = remoteTypeUrls[name].api;
|
|
1403
|
+
}
|
|
1404
|
+
if (!zipUrl && url) {
|
|
1405
|
+
zipUrl = buildZipUrl(hostOptions, url);
|
|
1406
|
+
}
|
|
1407
|
+
if (!apiTypeUrl && zipUrl) {
|
|
1408
|
+
apiTypeUrl = buildApiTypeUrl(zipUrl);
|
|
1409
|
+
}
|
|
1389
1410
|
return {
|
|
1390
|
-
name
|
|
1411
|
+
name,
|
|
1391
1412
|
url,
|
|
1392
1413
|
zipUrl,
|
|
1393
|
-
apiTypeUrl
|
|
1414
|
+
apiTypeUrl,
|
|
1394
1415
|
alias: remoteAlias
|
|
1395
1416
|
};
|
|
1396
1417
|
}, "retrieveRemoteInfo");
|
|
@@ -1466,6 +1487,7 @@ var DTSManager = (_a = class {
|
|
|
1466
1487
|
}
|
|
1467
1488
|
extractRemoteTypes(options) {
|
|
1468
1489
|
return __async(this, null, function* () {
|
|
1490
|
+
var _a2;
|
|
1469
1491
|
const { remoteOptions, tsConfig } = options;
|
|
1470
1492
|
if (!remoteOptions.extractRemoteTypes) {
|
|
1471
1493
|
return;
|
|
@@ -1480,20 +1502,29 @@ var DTSManager = (_a = class {
|
|
|
1480
1502
|
}
|
|
1481
1503
|
}
|
|
1482
1504
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1483
|
-
if (hasRemotes) {
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1505
|
+
if (hasRemotes && this.options.host) {
|
|
1506
|
+
try {
|
|
1507
|
+
const { hostOptions } = retrieveHostConfig(this.options.host);
|
|
1508
|
+
const remoteTypesFolder = import_path4.default.resolve(hostOptions.context, hostOptions.typesFolder);
|
|
1509
|
+
const targetDir = import_path4.default.join(mfTypesPath, "node_modules");
|
|
1510
|
+
if (import_fs2.default.existsSync(remoteTypesFolder)) {
|
|
1511
|
+
const targetFolder = import_path4.default.resolve(remoteOptions.context, targetDir);
|
|
1512
|
+
yield import_fs_extra3.default.ensureDir(targetFolder);
|
|
1513
|
+
yield import_fs_extra3.default.copy(remoteTypesFolder, targetFolder, {
|
|
1514
|
+
overwrite: true
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
} catch (err) {
|
|
1518
|
+
if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1519
|
+
fileLog(`Unable to copy remote types, ${err}`, "extractRemoteTypes", "error");
|
|
1520
|
+
} else {
|
|
1521
|
+
throw err;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1494
1524
|
}
|
|
1495
1525
|
});
|
|
1496
1526
|
}
|
|
1527
|
+
// it must execute after consumeTypes
|
|
1497
1528
|
generateTypes() {
|
|
1498
1529
|
return __async(this, null, function* () {
|
|
1499
1530
|
var _a2;
|
|
@@ -1506,6 +1537,18 @@ var DTSManager = (_a = class {
|
|
|
1506
1537
|
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1507
1538
|
return;
|
|
1508
1539
|
}
|
|
1540
|
+
if (tsConfig.compilerOptions.tsBuildInfoFile) {
|
|
1541
|
+
try {
|
|
1542
|
+
const tsBuildInfoFile = import_path4.default.resolve(remoteOptions.context, tsConfig.compilerOptions.tsBuildInfoFile);
|
|
1543
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1544
|
+
if (!import_fs2.default.existsSync(mfTypesPath)) {
|
|
1545
|
+
import_fs2.default.rmSync(tsBuildInfoFile, {
|
|
1546
|
+
force: true
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
} catch (e) {
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1509
1552
|
yield this.extractRemoteTypes({
|
|
1510
1553
|
remoteOptions,
|
|
1511
1554
|
tsConfig,
|
|
@@ -1535,7 +1578,7 @@ var DTSManager = (_a = class {
|
|
|
1535
1578
|
} catch (error2) {
|
|
1536
1579
|
if (((_a2 = this.options.remote) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1537
1580
|
if (this.options.displayErrorInTerminal) {
|
|
1538
|
-
logger.error(`Unable to compile federated types${error2}`);
|
|
1581
|
+
logger.error(`Unable to compile federated types ${error2}`);
|
|
1539
1582
|
}
|
|
1540
1583
|
} else {
|
|
1541
1584
|
throw error2;
|
|
@@ -1549,6 +1592,9 @@ var DTSManager = (_a = class {
|
|
|
1549
1592
|
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1550
1593
|
return remoteInfo;
|
|
1551
1594
|
}
|
|
1595
|
+
if (remoteInfo.zipUrl) {
|
|
1596
|
+
return remoteInfo;
|
|
1597
|
+
}
|
|
1552
1598
|
const url = remoteInfo.url;
|
|
1553
1599
|
const res = yield axiosGet(url);
|
|
1554
1600
|
const manifestJson = res.data;
|
|
@@ -1614,8 +1660,10 @@ var DTSManager = (_a = class {
|
|
|
1614
1660
|
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1615
1661
|
const filePath = import_path4.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1616
1662
|
import_fs2.default.writeFileSync(filePath, apiTypeFile);
|
|
1663
|
+
const existed = this.loadedRemoteAPIAlias.has(remoteInfo.alias);
|
|
1617
1664
|
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1618
1665
|
fileLog(`success`, "downloadAPITypes", "info");
|
|
1666
|
+
return existed;
|
|
1619
1667
|
} catch (err) {
|
|
1620
1668
|
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "downloadAPITypes", "error");
|
|
1621
1669
|
}
|
|
@@ -1757,7 +1805,10 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1757
1805
|
// use remoteTarPath first
|
|
1758
1806
|
zipUrl: remoteTarPath || requiredRemoteInfo.zipUrl
|
|
1759
1807
|
}));
|
|
1760
|
-
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1808
|
+
const addNew = yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1809
|
+
if (addNew) {
|
|
1810
|
+
this.consumeAPITypes(hostOptions);
|
|
1811
|
+
}
|
|
1761
1812
|
fileLog(`consumeTypes end`, "updateTypes", "info");
|
|
1762
1813
|
}), "consumeTypes");
|
|
1763
1814
|
fileLog(`loadedRemoteInfo: ${JSON.stringify(loadedRemoteInfo, null, 2)}`, "updateTypes", "info");
|
|
@@ -1775,7 +1826,6 @@ hostName: ${hostName}`, "updateTypes", "info");
|
|
|
1775
1826
|
} else if (updatedRemoteInfo) {
|
|
1776
1827
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1777
1828
|
yield consumeTypes(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1778
|
-
this.consumeAPITypes(hostOptions);
|
|
1779
1829
|
}), "consumeDynamicRemoteTypes");
|
|
1780
1830
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1781
1831
|
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
@@ -1827,10 +1877,13 @@ function cloneDeepOptions(options) {
|
|
|
1827
1877
|
"manifest",
|
|
1828
1878
|
"async"
|
|
1829
1879
|
];
|
|
1830
|
-
return (0, import_lodash.default)(options, (
|
|
1880
|
+
return (0, import_lodash.default)(options, (value, key) => {
|
|
1831
1881
|
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1832
1882
|
return false;
|
|
1833
1883
|
}
|
|
1884
|
+
if (typeof value === "function") {
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1834
1887
|
});
|
|
1835
1888
|
}
|
|
1836
1889
|
__name(cloneDeepOptions, "cloneDeepOptions");
|