@module-federation/dts-plugin 0.21.3 → 0.21.5
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 +24 -0
- package/dist/core.d.mts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +160 -143
- package/dist/esm/{chunk-2GDMDG2O.js → chunk-N7GTIQUA.js} +1 -1
- package/dist/esm/{chunk-ETMHGGQH.js → chunk-RWXNVNFM.js} +164 -149
- 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 +8 -19
- package/dist/fork-dev-worker.js +167 -138
- package/dist/fork-generate-dts.js +160 -131
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +166 -160
- package/dist/package.json +1 -1
- package/dist/{utils-BjKKtOcx.d.ts → utils-DxGrqb9N.d.ts} +0 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -133,7 +133,7 @@ var import_path2 = require("path");
|
|
|
133
133
|
var import_promises2 = require("fs/promises");
|
|
134
134
|
|
|
135
135
|
// src/core/lib/typeScriptCompiler.ts
|
|
136
|
-
var
|
|
136
|
+
var import_fs_extra2 = require("fs-extra");
|
|
137
137
|
var import_crypto = __toESM(require("crypto"));
|
|
138
138
|
var import_promises = require("fs/promises");
|
|
139
139
|
var import_path = require("path");
|
|
@@ -141,130 +141,7 @@ var import_error_codes = require("@module-federation/error-codes");
|
|
|
141
141
|
var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
142
142
|
var import_child_process = require("child_process");
|
|
143
143
|
var import_util = __toESM(require("util"));
|
|
144
|
-
var
|
|
145
|
-
var STARTS_WITH_SLASH = /^\//;
|
|
146
|
-
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
147
|
-
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
148
|
-
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
149
|
-
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
150
|
-
function writeTempTsConfig(tsConfig, context, name, cwd) {
|
|
151
|
-
const createHash = /* @__PURE__ */ __name((contents) => {
|
|
152
|
-
return import_crypto.default.createHash("md5").update(contents).digest("hex");
|
|
153
|
-
}, "createHash");
|
|
154
|
-
const hash = createHash(`${JSON.stringify(tsConfig)}${name}${Date.now()}`);
|
|
155
|
-
const tempTsConfigJsonPath = (0, import_path.resolve)(cwd != null ? cwd : context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${hash}.json`);
|
|
156
|
-
(0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
|
|
157
|
-
(0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
158
|
-
return tempTsConfigJsonPath;
|
|
159
|
-
}
|
|
160
|
-
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
161
|
-
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
162
|
-
const vueExt = ".vue";
|
|
163
|
-
const ext = (0, import_path.extname)(f);
|
|
164
|
-
if (ext === vueExt) {
|
|
165
|
-
return f;
|
|
166
|
-
}
|
|
167
|
-
const regexPattern = new RegExp(`\\${ext}$`);
|
|
168
|
-
return f.replace(regexPattern, "");
|
|
169
|
-
}, "removeExt");
|
|
170
|
-
function getExposeKey(options) {
|
|
171
|
-
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
172
|
-
const relativeFilePath = (0, import_path.relative)(outDir, filePath.replace(new RegExp(`\\.d.ts$`), ""));
|
|
173
|
-
return mapExposeToEntry[relativeFilePath];
|
|
174
|
-
}
|
|
175
|
-
__name(getExposeKey, "getExposeKey");
|
|
176
|
-
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
177
|
-
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
178
|
-
if (!(0, import_fs_extra.existsSync)(filePath)) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
const stats = yield (0, import_promises.stat)(filePath);
|
|
182
|
-
if (stats.isDirectory()) {
|
|
183
|
-
const files = yield (0, import_promises.readdir)(filePath);
|
|
184
|
-
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
185
|
-
filePath: (0, import_path.join)(filePath, file)
|
|
186
|
-
}))));
|
|
187
|
-
} else if (filePath.endsWith(".d.ts")) {
|
|
188
|
-
const exposeKey = getExposeKey({
|
|
189
|
-
filePath,
|
|
190
|
-
rootDir,
|
|
191
|
-
outDir,
|
|
192
|
-
mapExposeToEntry
|
|
193
|
-
});
|
|
194
|
-
if (exposeKey) {
|
|
195
|
-
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
196
|
-
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
197
|
-
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
198
|
-
const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
|
|
199
|
-
(0, import_fs_extra.ensureDirSync)(mfeTypeEntryDirectory);
|
|
200
|
-
yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
201
|
-
export { default } from './${relativePathToOutput}';`);
|
|
202
|
-
}
|
|
203
|
-
const content = yield (0, import_promises.readFile)(filePath, "utf8");
|
|
204
|
-
cb(content);
|
|
205
|
-
}
|
|
206
|
-
}), "processTypesFile");
|
|
207
|
-
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
208
|
-
var _a3, _b, _c, _d;
|
|
209
|
-
if (!Object.keys(mapComponentsToExpose).length) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const { compilerOptions } = tsConfig;
|
|
213
|
-
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf", typeof remoteOptions.moduleFederationConfig.dts !== "boolean" ? (_b = (_a3 = remoteOptions.moduleFederationConfig.dts) == null ? void 0 : _a3.cwd) != null ? _b : void 0 : void 0);
|
|
214
|
-
try {
|
|
215
|
-
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
216
|
-
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor({
|
|
217
|
-
destDir: (0, import_path.resolve)(mfTypePath, "node_modules"),
|
|
218
|
-
context: remoteOptions.context,
|
|
219
|
-
exclude: typeof remoteOptions.extractThirdParty === "object" ? remoteOptions.extractThirdParty.exclude : void 0
|
|
220
|
-
});
|
|
221
|
-
const execPromise = import_util.default.promisify(import_child_process.exec);
|
|
222
|
-
const cmd = `npx ${remoteOptions.compilerInstance} --project '${tempTsConfigJsonPath}'`;
|
|
223
|
-
try {
|
|
224
|
-
yield execPromise(cmd, {
|
|
225
|
-
cwd: typeof remoteOptions.moduleFederationConfig.dts !== "boolean" ? (_d = (_c = remoteOptions.moduleFederationConfig.dts) == null ? void 0 : _c.cwd) != null ? _d : void 0 : void 0
|
|
226
|
-
});
|
|
227
|
-
} catch (err) {
|
|
228
|
-
if (compilerOptions.tsBuildInfoFile) {
|
|
229
|
-
try {
|
|
230
|
-
yield (0, import_promises.rm)(compilerOptions.tsBuildInfoFile);
|
|
231
|
-
} catch (e) {
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
throw new Error((0, import_error_codes.getShortErrorMsg)(import_error_codes.TYPE_001, import_error_codes.typeDescMap, {
|
|
235
|
-
cmd
|
|
236
|
-
}));
|
|
237
|
-
}
|
|
238
|
-
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
239
|
-
const normalizedFileName = (0, import_path.normalize)(filename);
|
|
240
|
-
let relativeFileName = "";
|
|
241
|
-
if ((0, import_path.isAbsolute)(normalizedFileName)) {
|
|
242
|
-
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
243
|
-
} else {
|
|
244
|
-
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
|
|
245
|
-
}
|
|
246
|
-
return [
|
|
247
|
-
removeExt(relativeFileName),
|
|
248
|
-
exposed
|
|
249
|
-
];
|
|
250
|
-
}));
|
|
251
|
-
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
252
|
-
yield processTypesFile({
|
|
253
|
-
outDir: compilerOptions.outDir,
|
|
254
|
-
filePath: compilerOptions.outDir,
|
|
255
|
-
rootDir: compilerOptions.rootDir,
|
|
256
|
-
mfTypePath,
|
|
257
|
-
cb,
|
|
258
|
-
mapExposeToEntry
|
|
259
|
-
});
|
|
260
|
-
if (remoteOptions.extractThirdParty) {
|
|
261
|
-
yield thirdPartyExtractor.copyDts();
|
|
262
|
-
}
|
|
263
|
-
yield (0, import_promises.rm)(tempTsConfigJsonPath);
|
|
264
|
-
} catch (err) {
|
|
265
|
-
throw err;
|
|
266
|
-
}
|
|
267
|
-
}), "compileTs");
|
|
144
|
+
var import_sdk3 = require("@module-federation/sdk");
|
|
268
145
|
|
|
269
146
|
// src/server/message/Message.ts
|
|
270
147
|
var _Message = class _Message {
|
|
@@ -337,7 +214,7 @@ __name(_FetchTypesAPI, "FetchTypesAPI");
|
|
|
337
214
|
var FetchTypesAPI = _FetchTypesAPI;
|
|
338
215
|
|
|
339
216
|
// src/server/utils/index.ts
|
|
340
|
-
var
|
|
217
|
+
var import_sdk2 = require("@module-federation/sdk");
|
|
341
218
|
|
|
342
219
|
// src/server/utils/logTransform.ts
|
|
343
220
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -376,7 +253,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
|
|
|
376
253
|
var BrokerExitLog = _BrokerExitLog;
|
|
377
254
|
|
|
378
255
|
// src/server/utils/log.ts
|
|
379
|
-
var
|
|
256
|
+
var import_sdk = require("@module-federation/sdk");
|
|
380
257
|
var log4js = __toESM(require("log4js"));
|
|
381
258
|
|
|
382
259
|
// src/server/constant.ts
|
|
@@ -391,7 +268,7 @@ var UpdateMode;
|
|
|
391
268
|
})(UpdateMode || (UpdateMode = {}));
|
|
392
269
|
|
|
393
270
|
// src/server/utils/log.ts
|
|
394
|
-
var logger = (0,
|
|
271
|
+
var logger = (0, import_sdk.createLogger)(`[ ${MF_SERVER_IDENTIFIER} ]`);
|
|
395
272
|
function fileLog(msg, module2, level) {
|
|
396
273
|
var _a3, _b;
|
|
397
274
|
if (!((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3["FEDERATION_DEBUG"])) {
|
|
@@ -466,7 +343,7 @@ var getIPV4 = /* @__PURE__ */ __name(() => {
|
|
|
466
343
|
// src/server/utils/index.ts
|
|
467
344
|
function getIdentifier(options) {
|
|
468
345
|
const { ip, name } = options;
|
|
469
|
-
return `mf ${
|
|
346
|
+
return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
|
|
470
347
|
}
|
|
471
348
|
__name(getIdentifier, "getIdentifier");
|
|
472
349
|
|
|
@@ -1168,9 +1045,157 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
|
1168
1045
|
var Broker = _Broker;
|
|
1169
1046
|
|
|
1170
1047
|
// src/server/createKoaServer.ts
|
|
1171
|
-
var
|
|
1048
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
1172
1049
|
var import_koa = __toESM(require("koa"));
|
|
1173
1050
|
|
|
1051
|
+
// src/core/lib/typeScriptCompiler.ts
|
|
1052
|
+
var STARTS_WITH_SLASH = /^\//;
|
|
1053
|
+
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
1054
|
+
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
1055
|
+
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
1056
|
+
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
1057
|
+
function writeTempTsConfig(tsConfig, context, name, cwd) {
|
|
1058
|
+
const createHash = /* @__PURE__ */ __name((contents) => {
|
|
1059
|
+
return import_crypto.default.createHash("md5").update(contents).digest("hex");
|
|
1060
|
+
}, "createHash");
|
|
1061
|
+
const hash = createHash(`${JSON.stringify(tsConfig)}${name}${Date.now()}`);
|
|
1062
|
+
const tempTsConfigJsonPath = (0, import_path.resolve)(cwd != null ? cwd : context, "node_modules", import_sdk3.TEMP_DIR, `tsconfig.${hash}.json`);
|
|
1063
|
+
(0, import_fs_extra2.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
|
|
1064
|
+
(0, import_fs_extra2.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
1065
|
+
return tempTsConfigJsonPath;
|
|
1066
|
+
}
|
|
1067
|
+
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
1068
|
+
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
1069
|
+
const vueExt = ".vue";
|
|
1070
|
+
const ext = (0, import_path.extname)(f);
|
|
1071
|
+
if (ext === vueExt) {
|
|
1072
|
+
return f;
|
|
1073
|
+
}
|
|
1074
|
+
const regexPattern = new RegExp(`\\${ext}$`);
|
|
1075
|
+
return f.replace(regexPattern, "");
|
|
1076
|
+
}, "removeExt");
|
|
1077
|
+
function getExposeKey(options) {
|
|
1078
|
+
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
1079
|
+
const relativeFilePath = (0, import_path.relative)(outDir, filePath.replace(new RegExp(`\\.d.ts$`), ""));
|
|
1080
|
+
return mapExposeToEntry[relativeFilePath];
|
|
1081
|
+
}
|
|
1082
|
+
__name(getExposeKey, "getExposeKey");
|
|
1083
|
+
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
1084
|
+
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
1085
|
+
if (!(0, import_fs_extra2.existsSync)(filePath)) {
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
const stats = yield (0, import_promises.stat)(filePath);
|
|
1089
|
+
if (stats.isDirectory()) {
|
|
1090
|
+
const files = yield (0, import_promises.readdir)(filePath);
|
|
1091
|
+
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
1092
|
+
filePath: (0, import_path.join)(filePath, file)
|
|
1093
|
+
}))));
|
|
1094
|
+
} else if (filePath.endsWith(".d.ts")) {
|
|
1095
|
+
const exposeKey = getExposeKey({
|
|
1096
|
+
filePath,
|
|
1097
|
+
rootDir,
|
|
1098
|
+
outDir,
|
|
1099
|
+
mapExposeToEntry
|
|
1100
|
+
});
|
|
1101
|
+
if (exposeKey) {
|
|
1102
|
+
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
1103
|
+
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
1104
|
+
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
1105
|
+
const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
|
|
1106
|
+
(0, import_fs_extra2.ensureDirSync)(mfeTypeEntryDirectory);
|
|
1107
|
+
yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
1108
|
+
export { default } from './${relativePathToOutput}';`);
|
|
1109
|
+
}
|
|
1110
|
+
const content = yield (0, import_promises.readFile)(filePath, "utf8");
|
|
1111
|
+
cb(content);
|
|
1112
|
+
}
|
|
1113
|
+
}), "processTypesFile");
|
|
1114
|
+
var getPMFromUserAgent = /* @__PURE__ */ __name(() => {
|
|
1115
|
+
const userAgent = process.env["npm_config_user_agent"];
|
|
1116
|
+
if (userAgent == null) {
|
|
1117
|
+
return "null";
|
|
1118
|
+
}
|
|
1119
|
+
const name = userAgent.split("/")[0];
|
|
1120
|
+
return name;
|
|
1121
|
+
}, "getPMFromUserAgent");
|
|
1122
|
+
var resolvePackageManagerExecutable = /* @__PURE__ */ __name(() => {
|
|
1123
|
+
const pm = getPMFromUserAgent();
|
|
1124
|
+
switch (pm) {
|
|
1125
|
+
case "yarn":
|
|
1126
|
+
return "yarn";
|
|
1127
|
+
case "npm":
|
|
1128
|
+
case "pnpm":
|
|
1129
|
+
default:
|
|
1130
|
+
return "npx";
|
|
1131
|
+
}
|
|
1132
|
+
}, "resolvePackageManagerExecutable");
|
|
1133
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
1134
|
+
var _a3, _b, _c, _d;
|
|
1135
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
const { compilerOptions } = tsConfig;
|
|
1139
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf", typeof remoteOptions.moduleFederationConfig.dts !== "boolean" ? (_b = (_a3 = remoteOptions.moduleFederationConfig.dts) == null ? void 0 : _a3.cwd) != null ? _b : void 0 : void 0);
|
|
1140
|
+
logger.debug(`tempTsConfigJsonPath: ${tempTsConfigJsonPath}`);
|
|
1141
|
+
try {
|
|
1142
|
+
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1143
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor({
|
|
1144
|
+
destDir: (0, import_path.resolve)(mfTypePath, "node_modules"),
|
|
1145
|
+
context: remoteOptions.context,
|
|
1146
|
+
exclude: typeof remoteOptions.extractThirdParty === "object" ? remoteOptions.extractThirdParty.exclude : void 0
|
|
1147
|
+
});
|
|
1148
|
+
const execPromise = import_util.default.promisify(import_child_process.exec);
|
|
1149
|
+
const pmExecutable = resolvePackageManagerExecutable();
|
|
1150
|
+
const cmd = `${pmExecutable} ${remoteOptions.compilerInstance} --project '${tempTsConfigJsonPath}'`;
|
|
1151
|
+
try {
|
|
1152
|
+
yield execPromise(cmd, {
|
|
1153
|
+
cwd: typeof remoteOptions.moduleFederationConfig.dts !== "boolean" ? (_d = (_c = remoteOptions.moduleFederationConfig.dts) == null ? void 0 : _c.cwd) != null ? _d : void 0 : void 0
|
|
1154
|
+
});
|
|
1155
|
+
} catch (err) {
|
|
1156
|
+
if (compilerOptions.tsBuildInfoFile) {
|
|
1157
|
+
try {
|
|
1158
|
+
yield (0, import_promises.rm)(compilerOptions.tsBuildInfoFile);
|
|
1159
|
+
} catch (e) {
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
throw new Error((0, import_error_codes.getShortErrorMsg)(import_error_codes.TYPE_001, import_error_codes.typeDescMap, {
|
|
1163
|
+
cmd
|
|
1164
|
+
}));
|
|
1165
|
+
}
|
|
1166
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
1167
|
+
const normalizedFileName = (0, import_path.normalize)(filename);
|
|
1168
|
+
let relativeFileName = "";
|
|
1169
|
+
if ((0, import_path.isAbsolute)(normalizedFileName)) {
|
|
1170
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
1171
|
+
} else {
|
|
1172
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
|
|
1173
|
+
}
|
|
1174
|
+
return [
|
|
1175
|
+
removeExt(relativeFileName),
|
|
1176
|
+
exposed
|
|
1177
|
+
];
|
|
1178
|
+
}));
|
|
1179
|
+
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
1180
|
+
yield processTypesFile({
|
|
1181
|
+
outDir: compilerOptions.outDir,
|
|
1182
|
+
filePath: compilerOptions.outDir,
|
|
1183
|
+
rootDir: compilerOptions.rootDir,
|
|
1184
|
+
mfTypePath,
|
|
1185
|
+
cb,
|
|
1186
|
+
mapExposeToEntry
|
|
1187
|
+
});
|
|
1188
|
+
if (remoteOptions.extractThirdParty) {
|
|
1189
|
+
yield thirdPartyExtractor.copyDts();
|
|
1190
|
+
}
|
|
1191
|
+
if (remoteOptions.deleteTsConfig) {
|
|
1192
|
+
yield (0, import_promises.rm)(tempTsConfigJsonPath);
|
|
1193
|
+
}
|
|
1194
|
+
} catch (err) {
|
|
1195
|
+
throw err;
|
|
1196
|
+
}
|
|
1197
|
+
}), "compileTs");
|
|
1198
|
+
|
|
1174
1199
|
// src/core/lib/archiveHandler.ts
|
|
1175
1200
|
var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => (0, import_path2.join)(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
|
|
1176
1201
|
var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
@@ -1784,15 +1809,12 @@ var validateOptions = /* @__PURE__ */ __name((options) => {
|
|
|
1784
1809
|
}
|
|
1785
1810
|
}, "validateOptions");
|
|
1786
1811
|
function retrieveTypesAssetsInfo(options) {
|
|
1787
|
-
const { moduleFederationConfig } = options;
|
|
1788
1812
|
let apiTypesPath = "";
|
|
1789
1813
|
let zipTypesPath = "";
|
|
1790
|
-
let zipPrefix = "";
|
|
1791
1814
|
try {
|
|
1792
1815
|
const { tsConfig, remoteOptions, mapComponentsToExpose } = retrieveRemoteConfig(options);
|
|
1793
1816
|
if (!Object.keys(mapComponentsToExpose).length || !tsConfig.files.length) {
|
|
1794
1817
|
return {
|
|
1795
|
-
zipPrefix,
|
|
1796
1818
|
apiTypesPath,
|
|
1797
1819
|
zipTypesPath,
|
|
1798
1820
|
zipName: "",
|
|
@@ -1804,15 +1826,7 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1804
1826
|
if (remoteOptions.generateAPITypes) {
|
|
1805
1827
|
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1806
1828
|
}
|
|
1807
|
-
if (typeof moduleFederationConfig.manifest === "object" && moduleFederationConfig.manifest.filePath) {
|
|
1808
|
-
zipPrefix = moduleFederationConfig.manifest.filePath;
|
|
1809
|
-
} else if (typeof moduleFederationConfig.manifest === "object" && moduleFederationConfig.manifest.fileName) {
|
|
1810
|
-
zipPrefix = import_path4.default.dirname(moduleFederationConfig.manifest.fileName);
|
|
1811
|
-
} else if (moduleFederationConfig.filename) {
|
|
1812
|
-
zipPrefix = import_path4.default.dirname(moduleFederationConfig.filename);
|
|
1813
|
-
}
|
|
1814
1829
|
return {
|
|
1815
|
-
zipPrefix,
|
|
1816
1830
|
apiTypesPath,
|
|
1817
1831
|
zipTypesPath,
|
|
1818
1832
|
zipName: import_path4.default.basename(zipTypesPath),
|
|
@@ -1821,7 +1835,6 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1821
1835
|
} catch (err) {
|
|
1822
1836
|
console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${err}`));
|
|
1823
1837
|
return {
|
|
1824
|
-
zipPrefix,
|
|
1825
1838
|
apiTypesPath: "",
|
|
1826
1839
|
zipTypesPath: "",
|
|
1827
1840
|
zipName: "",
|
|
@@ -1914,7 +1927,8 @@ var defaultOptions2 = {
|
|
|
1914
1927
|
abortOnError: true,
|
|
1915
1928
|
extractRemoteTypes: false,
|
|
1916
1929
|
extractThirdParty: false,
|
|
1917
|
-
outputDir: ""
|
|
1930
|
+
outputDir: "",
|
|
1931
|
+
deleteTsConfig: true
|
|
1918
1932
|
};
|
|
1919
1933
|
function getEffectiveRootDir(parsedCommandLine) {
|
|
1920
1934
|
const compilerOptions = parsedCommandLine.options;
|
|
@@ -1984,6 +1998,9 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
|
|
|
1984
1998
|
rawTsConfigJson.exclude = [];
|
|
1985
1999
|
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
1986
2000
|
rawTsConfigJson.extends = resolvedTsConfigPath;
|
|
2001
|
+
if (rawTsConfigJson.compilerOptions.declarationDir) {
|
|
2002
|
+
delete rawTsConfigJson.compilerOptions.declarationDir;
|
|
2003
|
+
}
|
|
1987
2004
|
return rawTsConfigJson;
|
|
1988
2005
|
}, "readTsConfig");
|
|
1989
2006
|
var TS_EXTENSIONS = [
|
|
@@ -2792,23 +2809,12 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2792
2809
|
dtsManagerOptions
|
|
2793
2810
|
});
|
|
2794
2811
|
import_sdk10.logger.debug("generate types success!");
|
|
2795
|
-
const config = dtsManagerOptions.remote.moduleFederationConfig;
|
|
2796
|
-
let zipPrefix = "";
|
|
2797
|
-
if (typeof config.manifest === "object" && config.manifest.filePath) {
|
|
2798
|
-
zipPrefix = config.manifest.filePath;
|
|
2799
|
-
} else if (typeof config.manifest === "object" && config.manifest.fileName) {
|
|
2800
|
-
zipPrefix = import_path10.default.dirname(config.manifest.fileName);
|
|
2801
|
-
} else if (config.filename) {
|
|
2802
|
-
zipPrefix = import_path10.default.dirname(config.filename);
|
|
2803
|
-
}
|
|
2804
2812
|
if (isProd) {
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
if (zipTypesPath && !compilation.getAsset(zipAssetName) && import_fs4.default.existsSync(zipTypesPath)) {
|
|
2808
|
-
compilation.emitAsset(zipAssetName, new compiler.webpack.sources.RawSource(import_fs4.default.readFileSync(zipTypesPath), false));
|
|
2813
|
+
if (zipTypesPath && !compilation.getAsset(zipName) && import_fs4.default.existsSync(zipTypesPath)) {
|
|
2814
|
+
compilation.emitAsset(zipName, new compiler.webpack.sources.RawSource(import_fs4.default.readFileSync(zipTypesPath), false));
|
|
2809
2815
|
}
|
|
2810
|
-
if (apiTypesPath && !compilation.getAsset(
|
|
2811
|
-
compilation.emitAsset(
|
|
2816
|
+
if (apiTypesPath && !compilation.getAsset(apiFileName) && import_fs4.default.existsSync(apiTypesPath)) {
|
|
2817
|
+
compilation.emitAsset(apiFileName, new compiler.webpack.sources.RawSource(import_fs4.default.readFileSync(apiTypesPath), false));
|
|
2812
2818
|
}
|
|
2813
2819
|
callback();
|
|
2814
2820
|
} else {
|
|
@@ -2817,7 +2823,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2817
2823
|
}, "isEEXIST");
|
|
2818
2824
|
if (zipTypesPath && import_fs4.default.existsSync(zipTypesPath)) {
|
|
2819
2825
|
const zipContent = import_fs4.default.readFileSync(zipTypesPath);
|
|
2820
|
-
const zipOutputPath = import_path10.default.join(compiler.outputPath,
|
|
2826
|
+
const zipOutputPath = import_path10.default.join(compiler.outputPath, zipName);
|
|
2821
2827
|
yield new Promise((resolve5, reject) => {
|
|
2822
2828
|
compiler.outputFileSystem.mkdir(
|
|
2823
2829
|
import_path10.default.dirname(zipOutputPath),
|
|
@@ -2848,7 +2854,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2848
2854
|
}
|
|
2849
2855
|
if (apiTypesPath && import_fs4.default.existsSync(apiTypesPath)) {
|
|
2850
2856
|
const apiContent = import_fs4.default.readFileSync(apiTypesPath);
|
|
2851
|
-
const apiOutputPath = import_path10.default.join(compiler.outputPath,
|
|
2857
|
+
const apiOutputPath = import_path10.default.join(compiler.outputPath, apiFileName);
|
|
2852
2858
|
yield new Promise((resolve5, reject) => {
|
|
2853
2859
|
compiler.outputFileSystem.mkdir(
|
|
2854
2860
|
import_path10.default.dirname(apiOutputPath),
|
package/dist/package.json
CHANGED
|
@@ -5,7 +5,6 @@ import { D as DTSManager } from './DTSManager-b15Gfat3.js';
|
|
|
5
5
|
declare function getDTSManagerConstructor(implementation?: string): typeof DTSManager;
|
|
6
6
|
declare const validateOptions: (options: HostOptions) => void;
|
|
7
7
|
declare function retrieveTypesAssetsInfo(options: RemoteOptions): {
|
|
8
|
-
zipPrefix: string;
|
|
9
8
|
apiTypesPath: string;
|
|
10
9
|
zipTypesPath: string;
|
|
11
10
|
zipName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/dts-plugin",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.5",
|
|
4
4
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"log4js": "6.9.1",
|
|
61
61
|
"node-schedule": "2.1.1",
|
|
62
62
|
"ws": "8.18.0",
|
|
63
|
-
"@module-federation/
|
|
64
|
-
"@module-federation/
|
|
65
|
-
"@module-federation/third-party-dts-extractor": "0.21.
|
|
66
|
-
"@module-federation/error-codes": "0.21.
|
|
63
|
+
"@module-federation/sdk": "0.21.5",
|
|
64
|
+
"@module-federation/managers": "0.21.5",
|
|
65
|
+
"@module-federation/third-party-dts-extractor": "0.21.5",
|
|
66
|
+
"@module-federation/error-codes": "0.21.5"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/ws": "8.5.12",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@vue/tsconfig": "^0.7.0",
|
|
74
74
|
"vue-tsc": "^2.2.10",
|
|
75
75
|
"rimraf": "~6.0.1",
|
|
76
|
-
"@module-federation/runtime": "0.21.
|
|
76
|
+
"@module-federation/runtime": "0.21.5"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"typescript": "^4.9.0 || ^5.0.0",
|