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