@module-federation/dts-plugin 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.md +24 -0
- package/dist/{DtsWorker-d731dc2b.d.ts → DtsWorker-7113d2b0.d.ts} +6 -3
- package/dist/core.d.mts +85 -0
- package/dist/core.d.ts +5 -5
- package/dist/core.js +1055 -993
- package/dist/dynamic-remote-type-hints-plugin.d.mts +5 -0
- package/dist/dynamic-remote-type-hints-plugin.d.ts +5 -0
- package/dist/dynamic-remote-type-hints-plugin.js +198 -0
- package/dist/esm/chunk-AJO6KMSF.js +2337 -0
- package/dist/esm/chunk-G7ONFBMA.js +24 -0
- package/dist/esm/chunk-MQRIERJP.js +236 -0
- package/dist/esm/core.js +44 -0
- package/dist/esm/dynamic-remote-type-hints-plugin.js +73 -0
- package/dist/esm/fork-dev-worker.js +141 -0
- package/dist/esm/fork-generate-dts.js +26 -0
- package/dist/esm/index.js +406 -0
- package/dist/esm/start-broker.js +36 -0
- package/dist/fork-dev-worker.d.ts +15 -0
- package/dist/fork-dev-worker.js +2506 -0
- package/dist/{forkGenerateDts.d.ts → fork-generate-dts.d.mts} +1 -1
- package/dist/fork-generate-dts.d.ts +9 -0
- package/dist/fork-generate-dts.js +1865 -0
- package/dist/iife/launch-web-client.js +91 -42
- package/dist/index.d.mts +10 -0
- package/dist/index.js +1242 -1171
- package/dist/package.json +11 -2
- package/dist/{startBroker.d.ts → start-broker.d.mts} +2 -0
- package/dist/start-broker.d.ts +42 -0
- package/dist/start-broker.js +1276 -0
- package/package.json +14 -5
- package/dist/forkDevWorker.js +0 -2523
- package/dist/forkGenerateDts.js +0 -1618
- package/dist/launch-web-client.d.ts +0 -2
- package/dist/startBroker.js +0 -902
- /package/dist/{forkDevWorker.d.ts → fork-dev-worker.d.mts} +0 -0
package/dist/core.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
25
|
var __export = (target, all) => {
|
|
9
26
|
for (var name in all)
|
|
10
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,6 +43,30 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
43
|
mod
|
|
27
44
|
));
|
|
28
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __publicField = (obj, key, value) => {
|
|
47
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
var __async = (__this, __arguments, generator) => {
|
|
51
|
+
return new Promise((resolve4, reject) => {
|
|
52
|
+
var fulfilled = (value) => {
|
|
53
|
+
try {
|
|
54
|
+
step(generator.next(value));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var rejected = (value) => {
|
|
60
|
+
try {
|
|
61
|
+
step(generator.throw(value));
|
|
62
|
+
} catch (e) {
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var step = (x) => x.done ? resolve4(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
67
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
68
|
+
});
|
|
69
|
+
};
|
|
29
70
|
|
|
30
71
|
// packages/dts-plugin/src/core/index.ts
|
|
31
72
|
var core_exports = {};
|
|
@@ -68,6 +109,7 @@ var import_promises = require("fs/promises");
|
|
|
68
109
|
var import_fs = __toESM(require("fs"));
|
|
69
110
|
var import_sdk4 = require("@module-federation/sdk");
|
|
70
111
|
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
112
|
+
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
71
113
|
|
|
72
114
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
73
115
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
@@ -81,77 +123,43 @@ var import_typescript = __toESM(require("typescript"));
|
|
|
81
123
|
var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
82
124
|
var STARTS_WITH_SLASH = /^\//;
|
|
83
125
|
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
84
|
-
var reportCompileDiagnostic = (diagnostic) => {
|
|
85
|
-
const { line } = diagnostic.file.getLineAndCharacterOfPosition(
|
|
86
|
-
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)}`
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
console.error(
|
|
97
|
-
import_ansi_colors.default.red(
|
|
98
|
-
` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`
|
|
99
|
-
)
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
var retrieveMfTypesPath = (tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, ""));
|
|
103
|
-
var retrieveOriginalOutDir = (tsConfig, remoteOptions) => (0, import_path.normalize)(
|
|
104
|
-
tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")
|
|
105
|
-
);
|
|
106
|
-
var retrieveMfAPITypesPath = (tsConfig, remoteOptions) => (0, import_path.join)(
|
|
107
|
-
retrieveOriginalOutDir(tsConfig, remoteOptions),
|
|
108
|
-
`${remoteOptions.typesFolder}.d.ts`
|
|
109
|
-
);
|
|
110
|
-
var createHost = (mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
|
|
126
|
+
var reportCompileDiagnostic = /* @__PURE__ */ __name((diagnostic) => {
|
|
127
|
+
const { line } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
128
|
+
console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
|
|
129
|
+
console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
|
|
130
|
+
}, "reportCompileDiagnostic");
|
|
131
|
+
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
132
|
+
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
133
|
+
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
134
|
+
var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
|
|
111
135
|
const host = import_typescript.default.createCompilerHost(tsConfig);
|
|
112
136
|
const originalWriteFile = host.writeFile;
|
|
113
|
-
const mapExposeToEntry = Object.fromEntries(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
])
|
|
118
|
-
);
|
|
137
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => [
|
|
138
|
+
(0, import_path.normalize)(filename),
|
|
139
|
+
exposed
|
|
140
|
+
]));
|
|
119
141
|
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
120
142
|
host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
|
|
121
|
-
originalWriteFile(
|
|
122
|
-
filepath,
|
|
123
|
-
text,
|
|
124
|
-
writeOrderByteMark,
|
|
125
|
-
onError,
|
|
126
|
-
sourceFiles,
|
|
127
|
-
data
|
|
128
|
-
);
|
|
143
|
+
originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
|
|
129
144
|
for (const sourceFile of sourceFiles || []) {
|
|
130
145
|
const sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
|
|
131
146
|
if (sourceEntry) {
|
|
132
|
-
const mfeTypeEntry = (0, import_path.join)(
|
|
133
|
-
mfTypePath,
|
|
134
|
-
`${sourceEntry}${DEFINITION_FILE_EXTENSION}`
|
|
135
|
-
);
|
|
147
|
+
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
136
148
|
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
137
149
|
const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filepath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
|
|
138
|
-
originalWriteFile(
|
|
139
|
-
|
|
140
|
-
`export * from './${relativePathToOutput}';
|
|
141
|
-
export { default } from './${relativePathToOutput}';`,
|
|
142
|
-
writeOrderByteMark
|
|
143
|
-
);
|
|
150
|
+
originalWriteFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
151
|
+
export { default } from './${relativePathToOutput}';`, writeOrderByteMark);
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
cb(text);
|
|
147
155
|
};
|
|
148
156
|
return host;
|
|
149
|
-
};
|
|
150
|
-
var createVueTscProgram = (programOptions) => {
|
|
157
|
+
}, "createHost");
|
|
158
|
+
var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
|
|
151
159
|
const vueTypescript = require("vue-tsc");
|
|
152
160
|
return vueTypescript.createProgram(programOptions);
|
|
153
|
-
};
|
|
154
|
-
var createProgram = (remoteOptions, programOptions) => {
|
|
161
|
+
}, "createVueTscProgram");
|
|
162
|
+
var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
|
|
155
163
|
switch (remoteOptions.compilerInstance) {
|
|
156
164
|
case "vue-tsc":
|
|
157
165
|
return createVueTscProgram(programOptions);
|
|
@@ -159,13 +167,10 @@ var createProgram = (remoteOptions, programOptions) => {
|
|
|
159
167
|
default:
|
|
160
168
|
return import_typescript.default.createProgram(programOptions);
|
|
161
169
|
}
|
|
162
|
-
};
|
|
163
|
-
var compileTs = (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
170
|
+
}, "createProgram");
|
|
171
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
164
172
|
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
165
|
-
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor(
|
|
166
|
-
(0, import_path.resolve)(mfTypePath, "node_modules"),
|
|
167
|
-
remoteOptions.context
|
|
168
|
-
);
|
|
173
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
169
174
|
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
170
175
|
const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
|
|
171
176
|
const filesToCompile = [
|
|
@@ -183,52 +188,77 @@ var compileTs = (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
|
183
188
|
if (remoteOptions.extractThirdParty) {
|
|
184
189
|
thirdPartyExtractor.copyDts();
|
|
185
190
|
}
|
|
186
|
-
};
|
|
191
|
+
}, "compileTs");
|
|
187
192
|
|
|
188
193
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
189
|
-
var
|
|
194
|
+
var _Message = class _Message {
|
|
190
195
|
constructor(type, kind) {
|
|
196
|
+
__publicField(this, "type");
|
|
197
|
+
__publicField(this, "kind");
|
|
198
|
+
__publicField(this, "time");
|
|
191
199
|
this.type = type;
|
|
192
200
|
this.kind = kind;
|
|
193
201
|
this.time = Date.now();
|
|
194
202
|
}
|
|
195
203
|
};
|
|
204
|
+
__name(_Message, "Message");
|
|
205
|
+
var Message = _Message;
|
|
196
206
|
|
|
197
207
|
// packages/dts-plugin/src/server/message/API/API.ts
|
|
198
|
-
var
|
|
208
|
+
var APIKind;
|
|
209
|
+
(function(APIKind2) {
|
|
210
|
+
APIKind2["UPDATE_SUBSCRIBER"] = "UPDATE_SUBSCRIBER";
|
|
211
|
+
APIKind2["RELOAD_WEB_CLIENT"] = "RELOAD_WEB_CLIENT";
|
|
212
|
+
APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
213
|
+
})(APIKind || (APIKind = {}));
|
|
214
|
+
var _API = class _API extends Message {
|
|
199
215
|
constructor(content, kind) {
|
|
200
216
|
super("API", kind);
|
|
217
|
+
__publicField(this, "code");
|
|
218
|
+
__publicField(this, "payload");
|
|
201
219
|
const { code, payload } = content;
|
|
202
220
|
this.code = code;
|
|
203
221
|
this.payload = payload;
|
|
204
222
|
}
|
|
205
223
|
};
|
|
224
|
+
__name(_API, "API");
|
|
225
|
+
var API = _API;
|
|
206
226
|
|
|
207
227
|
// packages/dts-plugin/src/server/message/API/UpdateSubscriber.ts
|
|
208
|
-
var
|
|
228
|
+
var _UpdateSubscriberAPI = class _UpdateSubscriberAPI extends API {
|
|
209
229
|
constructor(payload) {
|
|
210
|
-
super(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
},
|
|
215
|
-
"UPDATE_SUBSCRIBER" /* UPDATE_SUBSCRIBER */
|
|
216
|
-
);
|
|
230
|
+
super({
|
|
231
|
+
code: 0,
|
|
232
|
+
payload
|
|
233
|
+
}, APIKind.UPDATE_SUBSCRIBER);
|
|
217
234
|
}
|
|
218
235
|
};
|
|
236
|
+
__name(_UpdateSubscriberAPI, "UpdateSubscriberAPI");
|
|
237
|
+
var UpdateSubscriberAPI = _UpdateSubscriberAPI;
|
|
219
238
|
|
|
220
239
|
// packages/dts-plugin/src/server/message/API/ReloadWebClient.ts
|
|
221
|
-
var
|
|
240
|
+
var _ReloadWebClientAPI = class _ReloadWebClientAPI extends API {
|
|
222
241
|
constructor(payload) {
|
|
223
|
-
super(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
242
|
+
super({
|
|
243
|
+
code: 0,
|
|
244
|
+
payload
|
|
245
|
+
}, APIKind.RELOAD_WEB_CLIENT);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
__name(_ReloadWebClientAPI, "ReloadWebClientAPI");
|
|
249
|
+
var ReloadWebClientAPI = _ReloadWebClientAPI;
|
|
250
|
+
|
|
251
|
+
// packages/dts-plugin/src/server/message/API/FetchTypes.ts
|
|
252
|
+
var _FetchTypesAPI = class _FetchTypesAPI extends API {
|
|
253
|
+
constructor(payload) {
|
|
254
|
+
super({
|
|
255
|
+
code: 0,
|
|
256
|
+
payload
|
|
257
|
+
}, APIKind.FETCH_TYPES);
|
|
230
258
|
}
|
|
231
259
|
};
|
|
260
|
+
__name(_FetchTypesAPI, "FetchTypesAPI");
|
|
261
|
+
var FetchTypesAPI = _FetchTypesAPI;
|
|
232
262
|
|
|
233
263
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
234
264
|
var import_sdk2 = require("@module-federation/sdk");
|
|
@@ -237,21 +267,37 @@ var import_sdk2 = require("@module-federation/sdk");
|
|
|
237
267
|
var import_chalk = __toESM(require("chalk"));
|
|
238
268
|
|
|
239
269
|
// packages/dts-plugin/src/server/message/Log/Log.ts
|
|
240
|
-
var
|
|
270
|
+
var LogLevel;
|
|
271
|
+
(function(LogLevel2) {
|
|
272
|
+
LogLevel2["LOG"] = "LOG";
|
|
273
|
+
LogLevel2["WARN"] = "WARN";
|
|
274
|
+
LogLevel2["ERROR"] = "ERROR";
|
|
275
|
+
})(LogLevel || (LogLevel = {}));
|
|
276
|
+
var LogKind;
|
|
277
|
+
(function(LogKind2) {
|
|
278
|
+
LogKind2["BrokerExitLog"] = "BrokerExitLog";
|
|
279
|
+
LogKind2["PublisherRegisteredLog"] = "PublisherRegisteredLog";
|
|
280
|
+
})(LogKind || (LogKind = {}));
|
|
281
|
+
var _Log = class _Log extends Message {
|
|
241
282
|
constructor(level, kind, ignoreVerbose = false) {
|
|
242
283
|
super("Log", kind);
|
|
243
|
-
this
|
|
284
|
+
__publicField(this, "level");
|
|
285
|
+
__publicField(this, "ignoreVerbose", false);
|
|
244
286
|
this.level = level;
|
|
245
287
|
this.ignoreVerbose = ignoreVerbose;
|
|
246
288
|
}
|
|
247
289
|
};
|
|
290
|
+
__name(_Log, "Log");
|
|
291
|
+
var Log = _Log;
|
|
248
292
|
|
|
249
293
|
// packages/dts-plugin/src/server/message/Log/BrokerExitLog.ts
|
|
250
|
-
var
|
|
294
|
+
var _BrokerExitLog = class _BrokerExitLog extends Log {
|
|
251
295
|
constructor() {
|
|
252
|
-
super(
|
|
296
|
+
super(LogLevel.LOG, LogKind.BrokerExitLog);
|
|
253
297
|
}
|
|
254
298
|
};
|
|
299
|
+
__name(_BrokerExitLog, "BrokerExitLog");
|
|
300
|
+
var BrokerExitLog = _BrokerExitLog;
|
|
255
301
|
|
|
256
302
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
257
303
|
var import_sdk = require("@module-federation/sdk");
|
|
@@ -264,43 +310,70 @@ var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
|
|
|
264
310
|
|
|
265
311
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
266
312
|
function fileLog(msg, module2, level) {
|
|
267
|
-
var
|
|
268
|
-
if (!((
|
|
313
|
+
var _a3, _b;
|
|
314
|
+
if (!((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3["FEDERATION_DEBUG"])) {
|
|
269
315
|
return;
|
|
270
316
|
}
|
|
271
317
|
log4js.configure({
|
|
272
318
|
appenders: {
|
|
273
|
-
[module2]: {
|
|
274
|
-
|
|
319
|
+
[module2]: {
|
|
320
|
+
type: "file",
|
|
321
|
+
filename: ".mf/typesGenerate.log"
|
|
322
|
+
},
|
|
323
|
+
default: {
|
|
324
|
+
type: "file",
|
|
325
|
+
filename: ".mf/typesGenerate.log"
|
|
326
|
+
}
|
|
275
327
|
},
|
|
276
328
|
categories: {
|
|
277
|
-
[module2]: {
|
|
278
|
-
|
|
329
|
+
[module2]: {
|
|
330
|
+
appenders: [
|
|
331
|
+
module2
|
|
332
|
+
],
|
|
333
|
+
level: "error"
|
|
334
|
+
},
|
|
335
|
+
default: {
|
|
336
|
+
appenders: [
|
|
337
|
+
"default"
|
|
338
|
+
],
|
|
339
|
+
level: "trace"
|
|
340
|
+
}
|
|
279
341
|
}
|
|
280
342
|
});
|
|
281
343
|
const logger4 = log4js.getLogger(module2);
|
|
282
344
|
logger4.level = "debug";
|
|
283
345
|
(_b = logger4[level]) == null ? void 0 : _b.call(logger4, msg);
|
|
284
346
|
}
|
|
347
|
+
__name(fileLog, "fileLog");
|
|
285
348
|
function error(error2, action, from) {
|
|
286
349
|
const err = error2 instanceof Error ? error2 : new Error(`${action} error`);
|
|
287
350
|
fileLog(`[${action}] error: ${err}`, from, "fatal");
|
|
288
351
|
return err.toString();
|
|
289
352
|
}
|
|
353
|
+
__name(error, "error");
|
|
290
354
|
|
|
291
355
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
292
356
|
function getIdentifier(options) {
|
|
293
357
|
const { ip, name } = options;
|
|
294
358
|
return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
|
|
295
359
|
}
|
|
360
|
+
__name(getIdentifier, "getIdentifier");
|
|
296
361
|
|
|
297
362
|
// packages/dts-plugin/src/server/Publisher.ts
|
|
298
|
-
var
|
|
363
|
+
var _Publisher = class _Publisher {
|
|
299
364
|
constructor(ctx) {
|
|
365
|
+
__publicField(this, "_ip");
|
|
366
|
+
__publicField(this, "_name");
|
|
367
|
+
__publicField(this, "_remoteTypeTarPath");
|
|
368
|
+
__publicField(this, "_subscribers");
|
|
369
|
+
__publicField(this, "_ws");
|
|
370
|
+
__publicField(this, "dynamicRemoteMap");
|
|
300
371
|
this._name = ctx.name;
|
|
301
372
|
this._ip = ctx.ip;
|
|
302
373
|
this._remoteTypeTarPath = ctx.remoteTypeTarPath;
|
|
303
374
|
this._subscribers = /* @__PURE__ */ new Map();
|
|
375
|
+
this._ws = ctx.ws;
|
|
376
|
+
this.dynamicRemoteMap = /* @__PURE__ */ new Map();
|
|
304
377
|
}
|
|
305
378
|
get identifier() {
|
|
306
379
|
return getIdentifier({
|
|
@@ -329,33 +402,27 @@ var Publisher = class {
|
|
|
329
402
|
}
|
|
330
403
|
removeSubscriber(identifier) {
|
|
331
404
|
if (this._subscribers.has(identifier)) {
|
|
332
|
-
fileLog(
|
|
333
|
-
`${this.name} removeSubscriber: ${identifier}`,
|
|
334
|
-
"Publisher",
|
|
335
|
-
"warn"
|
|
336
|
-
);
|
|
405
|
+
fileLog(`${this.name} removeSubscriber: ${identifier}`, "Publisher", "warn");
|
|
337
406
|
this._subscribers.delete(identifier);
|
|
338
407
|
}
|
|
339
408
|
}
|
|
340
409
|
notifySubscriber(subscriberIdentifier, options) {
|
|
341
410
|
const subscriber = this._subscribers.get(subscriberIdentifier);
|
|
342
411
|
if (!subscriber) {
|
|
343
|
-
fileLog(
|
|
344
|
-
`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`,
|
|
345
|
-
"Publisher",
|
|
346
|
-
"error"
|
|
347
|
-
);
|
|
412
|
+
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`, "Publisher", "error");
|
|
348
413
|
return;
|
|
349
414
|
}
|
|
350
415
|
const api = new UpdateSubscriberAPI(options);
|
|
351
416
|
subscriber.send(JSON.stringify(api));
|
|
352
|
-
fileLog(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
417
|
+
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(subscriberIdentifier)}, message: ${JSON.stringify(api)}`, "Publisher", "info");
|
|
418
|
+
}
|
|
419
|
+
fetchRemoteTypes(options) {
|
|
420
|
+
fileLog(`[fetchRemoteTypes] ${this.name} fetchRemoteTypes, options: ${JSON.stringify(options)}, ws: ${Boolean(this._ws)}`, "Publisher", "info");
|
|
421
|
+
if (!this._ws) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const api = new FetchTypesAPI(options);
|
|
425
|
+
this._ws.send(JSON.stringify(api));
|
|
359
426
|
}
|
|
360
427
|
notifySubscribers(options) {
|
|
361
428
|
const api = new UpdateSubscriberAPI(options);
|
|
@@ -364,32 +431,23 @@ var Publisher = class {
|
|
|
364
431
|
broadcast(message) {
|
|
365
432
|
if (this.hasSubscribes) {
|
|
366
433
|
this._subscribers.forEach((subscriber, key) => {
|
|
367
|
-
fileLog(
|
|
368
|
-
`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`,
|
|
369
|
-
"Publisher",
|
|
370
|
-
"info"
|
|
371
|
-
);
|
|
434
|
+
fileLog(`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`, "Publisher", "info");
|
|
372
435
|
subscriber.send(JSON.stringify(message));
|
|
373
436
|
});
|
|
374
437
|
} else {
|
|
375
|
-
fileLog(
|
|
376
|
-
`[BroadCast] ${this.name}'s subscribe is empty`,
|
|
377
|
-
"Publisher",
|
|
378
|
-
"warn"
|
|
379
|
-
);
|
|
438
|
+
fileLog(`[BroadCast] ${this.name}'s subscribe is empty`, "Publisher", "warn");
|
|
380
439
|
}
|
|
381
440
|
}
|
|
382
441
|
close() {
|
|
442
|
+
this._ws = void 0;
|
|
383
443
|
this._subscribers.forEach((_subscriber, identifier) => {
|
|
384
|
-
fileLog(
|
|
385
|
-
`[BroadCast] close ${this.name} remove: ${identifier}`,
|
|
386
|
-
"Publisher",
|
|
387
|
-
"warn"
|
|
388
|
-
);
|
|
444
|
+
fileLog(`[BroadCast] close ${this.name} remove: ${identifier}`, "Publisher", "warn");
|
|
389
445
|
this.removeSubscriber(identifier);
|
|
390
446
|
});
|
|
391
447
|
}
|
|
392
448
|
};
|
|
449
|
+
__name(_Publisher, "Publisher");
|
|
450
|
+
var Publisher = _Publisher;
|
|
393
451
|
|
|
394
452
|
// packages/dts-plugin/src/server/DevServer.ts
|
|
395
453
|
var import_isomorphic_ws2 = __toESM(require("isomorphic-ws"));
|
|
@@ -399,13 +457,48 @@ var import_http = require("http");
|
|
|
399
457
|
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
400
458
|
var import_node_schedule = __toESM(require("node-schedule"));
|
|
401
459
|
var import_url = require("url");
|
|
460
|
+
|
|
461
|
+
// packages/dts-plugin/src/server/message/Action/Action.ts
|
|
462
|
+
var ActionKind;
|
|
463
|
+
(function(ActionKind2) {
|
|
464
|
+
ActionKind2["ADD_SUBSCRIBER"] = "ADD_SUBSCRIBER";
|
|
465
|
+
ActionKind2["EXIT_SUBSCRIBER"] = "EXIT_SUBSCRIBER";
|
|
466
|
+
ActionKind2["ADD_PUBLISHER"] = "ADD_PUBLISHER";
|
|
467
|
+
ActionKind2["UPDATE_PUBLISHER"] = "UPDATE_PUBLISHER";
|
|
468
|
+
ActionKind2["NOTIFY_SUBSCRIBER"] = "NOTIFY_SUBSCRIBER";
|
|
469
|
+
ActionKind2["EXIT_PUBLISHER"] = "EXIT_PUBLISHER";
|
|
470
|
+
ActionKind2["ADD_WEB_CLIENT"] = "ADD_WEB_CLIENT";
|
|
471
|
+
ActionKind2["NOTIFY_WEB_CLIENT"] = "NOTIFY_WEB_CLIENT";
|
|
472
|
+
ActionKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
473
|
+
ActionKind2["ADD_DYNAMIC_REMOTE"] = "ADD_DYNAMIC_REMOTE";
|
|
474
|
+
})(ActionKind || (ActionKind = {}));
|
|
475
|
+
|
|
476
|
+
// packages/dts-plugin/src/server/message/Action/Update.ts
|
|
477
|
+
var UpdateKind;
|
|
478
|
+
(function(UpdateKind2) {
|
|
479
|
+
UpdateKind2["UPDATE_TYPE"] = "UPDATE_TYPE";
|
|
480
|
+
UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
|
|
481
|
+
})(UpdateKind || (UpdateKind = {}));
|
|
482
|
+
|
|
483
|
+
// packages/dts-plugin/src/core/constant.ts
|
|
484
|
+
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
485
|
+
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
486
|
+
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
487
|
+
var UpdateMode;
|
|
488
|
+
(function(UpdateMode2) {
|
|
489
|
+
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
490
|
+
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
491
|
+
})(UpdateMode || (UpdateMode = {}));
|
|
492
|
+
|
|
493
|
+
// packages/dts-plugin/src/server/broker/Broker.ts
|
|
402
494
|
var _Broker = class _Broker {
|
|
403
495
|
constructor() {
|
|
404
|
-
|
|
405
|
-
this
|
|
406
|
-
this
|
|
407
|
-
this
|
|
408
|
-
this
|
|
496
|
+
__publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
|
|
497
|
+
__publicField(this, "_webClientMap", /* @__PURE__ */ new Map());
|
|
498
|
+
__publicField(this, "_webSocketServer");
|
|
499
|
+
__publicField(this, "_secureWebSocketServer");
|
|
500
|
+
__publicField(this, "_tmpSubscriberShelter", /* @__PURE__ */ new Map());
|
|
501
|
+
__publicField(this, "_scheduleJob", null);
|
|
409
502
|
this._setSchedule();
|
|
410
503
|
this._startWsServer();
|
|
411
504
|
this._stopWhenSIGTERMOrSIGINT();
|
|
@@ -414,389 +507,407 @@ var _Broker = class _Broker {
|
|
|
414
507
|
get hasPublishers() {
|
|
415
508
|
return Boolean(this._publisherMap.size);
|
|
416
509
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
510
|
+
_startWsServer() {
|
|
511
|
+
return __async(this, null, function* () {
|
|
512
|
+
const wsHandler = /* @__PURE__ */ __name((ws, req) => {
|
|
513
|
+
const { url: reqUrl = "" } = req;
|
|
514
|
+
const { query } = (0, import_url.parse)(reqUrl, true);
|
|
515
|
+
const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
|
|
516
|
+
if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
|
|
517
|
+
ws.on("message", (message) => {
|
|
518
|
+
try {
|
|
519
|
+
const text = message.toString();
|
|
520
|
+
const action = JSON.parse(text);
|
|
521
|
+
fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
|
|
522
|
+
this._takeAction(action, ws);
|
|
523
|
+
} catch (error2) {
|
|
524
|
+
fileLog(`parse action message error: ${error2}`, "Broker", "error");
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
ws.on("error", (e) => {
|
|
528
|
+
fileLog(`parse action message error: ${e}`, "Broker", "error");
|
|
529
|
+
});
|
|
530
|
+
} else {
|
|
531
|
+
ws.send("Invalid CONNECT ID.");
|
|
532
|
+
fileLog("Invalid CONNECT ID.", "Broker", "warn");
|
|
533
|
+
ws.close();
|
|
534
|
+
}
|
|
535
|
+
}, "wsHandler");
|
|
536
|
+
const server = (0, import_http.createServer)();
|
|
537
|
+
this._webSocketServer = new import_isomorphic_ws.default.Server({
|
|
538
|
+
noServer: true
|
|
539
|
+
});
|
|
540
|
+
this._webSocketServer.on("error", (err) => {
|
|
541
|
+
fileLog(`ws error:
|
|
446
542
|
${err.message}
|
|
447
543
|
${err.stack}`, "Broker", "error");
|
|
544
|
+
});
|
|
545
|
+
this._webSocketServer.on("listening", () => {
|
|
546
|
+
fileLog(`WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`, "Broker", "info");
|
|
547
|
+
});
|
|
548
|
+
this._webSocketServer.on("connection", wsHandler);
|
|
549
|
+
this._webSocketServer.on("close", (code) => {
|
|
550
|
+
fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
|
|
551
|
+
this._webSocketServer && this._webSocketServer.close();
|
|
552
|
+
this._webSocketServer = void 0;
|
|
553
|
+
});
|
|
554
|
+
server.on("upgrade", (req, socket, head) => {
|
|
555
|
+
var _a3;
|
|
556
|
+
if (req.url) {
|
|
557
|
+
const { pathname } = (0, import_url.parse)(req.url);
|
|
558
|
+
if (pathname === "/") {
|
|
559
|
+
(_a3 = this._webSocketServer) == null ? void 0 : _a3.handleUpgrade(req, socket, head, (ws) => {
|
|
560
|
+
var _a4;
|
|
561
|
+
(_a4 = this._webSocketServer) == null ? void 0 : _a4.emit("connection", ws, req);
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
448
567
|
});
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
568
|
+
}
|
|
569
|
+
_takeAction(action, client) {
|
|
570
|
+
return __async(this, null, function* () {
|
|
571
|
+
const { kind, payload } = action;
|
|
572
|
+
if (kind === ActionKind.ADD_PUBLISHER) {
|
|
573
|
+
yield this._addPublisher(payload, client);
|
|
574
|
+
}
|
|
575
|
+
if (kind === ActionKind.UPDATE_PUBLISHER) {
|
|
576
|
+
yield this._updatePublisher(payload, client);
|
|
577
|
+
}
|
|
578
|
+
if (kind === ActionKind.ADD_SUBSCRIBER) {
|
|
579
|
+
yield this._addSubscriber(payload, client);
|
|
580
|
+
}
|
|
581
|
+
if (kind === ActionKind.EXIT_SUBSCRIBER) {
|
|
582
|
+
yield this._removeSubscriber(payload, client);
|
|
583
|
+
}
|
|
584
|
+
if (kind === ActionKind.EXIT_PUBLISHER) {
|
|
585
|
+
yield this._removePublisher(payload, client);
|
|
586
|
+
}
|
|
587
|
+
if (kind === ActionKind.ADD_WEB_CLIENT) {
|
|
588
|
+
yield this._addWebClient(payload, client);
|
|
589
|
+
}
|
|
590
|
+
if (kind === ActionKind.NOTIFY_WEB_CLIENT) {
|
|
591
|
+
yield this._notifyWebClient(payload, client);
|
|
592
|
+
}
|
|
593
|
+
if (kind === ActionKind.FETCH_TYPES) {
|
|
594
|
+
yield this._fetchTypes(payload, client);
|
|
595
|
+
}
|
|
596
|
+
if (kind === ActionKind.ADD_DYNAMIC_REMOTE) {
|
|
597
|
+
this._addDynamicRemote(payload);
|
|
598
|
+
}
|
|
461
599
|
});
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
600
|
+
}
|
|
601
|
+
_addPublisher(context, client) {
|
|
602
|
+
return __async(this, null, function* () {
|
|
603
|
+
const { name, ip, remoteTypeTarPath } = context != null ? context : {};
|
|
604
|
+
const identifier = getIdentifier({
|
|
605
|
+
name,
|
|
606
|
+
ip
|
|
607
|
+
});
|
|
608
|
+
if (this._publisherMap.has(identifier)) {
|
|
609
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} has been added, this action will be ignored`, "Broker", "warn");
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
const publisher = new Publisher({
|
|
614
|
+
name,
|
|
615
|
+
ip,
|
|
616
|
+
remoteTypeTarPath,
|
|
617
|
+
ws: client
|
|
618
|
+
});
|
|
619
|
+
this._publisherMap.set(identifier, publisher);
|
|
620
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} Adding Publisher Succeed`, "Broker", "info");
|
|
621
|
+
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
622
|
+
if (tmpSubScribers) {
|
|
623
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `, "Broker", "info");
|
|
624
|
+
this._consumeTmpSubScribers(publisher, tmpSubScribers);
|
|
625
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
471
626
|
}
|
|
627
|
+
} catch (err) {
|
|
628
|
+
const msg = error(err, ActionKind.ADD_PUBLISHER, "Broker");
|
|
629
|
+
client.send(msg);
|
|
630
|
+
client.close();
|
|
472
631
|
}
|
|
473
632
|
});
|
|
474
|
-
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
475
|
-
}
|
|
476
|
-
async _takeAction(action, client) {
|
|
477
|
-
const { kind, payload } = action;
|
|
478
|
-
if (kind === "ADD_PUBLISHER" /* ADD_PUBLISHER */) {
|
|
479
|
-
await this._addPublisher(payload, client);
|
|
480
|
-
}
|
|
481
|
-
if (kind === "UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */) {
|
|
482
|
-
await this._updatePublisher(
|
|
483
|
-
payload,
|
|
484
|
-
client
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
if (kind === "ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */) {
|
|
488
|
-
await this._addSubscriber(payload, client);
|
|
489
|
-
}
|
|
490
|
-
if (kind === "EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */) {
|
|
491
|
-
await this._removeSubscriber(
|
|
492
|
-
payload,
|
|
493
|
-
client
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
if (kind === "EXIT_PUBLISHER" /* EXIT_PUBLISHER */) {
|
|
497
|
-
await this._removePublisher(payload, client);
|
|
498
|
-
}
|
|
499
|
-
if (kind === "ADD_WEB_CLIENT" /* ADD_WEB_CLIENT */) {
|
|
500
|
-
await this._addWebClient(payload, client);
|
|
501
|
-
}
|
|
502
|
-
if (kind === "NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */) {
|
|
503
|
-
await this._notifyWebClient(
|
|
504
|
-
payload,
|
|
505
|
-
client
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
633
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
`[${"ADD_PUBLISHER" /* ADD_PUBLISHER */}] ${identifier} Adding Publisher Succeed`,
|
|
525
|
-
"Broker",
|
|
526
|
-
"info"
|
|
527
|
-
);
|
|
528
|
-
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
529
|
-
if (tmpSubScribers) {
|
|
634
|
+
_updatePublisher(context, client) {
|
|
635
|
+
return __async(this, null, function* () {
|
|
636
|
+
const { name, updateMode, updateKind, updateSourcePaths, remoteTypeTarPath, ip } = context != null ? context : {};
|
|
637
|
+
const identifier = getIdentifier({
|
|
638
|
+
name,
|
|
639
|
+
ip
|
|
640
|
+
});
|
|
641
|
+
if (!this._publisherMap.has(identifier)) {
|
|
642
|
+
fileLog(`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} has not been started, this action will be ignored
|
|
643
|
+
this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
|
|
644
|
+
`, "Broker", "warn");
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
const publisher = this._publisherMap.get(identifier);
|
|
530
649
|
fileLog(
|
|
531
|
-
|
|
650
|
+
// eslint-disable-next-line max-len
|
|
651
|
+
`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} update, and notify subscribers to update`,
|
|
532
652
|
"Broker",
|
|
533
653
|
"info"
|
|
534
654
|
);
|
|
535
|
-
|
|
536
|
-
|
|
655
|
+
if (publisher) {
|
|
656
|
+
publisher.notifySubscribers({
|
|
657
|
+
remoteTypeTarPath,
|
|
658
|
+
name,
|
|
659
|
+
updateMode,
|
|
660
|
+
updateKind,
|
|
661
|
+
updateSourcePaths: updateSourcePaths || []
|
|
662
|
+
});
|
|
663
|
+
this._publisherMap.forEach((p) => {
|
|
664
|
+
if (p.name === publisher.name) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const dynamicRemoteInfo = p.dynamicRemoteMap.get(identifier);
|
|
668
|
+
if (dynamicRemoteInfo) {
|
|
669
|
+
fileLog(
|
|
670
|
+
// eslint-disable-next-line max-len
|
|
671
|
+
`dynamicRemoteInfo: ${JSON.stringify(dynamicRemoteInfo)}, identifier:${identifier} publish: ${p.name}`,
|
|
672
|
+
"Broker",
|
|
673
|
+
"info"
|
|
674
|
+
);
|
|
675
|
+
p.fetchRemoteTypes({
|
|
676
|
+
remoteInfo: dynamicRemoteInfo,
|
|
677
|
+
once: false
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
} catch (err) {
|
|
683
|
+
const msg = error(err, ActionKind.UPDATE_PUBLISHER, "Broker");
|
|
684
|
+
client.send(msg);
|
|
685
|
+
client.close();
|
|
537
686
|
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
_fetchTypes(context, _client) {
|
|
690
|
+
return __async(this, null, function* () {
|
|
691
|
+
const { name, ip, remoteInfo } = context != null ? context : {};
|
|
692
|
+
const identifier = getIdentifier({
|
|
693
|
+
name,
|
|
694
|
+
ip
|
|
695
|
+
});
|
|
696
|
+
try {
|
|
697
|
+
const publisher = this._publisherMap.get(identifier);
|
|
698
|
+
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types`, "Broker", "info");
|
|
699
|
+
if (publisher) {
|
|
700
|
+
publisher.fetchRemoteTypes({
|
|
701
|
+
remoteInfo,
|
|
702
|
+
once: true
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
} catch (err) {
|
|
706
|
+
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types fail , error info: ${err}`, "Broker", "error");
|
|
707
|
+
}
|
|
708
|
+
});
|
|
543
709
|
}
|
|
544
|
-
|
|
545
|
-
const {
|
|
710
|
+
_addDynamicRemote(context) {
|
|
711
|
+
const { name, ip, remoteInfo, remoteIp } = context != null ? context : {};
|
|
712
|
+
const identifier = getIdentifier({
|
|
546
713
|
name,
|
|
547
|
-
updateMode,
|
|
548
|
-
updateKind,
|
|
549
|
-
updateSourcePaths,
|
|
550
|
-
remoteTypeTarPath,
|
|
551
714
|
ip
|
|
552
|
-
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
"warn"
|
|
561
|
-
);
|
|
715
|
+
});
|
|
716
|
+
const publisher = this._publisherMap.get(identifier);
|
|
717
|
+
const remoteId = getIdentifier({
|
|
718
|
+
name: remoteInfo.name,
|
|
719
|
+
ip: remoteIp
|
|
720
|
+
});
|
|
721
|
+
fileLog(`[${ActionKind.ADD_DYNAMIC_REMOTE}] identifier:${identifier},publisher: ${publisher.name}, remoteId:${remoteId}`, "Broker", "error");
|
|
722
|
+
if (!publisher || publisher.dynamicRemoteMap.has(remoteId)) {
|
|
562
723
|
return;
|
|
563
724
|
}
|
|
564
|
-
|
|
565
|
-
const publisher = this._publisherMap.get(identifier);
|
|
566
|
-
fileLog(
|
|
567
|
-
// eslint-disable-next-line max-len
|
|
568
|
-
`[${"UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */}] ${identifier} update, and notify subscribers to update`,
|
|
569
|
-
"Broker",
|
|
570
|
-
"info"
|
|
571
|
-
);
|
|
572
|
-
if (publisher) {
|
|
573
|
-
publisher.notifySubscribers({
|
|
574
|
-
remoteTypeTarPath,
|
|
575
|
-
name,
|
|
576
|
-
updateMode,
|
|
577
|
-
updateKind,
|
|
578
|
-
updateSourcePaths: updateSourcePaths || []
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
} catch (err) {
|
|
582
|
-
const msg = error(err, "UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */, "Broker");
|
|
583
|
-
client.send(msg);
|
|
584
|
-
client.close();
|
|
585
|
-
}
|
|
725
|
+
publisher.dynamicRemoteMap.set(remoteId, remoteInfo);
|
|
586
726
|
}
|
|
587
727
|
// app1 consumes provider1,provider2. Dependencies at this time: publishers: [provider1, provider2], subscriberName: app1
|
|
588
728
|
// provider1 is app1's remote
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
{
|
|
729
|
+
_addSubscriber(context, client) {
|
|
730
|
+
return __async(this, null, function* () {
|
|
731
|
+
const { publishers, name: subscriberName } = context != null ? context : {};
|
|
732
|
+
publishers.forEach((publisher) => {
|
|
733
|
+
const { name, ip } = publisher;
|
|
734
|
+
const identifier = getIdentifier({
|
|
735
|
+
name,
|
|
736
|
+
ip
|
|
737
|
+
});
|
|
738
|
+
if (!this._publisherMap.has(identifier)) {
|
|
739
|
+
fileLog(`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`, "Broker", "warn");
|
|
740
|
+
this._addTmpSubScriberRelation({
|
|
602
741
|
name: getIdentifier({
|
|
603
742
|
name: context.name,
|
|
604
743
|
ip: context.ip
|
|
605
744
|
}),
|
|
606
745
|
client
|
|
607
|
-
},
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
if (registeredPublisher) {
|
|
615
|
-
registeredPublisher.addSubscriber(
|
|
616
|
-
getIdentifier({
|
|
746
|
+
}, publisher);
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
try {
|
|
750
|
+
const registeredPublisher = this._publisherMap.get(identifier);
|
|
751
|
+
if (registeredPublisher) {
|
|
752
|
+
registeredPublisher.addSubscriber(getIdentifier({
|
|
617
753
|
name: subscriberName,
|
|
618
754
|
ip: context.ip
|
|
619
|
-
}),
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
"Broker",
|
|
628
|
-
"info"
|
|
629
|
-
);
|
|
630
|
-
registeredPublisher.notifySubscriber(
|
|
631
|
-
getIdentifier({
|
|
755
|
+
}), client);
|
|
756
|
+
fileLog(
|
|
757
|
+
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
758
|
+
`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(Array.from(this._publisherMap.entries()))}`,
|
|
759
|
+
"Broker",
|
|
760
|
+
"info"
|
|
761
|
+
);
|
|
762
|
+
registeredPublisher.notifySubscriber(getIdentifier({
|
|
632
763
|
name: subscriberName,
|
|
633
764
|
ip: context.ip
|
|
634
|
-
}),
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
765
|
+
}), {
|
|
766
|
+
updateKind: UpdateKind.UPDATE_TYPE,
|
|
767
|
+
updateMode: UpdateMode.PASSIVE,
|
|
768
|
+
updateSourcePaths: [
|
|
769
|
+
registeredPublisher.name
|
|
770
|
+
],
|
|
639
771
|
remoteTypeTarPath: registeredPublisher.remoteTypeTarPath,
|
|
640
772
|
name: registeredPublisher.name
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
773
|
+
});
|
|
774
|
+
fileLog(
|
|
775
|
+
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
776
|
+
`[${ActionKind.ADD_SUBSCRIBER}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
|
|
777
|
+
"Broker",
|
|
778
|
+
"info"
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
} catch (err) {
|
|
782
|
+
const msg = error(err, ActionKind.ADD_SUBSCRIBER, "Broker");
|
|
783
|
+
client.send(msg);
|
|
784
|
+
client.close();
|
|
649
785
|
}
|
|
650
|
-
}
|
|
651
|
-
const msg = error(err, "ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */, "Broker");
|
|
652
|
-
client.send(msg);
|
|
653
|
-
client.close();
|
|
654
|
-
}
|
|
786
|
+
});
|
|
655
787
|
});
|
|
656
788
|
}
|
|
657
789
|
// Trigger while consumer exit
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
790
|
+
_removeSubscriber(context, client) {
|
|
791
|
+
return __async(this, null, function* () {
|
|
792
|
+
const { publishers } = context != null ? context : {};
|
|
793
|
+
const subscriberIdentifier = getIdentifier({
|
|
794
|
+
name: context == null ? void 0 : context.name,
|
|
795
|
+
ip: context == null ? void 0 : context.ip
|
|
796
|
+
});
|
|
797
|
+
publishers.forEach((publisher) => {
|
|
798
|
+
const { name, ip } = publisher;
|
|
799
|
+
const identifier = getIdentifier({
|
|
800
|
+
name,
|
|
801
|
+
ip
|
|
802
|
+
});
|
|
803
|
+
const registeredPublisher = this._publisherMap.get(identifier);
|
|
804
|
+
if (!registeredPublisher) {
|
|
805
|
+
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} does not exit `, "Broker", "warn");
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
try {
|
|
809
|
+
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} will exit `, "Broker", "INFO");
|
|
810
|
+
registeredPublisher.removeSubscriber(subscriberIdentifier);
|
|
811
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
812
|
+
if (!registeredPublisher.hasSubscribes) {
|
|
813
|
+
this._publisherMap.delete(identifier);
|
|
814
|
+
}
|
|
815
|
+
if (!this.hasPublishers) {
|
|
816
|
+
this.exit();
|
|
817
|
+
}
|
|
818
|
+
} catch (err) {
|
|
819
|
+
const msg = error(err, ActionKind.EXIT_SUBSCRIBER, "Broker");
|
|
820
|
+
client.send(msg);
|
|
821
|
+
client.close();
|
|
822
|
+
}
|
|
823
|
+
});
|
|
663
824
|
});
|
|
664
|
-
|
|
665
|
-
|
|
825
|
+
}
|
|
826
|
+
_removePublisher(context, client) {
|
|
827
|
+
return __async(this, null, function* () {
|
|
828
|
+
const { name, ip } = context != null ? context : {};
|
|
666
829
|
const identifier = getIdentifier({
|
|
667
830
|
name,
|
|
668
831
|
ip
|
|
669
832
|
});
|
|
670
|
-
const
|
|
671
|
-
if (!
|
|
672
|
-
fileLog(
|
|
673
|
-
`[${"EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */}], ${identifier} does not exit `,
|
|
674
|
-
"Broker",
|
|
675
|
-
"warn"
|
|
676
|
-
);
|
|
833
|
+
const publisher = this._publisherMap.get(identifier);
|
|
834
|
+
if (!publisher) {
|
|
835
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier}} has not been added, this action will be ingored`, "Broker", "warn");
|
|
677
836
|
return;
|
|
678
837
|
}
|
|
679
838
|
try {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
839
|
+
const { subscribers } = publisher;
|
|
840
|
+
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
841
|
+
this._addTmpSubScriberRelation({
|
|
842
|
+
name: subscriberIdentifier,
|
|
843
|
+
client: subscriber
|
|
844
|
+
}, {
|
|
845
|
+
name: publisher.name,
|
|
846
|
+
ip: publisher.ip
|
|
847
|
+
});
|
|
848
|
+
fileLog(
|
|
849
|
+
// eslint-disable-next-line max-len
|
|
850
|
+
`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
851
|
+
"Broker",
|
|
852
|
+
"info"
|
|
853
|
+
);
|
|
854
|
+
});
|
|
855
|
+
this._publisherMap.delete(identifier);
|
|
856
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removed `, "Broker", "info");
|
|
690
857
|
if (!this.hasPublishers) {
|
|
858
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: _publisherMap is empty, all server will exit `, "Broker", "warn");
|
|
691
859
|
this.exit();
|
|
692
860
|
}
|
|
693
861
|
} catch (err) {
|
|
694
|
-
const msg = error(err,
|
|
862
|
+
const msg = error(err, ActionKind.EXIT_PUBLISHER, "Broker");
|
|
695
863
|
client.send(msg);
|
|
696
864
|
client.close();
|
|
697
865
|
}
|
|
698
866
|
});
|
|
699
867
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
});
|
|
706
|
-
const publisher = this._publisherMap.get(identifier);
|
|
707
|
-
if (!publisher) {
|
|
708
|
-
fileLog(
|
|
709
|
-
`[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier}} has not been added, this action will be ingored`,
|
|
710
|
-
"Broker",
|
|
711
|
-
"warn"
|
|
712
|
-
);
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
try {
|
|
716
|
-
const { subscribers } = publisher;
|
|
717
|
-
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
718
|
-
this._addTmpSubScriberRelation(
|
|
719
|
-
{
|
|
720
|
-
name: subscriberIdentifier,
|
|
721
|
-
client: subscriber
|
|
722
|
-
},
|
|
723
|
-
{ name: publisher.name, ip: publisher.ip }
|
|
724
|
-
);
|
|
725
|
-
fileLog(
|
|
726
|
-
// eslint-disable-next-line max-len
|
|
727
|
-
`[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
728
|
-
"Broker",
|
|
729
|
-
"info"
|
|
730
|
-
);
|
|
868
|
+
_addWebClient(context, client) {
|
|
869
|
+
return __async(this, null, function* () {
|
|
870
|
+
const { name } = context != null ? context : {};
|
|
871
|
+
const identifier = getIdentifier({
|
|
872
|
+
name
|
|
731
873
|
});
|
|
732
|
-
this.
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
"warn"
|
|
743
|
-
);
|
|
744
|
-
this.exit();
|
|
874
|
+
if (this._webClientMap.has(identifier)) {
|
|
875
|
+
fileLog(`${identifier}} has been added, this action will override prev WebClient`, "Broker", "warn");
|
|
876
|
+
}
|
|
877
|
+
try {
|
|
878
|
+
this._webClientMap.set(identifier, client);
|
|
879
|
+
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
880
|
+
} catch (err) {
|
|
881
|
+
const msg = error(err, ActionKind.ADD_WEB_CLIENT, "Broker");
|
|
882
|
+
client.send(msg);
|
|
883
|
+
client.close();
|
|
745
884
|
}
|
|
746
|
-
} catch (err) {
|
|
747
|
-
const msg = error(err, "EXIT_PUBLISHER" /* EXIT_PUBLISHER */, "Broker");
|
|
748
|
-
client.send(msg);
|
|
749
|
-
client.close();
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
async _addWebClient(context, client) {
|
|
753
|
-
const { name } = context ?? {};
|
|
754
|
-
const identifier = getIdentifier({
|
|
755
|
-
name
|
|
756
885
|
});
|
|
757
|
-
if (this._webClientMap.has(identifier)) {
|
|
758
|
-
fileLog(
|
|
759
|
-
`${identifier}} has been added, this action will override prev WebClient`,
|
|
760
|
-
"Broker",
|
|
761
|
-
"warn"
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
try {
|
|
765
|
-
this._webClientMap.set(identifier, client);
|
|
766
|
-
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
767
|
-
} catch (err) {
|
|
768
|
-
const msg = error(err, "ADD_WEB_CLIENT" /* ADD_WEB_CLIENT */, "Broker");
|
|
769
|
-
client.send(msg);
|
|
770
|
-
client.close();
|
|
771
|
-
}
|
|
772
886
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
887
|
+
_notifyWebClient(context, client) {
|
|
888
|
+
return __async(this, null, function* () {
|
|
889
|
+
const { name, updateMode } = context != null ? context : {};
|
|
890
|
+
const identifier = getIdentifier({
|
|
891
|
+
name
|
|
892
|
+
});
|
|
893
|
+
const webClient = this._webClientMap.get(identifier);
|
|
894
|
+
if (!webClient) {
|
|
895
|
+
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] ${identifier} has not been added, this action will be ignored`, "Broker", "warn");
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
try {
|
|
899
|
+
const api = new ReloadWebClientAPI({
|
|
900
|
+
name,
|
|
901
|
+
updateMode
|
|
902
|
+
});
|
|
903
|
+
webClient.send(JSON.stringify(api));
|
|
904
|
+
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] Notify ${name} WebClient Succeed`, "Broker", "info");
|
|
905
|
+
} catch (err) {
|
|
906
|
+
const msg = error(err, ActionKind.NOTIFY_WEB_CLIENT, "Broker");
|
|
907
|
+
client.send(msg);
|
|
908
|
+
client.close();
|
|
909
|
+
}
|
|
777
910
|
});
|
|
778
|
-
const webClient = this._webClientMap.get(identifier);
|
|
779
|
-
if (!webClient) {
|
|
780
|
-
fileLog(
|
|
781
|
-
`[${"NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */}] ${identifier} has not been added, this action will be ignored`,
|
|
782
|
-
"Broker",
|
|
783
|
-
"warn"
|
|
784
|
-
);
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
try {
|
|
788
|
-
const api = new ReloadWebClientAPI({ name, updateMode });
|
|
789
|
-
webClient.send(JSON.stringify(api));
|
|
790
|
-
fileLog(
|
|
791
|
-
`[${"NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */}] Notify ${name} WebClient Succeed`,
|
|
792
|
-
"Broker",
|
|
793
|
-
"info"
|
|
794
|
-
);
|
|
795
|
-
} catch (err) {
|
|
796
|
-
const msg = error(err, "NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */, "Broker");
|
|
797
|
-
client.send(msg);
|
|
798
|
-
client.close();
|
|
799
|
-
}
|
|
800
911
|
}
|
|
801
912
|
// app1 consumes provider1, and provider1 not launch. this._tmpSubscriberShelter at this time: {provider1: Map{subscribers: Map{app1: app1+ip+client'}, timestamp: 'xx'} }
|
|
802
913
|
_addTmpSubScriberRelation(subscriber, publisher) {
|
|
@@ -813,20 +924,12 @@ ${err.message}
|
|
|
813
924
|
subscribers: map,
|
|
814
925
|
timestamp: Date.now()
|
|
815
926
|
});
|
|
816
|
-
fileLog(
|
|
817
|
-
`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `,
|
|
818
|
-
"Broker",
|
|
819
|
-
"info"
|
|
820
|
-
);
|
|
927
|
+
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `, "Broker", "info");
|
|
821
928
|
return;
|
|
822
929
|
}
|
|
823
930
|
const tmpSubScriberShelterSubscriber = shelter.subscribers.get(subscriberIdentifier);
|
|
824
931
|
if (tmpSubScriberShelterSubscriber) {
|
|
825
|
-
fileLog(
|
|
826
|
-
`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`,
|
|
827
|
-
"Broker",
|
|
828
|
-
"warn"
|
|
829
|
-
);
|
|
932
|
+
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`, "Broker", "warn");
|
|
830
933
|
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
831
934
|
shelter.timestamp = Date.now();
|
|
832
935
|
} else {
|
|
@@ -840,22 +943,20 @@ ${err.message}
|
|
|
840
943
|
}
|
|
841
944
|
}
|
|
842
945
|
_getTmpSubScribers(publisherIdentifier) {
|
|
843
|
-
var
|
|
844
|
-
return (
|
|
946
|
+
var _a3;
|
|
947
|
+
return (_a3 = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a3.subscribers;
|
|
845
948
|
}
|
|
846
949
|
// after adding publisher, it will change the temp subscriber to regular subscriber
|
|
847
950
|
_consumeTmpSubScribers(publisher, tmpSubScribers) {
|
|
848
951
|
tmpSubScribers.forEach((tmpSubScriber, identifier) => {
|
|
849
|
-
fileLog(
|
|
850
|
-
`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `,
|
|
851
|
-
"Broker",
|
|
852
|
-
"warn"
|
|
853
|
-
);
|
|
952
|
+
fileLog(`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `, "Broker", "warn");
|
|
854
953
|
publisher.addSubscriber(identifier, tmpSubScriber.client);
|
|
855
954
|
publisher.notifySubscriber(identifier, {
|
|
856
|
-
updateKind:
|
|
857
|
-
updateMode:
|
|
858
|
-
updateSourcePaths: [
|
|
955
|
+
updateKind: UpdateKind.UPDATE_TYPE,
|
|
956
|
+
updateMode: UpdateMode.PASSIVE,
|
|
957
|
+
updateSourcePaths: [
|
|
958
|
+
publisher.name
|
|
959
|
+
],
|
|
859
960
|
remoteTypeTarPath: publisher.remoteTypeTarPath,
|
|
860
961
|
name: publisher.name
|
|
861
962
|
});
|
|
@@ -885,17 +986,21 @@ ${err.message}
|
|
|
885
986
|
rule.second = second;
|
|
886
987
|
} else {
|
|
887
988
|
rule.second = 0;
|
|
888
|
-
rule.hour = [
|
|
989
|
+
rule.hour = [
|
|
990
|
+
0,
|
|
991
|
+
3,
|
|
992
|
+
6,
|
|
993
|
+
9,
|
|
994
|
+
12,
|
|
995
|
+
15,
|
|
996
|
+
18
|
|
997
|
+
];
|
|
889
998
|
rule.minute = 0;
|
|
890
999
|
}
|
|
891
1000
|
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
892
1001
|
this._scheduleJob = import_node_schedule.default.scheduleJob(rule, () => {
|
|
893
1002
|
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
894
|
-
fileLog(
|
|
895
|
-
` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`,
|
|
896
|
-
"Broker",
|
|
897
|
-
"info"
|
|
898
|
-
);
|
|
1003
|
+
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
899
1004
|
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)) {
|
|
900
1005
|
this._clearTmpSubScriberRelation(identifier);
|
|
901
1006
|
}
|
|
@@ -929,7 +1034,9 @@ ${err.message}
|
|
|
929
1034
|
process.exit(1);
|
|
930
1035
|
});
|
|
931
1036
|
}
|
|
932
|
-
|
|
1037
|
+
start() {
|
|
1038
|
+
return __async(this, null, function* () {
|
|
1039
|
+
});
|
|
933
1040
|
}
|
|
934
1041
|
exit() {
|
|
935
1042
|
const brokerExitLog = new BrokerExitLog();
|
|
@@ -942,13 +1049,9 @@ ${err.message}
|
|
|
942
1049
|
process.exit(0);
|
|
943
1050
|
}
|
|
944
1051
|
broadcast(message) {
|
|
945
|
-
var
|
|
946
|
-
fileLog(
|
|
947
|
-
|
|
948
|
-
"Broker",
|
|
949
|
-
"warn"
|
|
950
|
-
);
|
|
951
|
-
(_a = this._webSocketServer) == null ? void 0 : _a.clients.forEach((client) => {
|
|
1052
|
+
var _a3, _b;
|
|
1053
|
+
fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
|
|
1054
|
+
(_a3 = this._webSocketServer) == null ? void 0 : _a3.clients.forEach((client) => {
|
|
952
1055
|
client.send(JSON.stringify(message));
|
|
953
1056
|
});
|
|
954
1057
|
(_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
|
|
@@ -956,10 +1059,11 @@ ${err.message}
|
|
|
956
1059
|
});
|
|
957
1060
|
}
|
|
958
1061
|
};
|
|
959
|
-
_Broker
|
|
960
|
-
_Broker
|
|
961
|
-
_Broker
|
|
962
|
-
_Broker
|
|
1062
|
+
__name(_Broker, "Broker");
|
|
1063
|
+
__publicField(_Broker, "WEB_SOCKET_CONNECT_MAGIC_ID", WEB_SOCKET_CONNECT_MAGIC_ID);
|
|
1064
|
+
__publicField(_Broker, "DEFAULT_WEB_SOCKET_PORT", DEFAULT_WEB_SOCKET_PORT);
|
|
1065
|
+
__publicField(_Broker, "DEFAULT_SECURE_WEB_SOCKET_PORT", 16324);
|
|
1066
|
+
__publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
963
1067
|
var Broker = _Broker;
|
|
964
1068
|
|
|
965
1069
|
// packages/dts-plugin/src/server/createKoaServer.ts
|
|
@@ -967,49 +1071,39 @@ var import_fs_extra = __toESM(require("fs-extra"));
|
|
|
967
1071
|
var import_koa = __toESM(require("koa"));
|
|
968
1072
|
|
|
969
1073
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
970
|
-
var retrieveTypesZipPath = (mfTypesPath, remoteOptions) => (0, import_path2.join)(
|
|
971
|
-
|
|
972
|
-
`${remoteOptions.typesFolder}.zip`
|
|
973
|
-
);
|
|
974
|
-
var createTypesArchive = async (tsConfig, remoteOptions) => {
|
|
1074
|
+
var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => (0, import_path2.join)(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
|
|
1075
|
+
var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
975
1076
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
976
1077
|
const zip = new import_adm_zip.default();
|
|
977
1078
|
zip.addLocalFolder(mfTypesPath);
|
|
978
1079
|
return zip.writeZipPromise(retrieveTypesZipPath(mfTypesPath, remoteOptions));
|
|
979
|
-
};
|
|
980
|
-
var downloadErrorLogger = (destinationFolder, fileToDownload) => (reason) => {
|
|
981
|
-
throw {
|
|
982
|
-
...reason,
|
|
1080
|
+
}), "createTypesArchive");
|
|
1081
|
+
var downloadErrorLogger = /* @__PURE__ */ __name((destinationFolder, fileToDownload) => (reason) => {
|
|
1082
|
+
throw __spreadProps(__spreadValues({}, reason), {
|
|
983
1083
|
message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`
|
|
984
|
-
};
|
|
985
|
-
};
|
|
986
|
-
var retrieveTypesArchiveDestinationPath = (hostOptions, destinationFolder) => {
|
|
987
|
-
return (0, import_path2.resolve)(
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
destinationFolder
|
|
991
|
-
);
|
|
992
|
-
};
|
|
993
|
-
var downloadTypesArchive = (hostOptions) => {
|
|
1084
|
+
});
|
|
1085
|
+
}, "downloadErrorLogger");
|
|
1086
|
+
var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, destinationFolder) => {
|
|
1087
|
+
return (0, import_path2.resolve)(hostOptions.context, hostOptions.typesFolder, destinationFolder);
|
|
1088
|
+
}, "retrieveTypesArchiveDestinationPath");
|
|
1089
|
+
var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
994
1090
|
let retries = 0;
|
|
995
|
-
return
|
|
996
|
-
const destinationPath = retrieveTypesArchiveDestinationPath(
|
|
997
|
-
hostOptions,
|
|
998
|
-
destinationFolder
|
|
999
|
-
);
|
|
1091
|
+
return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
|
|
1092
|
+
const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
|
|
1000
1093
|
while (retries++ < hostOptions.maxRetries) {
|
|
1001
1094
|
try {
|
|
1002
1095
|
const url = fileToDownload;
|
|
1003
|
-
const response =
|
|
1096
|
+
const response = yield import_axios.default.get(url, {
|
|
1097
|
+
responseType: "arraybuffer"
|
|
1098
|
+
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1004
1099
|
const zip = new import_adm_zip.default(Buffer.from(response.data));
|
|
1005
1100
|
zip.extractAllTo(destinationPath, true);
|
|
1006
|
-
return [
|
|
1101
|
+
return [
|
|
1102
|
+
destinationFolder,
|
|
1103
|
+
destinationPath
|
|
1104
|
+
];
|
|
1007
1105
|
} catch (error2) {
|
|
1008
|
-
fileLog(
|
|
1009
|
-
`Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`,
|
|
1010
|
-
"downloadTypesArchive",
|
|
1011
|
-
"error"
|
|
1012
|
-
);
|
|
1106
|
+
fileLog(`Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`, "downloadTypesArchive", "error");
|
|
1013
1107
|
if (retries >= hostOptions.maxRetries) {
|
|
1014
1108
|
if (hostOptions.abortOnError !== false) {
|
|
1015
1109
|
throw error2;
|
|
@@ -1018,8 +1112,8 @@ var downloadTypesArchive = (hostOptions) => {
|
|
|
1018
1112
|
}
|
|
1019
1113
|
}
|
|
1020
1114
|
}
|
|
1021
|
-
};
|
|
1022
|
-
};
|
|
1115
|
+
});
|
|
1116
|
+
}, "downloadTypesArchive");
|
|
1023
1117
|
|
|
1024
1118
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1025
1119
|
var import_sdk3 = require("@module-federation/sdk");
|
|
@@ -1034,19 +1128,19 @@ var defaultOptions = {
|
|
|
1034
1128
|
abortOnError: true,
|
|
1035
1129
|
consumeAPITypes: false
|
|
1036
1130
|
};
|
|
1037
|
-
var buildZipUrl = (hostOptions, url) => {
|
|
1038
|
-
const remoteUrl = new URL(url);
|
|
1131
|
+
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1132
|
+
const remoteUrl = new URL(url, "file:");
|
|
1039
1133
|
const pathnameWithoutEntry = remoteUrl.pathname.split("/").slice(0, -1).join("/");
|
|
1040
1134
|
remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
|
|
1041
|
-
return remoteUrl.href;
|
|
1042
|
-
};
|
|
1043
|
-
var buildApiTypeUrl = (zipUrl) => {
|
|
1135
|
+
return remoteUrl.protocol === "file:" ? remoteUrl.pathname : remoteUrl.href;
|
|
1136
|
+
}, "buildZipUrl");
|
|
1137
|
+
var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
1044
1138
|
if (!zipUrl) {
|
|
1045
1139
|
return void 0;
|
|
1046
1140
|
}
|
|
1047
1141
|
return zipUrl.replace(".zip", ".d.ts");
|
|
1048
|
-
};
|
|
1049
|
-
var retrieveRemoteInfo = (options) => {
|
|
1142
|
+
}, "buildApiTypeUrl");
|
|
1143
|
+
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1050
1144
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1051
1145
|
const parsedInfo = (0, import_sdk3.parseEntry)(remote, void 0, "@");
|
|
1052
1146
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === remote ? remote : "";
|
|
@@ -1058,56 +1152,46 @@ var retrieveRemoteInfo = (options) => {
|
|
|
1058
1152
|
apiTypeUrl: buildApiTypeUrl(zipUrl),
|
|
1059
1153
|
alias: remoteAlias
|
|
1060
1154
|
};
|
|
1061
|
-
};
|
|
1062
|
-
var resolveRemotes = (hostOptions) => {
|
|
1063
|
-
const parsedOptions = import_managers.utils.parseOptions(
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
});
|
|
1082
|
-
return accumulator;
|
|
1083
|
-
},
|
|
1084
|
-
{}
|
|
1085
|
-
);
|
|
1086
|
-
};
|
|
1087
|
-
var retrieveHostConfig = (options) => {
|
|
1155
|
+
}, "retrieveRemoteInfo");
|
|
1156
|
+
var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
1157
|
+
const parsedOptions = import_managers.utils.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
|
|
1158
|
+
remote: Array.isArray(item) ? item[0] : item,
|
|
1159
|
+
key
|
|
1160
|
+
}), (item, key) => ({
|
|
1161
|
+
remote: Array.isArray(item.external) ? item.external[0] : item.external,
|
|
1162
|
+
key
|
|
1163
|
+
}));
|
|
1164
|
+
return parsedOptions.reduce((accumulator, item) => {
|
|
1165
|
+
const { key, remote } = item[1];
|
|
1166
|
+
accumulator[key] = retrieveRemoteInfo({
|
|
1167
|
+
hostOptions,
|
|
1168
|
+
remoteAlias: key,
|
|
1169
|
+
remote
|
|
1170
|
+
});
|
|
1171
|
+
return accumulator;
|
|
1172
|
+
}, {});
|
|
1173
|
+
}, "resolveRemotes");
|
|
1174
|
+
var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
1088
1175
|
validateOptions(options);
|
|
1089
|
-
const hostOptions = {
|
|
1176
|
+
const hostOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
1090
1177
|
const mapRemotesToDownload = resolveRemotes(hostOptions);
|
|
1091
1178
|
return {
|
|
1092
1179
|
hostOptions,
|
|
1093
1180
|
mapRemotesToDownload
|
|
1094
1181
|
};
|
|
1095
|
-
};
|
|
1096
|
-
|
|
1097
|
-
// packages/dts-plugin/src/core/constant.ts
|
|
1098
|
-
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
1099
|
-
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
1100
|
-
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
1101
|
-
var UpdateMode = /* @__PURE__ */ ((UpdateMode2) => {
|
|
1102
|
-
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
1103
|
-
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
1104
|
-
return UpdateMode2;
|
|
1105
|
-
})(UpdateMode || {});
|
|
1182
|
+
}, "retrieveHostConfig");
|
|
1106
1183
|
|
|
1107
1184
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1108
1185
|
var import_axios2 = __toESM(require("axios"));
|
|
1109
|
-
var
|
|
1186
|
+
var _a;
|
|
1187
|
+
var DTSManager = (_a = class {
|
|
1110
1188
|
constructor(options) {
|
|
1189
|
+
__publicField(this, "options");
|
|
1190
|
+
__publicField(this, "runtimePkgs");
|
|
1191
|
+
__publicField(this, "remoteAliasMap");
|
|
1192
|
+
__publicField(this, "loadedRemoteAPIAlias");
|
|
1193
|
+
__publicField(this, "extraOptions");
|
|
1194
|
+
__publicField(this, "updatedRemoteInfos");
|
|
1111
1195
|
this.options = (0, import_lodash.default)(options, (_value, key) => {
|
|
1112
1196
|
if (key === "manifest") {
|
|
1113
1197
|
return false;
|
|
@@ -1118,181 +1202,187 @@ var DTSManager = class {
|
|
|
1118
1202
|
"@module-federation/enhanced/runtime",
|
|
1119
1203
|
"@module-federation/runtime-tools"
|
|
1120
1204
|
];
|
|
1121
|
-
this.loadedRemoteAPIAlias =
|
|
1205
|
+
this.loadedRemoteAPIAlias = /* @__PURE__ */ new Set();
|
|
1122
1206
|
this.remoteAliasMap = {};
|
|
1123
1207
|
this.extraOptions = (options == null ? void 0 : options.extraOptions) || {};
|
|
1208
|
+
this.updatedRemoteInfos = {};
|
|
1124
1209
|
}
|
|
1125
1210
|
generateAPITypes(mapComponentsToExpose) {
|
|
1126
1211
|
const exposePaths = /* @__PURE__ */ new Set();
|
|
1127
|
-
const packageType = Object.keys(mapComponentsToExpose).reduce(
|
|
1128
|
-
(
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
);
|
|
1137
|
-
const exposePathKeys = [...exposePaths].join(" | ");
|
|
1212
|
+
const packageType = Object.keys(mapComponentsToExpose).reduce((sum, exposeKey) => {
|
|
1213
|
+
const exposePath = import_path3.default.join(REMOTE_ALIAS_IDENTIFIER, exposeKey).split(import_path3.default.sep).join("/");
|
|
1214
|
+
exposePaths.add(`'${exposePath}'`);
|
|
1215
|
+
const curType = `T extends '${exposePath}' ? typeof import('${exposePath}') :`;
|
|
1216
|
+
sum = curType + sum;
|
|
1217
|
+
return sum;
|
|
1218
|
+
}, "any;");
|
|
1219
|
+
const exposePathKeys = [
|
|
1220
|
+
...exposePaths
|
|
1221
|
+
].join(" | ");
|
|
1138
1222
|
return `
|
|
1139
1223
|
export type RemoteKeys = ${exposePathKeys};
|
|
1140
1224
|
type PackageType<T> = ${packageType}`;
|
|
1141
1225
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
}
|
|
1147
|
-
let hasRemotes = false;
|
|
1148
|
-
const remotes = remoteOptions.moduleFederationConfig.remotes;
|
|
1149
|
-
if (remotes) {
|
|
1150
|
-
if (Array.isArray(remotes)) {
|
|
1151
|
-
hasRemotes = Boolean(remotes.length);
|
|
1152
|
-
} else if (typeof remotes === "object") {
|
|
1153
|
-
hasRemotes = Boolean(Object.keys(remotes).length);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1157
|
-
if (hasRemotes) {
|
|
1158
|
-
const tempHostOptions = {
|
|
1159
|
-
moduleFederationConfig: remoteOptions.moduleFederationConfig,
|
|
1160
|
-
typesFolder: import_path3.default.join(mfTypesPath, "node_modules"),
|
|
1161
|
-
remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
|
|
1162
|
-
deleteTypesFolder: true,
|
|
1163
|
-
context: remoteOptions.context,
|
|
1164
|
-
implementation: remoteOptions.implementation,
|
|
1165
|
-
abortOnError: false
|
|
1166
|
-
};
|
|
1167
|
-
await this.consumeArchiveTypes(tempHostOptions);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
async generateTypes() {
|
|
1171
|
-
var _a;
|
|
1172
|
-
try {
|
|
1173
|
-
const { options } = this;
|
|
1174
|
-
if (!options.remote) {
|
|
1175
|
-
throw new Error(
|
|
1176
|
-
"options.remote is required if you want to generateTypes"
|
|
1177
|
-
);
|
|
1178
|
-
}
|
|
1179
|
-
const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
|
|
1180
|
-
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1226
|
+
extractRemoteTypes(options) {
|
|
1227
|
+
return __async(this, null, function* () {
|
|
1228
|
+
const { remoteOptions, tsConfig } = options;
|
|
1229
|
+
if (!remoteOptions.extractRemoteTypes) {
|
|
1181
1230
|
return;
|
|
1182
1231
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
if (remoteOptions.generateAPITypes) {
|
|
1192
|
-
const apiTypes = this.generateAPITypes(mapComponentsToExpose);
|
|
1193
|
-
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1194
|
-
import_fs.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1232
|
+
let hasRemotes = false;
|
|
1233
|
+
const remotes = remoteOptions.moduleFederationConfig.remotes;
|
|
1234
|
+
if (remotes) {
|
|
1235
|
+
if (Array.isArray(remotes)) {
|
|
1236
|
+
hasRemotes = Boolean(remotes.length);
|
|
1237
|
+
} else if (typeof remotes === "object") {
|
|
1238
|
+
hasRemotes = Boolean(Object.keys(remotes).length);
|
|
1239
|
+
}
|
|
1195
1240
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1241
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1242
|
+
if (hasRemotes) {
|
|
1243
|
+
const tempHostOptions = {
|
|
1244
|
+
moduleFederationConfig: remoteOptions.moduleFederationConfig,
|
|
1245
|
+
typesFolder: import_path3.default.join(mfTypesPath, "node_modules"),
|
|
1246
|
+
remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
|
|
1247
|
+
deleteTypesFolder: true,
|
|
1248
|
+
context: remoteOptions.context,
|
|
1249
|
+
implementation: remoteOptions.implementation,
|
|
1250
|
+
abortOnError: false
|
|
1251
|
+
};
|
|
1252
|
+
yield this.consumeArchiveTypes(tempHostOptions);
|
|
1201
1253
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
generateTypes() {
|
|
1257
|
+
return __async(this, null, function* () {
|
|
1258
|
+
var _a3;
|
|
1259
|
+
try {
|
|
1260
|
+
const { options } = this;
|
|
1261
|
+
if (!options.remote) {
|
|
1262
|
+
throw new Error("options.remote is required if you want to generateTypes");
|
|
1263
|
+
}
|
|
1264
|
+
const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
|
|
1265
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
this.extractRemoteTypes({
|
|
1269
|
+
remoteOptions,
|
|
1270
|
+
tsConfig,
|
|
1271
|
+
mapComponentsToExpose
|
|
1272
|
+
});
|
|
1273
|
+
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1274
|
+
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1275
|
+
let apiTypesPath = "";
|
|
1276
|
+
if (remoteOptions.generateAPITypes) {
|
|
1277
|
+
const apiTypes = this.generateAPITypes(mapComponentsToExpose);
|
|
1278
|
+
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1279
|
+
import_fs.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1280
|
+
}
|
|
1281
|
+
if (remoteOptions.deleteTypesFolder) {
|
|
1282
|
+
yield (0, import_promises.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1283
|
+
recursive: true,
|
|
1284
|
+
force: true
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
console.log(import_ansi_colors2.default.green("Federated types created correctly"));
|
|
1288
|
+
} catch (error2) {
|
|
1289
|
+
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1290
|
+
console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${error2}`));
|
|
1291
|
+
} else {
|
|
1292
|
+
throw error2;
|
|
1293
|
+
}
|
|
1210
1294
|
}
|
|
1211
|
-
}
|
|
1295
|
+
});
|
|
1212
1296
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1297
|
+
requestRemoteManifest(remoteInfo) {
|
|
1298
|
+
return __async(this, null, function* () {
|
|
1299
|
+
try {
|
|
1300
|
+
if (!remoteInfo.url.includes(import_sdk4.MANIFEST_EXT)) {
|
|
1301
|
+
return remoteInfo;
|
|
1302
|
+
}
|
|
1303
|
+
const url = remoteInfo.url;
|
|
1304
|
+
const res = yield (0, import_axios2.default)({
|
|
1305
|
+
method: "get",
|
|
1306
|
+
url
|
|
1307
|
+
});
|
|
1308
|
+
const manifestJson = res.data;
|
|
1309
|
+
if (!manifestJson.metaData.types.zip) {
|
|
1310
|
+
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1311
|
+
}
|
|
1312
|
+
const addProtocol = /* @__PURE__ */ __name((u) => {
|
|
1313
|
+
if (u.startsWith("//")) {
|
|
1314
|
+
return `https:${u}`;
|
|
1315
|
+
}
|
|
1316
|
+
return u;
|
|
1317
|
+
}, "addProtocol");
|
|
1318
|
+
let publicPath = "publicPath" in manifestJson.metaData ? manifestJson.metaData.publicPath : new Function(manifestJson.metaData.getPublicPath)();
|
|
1319
|
+
if (publicPath === "auto") {
|
|
1320
|
+
publicPath = (0, import_sdk4.inferAutoPublicPath)(remoteInfo.url);
|
|
1321
|
+
}
|
|
1322
|
+
remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1323
|
+
if (!manifestJson.metaData.types.api) {
|
|
1324
|
+
console.warn(`Can not get ${remoteInfo.name}'s api types url!`);
|
|
1325
|
+
remoteInfo.apiTypeUrl = "";
|
|
1326
|
+
return remoteInfo;
|
|
1327
|
+
}
|
|
1328
|
+
remoteInfo.apiTypeUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.api)).href;
|
|
1329
|
+
return remoteInfo;
|
|
1330
|
+
} catch (_err) {
|
|
1331
|
+
fileLog(`fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`, "requestRemoteManifest", "error");
|
|
1216
1332
|
return remoteInfo;
|
|
1217
1333
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
const manifestJson = res.data;
|
|
1224
|
-
if (!manifestJson.metaData.types.zip) {
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
consumeTargetRemotes(hostOptions, remoteInfo) {
|
|
1337
|
+
return __async(this, null, function* () {
|
|
1338
|
+
if (!remoteInfo.zipUrl) {
|
|
1225
1339
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1226
1340
|
}
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1341
|
+
const typesDownloader = downloadTypesArchive(hostOptions);
|
|
1342
|
+
return typesDownloader([
|
|
1343
|
+
remoteInfo.alias,
|
|
1344
|
+
remoteInfo.zipUrl
|
|
1345
|
+
]);
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
downloadAPITypes(remoteInfo, destinationPath) {
|
|
1349
|
+
return __async(this, null, function* () {
|
|
1350
|
+
const { apiTypeUrl } = remoteInfo;
|
|
1351
|
+
if (!apiTypeUrl) {
|
|
1352
|
+
return;
|
|
1236
1353
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1354
|
+
try {
|
|
1355
|
+
const url = apiTypeUrl;
|
|
1356
|
+
const res = yield import_axios2.default.get(url);
|
|
1357
|
+
let apiTypeFile = res.data;
|
|
1358
|
+
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1359
|
+
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1360
|
+
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1361
|
+
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1362
|
+
} catch (err) {
|
|
1363
|
+
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "consumeTargetRemotes", "error");
|
|
1244
1364
|
}
|
|
1245
|
-
|
|
1246
|
-
import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.api)
|
|
1247
|
-
).href;
|
|
1248
|
-
return remoteInfo;
|
|
1249
|
-
} catch (_err) {
|
|
1250
|
-
fileLog(
|
|
1251
|
-
`fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`,
|
|
1252
|
-
"requestRemoteManifest",
|
|
1253
|
-
"error"
|
|
1254
|
-
);
|
|
1255
|
-
return remoteInfo;
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
async consumeTargetRemotes(hostOptions, remoteInfo) {
|
|
1259
|
-
if (!remoteInfo.zipUrl) {
|
|
1260
|
-
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1261
|
-
}
|
|
1262
|
-
const typesDownloader = downloadTypesArchive(hostOptions);
|
|
1263
|
-
return typesDownloader([remoteInfo.alias, remoteInfo.zipUrl]);
|
|
1365
|
+
});
|
|
1264
1366
|
}
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1267
|
-
if (!apiTypeUrl) {
|
|
1268
|
-
return;
|
|
1269
|
-
}
|
|
1367
|
+
consumeAPITypes(hostOptions) {
|
|
1368
|
+
const apiTypeFileName = import_path3.default.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME);
|
|
1270
1369
|
try {
|
|
1271
|
-
const
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
);
|
|
1278
|
-
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1279
|
-
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1280
|
-
this.loadedRemoteAPIAlias.push(remoteInfo.alias);
|
|
1370
|
+
const existedFile = import_fs.default.readFileSync(apiTypeFileName, "utf-8");
|
|
1371
|
+
const existedImports = new import_third_party_dts_extractor2.ThirdPartyExtractor("").collectTypeImports(existedFile);
|
|
1372
|
+
existedImports.forEach((existedImport) => {
|
|
1373
|
+
const alias = existedImport.split("./").slice(1).join("./").replace("/apis.d.ts", "");
|
|
1374
|
+
this.loadedRemoteAPIAlias.add(alias);
|
|
1375
|
+
});
|
|
1281
1376
|
} catch (err) {
|
|
1282
|
-
fileLog(
|
|
1283
|
-
`Unable to download "${remoteInfo.name}" api types, ${err}`,
|
|
1284
|
-
"consumeTargetRemotes",
|
|
1285
|
-
"error"
|
|
1286
|
-
);
|
|
1287
1377
|
}
|
|
1288
|
-
|
|
1289
|
-
consumeAPITypes(hostOptions) {
|
|
1290
|
-
if (!this.loadedRemoteAPIAlias.length) {
|
|
1378
|
+
if (!this.loadedRemoteAPIAlias.size) {
|
|
1291
1379
|
return;
|
|
1292
1380
|
}
|
|
1293
1381
|
const packageTypes = [];
|
|
1294
1382
|
const remoteKeys = [];
|
|
1295
|
-
const importTypeStr =
|
|
1383
|
+
const importTypeStr = [
|
|
1384
|
+
...this.loadedRemoteAPIAlias
|
|
1385
|
+
].sort().map((alias, index) => {
|
|
1296
1386
|
const remoteKey = `RemoteKeys_${index}`;
|
|
1297
1387
|
const packageType = `PackageType_${index}`;
|
|
1298
1388
|
packageTypes.push(`T extends ${remoteKey} ? ${packageType}<T>`);
|
|
@@ -1315,63 +1405,47 @@ var DTSManager = class {
|
|
|
1315
1405
|
const fileStr = `${importTypeStr}
|
|
1316
1406
|
${pkgsDeclareStr}
|
|
1317
1407
|
`;
|
|
1318
|
-
import_fs.default.writeFileSync(
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
)
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
await (0, import_promises.rm)(hostOptions.typesFolder, {
|
|
1331
|
-
recursive: true,
|
|
1332
|
-
force: true
|
|
1333
|
-
}).catch(
|
|
1334
|
-
(error2) => fileLog(
|
|
1335
|
-
`Unable to remove types folder, ${error2}`,
|
|
1336
|
-
"consumeArchiveTypes",
|
|
1337
|
-
"error"
|
|
1338
|
-
)
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
const downloadPromises = Object.entries(mapRemotesToDownload).map(
|
|
1342
|
-
async (item) => {
|
|
1408
|
+
import_fs.default.writeFileSync(import_path3.default.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME), fileStr);
|
|
1409
|
+
}
|
|
1410
|
+
consumeArchiveTypes(options) {
|
|
1411
|
+
return __async(this, null, function* () {
|
|
1412
|
+
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1413
|
+
if (hostOptions.deleteTypesFolder) {
|
|
1414
|
+
yield (0, import_promises.rm)(hostOptions.typesFolder, {
|
|
1415
|
+
recursive: true,
|
|
1416
|
+
force: true
|
|
1417
|
+
}).catch((error2) => fileLog(`Unable to remove types folder, ${error2}`, "consumeArchiveTypes", "error"));
|
|
1418
|
+
}
|
|
1419
|
+
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1343
1420
|
const remoteInfo = item[1];
|
|
1344
1421
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1345
|
-
const requiredRemoteInfo =
|
|
1422
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1346
1423
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1347
1424
|
}
|
|
1348
|
-
return this.consumeTargetRemotes(
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
hostOptions,
|
|
1357
|
-
downloadPromisesResult
|
|
1358
|
-
};
|
|
1425
|
+
return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
1426
|
+
}));
|
|
1427
|
+
const downloadPromisesResult = yield Promise.allSettled(downloadPromises);
|
|
1428
|
+
return {
|
|
1429
|
+
hostOptions,
|
|
1430
|
+
downloadPromisesResult
|
|
1431
|
+
};
|
|
1432
|
+
});
|
|
1359
1433
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
downloadPromisesResult.map(
|
|
1434
|
+
consumeTypes() {
|
|
1435
|
+
return __async(this, null, function* () {
|
|
1436
|
+
var _a3;
|
|
1437
|
+
try {
|
|
1438
|
+
const { options } = this;
|
|
1439
|
+
if (!options.host) {
|
|
1440
|
+
throw new Error("options.host is required if you want to consumeTypes");
|
|
1441
|
+
}
|
|
1442
|
+
const { mapRemotesToDownload } = retrieveHostConfig(options.host);
|
|
1443
|
+
if (!Object.keys(mapRemotesToDownload).length) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
const { downloadPromisesResult, hostOptions } = yield this.consumeArchiveTypes(options.host);
|
|
1447
|
+
if (hostOptions.consumeAPITypes) {
|
|
1448
|
+
yield Promise.all(downloadPromisesResult.map((item) => __async(this, null, function* () {
|
|
1375
1449
|
if (item.status === "rejected" || !item.value) {
|
|
1376
1450
|
return;
|
|
1377
1451
|
}
|
|
@@ -1380,64 +1454,80 @@ var DTSManager = class {
|
|
|
1380
1454
|
if (!remoteInfo) {
|
|
1381
1455
|
return;
|
|
1382
1456
|
}
|
|
1383
|
-
|
|
1384
|
-
})
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
"error"
|
|
1395
|
-
);
|
|
1396
|
-
} else {
|
|
1397
|
-
throw err;
|
|
1457
|
+
yield this.downloadAPITypes(remoteInfo, destinationPath);
|
|
1458
|
+
})));
|
|
1459
|
+
this.consumeAPITypes(hostOptions);
|
|
1460
|
+
}
|
|
1461
|
+
console.log(import_ansi_colors2.default.green("Federated types extraction completed"));
|
|
1462
|
+
} catch (err) {
|
|
1463
|
+
if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1464
|
+
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
1465
|
+
} else {
|
|
1466
|
+
throw err;
|
|
1467
|
+
}
|
|
1398
1468
|
}
|
|
1399
|
-
}
|
|
1469
|
+
});
|
|
1400
1470
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1471
|
+
updateTypes(options) {
|
|
1472
|
+
return __async(this, null, function* () {
|
|
1473
|
+
var _a3, _b, _c;
|
|
1474
|
+
try {
|
|
1475
|
+
const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
|
|
1476
|
+
const hostName = (_c = (_b = (_a3 = this.options) == null ? void 0 : _a3.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
|
|
1477
|
+
fileLog(`updateTypes options:, ${JSON.stringify(options, null, 2)}`, "consumeTypes", "info");
|
|
1478
|
+
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
|
|
1479
|
+
if (!this.options.remote) {
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
this.generateTypes();
|
|
1483
|
+
} else {
|
|
1484
|
+
const { remoteAliasMap } = this;
|
|
1485
|
+
if (!this.options.host) {
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1489
|
+
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1490
|
+
if (!loadedRemoteInfo) {
|
|
1491
|
+
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
1492
|
+
return item.name === remoteName;
|
|
1493
|
+
});
|
|
1494
|
+
if (remoteInfo) {
|
|
1495
|
+
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1496
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1497
|
+
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1498
|
+
}
|
|
1499
|
+
yield this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
1500
|
+
} else if (updatedRemoteInfo) {
|
|
1501
|
+
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1502
|
+
const [_destinationFolder, destinationPath] = yield this.consumeTargetRemotes(hostOptions, this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1503
|
+
yield this.downloadAPITypes(this.updatedRemoteInfos[updatedRemoteInfo.name], destinationPath);
|
|
1504
|
+
this.consumeAPITypes(hostOptions);
|
|
1505
|
+
}), "consumeDynamicRemoteTypes");
|
|
1506
|
+
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1507
|
+
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
1508
|
+
hostOptions,
|
|
1509
|
+
remoteAlias: updatedRemoteInfo.alias || updatedRemoteInfo.name,
|
|
1510
|
+
remote: updatedRemoteInfo.url
|
|
1511
|
+
});
|
|
1512
|
+
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
1513
|
+
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
|
|
1514
|
+
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "consumeTypes", "info");
|
|
1515
|
+
yield consumeDynamicRemoteTypes();
|
|
1516
|
+
}
|
|
1517
|
+
if (!once && this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1518
|
+
yield consumeDynamicRemoteTypes();
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
} else {
|
|
1522
|
+
yield this.consumeTargetRemotes(hostOptions, loadedRemoteInfo);
|
|
1429
1523
|
}
|
|
1430
|
-
await this.consumeTargetRemotes(
|
|
1431
|
-
hostOptions,
|
|
1432
|
-
this.remoteAliasMap[remoteInfo.alias]
|
|
1433
|
-
);
|
|
1434
1524
|
}
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1525
|
+
} catch (err) {
|
|
1526
|
+
fileLog(`updateTypes fail, ${err}`, "updateTypes", "error");
|
|
1437
1527
|
}
|
|
1438
|
-
}
|
|
1528
|
+
});
|
|
1439
1529
|
}
|
|
1440
|
-
};
|
|
1530
|
+
}, __name(_a, "DTSManager"), _a);
|
|
1441
1531
|
|
|
1442
1532
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
1443
1533
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -1449,11 +1539,12 @@ function getDTSManagerConstructor(implementation) {
|
|
|
1449
1539
|
}
|
|
1450
1540
|
return DTSManager;
|
|
1451
1541
|
}
|
|
1452
|
-
|
|
1542
|
+
__name(getDTSManagerConstructor, "getDTSManagerConstructor");
|
|
1543
|
+
var validateOptions = /* @__PURE__ */ __name((options) => {
|
|
1453
1544
|
if (!options.moduleFederationConfig) {
|
|
1454
1545
|
throw new Error("moduleFederationConfig is required");
|
|
1455
1546
|
}
|
|
1456
|
-
};
|
|
1547
|
+
}, "validateOptions");
|
|
1457
1548
|
function retrieveTypesAssetsInfo(options) {
|
|
1458
1549
|
let apiTypesPath = "";
|
|
1459
1550
|
let zipTypesPath = "";
|
|
@@ -1488,7 +1579,8 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1488
1579
|
};
|
|
1489
1580
|
}
|
|
1490
1581
|
}
|
|
1491
|
-
|
|
1582
|
+
__name(retrieveTypesAssetsInfo, "retrieveTypesAssetsInfo");
|
|
1583
|
+
var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) => {
|
|
1492
1584
|
if (dtsOptions === false) {
|
|
1493
1585
|
return false;
|
|
1494
1586
|
}
|
|
@@ -1506,7 +1598,7 @@ var isTSProject = (dtsOptions, context = process.cwd()) => {
|
|
|
1506
1598
|
} catch (err) {
|
|
1507
1599
|
return false;
|
|
1508
1600
|
}
|
|
1509
|
-
};
|
|
1601
|
+
}, "isTSProject");
|
|
1510
1602
|
|
|
1511
1603
|
// packages/dts-plugin/src/core/configurations/remotePlugin.ts
|
|
1512
1604
|
var defaultOptions2 = {
|
|
@@ -1525,85 +1617,56 @@ var defaultOptions2 = {
|
|
|
1525
1617
|
extractRemoteTypes: false,
|
|
1526
1618
|
extractThirdParty: false
|
|
1527
1619
|
};
|
|
1528
|
-
var readTsConfig = ({
|
|
1529
|
-
tsConfigPath,
|
|
1530
|
-
typesFolder,
|
|
1531
|
-
compiledTypesFolder,
|
|
1532
|
-
context
|
|
1533
|
-
}) => {
|
|
1620
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context }) => {
|
|
1534
1621
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
1535
|
-
const readResult = import_typescript2.default.readConfigFile(
|
|
1536
|
-
resolvedTsConfigPath,
|
|
1537
|
-
import_typescript2.default.sys.readFile
|
|
1538
|
-
);
|
|
1622
|
+
const readResult = import_typescript2.default.readConfigFile(resolvedTsConfigPath, import_typescript2.default.sys.readFile);
|
|
1539
1623
|
if (readResult.error) {
|
|
1540
1624
|
throw new Error(readResult.error.messageText.toString());
|
|
1541
1625
|
}
|
|
1542
|
-
const configContent = import_typescript2.default.parseJsonConfigFileContent(
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
(0, import_path5.dirname)(resolvedTsConfigPath)
|
|
1546
|
-
);
|
|
1547
|
-
const outDir = (0, import_path5.resolve)(
|
|
1548
|
-
context,
|
|
1549
|
-
configContent.options.outDir || "dist",
|
|
1550
|
-
typesFolder,
|
|
1551
|
-
compiledTypesFolder
|
|
1552
|
-
);
|
|
1553
|
-
return {
|
|
1554
|
-
...configContent.options,
|
|
1626
|
+
const configContent = import_typescript2.default.parseJsonConfigFileContent(readResult.config, import_typescript2.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
|
|
1627
|
+
const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1628
|
+
return __spreadProps(__spreadValues({}, configContent.options), {
|
|
1555
1629
|
emitDeclarationOnly: true,
|
|
1556
1630
|
noEmit: false,
|
|
1557
1631
|
declaration: true,
|
|
1558
1632
|
outDir
|
|
1559
|
-
};
|
|
1560
|
-
};
|
|
1561
|
-
var TS_EXTENSIONS = [
|
|
1562
|
-
|
|
1633
|
+
});
|
|
1634
|
+
}, "readTsConfig");
|
|
1635
|
+
var TS_EXTENSIONS = [
|
|
1636
|
+
"ts",
|
|
1637
|
+
"tsx",
|
|
1638
|
+
"vue",
|
|
1639
|
+
"svelte"
|
|
1640
|
+
];
|
|
1641
|
+
var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
|
|
1563
1642
|
if ((0, import_path5.extname)(exposedPath)) {
|
|
1564
1643
|
return (0, import_path5.resolve)(context, exposedPath);
|
|
1565
1644
|
}
|
|
1566
1645
|
for (const extension of TS_EXTENSIONS) {
|
|
1567
|
-
const exposedPathWithExtension = (0, import_path5.resolve)(
|
|
1568
|
-
context,
|
|
1569
|
-
`${exposedPath}.${extension}`
|
|
1570
|
-
);
|
|
1646
|
+
const exposedPathWithExtension = (0, import_path5.resolve)(context, `${exposedPath}.${extension}`);
|
|
1571
1647
|
if ((0, import_fs3.existsSync)(exposedPathWithExtension)) {
|
|
1572
1648
|
return exposedPathWithExtension;
|
|
1573
1649
|
}
|
|
1574
1650
|
}
|
|
1575
1651
|
return void 0;
|
|
1576
|
-
};
|
|
1577
|
-
var resolveExposes = (remoteOptions) => {
|
|
1578
|
-
const parsedOptions = import_managers2.utils.parseOptions(
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(
|
|
1593
|
-
(0, import_path5.join)(exposePath, "index"),
|
|
1594
|
-
remoteOptions.context
|
|
1595
|
-
) || exposePath;
|
|
1596
|
-
return accumulator;
|
|
1597
|
-
},
|
|
1598
|
-
{}
|
|
1599
|
-
);
|
|
1600
|
-
};
|
|
1601
|
-
var retrieveRemoteConfig = (options) => {
|
|
1652
|
+
}, "resolveWithExtension");
|
|
1653
|
+
var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
|
|
1654
|
+
const parsedOptions = import_managers2.utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
|
|
1655
|
+
exposePath: Array.isArray(item) ? item[0] : item,
|
|
1656
|
+
key
|
|
1657
|
+
}), (item, key) => ({
|
|
1658
|
+
exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
|
|
1659
|
+
key
|
|
1660
|
+
}));
|
|
1661
|
+
return parsedOptions.reduce((accumulator, item) => {
|
|
1662
|
+
const { exposePath, key } = item[1];
|
|
1663
|
+
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension((0, import_path5.join)(exposePath, "index"), remoteOptions.context) || exposePath;
|
|
1664
|
+
return accumulator;
|
|
1665
|
+
}, {});
|
|
1666
|
+
}, "resolveExposes");
|
|
1667
|
+
var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
1602
1668
|
validateOptions(options);
|
|
1603
|
-
const remoteOptions = {
|
|
1604
|
-
...defaultOptions2,
|
|
1605
|
-
...options
|
|
1606
|
-
};
|
|
1669
|
+
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1607
1670
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
1608
1671
|
const tsConfig = readTsConfig(remoteOptions);
|
|
1609
1672
|
return {
|
|
@@ -1611,17 +1674,18 @@ var retrieveRemoteConfig = (options) => {
|
|
|
1611
1674
|
mapComponentsToExpose,
|
|
1612
1675
|
remoteOptions
|
|
1613
1676
|
};
|
|
1614
|
-
};
|
|
1677
|
+
}, "retrieveRemoteConfig");
|
|
1615
1678
|
|
|
1616
1679
|
// packages/dts-plugin/src/core/lib/generateTypes.ts
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
(
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1680
|
+
function generateTypes(options) {
|
|
1681
|
+
return __async(this, null, function* () {
|
|
1682
|
+
var _a3;
|
|
1683
|
+
const DTSManagerConstructor = getDTSManagerConstructor((_a3 = options.remote) == null ? void 0 : _a3.implementation);
|
|
1684
|
+
const dtsManager = new DTSManagerConstructor(options);
|
|
1685
|
+
return dtsManager.generateTypes();
|
|
1686
|
+
});
|
|
1624
1687
|
}
|
|
1688
|
+
__name(generateTypes, "generateTypes");
|
|
1625
1689
|
|
|
1626
1690
|
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
1627
1691
|
var import_path6 = __toESM(require("path"));
|
|
@@ -1642,23 +1706,21 @@ __export(rpc_exports, {
|
|
|
1642
1706
|
var import_process = __toESM(require("process"));
|
|
1643
1707
|
|
|
1644
1708
|
// packages/dts-plugin/src/core/rpc/types.ts
|
|
1645
|
-
var RpcGMCallTypes
|
|
1709
|
+
var RpcGMCallTypes;
|
|
1710
|
+
(function(RpcGMCallTypes2) {
|
|
1646
1711
|
RpcGMCallTypes2["CALL"] = "mf_call";
|
|
1647
1712
|
RpcGMCallTypes2["RESOLVE"] = "mf_resolve";
|
|
1648
1713
|
RpcGMCallTypes2["REJECT"] = "mf_reject";
|
|
1649
1714
|
RpcGMCallTypes2["EXIT"] = "mf_exit";
|
|
1650
|
-
|
|
1651
|
-
})(RpcGMCallTypes || {});
|
|
1715
|
+
})(RpcGMCallTypes || (RpcGMCallTypes = {}));
|
|
1652
1716
|
|
|
1653
1717
|
// packages/dts-plugin/src/core/rpc/expose-rpc.ts
|
|
1654
1718
|
function exposeRpc(fn) {
|
|
1655
|
-
const sendMessage = (message) => new Promise((resolve4, reject) => {
|
|
1719
|
+
const sendMessage = /* @__PURE__ */ __name((message) => new Promise((resolve4, reject) => {
|
|
1656
1720
|
if (!import_process.default.send) {
|
|
1657
1721
|
reject(new Error(`Process ${import_process.default.pid} doesn't have IPC channels`));
|
|
1658
1722
|
} else if (!import_process.default.connected) {
|
|
1659
|
-
reject(
|
|
1660
|
-
new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`)
|
|
1661
|
-
);
|
|
1723
|
+
reject(new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`));
|
|
1662
1724
|
} else {
|
|
1663
1725
|
import_process.default.send(message, void 0, void 0, (error2) => {
|
|
1664
1726
|
if (error2) {
|
|
@@ -1668,28 +1730,28 @@ function exposeRpc(fn) {
|
|
|
1668
1730
|
}
|
|
1669
1731
|
});
|
|
1670
1732
|
}
|
|
1671
|
-
});
|
|
1672
|
-
const handleMessage =
|
|
1673
|
-
if (message.type ===
|
|
1733
|
+
}), "sendMessage");
|
|
1734
|
+
const handleMessage = /* @__PURE__ */ __name((message) => __async(this, null, function* () {
|
|
1735
|
+
if (message.type === RpcGMCallTypes.CALL) {
|
|
1674
1736
|
if (!import_process.default.send) {
|
|
1675
1737
|
return;
|
|
1676
1738
|
}
|
|
1677
1739
|
let value, error2;
|
|
1678
1740
|
try {
|
|
1679
|
-
value =
|
|
1741
|
+
value = yield fn(...message.args);
|
|
1680
1742
|
} catch (fnError) {
|
|
1681
1743
|
error2 = fnError;
|
|
1682
1744
|
}
|
|
1683
1745
|
try {
|
|
1684
1746
|
if (error2) {
|
|
1685
|
-
|
|
1686
|
-
type:
|
|
1747
|
+
yield sendMessage({
|
|
1748
|
+
type: RpcGMCallTypes.REJECT,
|
|
1687
1749
|
id: message.id,
|
|
1688
1750
|
error: error2
|
|
1689
1751
|
});
|
|
1690
1752
|
} else {
|
|
1691
|
-
|
|
1692
|
-
type:
|
|
1753
|
+
yield sendMessage({
|
|
1754
|
+
type: RpcGMCallTypes.RESOLVE,
|
|
1693
1755
|
id: message.id,
|
|
1694
1756
|
value
|
|
1695
1757
|
});
|
|
@@ -1703,24 +1765,28 @@ function exposeRpc(fn) {
|
|
|
1703
1765
|
console.error(sendError);
|
|
1704
1766
|
}
|
|
1705
1767
|
}
|
|
1706
|
-
};
|
|
1768
|
+
}), "handleMessage");
|
|
1707
1769
|
import_process.default.on("message", handleMessage);
|
|
1708
1770
|
}
|
|
1771
|
+
__name(exposeRpc, "exposeRpc");
|
|
1709
1772
|
|
|
1710
1773
|
// packages/dts-plugin/src/core/rpc/rpc-error.ts
|
|
1711
|
-
var
|
|
1774
|
+
var _a2;
|
|
1775
|
+
var RpcExitError = (_a2 = class extends Error {
|
|
1712
1776
|
constructor(message, code, signal) {
|
|
1713
1777
|
super(message);
|
|
1778
|
+
__publicField(this, "code");
|
|
1779
|
+
__publicField(this, "signal");
|
|
1714
1780
|
this.code = code;
|
|
1715
1781
|
this.signal = signal;
|
|
1716
1782
|
this.name = "RpcExitError";
|
|
1717
1783
|
}
|
|
1718
|
-
};
|
|
1784
|
+
}, __name(_a2, "RpcExitError"), _a2);
|
|
1719
1785
|
|
|
1720
1786
|
// packages/dts-plugin/src/core/rpc/wrap-rpc.ts
|
|
1721
1787
|
function createControlledPromise() {
|
|
1722
|
-
let resolve4 = () => void 0;
|
|
1723
|
-
let reject = () => void 0;
|
|
1788
|
+
let resolve4 = /* @__PURE__ */ __name(() => void 0, "resolve");
|
|
1789
|
+
let reject = /* @__PURE__ */ __name(() => void 0, "reject");
|
|
1724
1790
|
const promise = new Promise((aResolve, aReject) => {
|
|
1725
1791
|
resolve4 = aResolve;
|
|
1726
1792
|
reject = aReject;
|
|
@@ -1731,76 +1797,59 @@ function createControlledPromise() {
|
|
|
1731
1797
|
reject
|
|
1732
1798
|
};
|
|
1733
1799
|
}
|
|
1800
|
+
__name(createControlledPromise, "createControlledPromise");
|
|
1734
1801
|
function wrapRpc(childProcess, options) {
|
|
1735
|
-
return
|
|
1802
|
+
return (...args) => __async(this, null, function* () {
|
|
1736
1803
|
if (!childProcess.send) {
|
|
1737
1804
|
throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
|
|
1738
1805
|
} else if (!childProcess.connected) {
|
|
1739
|
-
throw new Error(
|
|
1740
|
-
`Process ${childProcess.pid} doesn't have open IPC channels`
|
|
1741
|
-
);
|
|
1806
|
+
throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
|
|
1742
1807
|
}
|
|
1743
1808
|
const { id, once } = options;
|
|
1744
|
-
const {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
reject: rejectResult
|
|
1748
|
-
} = createControlledPromise();
|
|
1749
|
-
const {
|
|
1750
|
-
promise: sendPromise,
|
|
1751
|
-
resolve: resolveSend,
|
|
1752
|
-
reject: rejectSend
|
|
1753
|
-
} = createControlledPromise();
|
|
1754
|
-
const handleMessage = (message) => {
|
|
1809
|
+
const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
|
|
1810
|
+
const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
|
|
1811
|
+
const handleMessage = /* @__PURE__ */ __name((message) => {
|
|
1755
1812
|
if ((message == null ? void 0 : message.id) === id) {
|
|
1756
|
-
if (message.type ===
|
|
1813
|
+
if (message.type === RpcGMCallTypes.RESOLVE) {
|
|
1757
1814
|
resolveResult(message.value);
|
|
1758
|
-
} else if (message.type ===
|
|
1815
|
+
} else if (message.type === RpcGMCallTypes.REJECT) {
|
|
1759
1816
|
rejectResult(message.error);
|
|
1760
1817
|
}
|
|
1761
1818
|
}
|
|
1762
1819
|
if (once && (childProcess == null ? void 0 : childProcess.kill)) {
|
|
1763
1820
|
childProcess.kill("SIGTERM");
|
|
1764
1821
|
}
|
|
1765
|
-
};
|
|
1766
|
-
const handleClose = (code, signal) => {
|
|
1767
|
-
rejectResult(
|
|
1768
|
-
new RpcExitError(
|
|
1769
|
-
code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`,
|
|
1770
|
-
code,
|
|
1771
|
-
signal
|
|
1772
|
-
)
|
|
1773
|
-
);
|
|
1822
|
+
}, "handleMessage");
|
|
1823
|
+
const handleClose = /* @__PURE__ */ __name((code, signal) => {
|
|
1824
|
+
rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
|
|
1774
1825
|
removeHandlers();
|
|
1775
|
-
};
|
|
1776
|
-
const removeHandlers = () => {
|
|
1826
|
+
}, "handleClose");
|
|
1827
|
+
const removeHandlers = /* @__PURE__ */ __name(() => {
|
|
1777
1828
|
childProcess.off("message", handleMessage);
|
|
1778
1829
|
childProcess.off("close", handleClose);
|
|
1779
|
-
};
|
|
1830
|
+
}, "removeHandlers");
|
|
1780
1831
|
if (once) {
|
|
1781
1832
|
childProcess.once("message", handleMessage);
|
|
1782
1833
|
} else {
|
|
1783
1834
|
childProcess.on("message", handleMessage);
|
|
1784
1835
|
}
|
|
1785
1836
|
childProcess.on("close", handleClose);
|
|
1786
|
-
childProcess.send(
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
} else {
|
|
1797
|
-
resolveSend(void 0);
|
|
1798
|
-
}
|
|
1837
|
+
childProcess.send({
|
|
1838
|
+
type: RpcGMCallTypes.CALL,
|
|
1839
|
+
id,
|
|
1840
|
+
args
|
|
1841
|
+
}, (error2) => {
|
|
1842
|
+
if (error2) {
|
|
1843
|
+
rejectSend(error2);
|
|
1844
|
+
removeHandlers();
|
|
1845
|
+
} else {
|
|
1846
|
+
resolveSend(void 0);
|
|
1799
1847
|
}
|
|
1800
|
-
);
|
|
1848
|
+
});
|
|
1801
1849
|
return sendPromise.then(() => resultPromise);
|
|
1802
|
-
};
|
|
1850
|
+
});
|
|
1803
1851
|
}
|
|
1852
|
+
__name(wrapRpc, "wrapRpc");
|
|
1804
1853
|
|
|
1805
1854
|
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
1806
1855
|
var child_process = __toESM(require("child_process"));
|
|
@@ -1809,15 +1858,21 @@ var import_crypto = require("crypto");
|
|
|
1809
1858
|
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
1810
1859
|
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
1811
1860
|
const options = {
|
|
1812
|
-
env: {
|
|
1813
|
-
...process3.env,
|
|
1861
|
+
env: __spreadProps(__spreadValues({}, process3.env), {
|
|
1814
1862
|
[FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
|
|
1815
|
-
},
|
|
1816
|
-
stdio: [
|
|
1863
|
+
}),
|
|
1864
|
+
stdio: [
|
|
1865
|
+
"inherit",
|
|
1866
|
+
"inherit",
|
|
1867
|
+
"inherit",
|
|
1868
|
+
"ipc"
|
|
1869
|
+
],
|
|
1817
1870
|
serialization: "advanced"
|
|
1818
1871
|
};
|
|
1819
1872
|
if (memoryLimit) {
|
|
1820
|
-
options.execArgv = [
|
|
1873
|
+
options.execArgv = [
|
|
1874
|
+
`--max-old-space-size=${memoryLimit}`
|
|
1875
|
+
];
|
|
1821
1876
|
}
|
|
1822
1877
|
let childProcess, remoteMethod;
|
|
1823
1878
|
const id = (0, import_crypto.randomUUID)();
|
|
@@ -1825,7 +1880,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1825
1880
|
connect(...args) {
|
|
1826
1881
|
if (childProcess && !childProcess.connected) {
|
|
1827
1882
|
childProcess.send({
|
|
1828
|
-
type:
|
|
1883
|
+
type: RpcGMCallTypes.EXIT,
|
|
1829
1884
|
id
|
|
1830
1885
|
});
|
|
1831
1886
|
childProcess = void 0;
|
|
@@ -1833,19 +1888,20 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1833
1888
|
}
|
|
1834
1889
|
if (!(childProcess == null ? void 0 : childProcess.connected)) {
|
|
1835
1890
|
childProcess = child_process.fork(modulePath, options);
|
|
1836
|
-
remoteMethod = wrapRpc(childProcess, {
|
|
1891
|
+
remoteMethod = wrapRpc(childProcess, {
|
|
1892
|
+
id,
|
|
1893
|
+
once
|
|
1894
|
+
});
|
|
1837
1895
|
}
|
|
1838
1896
|
if (!remoteMethod) {
|
|
1839
|
-
return Promise.reject(
|
|
1840
|
-
new Error("Worker is not connected - cannot perform RPC.")
|
|
1841
|
-
);
|
|
1897
|
+
return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
|
|
1842
1898
|
}
|
|
1843
1899
|
return remoteMethod(...args);
|
|
1844
1900
|
},
|
|
1845
1901
|
terminate() {
|
|
1846
|
-
var
|
|
1847
|
-
(
|
|
1848
|
-
type:
|
|
1902
|
+
var _a3;
|
|
1903
|
+
(_a3 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a3.call(childProcess, {
|
|
1904
|
+
type: RpcGMCallTypes.EXIT,
|
|
1849
1905
|
id
|
|
1850
1906
|
});
|
|
1851
1907
|
childProcess = void 0;
|
|
@@ -1863,30 +1919,30 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1863
1919
|
};
|
|
1864
1920
|
return worker;
|
|
1865
1921
|
}
|
|
1922
|
+
__name(createRpcWorker, "createRpcWorker");
|
|
1866
1923
|
function getRpcWorkerData() {
|
|
1867
1924
|
return JSON.parse(process3.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
|
|
1868
1925
|
}
|
|
1926
|
+
__name(getRpcWorkerData, "getRpcWorkerData");
|
|
1869
1927
|
|
|
1870
1928
|
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
1871
|
-
var
|
|
1929
|
+
var _DtsWorker = class _DtsWorker {
|
|
1872
1930
|
constructor(options) {
|
|
1931
|
+
__publicField(this, "rpcWorker");
|
|
1932
|
+
__publicField(this, "_options");
|
|
1933
|
+
__publicField(this, "_res");
|
|
1873
1934
|
this._options = (0, import_lodash2.default)(options, (_value, key) => {
|
|
1874
1935
|
if (key === "manifest") {
|
|
1875
1936
|
return false;
|
|
1876
1937
|
}
|
|
1877
1938
|
});
|
|
1878
1939
|
this.removeUnSerializationOptions();
|
|
1879
|
-
this.rpcWorker = createRpcWorker(
|
|
1880
|
-
import_path6.default.resolve(__dirname, "./forkGenerateDts.js"),
|
|
1881
|
-
{},
|
|
1882
|
-
void 0,
|
|
1883
|
-
true
|
|
1884
|
-
);
|
|
1940
|
+
this.rpcWorker = createRpcWorker(import_path6.default.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
|
|
1885
1941
|
this._res = this.rpcWorker.connect(this._options);
|
|
1886
1942
|
}
|
|
1887
1943
|
removeUnSerializationOptions() {
|
|
1888
|
-
var
|
|
1889
|
-
if ((_b = (
|
|
1944
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h;
|
|
1945
|
+
if ((_b = (_a3 = this._options.remote) == null ? void 0 : _a3.moduleFederationConfig) == null ? void 0 : _b.manifest) {
|
|
1890
1946
|
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
1891
1947
|
}
|
|
1892
1948
|
if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
|
|
@@ -1899,26 +1955,32 @@ var DtsWorker = class {
|
|
|
1899
1955
|
});
|
|
1900
1956
|
}
|
|
1901
1957
|
exit() {
|
|
1902
|
-
var
|
|
1903
|
-
(
|
|
1958
|
+
var _a3;
|
|
1959
|
+
(_a3 = this.rpcWorker) == null ? void 0 : _a3.terminate();
|
|
1904
1960
|
}
|
|
1905
1961
|
};
|
|
1962
|
+
__name(_DtsWorker, "DtsWorker");
|
|
1963
|
+
var DtsWorker = _DtsWorker;
|
|
1906
1964
|
|
|
1907
1965
|
// packages/dts-plugin/src/core/lib/generateTypesInChildProcess.ts
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1966
|
+
function generateTypesInChildProcess(options) {
|
|
1967
|
+
return __async(this, null, function* () {
|
|
1968
|
+
const dtsWorker = new DtsWorker(options);
|
|
1969
|
+
return dtsWorker.controlledPromise;
|
|
1970
|
+
});
|
|
1911
1971
|
}
|
|
1972
|
+
__name(generateTypesInChildProcess, "generateTypesInChildProcess");
|
|
1912
1973
|
|
|
1913
1974
|
// packages/dts-plugin/src/core/lib/consumeTypes.ts
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
(
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1975
|
+
function consumeTypes(options) {
|
|
1976
|
+
return __async(this, null, function* () {
|
|
1977
|
+
var _a3;
|
|
1978
|
+
const DTSManagerConstructor = getDTSManagerConstructor((_a3 = options.host) == null ? void 0 : _a3.implementation);
|
|
1979
|
+
const dtsManager = new DTSManagerConstructor(options);
|
|
1980
|
+
yield dtsManager.consumeTypes();
|
|
1981
|
+
});
|
|
1921
1982
|
}
|
|
1983
|
+
__name(consumeTypes, "consumeTypes");
|
|
1922
1984
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1923
1985
|
0 && (module.exports = {
|
|
1924
1986
|
DTSManager,
|