@module-federation/dts-plugin 0.2.6 → 0.2.7
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 +10 -0
- package/dist/{DtsWorker-7113d2b0.d.ts → DtsWorker-90454949.d.ts} +11 -3
- package/dist/core.d.mts +5 -5
- package/dist/core.d.ts +5 -5
- package/dist/core.js +167 -99
- package/dist/esm/{chunk-CRKFI32N.js → chunk-ZLQBXHXA.js} +161 -93
- package/dist/esm/core.js +1 -1
- package/dist/esm/fork-dev-worker.js +1 -1
- package/dist/esm/fork-generate-dts.js +1 -1
- package/dist/esm/index.js +5 -6
- package/dist/esm/start-broker.js +1 -1
- package/dist/fork-dev-worker.js +171 -103
- package/dist/fork-generate-dts.d.mts +1 -1
- package/dist/fork-generate-dts.d.ts +1 -1
- package/dist/fork-generate-dts.js +164 -96
- package/dist/index.js +186 -119
- package/dist/package.json +6 -3
- package/dist/start-broker.js +11 -11
- package/package.json +9 -6
package/dist/fork-dev-worker.js
CHANGED
|
@@ -79,104 +79,136 @@ module.exports = __toCommonJS(forkDevWorker_exports);
|
|
|
79
79
|
var import_fs2 = require("fs");
|
|
80
80
|
var import_path5 = require("path");
|
|
81
81
|
var import_managers2 = require("@module-federation/managers");
|
|
82
|
-
var
|
|
82
|
+
var import_typescript = __toESM(require("typescript"));
|
|
83
83
|
|
|
84
84
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
85
85
|
var import_axios = __toESM(require("axios"));
|
|
86
86
|
var import_http2 = __toESM(require("http"));
|
|
87
87
|
var import_https = __toESM(require("https"));
|
|
88
|
-
var
|
|
88
|
+
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
89
89
|
|
|
90
90
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
91
|
-
var
|
|
91
|
+
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
92
92
|
var import_path4 = __toESM(require("path"));
|
|
93
|
-
var
|
|
93
|
+
var import_promises3 = require("fs/promises");
|
|
94
94
|
var import_fs = __toESM(require("fs"));
|
|
95
|
-
var
|
|
95
|
+
var import_sdk5 = require("@module-federation/sdk");
|
|
96
96
|
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
97
97
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
98
98
|
|
|
99
99
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
100
100
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
101
101
|
var import_path3 = require("path");
|
|
102
|
-
var
|
|
102
|
+
var import_promises2 = require("fs/promises");
|
|
103
103
|
|
|
104
104
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
105
|
-
var
|
|
105
|
+
var import_fs_extra = require("fs-extra");
|
|
106
|
+
var import_promises = require("fs/promises");
|
|
107
|
+
var import_crypto = require("crypto");
|
|
106
108
|
var import_path = require("path");
|
|
107
|
-
var import_typescript = __toESM(require("typescript"));
|
|
108
109
|
var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
110
|
+
var import_child_process = require("child_process");
|
|
111
|
+
var import_util = __toESM(require("util"));
|
|
112
|
+
var import_sdk = require("@module-federation/sdk");
|
|
109
113
|
var STARTS_WITH_SLASH = /^\//;
|
|
110
114
|
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
|
|
114
|
-
console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
|
|
115
|
-
}, "reportCompileDiagnostic");
|
|
116
|
-
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
117
|
-
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
115
|
+
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
116
|
+
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
118
117
|
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
118
|
+
function writeTempTsConfig(tsConfig, context) {
|
|
119
|
+
const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${(0, import_crypto.randomUUID)()}.json`);
|
|
120
|
+
(0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
|
|
121
|
+
(0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
122
|
+
return tempTsConfigJsonPath;
|
|
123
|
+
}
|
|
124
|
+
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
125
|
+
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
126
|
+
const ext = (0, import_path.extname)(f);
|
|
127
|
+
const regexPattern = new RegExp(`\\${ext}$`);
|
|
128
|
+
return f.replace(regexPattern, "");
|
|
129
|
+
}, "removeExt");
|
|
130
|
+
function getExposeKey(options) {
|
|
131
|
+
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
132
|
+
const relativeFilePath = removeExt((0, import_path.relative)(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
|
|
133
|
+
return mapExposeToEntry[relativeFilePath];
|
|
134
|
+
}
|
|
135
|
+
__name(getExposeKey, "getExposeKey");
|
|
136
|
+
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
137
|
+
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
138
|
+
if (!(0, import_fs_extra.existsSync)(filePath)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const stats = yield (0, import_promises.stat)(filePath);
|
|
142
|
+
if (stats.isDirectory()) {
|
|
143
|
+
const files = yield (0, import_promises.readdir)(filePath);
|
|
144
|
+
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
145
|
+
filePath: (0, import_path.join)(filePath, file)
|
|
146
|
+
}))));
|
|
147
|
+
} else if (filePath.endsWith(".d.ts")) {
|
|
148
|
+
const exposeKey = getExposeKey({
|
|
149
|
+
filePath,
|
|
150
|
+
rootDir,
|
|
151
|
+
outDir,
|
|
152
|
+
mapExposeToEntry
|
|
153
|
+
});
|
|
154
|
+
if (exposeKey) {
|
|
155
|
+
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
156
|
+
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
157
|
+
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
158
|
+
const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
|
|
159
|
+
yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
160
|
+
export { default } from './${relativePathToOutput}';`);
|
|
161
|
+
}
|
|
162
|
+
const content = yield (0, import_promises.readFile)(filePath, "utf8");
|
|
163
|
+
cb(content);
|
|
164
|
+
}
|
|
165
|
+
}), "processTypesFile");
|
|
166
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
167
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const { compilerOptions } = tsConfig;
|
|
171
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
|
|
172
|
+
try {
|
|
173
|
+
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
174
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
175
|
+
const execPromise = import_util.default.promisify(import_child_process.exec);
|
|
176
|
+
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
|
|
177
|
+
try {
|
|
178
|
+
yield execPromise(cmd);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
throw new Error(`compile TS failed, the original command is '${cmd}'`);
|
|
181
|
+
}
|
|
182
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
183
|
+
const normalizedFileName = (0, import_path.normalize)(filename);
|
|
184
|
+
let relativeFileName = "";
|
|
185
|
+
if ((0, import_path.isAbsolute)(normalizedFileName)) {
|
|
186
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
187
|
+
} else {
|
|
188
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
|
|
140
189
|
}
|
|
190
|
+
return [
|
|
191
|
+
removeExt(relativeFileName),
|
|
192
|
+
exposed
|
|
193
|
+
];
|
|
194
|
+
}));
|
|
195
|
+
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
196
|
+
yield processTypesFile({
|
|
197
|
+
outDir: compilerOptions.outDir,
|
|
198
|
+
filePath: compilerOptions.outDir,
|
|
199
|
+
rootDir: compilerOptions.rootDir,
|
|
200
|
+
mfTypePath,
|
|
201
|
+
cb,
|
|
202
|
+
mapExposeToEntry
|
|
203
|
+
});
|
|
204
|
+
if (remoteOptions.extractThirdParty) {
|
|
205
|
+
yield thirdPartyExtractor.copyDts();
|
|
141
206
|
}
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
}, "createHost");
|
|
146
|
-
var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
|
|
147
|
-
const vueTypescript = require("vue-tsc");
|
|
148
|
-
return vueTypescript.createProgram(programOptions);
|
|
149
|
-
}, "createVueTscProgram");
|
|
150
|
-
var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
|
|
151
|
-
switch (remoteOptions.compilerInstance) {
|
|
152
|
-
case "vue-tsc":
|
|
153
|
-
return createVueTscProgram(programOptions);
|
|
154
|
-
case "tsc":
|
|
155
|
-
default:
|
|
156
|
-
return import_typescript.default.createProgram(programOptions);
|
|
157
|
-
}
|
|
158
|
-
}, "createProgram");
|
|
159
|
-
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
160
|
-
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
161
|
-
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
162
|
-
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
163
|
-
const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
|
|
164
|
-
const filesToCompile = [
|
|
165
|
-
...Object.values(mapComponentsToExpose),
|
|
166
|
-
...remoteOptions.additionalFilesToCompile
|
|
167
|
-
];
|
|
168
|
-
const programOptions = {
|
|
169
|
-
rootNames: filesToCompile,
|
|
170
|
-
host: tsHost,
|
|
171
|
-
options: tsConfig
|
|
172
|
-
};
|
|
173
|
-
const tsProgram = createProgram(remoteOptions, programOptions);
|
|
174
|
-
const { diagnostics = [] } = tsProgram.emit();
|
|
175
|
-
diagnostics.forEach(reportCompileDiagnostic);
|
|
176
|
-
if (remoteOptions.extractThirdParty) {
|
|
177
|
-
thirdPartyExtractor.copyDts();
|
|
207
|
+
yield (0, import_promises.rm)(tempTsConfigJsonPath);
|
|
208
|
+
} catch (err) {
|
|
209
|
+
throw err;
|
|
178
210
|
}
|
|
179
|
-
}, "compileTs");
|
|
211
|
+
}), "compileTs");
|
|
180
212
|
|
|
181
213
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
182
214
|
var _Message = class _Message {
|
|
@@ -250,7 +282,7 @@ var FetchTypesAPI = _FetchTypesAPI;
|
|
|
250
282
|
|
|
251
283
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
252
284
|
var import_net = __toESM(require("net"));
|
|
253
|
-
var
|
|
285
|
+
var import_sdk3 = require("@module-federation/sdk");
|
|
254
286
|
|
|
255
287
|
// packages/dts-plugin/src/server/utils/logTransform.ts
|
|
256
288
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -289,7 +321,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
|
|
|
289
321
|
var BrokerExitLog = _BrokerExitLog;
|
|
290
322
|
|
|
291
323
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
292
|
-
var
|
|
324
|
+
var import_sdk2 = require("@module-federation/sdk");
|
|
293
325
|
var log4js = __toESM(require("log4js"));
|
|
294
326
|
var import_chalk2 = __toESM(require("chalk"));
|
|
295
327
|
|
|
@@ -374,7 +406,7 @@ var getIPV4 = /* @__PURE__ */ __name(() => {
|
|
|
374
406
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
375
407
|
function getIdentifier(options) {
|
|
376
408
|
const { ip, name } = options;
|
|
377
|
-
return `mf ${
|
|
409
|
+
return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
|
|
378
410
|
}
|
|
379
411
|
__name(getIdentifier, "getIdentifier");
|
|
380
412
|
function fib(n) {
|
|
@@ -1190,11 +1222,11 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
|
1190
1222
|
var Broker = _Broker;
|
|
1191
1223
|
|
|
1192
1224
|
// packages/dts-plugin/src/server/broker/createBroker.ts
|
|
1193
|
-
var
|
|
1225
|
+
var import_child_process2 = require("child_process");
|
|
1194
1226
|
var import_path2 = __toESM(require("path"));
|
|
1195
1227
|
function createBroker() {
|
|
1196
1228
|
const startBrokerPath = import_path2.default.resolve(__dirname, "./start-broker.js");
|
|
1197
|
-
const sub = (0,
|
|
1229
|
+
const sub = (0, import_child_process2.fork)(startBrokerPath, [], {
|
|
1198
1230
|
detached: true,
|
|
1199
1231
|
stdio: "ignore",
|
|
1200
1232
|
env: process.env
|
|
@@ -1562,7 +1594,7 @@ __name(_ModuleFederationDevServer, "ModuleFederationDevServer");
|
|
|
1562
1594
|
var ModuleFederationDevServer = _ModuleFederationDevServer;
|
|
1563
1595
|
|
|
1564
1596
|
// packages/dts-plugin/src/server/createKoaServer.ts
|
|
1565
|
-
var
|
|
1597
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
1566
1598
|
var import_koa = __toESM(require("koa"));
|
|
1567
1599
|
function createKoaServer(options) {
|
|
1568
1600
|
return __async(this, null, function* () {
|
|
@@ -1572,7 +1604,7 @@ function createKoaServer(options) {
|
|
|
1572
1604
|
app.use((ctx, next) => __async(this, null, function* () {
|
|
1573
1605
|
if (ctx.path === `/${DEFAULT_TAR_NAME}`) {
|
|
1574
1606
|
ctx.status = 200;
|
|
1575
|
-
ctx.body =
|
|
1607
|
+
ctx.body = import_fs_extra2.default.createReadStream(typeTarPath);
|
|
1576
1608
|
ctx.response.type = "application/x-gzip";
|
|
1577
1609
|
} else {
|
|
1578
1610
|
yield next();
|
|
@@ -1615,7 +1647,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1615
1647
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1616
1648
|
try {
|
|
1617
1649
|
if (hostOptions.deleteTypesFolder) {
|
|
1618
|
-
yield (0,
|
|
1650
|
+
yield (0, import_promises2.rm)(destinationPath, {
|
|
1619
1651
|
recursive: true,
|
|
1620
1652
|
force: true
|
|
1621
1653
|
});
|
|
@@ -1643,7 +1675,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1643
1675
|
}, "downloadTypesArchive");
|
|
1644
1676
|
|
|
1645
1677
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1646
|
-
var
|
|
1678
|
+
var import_sdk4 = require("@module-federation/sdk");
|
|
1647
1679
|
var import_managers = require("@module-federation/managers");
|
|
1648
1680
|
var defaultOptions = {
|
|
1649
1681
|
typesFolder: "@mf-types",
|
|
@@ -1670,10 +1702,10 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1670
1702
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1671
1703
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1672
1704
|
let decodedRemote = remote;
|
|
1673
|
-
if (decodedRemote.startsWith(
|
|
1674
|
-
decodedRemote = (0,
|
|
1705
|
+
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1706
|
+
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1675
1707
|
}
|
|
1676
|
-
const parsedInfo = (0,
|
|
1708
|
+
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1677
1709
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1678
1710
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1679
1711
|
return {
|
|
@@ -1800,7 +1832,7 @@ var DTSManager = (_a = class {
|
|
|
1800
1832
|
tsConfig,
|
|
1801
1833
|
mapComponentsToExpose
|
|
1802
1834
|
});
|
|
1803
|
-
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1835
|
+
yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1804
1836
|
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1805
1837
|
let apiTypesPath = "";
|
|
1806
1838
|
if (remoteOptions.generateAPITypes) {
|
|
@@ -1810,7 +1842,7 @@ var DTSManager = (_a = class {
|
|
|
1810
1842
|
}
|
|
1811
1843
|
try {
|
|
1812
1844
|
if (remoteOptions.deleteTypesFolder) {
|
|
1813
|
-
yield (0,
|
|
1845
|
+
yield (0, import_promises3.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1814
1846
|
recursive: true,
|
|
1815
1847
|
force: true
|
|
1816
1848
|
});
|
|
@@ -1820,10 +1852,10 @@ var DTSManager = (_a = class {
|
|
|
1820
1852
|
console.error(err);
|
|
1821
1853
|
}
|
|
1822
1854
|
}
|
|
1823
|
-
console.log(
|
|
1855
|
+
console.log(import_ansi_colors.default.green("Federated types created correctly"));
|
|
1824
1856
|
} catch (error2) {
|
|
1825
1857
|
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1826
|
-
console.error(
|
|
1858
|
+
console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
|
|
1827
1859
|
} else {
|
|
1828
1860
|
throw error2;
|
|
1829
1861
|
}
|
|
@@ -1833,7 +1865,7 @@ var DTSManager = (_a = class {
|
|
|
1833
1865
|
requestRemoteManifest(remoteInfo) {
|
|
1834
1866
|
return __async(this, null, function* () {
|
|
1835
1867
|
try {
|
|
1836
|
-
if (!remoteInfo.url.includes(
|
|
1868
|
+
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1837
1869
|
return remoteInfo;
|
|
1838
1870
|
}
|
|
1839
1871
|
const url = remoteInfo.url;
|
|
@@ -1860,7 +1892,7 @@ var DTSManager = (_a = class {
|
|
|
1860
1892
|
}
|
|
1861
1893
|
}
|
|
1862
1894
|
if (publicPath === "auto") {
|
|
1863
|
-
publicPath = (0,
|
|
1895
|
+
publicPath = (0, import_sdk5.inferAutoPublicPath)(remoteInfo.url);
|
|
1864
1896
|
}
|
|
1865
1897
|
remoteInfo.zipUrl = new URL(import_path4.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1866
1898
|
if (!manifestJson.metaData.types.api) {
|
|
@@ -1995,7 +2027,7 @@ var DTSManager = (_a = class {
|
|
|
1995
2027
|
})));
|
|
1996
2028
|
this.consumeAPITypes(hostOptions);
|
|
1997
2029
|
}
|
|
1998
|
-
console.log(
|
|
2030
|
+
console.log(import_ansi_colors.default.green("Federated types extraction completed"));
|
|
1999
2031
|
} catch (err) {
|
|
2000
2032
|
if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
|
|
2001
2033
|
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
@@ -2016,7 +2048,7 @@ var DTSManager = (_a = class {
|
|
|
2016
2048
|
if (!this.options.remote) {
|
|
2017
2049
|
return;
|
|
2018
2050
|
}
|
|
2019
|
-
this.generateTypes();
|
|
2051
|
+
yield this.generateTypes();
|
|
2020
2052
|
} else {
|
|
2021
2053
|
const { remoteAliasMap } = this;
|
|
2022
2054
|
if (!this.options.host) {
|
|
@@ -2120,20 +2152,56 @@ var defaultOptions2 = {
|
|
|
2120
2152
|
extractRemoteTypes: false,
|
|
2121
2153
|
extractThirdParty: false
|
|
2122
2154
|
};
|
|
2123
|
-
|
|
2155
|
+
function getEffectiveRootDir(parsedCommandLine) {
|
|
2156
|
+
const compilerOptions = parsedCommandLine.options;
|
|
2157
|
+
if (compilerOptions.rootDir) {
|
|
2158
|
+
return compilerOptions.rootDir;
|
|
2159
|
+
}
|
|
2160
|
+
const files = parsedCommandLine.fileNames;
|
|
2161
|
+
if (files.length > 0) {
|
|
2162
|
+
const commonRoot = files.map((file) => (0, import_path5.dirname)(file)).reduce((commonPath, fileDir) => {
|
|
2163
|
+
while (!fileDir.startsWith(commonPath)) {
|
|
2164
|
+
commonPath = (0, import_path5.dirname)(commonPath);
|
|
2165
|
+
}
|
|
2166
|
+
return commonPath;
|
|
2167
|
+
}, files[0]);
|
|
2168
|
+
return commonRoot;
|
|
2169
|
+
}
|
|
2170
|
+
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
2171
|
+
}
|
|
2172
|
+
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
2173
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
|
|
2124
2174
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
2125
|
-
const readResult =
|
|
2175
|
+
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
2126
2176
|
if (readResult.error) {
|
|
2127
2177
|
throw new Error(readResult.error.messageText.toString());
|
|
2128
2178
|
}
|
|
2129
|
-
const
|
|
2179
|
+
const rawTsConfigJson = readResult.config;
|
|
2180
|
+
const configContent = import_typescript.default.parseJsonConfigFileContent(rawTsConfigJson, import_typescript.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
|
|
2181
|
+
const rootDir = getEffectiveRootDir(configContent);
|
|
2130
2182
|
const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
2131
|
-
|
|
2183
|
+
const defaultCompilerOptions = {
|
|
2184
|
+
rootDir,
|
|
2132
2185
|
emitDeclarationOnly: true,
|
|
2133
2186
|
noEmit: false,
|
|
2134
2187
|
declaration: true,
|
|
2135
2188
|
outDir
|
|
2136
|
-
}
|
|
2189
|
+
};
|
|
2190
|
+
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
2191
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
2192
|
+
const filesToCompile = [
|
|
2193
|
+
...Object.values(mapComponentsToExpose),
|
|
2194
|
+
...additionalFilesToCompile
|
|
2195
|
+
];
|
|
2196
|
+
rawTsConfigJson.include = [];
|
|
2197
|
+
rawTsConfigJson.files = filesToCompile;
|
|
2198
|
+
rawTsConfigJson.exclude = [];
|
|
2199
|
+
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
2200
|
+
const extendsPath = rawTsConfigJson.extends;
|
|
2201
|
+
if (extendsPath && extendsPath.startsWith(".")) {
|
|
2202
|
+
rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
|
|
2203
|
+
}
|
|
2204
|
+
return rawTsConfigJson;
|
|
2137
2205
|
}, "readTsConfig");
|
|
2138
2206
|
var TS_EXTENSIONS = [
|
|
2139
2207
|
"ts",
|
|
@@ -2171,7 +2239,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
2171
2239
|
validateOptions(options);
|
|
2172
2240
|
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
2173
2241
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
2174
|
-
const tsConfig = readTsConfig(remoteOptions);
|
|
2242
|
+
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
2175
2243
|
return {
|
|
2176
2244
|
tsConfig,
|
|
2177
2245
|
mapComponentsToExpose,
|
|
@@ -2345,7 +2413,7 @@ __name(wrapRpc, "wrapRpc");
|
|
|
2345
2413
|
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
2346
2414
|
var child_process = __toESM(require("child_process"));
|
|
2347
2415
|
var process3 = __toESM(require("process"));
|
|
2348
|
-
var
|
|
2416
|
+
var import_crypto2 = require("crypto");
|
|
2349
2417
|
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
2350
2418
|
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
2351
2419
|
const options = {
|
|
@@ -2366,7 +2434,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
2366
2434
|
];
|
|
2367
2435
|
}
|
|
2368
2436
|
let childProcess, remoteMethod;
|
|
2369
|
-
const id = (0,
|
|
2437
|
+
const id = (0, import_crypto2.randomUUID)();
|
|
2370
2438
|
const worker = {
|
|
2371
2439
|
connect(...args) {
|
|
2372
2440
|
if (childProcess && !childProcess.connected) {
|
|
@@ -2417,7 +2485,7 @@ function getRpcWorkerData() {
|
|
|
2417
2485
|
__name(getRpcWorkerData, "getRpcWorkerData");
|
|
2418
2486
|
|
|
2419
2487
|
// packages/dts-plugin/src/dev-worker/forkDevWorker.ts
|
|
2420
|
-
var
|
|
2488
|
+
var import_sdk6 = require("@module-federation/sdk");
|
|
2421
2489
|
|
|
2422
2490
|
// packages/dts-plugin/src/dev-worker/utils.ts
|
|
2423
2491
|
var DEFAULT_LOCAL_IPS = [
|
|
@@ -2448,7 +2516,7 @@ function getLocalRemoteNames(options, encodeNameIdentifier) {
|
|
|
2448
2516
|
const { mapRemotesToDownload } = retrieveHostConfig(options);
|
|
2449
2517
|
return Object.keys(mapRemotesToDownload).reduce((sum, remoteModuleName) => {
|
|
2450
2518
|
const remoteInfo = mapRemotesToDownload[remoteModuleName];
|
|
2451
|
-
const name = encodeNameIdentifier ? (0,
|
|
2519
|
+
const name = encodeNameIdentifier ? (0, import_sdk6.decodeName)(remoteInfo.name, encodeNameIdentifier) : remoteInfo.name;
|
|
2452
2520
|
const ip = getIpFromEntry(remoteInfo.url, getIPV4());
|
|
2453
2521
|
if (!ip) {
|
|
2454
2522
|
return sum;
|