@module-federation/dts-plugin 0.2.6 → 0.2.8
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 +19 -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 +172 -100
- package/dist/esm/{chunk-CRKFI32N.js → chunk-2RCHPGBO.js} +166 -94
- 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 +176 -104
- package/dist/fork-generate-dts.d.mts +1 -1
- package/dist/fork-generate-dts.d.ts +1 -1
- package/dist/fork-generate-dts.js +169 -97
- package/dist/index.js +191 -120
- package/dist/package.json +6 -3
- package/dist/start-broker.js +11 -11
- package/package.json +9 -6
package/dist/index.js
CHANGED
|
@@ -76,7 +76,7 @@ __export(src_exports, {
|
|
|
76
76
|
module.exports = __toCommonJS(src_exports);
|
|
77
77
|
|
|
78
78
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
79
|
-
var
|
|
79
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
80
80
|
var import_chalk3 = __toESM(require("chalk"));
|
|
81
81
|
|
|
82
82
|
// packages/dts-plugin/src/dev-worker/createDevWorker.ts
|
|
@@ -91,7 +91,7 @@ var import_lodash3 = __toESM(require("lodash.clonedeepwith"));
|
|
|
91
91
|
var import_fs3 = require("fs");
|
|
92
92
|
var import_path5 = require("path");
|
|
93
93
|
var import_managers2 = require("@module-federation/managers");
|
|
94
|
-
var
|
|
94
|
+
var import_typescript = __toESM(require("typescript"));
|
|
95
95
|
|
|
96
96
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
97
97
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -99,98 +99,134 @@ var import_path4 = __toESM(require("path"));
|
|
|
99
99
|
var import_axios = __toESM(require("axios"));
|
|
100
100
|
var import_http2 = __toESM(require("http"));
|
|
101
101
|
var import_https = __toESM(require("https"));
|
|
102
|
-
var
|
|
102
|
+
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
103
103
|
|
|
104
104
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
105
|
-
var
|
|
105
|
+
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
106
106
|
var import_path3 = __toESM(require("path"));
|
|
107
|
-
var
|
|
107
|
+
var import_promises3 = require("fs/promises");
|
|
108
108
|
var import_fs = __toESM(require("fs"));
|
|
109
|
-
var
|
|
109
|
+
var import_sdk5 = require("@module-federation/sdk");
|
|
110
110
|
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
111
111
|
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
112
112
|
|
|
113
113
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
114
114
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
115
115
|
var import_path2 = require("path");
|
|
116
|
-
var
|
|
116
|
+
var import_promises2 = require("fs/promises");
|
|
117
117
|
|
|
118
118
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
119
|
-
var
|
|
119
|
+
var import_fs_extra = require("fs-extra");
|
|
120
|
+
var import_promises = require("fs/promises");
|
|
121
|
+
var import_crypto = require("crypto");
|
|
120
122
|
var import_path = require("path");
|
|
121
|
-
var import_typescript = __toESM(require("typescript"));
|
|
122
123
|
var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
124
|
+
var import_child_process = require("child_process");
|
|
125
|
+
var import_util = __toESM(require("util"));
|
|
126
|
+
var import_sdk = require("@module-federation/sdk");
|
|
123
127
|
var STARTS_WITH_SLASH = /^\//;
|
|
124
128
|
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
|
|
128
|
-
console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
|
|
129
|
-
}, "reportCompileDiagnostic");
|
|
130
|
-
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
131
|
-
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
129
|
+
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
130
|
+
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
132
131
|
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
132
|
+
function writeTempTsConfig(tsConfig, context) {
|
|
133
|
+
const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${(0, import_crypto.randomUUID)()}.json`);
|
|
134
|
+
(0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
|
|
135
|
+
(0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
136
|
+
return tempTsConfigJsonPath;
|
|
137
|
+
}
|
|
138
|
+
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
139
|
+
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
140
|
+
const ext = (0, import_path.extname)(f);
|
|
141
|
+
const regexPattern = new RegExp(`\\${ext}$`);
|
|
142
|
+
return f.replace(regexPattern, "");
|
|
143
|
+
}, "removeExt");
|
|
144
|
+
function getExposeKey(options) {
|
|
145
|
+
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
146
|
+
const relativeFilePath = removeExt((0, import_path.relative)(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
|
|
147
|
+
return mapExposeToEntry[relativeFilePath];
|
|
148
|
+
}
|
|
149
|
+
__name(getExposeKey, "getExposeKey");
|
|
150
|
+
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
151
|
+
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
152
|
+
if (!(0, import_fs_extra.existsSync)(filePath)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const stats = yield (0, import_promises.stat)(filePath);
|
|
156
|
+
if (stats.isDirectory()) {
|
|
157
|
+
const files = yield (0, import_promises.readdir)(filePath);
|
|
158
|
+
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
159
|
+
filePath: (0, import_path.join)(filePath, file)
|
|
160
|
+
}))));
|
|
161
|
+
} else if (filePath.endsWith(".d.ts")) {
|
|
162
|
+
const exposeKey = getExposeKey({
|
|
163
|
+
filePath,
|
|
164
|
+
rootDir,
|
|
165
|
+
outDir,
|
|
166
|
+
mapExposeToEntry
|
|
167
|
+
});
|
|
168
|
+
if (exposeKey) {
|
|
169
|
+
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
170
|
+
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
171
|
+
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
172
|
+
const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
|
|
173
|
+
(0, import_fs_extra.ensureDirSync)(mfeTypeEntryDirectory);
|
|
174
|
+
yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
175
|
+
export { default } from './${relativePathToOutput}';`);
|
|
176
|
+
}
|
|
177
|
+
const content = yield (0, import_promises.readFile)(filePath, "utf8");
|
|
178
|
+
cb(content);
|
|
179
|
+
}
|
|
180
|
+
}), "processTypesFile");
|
|
181
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
182
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const { compilerOptions } = tsConfig;
|
|
186
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
|
|
187
|
+
try {
|
|
188
|
+
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
189
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
190
|
+
const execPromise = import_util.default.promisify(import_child_process.exec);
|
|
191
|
+
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
|
|
192
|
+
try {
|
|
193
|
+
yield execPromise(cmd);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
throw new Error(`compile TS failed, the original command is '${cmd}'`);
|
|
196
|
+
}
|
|
197
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
198
|
+
const normalizedFileName = (0, import_path.normalize)(filename);
|
|
199
|
+
let relativeFileName = "";
|
|
200
|
+
if ((0, import_path.isAbsolute)(normalizedFileName)) {
|
|
201
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
202
|
+
} else {
|
|
203
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
|
|
154
204
|
}
|
|
205
|
+
return [
|
|
206
|
+
removeExt(relativeFileName),
|
|
207
|
+
exposed
|
|
208
|
+
];
|
|
209
|
+
}));
|
|
210
|
+
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
211
|
+
yield processTypesFile({
|
|
212
|
+
outDir: compilerOptions.outDir,
|
|
213
|
+
filePath: compilerOptions.outDir,
|
|
214
|
+
rootDir: compilerOptions.rootDir,
|
|
215
|
+
mfTypePath,
|
|
216
|
+
cb,
|
|
217
|
+
mapExposeToEntry
|
|
218
|
+
});
|
|
219
|
+
if (remoteOptions.extractThirdParty) {
|
|
220
|
+
yield thirdPartyExtractor.copyDts();
|
|
155
221
|
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return vueTypescript.createProgram(programOptions);
|
|
163
|
-
}, "createVueTscProgram");
|
|
164
|
-
var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
|
|
165
|
-
switch (remoteOptions.compilerInstance) {
|
|
166
|
-
case "vue-tsc":
|
|
167
|
-
return createVueTscProgram(programOptions);
|
|
168
|
-
case "tsc":
|
|
169
|
-
default:
|
|
170
|
-
return import_typescript.default.createProgram(programOptions);
|
|
171
|
-
}
|
|
172
|
-
}, "createProgram");
|
|
173
|
-
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
174
|
-
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
175
|
-
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
176
|
-
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
177
|
-
const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
|
|
178
|
-
const filesToCompile = [
|
|
179
|
-
...Object.values(mapComponentsToExpose),
|
|
180
|
-
...remoteOptions.additionalFilesToCompile
|
|
181
|
-
];
|
|
182
|
-
const programOptions = {
|
|
183
|
-
rootNames: filesToCompile,
|
|
184
|
-
host: tsHost,
|
|
185
|
-
options: tsConfig
|
|
186
|
-
};
|
|
187
|
-
const tsProgram = createProgram(remoteOptions, programOptions);
|
|
188
|
-
const { diagnostics = [] } = tsProgram.emit();
|
|
189
|
-
diagnostics.forEach(reportCompileDiagnostic);
|
|
190
|
-
if (remoteOptions.extractThirdParty) {
|
|
191
|
-
thirdPartyExtractor.copyDts();
|
|
222
|
+
yield (0, import_promises.rm)(tempTsConfigJsonPath);
|
|
223
|
+
} catch (err) {
|
|
224
|
+
if (isDebugMode()) {
|
|
225
|
+
console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
|
|
226
|
+
}
|
|
227
|
+
throw err;
|
|
192
228
|
}
|
|
193
|
-
}, "compileTs");
|
|
229
|
+
}), "compileTs");
|
|
194
230
|
|
|
195
231
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
196
232
|
var _Message = class _Message {
|
|
@@ -263,7 +299,7 @@ __name(_FetchTypesAPI, "FetchTypesAPI");
|
|
|
263
299
|
var FetchTypesAPI = _FetchTypesAPI;
|
|
264
300
|
|
|
265
301
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
266
|
-
var
|
|
302
|
+
var import_sdk3 = require("@module-federation/sdk");
|
|
267
303
|
|
|
268
304
|
// packages/dts-plugin/src/server/utils/logTransform.ts
|
|
269
305
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -302,7 +338,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
|
|
|
302
338
|
var BrokerExitLog = _BrokerExitLog;
|
|
303
339
|
|
|
304
340
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
305
|
-
var
|
|
341
|
+
var import_sdk2 = require("@module-federation/sdk");
|
|
306
342
|
var log4js = __toESM(require("log4js"));
|
|
307
343
|
var import_chalk2 = __toESM(require("chalk"));
|
|
308
344
|
|
|
@@ -386,7 +422,7 @@ var getIPV4 = /* @__PURE__ */ __name(() => {
|
|
|
386
422
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
387
423
|
function getIdentifier(options) {
|
|
388
424
|
const { ip, name } = options;
|
|
389
|
-
return `mf ${
|
|
425
|
+
return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
|
|
390
426
|
}
|
|
391
427
|
__name(getIdentifier, "getIdentifier");
|
|
392
428
|
|
|
@@ -1098,7 +1134,7 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
|
1098
1134
|
var Broker = _Broker;
|
|
1099
1135
|
|
|
1100
1136
|
// packages/dts-plugin/src/server/createKoaServer.ts
|
|
1101
|
-
var
|
|
1137
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
1102
1138
|
var import_koa = __toESM(require("koa"));
|
|
1103
1139
|
|
|
1104
1140
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
@@ -1129,7 +1165,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1129
1165
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1130
1166
|
try {
|
|
1131
1167
|
if (hostOptions.deleteTypesFolder) {
|
|
1132
|
-
yield (0,
|
|
1168
|
+
yield (0, import_promises2.rm)(destinationPath, {
|
|
1133
1169
|
recursive: true,
|
|
1134
1170
|
force: true
|
|
1135
1171
|
});
|
|
@@ -1157,7 +1193,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1157
1193
|
}, "downloadTypesArchive");
|
|
1158
1194
|
|
|
1159
1195
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1160
|
-
var
|
|
1196
|
+
var import_sdk4 = require("@module-federation/sdk");
|
|
1161
1197
|
var import_managers = require("@module-federation/managers");
|
|
1162
1198
|
var defaultOptions = {
|
|
1163
1199
|
typesFolder: "@mf-types",
|
|
@@ -1184,10 +1220,10 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1184
1220
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1185
1221
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1186
1222
|
let decodedRemote = remote;
|
|
1187
|
-
if (decodedRemote.startsWith(
|
|
1188
|
-
decodedRemote = (0,
|
|
1223
|
+
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1224
|
+
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1189
1225
|
}
|
|
1190
|
-
const parsedInfo = (0,
|
|
1226
|
+
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1191
1227
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1192
1228
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1193
1229
|
return {
|
|
@@ -1309,12 +1345,12 @@ var DTSManager = (_a = class {
|
|
|
1309
1345
|
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1310
1346
|
return;
|
|
1311
1347
|
}
|
|
1312
|
-
this.extractRemoteTypes({
|
|
1348
|
+
yield this.extractRemoteTypes({
|
|
1313
1349
|
remoteOptions,
|
|
1314
1350
|
tsConfig,
|
|
1315
1351
|
mapComponentsToExpose
|
|
1316
1352
|
});
|
|
1317
|
-
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1353
|
+
yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1318
1354
|
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1319
1355
|
let apiTypesPath = "";
|
|
1320
1356
|
if (remoteOptions.generateAPITypes) {
|
|
@@ -1324,7 +1360,7 @@ var DTSManager = (_a = class {
|
|
|
1324
1360
|
}
|
|
1325
1361
|
try {
|
|
1326
1362
|
if (remoteOptions.deleteTypesFolder) {
|
|
1327
|
-
yield (0,
|
|
1363
|
+
yield (0, import_promises3.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1328
1364
|
recursive: true,
|
|
1329
1365
|
force: true
|
|
1330
1366
|
});
|
|
@@ -1334,10 +1370,10 @@ var DTSManager = (_a = class {
|
|
|
1334
1370
|
console.error(err);
|
|
1335
1371
|
}
|
|
1336
1372
|
}
|
|
1337
|
-
console.log(
|
|
1373
|
+
console.log(import_ansi_colors.default.green("Federated types created correctly"));
|
|
1338
1374
|
} catch (error2) {
|
|
1339
1375
|
if (((_a4 = this.options.remote) == null ? void 0 : _a4.abortOnError) === false) {
|
|
1340
|
-
console.error(
|
|
1376
|
+
console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
|
|
1341
1377
|
} else {
|
|
1342
1378
|
throw error2;
|
|
1343
1379
|
}
|
|
@@ -1347,7 +1383,7 @@ var DTSManager = (_a = class {
|
|
|
1347
1383
|
requestRemoteManifest(remoteInfo) {
|
|
1348
1384
|
return __async(this, null, function* () {
|
|
1349
1385
|
try {
|
|
1350
|
-
if (!remoteInfo.url.includes(
|
|
1386
|
+
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1351
1387
|
return remoteInfo;
|
|
1352
1388
|
}
|
|
1353
1389
|
const url = remoteInfo.url;
|
|
@@ -1374,7 +1410,7 @@ var DTSManager = (_a = class {
|
|
|
1374
1410
|
}
|
|
1375
1411
|
}
|
|
1376
1412
|
if (publicPath === "auto") {
|
|
1377
|
-
publicPath = (0,
|
|
1413
|
+
publicPath = (0, import_sdk5.inferAutoPublicPath)(remoteInfo.url);
|
|
1378
1414
|
}
|
|
1379
1415
|
remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1380
1416
|
if (!manifestJson.metaData.types.api) {
|
|
@@ -1509,7 +1545,7 @@ var DTSManager = (_a = class {
|
|
|
1509
1545
|
})));
|
|
1510
1546
|
this.consumeAPITypes(hostOptions);
|
|
1511
1547
|
}
|
|
1512
|
-
console.log(
|
|
1548
|
+
console.log(import_ansi_colors.default.green("Federated types extraction completed"));
|
|
1513
1549
|
} catch (err) {
|
|
1514
1550
|
if (((_a4 = this.options.host) == null ? void 0 : _a4.abortOnError) === false) {
|
|
1515
1551
|
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
@@ -1530,7 +1566,7 @@ var DTSManager = (_a = class {
|
|
|
1530
1566
|
if (!this.options.remote) {
|
|
1531
1567
|
return;
|
|
1532
1568
|
}
|
|
1533
|
-
this.generateTypes();
|
|
1569
|
+
yield this.generateTypes();
|
|
1534
1570
|
} else {
|
|
1535
1571
|
const { remoteAliasMap } = this;
|
|
1536
1572
|
if (!this.options.host) {
|
|
@@ -1622,7 +1658,7 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1622
1658
|
apiFileName: import_path4.default.basename(apiTypesPath)
|
|
1623
1659
|
};
|
|
1624
1660
|
} catch (err) {
|
|
1625
|
-
console.error(
|
|
1661
|
+
console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${err}`));
|
|
1626
1662
|
return {
|
|
1627
1663
|
apiTypesPath: "",
|
|
1628
1664
|
zipTypesPath: "",
|
|
@@ -1688,20 +1724,56 @@ var defaultOptions2 = {
|
|
|
1688
1724
|
extractRemoteTypes: false,
|
|
1689
1725
|
extractThirdParty: false
|
|
1690
1726
|
};
|
|
1691
|
-
|
|
1727
|
+
function getEffectiveRootDir(parsedCommandLine) {
|
|
1728
|
+
const compilerOptions = parsedCommandLine.options;
|
|
1729
|
+
if (compilerOptions.rootDir) {
|
|
1730
|
+
return compilerOptions.rootDir;
|
|
1731
|
+
}
|
|
1732
|
+
const files = parsedCommandLine.fileNames;
|
|
1733
|
+
if (files.length > 0) {
|
|
1734
|
+
const commonRoot = files.map((file) => (0, import_path5.dirname)(file)).reduce((commonPath, fileDir) => {
|
|
1735
|
+
while (!fileDir.startsWith(commonPath)) {
|
|
1736
|
+
commonPath = (0, import_path5.dirname)(commonPath);
|
|
1737
|
+
}
|
|
1738
|
+
return commonPath;
|
|
1739
|
+
}, files[0]);
|
|
1740
|
+
return commonRoot;
|
|
1741
|
+
}
|
|
1742
|
+
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
1743
|
+
}
|
|
1744
|
+
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
1745
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
|
|
1692
1746
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
1693
|
-
const readResult =
|
|
1747
|
+
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
1694
1748
|
if (readResult.error) {
|
|
1695
1749
|
throw new Error(readResult.error.messageText.toString());
|
|
1696
1750
|
}
|
|
1697
|
-
const
|
|
1751
|
+
const rawTsConfigJson = readResult.config;
|
|
1752
|
+
const configContent = import_typescript.default.parseJsonConfigFileContent(rawTsConfigJson, import_typescript.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
|
|
1753
|
+
const rootDir = getEffectiveRootDir(configContent);
|
|
1698
1754
|
const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1699
|
-
|
|
1755
|
+
const defaultCompilerOptions = {
|
|
1756
|
+
rootDir,
|
|
1700
1757
|
emitDeclarationOnly: true,
|
|
1701
1758
|
noEmit: false,
|
|
1702
1759
|
declaration: true,
|
|
1703
1760
|
outDir
|
|
1704
|
-
}
|
|
1761
|
+
};
|
|
1762
|
+
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
1763
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
1764
|
+
const filesToCompile = [
|
|
1765
|
+
...Object.values(mapComponentsToExpose),
|
|
1766
|
+
...additionalFilesToCompile
|
|
1767
|
+
];
|
|
1768
|
+
rawTsConfigJson.include = [];
|
|
1769
|
+
rawTsConfigJson.files = filesToCompile;
|
|
1770
|
+
rawTsConfigJson.exclude = [];
|
|
1771
|
+
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
1772
|
+
const extendsPath = rawTsConfigJson.extends;
|
|
1773
|
+
if (extendsPath && extendsPath.startsWith(".")) {
|
|
1774
|
+
rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
|
|
1775
|
+
}
|
|
1776
|
+
return rawTsConfigJson;
|
|
1705
1777
|
}, "readTsConfig");
|
|
1706
1778
|
var TS_EXTENSIONS = [
|
|
1707
1779
|
"ts",
|
|
@@ -1739,7 +1811,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
1739
1811
|
validateOptions(options);
|
|
1740
1812
|
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1741
1813
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
1742
|
-
const tsConfig = readTsConfig(remoteOptions);
|
|
1814
|
+
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
1743
1815
|
return {
|
|
1744
1816
|
tsConfig,
|
|
1745
1817
|
mapComponentsToExpose,
|
|
@@ -1925,7 +1997,7 @@ __name(wrapRpc, "wrapRpc");
|
|
|
1925
1997
|
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
1926
1998
|
var child_process = __toESM(require("child_process"));
|
|
1927
1999
|
var process3 = __toESM(require("process"));
|
|
1928
|
-
var
|
|
2000
|
+
var import_crypto2 = require("crypto");
|
|
1929
2001
|
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
1930
2002
|
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
1931
2003
|
const options = {
|
|
@@ -1946,7 +2018,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1946
2018
|
];
|
|
1947
2019
|
}
|
|
1948
2020
|
let childProcess, remoteMethod;
|
|
1949
|
-
const id = (0,
|
|
2021
|
+
const id = (0, import_crypto2.randomUUID)();
|
|
1950
2022
|
const worker = {
|
|
1951
2023
|
connect(...args) {
|
|
1952
2024
|
if (childProcess && !childProcess.connected) {
|
|
@@ -2135,7 +2207,7 @@ function createDevWorker(options) {
|
|
|
2135
2207
|
__name(createDevWorker, "createDevWorker");
|
|
2136
2208
|
|
|
2137
2209
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
2138
|
-
var
|
|
2210
|
+
var import_sdk6 = require("@module-federation/sdk");
|
|
2139
2211
|
var import_path8 = __toESM(require("path"));
|
|
2140
2212
|
|
|
2141
2213
|
// packages/dts-plugin/src/plugins/utils.ts
|
|
@@ -2153,7 +2225,7 @@ var PROCESS_EXIT_CODE;
|
|
|
2153
2225
|
function ensureTempDir(filePath) {
|
|
2154
2226
|
try {
|
|
2155
2227
|
const dir = import_path8.default.dirname(filePath);
|
|
2156
|
-
|
|
2228
|
+
import_fs_extra3.default.ensureDirSync(dir);
|
|
2157
2229
|
} catch (_err) {
|
|
2158
2230
|
}
|
|
2159
2231
|
}
|
|
@@ -2167,9 +2239,9 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2167
2239
|
}
|
|
2168
2240
|
static ensureLiveReloadEntry(options, filePath) {
|
|
2169
2241
|
ensureTempDir(filePath);
|
|
2170
|
-
const liveReloadEntry =
|
|
2242
|
+
const liveReloadEntry = import_fs_extra3.default.readFileSync(import_path8.default.join(__dirname, "./iife/launch-web-client.js")).toString("utf-8");
|
|
2171
2243
|
const liveReloadEntryWithOptions = liveReloadEntry.replace(WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
|
|
2172
|
-
|
|
2244
|
+
import_fs_extra3.default.writeFileSync(filePath, liveReloadEntryWithOptions);
|
|
2173
2245
|
}
|
|
2174
2246
|
_stopWhenSIGTERMOrSIGINT() {
|
|
2175
2247
|
process.on("SIGTERM", () => {
|
|
@@ -2207,7 +2279,7 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2207
2279
|
new compiler.webpack.DefinePlugin({
|
|
2208
2280
|
FEDERATION_IPV4: JSON.stringify(getIPV4())
|
|
2209
2281
|
}).apply(compiler);
|
|
2210
|
-
const normalizedDev = (0,
|
|
2282
|
+
const normalizedDev = (0, import_sdk6.normalizeOptions)(true, {
|
|
2211
2283
|
disableLiveReload: true,
|
|
2212
2284
|
disableHotTypesReload: false,
|
|
2213
2285
|
disableDynamicRemoteTypeHints: false
|
|
@@ -2228,8 +2300,8 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2228
2300
|
this._options.runtimePlugins.push(import_path8.default.resolve(__dirname, "dynamic-remote-type-hints-plugin.js"));
|
|
2229
2301
|
}
|
|
2230
2302
|
if (!normalizedDev.disableLiveReload) {
|
|
2231
|
-
const
|
|
2232
|
-
const filepath = import_path8.default.join(
|
|
2303
|
+
const TEMP_DIR2 = import_path8.default.join(`${process.cwd()}/node_modules`, import_sdk6.TEMP_DIR);
|
|
2304
|
+
const filepath = import_path8.default.join(TEMP_DIR2, `live-reload.js`);
|
|
2233
2305
|
_DevPlugin.ensureLiveReloadEntry({
|
|
2234
2306
|
name
|
|
2235
2307
|
}, filepath);
|
|
@@ -2245,13 +2317,13 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2245
2317
|
const defaultConsumeTypes = {
|
|
2246
2318
|
consumeAPITypes: true
|
|
2247
2319
|
};
|
|
2248
|
-
const normalizedDtsOptions = (0,
|
|
2320
|
+
const normalizedDtsOptions = (0, import_sdk6.normalizeOptions)(isTSProject(dts, compiler.context), {
|
|
2249
2321
|
// remote types dist(.dev-server) not be used currently, so no need to set extractThirdParty etc
|
|
2250
2322
|
generateTypes: defaultGenerateTypes,
|
|
2251
2323
|
consumeTypes: defaultConsumeTypes,
|
|
2252
2324
|
extraOptions: {}
|
|
2253
2325
|
}, "mfOptions.dts")(dts);
|
|
2254
|
-
const normalizedGenerateTypes = (0,
|
|
2326
|
+
const normalizedGenerateTypes = (0, import_sdk6.normalizeOptions)(Boolean(normalizedDtsOptions), defaultGenerateTypes, "mfOptions.dts.generateTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes);
|
|
2255
2327
|
const remote = normalizedGenerateTypes === false ? void 0 : __spreadProps(__spreadValues({
|
|
2256
2328
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2257
2329
|
context: compiler.context,
|
|
@@ -2260,7 +2332,7 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2260
2332
|
}, normalizedGenerateTypes), {
|
|
2261
2333
|
typesFolder: `.dev-server`
|
|
2262
2334
|
});
|
|
2263
|
-
const normalizedConsumeTypes = (0,
|
|
2335
|
+
const normalizedConsumeTypes = (0, import_sdk6.normalizeOptions)(Boolean(normalizedDtsOptions), defaultConsumeTypes, "mfOptions.dts.consumeTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.consumeTypes);
|
|
2264
2336
|
const host = normalizedConsumeTypes === false ? void 0 : __spreadValues({
|
|
2265
2337
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2266
2338
|
context: compiler.context,
|
|
@@ -2292,10 +2364,10 @@ __name(_DevPlugin, "DevPlugin");
|
|
|
2292
2364
|
var DevPlugin = _DevPlugin;
|
|
2293
2365
|
|
|
2294
2366
|
// packages/dts-plugin/src/plugins/TypesPlugin.ts
|
|
2295
|
-
var
|
|
2367
|
+
var import_sdk9 = require("@module-federation/sdk");
|
|
2296
2368
|
|
|
2297
2369
|
// packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
|
|
2298
|
-
var
|
|
2370
|
+
var import_sdk7 = require("@module-federation/sdk");
|
|
2299
2371
|
var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
2300
2372
|
constructor(pluginOptions, dtsOptions, defaultOptions3) {
|
|
2301
2373
|
__publicField(this, "pluginOptions");
|
|
@@ -2307,7 +2379,7 @@ var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
|
2307
2379
|
}
|
|
2308
2380
|
apply(compiler) {
|
|
2309
2381
|
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions } = this;
|
|
2310
|
-
const normalizedConsumeTypes = (0,
|
|
2382
|
+
const normalizedConsumeTypes = (0, import_sdk7.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
2311
2383
|
if (!normalizedConsumeTypes) {
|
|
2312
2384
|
return;
|
|
2313
2385
|
}
|
|
@@ -2328,7 +2400,7 @@ var ConsumeTypesPlugin = _ConsumeTypesPlugin;
|
|
|
2328
2400
|
|
|
2329
2401
|
// packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
|
|
2330
2402
|
var import_fs4 = __toESM(require("fs"));
|
|
2331
|
-
var
|
|
2403
|
+
var import_sdk8 = require("@module-federation/sdk");
|
|
2332
2404
|
var import_path9 = __toESM(require("path"));
|
|
2333
2405
|
var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
2334
2406
|
constructor(pluginOptions, dtsOptions, defaultOptions3) {
|
|
@@ -2341,7 +2413,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2341
2413
|
}
|
|
2342
2414
|
apply(compiler) {
|
|
2343
2415
|
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions } = this;
|
|
2344
|
-
const normalizedGenerateTypes = (0,
|
|
2416
|
+
const normalizedGenerateTypes = (0, import_sdk8.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
|
|
2345
2417
|
if (!normalizedGenerateTypes) {
|
|
2346
2418
|
return;
|
|
2347
2419
|
}
|
|
@@ -2387,10 +2459,9 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2387
2459
|
yield generateTypesFn(finalOptions);
|
|
2388
2460
|
const config = finalOptions.remote.moduleFederationConfig;
|
|
2389
2461
|
let zipPrefix = "";
|
|
2390
|
-
|
|
2391
|
-
if (isManifestObject && config.manifest.filePath) {
|
|
2462
|
+
if (typeof config.manifest === "object" && config.manifest.filePath) {
|
|
2392
2463
|
zipPrefix = config.manifest.filePath;
|
|
2393
|
-
} else if (
|
|
2464
|
+
} else if (typeof config.manifest === "object" && config.manifest.fileName) {
|
|
2394
2465
|
zipPrefix = import_path9.default.dirname(config.manifest.fileName);
|
|
2395
2466
|
} else if (config.filename) {
|
|
2396
2467
|
zipPrefix = import_path9.default.dirname(config.filename);
|
|
@@ -2431,7 +2502,7 @@ var TypesPlugin = (_a3 = class {
|
|
|
2431
2502
|
abortOnError: false,
|
|
2432
2503
|
consumeAPITypes: true
|
|
2433
2504
|
};
|
|
2434
|
-
const normalizedDtsOptions = (0,
|
|
2505
|
+
const normalizedDtsOptions = (0, import_sdk9.normalizeOptions)(isTSProject(options.dts, compiler.context), {
|
|
2435
2506
|
generateTypes: defaultGenerateTypes,
|
|
2436
2507
|
consumeTypes: defaultConsumeTypes,
|
|
2437
2508
|
extraOptions: {}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/dts-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -63,11 +63,14 @@
|
|
|
63
63
|
"@types/ws": "8.5.10",
|
|
64
64
|
"@types/koa": "2.11.2",
|
|
65
65
|
"@types/node-schedule": "2.1.7",
|
|
66
|
-
"@module-federation/runtime": "workspace:*"
|
|
66
|
+
"@module-federation/runtime": "workspace:*",
|
|
67
|
+
"vue": "^3.4.29",
|
|
68
|
+
"@vue/tsconfig": "^0.5.1",
|
|
69
|
+
"vue-tsc": "^2.0.26"
|
|
67
70
|
},
|
|
68
71
|
"peerDependencies": {
|
|
69
72
|
"typescript": "^4.9.0 || ^5.0.0",
|
|
70
|
-
"vue-tsc": "
|
|
73
|
+
"vue-tsc": ">=1.0.24"
|
|
71
74
|
},
|
|
72
75
|
"peerDependenciesMeta": {
|
|
73
76
|
"vue-tsc": {
|