@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/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,130 @@ 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
|
+
yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
174
|
+
export { default } from './${relativePathToOutput}';`);
|
|
175
|
+
}
|
|
176
|
+
const content = yield (0, import_promises.readFile)(filePath, "utf8");
|
|
177
|
+
cb(content);
|
|
178
|
+
}
|
|
179
|
+
}), "processTypesFile");
|
|
180
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
181
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const { compilerOptions } = tsConfig;
|
|
185
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
|
|
186
|
+
try {
|
|
187
|
+
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
188
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
189
|
+
const execPromise = import_util.default.promisify(import_child_process.exec);
|
|
190
|
+
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
|
|
191
|
+
try {
|
|
192
|
+
yield execPromise(cmd);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
throw new Error(`compile TS failed, the original command is '${cmd}'`);
|
|
195
|
+
}
|
|
196
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
197
|
+
const normalizedFileName = (0, import_path.normalize)(filename);
|
|
198
|
+
let relativeFileName = "";
|
|
199
|
+
if ((0, import_path.isAbsolute)(normalizedFileName)) {
|
|
200
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
201
|
+
} else {
|
|
202
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
|
|
154
203
|
}
|
|
204
|
+
return [
|
|
205
|
+
removeExt(relativeFileName),
|
|
206
|
+
exposed
|
|
207
|
+
];
|
|
208
|
+
}));
|
|
209
|
+
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
210
|
+
yield processTypesFile({
|
|
211
|
+
outDir: compilerOptions.outDir,
|
|
212
|
+
filePath: compilerOptions.outDir,
|
|
213
|
+
rootDir: compilerOptions.rootDir,
|
|
214
|
+
mfTypePath,
|
|
215
|
+
cb,
|
|
216
|
+
mapExposeToEntry
|
|
217
|
+
});
|
|
218
|
+
if (remoteOptions.extractThirdParty) {
|
|
219
|
+
yield thirdPartyExtractor.copyDts();
|
|
155
220
|
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
}, "createHost");
|
|
160
|
-
var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
|
|
161
|
-
const vueTypescript = require("vue-tsc");
|
|
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();
|
|
221
|
+
yield (0, import_promises.rm)(tempTsConfigJsonPath);
|
|
222
|
+
} catch (err) {
|
|
223
|
+
throw err;
|
|
192
224
|
}
|
|
193
|
-
}, "compileTs");
|
|
225
|
+
}), "compileTs");
|
|
194
226
|
|
|
195
227
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
196
228
|
var _Message = class _Message {
|
|
@@ -263,7 +295,7 @@ __name(_FetchTypesAPI, "FetchTypesAPI");
|
|
|
263
295
|
var FetchTypesAPI = _FetchTypesAPI;
|
|
264
296
|
|
|
265
297
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
266
|
-
var
|
|
298
|
+
var import_sdk3 = require("@module-federation/sdk");
|
|
267
299
|
|
|
268
300
|
// packages/dts-plugin/src/server/utils/logTransform.ts
|
|
269
301
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -302,7 +334,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
|
|
|
302
334
|
var BrokerExitLog = _BrokerExitLog;
|
|
303
335
|
|
|
304
336
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
305
|
-
var
|
|
337
|
+
var import_sdk2 = require("@module-federation/sdk");
|
|
306
338
|
var log4js = __toESM(require("log4js"));
|
|
307
339
|
var import_chalk2 = __toESM(require("chalk"));
|
|
308
340
|
|
|
@@ -386,7 +418,7 @@ var getIPV4 = /* @__PURE__ */ __name(() => {
|
|
|
386
418
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
387
419
|
function getIdentifier(options) {
|
|
388
420
|
const { ip, name } = options;
|
|
389
|
-
return `mf ${
|
|
421
|
+
return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
|
|
390
422
|
}
|
|
391
423
|
__name(getIdentifier, "getIdentifier");
|
|
392
424
|
|
|
@@ -1098,7 +1130,7 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
|
1098
1130
|
var Broker = _Broker;
|
|
1099
1131
|
|
|
1100
1132
|
// packages/dts-plugin/src/server/createKoaServer.ts
|
|
1101
|
-
var
|
|
1133
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
1102
1134
|
var import_koa = __toESM(require("koa"));
|
|
1103
1135
|
|
|
1104
1136
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
@@ -1129,7 +1161,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1129
1161
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1130
1162
|
try {
|
|
1131
1163
|
if (hostOptions.deleteTypesFolder) {
|
|
1132
|
-
yield (0,
|
|
1164
|
+
yield (0, import_promises2.rm)(destinationPath, {
|
|
1133
1165
|
recursive: true,
|
|
1134
1166
|
force: true
|
|
1135
1167
|
});
|
|
@@ -1157,7 +1189,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1157
1189
|
}, "downloadTypesArchive");
|
|
1158
1190
|
|
|
1159
1191
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1160
|
-
var
|
|
1192
|
+
var import_sdk4 = require("@module-federation/sdk");
|
|
1161
1193
|
var import_managers = require("@module-federation/managers");
|
|
1162
1194
|
var defaultOptions = {
|
|
1163
1195
|
typesFolder: "@mf-types",
|
|
@@ -1184,10 +1216,10 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1184
1216
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1185
1217
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1186
1218
|
let decodedRemote = remote;
|
|
1187
|
-
if (decodedRemote.startsWith(
|
|
1188
|
-
decodedRemote = (0,
|
|
1219
|
+
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1220
|
+
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1189
1221
|
}
|
|
1190
|
-
const parsedInfo = (0,
|
|
1222
|
+
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1191
1223
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1192
1224
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1193
1225
|
return {
|
|
@@ -1314,7 +1346,7 @@ var DTSManager = (_a = class {
|
|
|
1314
1346
|
tsConfig,
|
|
1315
1347
|
mapComponentsToExpose
|
|
1316
1348
|
});
|
|
1317
|
-
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1349
|
+
yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1318
1350
|
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1319
1351
|
let apiTypesPath = "";
|
|
1320
1352
|
if (remoteOptions.generateAPITypes) {
|
|
@@ -1324,7 +1356,7 @@ var DTSManager = (_a = class {
|
|
|
1324
1356
|
}
|
|
1325
1357
|
try {
|
|
1326
1358
|
if (remoteOptions.deleteTypesFolder) {
|
|
1327
|
-
yield (0,
|
|
1359
|
+
yield (0, import_promises3.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1328
1360
|
recursive: true,
|
|
1329
1361
|
force: true
|
|
1330
1362
|
});
|
|
@@ -1334,10 +1366,10 @@ var DTSManager = (_a = class {
|
|
|
1334
1366
|
console.error(err);
|
|
1335
1367
|
}
|
|
1336
1368
|
}
|
|
1337
|
-
console.log(
|
|
1369
|
+
console.log(import_ansi_colors.default.green("Federated types created correctly"));
|
|
1338
1370
|
} catch (error2) {
|
|
1339
1371
|
if (((_a4 = this.options.remote) == null ? void 0 : _a4.abortOnError) === false) {
|
|
1340
|
-
console.error(
|
|
1372
|
+
console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
|
|
1341
1373
|
} else {
|
|
1342
1374
|
throw error2;
|
|
1343
1375
|
}
|
|
@@ -1347,7 +1379,7 @@ var DTSManager = (_a = class {
|
|
|
1347
1379
|
requestRemoteManifest(remoteInfo) {
|
|
1348
1380
|
return __async(this, null, function* () {
|
|
1349
1381
|
try {
|
|
1350
|
-
if (!remoteInfo.url.includes(
|
|
1382
|
+
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1351
1383
|
return remoteInfo;
|
|
1352
1384
|
}
|
|
1353
1385
|
const url = remoteInfo.url;
|
|
@@ -1374,7 +1406,7 @@ var DTSManager = (_a = class {
|
|
|
1374
1406
|
}
|
|
1375
1407
|
}
|
|
1376
1408
|
if (publicPath === "auto") {
|
|
1377
|
-
publicPath = (0,
|
|
1409
|
+
publicPath = (0, import_sdk5.inferAutoPublicPath)(remoteInfo.url);
|
|
1378
1410
|
}
|
|
1379
1411
|
remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1380
1412
|
if (!manifestJson.metaData.types.api) {
|
|
@@ -1509,7 +1541,7 @@ var DTSManager = (_a = class {
|
|
|
1509
1541
|
})));
|
|
1510
1542
|
this.consumeAPITypes(hostOptions);
|
|
1511
1543
|
}
|
|
1512
|
-
console.log(
|
|
1544
|
+
console.log(import_ansi_colors.default.green("Federated types extraction completed"));
|
|
1513
1545
|
} catch (err) {
|
|
1514
1546
|
if (((_a4 = this.options.host) == null ? void 0 : _a4.abortOnError) === false) {
|
|
1515
1547
|
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
@@ -1530,7 +1562,7 @@ var DTSManager = (_a = class {
|
|
|
1530
1562
|
if (!this.options.remote) {
|
|
1531
1563
|
return;
|
|
1532
1564
|
}
|
|
1533
|
-
this.generateTypes();
|
|
1565
|
+
yield this.generateTypes();
|
|
1534
1566
|
} else {
|
|
1535
1567
|
const { remoteAliasMap } = this;
|
|
1536
1568
|
if (!this.options.host) {
|
|
@@ -1622,7 +1654,7 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1622
1654
|
apiFileName: import_path4.default.basename(apiTypesPath)
|
|
1623
1655
|
};
|
|
1624
1656
|
} catch (err) {
|
|
1625
|
-
console.error(
|
|
1657
|
+
console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${err}`));
|
|
1626
1658
|
return {
|
|
1627
1659
|
apiTypesPath: "",
|
|
1628
1660
|
zipTypesPath: "",
|
|
@@ -1688,20 +1720,56 @@ var defaultOptions2 = {
|
|
|
1688
1720
|
extractRemoteTypes: false,
|
|
1689
1721
|
extractThirdParty: false
|
|
1690
1722
|
};
|
|
1691
|
-
|
|
1723
|
+
function getEffectiveRootDir(parsedCommandLine) {
|
|
1724
|
+
const compilerOptions = parsedCommandLine.options;
|
|
1725
|
+
if (compilerOptions.rootDir) {
|
|
1726
|
+
return compilerOptions.rootDir;
|
|
1727
|
+
}
|
|
1728
|
+
const files = parsedCommandLine.fileNames;
|
|
1729
|
+
if (files.length > 0) {
|
|
1730
|
+
const commonRoot = files.map((file) => (0, import_path5.dirname)(file)).reduce((commonPath, fileDir) => {
|
|
1731
|
+
while (!fileDir.startsWith(commonPath)) {
|
|
1732
|
+
commonPath = (0, import_path5.dirname)(commonPath);
|
|
1733
|
+
}
|
|
1734
|
+
return commonPath;
|
|
1735
|
+
}, files[0]);
|
|
1736
|
+
return commonRoot;
|
|
1737
|
+
}
|
|
1738
|
+
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
1739
|
+
}
|
|
1740
|
+
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
1741
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
|
|
1692
1742
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
1693
|
-
const readResult =
|
|
1743
|
+
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
1694
1744
|
if (readResult.error) {
|
|
1695
1745
|
throw new Error(readResult.error.messageText.toString());
|
|
1696
1746
|
}
|
|
1697
|
-
const
|
|
1747
|
+
const rawTsConfigJson = readResult.config;
|
|
1748
|
+
const configContent = import_typescript.default.parseJsonConfigFileContent(rawTsConfigJson, import_typescript.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
|
|
1749
|
+
const rootDir = getEffectiveRootDir(configContent);
|
|
1698
1750
|
const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1699
|
-
|
|
1751
|
+
const defaultCompilerOptions = {
|
|
1752
|
+
rootDir,
|
|
1700
1753
|
emitDeclarationOnly: true,
|
|
1701
1754
|
noEmit: false,
|
|
1702
1755
|
declaration: true,
|
|
1703
1756
|
outDir
|
|
1704
|
-
}
|
|
1757
|
+
};
|
|
1758
|
+
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
1759
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
1760
|
+
const filesToCompile = [
|
|
1761
|
+
...Object.values(mapComponentsToExpose),
|
|
1762
|
+
...additionalFilesToCompile
|
|
1763
|
+
];
|
|
1764
|
+
rawTsConfigJson.include = [];
|
|
1765
|
+
rawTsConfigJson.files = filesToCompile;
|
|
1766
|
+
rawTsConfigJson.exclude = [];
|
|
1767
|
+
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
1768
|
+
const extendsPath = rawTsConfigJson.extends;
|
|
1769
|
+
if (extendsPath && extendsPath.startsWith(".")) {
|
|
1770
|
+
rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
|
|
1771
|
+
}
|
|
1772
|
+
return rawTsConfigJson;
|
|
1705
1773
|
}, "readTsConfig");
|
|
1706
1774
|
var TS_EXTENSIONS = [
|
|
1707
1775
|
"ts",
|
|
@@ -1739,7 +1807,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
1739
1807
|
validateOptions(options);
|
|
1740
1808
|
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1741
1809
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
1742
|
-
const tsConfig = readTsConfig(remoteOptions);
|
|
1810
|
+
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
1743
1811
|
return {
|
|
1744
1812
|
tsConfig,
|
|
1745
1813
|
mapComponentsToExpose,
|
|
@@ -1925,7 +1993,7 @@ __name(wrapRpc, "wrapRpc");
|
|
|
1925
1993
|
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
1926
1994
|
var child_process = __toESM(require("child_process"));
|
|
1927
1995
|
var process3 = __toESM(require("process"));
|
|
1928
|
-
var
|
|
1996
|
+
var import_crypto2 = require("crypto");
|
|
1929
1997
|
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
1930
1998
|
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
1931
1999
|
const options = {
|
|
@@ -1946,7 +2014,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1946
2014
|
];
|
|
1947
2015
|
}
|
|
1948
2016
|
let childProcess, remoteMethod;
|
|
1949
|
-
const id = (0,
|
|
2017
|
+
const id = (0, import_crypto2.randomUUID)();
|
|
1950
2018
|
const worker = {
|
|
1951
2019
|
connect(...args) {
|
|
1952
2020
|
if (childProcess && !childProcess.connected) {
|
|
@@ -2135,7 +2203,7 @@ function createDevWorker(options) {
|
|
|
2135
2203
|
__name(createDevWorker, "createDevWorker");
|
|
2136
2204
|
|
|
2137
2205
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
2138
|
-
var
|
|
2206
|
+
var import_sdk6 = require("@module-federation/sdk");
|
|
2139
2207
|
var import_path8 = __toESM(require("path"));
|
|
2140
2208
|
|
|
2141
2209
|
// packages/dts-plugin/src/plugins/utils.ts
|
|
@@ -2153,7 +2221,7 @@ var PROCESS_EXIT_CODE;
|
|
|
2153
2221
|
function ensureTempDir(filePath) {
|
|
2154
2222
|
try {
|
|
2155
2223
|
const dir = import_path8.default.dirname(filePath);
|
|
2156
|
-
|
|
2224
|
+
import_fs_extra3.default.ensureDirSync(dir);
|
|
2157
2225
|
} catch (_err) {
|
|
2158
2226
|
}
|
|
2159
2227
|
}
|
|
@@ -2167,9 +2235,9 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2167
2235
|
}
|
|
2168
2236
|
static ensureLiveReloadEntry(options, filePath) {
|
|
2169
2237
|
ensureTempDir(filePath);
|
|
2170
|
-
const liveReloadEntry =
|
|
2238
|
+
const liveReloadEntry = import_fs_extra3.default.readFileSync(import_path8.default.join(__dirname, "./iife/launch-web-client.js")).toString("utf-8");
|
|
2171
2239
|
const liveReloadEntryWithOptions = liveReloadEntry.replace(WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
|
|
2172
|
-
|
|
2240
|
+
import_fs_extra3.default.writeFileSync(filePath, liveReloadEntryWithOptions);
|
|
2173
2241
|
}
|
|
2174
2242
|
_stopWhenSIGTERMOrSIGINT() {
|
|
2175
2243
|
process.on("SIGTERM", () => {
|
|
@@ -2207,7 +2275,7 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2207
2275
|
new compiler.webpack.DefinePlugin({
|
|
2208
2276
|
FEDERATION_IPV4: JSON.stringify(getIPV4())
|
|
2209
2277
|
}).apply(compiler);
|
|
2210
|
-
const normalizedDev = (0,
|
|
2278
|
+
const normalizedDev = (0, import_sdk6.normalizeOptions)(true, {
|
|
2211
2279
|
disableLiveReload: true,
|
|
2212
2280
|
disableHotTypesReload: false,
|
|
2213
2281
|
disableDynamicRemoteTypeHints: false
|
|
@@ -2228,8 +2296,8 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2228
2296
|
this._options.runtimePlugins.push(import_path8.default.resolve(__dirname, "dynamic-remote-type-hints-plugin.js"));
|
|
2229
2297
|
}
|
|
2230
2298
|
if (!normalizedDev.disableLiveReload) {
|
|
2231
|
-
const
|
|
2232
|
-
const filepath = import_path8.default.join(
|
|
2299
|
+
const TEMP_DIR2 = import_path8.default.join(`${process.cwd()}/node_modules`, import_sdk6.TEMP_DIR);
|
|
2300
|
+
const filepath = import_path8.default.join(TEMP_DIR2, `live-reload.js`);
|
|
2233
2301
|
_DevPlugin.ensureLiveReloadEntry({
|
|
2234
2302
|
name
|
|
2235
2303
|
}, filepath);
|
|
@@ -2245,13 +2313,13 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2245
2313
|
const defaultConsumeTypes = {
|
|
2246
2314
|
consumeAPITypes: true
|
|
2247
2315
|
};
|
|
2248
|
-
const normalizedDtsOptions = (0,
|
|
2316
|
+
const normalizedDtsOptions = (0, import_sdk6.normalizeOptions)(isTSProject(dts, compiler.context), {
|
|
2249
2317
|
// remote types dist(.dev-server) not be used currently, so no need to set extractThirdParty etc
|
|
2250
2318
|
generateTypes: defaultGenerateTypes,
|
|
2251
2319
|
consumeTypes: defaultConsumeTypes,
|
|
2252
2320
|
extraOptions: {}
|
|
2253
2321
|
}, "mfOptions.dts")(dts);
|
|
2254
|
-
const normalizedGenerateTypes = (0,
|
|
2322
|
+
const normalizedGenerateTypes = (0, import_sdk6.normalizeOptions)(Boolean(normalizedDtsOptions), defaultGenerateTypes, "mfOptions.dts.generateTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes);
|
|
2255
2323
|
const remote = normalizedGenerateTypes === false ? void 0 : __spreadProps(__spreadValues({
|
|
2256
2324
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2257
2325
|
context: compiler.context,
|
|
@@ -2260,7 +2328,7 @@ var _DevPlugin = class _DevPlugin {
|
|
|
2260
2328
|
}, normalizedGenerateTypes), {
|
|
2261
2329
|
typesFolder: `.dev-server`
|
|
2262
2330
|
});
|
|
2263
|
-
const normalizedConsumeTypes = (0,
|
|
2331
|
+
const normalizedConsumeTypes = (0, import_sdk6.normalizeOptions)(Boolean(normalizedDtsOptions), defaultConsumeTypes, "mfOptions.dts.consumeTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.consumeTypes);
|
|
2264
2332
|
const host = normalizedConsumeTypes === false ? void 0 : __spreadValues({
|
|
2265
2333
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2266
2334
|
context: compiler.context,
|
|
@@ -2292,10 +2360,10 @@ __name(_DevPlugin, "DevPlugin");
|
|
|
2292
2360
|
var DevPlugin = _DevPlugin;
|
|
2293
2361
|
|
|
2294
2362
|
// packages/dts-plugin/src/plugins/TypesPlugin.ts
|
|
2295
|
-
var
|
|
2363
|
+
var import_sdk9 = require("@module-federation/sdk");
|
|
2296
2364
|
|
|
2297
2365
|
// packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
|
|
2298
|
-
var
|
|
2366
|
+
var import_sdk7 = require("@module-federation/sdk");
|
|
2299
2367
|
var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
2300
2368
|
constructor(pluginOptions, dtsOptions, defaultOptions3) {
|
|
2301
2369
|
__publicField(this, "pluginOptions");
|
|
@@ -2307,7 +2375,7 @@ var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
|
2307
2375
|
}
|
|
2308
2376
|
apply(compiler) {
|
|
2309
2377
|
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions } = this;
|
|
2310
|
-
const normalizedConsumeTypes = (0,
|
|
2378
|
+
const normalizedConsumeTypes = (0, import_sdk7.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
2311
2379
|
if (!normalizedConsumeTypes) {
|
|
2312
2380
|
return;
|
|
2313
2381
|
}
|
|
@@ -2328,7 +2396,7 @@ var ConsumeTypesPlugin = _ConsumeTypesPlugin;
|
|
|
2328
2396
|
|
|
2329
2397
|
// packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
|
|
2330
2398
|
var import_fs4 = __toESM(require("fs"));
|
|
2331
|
-
var
|
|
2399
|
+
var import_sdk8 = require("@module-federation/sdk");
|
|
2332
2400
|
var import_path9 = __toESM(require("path"));
|
|
2333
2401
|
var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
2334
2402
|
constructor(pluginOptions, dtsOptions, defaultOptions3) {
|
|
@@ -2341,7 +2409,7 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2341
2409
|
}
|
|
2342
2410
|
apply(compiler) {
|
|
2343
2411
|
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions } = this;
|
|
2344
|
-
const normalizedGenerateTypes = (0,
|
|
2412
|
+
const normalizedGenerateTypes = (0, import_sdk8.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
|
|
2345
2413
|
if (!normalizedGenerateTypes) {
|
|
2346
2414
|
return;
|
|
2347
2415
|
}
|
|
@@ -2387,10 +2455,9 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
|
2387
2455
|
yield generateTypesFn(finalOptions);
|
|
2388
2456
|
const config = finalOptions.remote.moduleFederationConfig;
|
|
2389
2457
|
let zipPrefix = "";
|
|
2390
|
-
|
|
2391
|
-
if (isManifestObject && config.manifest.filePath) {
|
|
2458
|
+
if (typeof config.manifest === "object" && config.manifest.filePath) {
|
|
2392
2459
|
zipPrefix = config.manifest.filePath;
|
|
2393
|
-
} else if (
|
|
2460
|
+
} else if (typeof config.manifest === "object" && config.manifest.fileName) {
|
|
2394
2461
|
zipPrefix = import_path9.default.dirname(config.manifest.fileName);
|
|
2395
2462
|
} else if (config.filename) {
|
|
2396
2463
|
zipPrefix = import_path9.default.dirname(config.filename);
|
|
@@ -2431,7 +2498,7 @@ var TypesPlugin = (_a3 = class {
|
|
|
2431
2498
|
abortOnError: false,
|
|
2432
2499
|
consumeAPITypes: true
|
|
2433
2500
|
};
|
|
2434
|
-
const normalizedDtsOptions = (0,
|
|
2501
|
+
const normalizedDtsOptions = (0, import_sdk9.normalizeOptions)(isTSProject(options.dts, compiler.context), {
|
|
2435
2502
|
generateTypes: defaultGenerateTypes,
|
|
2436
2503
|
consumeTypes: defaultConsumeTypes,
|
|
2437
2504
|
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.7",
|
|
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": {
|