@module-federation/dts-plugin 0.2.8 → 0.3.0
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 +14 -0
- package/dist/{DTSManagerOptions-c0728719.d.ts → DTSManagerOptions-7109e8ac.d.ts} +1 -0
- package/dist/{DtsWorker-90454949.d.ts → DtsWorker-17de6ba4.d.ts} +2 -5
- package/dist/core.d.mts +8 -4
- package/dist/core.d.ts +8 -4
- package/dist/core.js +73 -40
- package/dist/dynamic-remote-type-hints-plugin.js +5 -7
- package/dist/esm/{chunk-MQRIERJP.js → chunk-6DND574L.js} +7 -15
- package/dist/esm/chunk-DEW2PNCR.js +283 -0
- package/dist/esm/chunk-HKRTV6ZH.js +900 -0
- package/dist/esm/{chunk-2RCHPGBO.js → chunk-SFEGBRA3.js} +329 -1428
- package/dist/esm/{chunk-G7ONFBMA.js → chunk-XKCIYRDL.js} +1 -1
- package/dist/esm/core.js +11 -11
- package/dist/esm/dynamic-remote-type-hints-plugin.js +2 -2
- package/dist/esm/fork-dev-worker.js +11 -7
- package/dist/esm/fork-generate-dts.js +3 -2
- package/dist/esm/index.js +21 -18
- package/dist/esm/start-broker.js +2 -2
- package/dist/fork-dev-worker.d.mts +1 -1
- package/dist/fork-dev-worker.d.ts +1 -1
- package/dist/fork-dev-worker.js +69 -38
- package/dist/fork-generate-dts.d.mts +2 -2
- package/dist/fork-generate-dts.d.ts +2 -2
- package/dist/fork-generate-dts.js +141 -289
- package/dist/iife/launch-web-client.js +5 -7
- package/dist/index.js +84 -51
- package/dist/package.json +1 -1
- package/dist/start-broker.js +28 -344
- package/package.json +5 -5
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
APIKind,
|
|
3
|
+
Broker,
|
|
4
|
+
LogKind,
|
|
5
|
+
fib,
|
|
6
|
+
fileLog,
|
|
7
|
+
getFreePort,
|
|
8
|
+
getIPV4,
|
|
9
|
+
getIdentifier
|
|
10
|
+
} from "./chunk-HKRTV6ZH.js";
|
|
11
|
+
import {
|
|
3
12
|
AddPublisherAction,
|
|
4
13
|
AddSubscriberAction,
|
|
5
14
|
DEFAULT_TAR_NAME,
|
|
6
|
-
DEFAULT_WEB_SOCKET_PORT,
|
|
7
15
|
ExitPublisherAction,
|
|
8
16
|
ExitSubscriberAction,
|
|
9
|
-
HOST_API_TYPES_FILE_NAME,
|
|
10
17
|
MF_SERVER_IDENTIFIER,
|
|
11
|
-
Message,
|
|
12
18
|
NotifyWebClientAction,
|
|
13
|
-
REMOTE_ALIAS_IDENTIFIER,
|
|
14
|
-
REMOTE_API_TYPES_FILE_NAME,
|
|
15
19
|
UpdateKind,
|
|
16
20
|
UpdateMode,
|
|
17
21
|
UpdatePublisherAction,
|
|
18
|
-
WEB_SOCKET_CONNECT_MAGIC_ID,
|
|
19
22
|
__async,
|
|
20
|
-
__export,
|
|
21
23
|
__name,
|
|
22
24
|
__publicField,
|
|
23
25
|
__require,
|
|
24
26
|
__spreadProps,
|
|
25
27
|
__spreadValues
|
|
26
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-6DND574L.js";
|
|
27
29
|
|
|
28
|
-
// packages/dts-plugin/src/core/
|
|
29
|
-
import { existsSync as existsSync2 } from "fs";
|
|
30
|
-
import
|
|
31
|
-
import {
|
|
32
|
-
import
|
|
30
|
+
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
31
|
+
import { ensureDirSync, writeFileSync, existsSync as existsSync2 } from "fs-extra";
|
|
32
|
+
import crypto from "crypto";
|
|
33
|
+
import { stat, readdir, writeFile, rm as rm3, readFile } from "fs/promises";
|
|
34
|
+
import { dirname as dirname2, join as join3, normalize, relative, resolve as resolve3, sep, extname as extname2, isAbsolute } from "path";
|
|
35
|
+
import { ThirdPartyExtractor as ThirdPartyExtractor2 } from "@module-federation/third-party-dts-extractor";
|
|
36
|
+
import { exec } from "child_process";
|
|
37
|
+
import util from "util";
|
|
38
|
+
import { TEMP_DIR } from "@module-federation/sdk";
|
|
33
39
|
|
|
34
40
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
35
41
|
import fs3 from "fs";
|
|
@@ -39,1011 +45,136 @@ import http from "http";
|
|
|
39
45
|
import https from "https";
|
|
40
46
|
import ansiColors2 from "ansi-colors";
|
|
41
47
|
|
|
42
|
-
// packages/dts-plugin/src/core/
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
import {
|
|
46
|
-
import
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
import { exec } from "child_process";
|
|
63
|
-
import util from "util";
|
|
64
|
-
import { TEMP_DIR } from "@module-federation/sdk";
|
|
65
|
-
var STARTS_WITH_SLASH = /^\//;
|
|
66
|
-
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
67
|
-
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
68
|
-
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
69
|
-
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => join(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
70
|
-
function writeTempTsConfig(tsConfig, context) {
|
|
71
|
-
const tempTsConfigJsonPath = resolve(context, "node_modules", TEMP_DIR, `tsconfig.${randomUUID()}.json`);
|
|
72
|
-
ensureDirSync(dirname(tempTsConfigJsonPath));
|
|
73
|
-
writeFileSync(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
74
|
-
return tempTsConfigJsonPath;
|
|
75
|
-
}
|
|
76
|
-
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
77
|
-
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
78
|
-
const ext = extname(f);
|
|
79
|
-
const regexPattern = new RegExp(`\\${ext}$`);
|
|
80
|
-
return f.replace(regexPattern, "");
|
|
81
|
-
}, "removeExt");
|
|
82
|
-
function getExposeKey(options) {
|
|
83
|
-
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
84
|
-
const relativeFilePath = removeExt(relative(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
|
|
85
|
-
return mapExposeToEntry[relativeFilePath];
|
|
86
|
-
}
|
|
87
|
-
__name(getExposeKey, "getExposeKey");
|
|
88
|
-
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
89
|
-
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
90
|
-
if (!existsSync(filePath)) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const stats = yield stat(filePath);
|
|
94
|
-
if (stats.isDirectory()) {
|
|
95
|
-
const files = yield readdir(filePath);
|
|
96
|
-
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
97
|
-
filePath: join(filePath, file)
|
|
98
|
-
}))));
|
|
99
|
-
} else if (filePath.endsWith(".d.ts")) {
|
|
100
|
-
const exposeKey = getExposeKey({
|
|
101
|
-
filePath,
|
|
102
|
-
rootDir,
|
|
103
|
-
outDir,
|
|
104
|
-
mapExposeToEntry
|
|
105
|
-
});
|
|
106
|
-
if (exposeKey) {
|
|
107
|
-
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
108
|
-
const mfeTypeEntry = join(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
109
|
-
const mfeTypeEntryDirectory = dirname(mfeTypeEntry);
|
|
110
|
-
const relativePathToOutput = relative(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(sep).join("/");
|
|
111
|
-
ensureDirSync(mfeTypeEntryDirectory);
|
|
112
|
-
yield writeFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
113
|
-
export { default } from './${relativePathToOutput}';`);
|
|
114
|
-
}
|
|
115
|
-
const content = yield readFile(filePath, "utf8");
|
|
116
|
-
cb(content);
|
|
117
|
-
}
|
|
118
|
-
}), "processTypesFile");
|
|
119
|
-
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
120
|
-
if (!Object.keys(mapComponentsToExpose).length) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const { compilerOptions } = tsConfig;
|
|
124
|
-
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
|
|
125
|
-
try {
|
|
126
|
-
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
127
|
-
const thirdPartyExtractor = new ThirdPartyExtractor(resolve(mfTypePath, "node_modules"), remoteOptions.context);
|
|
128
|
-
const execPromise = util.promisify(exec);
|
|
129
|
-
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
|
|
130
|
-
try {
|
|
131
|
-
yield execPromise(cmd);
|
|
132
|
-
} catch (err) {
|
|
133
|
-
throw new Error(`compile TS failed, the original command is '${cmd}'`);
|
|
134
|
-
}
|
|
135
|
-
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
136
|
-
const normalizedFileName = normalize(filename);
|
|
137
|
-
let relativeFileName = "";
|
|
138
|
-
if (isAbsolute(normalizedFileName)) {
|
|
139
|
-
relativeFileName = relative(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
140
|
-
} else {
|
|
141
|
-
relativeFileName = relative(tsConfig.compilerOptions.rootDir, resolve(remoteOptions.context, normalizedFileName));
|
|
142
|
-
}
|
|
143
|
-
return [
|
|
144
|
-
removeExt(relativeFileName),
|
|
145
|
-
exposed
|
|
146
|
-
];
|
|
147
|
-
}));
|
|
148
|
-
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
149
|
-
yield processTypesFile({
|
|
150
|
-
outDir: compilerOptions.outDir,
|
|
151
|
-
filePath: compilerOptions.outDir,
|
|
152
|
-
rootDir: compilerOptions.rootDir,
|
|
153
|
-
mfTypePath,
|
|
154
|
-
cb,
|
|
155
|
-
mapExposeToEntry
|
|
156
|
-
});
|
|
157
|
-
if (remoteOptions.extractThirdParty) {
|
|
158
|
-
yield thirdPartyExtractor.copyDts();
|
|
159
|
-
}
|
|
160
|
-
yield rm(tempTsConfigJsonPath);
|
|
161
|
-
} catch (err) {
|
|
162
|
-
if (isDebugMode()) {
|
|
163
|
-
console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
|
|
164
|
-
}
|
|
165
|
-
throw err;
|
|
166
|
-
}
|
|
167
|
-
}), "compileTs");
|
|
168
|
-
|
|
169
|
-
// packages/dts-plugin/src/server/message/API/API.ts
|
|
170
|
-
var APIKind;
|
|
171
|
-
(function(APIKind2) {
|
|
172
|
-
APIKind2["UPDATE_SUBSCRIBER"] = "UPDATE_SUBSCRIBER";
|
|
173
|
-
APIKind2["RELOAD_WEB_CLIENT"] = "RELOAD_WEB_CLIENT";
|
|
174
|
-
APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
175
|
-
})(APIKind || (APIKind = {}));
|
|
176
|
-
var _API = class _API extends Message {
|
|
177
|
-
constructor(content, kind) {
|
|
178
|
-
super("API", kind);
|
|
179
|
-
__publicField(this, "code");
|
|
180
|
-
__publicField(this, "payload");
|
|
181
|
-
const { code, payload } = content;
|
|
182
|
-
this.code = code;
|
|
183
|
-
this.payload = payload;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
__name(_API, "API");
|
|
187
|
-
var API = _API;
|
|
188
|
-
|
|
189
|
-
// packages/dts-plugin/src/server/message/API/UpdateSubscriber.ts
|
|
190
|
-
var _UpdateSubscriberAPI = class _UpdateSubscriberAPI extends API {
|
|
191
|
-
constructor(payload) {
|
|
192
|
-
super({
|
|
193
|
-
code: 0,
|
|
194
|
-
payload
|
|
195
|
-
}, APIKind.UPDATE_SUBSCRIBER);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
__name(_UpdateSubscriberAPI, "UpdateSubscriberAPI");
|
|
199
|
-
var UpdateSubscriberAPI = _UpdateSubscriberAPI;
|
|
200
|
-
|
|
201
|
-
// packages/dts-plugin/src/server/message/API/ReloadWebClient.ts
|
|
202
|
-
var _ReloadWebClientAPI = class _ReloadWebClientAPI extends API {
|
|
203
|
-
constructor(payload) {
|
|
204
|
-
super({
|
|
205
|
-
code: 0,
|
|
206
|
-
payload
|
|
207
|
-
}, APIKind.RELOAD_WEB_CLIENT);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
__name(_ReloadWebClientAPI, "ReloadWebClientAPI");
|
|
211
|
-
var ReloadWebClientAPI = _ReloadWebClientAPI;
|
|
212
|
-
|
|
213
|
-
// packages/dts-plugin/src/server/message/API/FetchTypes.ts
|
|
214
|
-
var _FetchTypesAPI = class _FetchTypesAPI extends API {
|
|
215
|
-
constructor(payload) {
|
|
216
|
-
super({
|
|
217
|
-
code: 0,
|
|
218
|
-
payload
|
|
219
|
-
}, APIKind.FETCH_TYPES);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
__name(_FetchTypesAPI, "FetchTypesAPI");
|
|
223
|
-
var FetchTypesAPI = _FetchTypesAPI;
|
|
224
|
-
|
|
225
|
-
// packages/dts-plugin/src/server/utils/index.ts
|
|
226
|
-
import net from "net";
|
|
227
|
-
import { SEPARATOR } from "@module-federation/sdk";
|
|
228
|
-
|
|
229
|
-
// packages/dts-plugin/src/server/utils/logTransform.ts
|
|
230
|
-
import chalk from "chalk";
|
|
231
|
-
|
|
232
|
-
// packages/dts-plugin/src/server/message/Log/Log.ts
|
|
233
|
-
var LogLevel;
|
|
234
|
-
(function(LogLevel2) {
|
|
235
|
-
LogLevel2["LOG"] = "LOG";
|
|
236
|
-
LogLevel2["WARN"] = "WARN";
|
|
237
|
-
LogLevel2["ERROR"] = "ERROR";
|
|
238
|
-
})(LogLevel || (LogLevel = {}));
|
|
239
|
-
var LogKind;
|
|
240
|
-
(function(LogKind2) {
|
|
241
|
-
LogKind2["BrokerExitLog"] = "BrokerExitLog";
|
|
242
|
-
LogKind2["PublisherRegisteredLog"] = "PublisherRegisteredLog";
|
|
243
|
-
})(LogKind || (LogKind = {}));
|
|
244
|
-
var _Log = class _Log extends Message {
|
|
245
|
-
constructor(level, kind, ignoreVerbose = false) {
|
|
246
|
-
super("Log", kind);
|
|
247
|
-
__publicField(this, "level");
|
|
248
|
-
__publicField(this, "ignoreVerbose", false);
|
|
249
|
-
this.level = level;
|
|
250
|
-
this.ignoreVerbose = ignoreVerbose;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
__name(_Log, "Log");
|
|
254
|
-
var Log = _Log;
|
|
255
|
-
|
|
256
|
-
// packages/dts-plugin/src/server/message/Log/BrokerExitLog.ts
|
|
257
|
-
var _BrokerExitLog = class _BrokerExitLog extends Log {
|
|
258
|
-
constructor() {
|
|
259
|
-
super(LogLevel.LOG, LogKind.BrokerExitLog);
|
|
260
|
-
}
|
|
48
|
+
// packages/dts-plugin/src/core/configurations/remotePlugin.ts
|
|
49
|
+
import { existsSync } from "fs";
|
|
50
|
+
import { dirname, join, resolve, extname } from "path";
|
|
51
|
+
import { utils } from "@module-federation/managers";
|
|
52
|
+
import typescript from "typescript";
|
|
53
|
+
var defaultOptions = {
|
|
54
|
+
tsConfigPath: "./tsconfig.json",
|
|
55
|
+
typesFolder: "@mf-types",
|
|
56
|
+
compiledTypesFolder: "compiled-types",
|
|
57
|
+
hostRemoteTypesFolder: "@mf-types",
|
|
58
|
+
deleteTypesFolder: true,
|
|
59
|
+
additionalFilesToCompile: [],
|
|
60
|
+
compilerInstance: "tsc",
|
|
61
|
+
compileInChildProcess: false,
|
|
62
|
+
implementation: "",
|
|
63
|
+
generateAPITypes: false,
|
|
64
|
+
context: process.cwd(),
|
|
65
|
+
abortOnError: true,
|
|
66
|
+
extractRemoteTypes: false,
|
|
67
|
+
extractThirdParty: false
|
|
261
68
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
import { logger } from "@module-federation/sdk";
|
|
267
|
-
import * as log4js from "log4js";
|
|
268
|
-
import chalk2 from "chalk";
|
|
269
|
-
function fileLog(msg, module, level) {
|
|
270
|
-
var _a3, _b;
|
|
271
|
-
if (!((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3["FEDERATION_DEBUG"])) {
|
|
272
|
-
return;
|
|
69
|
+
function getEffectiveRootDir(parsedCommandLine) {
|
|
70
|
+
const compilerOptions = parsedCommandLine.options;
|
|
71
|
+
if (compilerOptions.rootDir) {
|
|
72
|
+
return compilerOptions.rootDir;
|
|
273
73
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
},
|
|
280
|
-
default: {
|
|
281
|
-
type: "file",
|
|
282
|
-
filename: ".mf/typesGenerate.log"
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
categories: {
|
|
286
|
-
[module]: {
|
|
287
|
-
appenders: [
|
|
288
|
-
module
|
|
289
|
-
],
|
|
290
|
-
level: "error"
|
|
291
|
-
},
|
|
292
|
-
default: {
|
|
293
|
-
appenders: [
|
|
294
|
-
"default"
|
|
295
|
-
],
|
|
296
|
-
level: "trace"
|
|
74
|
+
const files = parsedCommandLine.fileNames;
|
|
75
|
+
if (files.length > 0) {
|
|
76
|
+
const commonRoot = files.map((file) => dirname(file)).reduce((commonPath, fileDir) => {
|
|
77
|
+
while (!fileDir.startsWith(commonPath)) {
|
|
78
|
+
commonPath = dirname(commonPath);
|
|
297
79
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
__name(fileLog, "fileLog");
|
|
305
|
-
function error(error2, action, from) {
|
|
306
|
-
const err = error2 instanceof Error ? error2 : new Error(`${action} error`);
|
|
307
|
-
fileLog(`[${action}] error: ${err}`, from, "fatal");
|
|
308
|
-
return err.toString();
|
|
80
|
+
return commonPath;
|
|
81
|
+
}, files[0]);
|
|
82
|
+
return commonRoot;
|
|
83
|
+
}
|
|
84
|
+
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
309
85
|
}
|
|
310
|
-
__name(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const interfaces = os.networkInterfaces();
|
|
318
|
-
const ipv4Interfaces = [];
|
|
319
|
-
Object.values(interfaces).forEach((detail) => {
|
|
320
|
-
detail == null ? void 0 : detail.forEach((detail2) => {
|
|
321
|
-
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
322
|
-
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
323
|
-
ipv4Interfaces.push(detail2);
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
return ipv4Interfaces;
|
|
328
|
-
} catch (_err) {
|
|
329
|
-
return [];
|
|
86
|
+
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
87
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
|
|
88
|
+
var _a2;
|
|
89
|
+
const resolvedTsConfigPath = resolve(context, tsConfigPath);
|
|
90
|
+
const readResult = typescript.readConfigFile(resolvedTsConfigPath, typescript.sys.readFile);
|
|
91
|
+
if (readResult.error) {
|
|
92
|
+
throw new Error(readResult.error.messageText.toString());
|
|
330
93
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
const
|
|
335
|
-
|
|
94
|
+
const rawTsConfigJson = readResult.config;
|
|
95
|
+
const configContent = typescript.parseJsonConfigFileContent(rawTsConfigJson, typescript.sys, dirname(resolvedTsConfigPath));
|
|
96
|
+
const rootDir = getEffectiveRootDir(configContent);
|
|
97
|
+
const outDir = resolve(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
98
|
+
const defaultCompilerOptions = {
|
|
99
|
+
rootDir,
|
|
100
|
+
emitDeclarationOnly: true,
|
|
101
|
+
noEmit: false,
|
|
102
|
+
declaration: true,
|
|
103
|
+
outDir
|
|
336
104
|
};
|
|
337
|
-
|
|
338
|
-
},
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return `mf ${SEPARATOR}${name}${ip ? `${SEPARATOR}${ip}` : ""}`;
|
|
344
|
-
}
|
|
345
|
-
__name(getIdentifier, "getIdentifier");
|
|
346
|
-
function fib(n) {
|
|
347
|
-
let i = 2;
|
|
348
|
-
const res = [
|
|
349
|
-
0,
|
|
350
|
-
1,
|
|
351
|
-
1
|
|
105
|
+
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
106
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
107
|
+
(_a2 = rawTsConfigJson.compilerOptions) == null ? true : delete _a2.paths;
|
|
108
|
+
const filesToCompile = [
|
|
109
|
+
...Object.values(mapComponentsToExpose),
|
|
110
|
+
...additionalFilesToCompile
|
|
352
111
|
];
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
__name(getFreePort, "getFreePort");
|
|
374
|
-
|
|
375
|
-
// packages/dts-plugin/src/server/Publisher.ts
|
|
376
|
-
var _Publisher = class _Publisher {
|
|
377
|
-
constructor(ctx) {
|
|
378
|
-
__publicField(this, "_ip");
|
|
379
|
-
__publicField(this, "_name");
|
|
380
|
-
__publicField(this, "_remoteTypeTarPath");
|
|
381
|
-
__publicField(this, "_subscribers");
|
|
382
|
-
__publicField(this, "_ws");
|
|
383
|
-
__publicField(this, "dynamicRemoteMap");
|
|
384
|
-
this._name = ctx.name;
|
|
385
|
-
this._ip = ctx.ip;
|
|
386
|
-
this._remoteTypeTarPath = ctx.remoteTypeTarPath;
|
|
387
|
-
this._subscribers = /* @__PURE__ */ new Map();
|
|
388
|
-
this._ws = ctx.ws;
|
|
389
|
-
this.dynamicRemoteMap = /* @__PURE__ */ new Map();
|
|
390
|
-
}
|
|
391
|
-
get identifier() {
|
|
392
|
-
return getIdentifier({
|
|
393
|
-
name: this._name,
|
|
394
|
-
ip: this._ip
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
get name() {
|
|
398
|
-
return this._name;
|
|
399
|
-
}
|
|
400
|
-
get ip() {
|
|
401
|
-
return this._ip;
|
|
402
|
-
}
|
|
403
|
-
get remoteTypeTarPath() {
|
|
404
|
-
return this._remoteTypeTarPath;
|
|
405
|
-
}
|
|
406
|
-
get hasSubscribes() {
|
|
407
|
-
return Boolean(this._subscribers.size);
|
|
408
|
-
}
|
|
409
|
-
get subscribers() {
|
|
410
|
-
return this._subscribers;
|
|
411
|
-
}
|
|
412
|
-
addSubscriber(identifier, subscriber) {
|
|
413
|
-
fileLog(`${this.name} set subscriber: ${identifier}`, "Publisher", "info");
|
|
414
|
-
this._subscribers.set(identifier, subscriber);
|
|
415
|
-
}
|
|
416
|
-
removeSubscriber(identifier) {
|
|
417
|
-
if (this._subscribers.has(identifier)) {
|
|
418
|
-
fileLog(`${this.name} removeSubscriber: ${identifier}`, "Publisher", "warn");
|
|
419
|
-
this._subscribers.delete(identifier);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
notifySubscriber(subscriberIdentifier, options) {
|
|
423
|
-
const subscriber = this._subscribers.get(subscriberIdentifier);
|
|
424
|
-
if (!subscriber) {
|
|
425
|
-
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`, "Publisher", "error");
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
const api = new UpdateSubscriberAPI(options);
|
|
429
|
-
subscriber.send(JSON.stringify(api));
|
|
430
|
-
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(subscriberIdentifier)}, message: ${JSON.stringify(api)}`, "Publisher", "info");
|
|
431
|
-
}
|
|
432
|
-
fetchRemoteTypes(options) {
|
|
433
|
-
fileLog(`[fetchRemoteTypes] ${this.name} fetchRemoteTypes, options: ${JSON.stringify(options)}, ws: ${Boolean(this._ws)}`, "Publisher", "info");
|
|
434
|
-
if (!this._ws) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
const api = new FetchTypesAPI(options);
|
|
438
|
-
this._ws.send(JSON.stringify(api));
|
|
439
|
-
}
|
|
440
|
-
notifySubscribers(options) {
|
|
441
|
-
const api = new UpdateSubscriberAPI(options);
|
|
442
|
-
this.broadcast(api);
|
|
112
|
+
rawTsConfigJson.include = [];
|
|
113
|
+
rawTsConfigJson.files = filesToCompile;
|
|
114
|
+
rawTsConfigJson.exclude = [];
|
|
115
|
+
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
116
|
+
rawTsConfigJson.extends = resolvedTsConfigPath;
|
|
117
|
+
return rawTsConfigJson;
|
|
118
|
+
}, "readTsConfig");
|
|
119
|
+
var TS_EXTENSIONS = [
|
|
120
|
+
"ts",
|
|
121
|
+
"tsx",
|
|
122
|
+
"vue",
|
|
123
|
+
"svelte"
|
|
124
|
+
];
|
|
125
|
+
var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
|
|
126
|
+
if (extname(exposedPath)) {
|
|
127
|
+
return resolve(context, exposedPath);
|
|
443
128
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
subscriber.send(JSON.stringify(message));
|
|
449
|
-
});
|
|
450
|
-
} else {
|
|
451
|
-
fileLog(`[BroadCast] ${this.name}'s subscribe is empty`, "Publisher", "warn");
|
|
129
|
+
for (const extension of TS_EXTENSIONS) {
|
|
130
|
+
const exposedPathWithExtension = resolve(context, `${exposedPath}.${extension}`);
|
|
131
|
+
if (existsSync(exposedPathWithExtension)) {
|
|
132
|
+
return exposedPathWithExtension;
|
|
452
133
|
}
|
|
453
134
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
135
|
+
return void 0;
|
|
136
|
+
}, "resolveWithExtension");
|
|
137
|
+
var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
|
|
138
|
+
const parsedOptions = utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
|
|
139
|
+
exposePath: Array.isArray(item) ? item[0] : item,
|
|
140
|
+
key
|
|
141
|
+
}), (item, key) => ({
|
|
142
|
+
exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
|
|
143
|
+
key
|
|
144
|
+
}));
|
|
145
|
+
return parsedOptions.reduce((accumulator, item) => {
|
|
146
|
+
const { exposePath, key } = item[1];
|
|
147
|
+
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(join(exposePath, "index"), remoteOptions.context) || exposePath;
|
|
148
|
+
return accumulator;
|
|
149
|
+
}, {});
|
|
150
|
+
}, "resolveExposes");
|
|
151
|
+
var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
152
|
+
validateOptions(options);
|
|
153
|
+
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
154
|
+
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
155
|
+
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
156
|
+
return {
|
|
157
|
+
tsConfig,
|
|
158
|
+
mapComponentsToExpose,
|
|
159
|
+
remoteOptions
|
|
160
|
+
};
|
|
161
|
+
}, "retrieveRemoteConfig");
|
|
464
162
|
|
|
465
|
-
// packages/dts-plugin/src/
|
|
466
|
-
import
|
|
163
|
+
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
164
|
+
import ansiColors from "ansi-colors";
|
|
165
|
+
import path2 from "path";
|
|
166
|
+
import { rm as rm2 } from "fs/promises";
|
|
167
|
+
import fs2 from "fs";
|
|
168
|
+
import { MANIFEST_EXT, inferAutoPublicPath } from "@module-federation/sdk";
|
|
169
|
+
import { ThirdPartyExtractor } from "@module-federation/third-party-dts-extractor";
|
|
170
|
+
|
|
171
|
+
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
172
|
+
import AdmZip from "adm-zip";
|
|
173
|
+
import { resolve as resolve2, join as join2 } from "path";
|
|
174
|
+
import { rm } from "fs/promises";
|
|
467
175
|
|
|
468
|
-
// packages/dts-plugin/src/server/
|
|
469
|
-
import { createServer } from "http";
|
|
176
|
+
// packages/dts-plugin/src/server/DevServer.ts
|
|
470
177
|
import WebSocket from "isomorphic-ws";
|
|
471
|
-
import schedule from "node-schedule";
|
|
472
|
-
import { parse } from "url";
|
|
473
|
-
var _Broker = class _Broker {
|
|
474
|
-
constructor() {
|
|
475
|
-
__publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
|
|
476
|
-
__publicField(this, "_webClientMap", /* @__PURE__ */ new Map());
|
|
477
|
-
__publicField(this, "_webSocketServer");
|
|
478
|
-
__publicField(this, "_secureWebSocketServer");
|
|
479
|
-
__publicField(this, "_tmpSubscriberShelter", /* @__PURE__ */ new Map());
|
|
480
|
-
__publicField(this, "_scheduleJob", null);
|
|
481
|
-
this._setSchedule();
|
|
482
|
-
this._startWsServer();
|
|
483
|
-
this._stopWhenSIGTERMOrSIGINT();
|
|
484
|
-
this._handleUnexpectedExit();
|
|
485
|
-
}
|
|
486
|
-
get hasPublishers() {
|
|
487
|
-
return Boolean(this._publisherMap.size);
|
|
488
|
-
}
|
|
489
|
-
_startWsServer() {
|
|
490
|
-
return __async(this, null, function* () {
|
|
491
|
-
const wsHandler = /* @__PURE__ */ __name((ws, req) => {
|
|
492
|
-
const { url: reqUrl = "" } = req;
|
|
493
|
-
const { query } = parse(reqUrl, true);
|
|
494
|
-
const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
|
|
495
|
-
if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
|
|
496
|
-
ws.on("message", (message) => {
|
|
497
|
-
try {
|
|
498
|
-
const text = message.toString();
|
|
499
|
-
const action = JSON.parse(text);
|
|
500
|
-
fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
|
|
501
|
-
this._takeAction(action, ws);
|
|
502
|
-
} catch (error2) {
|
|
503
|
-
fileLog(`parse action message error: ${error2}`, "Broker", "error");
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
ws.on("error", (e) => {
|
|
507
|
-
fileLog(`parse action message error: ${e}`, "Broker", "error");
|
|
508
|
-
});
|
|
509
|
-
} else {
|
|
510
|
-
ws.send("Invalid CONNECT ID.");
|
|
511
|
-
fileLog("Invalid CONNECT ID.", "Broker", "warn");
|
|
512
|
-
ws.close();
|
|
513
|
-
}
|
|
514
|
-
}, "wsHandler");
|
|
515
|
-
const server = createServer();
|
|
516
|
-
this._webSocketServer = new WebSocket.Server({
|
|
517
|
-
noServer: true
|
|
518
|
-
});
|
|
519
|
-
this._webSocketServer.on("error", (err) => {
|
|
520
|
-
fileLog(`ws error:
|
|
521
|
-
${err.message}
|
|
522
|
-
${err.stack}`, "Broker", "error");
|
|
523
|
-
});
|
|
524
|
-
this._webSocketServer.on("listening", () => {
|
|
525
|
-
fileLog(`WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`, "Broker", "info");
|
|
526
|
-
});
|
|
527
|
-
this._webSocketServer.on("connection", wsHandler);
|
|
528
|
-
this._webSocketServer.on("close", (code) => {
|
|
529
|
-
fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
|
|
530
|
-
this._webSocketServer && this._webSocketServer.close();
|
|
531
|
-
this._webSocketServer = void 0;
|
|
532
|
-
});
|
|
533
|
-
server.on("upgrade", (req, socket, head) => {
|
|
534
|
-
var _a3;
|
|
535
|
-
if (req.url) {
|
|
536
|
-
const { pathname } = parse(req.url);
|
|
537
|
-
if (pathname === "/") {
|
|
538
|
-
(_a3 = this._webSocketServer) == null ? void 0 : _a3.handleUpgrade(req, socket, head, (ws) => {
|
|
539
|
-
var _a4;
|
|
540
|
-
(_a4 = this._webSocketServer) == null ? void 0 : _a4.emit("connection", ws, req);
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
_takeAction(action, client) {
|
|
549
|
-
return __async(this, null, function* () {
|
|
550
|
-
const { kind, payload } = action;
|
|
551
|
-
if (kind === ActionKind.ADD_PUBLISHER) {
|
|
552
|
-
yield this._addPublisher(payload, client);
|
|
553
|
-
}
|
|
554
|
-
if (kind === ActionKind.UPDATE_PUBLISHER) {
|
|
555
|
-
yield this._updatePublisher(payload, client);
|
|
556
|
-
}
|
|
557
|
-
if (kind === ActionKind.ADD_SUBSCRIBER) {
|
|
558
|
-
yield this._addSubscriber(payload, client);
|
|
559
|
-
}
|
|
560
|
-
if (kind === ActionKind.EXIT_SUBSCRIBER) {
|
|
561
|
-
yield this._removeSubscriber(payload, client);
|
|
562
|
-
}
|
|
563
|
-
if (kind === ActionKind.EXIT_PUBLISHER) {
|
|
564
|
-
yield this._removePublisher(payload, client);
|
|
565
|
-
}
|
|
566
|
-
if (kind === ActionKind.ADD_WEB_CLIENT) {
|
|
567
|
-
yield this._addWebClient(payload, client);
|
|
568
|
-
}
|
|
569
|
-
if (kind === ActionKind.NOTIFY_WEB_CLIENT) {
|
|
570
|
-
yield this._notifyWebClient(payload, client);
|
|
571
|
-
}
|
|
572
|
-
if (kind === ActionKind.FETCH_TYPES) {
|
|
573
|
-
yield this._fetchTypes(payload, client);
|
|
574
|
-
}
|
|
575
|
-
if (kind === ActionKind.ADD_DYNAMIC_REMOTE) {
|
|
576
|
-
this._addDynamicRemote(payload);
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
_addPublisher(context, client) {
|
|
581
|
-
return __async(this, null, function* () {
|
|
582
|
-
const { name, ip, remoteTypeTarPath } = context != null ? context : {};
|
|
583
|
-
const identifier = getIdentifier({
|
|
584
|
-
name,
|
|
585
|
-
ip
|
|
586
|
-
});
|
|
587
|
-
if (this._publisherMap.has(identifier)) {
|
|
588
|
-
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} has been added, this action will be ignored`, "Broker", "warn");
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
try {
|
|
592
|
-
const publisher = new Publisher({
|
|
593
|
-
name,
|
|
594
|
-
ip,
|
|
595
|
-
remoteTypeTarPath,
|
|
596
|
-
ws: client
|
|
597
|
-
});
|
|
598
|
-
this._publisherMap.set(identifier, publisher);
|
|
599
|
-
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} Adding Publisher Succeed`, "Broker", "info");
|
|
600
|
-
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
601
|
-
if (tmpSubScribers) {
|
|
602
|
-
fileLog(`[${ActionKind.ADD_PUBLISHER}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `, "Broker", "info");
|
|
603
|
-
this._consumeTmpSubScribers(publisher, tmpSubScribers);
|
|
604
|
-
this._clearTmpSubScriberRelation(identifier);
|
|
605
|
-
}
|
|
606
|
-
} catch (err) {
|
|
607
|
-
const msg = error(err, ActionKind.ADD_PUBLISHER, "Broker");
|
|
608
|
-
client.send(msg);
|
|
609
|
-
client.close();
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
_updatePublisher(context, client) {
|
|
614
|
-
return __async(this, null, function* () {
|
|
615
|
-
const { name, updateMode, updateKind, updateSourcePaths, remoteTypeTarPath, ip } = context != null ? context : {};
|
|
616
|
-
const identifier = getIdentifier({
|
|
617
|
-
name,
|
|
618
|
-
ip
|
|
619
|
-
});
|
|
620
|
-
if (!this._publisherMap.has(identifier)) {
|
|
621
|
-
fileLog(`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} has not been started, this action will be ignored
|
|
622
|
-
this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
|
|
623
|
-
`, "Broker", "warn");
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
try {
|
|
627
|
-
const publisher = this._publisherMap.get(identifier);
|
|
628
|
-
fileLog(
|
|
629
|
-
// eslint-disable-next-line max-len
|
|
630
|
-
`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} update, and notify subscribers to update`,
|
|
631
|
-
"Broker",
|
|
632
|
-
"info"
|
|
633
|
-
);
|
|
634
|
-
if (publisher) {
|
|
635
|
-
publisher.notifySubscribers({
|
|
636
|
-
remoteTypeTarPath,
|
|
637
|
-
name,
|
|
638
|
-
updateMode,
|
|
639
|
-
updateKind,
|
|
640
|
-
updateSourcePaths: updateSourcePaths || []
|
|
641
|
-
});
|
|
642
|
-
this._publisherMap.forEach((p) => {
|
|
643
|
-
if (p.name === publisher.name) {
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
const dynamicRemoteInfo = p.dynamicRemoteMap.get(identifier);
|
|
647
|
-
if (dynamicRemoteInfo) {
|
|
648
|
-
fileLog(
|
|
649
|
-
// eslint-disable-next-line max-len
|
|
650
|
-
`dynamicRemoteInfo: ${JSON.stringify(dynamicRemoteInfo)}, identifier:${identifier} publish: ${p.name}`,
|
|
651
|
-
"Broker",
|
|
652
|
-
"info"
|
|
653
|
-
);
|
|
654
|
-
p.fetchRemoteTypes({
|
|
655
|
-
remoteInfo: dynamicRemoteInfo,
|
|
656
|
-
once: false
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
} catch (err) {
|
|
662
|
-
const msg = error(err, ActionKind.UPDATE_PUBLISHER, "Broker");
|
|
663
|
-
client.send(msg);
|
|
664
|
-
client.close();
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
_fetchTypes(context, _client) {
|
|
669
|
-
return __async(this, null, function* () {
|
|
670
|
-
const { name, ip, remoteInfo } = context != null ? context : {};
|
|
671
|
-
const identifier = getIdentifier({
|
|
672
|
-
name,
|
|
673
|
-
ip
|
|
674
|
-
});
|
|
675
|
-
try {
|
|
676
|
-
const publisher = this._publisherMap.get(identifier);
|
|
677
|
-
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types`, "Broker", "info");
|
|
678
|
-
if (publisher) {
|
|
679
|
-
publisher.fetchRemoteTypes({
|
|
680
|
-
remoteInfo,
|
|
681
|
-
once: true
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
} catch (err) {
|
|
685
|
-
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types fail , error info: ${err}`, "Broker", "error");
|
|
686
|
-
}
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
_addDynamicRemote(context) {
|
|
690
|
-
const { name, ip, remoteInfo, remoteIp } = context != null ? context : {};
|
|
691
|
-
const identifier = getIdentifier({
|
|
692
|
-
name,
|
|
693
|
-
ip
|
|
694
|
-
});
|
|
695
|
-
const publisher = this._publisherMap.get(identifier);
|
|
696
|
-
const remoteId = getIdentifier({
|
|
697
|
-
name: remoteInfo.name,
|
|
698
|
-
ip: remoteIp
|
|
699
|
-
});
|
|
700
|
-
fileLog(`[${ActionKind.ADD_DYNAMIC_REMOTE}] identifier:${identifier},publisher: ${publisher.name}, remoteId:${remoteId}`, "Broker", "error");
|
|
701
|
-
if (!publisher || publisher.dynamicRemoteMap.has(remoteId)) {
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
publisher.dynamicRemoteMap.set(remoteId, remoteInfo);
|
|
705
|
-
}
|
|
706
|
-
// app1 consumes provider1,provider2. Dependencies at this time: publishers: [provider1, provider2], subscriberName: app1
|
|
707
|
-
// provider1 is app1's remote
|
|
708
|
-
_addSubscriber(context, client) {
|
|
709
|
-
return __async(this, null, function* () {
|
|
710
|
-
const { publishers, name: subscriberName } = context != null ? context : {};
|
|
711
|
-
publishers.forEach((publisher) => {
|
|
712
|
-
const { name, ip } = publisher;
|
|
713
|
-
const identifier = getIdentifier({
|
|
714
|
-
name,
|
|
715
|
-
ip
|
|
716
|
-
});
|
|
717
|
-
if (!this._publisherMap.has(identifier)) {
|
|
718
|
-
fileLog(`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`, "Broker", "warn");
|
|
719
|
-
this._addTmpSubScriberRelation({
|
|
720
|
-
name: getIdentifier({
|
|
721
|
-
name: context.name,
|
|
722
|
-
ip: context.ip
|
|
723
|
-
}),
|
|
724
|
-
client
|
|
725
|
-
}, publisher);
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
try {
|
|
729
|
-
const registeredPublisher = this._publisherMap.get(identifier);
|
|
730
|
-
if (registeredPublisher) {
|
|
731
|
-
registeredPublisher.addSubscriber(getIdentifier({
|
|
732
|
-
name: subscriberName,
|
|
733
|
-
ip: context.ip
|
|
734
|
-
}), client);
|
|
735
|
-
fileLog(
|
|
736
|
-
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
737
|
-
`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(Array.from(this._publisherMap.entries()))}`,
|
|
738
|
-
"Broker",
|
|
739
|
-
"info"
|
|
740
|
-
);
|
|
741
|
-
registeredPublisher.notifySubscriber(getIdentifier({
|
|
742
|
-
name: subscriberName,
|
|
743
|
-
ip: context.ip
|
|
744
|
-
}), {
|
|
745
|
-
updateKind: UpdateKind.UPDATE_TYPE,
|
|
746
|
-
updateMode: UpdateMode.PASSIVE,
|
|
747
|
-
updateSourcePaths: [
|
|
748
|
-
registeredPublisher.name
|
|
749
|
-
],
|
|
750
|
-
remoteTypeTarPath: registeredPublisher.remoteTypeTarPath,
|
|
751
|
-
name: registeredPublisher.name
|
|
752
|
-
});
|
|
753
|
-
fileLog(
|
|
754
|
-
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
755
|
-
`[${ActionKind.ADD_SUBSCRIBER}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
|
|
756
|
-
"Broker",
|
|
757
|
-
"info"
|
|
758
|
-
);
|
|
759
|
-
}
|
|
760
|
-
} catch (err) {
|
|
761
|
-
const msg = error(err, ActionKind.ADD_SUBSCRIBER, "Broker");
|
|
762
|
-
client.send(msg);
|
|
763
|
-
client.close();
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
// Trigger while consumer exit
|
|
769
|
-
_removeSubscriber(context, client) {
|
|
770
|
-
return __async(this, null, function* () {
|
|
771
|
-
const { publishers } = context != null ? context : {};
|
|
772
|
-
const subscriberIdentifier = getIdentifier({
|
|
773
|
-
name: context == null ? void 0 : context.name,
|
|
774
|
-
ip: context == null ? void 0 : context.ip
|
|
775
|
-
});
|
|
776
|
-
publishers.forEach((publisher) => {
|
|
777
|
-
const { name, ip } = publisher;
|
|
778
|
-
const identifier = getIdentifier({
|
|
779
|
-
name,
|
|
780
|
-
ip
|
|
781
|
-
});
|
|
782
|
-
const registeredPublisher = this._publisherMap.get(identifier);
|
|
783
|
-
if (!registeredPublisher) {
|
|
784
|
-
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} does not exit `, "Broker", "warn");
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
try {
|
|
788
|
-
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} will exit `, "Broker", "INFO");
|
|
789
|
-
registeredPublisher.removeSubscriber(subscriberIdentifier);
|
|
790
|
-
this._clearTmpSubScriberRelation(identifier);
|
|
791
|
-
if (!registeredPublisher.hasSubscribes) {
|
|
792
|
-
this._publisherMap.delete(identifier);
|
|
793
|
-
}
|
|
794
|
-
if (!this.hasPublishers) {
|
|
795
|
-
this.exit();
|
|
796
|
-
}
|
|
797
|
-
} catch (err) {
|
|
798
|
-
const msg = error(err, ActionKind.EXIT_SUBSCRIBER, "Broker");
|
|
799
|
-
client.send(msg);
|
|
800
|
-
client.close();
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
_removePublisher(context, client) {
|
|
806
|
-
return __async(this, null, function* () {
|
|
807
|
-
const { name, ip } = context != null ? context : {};
|
|
808
|
-
const identifier = getIdentifier({
|
|
809
|
-
name,
|
|
810
|
-
ip
|
|
811
|
-
});
|
|
812
|
-
const publisher = this._publisherMap.get(identifier);
|
|
813
|
-
if (!publisher) {
|
|
814
|
-
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier}} has not been added, this action will be ingored`, "Broker", "warn");
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
try {
|
|
818
|
-
const { subscribers } = publisher;
|
|
819
|
-
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
820
|
-
this._addTmpSubScriberRelation({
|
|
821
|
-
name: subscriberIdentifier,
|
|
822
|
-
client: subscriber
|
|
823
|
-
}, {
|
|
824
|
-
name: publisher.name,
|
|
825
|
-
ip: publisher.ip
|
|
826
|
-
});
|
|
827
|
-
fileLog(
|
|
828
|
-
// eslint-disable-next-line max-len
|
|
829
|
-
`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
830
|
-
"Broker",
|
|
831
|
-
"info"
|
|
832
|
-
);
|
|
833
|
-
});
|
|
834
|
-
this._publisherMap.delete(identifier);
|
|
835
|
-
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removed `, "Broker", "info");
|
|
836
|
-
if (!this.hasPublishers) {
|
|
837
|
-
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: _publisherMap is empty, all server will exit `, "Broker", "warn");
|
|
838
|
-
this.exit();
|
|
839
|
-
}
|
|
840
|
-
} catch (err) {
|
|
841
|
-
const msg = error(err, ActionKind.EXIT_PUBLISHER, "Broker");
|
|
842
|
-
client.send(msg);
|
|
843
|
-
client.close();
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
_addWebClient(context, client) {
|
|
848
|
-
return __async(this, null, function* () {
|
|
849
|
-
const { name } = context != null ? context : {};
|
|
850
|
-
const identifier = getIdentifier({
|
|
851
|
-
name
|
|
852
|
-
});
|
|
853
|
-
if (this._webClientMap.has(identifier)) {
|
|
854
|
-
fileLog(`${identifier}} has been added, this action will override prev WebClient`, "Broker", "warn");
|
|
855
|
-
}
|
|
856
|
-
try {
|
|
857
|
-
this._webClientMap.set(identifier, client);
|
|
858
|
-
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
859
|
-
} catch (err) {
|
|
860
|
-
const msg = error(err, ActionKind.ADD_WEB_CLIENT, "Broker");
|
|
861
|
-
client.send(msg);
|
|
862
|
-
client.close();
|
|
863
|
-
}
|
|
864
|
-
});
|
|
865
|
-
}
|
|
866
|
-
_notifyWebClient(context, client) {
|
|
867
|
-
return __async(this, null, function* () {
|
|
868
|
-
const { name, updateMode } = context != null ? context : {};
|
|
869
|
-
const identifier = getIdentifier({
|
|
870
|
-
name
|
|
871
|
-
});
|
|
872
|
-
const webClient = this._webClientMap.get(identifier);
|
|
873
|
-
if (!webClient) {
|
|
874
|
-
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] ${identifier} has not been added, this action will be ignored`, "Broker", "warn");
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
try {
|
|
878
|
-
const api = new ReloadWebClientAPI({
|
|
879
|
-
name,
|
|
880
|
-
updateMode
|
|
881
|
-
});
|
|
882
|
-
webClient.send(JSON.stringify(api));
|
|
883
|
-
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] Notify ${name} WebClient Succeed`, "Broker", "info");
|
|
884
|
-
} catch (err) {
|
|
885
|
-
const msg = error(err, ActionKind.NOTIFY_WEB_CLIENT, "Broker");
|
|
886
|
-
client.send(msg);
|
|
887
|
-
client.close();
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
// app1 consumes provider1, and provider1 not launch. this._tmpSubscriberShelter at this time: {provider1: Map{subscribers: Map{app1: app1+ip+client'}, timestamp: 'xx'} }
|
|
892
|
-
_addTmpSubScriberRelation(subscriber, publisher) {
|
|
893
|
-
const publisherIdentifier = getIdentifier({
|
|
894
|
-
name: publisher.name,
|
|
895
|
-
ip: publisher.ip
|
|
896
|
-
});
|
|
897
|
-
const subscriberIdentifier = subscriber.name;
|
|
898
|
-
const shelter = this._tmpSubscriberShelter.get(publisherIdentifier);
|
|
899
|
-
if (!shelter) {
|
|
900
|
-
const map = /* @__PURE__ */ new Map();
|
|
901
|
-
map.set(subscriberIdentifier, subscriber);
|
|
902
|
-
this._tmpSubscriberShelter.set(publisherIdentifier, {
|
|
903
|
-
subscribers: map,
|
|
904
|
-
timestamp: Date.now()
|
|
905
|
-
});
|
|
906
|
-
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `, "Broker", "info");
|
|
907
|
-
return;
|
|
908
|
-
}
|
|
909
|
-
const tmpSubScriberShelterSubscriber = shelter.subscribers.get(subscriberIdentifier);
|
|
910
|
-
if (tmpSubScriberShelterSubscriber) {
|
|
911
|
-
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`, "Broker", "warn");
|
|
912
|
-
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
913
|
-
shelter.timestamp = Date.now();
|
|
914
|
-
} else {
|
|
915
|
-
fileLog(
|
|
916
|
-
// eslint-disable-next-line max-len
|
|
917
|
-
`AddTmpSubscriberLog ${publisherIdentifier}'s shelter has been added, update shelter.subscribers ${subscriberIdentifier}`,
|
|
918
|
-
"Broker",
|
|
919
|
-
"warn"
|
|
920
|
-
);
|
|
921
|
-
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
_getTmpSubScribers(publisherIdentifier) {
|
|
925
|
-
var _a3;
|
|
926
|
-
return (_a3 = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a3.subscribers;
|
|
927
|
-
}
|
|
928
|
-
// after adding publisher, it will change the temp subscriber to regular subscriber
|
|
929
|
-
_consumeTmpSubScribers(publisher, tmpSubScribers) {
|
|
930
|
-
tmpSubScribers.forEach((tmpSubScriber, identifier) => {
|
|
931
|
-
fileLog(`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `, "Broker", "warn");
|
|
932
|
-
publisher.addSubscriber(identifier, tmpSubScriber.client);
|
|
933
|
-
publisher.notifySubscriber(identifier, {
|
|
934
|
-
updateKind: UpdateKind.UPDATE_TYPE,
|
|
935
|
-
updateMode: UpdateMode.PASSIVE,
|
|
936
|
-
updateSourcePaths: [
|
|
937
|
-
publisher.name
|
|
938
|
-
],
|
|
939
|
-
remoteTypeTarPath: publisher.remoteTypeTarPath,
|
|
940
|
-
name: publisher.name
|
|
941
|
-
});
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
_clearTmpSubScriberRelation(identifier) {
|
|
945
|
-
this._tmpSubscriberShelter.delete(identifier);
|
|
946
|
-
}
|
|
947
|
-
_clearTmpSubScriberRelations() {
|
|
948
|
-
this._tmpSubscriberShelter.clear();
|
|
949
|
-
}
|
|
950
|
-
_disconnect() {
|
|
951
|
-
this._publisherMap.forEach((publisher) => {
|
|
952
|
-
publisher.close();
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
// Every day on 0/6/9/12/15//18, Publishers that have not been connected within 1.5 hours will be cleared regularly.
|
|
956
|
-
// If process.env.FEDERATION_SERVER_TEST is set, it will be read at a specified time.
|
|
957
|
-
_setSchedule() {
|
|
958
|
-
const rule = new schedule.RecurrenceRule();
|
|
959
|
-
if (Number(process.env["FEDERATION_SERVER_TEST"])) {
|
|
960
|
-
const interval = Number(process.env["FEDERATION_SERVER_TEST"]) / 1e3;
|
|
961
|
-
const second = [];
|
|
962
|
-
for (let i = 0; i < 60; i = i + interval) {
|
|
963
|
-
second.push(i);
|
|
964
|
-
}
|
|
965
|
-
rule.second = second;
|
|
966
|
-
} else {
|
|
967
|
-
rule.second = 0;
|
|
968
|
-
rule.hour = [
|
|
969
|
-
0,
|
|
970
|
-
3,
|
|
971
|
-
6,
|
|
972
|
-
9,
|
|
973
|
-
12,
|
|
974
|
-
15,
|
|
975
|
-
18
|
|
976
|
-
];
|
|
977
|
-
rule.minute = 0;
|
|
978
|
-
}
|
|
979
|
-
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
980
|
-
this._scheduleJob = schedule.scheduleJob(rule, () => {
|
|
981
|
-
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
982
|
-
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
983
|
-
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)) {
|
|
984
|
-
this._clearTmpSubScriberRelation(identifier);
|
|
985
|
-
}
|
|
986
|
-
});
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
_clearSchedule() {
|
|
990
|
-
if (!this._scheduleJob) {
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
this._scheduleJob.cancel();
|
|
994
|
-
this._scheduleJob = null;
|
|
995
|
-
}
|
|
996
|
-
_stopWhenSIGTERMOrSIGINT() {
|
|
997
|
-
process.on("SIGTERM", () => {
|
|
998
|
-
this.exit();
|
|
999
|
-
});
|
|
1000
|
-
process.on("SIGINT", () => {
|
|
1001
|
-
this.exit();
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
_handleUnexpectedExit() {
|
|
1005
|
-
process.on("unhandledRejection", (error2) => {
|
|
1006
|
-
console.error("Unhandled Rejection Error: ", error2);
|
|
1007
|
-
fileLog(`Unhandled Rejection Error: ${error2}`, "Broker", "fatal");
|
|
1008
|
-
process.exit(1);
|
|
1009
|
-
});
|
|
1010
|
-
process.on("uncaughtException", (error2) => {
|
|
1011
|
-
console.error("Unhandled Exception Error: ", error2);
|
|
1012
|
-
fileLog(`Unhandled Rejection Error: ${error2}`, "Broker", "fatal");
|
|
1013
|
-
process.exit(1);
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
start() {
|
|
1017
|
-
return __async(this, null, function* () {
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
exit() {
|
|
1021
|
-
const brokerExitLog = new BrokerExitLog();
|
|
1022
|
-
this.broadcast(JSON.stringify(brokerExitLog));
|
|
1023
|
-
this._disconnect();
|
|
1024
|
-
this._clearSchedule();
|
|
1025
|
-
this._clearTmpSubScriberRelations();
|
|
1026
|
-
this._webSocketServer && this._webSocketServer.close();
|
|
1027
|
-
this._secureWebSocketServer && this._secureWebSocketServer.close();
|
|
1028
|
-
process.exit(0);
|
|
1029
|
-
}
|
|
1030
|
-
broadcast(message) {
|
|
1031
|
-
var _a3, _b;
|
|
1032
|
-
fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
|
|
1033
|
-
(_a3 = this._webSocketServer) == null ? void 0 : _a3.clients.forEach((client) => {
|
|
1034
|
-
client.send(JSON.stringify(message));
|
|
1035
|
-
});
|
|
1036
|
-
(_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
|
|
1037
|
-
client.send(JSON.stringify(message));
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
__name(_Broker, "Broker");
|
|
1042
|
-
__publicField(_Broker, "WEB_SOCKET_CONNECT_MAGIC_ID", WEB_SOCKET_CONNECT_MAGIC_ID);
|
|
1043
|
-
__publicField(_Broker, "DEFAULT_WEB_SOCKET_PORT", DEFAULT_WEB_SOCKET_PORT);
|
|
1044
|
-
__publicField(_Broker, "DEFAULT_SECURE_WEB_SOCKET_PORT", 16324);
|
|
1045
|
-
__publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
1046
|
-
var Broker = _Broker;
|
|
1047
178
|
|
|
1048
179
|
// packages/dts-plugin/src/server/broker/createBroker.ts
|
|
1049
180
|
import { fork } from "child_process";
|
|
@@ -1090,21 +221,21 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1090
221
|
return;
|
|
1091
222
|
}
|
|
1092
223
|
fileLog(`Publisher:${this._name} Trying to connect to ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}...`, MF_SERVER_IDENTIFIER, "info");
|
|
1093
|
-
this._publishWebSocket = new
|
|
224
|
+
this._publishWebSocket = new WebSocket(`ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${Broker.WEB_SOCKET_CONNECT_MAGIC_ID}`);
|
|
1094
225
|
this._publishWebSocket.on("open", () => {
|
|
1095
|
-
var
|
|
226
|
+
var _a2;
|
|
1096
227
|
fileLog(`Current pid: ${process.pid}, publisher:${this._name} connected to ws://${this._ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}, starting service...`, MF_SERVER_IDENTIFIER, "info");
|
|
1097
228
|
this._isConnected = true;
|
|
1098
|
-
const
|
|
229
|
+
const addPublisherAction = new AddPublisherAction({
|
|
1099
230
|
name: this._name,
|
|
1100
231
|
ip: this._ip,
|
|
1101
232
|
remoteTypeTarPath: this._remoteTypeTarPath
|
|
1102
233
|
});
|
|
1103
|
-
(
|
|
234
|
+
(_a2 = this._publishWebSocket) == null ? void 0 : _a2.send(JSON.stringify(addPublisherAction));
|
|
1104
235
|
this._connectSubscribers();
|
|
1105
236
|
});
|
|
1106
237
|
this._publishWebSocket.on("message", (message) => __async(this, null, function* () {
|
|
1107
|
-
var
|
|
238
|
+
var _a2, _b;
|
|
1108
239
|
try {
|
|
1109
240
|
const parsedMessage = JSON.parse(message.toString());
|
|
1110
241
|
if (parsedMessage.type === "Log") {
|
|
@@ -1136,7 +267,7 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1136
267
|
ip: remote.ip
|
|
1137
268
|
}))
|
|
1138
269
|
});
|
|
1139
|
-
(
|
|
270
|
+
(_a2 = this._publishWebSocket) == null ? void 0 : _a2.send(JSON.stringify(exitPublisher));
|
|
1140
271
|
(_b = this._publishWebSocket) == null ? void 0 : _b.send(JSON.stringify(exitSubscriber));
|
|
1141
272
|
fileLog("Parse messages error, ModuleFederationDevServer will exit...", MF_SERVER_IDENTIFIER, "fatal");
|
|
1142
273
|
this._exit();
|
|
@@ -1163,7 +294,7 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1163
294
|
name,
|
|
1164
295
|
ip
|
|
1165
296
|
});
|
|
1166
|
-
this._subscriberWebsocketMap[identifier] = new
|
|
297
|
+
this._subscriberWebsocketMap[identifier] = new WebSocket(`ws://${ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}?WEB_SOCKET_CONNECT_MAGIC_ID=${Broker.WEB_SOCKET_CONNECT_MAGIC_ID}`);
|
|
1167
298
|
this._subscriberWebsocketMap[identifier].on("open", () => {
|
|
1168
299
|
fileLog(`Current pid: ${process.pid} remote module: ${name} connected to ws://${ip}:${Broker.DEFAULT_WEB_SOCKET_PORT}, starting service...`, MF_SERVER_IDENTIFIER, "info");
|
|
1169
300
|
const addSubscriber = new AddSubscriberAction({
|
|
@@ -1231,7 +362,7 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1231
362
|
// app1 consumes provider1. And the function will be triggered when provider1 code change.
|
|
1232
363
|
_updateSubscriber(options) {
|
|
1233
364
|
return __async(this, null, function* () {
|
|
1234
|
-
var
|
|
365
|
+
var _a2;
|
|
1235
366
|
const { updateMode, updateKind, updateSourcePaths, name, remoteTypeTarPath, remoteInfo } = options;
|
|
1236
367
|
fileLog(
|
|
1237
368
|
// eslint-disable-next-line max-len
|
|
@@ -1281,7 +412,7 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1281
412
|
MF_SERVER_IDENTIFIER,
|
|
1282
413
|
"info"
|
|
1283
414
|
);
|
|
1284
|
-
(
|
|
415
|
+
(_a2 = this._publishWebSocket) == null ? void 0 : _a2.send(JSON.stringify(updatePublisher));
|
|
1285
416
|
});
|
|
1286
417
|
}
|
|
1287
418
|
_tryCreateBackgroundBroker(err) {
|
|
@@ -1320,19 +451,19 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1320
451
|
});
|
|
1321
452
|
}
|
|
1322
453
|
_handleUnexpectedExit() {
|
|
1323
|
-
process.on("unhandledRejection", (
|
|
454
|
+
process.on("unhandledRejection", (error) => {
|
|
1324
455
|
if (this._isReconnecting) {
|
|
1325
456
|
return;
|
|
1326
457
|
}
|
|
1327
|
-
console.error("Unhandled Rejection Error: ",
|
|
458
|
+
console.error("Unhandled Rejection Error: ", error);
|
|
1328
459
|
fileLog(`Process(${process.pid}) unhandledRejection, garfishModuleServer will exit...`, MF_SERVER_IDENTIFIER, "error");
|
|
1329
460
|
this._exit();
|
|
1330
461
|
});
|
|
1331
|
-
process.on("uncaughtException", (
|
|
462
|
+
process.on("uncaughtException", (error) => {
|
|
1332
463
|
if (this._isReconnecting) {
|
|
1333
464
|
return;
|
|
1334
465
|
}
|
|
1335
|
-
console.error("Unhandled Exception Error: ",
|
|
466
|
+
console.error("Unhandled Exception Error: ", error);
|
|
1336
467
|
fileLog(`Process(${process.pid}) uncaughtException, garfishModuleServer will exit...`, MF_SERVER_IDENTIFIER, "error");
|
|
1337
468
|
this._exit();
|
|
1338
469
|
});
|
|
@@ -1363,11 +494,11 @@ var _ModuleFederationDevServer = class _ModuleFederationDevServer {
|
|
|
1363
494
|
if (!this._publishWebSocket || !this._isConnected) {
|
|
1364
495
|
return;
|
|
1365
496
|
}
|
|
1366
|
-
const { updateKind, updateMode, updateSourcePaths } = options;
|
|
497
|
+
const { updateKind, updateMode, updateSourcePaths, clientName } = options;
|
|
1367
498
|
fileLog(`update run, ${this._name} module update, updateKind: ${updateKind}, updateMode: ${updateMode}, updateSourcePaths: ${updateSourcePaths}`, MF_SERVER_IDENTIFIER, "info");
|
|
1368
499
|
if (updateKind === UpdateKind.RELOAD_PAGE) {
|
|
1369
500
|
const notifyWebClient = new NotifyWebClientAction({
|
|
1370
|
-
name: this._name,
|
|
501
|
+
name: clientName || this._name,
|
|
1371
502
|
updateMode
|
|
1372
503
|
});
|
|
1373
504
|
this._publishWebSocket.send(JSON.stringify(notifyWebClient));
|
|
@@ -1471,13 +602,13 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1471
602
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1472
603
|
try {
|
|
1473
604
|
if (hostOptions.deleteTypesFolder) {
|
|
1474
|
-
yield
|
|
605
|
+
yield rm(destinationPath, {
|
|
1475
606
|
recursive: true,
|
|
1476
607
|
force: true
|
|
1477
608
|
});
|
|
1478
609
|
}
|
|
1479
|
-
} catch (
|
|
1480
|
-
fileLog(`Unable to remove types folder, ${
|
|
610
|
+
} catch (error) {
|
|
611
|
+
fileLog(`Unable to remove types folder, ${error}`, "downloadTypesArchive", "error");
|
|
1481
612
|
}
|
|
1482
613
|
const zip = new AdmZip(Buffer.from(response.data));
|
|
1483
614
|
zip.extractAllTo(destinationPath, true);
|
|
@@ -1485,11 +616,11 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1485
616
|
destinationFolder,
|
|
1486
617
|
destinationPath
|
|
1487
618
|
];
|
|
1488
|
-
} catch (
|
|
1489
|
-
fileLog(`Error during types archive download: ${(
|
|
619
|
+
} catch (error) {
|
|
620
|
+
fileLog(`Error during types archive download: ${(error == null ? void 0 : error.message) || "unknown error"}`, "downloadTypesArchive", "error");
|
|
1490
621
|
if (retries >= hostOptions.maxRetries) {
|
|
1491
622
|
if (hostOptions.abortOnError !== false) {
|
|
1492
|
-
throw
|
|
623
|
+
throw error;
|
|
1493
624
|
}
|
|
1494
625
|
return void 0;
|
|
1495
626
|
}
|
|
@@ -1500,8 +631,8 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1500
631
|
|
|
1501
632
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1502
633
|
import { parseEntry, ENCODE_NAME_PREFIX, decodeName } from "@module-federation/sdk";
|
|
1503
|
-
import { utils } from "@module-federation/managers";
|
|
1504
|
-
var
|
|
634
|
+
import { utils as utils2 } from "@module-federation/managers";
|
|
635
|
+
var defaultOptions2 = {
|
|
1505
636
|
typesFolder: "@mf-types",
|
|
1506
637
|
remoteTypesFolder: "@mf-types",
|
|
1507
638
|
deleteTypesFolder: true,
|
|
@@ -1509,7 +640,8 @@ var defaultOptions = {
|
|
|
1509
640
|
implementation: "",
|
|
1510
641
|
context: process.cwd(),
|
|
1511
642
|
abortOnError: true,
|
|
1512
|
-
consumeAPITypes: false
|
|
643
|
+
consumeAPITypes: false,
|
|
644
|
+
runtimePkgs: []
|
|
1513
645
|
};
|
|
1514
646
|
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1515
647
|
const remoteUrl = new URL(url, "file:");
|
|
@@ -1541,7 +673,7 @@ var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
|
1541
673
|
};
|
|
1542
674
|
}, "retrieveRemoteInfo");
|
|
1543
675
|
var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
1544
|
-
const parsedOptions =
|
|
676
|
+
const parsedOptions = utils2.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
|
|
1545
677
|
remote: Array.isArray(item) ? item[0] : item,
|
|
1546
678
|
key
|
|
1547
679
|
}), (item, key) => ({
|
|
@@ -1560,7 +692,7 @@ var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1560
692
|
}, "resolveRemotes");
|
|
1561
693
|
var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
1562
694
|
validateOptions(options);
|
|
1563
|
-
const hostOptions = __spreadValues(__spreadValues({},
|
|
695
|
+
const hostOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1564
696
|
const mapRemotesToDownload = resolveRemotes(hostOptions);
|
|
1565
697
|
return {
|
|
1566
698
|
hostOptions,
|
|
@@ -1568,6 +700,11 @@ var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
|
1568
700
|
};
|
|
1569
701
|
}, "retrieveHostConfig");
|
|
1570
702
|
|
|
703
|
+
// packages/dts-plugin/src/core/constant.ts
|
|
704
|
+
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
705
|
+
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
706
|
+
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
707
|
+
|
|
1571
708
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1572
709
|
var _a;
|
|
1573
710
|
var DTSManager = (_a = class {
|
|
@@ -1578,11 +715,7 @@ var DTSManager = (_a = class {
|
|
|
1578
715
|
__publicField(this, "loadedRemoteAPIAlias");
|
|
1579
716
|
__publicField(this, "extraOptions");
|
|
1580
717
|
__publicField(this, "updatedRemoteInfos");
|
|
1581
|
-
this.options =
|
|
1582
|
-
if (key === "manifest") {
|
|
1583
|
-
return false;
|
|
1584
|
-
}
|
|
1585
|
-
});
|
|
718
|
+
this.options = cloneDeepOptions(options);
|
|
1586
719
|
this.runtimePkgs = [
|
|
1587
720
|
"@module-federation/runtime",
|
|
1588
721
|
"@module-federation/enhanced/runtime",
|
|
@@ -1641,7 +774,7 @@ var DTSManager = (_a = class {
|
|
|
1641
774
|
}
|
|
1642
775
|
generateTypes() {
|
|
1643
776
|
return __async(this, null, function* () {
|
|
1644
|
-
var
|
|
777
|
+
var _a2;
|
|
1645
778
|
try {
|
|
1646
779
|
const { options } = this;
|
|
1647
780
|
if (!options.remote) {
|
|
@@ -1666,7 +799,7 @@ var DTSManager = (_a = class {
|
|
|
1666
799
|
}
|
|
1667
800
|
try {
|
|
1668
801
|
if (remoteOptions.deleteTypesFolder) {
|
|
1669
|
-
yield
|
|
802
|
+
yield rm2(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1670
803
|
recursive: true,
|
|
1671
804
|
force: true
|
|
1672
805
|
});
|
|
@@ -1677,11 +810,11 @@ var DTSManager = (_a = class {
|
|
|
1677
810
|
}
|
|
1678
811
|
}
|
|
1679
812
|
console.log(ansiColors.green("Federated types created correctly"));
|
|
1680
|
-
} catch (
|
|
1681
|
-
if (((
|
|
1682
|
-
console.error(ansiColors.red(`Unable to compile federated types, ${
|
|
813
|
+
} catch (error) {
|
|
814
|
+
if (((_a2 = this.options.remote) == null ? void 0 : _a2.abortOnError) === false) {
|
|
815
|
+
console.error(ansiColors.red(`Unable to compile federated types, ${error}`));
|
|
1683
816
|
} else {
|
|
1684
|
-
throw
|
|
817
|
+
throw error;
|
|
1685
818
|
}
|
|
1686
819
|
}
|
|
1687
820
|
});
|
|
@@ -1767,7 +900,7 @@ var DTSManager = (_a = class {
|
|
|
1767
900
|
const apiTypeFileName = path2.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME);
|
|
1768
901
|
try {
|
|
1769
902
|
const existedFile = fs2.readFileSync(apiTypeFileName, "utf-8");
|
|
1770
|
-
const existedImports = new
|
|
903
|
+
const existedImports = new ThirdPartyExtractor("").collectTypeImports(existedFile);
|
|
1771
904
|
existedImports.forEach((existedImport) => {
|
|
1772
905
|
const alias = existedImport.split("./").slice(1).join("./").replace("/apis.d.ts", "");
|
|
1773
906
|
this.loadedRemoteAPIAlias.add(alias);
|
|
@@ -1793,7 +926,16 @@ var DTSManager = (_a = class {
|
|
|
1793
926
|
...packageTypes,
|
|
1794
927
|
"Y"
|
|
1795
928
|
].join(" :\n")} ;`;
|
|
1796
|
-
const
|
|
929
|
+
const runtimePkgs = /* @__PURE__ */ new Set();
|
|
930
|
+
[
|
|
931
|
+
...this.runtimePkgs,
|
|
932
|
+
...hostOptions.runtimePkgs
|
|
933
|
+
].forEach((pkg) => {
|
|
934
|
+
runtimePkgs.add(pkg);
|
|
935
|
+
});
|
|
936
|
+
const pkgsDeclareStr = [
|
|
937
|
+
...runtimePkgs
|
|
938
|
+
].map((pkg) => {
|
|
1797
939
|
return `declare module "${pkg}" {
|
|
1798
940
|
${remoteKeysStr}
|
|
1799
941
|
${packageTypesStr}
|
|
@@ -1826,7 +968,7 @@ var DTSManager = (_a = class {
|
|
|
1826
968
|
}
|
|
1827
969
|
consumeTypes() {
|
|
1828
970
|
return __async(this, null, function* () {
|
|
1829
|
-
var
|
|
971
|
+
var _a2;
|
|
1830
972
|
try {
|
|
1831
973
|
const { options } = this;
|
|
1832
974
|
if (!options.host) {
|
|
@@ -1853,7 +995,7 @@ var DTSManager = (_a = class {
|
|
|
1853
995
|
}
|
|
1854
996
|
console.log(ansiColors.green("Federated types extraction completed"));
|
|
1855
997
|
} catch (err) {
|
|
1856
|
-
if (((
|
|
998
|
+
if (((_a2 = this.options.host) == null ? void 0 : _a2.abortOnError) === false) {
|
|
1857
999
|
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
1858
1000
|
} else {
|
|
1859
1001
|
throw err;
|
|
@@ -1863,10 +1005,10 @@ var DTSManager = (_a = class {
|
|
|
1863
1005
|
}
|
|
1864
1006
|
updateTypes(options) {
|
|
1865
1007
|
return __async(this, null, function* () {
|
|
1866
|
-
var
|
|
1008
|
+
var _a2, _b, _c;
|
|
1867
1009
|
try {
|
|
1868
1010
|
const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
|
|
1869
|
-
const hostName = (_c = (_b = (
|
|
1011
|
+
const hostName = (_c = (_b = (_a2 = this.options) == null ? void 0 : _a2.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
|
|
1870
1012
|
fileLog(`updateTypes options:, ${JSON.stringify(options, null, 2)}`, "consumeTypes", "info");
|
|
1871
1013
|
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
|
|
1872
1014
|
if (!this.options.remote) {
|
|
@@ -1880,7 +1022,7 @@ var DTSManager = (_a = class {
|
|
|
1880
1022
|
}
|
|
1881
1023
|
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1882
1024
|
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1883
|
-
const
|
|
1025
|
+
const consumeTypes = /* @__PURE__ */ __name((requiredRemoteInfo) => __async(this, null, function* () {
|
|
1884
1026
|
const [_alias, destinationPath] = yield this.consumeTargetRemotes(hostOptions, requiredRemoteInfo);
|
|
1885
1027
|
yield this.downloadAPITypes(requiredRemoteInfo, destinationPath);
|
|
1886
1028
|
}), "consumeTypes");
|
|
@@ -1893,10 +1035,10 @@ var DTSManager = (_a = class {
|
|
|
1893
1035
|
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1894
1036
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1895
1037
|
}
|
|
1896
|
-
yield
|
|
1038
|
+
yield consumeTypes(this.remoteAliasMap[remoteInfo.alias]);
|
|
1897
1039
|
} else if (updatedRemoteInfo) {
|
|
1898
1040
|
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1899
|
-
yield
|
|
1041
|
+
yield consumeTypes(this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1900
1042
|
this.consumeAPITypes(hostOptions);
|
|
1901
1043
|
}), "consumeDynamicRemoteTypes");
|
|
1902
1044
|
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
@@ -1915,7 +1057,7 @@ var DTSManager = (_a = class {
|
|
|
1915
1057
|
}
|
|
1916
1058
|
}
|
|
1917
1059
|
} else {
|
|
1918
|
-
yield
|
|
1060
|
+
yield consumeTypes(loadedRemoteInfo);
|
|
1919
1061
|
}
|
|
1920
1062
|
}
|
|
1921
1063
|
} catch (err) {
|
|
@@ -1926,6 +1068,7 @@ var DTSManager = (_a = class {
|
|
|
1926
1068
|
}, __name(_a, "DTSManager"), _a);
|
|
1927
1069
|
|
|
1928
1070
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
1071
|
+
import cloneDeepWith from "lodash.clonedeepwith";
|
|
1929
1072
|
function getDTSManagerConstructor(implementation) {
|
|
1930
1073
|
if (implementation) {
|
|
1931
1074
|
const NewConstructor = __require(implementation);
|
|
@@ -1997,6 +1140,18 @@ var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) =
|
|
|
1997
1140
|
return false;
|
|
1998
1141
|
}
|
|
1999
1142
|
}, "isTSProject");
|
|
1143
|
+
function cloneDeepOptions(options) {
|
|
1144
|
+
const excludeKeys = [
|
|
1145
|
+
"manifest",
|
|
1146
|
+
"async"
|
|
1147
|
+
];
|
|
1148
|
+
return cloneDeepWith(options, (_value, key) => {
|
|
1149
|
+
if (typeof key === "string" && excludeKeys.includes(key)) {
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
__name(cloneDeepOptions, "cloneDeepOptions");
|
|
2000
1155
|
function axiosGet(url, config) {
|
|
2001
1156
|
return __async(this, null, function* () {
|
|
2002
1157
|
const httpAgent = new http.Agent({
|
|
@@ -2013,147 +1168,126 @@ function axiosGet(url, config) {
|
|
|
2013
1168
|
}
|
|
2014
1169
|
__name(axiosGet, "axiosGet");
|
|
2015
1170
|
|
|
2016
|
-
// packages/dts-plugin/src/core/
|
|
2017
|
-
var
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
extractThirdParty: false
|
|
2032
|
-
};
|
|
2033
|
-
function getEffectiveRootDir(parsedCommandLine) {
|
|
2034
|
-
const compilerOptions = parsedCommandLine.options;
|
|
2035
|
-
if (compilerOptions.rootDir) {
|
|
2036
|
-
return compilerOptions.rootDir;
|
|
2037
|
-
}
|
|
2038
|
-
const files = parsedCommandLine.fileNames;
|
|
2039
|
-
if (files.length > 0) {
|
|
2040
|
-
const commonRoot = files.map((file) => dirname2(file)).reduce((commonPath, fileDir) => {
|
|
2041
|
-
while (!fileDir.startsWith(commonPath)) {
|
|
2042
|
-
commonPath = dirname2(commonPath);
|
|
2043
|
-
}
|
|
2044
|
-
return commonPath;
|
|
2045
|
-
}, files[0]);
|
|
2046
|
-
return commonRoot;
|
|
2047
|
-
}
|
|
2048
|
-
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
1171
|
+
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
1172
|
+
var STARTS_WITH_SLASH = /^\//;
|
|
1173
|
+
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
1174
|
+
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
1175
|
+
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
1176
|
+
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => join3(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
1177
|
+
function writeTempTsConfig(tsConfig, context, name) {
|
|
1178
|
+
const createHash = /* @__PURE__ */ __name((contents) => {
|
|
1179
|
+
return crypto.createHash("md5").update(contents).digest("hex");
|
|
1180
|
+
}, "createHash");
|
|
1181
|
+
const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
|
|
1182
|
+
const tempTsConfigJsonPath = resolve3(context, "node_modules", TEMP_DIR, `tsconfig.${hash}.json`);
|
|
1183
|
+
ensureDirSync(dirname2(tempTsConfigJsonPath));
|
|
1184
|
+
writeFileSync(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
|
|
1185
|
+
return tempTsConfigJsonPath;
|
|
2049
1186
|
}
|
|
2050
|
-
__name(
|
|
2051
|
-
var
|
|
2052
|
-
const
|
|
2053
|
-
const
|
|
2054
|
-
|
|
2055
|
-
|
|
1187
|
+
__name(writeTempTsConfig, "writeTempTsConfig");
|
|
1188
|
+
var removeExt = /* @__PURE__ */ __name((f) => {
|
|
1189
|
+
const ext = extname2(f);
|
|
1190
|
+
const regexPattern = new RegExp(`\\${ext}$`);
|
|
1191
|
+
return f.replace(regexPattern, "");
|
|
1192
|
+
}, "removeExt");
|
|
1193
|
+
function getExposeKey(options) {
|
|
1194
|
+
const { filePath, rootDir, outDir, mapExposeToEntry } = options;
|
|
1195
|
+
const relativeFilePath = removeExt(relative(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
|
|
1196
|
+
return mapExposeToEntry[relativeFilePath];
|
|
1197
|
+
}
|
|
1198
|
+
__name(getExposeKey, "getExposeKey");
|
|
1199
|
+
var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
|
|
1200
|
+
const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
|
|
1201
|
+
if (!existsSync2(filePath)) {
|
|
1202
|
+
return;
|
|
2056
1203
|
}
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
1204
|
+
const stats = yield stat(filePath);
|
|
1205
|
+
if (stats.isDirectory()) {
|
|
1206
|
+
const files = yield readdir(filePath);
|
|
1207
|
+
yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
|
|
1208
|
+
filePath: join3(filePath, file)
|
|
1209
|
+
}))));
|
|
1210
|
+
} else if (filePath.endsWith(".d.ts")) {
|
|
1211
|
+
const exposeKey = getExposeKey({
|
|
1212
|
+
filePath,
|
|
1213
|
+
rootDir,
|
|
1214
|
+
outDir,
|
|
1215
|
+
mapExposeToEntry
|
|
1216
|
+
});
|
|
1217
|
+
if (exposeKey) {
|
|
1218
|
+
const sourceEntry = exposeKey === "." ? "index" : exposeKey;
|
|
1219
|
+
const mfeTypeEntry = join3(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
1220
|
+
const mfeTypeEntryDirectory = dirname2(mfeTypeEntry);
|
|
1221
|
+
const relativePathToOutput = relative(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(sep).join("/");
|
|
1222
|
+
ensureDirSync(mfeTypeEntryDirectory);
|
|
1223
|
+
yield writeFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
1224
|
+
export { default } from './${relativePathToOutput}';`);
|
|
1225
|
+
}
|
|
1226
|
+
const content = yield readFile(filePath, "utf8");
|
|
1227
|
+
cb(content);
|
|
2081
1228
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
"tsx",
|
|
2087
|
-
"vue",
|
|
2088
|
-
"svelte"
|
|
2089
|
-
];
|
|
2090
|
-
var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
|
|
2091
|
-
if (extname2(exposedPath)) {
|
|
2092
|
-
return resolve3(context, exposedPath);
|
|
1229
|
+
}), "processTypesFile");
|
|
1230
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
1231
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1232
|
+
return;
|
|
2093
1233
|
}
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
1234
|
+
const { compilerOptions } = tsConfig;
|
|
1235
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
|
|
1236
|
+
try {
|
|
1237
|
+
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1238
|
+
const thirdPartyExtractor = new ThirdPartyExtractor2(resolve3(mfTypePath, "node_modules"), remoteOptions.context);
|
|
1239
|
+
const execPromise = util.promisify(exec);
|
|
1240
|
+
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
|
|
1241
|
+
try {
|
|
1242
|
+
yield execPromise(cmd);
|
|
1243
|
+
} catch (err) {
|
|
1244
|
+
throw new Error(`compile TS failed, the original command is '${cmd}'`);
|
|
1245
|
+
}
|
|
1246
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
1247
|
+
const normalizedFileName = normalize(filename);
|
|
1248
|
+
let relativeFileName = "";
|
|
1249
|
+
if (isAbsolute(normalizedFileName)) {
|
|
1250
|
+
relativeFileName = relative(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
1251
|
+
} else {
|
|
1252
|
+
relativeFileName = relative(tsConfig.compilerOptions.rootDir, resolve3(remoteOptions.context, normalizedFileName));
|
|
1253
|
+
}
|
|
1254
|
+
return [
|
|
1255
|
+
removeExt(relativeFileName),
|
|
1256
|
+
exposed
|
|
1257
|
+
];
|
|
1258
|
+
}));
|
|
1259
|
+
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
1260
|
+
yield processTypesFile({
|
|
1261
|
+
outDir: compilerOptions.outDir,
|
|
1262
|
+
filePath: compilerOptions.outDir,
|
|
1263
|
+
rootDir: compilerOptions.rootDir,
|
|
1264
|
+
mfTypePath,
|
|
1265
|
+
cb,
|
|
1266
|
+
mapExposeToEntry
|
|
1267
|
+
});
|
|
1268
|
+
if (remoteOptions.extractThirdParty) {
|
|
1269
|
+
yield thirdPartyExtractor.copyDts();
|
|
1270
|
+
}
|
|
1271
|
+
yield rm3(tempTsConfigJsonPath);
|
|
1272
|
+
} catch (err) {
|
|
1273
|
+
if (isDebugMode()) {
|
|
1274
|
+
console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
|
|
2098
1275
|
}
|
|
1276
|
+
throw err;
|
|
2099
1277
|
}
|
|
2100
|
-
|
|
2101
|
-
}, "resolveWithExtension");
|
|
2102
|
-
var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
|
|
2103
|
-
const parsedOptions = utils2.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
|
|
2104
|
-
exposePath: Array.isArray(item) ? item[0] : item,
|
|
2105
|
-
key
|
|
2106
|
-
}), (item, key) => ({
|
|
2107
|
-
exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
|
|
2108
|
-
key
|
|
2109
|
-
}));
|
|
2110
|
-
return parsedOptions.reduce((accumulator, item) => {
|
|
2111
|
-
const { exposePath, key } = item[1];
|
|
2112
|
-
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(join3(exposePath, "index"), remoteOptions.context) || exposePath;
|
|
2113
|
-
return accumulator;
|
|
2114
|
-
}, {});
|
|
2115
|
-
}, "resolveExposes");
|
|
2116
|
-
var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
2117
|
-
validateOptions(options);
|
|
2118
|
-
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
2119
|
-
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
2120
|
-
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
2121
|
-
return {
|
|
2122
|
-
tsConfig,
|
|
2123
|
-
mapComponentsToExpose,
|
|
2124
|
-
remoteOptions
|
|
2125
|
-
};
|
|
2126
|
-
}, "retrieveRemoteConfig");
|
|
1278
|
+
}), "compileTs");
|
|
2127
1279
|
|
|
2128
1280
|
// packages/dts-plugin/src/core/lib/generateTypes.ts
|
|
2129
1281
|
function generateTypes(options) {
|
|
2130
1282
|
return __async(this, null, function* () {
|
|
2131
|
-
var
|
|
2132
|
-
const DTSManagerConstructor = getDTSManagerConstructor((
|
|
1283
|
+
var _a2;
|
|
1284
|
+
const DTSManagerConstructor = getDTSManagerConstructor((_a2 = options.remote) == null ? void 0 : _a2.implementation);
|
|
2133
1285
|
const dtsManager = new DTSManagerConstructor(options);
|
|
2134
1286
|
return dtsManager.generateTypes();
|
|
2135
1287
|
});
|
|
2136
1288
|
}
|
|
2137
1289
|
__name(generateTypes, "generateTypes");
|
|
2138
1290
|
|
|
2139
|
-
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
2140
|
-
import path4 from "path";
|
|
2141
|
-
import cloneDeepWith2 from "lodash.clonedeepwith";
|
|
2142
|
-
|
|
2143
|
-
// packages/dts-plugin/src/core/rpc/index.ts
|
|
2144
|
-
var rpc_exports = {};
|
|
2145
|
-
__export(rpc_exports, {
|
|
2146
|
-
RpcExitError: () => RpcExitError,
|
|
2147
|
-
RpcGMCallTypes: () => RpcGMCallTypes,
|
|
2148
|
-
createRpcWorker: () => createRpcWorker,
|
|
2149
|
-
exposeRpc: () => exposeRpc,
|
|
2150
|
-
getRpcWorkerData: () => getRpcWorkerData,
|
|
2151
|
-
wrapRpc: () => wrapRpc
|
|
2152
|
-
});
|
|
2153
|
-
|
|
2154
|
-
// packages/dts-plugin/src/core/rpc/expose-rpc.ts
|
|
2155
|
-
import process2 from "process";
|
|
2156
|
-
|
|
2157
1291
|
// packages/dts-plugin/src/core/rpc/types.ts
|
|
2158
1292
|
var RpcGMCallTypes;
|
|
2159
1293
|
(function(RpcGMCallTypes2) {
|
|
@@ -2164,6 +1298,7 @@ var RpcGMCallTypes;
|
|
|
2164
1298
|
})(RpcGMCallTypes || (RpcGMCallTypes = {}));
|
|
2165
1299
|
|
|
2166
1300
|
// packages/dts-plugin/src/core/rpc/expose-rpc.ts
|
|
1301
|
+
import process2 from "process";
|
|
2167
1302
|
function exposeRpc(fn) {
|
|
2168
1303
|
const sendMessage = /* @__PURE__ */ __name((message) => new Promise((resolve4, reject) => {
|
|
2169
1304
|
if (!process2.send) {
|
|
@@ -2171,9 +1306,9 @@ function exposeRpc(fn) {
|
|
|
2171
1306
|
} else if (!process2.connected) {
|
|
2172
1307
|
reject(new Error(`Process ${process2.pid} doesn't have open IPC channels`));
|
|
2173
1308
|
} else {
|
|
2174
|
-
process2.send(message, void 0, void 0, (
|
|
2175
|
-
if (
|
|
2176
|
-
reject(
|
|
1309
|
+
process2.send(message, void 0, void 0, (error) => {
|
|
1310
|
+
if (error) {
|
|
1311
|
+
reject(error);
|
|
2177
1312
|
} else {
|
|
2178
1313
|
resolve4(void 0);
|
|
2179
1314
|
}
|
|
@@ -2185,18 +1320,18 @@ function exposeRpc(fn) {
|
|
|
2185
1320
|
if (!process2.send) {
|
|
2186
1321
|
return;
|
|
2187
1322
|
}
|
|
2188
|
-
let value,
|
|
1323
|
+
let value, error;
|
|
2189
1324
|
try {
|
|
2190
1325
|
value = yield fn(...message.args);
|
|
2191
1326
|
} catch (fnError) {
|
|
2192
|
-
|
|
1327
|
+
error = fnError;
|
|
2193
1328
|
}
|
|
2194
1329
|
try {
|
|
2195
|
-
if (
|
|
1330
|
+
if (error) {
|
|
2196
1331
|
yield sendMessage({
|
|
2197
1332
|
type: RpcGMCallTypes.REJECT,
|
|
2198
1333
|
id: message.id,
|
|
2199
|
-
error
|
|
1334
|
+
error
|
|
2200
1335
|
});
|
|
2201
1336
|
} else {
|
|
2202
1337
|
yield sendMessage({
|
|
@@ -2206,9 +1341,9 @@ function exposeRpc(fn) {
|
|
|
2206
1341
|
});
|
|
2207
1342
|
}
|
|
2208
1343
|
} catch (sendError) {
|
|
2209
|
-
if (
|
|
2210
|
-
if (
|
|
2211
|
-
console.error(
|
|
1344
|
+
if (error) {
|
|
1345
|
+
if (error instanceof Error) {
|
|
1346
|
+
console.error(error);
|
|
2212
1347
|
}
|
|
2213
1348
|
}
|
|
2214
1349
|
console.error(sendError);
|
|
@@ -2219,259 +1354,25 @@ function exposeRpc(fn) {
|
|
|
2219
1354
|
}
|
|
2220
1355
|
__name(exposeRpc, "exposeRpc");
|
|
2221
1356
|
|
|
2222
|
-
// packages/dts-plugin/src/core/rpc/rpc-error.ts
|
|
2223
|
-
var _a2;
|
|
2224
|
-
var RpcExitError = (_a2 = class extends Error {
|
|
2225
|
-
constructor(message, code, signal) {
|
|
2226
|
-
super(message);
|
|
2227
|
-
__publicField(this, "code");
|
|
2228
|
-
__publicField(this, "signal");
|
|
2229
|
-
this.code = code;
|
|
2230
|
-
this.signal = signal;
|
|
2231
|
-
this.name = "RpcExitError";
|
|
2232
|
-
}
|
|
2233
|
-
}, __name(_a2, "RpcExitError"), _a2);
|
|
2234
|
-
|
|
2235
|
-
// packages/dts-plugin/src/core/rpc/wrap-rpc.ts
|
|
2236
|
-
function createControlledPromise() {
|
|
2237
|
-
let resolve4 = /* @__PURE__ */ __name(() => void 0, "resolve");
|
|
2238
|
-
let reject = /* @__PURE__ */ __name(() => void 0, "reject");
|
|
2239
|
-
const promise = new Promise((aResolve, aReject) => {
|
|
2240
|
-
resolve4 = aResolve;
|
|
2241
|
-
reject = aReject;
|
|
2242
|
-
});
|
|
2243
|
-
return {
|
|
2244
|
-
promise,
|
|
2245
|
-
resolve: resolve4,
|
|
2246
|
-
reject
|
|
2247
|
-
};
|
|
2248
|
-
}
|
|
2249
|
-
__name(createControlledPromise, "createControlledPromise");
|
|
2250
|
-
function wrapRpc(childProcess, options) {
|
|
2251
|
-
return (...args) => __async(this, null, function* () {
|
|
2252
|
-
if (!childProcess.send) {
|
|
2253
|
-
throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
|
|
2254
|
-
} else if (!childProcess.connected) {
|
|
2255
|
-
throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
|
|
2256
|
-
}
|
|
2257
|
-
const { id, once } = options;
|
|
2258
|
-
const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
|
|
2259
|
-
const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
|
|
2260
|
-
const handleMessage = /* @__PURE__ */ __name((message) => {
|
|
2261
|
-
if ((message == null ? void 0 : message.id) === id) {
|
|
2262
|
-
if (message.type === RpcGMCallTypes.RESOLVE) {
|
|
2263
|
-
resolveResult(message.value);
|
|
2264
|
-
} else if (message.type === RpcGMCallTypes.REJECT) {
|
|
2265
|
-
rejectResult(message.error);
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
if (once && (childProcess == null ? void 0 : childProcess.kill)) {
|
|
2269
|
-
childProcess.kill("SIGTERM");
|
|
2270
|
-
}
|
|
2271
|
-
}, "handleMessage");
|
|
2272
|
-
const handleClose = /* @__PURE__ */ __name((code, signal) => {
|
|
2273
|
-
rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
|
|
2274
|
-
removeHandlers();
|
|
2275
|
-
}, "handleClose");
|
|
2276
|
-
const removeHandlers = /* @__PURE__ */ __name(() => {
|
|
2277
|
-
childProcess.off("message", handleMessage);
|
|
2278
|
-
childProcess.off("close", handleClose);
|
|
2279
|
-
}, "removeHandlers");
|
|
2280
|
-
if (once) {
|
|
2281
|
-
childProcess.once("message", handleMessage);
|
|
2282
|
-
} else {
|
|
2283
|
-
childProcess.on("message", handleMessage);
|
|
2284
|
-
}
|
|
2285
|
-
childProcess.on("close", handleClose);
|
|
2286
|
-
childProcess.send({
|
|
2287
|
-
type: RpcGMCallTypes.CALL,
|
|
2288
|
-
id,
|
|
2289
|
-
args
|
|
2290
|
-
}, (error2) => {
|
|
2291
|
-
if (error2) {
|
|
2292
|
-
rejectSend(error2);
|
|
2293
|
-
removeHandlers();
|
|
2294
|
-
} else {
|
|
2295
|
-
resolveSend(void 0);
|
|
2296
|
-
}
|
|
2297
|
-
});
|
|
2298
|
-
return sendPromise.then(() => resultPromise);
|
|
2299
|
-
});
|
|
2300
|
-
}
|
|
2301
|
-
__name(wrapRpc, "wrapRpc");
|
|
2302
|
-
|
|
2303
|
-
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
2304
|
-
import * as child_process from "child_process";
|
|
2305
|
-
import * as process3 from "process";
|
|
2306
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
2307
|
-
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
2308
|
-
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
2309
|
-
const options = {
|
|
2310
|
-
env: __spreadProps(__spreadValues({}, process3.env), {
|
|
2311
|
-
[FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
|
|
2312
|
-
}),
|
|
2313
|
-
stdio: [
|
|
2314
|
-
"inherit",
|
|
2315
|
-
"inherit",
|
|
2316
|
-
"inherit",
|
|
2317
|
-
"ipc"
|
|
2318
|
-
],
|
|
2319
|
-
serialization: "advanced"
|
|
2320
|
-
};
|
|
2321
|
-
if (memoryLimit) {
|
|
2322
|
-
options.execArgv = [
|
|
2323
|
-
`--max-old-space-size=${memoryLimit}`
|
|
2324
|
-
];
|
|
2325
|
-
}
|
|
2326
|
-
let childProcess, remoteMethod;
|
|
2327
|
-
const id = randomUUID2();
|
|
2328
|
-
const worker = {
|
|
2329
|
-
connect(...args) {
|
|
2330
|
-
if (childProcess && !childProcess.connected) {
|
|
2331
|
-
childProcess.send({
|
|
2332
|
-
type: RpcGMCallTypes.EXIT,
|
|
2333
|
-
id
|
|
2334
|
-
});
|
|
2335
|
-
childProcess = void 0;
|
|
2336
|
-
remoteMethod = void 0;
|
|
2337
|
-
}
|
|
2338
|
-
if (!(childProcess == null ? void 0 : childProcess.connected)) {
|
|
2339
|
-
childProcess = child_process.fork(modulePath, options);
|
|
2340
|
-
remoteMethod = wrapRpc(childProcess, {
|
|
2341
|
-
id,
|
|
2342
|
-
once
|
|
2343
|
-
});
|
|
2344
|
-
}
|
|
2345
|
-
if (!remoteMethod) {
|
|
2346
|
-
return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
|
|
2347
|
-
}
|
|
2348
|
-
return remoteMethod(...args);
|
|
2349
|
-
},
|
|
2350
|
-
terminate() {
|
|
2351
|
-
var _a3;
|
|
2352
|
-
(_a3 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a3.call(childProcess, {
|
|
2353
|
-
type: RpcGMCallTypes.EXIT,
|
|
2354
|
-
id
|
|
2355
|
-
});
|
|
2356
|
-
childProcess = void 0;
|
|
2357
|
-
remoteMethod = void 0;
|
|
2358
|
-
},
|
|
2359
|
-
get connected() {
|
|
2360
|
-
return Boolean(childProcess == null ? void 0 : childProcess.connected);
|
|
2361
|
-
},
|
|
2362
|
-
get process() {
|
|
2363
|
-
return childProcess;
|
|
2364
|
-
},
|
|
2365
|
-
get id() {
|
|
2366
|
-
return id;
|
|
2367
|
-
}
|
|
2368
|
-
};
|
|
2369
|
-
return worker;
|
|
2370
|
-
}
|
|
2371
|
-
__name(createRpcWorker, "createRpcWorker");
|
|
2372
|
-
function getRpcWorkerData() {
|
|
2373
|
-
return JSON.parse(process3.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
|
|
2374
|
-
}
|
|
2375
|
-
__name(getRpcWorkerData, "getRpcWorkerData");
|
|
2376
|
-
|
|
2377
|
-
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
2378
|
-
var _DtsWorker = class _DtsWorker {
|
|
2379
|
-
constructor(options) {
|
|
2380
|
-
__publicField(this, "rpcWorker");
|
|
2381
|
-
__publicField(this, "_options");
|
|
2382
|
-
__publicField(this, "_res");
|
|
2383
|
-
this._options = cloneDeepWith2(options, (_value, key) => {
|
|
2384
|
-
if (key === "manifest") {
|
|
2385
|
-
return false;
|
|
2386
|
-
}
|
|
2387
|
-
});
|
|
2388
|
-
this.removeUnSerializationOptions();
|
|
2389
|
-
this.rpcWorker = createRpcWorker(path4.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
|
|
2390
|
-
this._res = this.rpcWorker.connect(this._options);
|
|
2391
|
-
}
|
|
2392
|
-
removeUnSerializationOptions() {
|
|
2393
|
-
var _a3, _b, _c, _d, _e, _f, _g, _h;
|
|
2394
|
-
if ((_b = (_a3 = this._options.remote) == null ? void 0 : _a3.moduleFederationConfig) == null ? void 0 : _b.manifest) {
|
|
2395
|
-
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
2396
|
-
}
|
|
2397
|
-
if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
|
|
2398
|
-
(_h = (_g = this._options.host) == null ? void 0 : _g.moduleFederationConfig) == null ? true : delete _h.manifest;
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
get controlledPromise() {
|
|
2402
|
-
const ensureChildProcessExit = /* @__PURE__ */ __name(() => {
|
|
2403
|
-
var _a3;
|
|
2404
|
-
try {
|
|
2405
|
-
const pid = (_a3 = this.rpcWorker.process) == null ? void 0 : _a3.pid;
|
|
2406
|
-
const rootPid = process.pid;
|
|
2407
|
-
if (pid && rootPid !== pid) {
|
|
2408
|
-
process.kill(pid, 0);
|
|
2409
|
-
}
|
|
2410
|
-
} catch (error2) {
|
|
2411
|
-
if (isDebugMode()) {
|
|
2412
|
-
console.error(error2);
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
}, "ensureChildProcessExit");
|
|
2416
|
-
return Promise.resolve(this._res).then(() => {
|
|
2417
|
-
this.exit();
|
|
2418
|
-
ensureChildProcessExit();
|
|
2419
|
-
}).catch((err) => {
|
|
2420
|
-
if (isDebugMode()) {
|
|
2421
|
-
console.error(err);
|
|
2422
|
-
}
|
|
2423
|
-
ensureChildProcessExit();
|
|
2424
|
-
});
|
|
2425
|
-
}
|
|
2426
|
-
exit() {
|
|
2427
|
-
var _a3;
|
|
2428
|
-
(_a3 = this.rpcWorker) == null ? void 0 : _a3.terminate();
|
|
2429
|
-
}
|
|
2430
|
-
};
|
|
2431
|
-
__name(_DtsWorker, "DtsWorker");
|
|
2432
|
-
var DtsWorker = _DtsWorker;
|
|
2433
|
-
|
|
2434
|
-
// packages/dts-plugin/src/core/lib/generateTypesInChildProcess.ts
|
|
2435
|
-
function generateTypesInChildProcess(options) {
|
|
2436
|
-
return __async(this, null, function* () {
|
|
2437
|
-
const dtsWorker = new DtsWorker(options);
|
|
2438
|
-
return dtsWorker.controlledPromise;
|
|
2439
|
-
});
|
|
2440
|
-
}
|
|
2441
|
-
__name(generateTypesInChildProcess, "generateTypesInChildProcess");
|
|
2442
|
-
|
|
2443
|
-
// packages/dts-plugin/src/core/lib/consumeTypes.ts
|
|
2444
|
-
function consumeTypes(options) {
|
|
2445
|
-
return __async(this, null, function* () {
|
|
2446
|
-
var _a3;
|
|
2447
|
-
const DTSManagerConstructor = getDTSManagerConstructor((_a3 = options.host) == null ? void 0 : _a3.implementation);
|
|
2448
|
-
const dtsManager = new DTSManagerConstructor(options);
|
|
2449
|
-
yield dtsManager.consumeTypes();
|
|
2450
|
-
});
|
|
2451
|
-
}
|
|
2452
|
-
__name(consumeTypes, "consumeTypes");
|
|
2453
|
-
|
|
2454
1357
|
export {
|
|
2455
1358
|
retrieveMfTypesPath,
|
|
2456
1359
|
retrieveOriginalOutDir,
|
|
2457
|
-
fileLog,
|
|
2458
|
-
getIPV4,
|
|
2459
|
-
Broker,
|
|
2460
1360
|
ModuleFederationDevServer,
|
|
2461
1361
|
createKoaServer,
|
|
2462
1362
|
retrieveTypesZipPath,
|
|
2463
1363
|
retrieveHostConfig,
|
|
1364
|
+
REMOTE_ALIAS_IDENTIFIER,
|
|
1365
|
+
REMOTE_API_TYPES_FILE_NAME,
|
|
1366
|
+
HOST_API_TYPES_FILE_NAME,
|
|
2464
1367
|
DTSManager,
|
|
2465
1368
|
getDTSManagerConstructor,
|
|
2466
1369
|
validateOptions,
|
|
2467
1370
|
retrieveTypesAssetsInfo,
|
|
1371
|
+
isDebugMode,
|
|
2468
1372
|
isTSProject,
|
|
1373
|
+
cloneDeepOptions,
|
|
2469
1374
|
retrieveRemoteConfig,
|
|
2470
1375
|
generateTypes,
|
|
2471
1376
|
RpcGMCallTypes,
|
|
2472
|
-
exposeRpc
|
|
2473
|
-
rpc_exports,
|
|
2474
|
-
DtsWorker,
|
|
2475
|
-
generateTypesInChildProcess,
|
|
2476
|
-
consumeTypes
|
|
1377
|
+
exposeRpc
|
|
2477
1378
|
};
|