@module-federation/dts-plugin 0.1.19 → 0.1.21
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 +27 -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 +1105 -1008
- 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-55BKSNZ4.js +2372 -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 +2543 -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 +1902 -0
- package/dist/iife/launch-web-client.js +91 -42
- package/dist/index.d.mts +10 -0
- package/dist/index.js +1287 -1181
- 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 +1273 -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/index.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((resolve5, 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 ? resolve5(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/index.ts
|
|
31
72
|
var src_exports = {};
|
|
@@ -53,20 +94,26 @@ var import_managers2 = require("@module-federation/managers");
|
|
|
53
94
|
var import_typescript2 = __toESM(require("typescript"));
|
|
54
95
|
|
|
55
96
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
97
|
+
var import_fs2 = __toESM(require("fs"));
|
|
56
98
|
var import_path4 = __toESM(require("path"));
|
|
99
|
+
var import_axios = __toESM(require("axios"));
|
|
100
|
+
var import_http2 = __toESM(require("http"));
|
|
101
|
+
var import_https = __toESM(require("https"));
|
|
102
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
57
103
|
|
|
58
104
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
59
105
|
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
60
106
|
var import_path3 = __toESM(require("path"));
|
|
61
|
-
var
|
|
107
|
+
var import_promises2 = require("fs/promises");
|
|
62
108
|
var import_fs = __toESM(require("fs"));
|
|
63
109
|
var import_sdk4 = require("@module-federation/sdk");
|
|
64
110
|
var import_lodash = __toESM(require("lodash.clonedeepwith"));
|
|
111
|
+
var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
|
|
65
112
|
|
|
66
113
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
67
114
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
68
|
-
var import_axios = __toESM(require("axios"));
|
|
69
115
|
var import_path2 = require("path");
|
|
116
|
+
var import_promises = require("fs/promises");
|
|
70
117
|
|
|
71
118
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
72
119
|
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
@@ -75,77 +122,46 @@ var import_typescript = __toESM(require("typescript"));
|
|
|
75
122
|
var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
76
123
|
var STARTS_WITH_SLASH = /^\//;
|
|
77
124
|
var DEFINITION_FILE_EXTENSION = ".d.ts";
|
|
78
|
-
var reportCompileDiagnostic = (diagnostic) => {
|
|
79
|
-
const { line } = diagnostic.file.getLineAndCharacterOfPosition(
|
|
80
|
-
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)}`
|
|
88
|
-
)
|
|
89
|
-
);
|
|
90
|
-
console.error(
|
|
91
|
-
import_ansi_colors.default.red(
|
|
92
|
-
` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`
|
|
93
|
-
)
|
|
94
|
-
);
|
|
95
|
-
};
|
|
96
|
-
var retrieveMfTypesPath = (tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, ""));
|
|
97
|
-
var retrieveOriginalOutDir = (tsConfig, remoteOptions) => (0, import_path.normalize)(
|
|
98
|
-
tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")
|
|
99
|
-
);
|
|
100
|
-
var retrieveMfAPITypesPath = (tsConfig, remoteOptions) => (0, import_path.join)(
|
|
101
|
-
retrieveOriginalOutDir(tsConfig, remoteOptions),
|
|
102
|
-
`${remoteOptions.typesFolder}.d.ts`
|
|
103
|
-
);
|
|
104
|
-
var createHost = (mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
|
|
125
|
+
var reportCompileDiagnostic = /* @__PURE__ */ __name((diagnostic) => {
|
|
126
|
+
const { line } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
127
|
+
console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
|
|
128
|
+
console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
|
|
129
|
+
}, "reportCompileDiagnostic");
|
|
130
|
+
var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
|
|
131
|
+
var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
|
|
132
|
+
var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
|
|
133
|
+
var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
|
|
105
134
|
const host = import_typescript.default.createCompilerHost(tsConfig);
|
|
106
135
|
const originalWriteFile = host.writeFile;
|
|
107
|
-
const mapExposeToEntry = Object.fromEntries(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
])
|
|
112
|
-
);
|
|
136
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => [
|
|
137
|
+
(0, import_path.normalize)(filename),
|
|
138
|
+
exposed
|
|
139
|
+
]));
|
|
113
140
|
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
114
141
|
host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
|
|
115
|
-
originalWriteFile(
|
|
116
|
-
filepath,
|
|
117
|
-
text,
|
|
118
|
-
writeOrderByteMark,
|
|
119
|
-
onError,
|
|
120
|
-
sourceFiles,
|
|
121
|
-
data
|
|
122
|
-
);
|
|
142
|
+
originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
|
|
123
143
|
for (const sourceFile of sourceFiles || []) {
|
|
124
|
-
|
|
144
|
+
let sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
|
|
145
|
+
if (sourceEntry === ".") {
|
|
146
|
+
sourceEntry = "index";
|
|
147
|
+
}
|
|
125
148
|
if (sourceEntry) {
|
|
126
|
-
const mfeTypeEntry = (0, import_path.join)(
|
|
127
|
-
mfTypePath,
|
|
128
|
-
`${sourceEntry}${DEFINITION_FILE_EXTENSION}`
|
|
129
|
-
);
|
|
149
|
+
const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
|
|
130
150
|
const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
|
|
131
151
|
const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filepath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
|
|
132
|
-
originalWriteFile(
|
|
133
|
-
|
|
134
|
-
`export * from './${relativePathToOutput}';
|
|
135
|
-
export { default } from './${relativePathToOutput}';`,
|
|
136
|
-
writeOrderByteMark
|
|
137
|
-
);
|
|
152
|
+
originalWriteFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
153
|
+
export { default } from './${relativePathToOutput}';`, writeOrderByteMark);
|
|
138
154
|
}
|
|
139
155
|
}
|
|
140
156
|
cb(text);
|
|
141
157
|
};
|
|
142
158
|
return host;
|
|
143
|
-
};
|
|
144
|
-
var createVueTscProgram = (programOptions) => {
|
|
159
|
+
}, "createHost");
|
|
160
|
+
var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
|
|
145
161
|
const vueTypescript = require("vue-tsc");
|
|
146
162
|
return vueTypescript.createProgram(programOptions);
|
|
147
|
-
};
|
|
148
|
-
var createProgram = (remoteOptions, programOptions) => {
|
|
163
|
+
}, "createVueTscProgram");
|
|
164
|
+
var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
|
|
149
165
|
switch (remoteOptions.compilerInstance) {
|
|
150
166
|
case "vue-tsc":
|
|
151
167
|
return createVueTscProgram(programOptions);
|
|
@@ -153,13 +169,10 @@ var createProgram = (remoteOptions, programOptions) => {
|
|
|
153
169
|
default:
|
|
154
170
|
return import_typescript.default.createProgram(programOptions);
|
|
155
171
|
}
|
|
156
|
-
};
|
|
157
|
-
var compileTs = (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
172
|
+
}, "createProgram");
|
|
173
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
158
174
|
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
159
|
-
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor(
|
|
160
|
-
(0, import_path.resolve)(mfTypePath, "node_modules"),
|
|
161
|
-
remoteOptions.context
|
|
162
|
-
);
|
|
175
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
163
176
|
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
164
177
|
const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
|
|
165
178
|
const filesToCompile = [
|
|
@@ -177,52 +190,77 @@ var compileTs = (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
|
177
190
|
if (remoteOptions.extractThirdParty) {
|
|
178
191
|
thirdPartyExtractor.copyDts();
|
|
179
192
|
}
|
|
180
|
-
};
|
|
193
|
+
}, "compileTs");
|
|
181
194
|
|
|
182
195
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
183
|
-
var
|
|
196
|
+
var _Message = class _Message {
|
|
184
197
|
constructor(type, kind) {
|
|
198
|
+
__publicField(this, "type");
|
|
199
|
+
__publicField(this, "kind");
|
|
200
|
+
__publicField(this, "time");
|
|
185
201
|
this.type = type;
|
|
186
202
|
this.kind = kind;
|
|
187
203
|
this.time = Date.now();
|
|
188
204
|
}
|
|
189
205
|
};
|
|
206
|
+
__name(_Message, "Message");
|
|
207
|
+
var Message = _Message;
|
|
190
208
|
|
|
191
209
|
// packages/dts-plugin/src/server/message/API/API.ts
|
|
192
|
-
var
|
|
210
|
+
var APIKind;
|
|
211
|
+
(function(APIKind2) {
|
|
212
|
+
APIKind2["UPDATE_SUBSCRIBER"] = "UPDATE_SUBSCRIBER";
|
|
213
|
+
APIKind2["RELOAD_WEB_CLIENT"] = "RELOAD_WEB_CLIENT";
|
|
214
|
+
APIKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
215
|
+
})(APIKind || (APIKind = {}));
|
|
216
|
+
var _API = class _API extends Message {
|
|
193
217
|
constructor(content, kind) {
|
|
194
218
|
super("API", kind);
|
|
219
|
+
__publicField(this, "code");
|
|
220
|
+
__publicField(this, "payload");
|
|
195
221
|
const { code, payload } = content;
|
|
196
222
|
this.code = code;
|
|
197
223
|
this.payload = payload;
|
|
198
224
|
}
|
|
199
225
|
};
|
|
226
|
+
__name(_API, "API");
|
|
227
|
+
var API = _API;
|
|
200
228
|
|
|
201
229
|
// packages/dts-plugin/src/server/message/API/UpdateSubscriber.ts
|
|
202
|
-
var
|
|
230
|
+
var _UpdateSubscriberAPI = class _UpdateSubscriberAPI extends API {
|
|
203
231
|
constructor(payload) {
|
|
204
|
-
super(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
},
|
|
209
|
-
"UPDATE_SUBSCRIBER" /* UPDATE_SUBSCRIBER */
|
|
210
|
-
);
|
|
232
|
+
super({
|
|
233
|
+
code: 0,
|
|
234
|
+
payload
|
|
235
|
+
}, APIKind.UPDATE_SUBSCRIBER);
|
|
211
236
|
}
|
|
212
237
|
};
|
|
238
|
+
__name(_UpdateSubscriberAPI, "UpdateSubscriberAPI");
|
|
239
|
+
var UpdateSubscriberAPI = _UpdateSubscriberAPI;
|
|
213
240
|
|
|
214
241
|
// packages/dts-plugin/src/server/message/API/ReloadWebClient.ts
|
|
215
|
-
var
|
|
242
|
+
var _ReloadWebClientAPI = class _ReloadWebClientAPI extends API {
|
|
216
243
|
constructor(payload) {
|
|
217
|
-
super(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
244
|
+
super({
|
|
245
|
+
code: 0,
|
|
246
|
+
payload
|
|
247
|
+
}, APIKind.RELOAD_WEB_CLIENT);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
__name(_ReloadWebClientAPI, "ReloadWebClientAPI");
|
|
251
|
+
var ReloadWebClientAPI = _ReloadWebClientAPI;
|
|
252
|
+
|
|
253
|
+
// packages/dts-plugin/src/server/message/API/FetchTypes.ts
|
|
254
|
+
var _FetchTypesAPI = class _FetchTypesAPI extends API {
|
|
255
|
+
constructor(payload) {
|
|
256
|
+
super({
|
|
257
|
+
code: 0,
|
|
258
|
+
payload
|
|
259
|
+
}, APIKind.FETCH_TYPES);
|
|
224
260
|
}
|
|
225
261
|
};
|
|
262
|
+
__name(_FetchTypesAPI, "FetchTypesAPI");
|
|
263
|
+
var FetchTypesAPI = _FetchTypesAPI;
|
|
226
264
|
|
|
227
265
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
228
266
|
var import_sdk2 = require("@module-federation/sdk");
|
|
@@ -231,21 +269,37 @@ var import_sdk2 = require("@module-federation/sdk");
|
|
|
231
269
|
var import_chalk = __toESM(require("chalk"));
|
|
232
270
|
|
|
233
271
|
// packages/dts-plugin/src/server/message/Log/Log.ts
|
|
234
|
-
var
|
|
272
|
+
var LogLevel;
|
|
273
|
+
(function(LogLevel2) {
|
|
274
|
+
LogLevel2["LOG"] = "LOG";
|
|
275
|
+
LogLevel2["WARN"] = "WARN";
|
|
276
|
+
LogLevel2["ERROR"] = "ERROR";
|
|
277
|
+
})(LogLevel || (LogLevel = {}));
|
|
278
|
+
var LogKind;
|
|
279
|
+
(function(LogKind2) {
|
|
280
|
+
LogKind2["BrokerExitLog"] = "BrokerExitLog";
|
|
281
|
+
LogKind2["PublisherRegisteredLog"] = "PublisherRegisteredLog";
|
|
282
|
+
})(LogKind || (LogKind = {}));
|
|
283
|
+
var _Log = class _Log extends Message {
|
|
235
284
|
constructor(level, kind, ignoreVerbose = false) {
|
|
236
285
|
super("Log", kind);
|
|
237
|
-
this
|
|
286
|
+
__publicField(this, "level");
|
|
287
|
+
__publicField(this, "ignoreVerbose", false);
|
|
238
288
|
this.level = level;
|
|
239
289
|
this.ignoreVerbose = ignoreVerbose;
|
|
240
290
|
}
|
|
241
291
|
};
|
|
292
|
+
__name(_Log, "Log");
|
|
293
|
+
var Log = _Log;
|
|
242
294
|
|
|
243
295
|
// packages/dts-plugin/src/server/message/Log/BrokerExitLog.ts
|
|
244
|
-
var
|
|
296
|
+
var _BrokerExitLog = class _BrokerExitLog extends Log {
|
|
245
297
|
constructor() {
|
|
246
|
-
super(
|
|
298
|
+
super(LogLevel.LOG, LogKind.BrokerExitLog);
|
|
247
299
|
}
|
|
248
300
|
};
|
|
301
|
+
__name(_BrokerExitLog, "BrokerExitLog");
|
|
302
|
+
var BrokerExitLog = _BrokerExitLog;
|
|
249
303
|
|
|
250
304
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
251
305
|
var import_sdk = require("@module-federation/sdk");
|
|
@@ -259,43 +313,98 @@ var WEB_CLIENT_OPTIONS_IDENTIFIER = "__WEB_CLIENT_OPTIONS__";
|
|
|
259
313
|
|
|
260
314
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
261
315
|
function fileLog(msg, module2, level) {
|
|
262
|
-
var
|
|
263
|
-
if (!((
|
|
316
|
+
var _a4, _b;
|
|
317
|
+
if (!((_a4 = process == null ? void 0 : process.env) == null ? void 0 : _a4["FEDERATION_DEBUG"])) {
|
|
264
318
|
return;
|
|
265
319
|
}
|
|
266
320
|
log4js.configure({
|
|
267
321
|
appenders: {
|
|
268
|
-
[module2]: {
|
|
269
|
-
|
|
322
|
+
[module2]: {
|
|
323
|
+
type: "file",
|
|
324
|
+
filename: ".mf/typesGenerate.log"
|
|
325
|
+
},
|
|
326
|
+
default: {
|
|
327
|
+
type: "file",
|
|
328
|
+
filename: ".mf/typesGenerate.log"
|
|
329
|
+
}
|
|
270
330
|
},
|
|
271
331
|
categories: {
|
|
272
|
-
[module2]: {
|
|
273
|
-
|
|
332
|
+
[module2]: {
|
|
333
|
+
appenders: [
|
|
334
|
+
module2
|
|
335
|
+
],
|
|
336
|
+
level: "error"
|
|
337
|
+
},
|
|
338
|
+
default: {
|
|
339
|
+
appenders: [
|
|
340
|
+
"default"
|
|
341
|
+
],
|
|
342
|
+
level: "trace"
|
|
343
|
+
}
|
|
274
344
|
}
|
|
275
345
|
});
|
|
276
346
|
const logger4 = log4js.getLogger(module2);
|
|
277
347
|
logger4.level = "debug";
|
|
278
348
|
(_b = logger4[level]) == null ? void 0 : _b.call(logger4, msg);
|
|
279
349
|
}
|
|
350
|
+
__name(fileLog, "fileLog");
|
|
280
351
|
function error(error2, action, from) {
|
|
281
352
|
const err = error2 instanceof Error ? error2 : new Error(`${action} error`);
|
|
282
353
|
fileLog(`[${action}] error: ${err}`, from, "fatal");
|
|
283
354
|
return err.toString();
|
|
284
355
|
}
|
|
356
|
+
__name(error, "error");
|
|
357
|
+
|
|
358
|
+
// packages/dts-plugin/src/server/utils/getIPV4.ts
|
|
359
|
+
var import_os = __toESM(require("os"));
|
|
360
|
+
var localIpv4 = "127.0.0.1";
|
|
361
|
+
var getIpv4Interfaces = /* @__PURE__ */ __name(() => {
|
|
362
|
+
try {
|
|
363
|
+
const interfaces = import_os.default.networkInterfaces();
|
|
364
|
+
const ipv4Interfaces = [];
|
|
365
|
+
Object.values(interfaces).forEach((detail) => {
|
|
366
|
+
detail == null ? void 0 : detail.forEach((detail2) => {
|
|
367
|
+
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
368
|
+
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
369
|
+
ipv4Interfaces.push(detail2);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
return ipv4Interfaces;
|
|
374
|
+
} catch (_err) {
|
|
375
|
+
return [];
|
|
376
|
+
}
|
|
377
|
+
}, "getIpv4Interfaces");
|
|
378
|
+
var getIPV4 = /* @__PURE__ */ __name(() => {
|
|
379
|
+
const ipv4Interfaces = getIpv4Interfaces();
|
|
380
|
+
const ipv4Interface = ipv4Interfaces[0] || {
|
|
381
|
+
address: localIpv4
|
|
382
|
+
};
|
|
383
|
+
return ipv4Interface.address;
|
|
384
|
+
}, "getIPV4");
|
|
285
385
|
|
|
286
386
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
287
387
|
function getIdentifier(options) {
|
|
288
388
|
const { ip, name } = options;
|
|
289
389
|
return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
|
|
290
390
|
}
|
|
391
|
+
__name(getIdentifier, "getIdentifier");
|
|
291
392
|
|
|
292
393
|
// packages/dts-plugin/src/server/Publisher.ts
|
|
293
|
-
var
|
|
394
|
+
var _Publisher = class _Publisher {
|
|
294
395
|
constructor(ctx) {
|
|
396
|
+
__publicField(this, "_ip");
|
|
397
|
+
__publicField(this, "_name");
|
|
398
|
+
__publicField(this, "_remoteTypeTarPath");
|
|
399
|
+
__publicField(this, "_subscribers");
|
|
400
|
+
__publicField(this, "_ws");
|
|
401
|
+
__publicField(this, "dynamicRemoteMap");
|
|
295
402
|
this._name = ctx.name;
|
|
296
403
|
this._ip = ctx.ip;
|
|
297
404
|
this._remoteTypeTarPath = ctx.remoteTypeTarPath;
|
|
298
405
|
this._subscribers = /* @__PURE__ */ new Map();
|
|
406
|
+
this._ws = ctx.ws;
|
|
407
|
+
this.dynamicRemoteMap = /* @__PURE__ */ new Map();
|
|
299
408
|
}
|
|
300
409
|
get identifier() {
|
|
301
410
|
return getIdentifier({
|
|
@@ -324,33 +433,27 @@ var Publisher = class {
|
|
|
324
433
|
}
|
|
325
434
|
removeSubscriber(identifier) {
|
|
326
435
|
if (this._subscribers.has(identifier)) {
|
|
327
|
-
fileLog(
|
|
328
|
-
`${this.name} removeSubscriber: ${identifier}`,
|
|
329
|
-
"Publisher",
|
|
330
|
-
"warn"
|
|
331
|
-
);
|
|
436
|
+
fileLog(`${this.name} removeSubscriber: ${identifier}`, "Publisher", "warn");
|
|
332
437
|
this._subscribers.delete(identifier);
|
|
333
438
|
}
|
|
334
439
|
}
|
|
335
440
|
notifySubscriber(subscriberIdentifier, options) {
|
|
336
441
|
const subscriber = this._subscribers.get(subscriberIdentifier);
|
|
337
442
|
if (!subscriber) {
|
|
338
|
-
fileLog(
|
|
339
|
-
`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`,
|
|
340
|
-
"Publisher",
|
|
341
|
-
"error"
|
|
342
|
-
);
|
|
443
|
+
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${subscriberIdentifier}, does not exits`, "Publisher", "error");
|
|
343
444
|
return;
|
|
344
445
|
}
|
|
345
446
|
const api = new UpdateSubscriberAPI(options);
|
|
346
447
|
subscriber.send(JSON.stringify(api));
|
|
347
|
-
fileLog(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
448
|
+
fileLog(`[notifySubscriber] ${this.name} notifySubscriber: ${JSON.stringify(subscriberIdentifier)}, message: ${JSON.stringify(api)}`, "Publisher", "info");
|
|
449
|
+
}
|
|
450
|
+
fetchRemoteTypes(options) {
|
|
451
|
+
fileLog(`[fetchRemoteTypes] ${this.name} fetchRemoteTypes, options: ${JSON.stringify(options)}, ws: ${Boolean(this._ws)}`, "Publisher", "info");
|
|
452
|
+
if (!this._ws) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const api = new FetchTypesAPI(options);
|
|
456
|
+
this._ws.send(JSON.stringify(api));
|
|
354
457
|
}
|
|
355
458
|
notifySubscribers(options) {
|
|
356
459
|
const api = new UpdateSubscriberAPI(options);
|
|
@@ -359,32 +462,23 @@ var Publisher = class {
|
|
|
359
462
|
broadcast(message) {
|
|
360
463
|
if (this.hasSubscribes) {
|
|
361
464
|
this._subscribers.forEach((subscriber, key) => {
|
|
362
|
-
fileLog(
|
|
363
|
-
`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`,
|
|
364
|
-
"Publisher",
|
|
365
|
-
"info"
|
|
366
|
-
);
|
|
465
|
+
fileLog(`[BroadCast] ${this.name} notifySubscriber: ${key}, PID: ${process.pid}, message: ${JSON.stringify(message)}`, "Publisher", "info");
|
|
367
466
|
subscriber.send(JSON.stringify(message));
|
|
368
467
|
});
|
|
369
468
|
} else {
|
|
370
|
-
fileLog(
|
|
371
|
-
`[BroadCast] ${this.name}'s subscribe is empty`,
|
|
372
|
-
"Publisher",
|
|
373
|
-
"warn"
|
|
374
|
-
);
|
|
469
|
+
fileLog(`[BroadCast] ${this.name}'s subscribe is empty`, "Publisher", "warn");
|
|
375
470
|
}
|
|
376
471
|
}
|
|
377
472
|
close() {
|
|
473
|
+
this._ws = void 0;
|
|
378
474
|
this._subscribers.forEach((_subscriber, identifier) => {
|
|
379
|
-
fileLog(
|
|
380
|
-
`[BroadCast] close ${this.name} remove: ${identifier}`,
|
|
381
|
-
"Publisher",
|
|
382
|
-
"warn"
|
|
383
|
-
);
|
|
475
|
+
fileLog(`[BroadCast] close ${this.name} remove: ${identifier}`, "Publisher", "warn");
|
|
384
476
|
this.removeSubscriber(identifier);
|
|
385
477
|
});
|
|
386
478
|
}
|
|
387
479
|
};
|
|
480
|
+
__name(_Publisher, "Publisher");
|
|
481
|
+
var Publisher = _Publisher;
|
|
388
482
|
|
|
389
483
|
// packages/dts-plugin/src/server/DevServer.ts
|
|
390
484
|
var import_isomorphic_ws2 = __toESM(require("isomorphic-ws"));
|
|
@@ -394,13 +488,48 @@ var import_http = require("http");
|
|
|
394
488
|
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
395
489
|
var import_node_schedule = __toESM(require("node-schedule"));
|
|
396
490
|
var import_url = require("url");
|
|
491
|
+
|
|
492
|
+
// packages/dts-plugin/src/server/message/Action/Action.ts
|
|
493
|
+
var ActionKind;
|
|
494
|
+
(function(ActionKind2) {
|
|
495
|
+
ActionKind2["ADD_SUBSCRIBER"] = "ADD_SUBSCRIBER";
|
|
496
|
+
ActionKind2["EXIT_SUBSCRIBER"] = "EXIT_SUBSCRIBER";
|
|
497
|
+
ActionKind2["ADD_PUBLISHER"] = "ADD_PUBLISHER";
|
|
498
|
+
ActionKind2["UPDATE_PUBLISHER"] = "UPDATE_PUBLISHER";
|
|
499
|
+
ActionKind2["NOTIFY_SUBSCRIBER"] = "NOTIFY_SUBSCRIBER";
|
|
500
|
+
ActionKind2["EXIT_PUBLISHER"] = "EXIT_PUBLISHER";
|
|
501
|
+
ActionKind2["ADD_WEB_CLIENT"] = "ADD_WEB_CLIENT";
|
|
502
|
+
ActionKind2["NOTIFY_WEB_CLIENT"] = "NOTIFY_WEB_CLIENT";
|
|
503
|
+
ActionKind2["FETCH_TYPES"] = "FETCH_TYPES";
|
|
504
|
+
ActionKind2["ADD_DYNAMIC_REMOTE"] = "ADD_DYNAMIC_REMOTE";
|
|
505
|
+
})(ActionKind || (ActionKind = {}));
|
|
506
|
+
|
|
507
|
+
// packages/dts-plugin/src/server/message/Action/Update.ts
|
|
508
|
+
var UpdateKind;
|
|
509
|
+
(function(UpdateKind2) {
|
|
510
|
+
UpdateKind2["UPDATE_TYPE"] = "UPDATE_TYPE";
|
|
511
|
+
UpdateKind2["RELOAD_PAGE"] = "RELOAD_PAGE";
|
|
512
|
+
})(UpdateKind || (UpdateKind = {}));
|
|
513
|
+
|
|
514
|
+
// packages/dts-plugin/src/core/constant.ts
|
|
515
|
+
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
516
|
+
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
517
|
+
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
518
|
+
var UpdateMode;
|
|
519
|
+
(function(UpdateMode2) {
|
|
520
|
+
UpdateMode2["POSITIVE"] = "POSITIVE";
|
|
521
|
+
UpdateMode2["PASSIVE"] = "PASSIVE";
|
|
522
|
+
})(UpdateMode || (UpdateMode = {}));
|
|
523
|
+
|
|
524
|
+
// packages/dts-plugin/src/server/broker/Broker.ts
|
|
397
525
|
var _Broker = class _Broker {
|
|
398
526
|
constructor() {
|
|
399
|
-
|
|
400
|
-
this
|
|
401
|
-
this
|
|
402
|
-
this
|
|
403
|
-
this
|
|
527
|
+
__publicField(this, "_publisherMap", /* @__PURE__ */ new Map());
|
|
528
|
+
__publicField(this, "_webClientMap", /* @__PURE__ */ new Map());
|
|
529
|
+
__publicField(this, "_webSocketServer");
|
|
530
|
+
__publicField(this, "_secureWebSocketServer");
|
|
531
|
+
__publicField(this, "_tmpSubscriberShelter", /* @__PURE__ */ new Map());
|
|
532
|
+
__publicField(this, "_scheduleJob", null);
|
|
404
533
|
this._setSchedule();
|
|
405
534
|
this._startWsServer();
|
|
406
535
|
this._stopWhenSIGTERMOrSIGINT();
|
|
@@ -409,389 +538,407 @@ var _Broker = class _Broker {
|
|
|
409
538
|
get hasPublishers() {
|
|
410
539
|
return Boolean(this._publisherMap.size);
|
|
411
540
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
541
|
+
_startWsServer() {
|
|
542
|
+
return __async(this, null, function* () {
|
|
543
|
+
const wsHandler = /* @__PURE__ */ __name((ws, req) => {
|
|
544
|
+
const { url: reqUrl = "" } = req;
|
|
545
|
+
const { query } = (0, import_url.parse)(reqUrl, true);
|
|
546
|
+
const { WEB_SOCKET_CONNECT_MAGIC_ID: WEB_SOCKET_CONNECT_MAGIC_ID2 } = query;
|
|
547
|
+
if (WEB_SOCKET_CONNECT_MAGIC_ID2 === _Broker.WEB_SOCKET_CONNECT_MAGIC_ID) {
|
|
548
|
+
ws.on("message", (message) => {
|
|
549
|
+
try {
|
|
550
|
+
const text = message.toString();
|
|
551
|
+
const action = JSON.parse(text);
|
|
552
|
+
fileLog(`${action == null ? void 0 : action.kind} action received `, "Broker", "info");
|
|
553
|
+
this._takeAction(action, ws);
|
|
554
|
+
} catch (error2) {
|
|
555
|
+
fileLog(`parse action message error: ${error2}`, "Broker", "error");
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
ws.on("error", (e) => {
|
|
559
|
+
fileLog(`parse action message error: ${e}`, "Broker", "error");
|
|
560
|
+
});
|
|
561
|
+
} else {
|
|
562
|
+
ws.send("Invalid CONNECT ID.");
|
|
563
|
+
fileLog("Invalid CONNECT ID.", "Broker", "warn");
|
|
564
|
+
ws.close();
|
|
565
|
+
}
|
|
566
|
+
}, "wsHandler");
|
|
567
|
+
const server = (0, import_http.createServer)();
|
|
568
|
+
this._webSocketServer = new import_isomorphic_ws.default.Server({
|
|
569
|
+
noServer: true
|
|
570
|
+
});
|
|
571
|
+
this._webSocketServer.on("error", (err) => {
|
|
572
|
+
fileLog(`ws error:
|
|
441
573
|
${err.message}
|
|
442
574
|
${err.stack}`, "Broker", "error");
|
|
575
|
+
});
|
|
576
|
+
this._webSocketServer.on("listening", () => {
|
|
577
|
+
fileLog(`WebSocket server is listening on port ${_Broker.DEFAULT_WEB_SOCKET_PORT}`, "Broker", "info");
|
|
578
|
+
});
|
|
579
|
+
this._webSocketServer.on("connection", wsHandler);
|
|
580
|
+
this._webSocketServer.on("close", (code) => {
|
|
581
|
+
fileLog(`WebSocket Server Close with Code ${code}`, "Broker", "warn");
|
|
582
|
+
this._webSocketServer && this._webSocketServer.close();
|
|
583
|
+
this._webSocketServer = void 0;
|
|
584
|
+
});
|
|
585
|
+
server.on("upgrade", (req, socket, head) => {
|
|
586
|
+
var _a4;
|
|
587
|
+
if (req.url) {
|
|
588
|
+
const { pathname } = (0, import_url.parse)(req.url);
|
|
589
|
+
if (pathname === "/") {
|
|
590
|
+
(_a4 = this._webSocketServer) == null ? void 0 : _a4.handleUpgrade(req, socket, head, (ws) => {
|
|
591
|
+
var _a5;
|
|
592
|
+
(_a5 = this._webSocketServer) == null ? void 0 : _a5.emit("connection", ws, req);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
443
598
|
});
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
599
|
+
}
|
|
600
|
+
_takeAction(action, client) {
|
|
601
|
+
return __async(this, null, function* () {
|
|
602
|
+
const { kind, payload } = action;
|
|
603
|
+
if (kind === ActionKind.ADD_PUBLISHER) {
|
|
604
|
+
yield this._addPublisher(payload, client);
|
|
605
|
+
}
|
|
606
|
+
if (kind === ActionKind.UPDATE_PUBLISHER) {
|
|
607
|
+
yield this._updatePublisher(payload, client);
|
|
608
|
+
}
|
|
609
|
+
if (kind === ActionKind.ADD_SUBSCRIBER) {
|
|
610
|
+
yield this._addSubscriber(payload, client);
|
|
611
|
+
}
|
|
612
|
+
if (kind === ActionKind.EXIT_SUBSCRIBER) {
|
|
613
|
+
yield this._removeSubscriber(payload, client);
|
|
614
|
+
}
|
|
615
|
+
if (kind === ActionKind.EXIT_PUBLISHER) {
|
|
616
|
+
yield this._removePublisher(payload, client);
|
|
617
|
+
}
|
|
618
|
+
if (kind === ActionKind.ADD_WEB_CLIENT) {
|
|
619
|
+
yield this._addWebClient(payload, client);
|
|
620
|
+
}
|
|
621
|
+
if (kind === ActionKind.NOTIFY_WEB_CLIENT) {
|
|
622
|
+
yield this._notifyWebClient(payload, client);
|
|
623
|
+
}
|
|
624
|
+
if (kind === ActionKind.FETCH_TYPES) {
|
|
625
|
+
yield this._fetchTypes(payload, client);
|
|
626
|
+
}
|
|
627
|
+
if (kind === ActionKind.ADD_DYNAMIC_REMOTE) {
|
|
628
|
+
this._addDynamicRemote(payload);
|
|
629
|
+
}
|
|
456
630
|
});
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
631
|
+
}
|
|
632
|
+
_addPublisher(context, client) {
|
|
633
|
+
return __async(this, null, function* () {
|
|
634
|
+
const { name, ip, remoteTypeTarPath } = context != null ? context : {};
|
|
635
|
+
const identifier = getIdentifier({
|
|
636
|
+
name,
|
|
637
|
+
ip
|
|
638
|
+
});
|
|
639
|
+
if (this._publisherMap.has(identifier)) {
|
|
640
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} has been added, this action will be ignored`, "Broker", "warn");
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
try {
|
|
644
|
+
const publisher = new Publisher({
|
|
645
|
+
name,
|
|
646
|
+
ip,
|
|
647
|
+
remoteTypeTarPath,
|
|
648
|
+
ws: client
|
|
649
|
+
});
|
|
650
|
+
this._publisherMap.set(identifier, publisher);
|
|
651
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] ${identifier} Adding Publisher Succeed`, "Broker", "info");
|
|
652
|
+
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
653
|
+
if (tmpSubScribers) {
|
|
654
|
+
fileLog(`[${ActionKind.ADD_PUBLISHER}] consumeTmpSubscriber set ${publisher.name}\u2019s subscribers `, "Broker", "info");
|
|
655
|
+
this._consumeTmpSubScribers(publisher, tmpSubScribers);
|
|
656
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
466
657
|
}
|
|
658
|
+
} catch (err) {
|
|
659
|
+
const msg = error(err, ActionKind.ADD_PUBLISHER, "Broker");
|
|
660
|
+
client.send(msg);
|
|
661
|
+
client.close();
|
|
467
662
|
}
|
|
468
663
|
});
|
|
469
|
-
server.listen(_Broker.DEFAULT_WEB_SOCKET_PORT);
|
|
470
664
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
await this._removeSubscriber(
|
|
487
|
-
payload,
|
|
488
|
-
client
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
if (kind === "EXIT_PUBLISHER" /* EXIT_PUBLISHER */) {
|
|
492
|
-
await this._removePublisher(payload, client);
|
|
493
|
-
}
|
|
494
|
-
if (kind === "ADD_WEB_CLIENT" /* ADD_WEB_CLIENT */) {
|
|
495
|
-
await this._addWebClient(payload, client);
|
|
496
|
-
}
|
|
497
|
-
if (kind === "NOTIFY_WEB_CLIENT" /* NOTIFY_WEB_CLIENT */) {
|
|
498
|
-
await this._notifyWebClient(
|
|
499
|
-
payload,
|
|
500
|
-
client
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
async _addPublisher(context, client) {
|
|
505
|
-
const { name, ip, remoteTypeTarPath } = context ?? {};
|
|
506
|
-
const identifier = getIdentifier({ name, ip });
|
|
507
|
-
if (this._publisherMap.has(identifier)) {
|
|
508
|
-
fileLog(
|
|
509
|
-
`[${"ADD_PUBLISHER" /* ADD_PUBLISHER */}] ${identifier} has been added, this action will be ignored`,
|
|
510
|
-
"Broker",
|
|
511
|
-
"warn"
|
|
512
|
-
);
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
try {
|
|
516
|
-
const publisher = new Publisher({ name, ip, remoteTypeTarPath });
|
|
517
|
-
this._publisherMap.set(identifier, publisher);
|
|
518
|
-
fileLog(
|
|
519
|
-
`[${"ADD_PUBLISHER" /* ADD_PUBLISHER */}] ${identifier} Adding Publisher Succeed`,
|
|
520
|
-
"Broker",
|
|
521
|
-
"info"
|
|
522
|
-
);
|
|
523
|
-
const tmpSubScribers = this._getTmpSubScribers(identifier);
|
|
524
|
-
if (tmpSubScribers) {
|
|
665
|
+
_updatePublisher(context, client) {
|
|
666
|
+
return __async(this, null, function* () {
|
|
667
|
+
const { name, updateMode, updateKind, updateSourcePaths, remoteTypeTarPath, ip } = context != null ? context : {};
|
|
668
|
+
const identifier = getIdentifier({
|
|
669
|
+
name,
|
|
670
|
+
ip
|
|
671
|
+
});
|
|
672
|
+
if (!this._publisherMap.has(identifier)) {
|
|
673
|
+
fileLog(`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} has not been started, this action will be ignored
|
|
674
|
+
this._publisherMap: ${JSON.stringify(this._publisherMap.entries())}
|
|
675
|
+
`, "Broker", "warn");
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
try {
|
|
679
|
+
const publisher = this._publisherMap.get(identifier);
|
|
525
680
|
fileLog(
|
|
526
|
-
|
|
681
|
+
// eslint-disable-next-line max-len
|
|
682
|
+
`[${ActionKind.UPDATE_PUBLISHER}] ${identifier} update, and notify subscribers to update`,
|
|
527
683
|
"Broker",
|
|
528
684
|
"info"
|
|
529
685
|
);
|
|
530
|
-
|
|
531
|
-
|
|
686
|
+
if (publisher) {
|
|
687
|
+
publisher.notifySubscribers({
|
|
688
|
+
remoteTypeTarPath,
|
|
689
|
+
name,
|
|
690
|
+
updateMode,
|
|
691
|
+
updateKind,
|
|
692
|
+
updateSourcePaths: updateSourcePaths || []
|
|
693
|
+
});
|
|
694
|
+
this._publisherMap.forEach((p) => {
|
|
695
|
+
if (p.name === publisher.name) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const dynamicRemoteInfo = p.dynamicRemoteMap.get(identifier);
|
|
699
|
+
if (dynamicRemoteInfo) {
|
|
700
|
+
fileLog(
|
|
701
|
+
// eslint-disable-next-line max-len
|
|
702
|
+
`dynamicRemoteInfo: ${JSON.stringify(dynamicRemoteInfo)}, identifier:${identifier} publish: ${p.name}`,
|
|
703
|
+
"Broker",
|
|
704
|
+
"info"
|
|
705
|
+
);
|
|
706
|
+
p.fetchRemoteTypes({
|
|
707
|
+
remoteInfo: dynamicRemoteInfo,
|
|
708
|
+
once: false
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
} catch (err) {
|
|
714
|
+
const msg = error(err, ActionKind.UPDATE_PUBLISHER, "Broker");
|
|
715
|
+
client.send(msg);
|
|
716
|
+
client.close();
|
|
532
717
|
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
_fetchTypes(context, _client) {
|
|
721
|
+
return __async(this, null, function* () {
|
|
722
|
+
const { name, ip, remoteInfo } = context != null ? context : {};
|
|
723
|
+
const identifier = getIdentifier({
|
|
724
|
+
name,
|
|
725
|
+
ip
|
|
726
|
+
});
|
|
727
|
+
try {
|
|
728
|
+
const publisher = this._publisherMap.get(identifier);
|
|
729
|
+
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types`, "Broker", "info");
|
|
730
|
+
if (publisher) {
|
|
731
|
+
publisher.fetchRemoteTypes({
|
|
732
|
+
remoteInfo,
|
|
733
|
+
once: true
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
} catch (err) {
|
|
737
|
+
fileLog(`[${ActionKind.FETCH_TYPES}] ${identifier} fetch types fail , error info: ${err}`, "Broker", "error");
|
|
738
|
+
}
|
|
739
|
+
});
|
|
538
740
|
}
|
|
539
|
-
|
|
540
|
-
const {
|
|
741
|
+
_addDynamicRemote(context) {
|
|
742
|
+
const { name, ip, remoteInfo, remoteIp } = context != null ? context : {};
|
|
743
|
+
const identifier = getIdentifier({
|
|
541
744
|
name,
|
|
542
|
-
updateMode,
|
|
543
|
-
updateKind,
|
|
544
|
-
updateSourcePaths,
|
|
545
|
-
remoteTypeTarPath,
|
|
546
745
|
ip
|
|
547
|
-
}
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
"warn"
|
|
556
|
-
);
|
|
746
|
+
});
|
|
747
|
+
const publisher = this._publisherMap.get(identifier);
|
|
748
|
+
const remoteId = getIdentifier({
|
|
749
|
+
name: remoteInfo.name,
|
|
750
|
+
ip: remoteIp
|
|
751
|
+
});
|
|
752
|
+
fileLog(`[${ActionKind.ADD_DYNAMIC_REMOTE}] identifier:${identifier},publisher: ${publisher.name}, remoteId:${remoteId}`, "Broker", "error");
|
|
753
|
+
if (!publisher || publisher.dynamicRemoteMap.has(remoteId)) {
|
|
557
754
|
return;
|
|
558
755
|
}
|
|
559
|
-
|
|
560
|
-
const publisher = this._publisherMap.get(identifier);
|
|
561
|
-
fileLog(
|
|
562
|
-
// eslint-disable-next-line max-len
|
|
563
|
-
`[${"UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */}] ${identifier} update, and notify subscribers to update`,
|
|
564
|
-
"Broker",
|
|
565
|
-
"info"
|
|
566
|
-
);
|
|
567
|
-
if (publisher) {
|
|
568
|
-
publisher.notifySubscribers({
|
|
569
|
-
remoteTypeTarPath,
|
|
570
|
-
name,
|
|
571
|
-
updateMode,
|
|
572
|
-
updateKind,
|
|
573
|
-
updateSourcePaths: updateSourcePaths || []
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
} catch (err) {
|
|
577
|
-
const msg = error(err, "UPDATE_PUBLISHER" /* UPDATE_PUBLISHER */, "Broker");
|
|
578
|
-
client.send(msg);
|
|
579
|
-
client.close();
|
|
580
|
-
}
|
|
756
|
+
publisher.dynamicRemoteMap.set(remoteId, remoteInfo);
|
|
581
757
|
}
|
|
582
758
|
// app1 consumes provider1,provider2. Dependencies at this time: publishers: [provider1, provider2], subscriberName: app1
|
|
583
759
|
// provider1 is app1's remote
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
{
|
|
760
|
+
_addSubscriber(context, client) {
|
|
761
|
+
return __async(this, null, function* () {
|
|
762
|
+
const { publishers, name: subscriberName } = context != null ? context : {};
|
|
763
|
+
publishers.forEach((publisher) => {
|
|
764
|
+
const { name, ip } = publisher;
|
|
765
|
+
const identifier = getIdentifier({
|
|
766
|
+
name,
|
|
767
|
+
ip
|
|
768
|
+
});
|
|
769
|
+
if (!this._publisherMap.has(identifier)) {
|
|
770
|
+
fileLog(`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has not been started, ${subscriberName} will add the relation to tmp shelter`, "Broker", "warn");
|
|
771
|
+
this._addTmpSubScriberRelation({
|
|
597
772
|
name: getIdentifier({
|
|
598
773
|
name: context.name,
|
|
599
774
|
ip: context.ip
|
|
600
775
|
}),
|
|
601
776
|
client
|
|
602
|
-
},
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
if (registeredPublisher) {
|
|
610
|
-
registeredPublisher.addSubscriber(
|
|
611
|
-
getIdentifier({
|
|
777
|
+
}, publisher);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
try {
|
|
781
|
+
const registeredPublisher = this._publisherMap.get(identifier);
|
|
782
|
+
if (registeredPublisher) {
|
|
783
|
+
registeredPublisher.addSubscriber(getIdentifier({
|
|
612
784
|
name: subscriberName,
|
|
613
785
|
ip: context.ip
|
|
614
|
-
}),
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
"Broker",
|
|
623
|
-
"info"
|
|
624
|
-
);
|
|
625
|
-
registeredPublisher.notifySubscriber(
|
|
626
|
-
getIdentifier({
|
|
786
|
+
}), client);
|
|
787
|
+
fileLog(
|
|
788
|
+
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
789
|
+
`[${ActionKind.ADD_SUBSCRIBER}]: ${identifier} has been started, Adding Subscriber ${subscriberName} Succeed, this.__publisherMap are: ${JSON.stringify(Array.from(this._publisherMap.entries()))}`,
|
|
790
|
+
"Broker",
|
|
791
|
+
"info"
|
|
792
|
+
);
|
|
793
|
+
registeredPublisher.notifySubscriber(getIdentifier({
|
|
627
794
|
name: subscriberName,
|
|
628
795
|
ip: context.ip
|
|
629
|
-
}),
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
796
|
+
}), {
|
|
797
|
+
updateKind: UpdateKind.UPDATE_TYPE,
|
|
798
|
+
updateMode: UpdateMode.PASSIVE,
|
|
799
|
+
updateSourcePaths: [
|
|
800
|
+
registeredPublisher.name
|
|
801
|
+
],
|
|
634
802
|
remoteTypeTarPath: registeredPublisher.remoteTypeTarPath,
|
|
635
803
|
name: registeredPublisher.name
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
804
|
+
});
|
|
805
|
+
fileLog(
|
|
806
|
+
// eslint-disable-next-line @ies/eden/max-calls-in-template
|
|
807
|
+
`[${ActionKind.ADD_SUBSCRIBER}]: notifySubscriber Subscriber ${subscriberName}, updateMode: "PASSIVE", updateSourcePaths: ${registeredPublisher.name}`,
|
|
808
|
+
"Broker",
|
|
809
|
+
"info"
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
} catch (err) {
|
|
813
|
+
const msg = error(err, ActionKind.ADD_SUBSCRIBER, "Broker");
|
|
814
|
+
client.send(msg);
|
|
815
|
+
client.close();
|
|
644
816
|
}
|
|
645
|
-
}
|
|
646
|
-
const msg = error(err, "ADD_SUBSCRIBER" /* ADD_SUBSCRIBER */, "Broker");
|
|
647
|
-
client.send(msg);
|
|
648
|
-
client.close();
|
|
649
|
-
}
|
|
817
|
+
});
|
|
650
818
|
});
|
|
651
819
|
}
|
|
652
820
|
// Trigger while consumer exit
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
821
|
+
_removeSubscriber(context, client) {
|
|
822
|
+
return __async(this, null, function* () {
|
|
823
|
+
const { publishers } = context != null ? context : {};
|
|
824
|
+
const subscriberIdentifier = getIdentifier({
|
|
825
|
+
name: context == null ? void 0 : context.name,
|
|
826
|
+
ip: context == null ? void 0 : context.ip
|
|
827
|
+
});
|
|
828
|
+
publishers.forEach((publisher) => {
|
|
829
|
+
const { name, ip } = publisher;
|
|
830
|
+
const identifier = getIdentifier({
|
|
831
|
+
name,
|
|
832
|
+
ip
|
|
833
|
+
});
|
|
834
|
+
const registeredPublisher = this._publisherMap.get(identifier);
|
|
835
|
+
if (!registeredPublisher) {
|
|
836
|
+
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} does not exit `, "Broker", "warn");
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
try {
|
|
840
|
+
fileLog(`[${ActionKind.EXIT_SUBSCRIBER}], ${identifier} will exit `, "Broker", "INFO");
|
|
841
|
+
registeredPublisher.removeSubscriber(subscriberIdentifier);
|
|
842
|
+
this._clearTmpSubScriberRelation(identifier);
|
|
843
|
+
if (!registeredPublisher.hasSubscribes) {
|
|
844
|
+
this._publisherMap.delete(identifier);
|
|
845
|
+
}
|
|
846
|
+
if (!this.hasPublishers) {
|
|
847
|
+
this.exit();
|
|
848
|
+
}
|
|
849
|
+
} catch (err) {
|
|
850
|
+
const msg = error(err, ActionKind.EXIT_SUBSCRIBER, "Broker");
|
|
851
|
+
client.send(msg);
|
|
852
|
+
client.close();
|
|
853
|
+
}
|
|
854
|
+
});
|
|
658
855
|
});
|
|
659
|
-
|
|
660
|
-
|
|
856
|
+
}
|
|
857
|
+
_removePublisher(context, client) {
|
|
858
|
+
return __async(this, null, function* () {
|
|
859
|
+
const { name, ip } = context != null ? context : {};
|
|
661
860
|
const identifier = getIdentifier({
|
|
662
861
|
name,
|
|
663
862
|
ip
|
|
664
863
|
});
|
|
665
|
-
const
|
|
666
|
-
if (!
|
|
667
|
-
fileLog(
|
|
668
|
-
`[${"EXIT_SUBSCRIBER" /* EXIT_SUBSCRIBER */}], ${identifier} does not exit `,
|
|
669
|
-
"Broker",
|
|
670
|
-
"warn"
|
|
671
|
-
);
|
|
864
|
+
const publisher = this._publisherMap.get(identifier);
|
|
865
|
+
if (!publisher) {
|
|
866
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier}} has not been added, this action will be ingored`, "Broker", "warn");
|
|
672
867
|
return;
|
|
673
868
|
}
|
|
674
869
|
try {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
870
|
+
const { subscribers } = publisher;
|
|
871
|
+
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
872
|
+
this._addTmpSubScriberRelation({
|
|
873
|
+
name: subscriberIdentifier,
|
|
874
|
+
client: subscriber
|
|
875
|
+
}, {
|
|
876
|
+
name: publisher.name,
|
|
877
|
+
ip: publisher.ip
|
|
878
|
+
});
|
|
879
|
+
fileLog(
|
|
880
|
+
// eslint-disable-next-line max-len
|
|
881
|
+
`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
882
|
+
"Broker",
|
|
883
|
+
"info"
|
|
884
|
+
);
|
|
885
|
+
});
|
|
886
|
+
this._publisherMap.delete(identifier);
|
|
887
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: ${identifier} is removed `, "Broker", "info");
|
|
685
888
|
if (!this.hasPublishers) {
|
|
889
|
+
fileLog(`[${ActionKind.EXIT_PUBLISHER}]: _publisherMap is empty, all server will exit `, "Broker", "warn");
|
|
686
890
|
this.exit();
|
|
687
891
|
}
|
|
688
892
|
} catch (err) {
|
|
689
|
-
const msg = error(err,
|
|
893
|
+
const msg = error(err, ActionKind.EXIT_PUBLISHER, "Broker");
|
|
690
894
|
client.send(msg);
|
|
691
895
|
client.close();
|
|
692
896
|
}
|
|
693
897
|
});
|
|
694
898
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
});
|
|
701
|
-
const publisher = this._publisherMap.get(identifier);
|
|
702
|
-
if (!publisher) {
|
|
703
|
-
fileLog(
|
|
704
|
-
`[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier}} has not been added, this action will be ingored`,
|
|
705
|
-
"Broker",
|
|
706
|
-
"warn"
|
|
707
|
-
);
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
try {
|
|
711
|
-
const { subscribers } = publisher;
|
|
712
|
-
subscribers.forEach((subscriber, subscriberIdentifier) => {
|
|
713
|
-
this._addTmpSubScriberRelation(
|
|
714
|
-
{
|
|
715
|
-
name: subscriberIdentifier,
|
|
716
|
-
client: subscriber
|
|
717
|
-
},
|
|
718
|
-
{ name: publisher.name, ip: publisher.ip }
|
|
719
|
-
);
|
|
720
|
-
fileLog(
|
|
721
|
-
// eslint-disable-next-line max-len
|
|
722
|
-
`[${"EXIT_PUBLISHER" /* EXIT_PUBLISHER */}]: ${identifier} is removing , subscriber: ${subscriberIdentifier} will be add tmpSubScriberRelation`,
|
|
723
|
-
"Broker",
|
|
724
|
-
"info"
|
|
725
|
-
);
|
|
899
|
+
_addWebClient(context, client) {
|
|
900
|
+
return __async(this, null, function* () {
|
|
901
|
+
const { name } = context != null ? context : {};
|
|
902
|
+
const identifier = getIdentifier({
|
|
903
|
+
name
|
|
726
904
|
});
|
|
727
|
-
this.
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
"warn"
|
|
738
|
-
);
|
|
739
|
-
this.exit();
|
|
905
|
+
if (this._webClientMap.has(identifier)) {
|
|
906
|
+
fileLog(`${identifier}} has been added, this action will override prev WebClient`, "Broker", "warn");
|
|
907
|
+
}
|
|
908
|
+
try {
|
|
909
|
+
this._webClientMap.set(identifier, client);
|
|
910
|
+
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
911
|
+
} catch (err) {
|
|
912
|
+
const msg = error(err, ActionKind.ADD_WEB_CLIENT, "Broker");
|
|
913
|
+
client.send(msg);
|
|
914
|
+
client.close();
|
|
740
915
|
}
|
|
741
|
-
} catch (err) {
|
|
742
|
-
const msg = error(err, "EXIT_PUBLISHER" /* EXIT_PUBLISHER */, "Broker");
|
|
743
|
-
client.send(msg);
|
|
744
|
-
client.close();
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
async _addWebClient(context, client) {
|
|
748
|
-
const { name } = context ?? {};
|
|
749
|
-
const identifier = getIdentifier({
|
|
750
|
-
name
|
|
751
916
|
});
|
|
752
|
-
if (this._webClientMap.has(identifier)) {
|
|
753
|
-
fileLog(
|
|
754
|
-
`${identifier}} has been added, this action will override prev WebClient`,
|
|
755
|
-
"Broker",
|
|
756
|
-
"warn"
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
try {
|
|
760
|
-
this._webClientMap.set(identifier, client);
|
|
761
|
-
fileLog(`${identifier} adding WebClient Succeed`, "Broker", "info");
|
|
762
|
-
} catch (err) {
|
|
763
|
-
const msg = error(err, "ADD_WEB_CLIENT" /* ADD_WEB_CLIENT */, "Broker");
|
|
764
|
-
client.send(msg);
|
|
765
|
-
client.close();
|
|
766
|
-
}
|
|
767
917
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
`[${
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
"Broker"
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
client.send(msg);
|
|
793
|
-
client.close();
|
|
794
|
-
}
|
|
918
|
+
_notifyWebClient(context, client) {
|
|
919
|
+
return __async(this, null, function* () {
|
|
920
|
+
const { name, updateMode } = context != null ? context : {};
|
|
921
|
+
const identifier = getIdentifier({
|
|
922
|
+
name
|
|
923
|
+
});
|
|
924
|
+
const webClient = this._webClientMap.get(identifier);
|
|
925
|
+
if (!webClient) {
|
|
926
|
+
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] ${identifier} has not been added, this action will be ignored`, "Broker", "warn");
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
try {
|
|
930
|
+
const api = new ReloadWebClientAPI({
|
|
931
|
+
name,
|
|
932
|
+
updateMode
|
|
933
|
+
});
|
|
934
|
+
webClient.send(JSON.stringify(api));
|
|
935
|
+
fileLog(`[${ActionKind.NOTIFY_WEB_CLIENT}] Notify ${name} WebClient Succeed`, "Broker", "info");
|
|
936
|
+
} catch (err) {
|
|
937
|
+
const msg = error(err, ActionKind.NOTIFY_WEB_CLIENT, "Broker");
|
|
938
|
+
client.send(msg);
|
|
939
|
+
client.close();
|
|
940
|
+
}
|
|
941
|
+
});
|
|
795
942
|
}
|
|
796
943
|
// app1 consumes provider1, and provider1 not launch. this._tmpSubscriberShelter at this time: {provider1: Map{subscribers: Map{app1: app1+ip+client'}, timestamp: 'xx'} }
|
|
797
944
|
_addTmpSubScriberRelation(subscriber, publisher) {
|
|
@@ -808,20 +955,12 @@ ${err.message}
|
|
|
808
955
|
subscribers: map,
|
|
809
956
|
timestamp: Date.now()
|
|
810
957
|
});
|
|
811
|
-
fileLog(
|
|
812
|
-
`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `,
|
|
813
|
-
"Broker",
|
|
814
|
-
"info"
|
|
815
|
-
);
|
|
958
|
+
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier}'s subscriber has ${subscriberIdentifier} `, "Broker", "info");
|
|
816
959
|
return;
|
|
817
960
|
}
|
|
818
961
|
const tmpSubScriberShelterSubscriber = shelter.subscribers.get(subscriberIdentifier);
|
|
819
962
|
if (tmpSubScriberShelterSubscriber) {
|
|
820
|
-
fileLog(
|
|
821
|
-
`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`,
|
|
822
|
-
"Broker",
|
|
823
|
-
"warn"
|
|
824
|
-
);
|
|
963
|
+
fileLog(`[AddTmpSubscriberRelation] ${publisherIdentifier} and ${subscriberIdentifier} relation has been added`, "Broker", "warn");
|
|
825
964
|
shelter.subscribers.set(subscriberIdentifier, subscriber);
|
|
826
965
|
shelter.timestamp = Date.now();
|
|
827
966
|
} else {
|
|
@@ -835,22 +974,20 @@ ${err.message}
|
|
|
835
974
|
}
|
|
836
975
|
}
|
|
837
976
|
_getTmpSubScribers(publisherIdentifier) {
|
|
838
|
-
var
|
|
839
|
-
return (
|
|
977
|
+
var _a4;
|
|
978
|
+
return (_a4 = this._tmpSubscriberShelter.get(publisherIdentifier)) == null ? void 0 : _a4.subscribers;
|
|
840
979
|
}
|
|
841
980
|
// after adding publisher, it will change the temp subscriber to regular subscriber
|
|
842
981
|
_consumeTmpSubScribers(publisher, tmpSubScribers) {
|
|
843
982
|
tmpSubScribers.forEach((tmpSubScriber, identifier) => {
|
|
844
|
-
fileLog(
|
|
845
|
-
`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `,
|
|
846
|
-
"Broker",
|
|
847
|
-
"warn"
|
|
848
|
-
);
|
|
983
|
+
fileLog(`notifyTmpSubScribers ${publisher.name} will be add a subscriber: ${identifier} `, "Broker", "warn");
|
|
849
984
|
publisher.addSubscriber(identifier, tmpSubScriber.client);
|
|
850
985
|
publisher.notifySubscriber(identifier, {
|
|
851
|
-
updateKind:
|
|
852
|
-
updateMode:
|
|
853
|
-
updateSourcePaths: [
|
|
986
|
+
updateKind: UpdateKind.UPDATE_TYPE,
|
|
987
|
+
updateMode: UpdateMode.PASSIVE,
|
|
988
|
+
updateSourcePaths: [
|
|
989
|
+
publisher.name
|
|
990
|
+
],
|
|
854
991
|
remoteTypeTarPath: publisher.remoteTypeTarPath,
|
|
855
992
|
name: publisher.name
|
|
856
993
|
});
|
|
@@ -880,17 +1017,21 @@ ${err.message}
|
|
|
880
1017
|
rule.second = second;
|
|
881
1018
|
} else {
|
|
882
1019
|
rule.second = 0;
|
|
883
|
-
rule.hour = [
|
|
1020
|
+
rule.hour = [
|
|
1021
|
+
0,
|
|
1022
|
+
3,
|
|
1023
|
+
6,
|
|
1024
|
+
9,
|
|
1025
|
+
12,
|
|
1026
|
+
15,
|
|
1027
|
+
18
|
|
1028
|
+
];
|
|
884
1029
|
rule.minute = 0;
|
|
885
1030
|
}
|
|
886
1031
|
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
887
1032
|
this._scheduleJob = import_node_schedule.default.scheduleJob(rule, () => {
|
|
888
1033
|
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
889
|
-
fileLog(
|
|
890
|
-
` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`,
|
|
891
|
-
"Broker",
|
|
892
|
-
"info"
|
|
893
|
-
);
|
|
1034
|
+
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
894
1035
|
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : _Broker.DEFAULT_WAITING_TIME)) {
|
|
895
1036
|
this._clearTmpSubScriberRelation(identifier);
|
|
896
1037
|
}
|
|
@@ -924,7 +1065,9 @@ ${err.message}
|
|
|
924
1065
|
process.exit(1);
|
|
925
1066
|
});
|
|
926
1067
|
}
|
|
927
|
-
|
|
1068
|
+
start() {
|
|
1069
|
+
return __async(this, null, function* () {
|
|
1070
|
+
});
|
|
928
1071
|
}
|
|
929
1072
|
exit() {
|
|
930
1073
|
const brokerExitLog = new BrokerExitLog();
|
|
@@ -937,13 +1080,9 @@ ${err.message}
|
|
|
937
1080
|
process.exit(0);
|
|
938
1081
|
}
|
|
939
1082
|
broadcast(message) {
|
|
940
|
-
var
|
|
941
|
-
fileLog(
|
|
942
|
-
|
|
943
|
-
"Broker",
|
|
944
|
-
"warn"
|
|
945
|
-
);
|
|
946
|
-
(_a = this._webSocketServer) == null ? void 0 : _a.clients.forEach((client) => {
|
|
1083
|
+
var _a4, _b;
|
|
1084
|
+
fileLog(`[broadcast] exit info : ${JSON.stringify(message)}`, "Broker", "warn");
|
|
1085
|
+
(_a4 = this._webSocketServer) == null ? void 0 : _a4.clients.forEach((client) => {
|
|
947
1086
|
client.send(JSON.stringify(message));
|
|
948
1087
|
});
|
|
949
1088
|
(_b = this._secureWebSocketServer) == null ? void 0 : _b.clients.forEach((client) => {
|
|
@@ -951,10 +1090,11 @@ ${err.message}
|
|
|
951
1090
|
});
|
|
952
1091
|
}
|
|
953
1092
|
};
|
|
954
|
-
_Broker
|
|
955
|
-
_Broker
|
|
956
|
-
_Broker
|
|
957
|
-
_Broker
|
|
1093
|
+
__name(_Broker, "Broker");
|
|
1094
|
+
__publicField(_Broker, "WEB_SOCKET_CONNECT_MAGIC_ID", WEB_SOCKET_CONNECT_MAGIC_ID);
|
|
1095
|
+
__publicField(_Broker, "DEFAULT_WEB_SOCKET_PORT", DEFAULT_WEB_SOCKET_PORT);
|
|
1096
|
+
__publicField(_Broker, "DEFAULT_SECURE_WEB_SOCKET_PORT", 16324);
|
|
1097
|
+
__publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
958
1098
|
var Broker = _Broker;
|
|
959
1099
|
|
|
960
1100
|
// packages/dts-plugin/src/server/createKoaServer.ts
|
|
@@ -962,49 +1102,49 @@ var import_fs_extra = __toESM(require("fs-extra"));
|
|
|
962
1102
|
var import_koa = __toESM(require("koa"));
|
|
963
1103
|
|
|
964
1104
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
965
|
-
var retrieveTypesZipPath = (mfTypesPath, remoteOptions) => (0, import_path2.join)(
|
|
966
|
-
|
|
967
|
-
`${remoteOptions.typesFolder}.zip`
|
|
968
|
-
);
|
|
969
|
-
var createTypesArchive = async (tsConfig, remoteOptions) => {
|
|
1105
|
+
var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => (0, import_path2.join)(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
|
|
1106
|
+
var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
970
1107
|
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
971
1108
|
const zip = new import_adm_zip.default();
|
|
972
1109
|
zip.addLocalFolder(mfTypesPath);
|
|
973
1110
|
return zip.writeZipPromise(retrieveTypesZipPath(mfTypesPath, remoteOptions));
|
|
974
|
-
};
|
|
975
|
-
var downloadErrorLogger = (destinationFolder, fileToDownload) => (reason) => {
|
|
976
|
-
throw {
|
|
977
|
-
...reason,
|
|
1111
|
+
}), "createTypesArchive");
|
|
1112
|
+
var downloadErrorLogger = /* @__PURE__ */ __name((destinationFolder, fileToDownload) => (reason) => {
|
|
1113
|
+
throw __spreadProps(__spreadValues({}, reason), {
|
|
978
1114
|
message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`
|
|
979
|
-
};
|
|
980
|
-
};
|
|
981
|
-
var retrieveTypesArchiveDestinationPath = (hostOptions, destinationFolder) => {
|
|
982
|
-
return (0, import_path2.resolve)(
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
destinationFolder
|
|
986
|
-
);
|
|
987
|
-
};
|
|
988
|
-
var downloadTypesArchive = (hostOptions) => {
|
|
1115
|
+
});
|
|
1116
|
+
}, "downloadErrorLogger");
|
|
1117
|
+
var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, destinationFolder) => {
|
|
1118
|
+
return (0, import_path2.resolve)(hostOptions.context, hostOptions.typesFolder, destinationFolder);
|
|
1119
|
+
}, "retrieveTypesArchiveDestinationPath");
|
|
1120
|
+
var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
989
1121
|
let retries = 0;
|
|
990
|
-
return
|
|
991
|
-
const destinationPath = retrieveTypesArchiveDestinationPath(
|
|
992
|
-
hostOptions,
|
|
993
|
-
destinationFolder
|
|
994
|
-
);
|
|
1122
|
+
return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
|
|
1123
|
+
const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
|
|
995
1124
|
while (retries++ < hostOptions.maxRetries) {
|
|
996
1125
|
try {
|
|
997
1126
|
const url = fileToDownload;
|
|
998
|
-
const response =
|
|
1127
|
+
const response = yield axiosGet(url, {
|
|
1128
|
+
responseType: "arraybuffer"
|
|
1129
|
+
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1130
|
+
try {
|
|
1131
|
+
if (hostOptions.deleteTypesFolder) {
|
|
1132
|
+
yield (0, import_promises.rm)(destinationPath, {
|
|
1133
|
+
recursive: true,
|
|
1134
|
+
force: true
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
} catch (error2) {
|
|
1138
|
+
fileLog(`Unable to remove types folder, ${error2}`, "downloadTypesArchive", "error");
|
|
1139
|
+
}
|
|
999
1140
|
const zip = new import_adm_zip.default(Buffer.from(response.data));
|
|
1000
1141
|
zip.extractAllTo(destinationPath, true);
|
|
1001
|
-
return [
|
|
1142
|
+
return [
|
|
1143
|
+
destinationFolder,
|
|
1144
|
+
destinationPath
|
|
1145
|
+
];
|
|
1002
1146
|
} catch (error2) {
|
|
1003
|
-
fileLog(
|
|
1004
|
-
`Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`,
|
|
1005
|
-
"downloadTypesArchive",
|
|
1006
|
-
"error"
|
|
1007
|
-
);
|
|
1147
|
+
fileLog(`Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`, "downloadTypesArchive", "error");
|
|
1008
1148
|
if (retries >= hostOptions.maxRetries) {
|
|
1009
1149
|
if (hostOptions.abortOnError !== false) {
|
|
1010
1150
|
throw error2;
|
|
@@ -1013,8 +1153,8 @@ var downloadTypesArchive = (hostOptions) => {
|
|
|
1013
1153
|
}
|
|
1014
1154
|
}
|
|
1015
1155
|
}
|
|
1016
|
-
};
|
|
1017
|
-
};
|
|
1156
|
+
});
|
|
1157
|
+
}, "downloadTypesArchive");
|
|
1018
1158
|
|
|
1019
1159
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1020
1160
|
var import_sdk3 = require("@module-federation/sdk");
|
|
@@ -1029,22 +1169,26 @@ var defaultOptions = {
|
|
|
1029
1169
|
abortOnError: true,
|
|
1030
1170
|
consumeAPITypes: false
|
|
1031
1171
|
};
|
|
1032
|
-
var buildZipUrl = (hostOptions, url) => {
|
|
1033
|
-
const remoteUrl = new URL(url);
|
|
1172
|
+
var buildZipUrl = /* @__PURE__ */ __name((hostOptions, url) => {
|
|
1173
|
+
const remoteUrl = new URL(url, "file:");
|
|
1034
1174
|
const pathnameWithoutEntry = remoteUrl.pathname.split("/").slice(0, -1).join("/");
|
|
1035
1175
|
remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
|
|
1036
|
-
return remoteUrl.href;
|
|
1037
|
-
};
|
|
1038
|
-
var buildApiTypeUrl = (zipUrl) => {
|
|
1176
|
+
return remoteUrl.protocol === "file:" ? remoteUrl.pathname : remoteUrl.href;
|
|
1177
|
+
}, "buildZipUrl");
|
|
1178
|
+
var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
1039
1179
|
if (!zipUrl) {
|
|
1040
1180
|
return void 0;
|
|
1041
1181
|
}
|
|
1042
1182
|
return zipUrl.replace(".zip", ".d.ts");
|
|
1043
|
-
};
|
|
1044
|
-
var retrieveRemoteInfo = (options) => {
|
|
1183
|
+
}, "buildApiTypeUrl");
|
|
1184
|
+
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1045
1185
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1046
|
-
|
|
1047
|
-
|
|
1186
|
+
let decodedRemote = remote;
|
|
1187
|
+
if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
|
|
1188
|
+
decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
|
|
1189
|
+
}
|
|
1190
|
+
const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
|
|
1191
|
+
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1048
1192
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1049
1193
|
return {
|
|
1050
1194
|
name: parsedInfo.name || remoteAlias,
|
|
@@ -1053,51 +1197,45 @@ var retrieveRemoteInfo = (options) => {
|
|
|
1053
1197
|
apiTypeUrl: buildApiTypeUrl(zipUrl),
|
|
1054
1198
|
alias: remoteAlias
|
|
1055
1199
|
};
|
|
1056
|
-
};
|
|
1057
|
-
var resolveRemotes = (hostOptions) => {
|
|
1058
|
-
const parsedOptions = import_managers.utils.parseOptions(
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
});
|
|
1077
|
-
return accumulator;
|
|
1078
|
-
},
|
|
1079
|
-
{}
|
|
1080
|
-
);
|
|
1081
|
-
};
|
|
1082
|
-
var retrieveHostConfig = (options) => {
|
|
1200
|
+
}, "retrieveRemoteInfo");
|
|
1201
|
+
var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
|
|
1202
|
+
const parsedOptions = import_managers.utils.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
|
|
1203
|
+
remote: Array.isArray(item) ? item[0] : item,
|
|
1204
|
+
key
|
|
1205
|
+
}), (item, key) => ({
|
|
1206
|
+
remote: Array.isArray(item.external) ? item.external[0] : item.external,
|
|
1207
|
+
key
|
|
1208
|
+
}));
|
|
1209
|
+
return parsedOptions.reduce((accumulator, item) => {
|
|
1210
|
+
const { key, remote } = item[1];
|
|
1211
|
+
accumulator[key] = retrieveRemoteInfo({
|
|
1212
|
+
hostOptions,
|
|
1213
|
+
remoteAlias: key,
|
|
1214
|
+
remote
|
|
1215
|
+
});
|
|
1216
|
+
return accumulator;
|
|
1217
|
+
}, {});
|
|
1218
|
+
}, "resolveRemotes");
|
|
1219
|
+
var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
|
|
1083
1220
|
validateOptions(options);
|
|
1084
|
-
const hostOptions = {
|
|
1221
|
+
const hostOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
1085
1222
|
const mapRemotesToDownload = resolveRemotes(hostOptions);
|
|
1086
1223
|
return {
|
|
1087
1224
|
hostOptions,
|
|
1088
1225
|
mapRemotesToDownload
|
|
1089
1226
|
};
|
|
1090
|
-
};
|
|
1091
|
-
|
|
1092
|
-
// packages/dts-plugin/src/core/constant.ts
|
|
1093
|
-
var REMOTE_ALIAS_IDENTIFIER = "REMOTE_ALIAS_IDENTIFIER";
|
|
1094
|
-
var REMOTE_API_TYPES_FILE_NAME = "apis.d.ts";
|
|
1095
|
-
var HOST_API_TYPES_FILE_NAME = "index.d.ts";
|
|
1227
|
+
}, "retrieveHostConfig");
|
|
1096
1228
|
|
|
1097
1229
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
1098
|
-
var
|
|
1099
|
-
var DTSManager = class {
|
|
1230
|
+
var _a;
|
|
1231
|
+
var DTSManager = (_a = class {
|
|
1100
1232
|
constructor(options) {
|
|
1233
|
+
__publicField(this, "options");
|
|
1234
|
+
__publicField(this, "runtimePkgs");
|
|
1235
|
+
__publicField(this, "remoteAliasMap");
|
|
1236
|
+
__publicField(this, "loadedRemoteAPIAlias");
|
|
1237
|
+
__publicField(this, "extraOptions");
|
|
1238
|
+
__publicField(this, "updatedRemoteInfos");
|
|
1101
1239
|
this.options = (0, import_lodash.default)(options, (_value, key) => {
|
|
1102
1240
|
if (key === "manifest") {
|
|
1103
1241
|
return false;
|
|
@@ -1108,181 +1246,190 @@ var DTSManager = class {
|
|
|
1108
1246
|
"@module-federation/enhanced/runtime",
|
|
1109
1247
|
"@module-federation/runtime-tools"
|
|
1110
1248
|
];
|
|
1111
|
-
this.loadedRemoteAPIAlias =
|
|
1249
|
+
this.loadedRemoteAPIAlias = /* @__PURE__ */ new Set();
|
|
1112
1250
|
this.remoteAliasMap = {};
|
|
1113
1251
|
this.extraOptions = (options == null ? void 0 : options.extraOptions) || {};
|
|
1252
|
+
this.updatedRemoteInfos = {};
|
|
1114
1253
|
}
|
|
1115
1254
|
generateAPITypes(mapComponentsToExpose) {
|
|
1116
1255
|
const exposePaths = /* @__PURE__ */ new Set();
|
|
1117
|
-
const packageType = Object.keys(mapComponentsToExpose).reduce(
|
|
1118
|
-
(
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
);
|
|
1127
|
-
const exposePathKeys = [...exposePaths].join(" | ");
|
|
1256
|
+
const packageType = Object.keys(mapComponentsToExpose).reduce((sum, exposeKey) => {
|
|
1257
|
+
const exposePath = import_path3.default.join(REMOTE_ALIAS_IDENTIFIER, exposeKey).split(import_path3.default.sep).join("/");
|
|
1258
|
+
exposePaths.add(`'${exposePath}'`);
|
|
1259
|
+
const curType = `T extends '${exposePath}' ? typeof import('${exposePath}') :`;
|
|
1260
|
+
sum = curType + sum;
|
|
1261
|
+
return sum;
|
|
1262
|
+
}, "any;");
|
|
1263
|
+
const exposePathKeys = [
|
|
1264
|
+
...exposePaths
|
|
1265
|
+
].join(" | ");
|
|
1128
1266
|
return `
|
|
1129
1267
|
export type RemoteKeys = ${exposePathKeys};
|
|
1130
1268
|
type PackageType<T> = ${packageType}`;
|
|
1131
1269
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1137
|
-
let hasRemotes = false;
|
|
1138
|
-
const remotes = remoteOptions.moduleFederationConfig.remotes;
|
|
1139
|
-
if (remotes) {
|
|
1140
|
-
if (Array.isArray(remotes)) {
|
|
1141
|
-
hasRemotes = Boolean(remotes.length);
|
|
1142
|
-
} else if (typeof remotes === "object") {
|
|
1143
|
-
hasRemotes = Boolean(Object.keys(remotes).length);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1147
|
-
if (hasRemotes) {
|
|
1148
|
-
const tempHostOptions = {
|
|
1149
|
-
moduleFederationConfig: remoteOptions.moduleFederationConfig,
|
|
1150
|
-
typesFolder: import_path3.default.join(mfTypesPath, "node_modules"),
|
|
1151
|
-
remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
|
|
1152
|
-
deleteTypesFolder: true,
|
|
1153
|
-
context: remoteOptions.context,
|
|
1154
|
-
implementation: remoteOptions.implementation,
|
|
1155
|
-
abortOnError: false
|
|
1156
|
-
};
|
|
1157
|
-
await this.consumeArchiveTypes(tempHostOptions);
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
async generateTypes() {
|
|
1161
|
-
var _a;
|
|
1162
|
-
try {
|
|
1163
|
-
const { options } = this;
|
|
1164
|
-
if (!options.remote) {
|
|
1165
|
-
throw new Error(
|
|
1166
|
-
"options.remote is required if you want to generateTypes"
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
|
|
1170
|
-
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1270
|
+
extractRemoteTypes(options) {
|
|
1271
|
+
return __async(this, null, function* () {
|
|
1272
|
+
const { remoteOptions, tsConfig } = options;
|
|
1273
|
+
if (!remoteOptions.extractRemoteTypes) {
|
|
1171
1274
|
return;
|
|
1172
1275
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
if (remoteOptions.generateAPITypes) {
|
|
1182
|
-
const apiTypes = this.generateAPITypes(mapComponentsToExpose);
|
|
1183
|
-
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1184
|
-
import_fs.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1276
|
+
let hasRemotes = false;
|
|
1277
|
+
const remotes = remoteOptions.moduleFederationConfig.remotes;
|
|
1278
|
+
if (remotes) {
|
|
1279
|
+
if (Array.isArray(remotes)) {
|
|
1280
|
+
hasRemotes = Boolean(remotes.length);
|
|
1281
|
+
} else if (typeof remotes === "object") {
|
|
1282
|
+
hasRemotes = Boolean(Object.keys(remotes).length);
|
|
1283
|
+
}
|
|
1185
1284
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1285
|
+
const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
1286
|
+
if (hasRemotes) {
|
|
1287
|
+
const tempHostOptions = {
|
|
1288
|
+
moduleFederationConfig: remoteOptions.moduleFederationConfig,
|
|
1289
|
+
typesFolder: import_path3.default.join(mfTypesPath, "node_modules"),
|
|
1290
|
+
remoteTypesFolder: (remoteOptions == null ? void 0 : remoteOptions.hostRemoteTypesFolder) || remoteOptions.typesFolder,
|
|
1291
|
+
deleteTypesFolder: true,
|
|
1292
|
+
context: remoteOptions.context,
|
|
1293
|
+
implementation: remoteOptions.implementation,
|
|
1294
|
+
abortOnError: false
|
|
1295
|
+
};
|
|
1296
|
+
yield this.consumeArchiveTypes(tempHostOptions);
|
|
1191
1297
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
generateTypes() {
|
|
1301
|
+
return __async(this, null, function* () {
|
|
1302
|
+
var _a4;
|
|
1303
|
+
try {
|
|
1304
|
+
const { options } = this;
|
|
1305
|
+
if (!options.remote) {
|
|
1306
|
+
throw new Error("options.remote is required if you want to generateTypes");
|
|
1307
|
+
}
|
|
1308
|
+
const { remoteOptions, tsConfig, mapComponentsToExpose } = retrieveRemoteConfig(options.remote);
|
|
1309
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
this.extractRemoteTypes({
|
|
1313
|
+
remoteOptions,
|
|
1314
|
+
tsConfig,
|
|
1315
|
+
mapComponentsToExpose
|
|
1316
|
+
});
|
|
1317
|
+
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1318
|
+
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1319
|
+
let apiTypesPath = "";
|
|
1320
|
+
if (remoteOptions.generateAPITypes) {
|
|
1321
|
+
const apiTypes = this.generateAPITypes(mapComponentsToExpose);
|
|
1322
|
+
apiTypesPath = retrieveMfAPITypesPath(tsConfig, remoteOptions);
|
|
1323
|
+
import_fs.default.writeFileSync(apiTypesPath, apiTypes);
|
|
1324
|
+
}
|
|
1325
|
+
try {
|
|
1326
|
+
if (remoteOptions.deleteTypesFolder) {
|
|
1327
|
+
yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1328
|
+
recursive: true,
|
|
1329
|
+
force: true
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
} catch (err) {
|
|
1333
|
+
if (isDebugMode()) {
|
|
1334
|
+
console.error(err);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
console.log(import_ansi_colors2.default.green("Federated types created correctly"));
|
|
1338
|
+
} catch (error2) {
|
|
1339
|
+
if (((_a4 = this.options.remote) == null ? void 0 : _a4.abortOnError) === false) {
|
|
1340
|
+
console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${error2}`));
|
|
1341
|
+
} else {
|
|
1342
|
+
throw error2;
|
|
1343
|
+
}
|
|
1200
1344
|
}
|
|
1201
|
-
}
|
|
1345
|
+
});
|
|
1202
1346
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1347
|
+
requestRemoteManifest(remoteInfo) {
|
|
1348
|
+
return __async(this, null, function* () {
|
|
1349
|
+
try {
|
|
1350
|
+
if (!remoteInfo.url.includes(import_sdk4.MANIFEST_EXT)) {
|
|
1351
|
+
return remoteInfo;
|
|
1352
|
+
}
|
|
1353
|
+
const url = remoteInfo.url;
|
|
1354
|
+
const res = yield axiosGet(url);
|
|
1355
|
+
const manifestJson = res.data;
|
|
1356
|
+
if (!manifestJson.metaData.types.zip) {
|
|
1357
|
+
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1358
|
+
}
|
|
1359
|
+
const addProtocol = /* @__PURE__ */ __name((u) => {
|
|
1360
|
+
if (u.startsWith("//")) {
|
|
1361
|
+
return `https:${u}`;
|
|
1362
|
+
}
|
|
1363
|
+
return u;
|
|
1364
|
+
}, "addProtocol");
|
|
1365
|
+
let publicPath = "publicPath" in manifestJson.metaData ? manifestJson.metaData.publicPath : new Function(manifestJson.metaData.getPublicPath)();
|
|
1366
|
+
if (publicPath === "auto") {
|
|
1367
|
+
publicPath = (0, import_sdk4.inferAutoPublicPath)(remoteInfo.url);
|
|
1368
|
+
}
|
|
1369
|
+
remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1370
|
+
if (!manifestJson.metaData.types.api) {
|
|
1371
|
+
console.warn(`Can not get ${remoteInfo.name}'s api types url!`);
|
|
1372
|
+
remoteInfo.apiTypeUrl = "";
|
|
1373
|
+
return remoteInfo;
|
|
1374
|
+
}
|
|
1375
|
+
remoteInfo.apiTypeUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.api)).href;
|
|
1376
|
+
return remoteInfo;
|
|
1377
|
+
} catch (_err) {
|
|
1378
|
+
fileLog(`fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`, "requestRemoteManifest", "error");
|
|
1206
1379
|
return remoteInfo;
|
|
1207
1380
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
const manifestJson = res.data;
|
|
1214
|
-
if (!manifestJson.metaData.types.zip) {
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
consumeTargetRemotes(hostOptions, remoteInfo) {
|
|
1384
|
+
return __async(this, null, function* () {
|
|
1385
|
+
if (!remoteInfo.zipUrl) {
|
|
1215
1386
|
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1216
1387
|
}
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1388
|
+
const typesDownloader = downloadTypesArchive(hostOptions);
|
|
1389
|
+
return typesDownloader([
|
|
1390
|
+
remoteInfo.alias,
|
|
1391
|
+
remoteInfo.zipUrl
|
|
1392
|
+
]);
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
downloadAPITypes(remoteInfo, destinationPath) {
|
|
1396
|
+
return __async(this, null, function* () {
|
|
1397
|
+
const { apiTypeUrl } = remoteInfo;
|
|
1398
|
+
if (!apiTypeUrl) {
|
|
1399
|
+
return;
|
|
1226
1400
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1401
|
+
try {
|
|
1402
|
+
const url = apiTypeUrl;
|
|
1403
|
+
const res = yield axiosGet(url);
|
|
1404
|
+
let apiTypeFile = res.data;
|
|
1405
|
+
apiTypeFile = apiTypeFile.replaceAll(REMOTE_ALIAS_IDENTIFIER, remoteInfo.alias);
|
|
1406
|
+
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1407
|
+
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1408
|
+
this.loadedRemoteAPIAlias.add(remoteInfo.alias);
|
|
1409
|
+
} catch (err) {
|
|
1410
|
+
fileLog(`Unable to download "${remoteInfo.name}" api types, ${err}`, "consumeTargetRemotes", "error");
|
|
1234
1411
|
}
|
|
1235
|
-
|
|
1236
|
-
import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.api)
|
|
1237
|
-
).href;
|
|
1238
|
-
return remoteInfo;
|
|
1239
|
-
} catch (_err) {
|
|
1240
|
-
fileLog(
|
|
1241
|
-
`fetch manifest failed, ${_err}, ${remoteInfo.name} will be ignored`,
|
|
1242
|
-
"requestRemoteManifest",
|
|
1243
|
-
"error"
|
|
1244
|
-
);
|
|
1245
|
-
return remoteInfo;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
async consumeTargetRemotes(hostOptions, remoteInfo) {
|
|
1249
|
-
if (!remoteInfo.zipUrl) {
|
|
1250
|
-
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
|
|
1251
|
-
}
|
|
1252
|
-
const typesDownloader = downloadTypesArchive(hostOptions);
|
|
1253
|
-
return typesDownloader([remoteInfo.alias, remoteInfo.zipUrl]);
|
|
1412
|
+
});
|
|
1254
1413
|
}
|
|
1255
|
-
|
|
1256
|
-
const
|
|
1257
|
-
if (!apiTypeUrl) {
|
|
1258
|
-
return;
|
|
1259
|
-
}
|
|
1414
|
+
consumeAPITypes(hostOptions) {
|
|
1415
|
+
const apiTypeFileName = import_path3.default.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME);
|
|
1260
1416
|
try {
|
|
1261
|
-
const
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
);
|
|
1268
|
-
const filePath = import_path3.default.join(destinationPath, REMOTE_API_TYPES_FILE_NAME);
|
|
1269
|
-
import_fs.default.writeFileSync(filePath, apiTypeFile);
|
|
1270
|
-
this.loadedRemoteAPIAlias.push(remoteInfo.alias);
|
|
1417
|
+
const existedFile = import_fs.default.readFileSync(apiTypeFileName, "utf-8");
|
|
1418
|
+
const existedImports = new import_third_party_dts_extractor2.ThirdPartyExtractor("").collectTypeImports(existedFile);
|
|
1419
|
+
existedImports.forEach((existedImport) => {
|
|
1420
|
+
const alias = existedImport.split("./").slice(1).join("./").replace("/apis.d.ts", "");
|
|
1421
|
+
this.loadedRemoteAPIAlias.add(alias);
|
|
1422
|
+
});
|
|
1271
1423
|
} catch (err) {
|
|
1272
|
-
fileLog(
|
|
1273
|
-
`Unable to download "${remoteInfo.name}" api types, ${err}`,
|
|
1274
|
-
"consumeTargetRemotes",
|
|
1275
|
-
"error"
|
|
1276
|
-
);
|
|
1277
1424
|
}
|
|
1278
|
-
|
|
1279
|
-
consumeAPITypes(hostOptions) {
|
|
1280
|
-
if (!this.loadedRemoteAPIAlias.length) {
|
|
1425
|
+
if (!this.loadedRemoteAPIAlias.size) {
|
|
1281
1426
|
return;
|
|
1282
1427
|
}
|
|
1283
1428
|
const packageTypes = [];
|
|
1284
1429
|
const remoteKeys = [];
|
|
1285
|
-
const importTypeStr =
|
|
1430
|
+
const importTypeStr = [
|
|
1431
|
+
...this.loadedRemoteAPIAlias
|
|
1432
|
+
].sort().map((alias, index) => {
|
|
1286
1433
|
const remoteKey = `RemoteKeys_${index}`;
|
|
1287
1434
|
const packageType = `PackageType_${index}`;
|
|
1288
1435
|
packageTypes.push(`T extends ${remoteKey} ? ${packageType}<T>`);
|
|
@@ -1305,63 +1452,41 @@ var DTSManager = class {
|
|
|
1305
1452
|
const fileStr = `${importTypeStr}
|
|
1306
1453
|
${pkgsDeclareStr}
|
|
1307
1454
|
`;
|
|
1308
|
-
import_fs.default.writeFileSync(
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
),
|
|
1314
|
-
fileStr
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
async consumeArchiveTypes(options) {
|
|
1318
|
-
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1319
|
-
if (hostOptions.deleteTypesFolder) {
|
|
1320
|
-
await (0, import_promises.rm)(hostOptions.typesFolder, {
|
|
1321
|
-
recursive: true,
|
|
1322
|
-
force: true
|
|
1323
|
-
}).catch(
|
|
1324
|
-
(error2) => fileLog(
|
|
1325
|
-
`Unable to remove types folder, ${error2}`,
|
|
1326
|
-
"consumeArchiveTypes",
|
|
1327
|
-
"error"
|
|
1328
|
-
)
|
|
1329
|
-
);
|
|
1330
|
-
}
|
|
1331
|
-
const downloadPromises = Object.entries(mapRemotesToDownload).map(
|
|
1332
|
-
async (item) => {
|
|
1455
|
+
import_fs.default.writeFileSync(import_path3.default.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME), fileStr);
|
|
1456
|
+
}
|
|
1457
|
+
consumeArchiveTypes(options) {
|
|
1458
|
+
return __async(this, null, function* () {
|
|
1459
|
+
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(options);
|
|
1460
|
+
const downloadPromises = Object.entries(mapRemotesToDownload).map((item) => __async(this, null, function* () {
|
|
1333
1461
|
const remoteInfo = item[1];
|
|
1334
1462
|
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1335
|
-
const requiredRemoteInfo =
|
|
1463
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1336
1464
|
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1337
1465
|
}
|
|
1338
|
-
return this.consumeTargetRemotes(
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
hostOptions,
|
|
1347
|
-
downloadPromisesResult
|
|
1348
|
-
};
|
|
1466
|
+
return this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
1467
|
+
}));
|
|
1468
|
+
const downloadPromisesResult = yield Promise.allSettled(downloadPromises);
|
|
1469
|
+
return {
|
|
1470
|
+
hostOptions,
|
|
1471
|
+
downloadPromisesResult
|
|
1472
|
+
};
|
|
1473
|
+
});
|
|
1349
1474
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
downloadPromisesResult.map(
|
|
1475
|
+
consumeTypes() {
|
|
1476
|
+
return __async(this, null, function* () {
|
|
1477
|
+
var _a4;
|
|
1478
|
+
try {
|
|
1479
|
+
const { options } = this;
|
|
1480
|
+
if (!options.host) {
|
|
1481
|
+
throw new Error("options.host is required if you want to consumeTypes");
|
|
1482
|
+
}
|
|
1483
|
+
const { mapRemotesToDownload } = retrieveHostConfig(options.host);
|
|
1484
|
+
if (!Object.keys(mapRemotesToDownload).length) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
const { downloadPromisesResult, hostOptions } = yield this.consumeArchiveTypes(options.host);
|
|
1488
|
+
if (hostOptions.consumeAPITypes) {
|
|
1489
|
+
yield Promise.all(downloadPromisesResult.map((item) => __async(this, null, function* () {
|
|
1365
1490
|
if (item.status === "rejected" || !item.value) {
|
|
1366
1491
|
return;
|
|
1367
1492
|
}
|
|
@@ -1370,68 +1495,82 @@ var DTSManager = class {
|
|
|
1370
1495
|
if (!remoteInfo) {
|
|
1371
1496
|
return;
|
|
1372
1497
|
}
|
|
1373
|
-
|
|
1374
|
-
})
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
"error"
|
|
1385
|
-
);
|
|
1386
|
-
} else {
|
|
1387
|
-
throw err;
|
|
1498
|
+
yield this.downloadAPITypes(remoteInfo, destinationPath);
|
|
1499
|
+
})));
|
|
1500
|
+
this.consumeAPITypes(hostOptions);
|
|
1501
|
+
}
|
|
1502
|
+
console.log(import_ansi_colors2.default.green("Federated types extraction completed"));
|
|
1503
|
+
} catch (err) {
|
|
1504
|
+
if (((_a4 = this.options.host) == null ? void 0 : _a4.abortOnError) === false) {
|
|
1505
|
+
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
1506
|
+
} else {
|
|
1507
|
+
throw err;
|
|
1508
|
+
}
|
|
1388
1509
|
}
|
|
1389
|
-
}
|
|
1510
|
+
});
|
|
1390
1511
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1512
|
+
updateTypes(options) {
|
|
1513
|
+
return __async(this, null, function* () {
|
|
1514
|
+
var _a4, _b, _c;
|
|
1515
|
+
try {
|
|
1516
|
+
const { remoteName, updateMode, remoteInfo: updatedRemoteInfo, once } = options;
|
|
1517
|
+
const hostName = (_c = (_b = (_a4 = this.options) == null ? void 0 : _a4.host) == null ? void 0 : _b.moduleFederationConfig) == null ? void 0 : _c.name;
|
|
1518
|
+
fileLog(`updateTypes options:, ${JSON.stringify(options, null, 2)}`, "consumeTypes", "info");
|
|
1519
|
+
if (updateMode === UpdateMode.POSITIVE && remoteName === hostName) {
|
|
1520
|
+
if (!this.options.remote) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
this.generateTypes();
|
|
1524
|
+
} else {
|
|
1525
|
+
const { remoteAliasMap } = this;
|
|
1526
|
+
if (!this.options.host) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig(this.options.host);
|
|
1530
|
+
const loadedRemoteInfo = Object.values(remoteAliasMap).find((i) => i.name === remoteName);
|
|
1531
|
+
if (!loadedRemoteInfo) {
|
|
1532
|
+
const remoteInfo = Object.values(mapRemotesToDownload).find((item) => {
|
|
1533
|
+
return item.name === remoteName;
|
|
1534
|
+
});
|
|
1535
|
+
if (remoteInfo) {
|
|
1536
|
+
if (!this.remoteAliasMap[remoteInfo.alias]) {
|
|
1537
|
+
const requiredRemoteInfo = yield this.requestRemoteManifest(remoteInfo);
|
|
1538
|
+
this.remoteAliasMap[remoteInfo.alias] = requiredRemoteInfo;
|
|
1539
|
+
}
|
|
1540
|
+
yield this.consumeTargetRemotes(hostOptions, this.remoteAliasMap[remoteInfo.alias]);
|
|
1541
|
+
} else if (updatedRemoteInfo) {
|
|
1542
|
+
const consumeDynamicRemoteTypes = /* @__PURE__ */ __name(() => __async(this, null, function* () {
|
|
1543
|
+
const [_destinationFolder, destinationPath] = yield this.consumeTargetRemotes(hostOptions, this.updatedRemoteInfos[updatedRemoteInfo.name]);
|
|
1544
|
+
yield this.downloadAPITypes(this.updatedRemoteInfos[updatedRemoteInfo.name], destinationPath);
|
|
1545
|
+
this.consumeAPITypes(hostOptions);
|
|
1546
|
+
}), "consumeDynamicRemoteTypes");
|
|
1547
|
+
if (!this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1548
|
+
const parsedRemoteInfo = retrieveRemoteInfo({
|
|
1549
|
+
hostOptions,
|
|
1550
|
+
remoteAlias: updatedRemoteInfo.alias || updatedRemoteInfo.name,
|
|
1551
|
+
remote: updatedRemoteInfo.url
|
|
1552
|
+
});
|
|
1553
|
+
fileLog(`start request manifest`, "consumeTypes", "info");
|
|
1554
|
+
this.updatedRemoteInfos[updatedRemoteInfo.name] = yield this.requestRemoteManifest(parsedRemoteInfo);
|
|
1555
|
+
fileLog(`end request manifest, this.updatedRemoteInfos[updatedRemoteInfo.name]: ${JSON.stringify(this.updatedRemoteInfos[updatedRemoteInfo.name], null, 2)}`, "consumeTypes", "info");
|
|
1556
|
+
yield consumeDynamicRemoteTypes();
|
|
1557
|
+
}
|
|
1558
|
+
if (!once && this.updatedRemoteInfos[updatedRemoteInfo.name]) {
|
|
1559
|
+
yield consumeDynamicRemoteTypes();
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
} else {
|
|
1563
|
+
yield this.consumeTargetRemotes(hostOptions, loadedRemoteInfo);
|
|
1419
1564
|
}
|
|
1420
|
-
await this.consumeTargetRemotes(
|
|
1421
|
-
hostOptions,
|
|
1422
|
-
this.remoteAliasMap[remoteInfo.alias]
|
|
1423
|
-
);
|
|
1424
1565
|
}
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1566
|
+
} catch (err) {
|
|
1567
|
+
fileLog(`updateTypes fail, ${err}`, "updateTypes", "error");
|
|
1427
1568
|
}
|
|
1428
|
-
}
|
|
1569
|
+
});
|
|
1429
1570
|
}
|
|
1430
|
-
};
|
|
1571
|
+
}, __name(_a, "DTSManager"), _a);
|
|
1431
1572
|
|
|
1432
1573
|
// packages/dts-plugin/src/core/lib/utils.ts
|
|
1433
|
-
var import_fs2 = __toESM(require("fs"));
|
|
1434
|
-
var import_ansi_colors3 = __toESM(require("ansi-colors"));
|
|
1435
1574
|
function getDTSManagerConstructor(implementation) {
|
|
1436
1575
|
if (implementation) {
|
|
1437
1576
|
const NewConstructor = require(implementation);
|
|
@@ -1439,11 +1578,12 @@ function getDTSManagerConstructor(implementation) {
|
|
|
1439
1578
|
}
|
|
1440
1579
|
return DTSManager;
|
|
1441
1580
|
}
|
|
1442
|
-
|
|
1581
|
+
__name(getDTSManagerConstructor, "getDTSManagerConstructor");
|
|
1582
|
+
var validateOptions = /* @__PURE__ */ __name((options) => {
|
|
1443
1583
|
if (!options.moduleFederationConfig) {
|
|
1444
1584
|
throw new Error("moduleFederationConfig is required");
|
|
1445
1585
|
}
|
|
1446
|
-
};
|
|
1586
|
+
}, "validateOptions");
|
|
1447
1587
|
function retrieveTypesAssetsInfo(options) {
|
|
1448
1588
|
let apiTypesPath = "";
|
|
1449
1589
|
let zipTypesPath = "";
|
|
@@ -1478,7 +1618,12 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1478
1618
|
};
|
|
1479
1619
|
}
|
|
1480
1620
|
}
|
|
1481
|
-
|
|
1621
|
+
__name(retrieveTypesAssetsInfo, "retrieveTypesAssetsInfo");
|
|
1622
|
+
function isDebugMode() {
|
|
1623
|
+
return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
1624
|
+
}
|
|
1625
|
+
__name(isDebugMode, "isDebugMode");
|
|
1626
|
+
var isTSProject = /* @__PURE__ */ __name((dtsOptions, context = process.cwd()) => {
|
|
1482
1627
|
if (dtsOptions === false) {
|
|
1483
1628
|
return false;
|
|
1484
1629
|
}
|
|
@@ -1496,7 +1641,22 @@ var isTSProject = (dtsOptions, context = process.cwd()) => {
|
|
|
1496
1641
|
} catch (err) {
|
|
1497
1642
|
return false;
|
|
1498
1643
|
}
|
|
1499
|
-
};
|
|
1644
|
+
}, "isTSProject");
|
|
1645
|
+
function axiosGet(url, config) {
|
|
1646
|
+
return __async(this, null, function* () {
|
|
1647
|
+
const httpAgent = new import_http2.default.Agent({
|
|
1648
|
+
family: 4
|
|
1649
|
+
});
|
|
1650
|
+
const httpsAgent = new import_https.default.Agent({
|
|
1651
|
+
family: 4
|
|
1652
|
+
});
|
|
1653
|
+
return import_axios.default.get(url, __spreadValues({
|
|
1654
|
+
httpAgent,
|
|
1655
|
+
httpsAgent
|
|
1656
|
+
}, config));
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
__name(axiosGet, "axiosGet");
|
|
1500
1660
|
|
|
1501
1661
|
// packages/dts-plugin/src/core/configurations/remotePlugin.ts
|
|
1502
1662
|
var defaultOptions2 = {
|
|
@@ -1515,85 +1675,56 @@ var defaultOptions2 = {
|
|
|
1515
1675
|
extractRemoteTypes: false,
|
|
1516
1676
|
extractThirdParty: false
|
|
1517
1677
|
};
|
|
1518
|
-
var readTsConfig = ({
|
|
1519
|
-
tsConfigPath,
|
|
1520
|
-
typesFolder,
|
|
1521
|
-
compiledTypesFolder,
|
|
1522
|
-
context
|
|
1523
|
-
}) => {
|
|
1678
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context }) => {
|
|
1524
1679
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
1525
|
-
const readResult = import_typescript2.default.readConfigFile(
|
|
1526
|
-
resolvedTsConfigPath,
|
|
1527
|
-
import_typescript2.default.sys.readFile
|
|
1528
|
-
);
|
|
1680
|
+
const readResult = import_typescript2.default.readConfigFile(resolvedTsConfigPath, import_typescript2.default.sys.readFile);
|
|
1529
1681
|
if (readResult.error) {
|
|
1530
1682
|
throw new Error(readResult.error.messageText.toString());
|
|
1531
1683
|
}
|
|
1532
|
-
const configContent = import_typescript2.default.parseJsonConfigFileContent(
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
(0, import_path5.dirname)(resolvedTsConfigPath)
|
|
1536
|
-
);
|
|
1537
|
-
const outDir = (0, import_path5.resolve)(
|
|
1538
|
-
context,
|
|
1539
|
-
configContent.options.outDir || "dist",
|
|
1540
|
-
typesFolder,
|
|
1541
|
-
compiledTypesFolder
|
|
1542
|
-
);
|
|
1543
|
-
return {
|
|
1544
|
-
...configContent.options,
|
|
1684
|
+
const configContent = import_typescript2.default.parseJsonConfigFileContent(readResult.config, import_typescript2.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
|
|
1685
|
+
const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1686
|
+
return __spreadProps(__spreadValues({}, configContent.options), {
|
|
1545
1687
|
emitDeclarationOnly: true,
|
|
1546
1688
|
noEmit: false,
|
|
1547
1689
|
declaration: true,
|
|
1548
1690
|
outDir
|
|
1549
|
-
};
|
|
1550
|
-
};
|
|
1551
|
-
var TS_EXTENSIONS = [
|
|
1552
|
-
|
|
1691
|
+
});
|
|
1692
|
+
}, "readTsConfig");
|
|
1693
|
+
var TS_EXTENSIONS = [
|
|
1694
|
+
"ts",
|
|
1695
|
+
"tsx",
|
|
1696
|
+
"vue",
|
|
1697
|
+
"svelte"
|
|
1698
|
+
];
|
|
1699
|
+
var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
|
|
1553
1700
|
if ((0, import_path5.extname)(exposedPath)) {
|
|
1554
1701
|
return (0, import_path5.resolve)(context, exposedPath);
|
|
1555
1702
|
}
|
|
1556
1703
|
for (const extension of TS_EXTENSIONS) {
|
|
1557
|
-
const exposedPathWithExtension = (0, import_path5.resolve)(
|
|
1558
|
-
context,
|
|
1559
|
-
`${exposedPath}.${extension}`
|
|
1560
|
-
);
|
|
1704
|
+
const exposedPathWithExtension = (0, import_path5.resolve)(context, `${exposedPath}.${extension}`);
|
|
1561
1705
|
if ((0, import_fs3.existsSync)(exposedPathWithExtension)) {
|
|
1562
1706
|
return exposedPathWithExtension;
|
|
1563
1707
|
}
|
|
1564
1708
|
}
|
|
1565
1709
|
return void 0;
|
|
1566
|
-
};
|
|
1567
|
-
var resolveExposes = (remoteOptions) => {
|
|
1568
|
-
const parsedOptions = import_managers2.utils.parseOptions(
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(
|
|
1583
|
-
(0, import_path5.join)(exposePath, "index"),
|
|
1584
|
-
remoteOptions.context
|
|
1585
|
-
) || exposePath;
|
|
1586
|
-
return accumulator;
|
|
1587
|
-
},
|
|
1588
|
-
{}
|
|
1589
|
-
);
|
|
1590
|
-
};
|
|
1591
|
-
var retrieveRemoteConfig = (options) => {
|
|
1710
|
+
}, "resolveWithExtension");
|
|
1711
|
+
var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
|
|
1712
|
+
const parsedOptions = import_managers2.utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
|
|
1713
|
+
exposePath: Array.isArray(item) ? item[0] : item,
|
|
1714
|
+
key
|
|
1715
|
+
}), (item, key) => ({
|
|
1716
|
+
exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
|
|
1717
|
+
key
|
|
1718
|
+
}));
|
|
1719
|
+
return parsedOptions.reduce((accumulator, item) => {
|
|
1720
|
+
const { exposePath, key } = item[1];
|
|
1721
|
+
accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension((0, import_path5.join)(exposePath, "index"), remoteOptions.context) || exposePath;
|
|
1722
|
+
return accumulator;
|
|
1723
|
+
}, {});
|
|
1724
|
+
}, "resolveExposes");
|
|
1725
|
+
var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
1592
1726
|
validateOptions(options);
|
|
1593
|
-
const remoteOptions = {
|
|
1594
|
-
...defaultOptions2,
|
|
1595
|
-
...options
|
|
1596
|
-
};
|
|
1727
|
+
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1597
1728
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
1598
1729
|
const tsConfig = readTsConfig(remoteOptions);
|
|
1599
1730
|
return {
|
|
@@ -1601,17 +1732,18 @@ var retrieveRemoteConfig = (options) => {
|
|
|
1601
1732
|
mapComponentsToExpose,
|
|
1602
1733
|
remoteOptions
|
|
1603
1734
|
};
|
|
1604
|
-
};
|
|
1735
|
+
}, "retrieveRemoteConfig");
|
|
1605
1736
|
|
|
1606
1737
|
// packages/dts-plugin/src/core/lib/generateTypes.ts
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
(
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1738
|
+
function generateTypes(options) {
|
|
1739
|
+
return __async(this, null, function* () {
|
|
1740
|
+
var _a4;
|
|
1741
|
+
const DTSManagerConstructor = getDTSManagerConstructor((_a4 = options.remote) == null ? void 0 : _a4.implementation);
|
|
1742
|
+
const dtsManager = new DTSManagerConstructor(options);
|
|
1743
|
+
return dtsManager.generateTypes();
|
|
1744
|
+
});
|
|
1614
1745
|
}
|
|
1746
|
+
__name(generateTypes, "generateTypes");
|
|
1615
1747
|
|
|
1616
1748
|
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
1617
1749
|
var import_path6 = __toESM(require("path"));
|
|
@@ -1632,23 +1764,21 @@ __export(rpc_exports, {
|
|
|
1632
1764
|
var import_process = __toESM(require("process"));
|
|
1633
1765
|
|
|
1634
1766
|
// packages/dts-plugin/src/core/rpc/types.ts
|
|
1635
|
-
var RpcGMCallTypes
|
|
1767
|
+
var RpcGMCallTypes;
|
|
1768
|
+
(function(RpcGMCallTypes2) {
|
|
1636
1769
|
RpcGMCallTypes2["CALL"] = "mf_call";
|
|
1637
1770
|
RpcGMCallTypes2["RESOLVE"] = "mf_resolve";
|
|
1638
1771
|
RpcGMCallTypes2["REJECT"] = "mf_reject";
|
|
1639
1772
|
RpcGMCallTypes2["EXIT"] = "mf_exit";
|
|
1640
|
-
|
|
1641
|
-
})(RpcGMCallTypes || {});
|
|
1773
|
+
})(RpcGMCallTypes || (RpcGMCallTypes = {}));
|
|
1642
1774
|
|
|
1643
1775
|
// packages/dts-plugin/src/core/rpc/expose-rpc.ts
|
|
1644
1776
|
function exposeRpc(fn) {
|
|
1645
|
-
const sendMessage = (message) => new Promise((resolve5, reject) => {
|
|
1777
|
+
const sendMessage = /* @__PURE__ */ __name((message) => new Promise((resolve5, reject) => {
|
|
1646
1778
|
if (!import_process.default.send) {
|
|
1647
1779
|
reject(new Error(`Process ${import_process.default.pid} doesn't have IPC channels`));
|
|
1648
1780
|
} else if (!import_process.default.connected) {
|
|
1649
|
-
reject(
|
|
1650
|
-
new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`)
|
|
1651
|
-
);
|
|
1781
|
+
reject(new Error(`Process ${import_process.default.pid} doesn't have open IPC channels`));
|
|
1652
1782
|
} else {
|
|
1653
1783
|
import_process.default.send(message, void 0, void 0, (error2) => {
|
|
1654
1784
|
if (error2) {
|
|
@@ -1658,28 +1788,28 @@ function exposeRpc(fn) {
|
|
|
1658
1788
|
}
|
|
1659
1789
|
});
|
|
1660
1790
|
}
|
|
1661
|
-
});
|
|
1662
|
-
const handleMessage =
|
|
1663
|
-
if (message.type ===
|
|
1791
|
+
}), "sendMessage");
|
|
1792
|
+
const handleMessage = /* @__PURE__ */ __name((message) => __async(this, null, function* () {
|
|
1793
|
+
if (message.type === RpcGMCallTypes.CALL) {
|
|
1664
1794
|
if (!import_process.default.send) {
|
|
1665
1795
|
return;
|
|
1666
1796
|
}
|
|
1667
1797
|
let value, error2;
|
|
1668
1798
|
try {
|
|
1669
|
-
value =
|
|
1799
|
+
value = yield fn(...message.args);
|
|
1670
1800
|
} catch (fnError) {
|
|
1671
1801
|
error2 = fnError;
|
|
1672
1802
|
}
|
|
1673
1803
|
try {
|
|
1674
1804
|
if (error2) {
|
|
1675
|
-
|
|
1676
|
-
type:
|
|
1805
|
+
yield sendMessage({
|
|
1806
|
+
type: RpcGMCallTypes.REJECT,
|
|
1677
1807
|
id: message.id,
|
|
1678
1808
|
error: error2
|
|
1679
1809
|
});
|
|
1680
1810
|
} else {
|
|
1681
|
-
|
|
1682
|
-
type:
|
|
1811
|
+
yield sendMessage({
|
|
1812
|
+
type: RpcGMCallTypes.RESOLVE,
|
|
1683
1813
|
id: message.id,
|
|
1684
1814
|
value
|
|
1685
1815
|
});
|
|
@@ -1693,24 +1823,28 @@ function exposeRpc(fn) {
|
|
|
1693
1823
|
console.error(sendError);
|
|
1694
1824
|
}
|
|
1695
1825
|
}
|
|
1696
|
-
};
|
|
1826
|
+
}), "handleMessage");
|
|
1697
1827
|
import_process.default.on("message", handleMessage);
|
|
1698
1828
|
}
|
|
1829
|
+
__name(exposeRpc, "exposeRpc");
|
|
1699
1830
|
|
|
1700
1831
|
// packages/dts-plugin/src/core/rpc/rpc-error.ts
|
|
1701
|
-
var
|
|
1832
|
+
var _a2;
|
|
1833
|
+
var RpcExitError = (_a2 = class extends Error {
|
|
1702
1834
|
constructor(message, code, signal) {
|
|
1703
1835
|
super(message);
|
|
1836
|
+
__publicField(this, "code");
|
|
1837
|
+
__publicField(this, "signal");
|
|
1704
1838
|
this.code = code;
|
|
1705
1839
|
this.signal = signal;
|
|
1706
1840
|
this.name = "RpcExitError";
|
|
1707
1841
|
}
|
|
1708
|
-
};
|
|
1842
|
+
}, __name(_a2, "RpcExitError"), _a2);
|
|
1709
1843
|
|
|
1710
1844
|
// packages/dts-plugin/src/core/rpc/wrap-rpc.ts
|
|
1711
1845
|
function createControlledPromise() {
|
|
1712
|
-
let resolve5 = () => void 0;
|
|
1713
|
-
let reject = () => void 0;
|
|
1846
|
+
let resolve5 = /* @__PURE__ */ __name(() => void 0, "resolve");
|
|
1847
|
+
let reject = /* @__PURE__ */ __name(() => void 0, "reject");
|
|
1714
1848
|
const promise = new Promise((aResolve, aReject) => {
|
|
1715
1849
|
resolve5 = aResolve;
|
|
1716
1850
|
reject = aReject;
|
|
@@ -1721,76 +1855,59 @@ function createControlledPromise() {
|
|
|
1721
1855
|
reject
|
|
1722
1856
|
};
|
|
1723
1857
|
}
|
|
1858
|
+
__name(createControlledPromise, "createControlledPromise");
|
|
1724
1859
|
function wrapRpc(childProcess, options) {
|
|
1725
|
-
return
|
|
1860
|
+
return (...args) => __async(this, null, function* () {
|
|
1726
1861
|
if (!childProcess.send) {
|
|
1727
1862
|
throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
|
|
1728
1863
|
} else if (!childProcess.connected) {
|
|
1729
|
-
throw new Error(
|
|
1730
|
-
`Process ${childProcess.pid} doesn't have open IPC channels`
|
|
1731
|
-
);
|
|
1864
|
+
throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
|
|
1732
1865
|
}
|
|
1733
1866
|
const { id, once } = options;
|
|
1734
|
-
const {
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
reject: rejectResult
|
|
1738
|
-
} = createControlledPromise();
|
|
1739
|
-
const {
|
|
1740
|
-
promise: sendPromise,
|
|
1741
|
-
resolve: resolveSend,
|
|
1742
|
-
reject: rejectSend
|
|
1743
|
-
} = createControlledPromise();
|
|
1744
|
-
const handleMessage = (message) => {
|
|
1867
|
+
const { promise: resultPromise, resolve: resolveResult, reject: rejectResult } = createControlledPromise();
|
|
1868
|
+
const { promise: sendPromise, resolve: resolveSend, reject: rejectSend } = createControlledPromise();
|
|
1869
|
+
const handleMessage = /* @__PURE__ */ __name((message) => {
|
|
1745
1870
|
if ((message == null ? void 0 : message.id) === id) {
|
|
1746
|
-
if (message.type ===
|
|
1871
|
+
if (message.type === RpcGMCallTypes.RESOLVE) {
|
|
1747
1872
|
resolveResult(message.value);
|
|
1748
|
-
} else if (message.type ===
|
|
1873
|
+
} else if (message.type === RpcGMCallTypes.REJECT) {
|
|
1749
1874
|
rejectResult(message.error);
|
|
1750
1875
|
}
|
|
1751
1876
|
}
|
|
1752
1877
|
if (once && (childProcess == null ? void 0 : childProcess.kill)) {
|
|
1753
1878
|
childProcess.kill("SIGTERM");
|
|
1754
1879
|
}
|
|
1755
|
-
};
|
|
1756
|
-
const handleClose = (code, signal) => {
|
|
1757
|
-
rejectResult(
|
|
1758
|
-
new RpcExitError(
|
|
1759
|
-
code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`,
|
|
1760
|
-
code,
|
|
1761
|
-
signal
|
|
1762
|
-
)
|
|
1763
|
-
);
|
|
1880
|
+
}, "handleMessage");
|
|
1881
|
+
const handleClose = /* @__PURE__ */ __name((code, signal) => {
|
|
1882
|
+
rejectResult(new RpcExitError(code ? `Process ${childProcess.pid} exited with code ${code}${signal ? ` [${signal}]` : ""}` : `Process ${childProcess.pid} exited${signal ? ` [${signal}]` : ""}`, code, signal));
|
|
1764
1883
|
removeHandlers();
|
|
1765
|
-
};
|
|
1766
|
-
const removeHandlers = () => {
|
|
1884
|
+
}, "handleClose");
|
|
1885
|
+
const removeHandlers = /* @__PURE__ */ __name(() => {
|
|
1767
1886
|
childProcess.off("message", handleMessage);
|
|
1768
1887
|
childProcess.off("close", handleClose);
|
|
1769
|
-
};
|
|
1888
|
+
}, "removeHandlers");
|
|
1770
1889
|
if (once) {
|
|
1771
1890
|
childProcess.once("message", handleMessage);
|
|
1772
1891
|
} else {
|
|
1773
1892
|
childProcess.on("message", handleMessage);
|
|
1774
1893
|
}
|
|
1775
1894
|
childProcess.on("close", handleClose);
|
|
1776
|
-
childProcess.send(
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
} else {
|
|
1787
|
-
resolveSend(void 0);
|
|
1788
|
-
}
|
|
1895
|
+
childProcess.send({
|
|
1896
|
+
type: RpcGMCallTypes.CALL,
|
|
1897
|
+
id,
|
|
1898
|
+
args
|
|
1899
|
+
}, (error2) => {
|
|
1900
|
+
if (error2) {
|
|
1901
|
+
rejectSend(error2);
|
|
1902
|
+
removeHandlers();
|
|
1903
|
+
} else {
|
|
1904
|
+
resolveSend(void 0);
|
|
1789
1905
|
}
|
|
1790
|
-
);
|
|
1906
|
+
});
|
|
1791
1907
|
return sendPromise.then(() => resultPromise);
|
|
1792
|
-
};
|
|
1908
|
+
});
|
|
1793
1909
|
}
|
|
1910
|
+
__name(wrapRpc, "wrapRpc");
|
|
1794
1911
|
|
|
1795
1912
|
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
1796
1913
|
var child_process = __toESM(require("child_process"));
|
|
@@ -1799,15 +1916,21 @@ var import_crypto = require("crypto");
|
|
|
1799
1916
|
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
1800
1917
|
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
1801
1918
|
const options = {
|
|
1802
|
-
env: {
|
|
1803
|
-
...process3.env,
|
|
1919
|
+
env: __spreadProps(__spreadValues({}, process3.env), {
|
|
1804
1920
|
[FEDERATION_WORKER_DATA_ENV_KEY]: JSON.stringify(data || {})
|
|
1805
|
-
},
|
|
1806
|
-
stdio: [
|
|
1921
|
+
}),
|
|
1922
|
+
stdio: [
|
|
1923
|
+
"inherit",
|
|
1924
|
+
"inherit",
|
|
1925
|
+
"inherit",
|
|
1926
|
+
"ipc"
|
|
1927
|
+
],
|
|
1807
1928
|
serialization: "advanced"
|
|
1808
1929
|
};
|
|
1809
1930
|
if (memoryLimit) {
|
|
1810
|
-
options.execArgv = [
|
|
1931
|
+
options.execArgv = [
|
|
1932
|
+
`--max-old-space-size=${memoryLimit}`
|
|
1933
|
+
];
|
|
1811
1934
|
}
|
|
1812
1935
|
let childProcess, remoteMethod;
|
|
1813
1936
|
const id = (0, import_crypto.randomUUID)();
|
|
@@ -1815,7 +1938,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1815
1938
|
connect(...args) {
|
|
1816
1939
|
if (childProcess && !childProcess.connected) {
|
|
1817
1940
|
childProcess.send({
|
|
1818
|
-
type:
|
|
1941
|
+
type: RpcGMCallTypes.EXIT,
|
|
1819
1942
|
id
|
|
1820
1943
|
});
|
|
1821
1944
|
childProcess = void 0;
|
|
@@ -1823,19 +1946,20 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1823
1946
|
}
|
|
1824
1947
|
if (!(childProcess == null ? void 0 : childProcess.connected)) {
|
|
1825
1948
|
childProcess = child_process.fork(modulePath, options);
|
|
1826
|
-
remoteMethod = wrapRpc(childProcess, {
|
|
1949
|
+
remoteMethod = wrapRpc(childProcess, {
|
|
1950
|
+
id,
|
|
1951
|
+
once
|
|
1952
|
+
});
|
|
1827
1953
|
}
|
|
1828
1954
|
if (!remoteMethod) {
|
|
1829
|
-
return Promise.reject(
|
|
1830
|
-
new Error("Worker is not connected - cannot perform RPC.")
|
|
1831
|
-
);
|
|
1955
|
+
return Promise.reject(new Error("Worker is not connected - cannot perform RPC."));
|
|
1832
1956
|
}
|
|
1833
1957
|
return remoteMethod(...args);
|
|
1834
1958
|
},
|
|
1835
1959
|
terminate() {
|
|
1836
|
-
var
|
|
1837
|
-
(
|
|
1838
|
-
type:
|
|
1960
|
+
var _a4;
|
|
1961
|
+
(_a4 = childProcess == null ? void 0 : childProcess.send) == null ? void 0 : _a4.call(childProcess, {
|
|
1962
|
+
type: RpcGMCallTypes.EXIT,
|
|
1839
1963
|
id
|
|
1840
1964
|
});
|
|
1841
1965
|
childProcess = void 0;
|
|
@@ -1853,30 +1977,30 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1853
1977
|
};
|
|
1854
1978
|
return worker;
|
|
1855
1979
|
}
|
|
1980
|
+
__name(createRpcWorker, "createRpcWorker");
|
|
1856
1981
|
function getRpcWorkerData() {
|
|
1857
1982
|
return JSON.parse(process3.env[FEDERATION_WORKER_DATA_ENV_KEY] || "{}");
|
|
1858
1983
|
}
|
|
1984
|
+
__name(getRpcWorkerData, "getRpcWorkerData");
|
|
1859
1985
|
|
|
1860
1986
|
// packages/dts-plugin/src/core/lib/DtsWorker.ts
|
|
1861
|
-
var
|
|
1987
|
+
var _DtsWorker = class _DtsWorker {
|
|
1862
1988
|
constructor(options) {
|
|
1989
|
+
__publicField(this, "rpcWorker");
|
|
1990
|
+
__publicField(this, "_options");
|
|
1991
|
+
__publicField(this, "_res");
|
|
1863
1992
|
this._options = (0, import_lodash2.default)(options, (_value, key) => {
|
|
1864
1993
|
if (key === "manifest") {
|
|
1865
1994
|
return false;
|
|
1866
1995
|
}
|
|
1867
1996
|
});
|
|
1868
1997
|
this.removeUnSerializationOptions();
|
|
1869
|
-
this.rpcWorker = createRpcWorker(
|
|
1870
|
-
import_path6.default.resolve(__dirname, "./forkGenerateDts.js"),
|
|
1871
|
-
{},
|
|
1872
|
-
void 0,
|
|
1873
|
-
true
|
|
1874
|
-
);
|
|
1998
|
+
this.rpcWorker = createRpcWorker(import_path6.default.resolve(__dirname, "./fork-generate-dts.js"), {}, void 0, true);
|
|
1875
1999
|
this._res = this.rpcWorker.connect(this._options);
|
|
1876
2000
|
}
|
|
1877
2001
|
removeUnSerializationOptions() {
|
|
1878
|
-
var
|
|
1879
|
-
if ((_b = (
|
|
2002
|
+
var _a4, _b, _c, _d, _e, _f, _g, _h;
|
|
2003
|
+
if ((_b = (_a4 = this._options.remote) == null ? void 0 : _a4.moduleFederationConfig) == null ? void 0 : _b.manifest) {
|
|
1880
2004
|
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
1881
2005
|
}
|
|
1882
2006
|
if ((_f = (_e = this._options.host) == null ? void 0 : _e.moduleFederationConfig) == null ? void 0 : _f.manifest) {
|
|
@@ -1889,80 +2013,93 @@ var DtsWorker = class {
|
|
|
1889
2013
|
});
|
|
1890
2014
|
}
|
|
1891
2015
|
exit() {
|
|
1892
|
-
var
|
|
1893
|
-
(
|
|
2016
|
+
var _a4;
|
|
2017
|
+
(_a4 = this.rpcWorker) == null ? void 0 : _a4.terminate();
|
|
1894
2018
|
}
|
|
1895
2019
|
};
|
|
2020
|
+
__name(_DtsWorker, "DtsWorker");
|
|
2021
|
+
var DtsWorker = _DtsWorker;
|
|
1896
2022
|
|
|
1897
2023
|
// packages/dts-plugin/src/core/lib/generateTypesInChildProcess.ts
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
2024
|
+
function generateTypesInChildProcess(options) {
|
|
2025
|
+
return __async(this, null, function* () {
|
|
2026
|
+
const dtsWorker = new DtsWorker(options);
|
|
2027
|
+
return dtsWorker.controlledPromise;
|
|
2028
|
+
});
|
|
1901
2029
|
}
|
|
2030
|
+
__name(generateTypesInChildProcess, "generateTypesInChildProcess");
|
|
1902
2031
|
|
|
1903
2032
|
// packages/dts-plugin/src/core/lib/consumeTypes.ts
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
(
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
2033
|
+
function consumeTypes(options) {
|
|
2034
|
+
return __async(this, null, function* () {
|
|
2035
|
+
var _a4;
|
|
2036
|
+
const DTSManagerConstructor = getDTSManagerConstructor((_a4 = options.host) == null ? void 0 : _a4.implementation);
|
|
2037
|
+
const dtsManager = new DTSManagerConstructor(options);
|
|
2038
|
+
yield dtsManager.consumeTypes();
|
|
2039
|
+
});
|
|
1911
2040
|
}
|
|
2041
|
+
__name(consumeTypes, "consumeTypes");
|
|
1912
2042
|
|
|
1913
2043
|
// packages/dts-plugin/src/dev-worker/DevWorker.ts
|
|
1914
|
-
var
|
|
2044
|
+
var _DevWorker = class _DevWorker {
|
|
1915
2045
|
constructor(options) {
|
|
2046
|
+
__publicField(this, "_rpcWorker");
|
|
2047
|
+
__publicField(this, "_options");
|
|
2048
|
+
__publicField(this, "_res");
|
|
1916
2049
|
this._options = (0, import_lodash3.default)(options, (_value, key) => {
|
|
1917
2050
|
if (key === "manifest") {
|
|
1918
2051
|
return false;
|
|
1919
2052
|
}
|
|
1920
2053
|
});
|
|
1921
2054
|
this.removeUnSerializationOptions();
|
|
1922
|
-
this._rpcWorker = rpc_exports.createRpcWorker(
|
|
1923
|
-
import_path7.default.resolve(__dirname, "./forkDevWorker.js"),
|
|
1924
|
-
{},
|
|
1925
|
-
void 0,
|
|
1926
|
-
false
|
|
1927
|
-
);
|
|
2055
|
+
this._rpcWorker = rpc_exports.createRpcWorker(import_path7.default.resolve(__dirname, "./fork-dev-worker.js"), {}, void 0, false);
|
|
1928
2056
|
this._res = this._rpcWorker.connect(this._options);
|
|
1929
2057
|
}
|
|
1930
2058
|
// moduleFederationConfig.manifest may have un serialization options
|
|
1931
2059
|
removeUnSerializationOptions() {
|
|
1932
|
-
var
|
|
1933
|
-
(_b = (
|
|
2060
|
+
var _a4, _b, _c, _d;
|
|
2061
|
+
(_b = (_a4 = this._options.host) == null ? void 0 : _a4.moduleFederationConfig) == null ? true : delete _b.manifest;
|
|
1934
2062
|
(_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
|
|
1935
2063
|
}
|
|
1936
2064
|
get controlledPromise() {
|
|
1937
2065
|
return this._res;
|
|
1938
2066
|
}
|
|
1939
2067
|
update() {
|
|
1940
|
-
var
|
|
1941
|
-
(_b = (
|
|
2068
|
+
var _a4, _b;
|
|
2069
|
+
(_b = (_a4 = this._rpcWorker.process) == null ? void 0 : _a4.send) == null ? void 0 : _b.call(_a4, {
|
|
1942
2070
|
type: rpc_exports.RpcGMCallTypes.CALL,
|
|
1943
2071
|
id: this._rpcWorker.id,
|
|
1944
|
-
args: [
|
|
2072
|
+
args: [
|
|
2073
|
+
void 0,
|
|
2074
|
+
"update"
|
|
2075
|
+
]
|
|
1945
2076
|
});
|
|
1946
2077
|
}
|
|
1947
2078
|
exit() {
|
|
1948
|
-
var
|
|
1949
|
-
(
|
|
2079
|
+
var _a4;
|
|
2080
|
+
(_a4 = this._rpcWorker) == null ? void 0 : _a4.terminate();
|
|
1950
2081
|
}
|
|
1951
2082
|
};
|
|
2083
|
+
__name(_DevWorker, "DevWorker");
|
|
2084
|
+
var DevWorker = _DevWorker;
|
|
1952
2085
|
|
|
1953
2086
|
// packages/dts-plugin/src/dev-worker/createDevWorker.ts
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2087
|
+
function removeLogFile() {
|
|
2088
|
+
return __async(this, null, function* () {
|
|
2089
|
+
try {
|
|
2090
|
+
const logDir = path5.resolve(process.cwd(), ".mf/typesGenerate.log");
|
|
2091
|
+
yield fse.remove(logDir);
|
|
2092
|
+
} catch (err) {
|
|
2093
|
+
console.error("removeLogFile error", "forkDevWorker", err);
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
1961
2096
|
}
|
|
2097
|
+
__name(removeLogFile, "removeLogFile");
|
|
1962
2098
|
function createDevWorker(options) {
|
|
1963
2099
|
removeLogFile();
|
|
1964
|
-
return new DevWorker({
|
|
2100
|
+
return new DevWorker(__spreadValues({}, options));
|
|
1965
2101
|
}
|
|
2102
|
+
__name(createDevWorker, "createDevWorker");
|
|
1966
2103
|
|
|
1967
2104
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
1968
2105
|
var import_sdk5 = require("@module-federation/sdk");
|
|
@@ -1972,8 +2109,14 @@ var import_path8 = __toESM(require("path"));
|
|
|
1972
2109
|
function isDev() {
|
|
1973
2110
|
return process.env["NODE_ENV"] === "development";
|
|
1974
2111
|
}
|
|
2112
|
+
__name(isDev, "isDev");
|
|
1975
2113
|
|
|
1976
2114
|
// packages/dts-plugin/src/plugins/DevPlugin.ts
|
|
2115
|
+
var PROCESS_EXIT_CODE;
|
|
2116
|
+
(function(PROCESS_EXIT_CODE2) {
|
|
2117
|
+
PROCESS_EXIT_CODE2[PROCESS_EXIT_CODE2["SUCCESS"] = 0] = "SUCCESS";
|
|
2118
|
+
PROCESS_EXIT_CODE2[PROCESS_EXIT_CODE2["FAILURE"] = 1] = "FAILURE";
|
|
2119
|
+
})(PROCESS_EXIT_CODE || (PROCESS_EXIT_CODE = {}));
|
|
1977
2120
|
function ensureTempDir(filePath) {
|
|
1978
2121
|
try {
|
|
1979
2122
|
const dir = import_path8.default.dirname(filePath);
|
|
@@ -1981,137 +2124,117 @@ function ensureTempDir(filePath) {
|
|
|
1981
2124
|
} catch (_err) {
|
|
1982
2125
|
}
|
|
1983
2126
|
}
|
|
1984
|
-
|
|
2127
|
+
__name(ensureTempDir, "ensureTempDir");
|
|
2128
|
+
var _DevPlugin = class _DevPlugin {
|
|
1985
2129
|
constructor(options) {
|
|
1986
|
-
this
|
|
2130
|
+
__publicField(this, "name", "MFDevPlugin");
|
|
2131
|
+
__publicField(this, "_options");
|
|
2132
|
+
__publicField(this, "_devWorker");
|
|
1987
2133
|
this._options = options;
|
|
1988
2134
|
}
|
|
1989
2135
|
static ensureLiveReloadEntry(options, filePath) {
|
|
1990
2136
|
ensureTempDir(filePath);
|
|
1991
2137
|
const liveReloadEntry = import_fs_extra2.default.readFileSync(import_path8.default.join(__dirname, "./iife/launch-web-client.js")).toString("utf-8");
|
|
1992
|
-
const liveReloadEntryWithOptions = liveReloadEntry.replace(
|
|
1993
|
-
WEB_CLIENT_OPTIONS_IDENTIFIER,
|
|
1994
|
-
JSON.stringify(options)
|
|
1995
|
-
);
|
|
2138
|
+
const liveReloadEntryWithOptions = liveReloadEntry.replace(WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
|
|
1996
2139
|
import_fs_extra2.default.writeFileSync(filePath, liveReloadEntryWithOptions);
|
|
1997
2140
|
}
|
|
1998
2141
|
_stopWhenSIGTERMOrSIGINT() {
|
|
1999
2142
|
process.on("SIGTERM", () => {
|
|
2000
|
-
console.log(
|
|
2001
|
-
|
|
2002
|
-
);
|
|
2003
|
-
this._exit(0 /* SUCCESS */);
|
|
2143
|
+
console.log(import_chalk3.default`{cyan ${this._options.name} Process(${process.pid}) SIGTERM, mf server will exit...}`);
|
|
2144
|
+
this._exit(0);
|
|
2004
2145
|
});
|
|
2005
2146
|
process.on("SIGINT", () => {
|
|
2006
|
-
console.log(
|
|
2007
|
-
|
|
2008
|
-
);
|
|
2009
|
-
this._exit(0 /* SUCCESS */);
|
|
2147
|
+
console.log(import_chalk3.default`{cyan ${this._options.name} Process(${process.pid}) SIGINT, mf server will exit...}`);
|
|
2148
|
+
this._exit(0);
|
|
2010
2149
|
});
|
|
2011
2150
|
}
|
|
2012
2151
|
_handleUnexpectedExit() {
|
|
2013
2152
|
process.on("unhandledRejection", (error2) => {
|
|
2014
2153
|
console.error("Unhandled Rejection Error: ", error2);
|
|
2015
|
-
console.log(
|
|
2016
|
-
|
|
2017
|
-
);
|
|
2018
|
-
this._exit(1 /* FAILURE */);
|
|
2154
|
+
console.log(import_chalk3.default`{cyan ${this._options.name} Process(${process.pid}) unhandledRejection, mf server will exit...}`);
|
|
2155
|
+
this._exit(1);
|
|
2019
2156
|
});
|
|
2020
2157
|
process.on("uncaughtException", (error2) => {
|
|
2021
2158
|
console.error("Unhandled Rejection Error: ", error2);
|
|
2022
|
-
console.log(
|
|
2023
|
-
|
|
2024
|
-
);
|
|
2025
|
-
this._exit(1 /* FAILURE */);
|
|
2159
|
+
console.log(import_chalk3.default`{cyan ${this._options.name} Process(${process.pid}) uncaughtException, mf server will exit...}`);
|
|
2160
|
+
this._exit(1);
|
|
2026
2161
|
});
|
|
2027
2162
|
}
|
|
2028
2163
|
_exit(exitCode = 0) {
|
|
2029
|
-
var
|
|
2030
|
-
(
|
|
2164
|
+
var _a4;
|
|
2165
|
+
(_a4 = this._devWorker) == null ? void 0 : _a4.exit();
|
|
2031
2166
|
process.exit(exitCode);
|
|
2032
2167
|
}
|
|
2033
2168
|
_afterEmit() {
|
|
2034
|
-
var
|
|
2035
|
-
(
|
|
2169
|
+
var _a4;
|
|
2170
|
+
(_a4 = this._devWorker) == null ? void 0 : _a4.update();
|
|
2036
2171
|
}
|
|
2037
2172
|
apply(compiler) {
|
|
2038
|
-
const {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
"mfOptions.dev"
|
|
2048
|
-
)(dev);
|
|
2173
|
+
const { _options: { name, dev, dts } } = this;
|
|
2174
|
+
new compiler.webpack.DefinePlugin({
|
|
2175
|
+
FEDERATION_IPV4: JSON.stringify(getIPV4())
|
|
2176
|
+
}).apply(compiler);
|
|
2177
|
+
const normalizedDev = (0, import_sdk5.normalizeOptions)(true, {
|
|
2178
|
+
disableLiveReload: true,
|
|
2179
|
+
disableHotTypesReload: false,
|
|
2180
|
+
disableDynamicRemoteTypeHints: false
|
|
2181
|
+
}, "mfOptions.dev")(dev);
|
|
2049
2182
|
if (!isDev() || normalizedDev === false) {
|
|
2050
2183
|
return;
|
|
2051
2184
|
}
|
|
2052
|
-
if (normalizedDev.disableHotTypesReload && normalizedDev.disableLiveReload) {
|
|
2185
|
+
if (normalizedDev.disableHotTypesReload && normalizedDev.disableLiveReload && normalizedDev.disableDynamicRemoteTypeHints) {
|
|
2053
2186
|
return;
|
|
2054
2187
|
}
|
|
2055
2188
|
if (!name) {
|
|
2056
2189
|
throw new Error("name is required if you want to enable dev server!");
|
|
2057
2190
|
}
|
|
2191
|
+
if (!normalizedDev.disableDynamicRemoteTypeHints) {
|
|
2192
|
+
if (!this._options.runtimePlugins) {
|
|
2193
|
+
this._options.runtimePlugins = [];
|
|
2194
|
+
}
|
|
2195
|
+
this._options.runtimePlugins.push(import_path8.default.resolve(__dirname, "dynamic-remote-type-hints-plugin.js"));
|
|
2196
|
+
}
|
|
2058
2197
|
if (!normalizedDev.disableLiveReload) {
|
|
2059
|
-
const TEMP_DIR = import_path8.default.join(
|
|
2060
|
-
`${process.cwd()}/node_modules`,
|
|
2061
|
-
`.federation`
|
|
2062
|
-
);
|
|
2198
|
+
const TEMP_DIR = import_path8.default.join(`${process.cwd()}/node_modules`, `.federation`);
|
|
2063
2199
|
const filepath = import_path8.default.join(TEMP_DIR, `live-reload.js`);
|
|
2064
|
-
_DevPlugin.ensureLiveReloadEntry({
|
|
2200
|
+
_DevPlugin.ensureLiveReloadEntry({
|
|
2201
|
+
name
|
|
2202
|
+
}, filepath);
|
|
2065
2203
|
compiler.hooks.afterPlugins.tap("MFDevPlugin", () => {
|
|
2066
2204
|
new compiler.webpack.EntryPlugin(compiler.context, filepath, {
|
|
2067
2205
|
name
|
|
2068
2206
|
}).apply(compiler);
|
|
2069
2207
|
});
|
|
2070
2208
|
}
|
|
2071
|
-
const defaultGenerateTypes = {
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
)(dts);
|
|
2083
|
-
const normalizedGenerateTypes = (0, import_sdk5.normalizeOptions)(
|
|
2084
|
-
|
|
2085
|
-
defaultGenerateTypes,
|
|
2086
|
-
"mfOptions.dts.generateTypes"
|
|
2087
|
-
)(
|
|
2088
|
-
normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes
|
|
2089
|
-
);
|
|
2090
|
-
const remote = normalizedGenerateTypes === false ? void 0 : {
|
|
2209
|
+
const defaultGenerateTypes = {
|
|
2210
|
+
compileInChildProcess: true
|
|
2211
|
+
};
|
|
2212
|
+
const defaultConsumeTypes = {
|
|
2213
|
+
consumeAPITypes: true
|
|
2214
|
+
};
|
|
2215
|
+
const normalizedDtsOptions = (0, import_sdk5.normalizeOptions)(isTSProject(dts, compiler.context), {
|
|
2216
|
+
// remote types dist(.dev-server) not be used currently, so no need to set extractThirdParty etc
|
|
2217
|
+
generateTypes: defaultGenerateTypes,
|
|
2218
|
+
consumeTypes: defaultConsumeTypes,
|
|
2219
|
+
extraOptions: {}
|
|
2220
|
+
}, "mfOptions.dts")(dts);
|
|
2221
|
+
const normalizedGenerateTypes = (0, import_sdk5.normalizeOptions)(Boolean(normalizedDtsOptions), defaultGenerateTypes, "mfOptions.dts.generateTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes);
|
|
2222
|
+
const remote = normalizedGenerateTypes === false ? void 0 : __spreadProps(__spreadValues({
|
|
2091
2223
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2092
2224
|
context: compiler.context,
|
|
2093
|
-
moduleFederationConfig: {
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || "@mf-types",
|
|
2097
|
-
...normalizedGenerateTypes,
|
|
2225
|
+
moduleFederationConfig: __spreadValues({}, this._options),
|
|
2226
|
+
hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || "@mf-types"
|
|
2227
|
+
}, normalizedGenerateTypes), {
|
|
2098
2228
|
typesFolder: `.dev-server`
|
|
2099
|
-
};
|
|
2100
|
-
const normalizedConsumeTypes = (0, import_sdk5.normalizeOptions)(
|
|
2101
|
-
|
|
2102
|
-
defaultConsumeTypes,
|
|
2103
|
-
"mfOptions.dts.consumeTypes"
|
|
2104
|
-
)(
|
|
2105
|
-
normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.consumeTypes
|
|
2106
|
-
);
|
|
2107
|
-
const host = normalizedConsumeTypes === false ? void 0 : {
|
|
2229
|
+
});
|
|
2230
|
+
const normalizedConsumeTypes = (0, import_sdk5.normalizeOptions)(Boolean(normalizedDtsOptions), defaultConsumeTypes, "mfOptions.dts.consumeTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.consumeTypes);
|
|
2231
|
+
const host = normalizedConsumeTypes === false ? void 0 : __spreadValues({
|
|
2108
2232
|
implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
|
|
2109
2233
|
context: compiler.context,
|
|
2110
2234
|
moduleFederationConfig: this._options,
|
|
2111
|
-
typesFolder: "@mf-types",
|
|
2112
|
-
abortOnError: false
|
|
2113
|
-
|
|
2114
|
-
};
|
|
2235
|
+
typesFolder: normalizedConsumeTypes.typesFolder || "@mf-types",
|
|
2236
|
+
abortOnError: false
|
|
2237
|
+
}, normalizedConsumeTypes);
|
|
2115
2238
|
const extraOptions = normalizedDtsOptions ? normalizedDtsOptions.extraOptions || {} : {};
|
|
2116
2239
|
if (!remote && !host && normalizedDev.disableLiveReload) {
|
|
2117
2240
|
return;
|
|
@@ -2132,68 +2255,68 @@ var DevPlugin = class _DevPlugin {
|
|
|
2132
2255
|
compiler.hooks.afterEmit.tap(this.name, this._afterEmit.bind(this));
|
|
2133
2256
|
}
|
|
2134
2257
|
};
|
|
2258
|
+
__name(_DevPlugin, "DevPlugin");
|
|
2259
|
+
var DevPlugin = _DevPlugin;
|
|
2135
2260
|
|
|
2136
2261
|
// packages/dts-plugin/src/plugins/TypesPlugin.ts
|
|
2137
2262
|
var import_sdk8 = require("@module-federation/sdk");
|
|
2138
2263
|
|
|
2139
2264
|
// packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
|
|
2140
2265
|
var import_sdk6 = require("@module-federation/sdk");
|
|
2141
|
-
var
|
|
2266
|
+
var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
|
|
2142
2267
|
constructor(pluginOptions, dtsOptions, defaultOptions3) {
|
|
2268
|
+
__publicField(this, "pluginOptions");
|
|
2269
|
+
__publicField(this, "dtsOptions");
|
|
2270
|
+
__publicField(this, "defaultOptions");
|
|
2143
2271
|
this.pluginOptions = pluginOptions;
|
|
2144
2272
|
this.dtsOptions = dtsOptions;
|
|
2145
2273
|
this.defaultOptions = defaultOptions3;
|
|
2146
2274
|
}
|
|
2147
2275
|
apply(compiler) {
|
|
2148
2276
|
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions } = this;
|
|
2149
|
-
const normalizedConsumeTypes = (0, import_sdk6.normalizeOptions)(
|
|
2150
|
-
true,
|
|
2151
|
-
defaultOptions3,
|
|
2152
|
-
"mfOptions.dts.consumeTypes"
|
|
2153
|
-
)(dtsOptions.consumeTypes);
|
|
2277
|
+
const normalizedConsumeTypes = (0, import_sdk6.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
|
|
2154
2278
|
if (!normalizedConsumeTypes) {
|
|
2155
2279
|
return;
|
|
2156
2280
|
}
|
|
2157
2281
|
const finalOptions = {
|
|
2158
|
-
host: {
|
|
2282
|
+
host: __spreadValues({
|
|
2159
2283
|
implementation: dtsOptions.implementation,
|
|
2160
2284
|
context: compiler.context,
|
|
2161
|
-
moduleFederationConfig: pluginOptions
|
|
2162
|
-
|
|
2163
|
-
},
|
|
2285
|
+
moduleFederationConfig: pluginOptions
|
|
2286
|
+
}, normalizedConsumeTypes),
|
|
2164
2287
|
extraOptions: dtsOptions.extraOptions || {}
|
|
2165
2288
|
};
|
|
2166
2289
|
validateOptions(finalOptions.host);
|
|
2167
2290
|
consumeTypes(finalOptions);
|
|
2168
2291
|
}
|
|
2169
2292
|
};
|
|
2293
|
+
__name(_ConsumeTypesPlugin, "ConsumeTypesPlugin");
|
|
2294
|
+
var ConsumeTypesPlugin = _ConsumeTypesPlugin;
|
|
2170
2295
|
|
|
2171
2296
|
// packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
|
|
2172
2297
|
var import_fs4 = __toESM(require("fs"));
|
|
2173
2298
|
var import_sdk7 = require("@module-federation/sdk");
|
|
2174
|
-
var
|
|
2299
|
+
var _GenerateTypesPlugin = class _GenerateTypesPlugin {
|
|
2175
2300
|
constructor(pluginOptions, dtsOptions, defaultOptions3) {
|
|
2301
|
+
__publicField(this, "pluginOptions");
|
|
2302
|
+
__publicField(this, "dtsOptions");
|
|
2303
|
+
__publicField(this, "defaultOptions");
|
|
2176
2304
|
this.pluginOptions = pluginOptions;
|
|
2177
2305
|
this.dtsOptions = dtsOptions;
|
|
2178
2306
|
this.defaultOptions = defaultOptions3;
|
|
2179
2307
|
}
|
|
2180
2308
|
apply(compiler) {
|
|
2181
2309
|
const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions } = this;
|
|
2182
|
-
const normalizedGenerateTypes = (0, import_sdk7.normalizeOptions)(
|
|
2183
|
-
true,
|
|
2184
|
-
defaultOptions3,
|
|
2185
|
-
"mfOptions.dts.generateTypes"
|
|
2186
|
-
)(dtsOptions.generateTypes);
|
|
2310
|
+
const normalizedGenerateTypes = (0, import_sdk7.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
|
|
2187
2311
|
if (!normalizedGenerateTypes) {
|
|
2188
2312
|
return;
|
|
2189
2313
|
}
|
|
2190
2314
|
const finalOptions = {
|
|
2191
|
-
remote: {
|
|
2315
|
+
remote: __spreadValues({
|
|
2192
2316
|
implementation: dtsOptions.implementation,
|
|
2193
2317
|
context: compiler.context,
|
|
2194
|
-
moduleFederationConfig: pluginOptions
|
|
2195
|
-
|
|
2196
|
-
},
|
|
2318
|
+
moduleFederationConfig: pluginOptions
|
|
2319
|
+
}, normalizedGenerateTypes),
|
|
2197
2320
|
extraOptions: dtsOptions.extraOptions || {}
|
|
2198
2321
|
};
|
|
2199
2322
|
if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
|
|
@@ -2201,7 +2324,7 @@ var GenerateTypesPlugin = class {
|
|
|
2201
2324
|
}
|
|
2202
2325
|
validateOptions(finalOptions.remote);
|
|
2203
2326
|
const isProd = !isDev();
|
|
2204
|
-
const getGenerateTypesFn = () => {
|
|
2327
|
+
const getGenerateTypesFn = /* @__PURE__ */ __name(() => {
|
|
2205
2328
|
let fn = generateTypes;
|
|
2206
2329
|
let res;
|
|
2207
2330
|
if (finalOptions.remote.compileInChildProcess) {
|
|
@@ -2212,54 +2335,43 @@ var GenerateTypesPlugin = class {
|
|
|
2212
2335
|
return () => res;
|
|
2213
2336
|
}
|
|
2214
2337
|
return fn;
|
|
2215
|
-
};
|
|
2338
|
+
}, "getGenerateTypesFn");
|
|
2216
2339
|
const generateTypesFn = getGenerateTypesFn();
|
|
2217
2340
|
compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
|
|
2218
|
-
compilation.hooks.processAssets.tapPromise(
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
if (zipTypesPath) {
|
|
2234
|
-
compilation.emitAsset(
|
|
2235
|
-
zipName,
|
|
2236
|
-
new compiler.webpack.sources.RawSource(
|
|
2237
|
-
import_fs4.default.readFileSync(zipTypesPath),
|
|
2238
|
-
false
|
|
2239
|
-
)
|
|
2240
|
-
);
|
|
2241
|
-
}
|
|
2242
|
-
if (apiTypesPath) {
|
|
2243
|
-
compilation.emitAsset(
|
|
2244
|
-
apiFileName,
|
|
2245
|
-
new compiler.webpack.sources.RawSource(
|
|
2246
|
-
import_fs4.default.readFileSync(apiTypesPath),
|
|
2247
|
-
false
|
|
2248
|
-
)
|
|
2249
|
-
);
|
|
2250
|
-
}
|
|
2251
|
-
} catch (err) {
|
|
2252
|
-
console.error(err);
|
|
2341
|
+
compilation.hooks.processAssets.tapPromise({
|
|
2342
|
+
name: "mf:generateTypes",
|
|
2343
|
+
stage: (
|
|
2344
|
+
// @ts-expect-error use runtime variable in case peer dep not installed
|
|
2345
|
+
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
2346
|
+
)
|
|
2347
|
+
}, () => __async(this, null, function* () {
|
|
2348
|
+
try {
|
|
2349
|
+
const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(finalOptions.remote);
|
|
2350
|
+
if (zipName && compilation.getAsset(zipName)) {
|
|
2351
|
+
return;
|
|
2352
|
+
}
|
|
2353
|
+
yield generateTypesFn(finalOptions);
|
|
2354
|
+
if (zipTypesPath) {
|
|
2355
|
+
compilation.emitAsset(zipName, new compiler.webpack.sources.RawSource(import_fs4.default.readFileSync(zipTypesPath), false));
|
|
2253
2356
|
}
|
|
2357
|
+
if (apiTypesPath) {
|
|
2358
|
+
compilation.emitAsset(apiFileName, new compiler.webpack.sources.RawSource(import_fs4.default.readFileSync(apiTypesPath), false));
|
|
2359
|
+
}
|
|
2360
|
+
} catch (err) {
|
|
2361
|
+
console.error(err);
|
|
2254
2362
|
}
|
|
2255
|
-
);
|
|
2363
|
+
}));
|
|
2256
2364
|
});
|
|
2257
2365
|
}
|
|
2258
2366
|
};
|
|
2367
|
+
__name(_GenerateTypesPlugin, "GenerateTypesPlugin");
|
|
2368
|
+
var GenerateTypesPlugin = _GenerateTypesPlugin;
|
|
2259
2369
|
|
|
2260
2370
|
// packages/dts-plugin/src/plugins/TypesPlugin.ts
|
|
2261
|
-
var
|
|
2371
|
+
var _a3;
|
|
2372
|
+
var TypesPlugin = (_a3 = class {
|
|
2262
2373
|
constructor(options) {
|
|
2374
|
+
__publicField(this, "options");
|
|
2263
2375
|
this.options = options;
|
|
2264
2376
|
}
|
|
2265
2377
|
apply(compiler) {
|
|
@@ -2271,35 +2383,27 @@ var TypesPlugin = class {
|
|
|
2271
2383
|
extractThirdParty: true,
|
|
2272
2384
|
extractRemoteTypes: true
|
|
2273
2385
|
};
|
|
2274
|
-
const defaultConsumeTypes = {
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
}
|
|
2282
|
-
|
|
2283
|
-
)(options.dts);
|
|
2386
|
+
const defaultConsumeTypes = {
|
|
2387
|
+
abortOnError: false,
|
|
2388
|
+
consumeAPITypes: true
|
|
2389
|
+
};
|
|
2390
|
+
const normalizedDtsOptions = (0, import_sdk8.normalizeOptions)(isTSProject(options.dts, compiler.context), {
|
|
2391
|
+
generateTypes: defaultGenerateTypes,
|
|
2392
|
+
consumeTypes: defaultConsumeTypes,
|
|
2393
|
+
extraOptions: {}
|
|
2394
|
+
}, "mfOptions.dts")(options.dts);
|
|
2284
2395
|
if (typeof normalizedDtsOptions !== "object") {
|
|
2285
2396
|
return;
|
|
2286
2397
|
}
|
|
2287
|
-
new GenerateTypesPlugin(
|
|
2288
|
-
|
|
2289
|
-
normalizedDtsOptions,
|
|
2290
|
-
defaultGenerateTypes
|
|
2291
|
-
).apply(compiler);
|
|
2292
|
-
new ConsumeTypesPlugin(
|
|
2293
|
-
options,
|
|
2294
|
-
normalizedDtsOptions,
|
|
2295
|
-
defaultConsumeTypes
|
|
2296
|
-
).apply(compiler);
|
|
2398
|
+
new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes).apply(compiler);
|
|
2399
|
+
new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes).apply(compiler);
|
|
2297
2400
|
}
|
|
2298
|
-
};
|
|
2401
|
+
}, __name(_a3, "TypesPlugin"), _a3);
|
|
2299
2402
|
|
|
2300
2403
|
// packages/dts-plugin/src/plugins/DtsPlugin.ts
|
|
2301
|
-
var
|
|
2404
|
+
var _DtsPlugin = class _DtsPlugin {
|
|
2302
2405
|
constructor(options) {
|
|
2406
|
+
__publicField(this, "options");
|
|
2303
2407
|
this.options = options;
|
|
2304
2408
|
}
|
|
2305
2409
|
apply(compiler) {
|
|
@@ -2308,6 +2412,8 @@ var DtsPlugin = class {
|
|
|
2308
2412
|
new TypesPlugin(options).apply(compiler);
|
|
2309
2413
|
}
|
|
2310
2414
|
};
|
|
2415
|
+
__name(_DtsPlugin, "DtsPlugin");
|
|
2416
|
+
var DtsPlugin = _DtsPlugin;
|
|
2311
2417
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2312
2418
|
0 && (module.exports = {
|
|
2313
2419
|
DtsPlugin
|