@module-federation/dts-plugin 0.0.0-chore-bump-node-22-20260710161714

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/index.js ADDED
@@ -0,0 +1,517 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_Action = require('./Action-CzhPMw2i.js');
3
+ const require_Broker = require('./Broker-CaenCqdn.js');
4
+ const require_expose_rpc = require('./expose-rpc-BpRiu3VK.js');
5
+ const require_consumeTypes = require('./consumeTypes-Dle9g2SZ.js');
6
+ require('./core.js');
7
+ let fs = require("fs");
8
+ fs = require_Action.__toESM(fs);
9
+ let url = require("url");
10
+ let path = require("path");
11
+ path = require_Action.__toESM(path);
12
+ let fs_promises = require("fs/promises");
13
+ let _module_federation_sdk = require("@module-federation/sdk");
14
+
15
+ //#region src/dev-worker/DevWorker.ts
16
+ const __filename$2 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
17
+ const __dirname$2 = path.default.dirname(__filename$2);
18
+ var DevWorker = class {
19
+ constructor(options) {
20
+ this._options = require_expose_rpc.cloneDeepOptions(options);
21
+ this.removeUnSerializationOptions();
22
+ this._rpcWorker = require_consumeTypes.createRpcWorker(path.default.resolve(__dirname$2, "./fork-dev-worker.js"), {}, void 0, false);
23
+ this._res = this._rpcWorker.connect(this._options);
24
+ }
25
+ removeUnSerializationOptions() {
26
+ delete this._options.host?.moduleFederationConfig?.manifest;
27
+ delete this._options.remote?.moduleFederationConfig?.manifest;
28
+ }
29
+ get controlledPromise() {
30
+ return this._res;
31
+ }
32
+ update() {
33
+ this._rpcWorker.process?.send?.({
34
+ type: require_expose_rpc.RpcGMCallTypes.CALL,
35
+ id: this._rpcWorker.id,
36
+ args: [void 0, "update"]
37
+ });
38
+ }
39
+ exit() {
40
+ this._rpcWorker?.terminate();
41
+ }
42
+ };
43
+
44
+ //#endregion
45
+ //#region src/dev-worker/createDevWorker.ts
46
+ async function removeLogFile() {
47
+ try {
48
+ await (0, fs_promises.rm)(path.resolve(process.cwd(), ".mf/typesGenerate.log"), {
49
+ force: true,
50
+ recursive: true
51
+ });
52
+ } catch (err) {
53
+ console.error("removeLogFile error", "forkDevWorker", err);
54
+ }
55
+ }
56
+ function createDevWorker(options) {
57
+ removeLogFile();
58
+ return new DevWorker({ ...options });
59
+ }
60
+
61
+ //#endregion
62
+ //#region src/plugins/utils.ts
63
+ function isDev() {
64
+ return process.env["NODE_ENV"] === "development";
65
+ }
66
+ function isPrd() {
67
+ return process.env["NODE_ENV"] === "production";
68
+ }
69
+ function getCompilerOutputDir(compiler) {
70
+ try {
71
+ return path.default.relative(compiler.context, compiler.outputPath || compiler.options.output.path);
72
+ } catch (err) {
73
+ return "";
74
+ }
75
+ }
76
+
77
+ //#endregion
78
+ //#region src/plugins/DevPlugin.ts
79
+ const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
80
+ const __dirname$1 = path.default.dirname(__filename$1);
81
+ var PROCESS_EXIT_CODE = /* @__PURE__ */ function(PROCESS_EXIT_CODE) {
82
+ PROCESS_EXIT_CODE[PROCESS_EXIT_CODE["SUCCESS"] = 0] = "SUCCESS";
83
+ PROCESS_EXIT_CODE[PROCESS_EXIT_CODE["FAILURE"] = 1] = "FAILURE";
84
+ return PROCESS_EXIT_CODE;
85
+ }(PROCESS_EXIT_CODE || {});
86
+ function ensureTempDir(filePath) {
87
+ try {
88
+ const dir = path.default.dirname(filePath);
89
+ fs.default.mkdirSync(dir, { recursive: true });
90
+ } catch (_err) {}
91
+ }
92
+ var DevPlugin = class DevPlugin {
93
+ constructor(options, dtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise) {
94
+ this.name = "MFDevPlugin";
95
+ this._options = options;
96
+ this.generateTypesPromise = generateTypesPromise;
97
+ this.dtsOptions = dtsOptions;
98
+ this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
99
+ }
100
+ static ensureLiveReloadEntry(options, filePath) {
101
+ ensureTempDir(filePath);
102
+ const liveReloadEntryWithOptions = fs.default.readFileSync(path.default.join(__dirname$1, "./iife/launch-web-client.iife.js")).toString("utf-8").replace(require_Action.WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
103
+ fs.default.writeFileSync(filePath, liveReloadEntryWithOptions);
104
+ }
105
+ _stopWhenSIGTERMOrSIGINT() {
106
+ process.on("SIGTERM", () => {
107
+ require_Broker.logger.info(`${this._options.name} Process(${process.pid}) SIGTERM, mf server will exit...`);
108
+ this._exit(PROCESS_EXIT_CODE.SUCCESS);
109
+ });
110
+ process.on("SIGINT", () => {
111
+ require_Broker.logger.info(`${this._options.name} Process(${process.pid}) SIGINT, mf server will exit...`);
112
+ this._exit(PROCESS_EXIT_CODE.SUCCESS);
113
+ });
114
+ }
115
+ _handleUnexpectedExit() {
116
+ process.on("unhandledRejection", (error) => {
117
+ require_Broker.logger.error(error);
118
+ require_Broker.logger.error(`Process(${process.pid}) unhandledRejection, mf server will exit...`);
119
+ this._exit(PROCESS_EXIT_CODE.FAILURE);
120
+ });
121
+ process.on("uncaughtException", (error) => {
122
+ require_Broker.logger.error(error);
123
+ require_Broker.logger.error(`Process(${process.pid}) uncaughtException, mf server will exit...`);
124
+ this._exit(PROCESS_EXIT_CODE.FAILURE);
125
+ });
126
+ }
127
+ _exit(exitCode = 0) {
128
+ this._devWorker?.exit();
129
+ process.exit(exitCode);
130
+ }
131
+ _afterEmit() {
132
+ this._devWorker?.update();
133
+ }
134
+ apply(compiler) {
135
+ const { _options: { name, dev, dts } } = this;
136
+ const normalizedDev = (0, _module_federation_sdk.normalizeOptions)(true, {
137
+ disableLiveReload: true,
138
+ disableHotTypesReload: false,
139
+ disableDynamicRemoteTypeHints: false
140
+ }, "mfOptions.dev")(dev);
141
+ if (!isDev() || normalizedDev === false) return;
142
+ new compiler.webpack.DefinePlugin({ FEDERATION_IPV4: JSON.stringify(require_Broker.getIPV4()) }).apply(compiler);
143
+ if (normalizedDev.disableHotTypesReload && normalizedDev.disableLiveReload && normalizedDev.disableDynamicRemoteTypeHints) return;
144
+ if (!name) throw new Error("name is required if you want to enable dev server!");
145
+ if (!normalizedDev.disableDynamicRemoteTypeHints) {
146
+ if (!this._options.runtimePlugins) this._options.runtimePlugins = [];
147
+ this._options.runtimePlugins.push(path.default.resolve(__dirname$1, "dynamic-remote-type-hints-plugin.js"));
148
+ }
149
+ if (!normalizedDev.disableLiveReload) {
150
+ const TEMP_DIR = path.default.join(`${process.cwd()}/node_modules`, _module_federation_sdk.TEMP_DIR);
151
+ const filepath = path.default.join(TEMP_DIR, `live-reload.js`);
152
+ if (typeof compiler.options.entry === "object") {
153
+ DevPlugin.ensureLiveReloadEntry({ name }, filepath);
154
+ Object.keys(compiler.options.entry).forEach((entry) => {
155
+ const normalizedEntry = compiler.options.entry[entry];
156
+ if (typeof normalizedEntry === "object" && Array.isArray(normalizedEntry.import)) normalizedEntry.import.unshift(filepath);
157
+ });
158
+ }
159
+ }
160
+ const defaultGenerateTypes = { compileInChildProcess: true };
161
+ const defaultConsumeTypes = { consumeAPITypes: true };
162
+ const normalizedDtsOptions = (0, _module_federation_sdk.normalizeOptions)(require_expose_rpc.isTSProject(dts, compiler.context), {
163
+ generateTypes: defaultGenerateTypes,
164
+ consumeTypes: defaultConsumeTypes,
165
+ extraOptions: {},
166
+ displayErrorInTerminal: this.dtsOptions?.displayErrorInTerminal
167
+ }, "mfOptions.dts")(dts);
168
+ const normalizedGenerateTypes = (0, _module_federation_sdk.normalizeOptions)(Boolean(normalizedDtsOptions), defaultGenerateTypes, "mfOptions.dts.generateTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes);
169
+ const remote = normalizedGenerateTypes === false ? void 0 : {
170
+ implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
171
+ context: compiler.context,
172
+ outputDir: getCompilerOutputDir(compiler),
173
+ moduleFederationConfig: { ...this._options },
174
+ hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || "@mf-types",
175
+ ...normalizedGenerateTypes,
176
+ typesFolder: `.dev-server`
177
+ };
178
+ const normalizedConsumeTypes = (0, _module_federation_sdk.normalizeOptions)(Boolean(normalizedDtsOptions), defaultConsumeTypes, "mfOptions.dts.consumeTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.consumeTypes);
179
+ const host = normalizedConsumeTypes === false ? void 0 : {
180
+ implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
181
+ context: compiler.context,
182
+ moduleFederationConfig: this._options,
183
+ typesFolder: normalizedConsumeTypes.typesFolder || "@mf-types",
184
+ abortOnError: false,
185
+ ...normalizedConsumeTypes
186
+ };
187
+ const extraOptions = normalizedDtsOptions ? normalizedDtsOptions.extraOptions || {} : {};
188
+ if (!remote && !host && normalizedDev.disableLiveReload) return;
189
+ if (remote && !remote?.tsConfigPath && typeof normalizedDtsOptions === "object" && normalizedDtsOptions.tsConfigPath) remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
190
+ Promise.all([this.generateTypesPromise, this.fetchRemoteTypeUrlsPromise]).then(([_, remoteTypeUrls]) => {
191
+ this._devWorker = createDevWorker({
192
+ name,
193
+ remote,
194
+ host: {
195
+ moduleFederationConfig: {},
196
+ ...host,
197
+ remoteTypeUrls
198
+ },
199
+ extraOptions,
200
+ disableLiveReload: normalizedDev.disableHotTypesReload,
201
+ disableHotTypesReload: normalizedDev.disableHotTypesReload
202
+ });
203
+ });
204
+ this._stopWhenSIGTERMOrSIGINT();
205
+ this._handleUnexpectedExit();
206
+ compiler.hooks.afterEmit.tap(this.name, this._afterEmit.bind(this));
207
+ }
208
+ };
209
+
210
+ //#endregion
211
+ //#region src/plugins/ConsumeTypesPlugin.ts
212
+ const DEFAULT_CONSUME_TYPES = {
213
+ abortOnError: false,
214
+ consumeAPITypes: true,
215
+ typesOnBuild: false
216
+ };
217
+ const normalizeConsumeTypesOptions = ({ context, dtsOptions, pluginOptions }) => {
218
+ const normalizedConsumeTypes = (0, _module_federation_sdk.normalizeOptions)(true, DEFAULT_CONSUME_TYPES, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
219
+ if (!normalizedConsumeTypes) return;
220
+ const dtsManagerOptions = {
221
+ host: {
222
+ implementation: dtsOptions.implementation,
223
+ context,
224
+ moduleFederationConfig: pluginOptions,
225
+ ...normalizedConsumeTypes
226
+ },
227
+ extraOptions: dtsOptions.extraOptions || {},
228
+ displayErrorInTerminal: dtsOptions.displayErrorInTerminal
229
+ };
230
+ require_expose_rpc.validateOptions(dtsManagerOptions.host);
231
+ return dtsManagerOptions;
232
+ };
233
+ const consumeTypesAPI = async (dtsManagerOptions, cb) => {
234
+ return (typeof dtsManagerOptions.host.remoteTypeUrls === "function" ? dtsManagerOptions.host.remoteTypeUrls() : Promise.resolve(dtsManagerOptions.host.remoteTypeUrls)).then((remoteTypeUrls) => {
235
+ require_consumeTypes.consumeTypes({
236
+ ...dtsManagerOptions,
237
+ host: {
238
+ ...dtsManagerOptions.host,
239
+ remoteTypeUrls
240
+ }
241
+ }).then(() => {
242
+ typeof cb === "function" && cb(remoteTypeUrls);
243
+ }).catch(() => {
244
+ typeof cb === "function" && cb(remoteTypeUrls);
245
+ });
246
+ });
247
+ };
248
+ var ConsumeTypesPlugin = class {
249
+ constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsResolve) {
250
+ this.pluginOptions = pluginOptions;
251
+ this.dtsOptions = dtsOptions;
252
+ this.fetchRemoteTypeUrlsResolve = fetchRemoteTypeUrlsResolve;
253
+ }
254
+ apply(compiler) {
255
+ const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
256
+ const dtsManagerOptions = normalizeConsumeTypesOptions({
257
+ context: compiler.context,
258
+ dtsOptions,
259
+ pluginOptions
260
+ });
261
+ if (!dtsManagerOptions) {
262
+ fetchRemoteTypeUrlsResolve(void 0);
263
+ return;
264
+ }
265
+ if (isPrd() && !dtsManagerOptions.host.typesOnBuild) {
266
+ fetchRemoteTypeUrlsResolve(void 0);
267
+ return;
268
+ }
269
+ _module_federation_sdk.infrastructureLogger.debug("start fetching remote types...");
270
+ const promise = consumeTypesAPI(dtsManagerOptions, fetchRemoteTypeUrlsResolve);
271
+ compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
272
+ compilation.hooks.processAssets.tapPromise({
273
+ name: "mf:generateTypes",
274
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 1
275
+ }, async () => {
276
+ await promise;
277
+ _module_federation_sdk.infrastructureLogger.debug("fetch remote types success!");
278
+ });
279
+ });
280
+ }
281
+ };
282
+
283
+ //#endregion
284
+ //#region src/plugins/GenerateTypesPlugin.ts
285
+ const DEFAULT_GENERATE_TYPES = {
286
+ generateAPITypes: true,
287
+ compileInChildProcess: true,
288
+ abortOnError: false,
289
+ extractThirdParty: false,
290
+ extractRemoteTypes: false
291
+ };
292
+ const normalizeGenerateTypesOptions = ({ context, outputDir, dtsOptions, pluginOptions }) => {
293
+ const normalizedGenerateTypes = (0, _module_federation_sdk.normalizeOptions)(true, DEFAULT_GENERATE_TYPES, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
294
+ if (!normalizedGenerateTypes) return;
295
+ const normalizedConsumeTypes = (0, _module_federation_sdk.normalizeOptions)(true, {}, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
296
+ const finalOptions = {
297
+ remote: {
298
+ implementation: dtsOptions.implementation,
299
+ context,
300
+ outputDir,
301
+ moduleFederationConfig: pluginOptions,
302
+ ...normalizedGenerateTypes
303
+ },
304
+ host: normalizedConsumeTypes === false ? void 0 : {
305
+ context,
306
+ moduleFederationConfig: pluginOptions,
307
+ ...normalizedConsumeTypes,
308
+ remoteTypeUrls: typeof normalizedConsumeTypes?.remoteTypeUrls === "object" ? normalizedConsumeTypes?.remoteTypeUrls : void 0
309
+ },
310
+ extraOptions: dtsOptions.extraOptions || {},
311
+ displayErrorInTerminal: dtsOptions.displayErrorInTerminal
312
+ };
313
+ if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) finalOptions.remote.tsConfigPath = dtsOptions.tsConfigPath;
314
+ require_expose_rpc.validateOptions(finalOptions.remote);
315
+ return finalOptions;
316
+ };
317
+ const getGenerateTypesFn = (dtsManagerOptions) => {
318
+ let fn = require_expose_rpc.generateTypes;
319
+ if (dtsManagerOptions.remote.compileInChildProcess) fn = require_consumeTypes.generateTypesInChildProcess;
320
+ return fn;
321
+ };
322
+ const generateTypesAPI = ({ dtsManagerOptions }) => {
323
+ return getGenerateTypesFn(dtsManagerOptions)(dtsManagerOptions).then(async () => {
324
+ await callAfterGenerateHook({
325
+ dtsManagerOptions,
326
+ generatedTypes: require_expose_rpc.retrieveTypesAssetsInfo(dtsManagerOptions.remote)
327
+ });
328
+ });
329
+ };
330
+ const callAfterGenerateHook = async ({ dtsManagerOptions, generatedTypes }) => {
331
+ const afterGenerate = dtsManagerOptions.remote.afterGenerate;
332
+ if (!afterGenerate) return;
333
+ try {
334
+ await afterGenerate(generatedTypes);
335
+ } catch (error) {
336
+ if (dtsManagerOptions.remote.abortOnError === false) {
337
+ if (dtsManagerOptions.displayErrorInTerminal) _module_federation_sdk.logger.error(error);
338
+ return;
339
+ }
340
+ throw error;
341
+ }
342
+ };
343
+ const WINDOWS_ABSOLUTE_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
344
+ const isSafeRelativePath = (relativePath) => {
345
+ return Boolean(relativePath) && !relativePath.startsWith("..") && !path.default.isAbsolute(relativePath) && !WINDOWS_ABSOLUTE_PATH_REGEXP.test(relativePath);
346
+ };
347
+ const resolveEmitAssetName = ({ compilerOutputPath, assetPath, fallbackName }) => {
348
+ if (!assetPath) return fallbackName;
349
+ const relativePath = path.default.relative(compilerOutputPath, assetPath);
350
+ return isSafeRelativePath(relativePath) ? relativePath : fallbackName;
351
+ };
352
+ var GenerateTypesPlugin = class {
353
+ constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsPromise, callback) {
354
+ this.pluginOptions = pluginOptions;
355
+ this.dtsOptions = dtsOptions;
356
+ this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
357
+ this.callback = callback;
358
+ }
359
+ apply(compiler) {
360
+ const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsPromise, callback } = this;
361
+ const outputDir = getCompilerOutputDir(compiler);
362
+ const context = compiler.context;
363
+ const dtsManagerOptions = normalizeGenerateTypesOptions({
364
+ context,
365
+ outputDir,
366
+ dtsOptions,
367
+ pluginOptions
368
+ });
369
+ if (!dtsManagerOptions) {
370
+ callback();
371
+ return;
372
+ }
373
+ const isProd = !isDev();
374
+ const compilerOutputPath = path.default.resolve(context, outputDir);
375
+ const emitTypesFiles = async (compilation) => {
376
+ try {
377
+ const { zipTypesPath, apiTypesPath, zipName, apiFileName } = require_expose_rpc.retrieveTypesAssetsInfo(dtsManagerOptions.remote);
378
+ const emitZipName = resolveEmitAssetName({
379
+ compilerOutputPath,
380
+ assetPath: zipTypesPath,
381
+ fallbackName: zipName
382
+ });
383
+ const emitApiFileName = resolveEmitAssetName({
384
+ compilerOutputPath,
385
+ assetPath: apiTypesPath,
386
+ fallbackName: apiFileName
387
+ });
388
+ if (isProd && emitZipName && compilation.getAsset(emitZipName)) {
389
+ callback();
390
+ return;
391
+ }
392
+ _module_federation_sdk.logger.debug("start generating types...");
393
+ await generateTypesAPI({ dtsManagerOptions });
394
+ _module_federation_sdk.logger.debug("generate types success!");
395
+ if (isProd) {
396
+ if (zipTypesPath && !compilation.getAsset(emitZipName) && fs.default.existsSync(zipTypesPath)) compilation.emitAsset(emitZipName, new compiler.webpack.sources.RawSource(fs.default.readFileSync(zipTypesPath)));
397
+ if (apiTypesPath && !compilation.getAsset(emitApiFileName) && fs.default.existsSync(apiTypesPath)) compilation.emitAsset(emitApiFileName, new compiler.webpack.sources.RawSource(fs.default.readFileSync(apiTypesPath)));
398
+ callback();
399
+ } else {
400
+ const isEEXIST = (err) => {
401
+ return err.code == "EEXIST";
402
+ };
403
+ if (zipTypesPath && fs.default.existsSync(zipTypesPath)) {
404
+ const zipContent = fs.default.readFileSync(zipTypesPath);
405
+ const zipOutputPath = path.default.join(compiler.outputPath, emitZipName);
406
+ await new Promise((resolve, reject) => {
407
+ compiler.outputFileSystem.mkdir(path.default.dirname(zipOutputPath), { recursive: true }, (err) => {
408
+ if (err && !isEEXIST(err)) reject(err);
409
+ else compiler.outputFileSystem.writeFile(zipOutputPath, zipContent, (writeErr) => {
410
+ if (writeErr && !isEEXIST(writeErr)) reject(writeErr);
411
+ else resolve();
412
+ });
413
+ });
414
+ });
415
+ }
416
+ if (apiTypesPath && fs.default.existsSync(apiTypesPath)) {
417
+ const apiContent = fs.default.readFileSync(apiTypesPath);
418
+ const apiOutputPath = path.default.join(compiler.outputPath, emitApiFileName);
419
+ await new Promise((resolve, reject) => {
420
+ compiler.outputFileSystem.mkdir(path.default.dirname(apiOutputPath), { recursive: true }, (err) => {
421
+ if (err && !isEEXIST(err)) reject(err);
422
+ else compiler.outputFileSystem.writeFile(apiOutputPath, apiContent, (writeErr) => {
423
+ if (writeErr && !isEEXIST(writeErr)) reject(writeErr);
424
+ else resolve();
425
+ });
426
+ });
427
+ });
428
+ }
429
+ callback();
430
+ }
431
+ } catch (err) {
432
+ callback();
433
+ if (dtsManagerOptions.displayErrorInTerminal) console.error(err);
434
+ _module_federation_sdk.logger.debug("generate types fail!");
435
+ }
436
+ };
437
+ compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
438
+ compilation.hooks.processAssets.tapPromise({
439
+ name: "mf:generateTypes",
440
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
441
+ }, async () => {
442
+ await fetchRemoteTypeUrlsPromise;
443
+ const emitTypesFilesPromise = emitTypesFiles(compilation);
444
+ if (isProd) await emitTypesFilesPromise;
445
+ });
446
+ });
447
+ }
448
+ };
449
+
450
+ //#endregion
451
+ //#region src/plugins/DtsPlugin.ts
452
+ const normalizeDtsOptions = (options, context, defaultOptions) => {
453
+ return (0, _module_federation_sdk.normalizeOptions)(require_expose_rpc.isTSProject(options.dts, context), {
454
+ generateTypes: defaultOptions?.defaultGenerateOptions || DEFAULT_GENERATE_TYPES,
455
+ consumeTypes: defaultOptions?.defaultConsumeOptions || DEFAULT_CONSUME_TYPES,
456
+ extraOptions: {},
457
+ displayErrorInTerminal: true
458
+ }, "mfOptions.dts")(options.dts);
459
+ };
460
+ const excludeDts = (filepath) => {
461
+ if (typeof filepath !== "string") return false;
462
+ const [_p, query] = filepath.split("?");
463
+ if (query && query.startsWith("exclude-mf-dts")) return true;
464
+ return false;
465
+ };
466
+ var DtsPlugin = class {
467
+ constructor(options) {
468
+ this.options = options;
469
+ this.clonedOptions = { ...options };
470
+ }
471
+ apply(compiler) {
472
+ const { options, clonedOptions } = this;
473
+ if (options.exposes && typeof options.exposes === "object") {
474
+ const cleanedExposes = {};
475
+ Object.entries(options.exposes).forEach(([key, value]) => {
476
+ if (typeof value === "string") {
477
+ const [filepath, _query] = value.split("?");
478
+ if (excludeDts(value)) return;
479
+ cleanedExposes[key] = filepath;
480
+ } else {
481
+ if (typeof value === "object" && Array.isArray(value.import) && value.import.some((v) => excludeDts(v))) return;
482
+ cleanedExposes[key] = value;
483
+ }
484
+ });
485
+ clonedOptions.exposes = cleanedExposes;
486
+ }
487
+ const normalizedDtsOptions = normalizeDtsOptions(clonedOptions, compiler.context);
488
+ if (typeof normalizedDtsOptions !== "object") return;
489
+ let fetchRemoteTypeUrlsResolve;
490
+ const fetchRemoteTypeUrlsPromise = new Promise((resolve) => {
491
+ fetchRemoteTypeUrlsResolve = resolve;
492
+ });
493
+ let generateTypesPromiseResolve;
494
+ new DevPlugin(clonedOptions, normalizedDtsOptions, new Promise((resolve) => {
495
+ generateTypesPromiseResolve = resolve;
496
+ }), fetchRemoteTypeUrlsPromise).apply(compiler);
497
+ new GenerateTypesPlugin(clonedOptions, normalizedDtsOptions, fetchRemoteTypeUrlsPromise, generateTypesPromiseResolve).apply(compiler);
498
+ new ConsumeTypesPlugin(clonedOptions, normalizedDtsOptions, fetchRemoteTypeUrlsResolve).apply(compiler);
499
+ }
500
+ addRuntimePlugins() {
501
+ const { options, clonedOptions } = this;
502
+ if (!clonedOptions.runtimePlugins) return;
503
+ if (!options.runtimePlugins) options.runtimePlugins = [];
504
+ clonedOptions.runtimePlugins.forEach((plugin) => {
505
+ options.runtimePlugins.includes(plugin) || options.runtimePlugins.push(plugin);
506
+ });
507
+ }
508
+ };
509
+
510
+ //#endregion
511
+ exports.DtsPlugin = DtsPlugin;
512
+ exports.consumeTypesAPI = consumeTypesAPI;
513
+ exports.generateTypesAPI = generateTypesAPI;
514
+ exports.isTSProject = require_expose_rpc.isTSProject;
515
+ exports.normalizeConsumeTypesOptions = normalizeConsumeTypesOptions;
516
+ exports.normalizeDtsOptions = normalizeDtsOptions;
517
+ exports.normalizeGenerateTypesOptions = normalizeGenerateTypesOptions;
@@ -0,0 +1,44 @@
1
+ //#region src/server/broker/Broker.d.ts
2
+ declare class Broker {
3
+ static readonly WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
4
+ static readonly DEFAULT_WEB_SOCKET_PORT = 16322;
5
+ static readonly DEFAULT_SECURE_WEB_SOCKET_PORT = 16324;
6
+ static readonly DEFAULT_WAITING_TIME: number;
7
+ private _publisherMap;
8
+ private _webClientMap;
9
+ private _webSocketServer?;
10
+ private _secureWebSocketServer?;
11
+ private _tmpSubscriberShelter;
12
+ private _scheduleJob;
13
+ constructor();
14
+ get hasPublishers(): boolean;
15
+ private _startWsServer;
16
+ private _takeAction;
17
+ private _addPublisher;
18
+ private _updatePublisher;
19
+ private _fetchTypes;
20
+ private _addDynamicRemote;
21
+ private _addSubscriber;
22
+ private _removeSubscriber;
23
+ private _removePublisher;
24
+ private _addWebClient;
25
+ private _notifyWebClient;
26
+ private _addTmpSubScriberRelation;
27
+ private _getTmpSubScribers;
28
+ private _consumeTmpSubScribers;
29
+ private _clearTmpSubScriberRelation;
30
+ private _clearTmpSubScriberRelations;
31
+ private _disconnect;
32
+ private _setSchedule;
33
+ private _clearSchedule;
34
+ private _stopWhenSIGTERMOrSIGINT;
35
+ private _handleUnexpectedExit;
36
+ start(): Promise<void>;
37
+ exit(): void;
38
+ broadcast(message: unknown): void;
39
+ }
40
+ //#endregion
41
+ //#region src/server/broker/startBroker.d.ts
42
+ declare function getBroker(): Broker | undefined;
43
+ //#endregion
44
+ export { getBroker };
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_Broker = require('./Broker-CaenCqdn.js');
3
+
4
+ //#region src/server/broker/startBroker.ts
5
+ let broker;
6
+ function getBroker() {
7
+ return broker;
8
+ }
9
+ async function startBroker() {
10
+ if (getBroker()) return;
11
+ broker = new require_Broker.Broker();
12
+ await broker.start();
13
+ process.send?.("ready");
14
+ }
15
+ process.on("message", (message) => {
16
+ if (message === "start") {
17
+ require_Broker.fileLog(`startBroker... ${process.pid}`, "StartBroker", "info");
18
+ startBroker();
19
+ }
20
+ });
21
+
22
+ //#endregion
23
+ exports.getBroker = getBroker;
@@ -0,0 +1,19 @@
1
+
2
+ //#region src/dev-worker/utils.ts
3
+ const DEFAULT_LOCAL_IPS = ["localhost", "127.0.0.1"];
4
+ function getIpFromEntry(entry, ipv4) {
5
+ let ip;
6
+ entry.replace(/https?:\/\/([0-9|.]+|localhost):/, (str, matched) => {
7
+ ip = matched;
8
+ return str;
9
+ });
10
+ if (ip) return DEFAULT_LOCAL_IPS.includes(ip) ? ipv4 : ip;
11
+ }
12
+
13
+ //#endregion
14
+ Object.defineProperty(exports, 'getIpFromEntry', {
15
+ enumerable: true,
16
+ get: function () {
17
+ return getIpFromEntry;
18
+ }
19
+ });