@module-federation/dts-plugin 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/Action-CzhPMw2i.js +153 -0
  2. package/dist/Broker-DRlzScTT.js +800 -0
  3. package/dist/CHANGELOG.md +15 -0
  4. package/dist/DtsWorker-Dtem3-FM.d.ts +166 -0
  5. package/dist/constant-BwEkyidO.d.ts +42 -0
  6. package/dist/consumeTypes-AD2ig87l.js +237 -0
  7. package/dist/core.d.ts +3 -68
  8. package/dist/core.js +26 -2443
  9. package/dist/dynamic-remote-type-hints-plugin.d.ts +622 -3
  10. package/dist/dynamic-remote-type-hints-plugin.js +65 -187
  11. package/dist/esm/Action-DNNg2YDh.mjs +47 -0
  12. package/dist/esm/Broker-BU4gToNr.mjs +736 -0
  13. package/dist/esm/consumeTypes-D51rVbSt.mjs +204 -0
  14. package/dist/esm/core.mjs +5 -0
  15. package/dist/esm/dynamic-remote-type-hints-plugin.mjs +73 -0
  16. package/dist/esm/expose-rpc-DMhY1i8A.mjs +1301 -0
  17. package/dist/esm/fork-dev-worker.mjs +103 -0
  18. package/dist/esm/fork-generate-dts.mjs +14 -0
  19. package/dist/esm/index.mjs +465 -0
  20. package/dist/esm/start-broker.mjs +22 -0
  21. package/dist/esm/utils-CkPvDGOy.mjs +13 -0
  22. package/dist/expose-rpc-BLAH20uj.js +1415 -0
  23. package/dist/fork-dev-worker.d.ts +10 -9
  24. package/dist/fork-dev-worker.js +100 -2932
  25. package/dist/fork-generate-dts.d.ts +4 -8
  26. package/dist/fork-generate-dts.js +11 -2103
  27. package/dist/iife/launch-web-client.iife.js +117 -0
  28. package/dist/index.d.ts +57 -46
  29. package/dist/index.js +449 -3043
  30. package/dist/package.json +26 -11
  31. package/dist/start-broker.d.ts +41 -39
  32. package/dist/start-broker.js +17 -952
  33. package/dist/utils-7KqCZHbb.js +19 -0
  34. package/package.json +31 -16
  35. package/dist/DTSManager-b15Gfat3.d.ts +0 -53
  36. package/dist/DTSManagerOptions-QVchWb0x.d.ts +0 -32
  37. package/dist/DtsWorker-BrHsGz8C.d.ts +0 -56
  38. package/dist/core.d.mts +0 -68
  39. package/dist/dynamic-remote-type-hints-plugin.d.mts +0 -5
  40. package/dist/esm/chunk-647HGGGS.js +0 -241
  41. package/dist/esm/chunk-G65LOFTY.js +0 -24
  42. package/dist/esm/chunk-LJTUMI5K.js +0 -282
  43. package/dist/esm/chunk-MV6M4VFH.js +0 -1642
  44. package/dist/esm/chunk-WWV5RWOP.js +0 -902
  45. package/dist/esm/core.js +0 -44
  46. package/dist/esm/dynamic-remote-type-hints-plugin.js +0 -73
  47. package/dist/esm/fork-dev-worker.js +0 -145
  48. package/dist/esm/fork-generate-dts.js +0 -27
  49. package/dist/esm/index.js +0 -646
  50. package/dist/esm/start-broker.js +0 -36
  51. package/dist/fork-dev-worker.d.mts +0 -15
  52. package/dist/fork-generate-dts.d.mts +0 -10
  53. package/dist/iife/launch-web-client.js +0 -152
  54. package/dist/index.d.mts +0 -56
  55. package/dist/start-broker.d.mts +0 -42
  56. package/dist/utils-C4sQemLR.d.ts +0 -15
package/dist/esm/index.js DELETED
@@ -1,646 +0,0 @@
1
- import {
2
- consumeTypes,
3
- generateTypesInChildProcess,
4
- rpc_exports
5
- } from "./chunk-LJTUMI5K.js";
6
- import {
7
- cloneDeepOptions,
8
- generateTypes,
9
- isTSProject,
10
- retrieveTypesAssetsInfo,
11
- validateOptions
12
- } from "./chunk-MV6M4VFH.js";
13
- import {
14
- getIPV4,
15
- logger
16
- } from "./chunk-WWV5RWOP.js";
17
- import {
18
- WEB_CLIENT_OPTIONS_IDENTIFIER,
19
- __async,
20
- __name,
21
- __publicField,
22
- __spreadProps,
23
- __spreadValues
24
- } from "./chunk-647HGGGS.js";
25
-
26
- // src/plugins/DevPlugin.ts
27
- import fs from "fs-extra";
28
- import path4 from "path";
29
-
30
- // src/dev-worker/createDevWorker.ts
31
- import * as path2 from "path";
32
- import * as fse from "fs-extra";
33
-
34
- // src/dev-worker/DevWorker.ts
35
- import path from "path";
36
- var _DevWorker = class _DevWorker {
37
- constructor(options) {
38
- __publicField(this, "_rpcWorker");
39
- __publicField(this, "_options");
40
- __publicField(this, "_res");
41
- this._options = cloneDeepOptions(options);
42
- this.removeUnSerializationOptions();
43
- this._rpcWorker = rpc_exports.createRpcWorker(path.resolve(__dirname, "./fork-dev-worker.js"), {}, void 0, false);
44
- this._res = this._rpcWorker.connect(this._options);
45
- }
46
- // moduleFederationConfig.manifest may have un serialization options
47
- removeUnSerializationOptions() {
48
- var _a, _b, _c, _d;
49
- (_b = (_a = this._options.host) == null ? void 0 : _a.moduleFederationConfig) == null ? true : delete _b.manifest;
50
- (_d = (_c = this._options.remote) == null ? void 0 : _c.moduleFederationConfig) == null ? true : delete _d.manifest;
51
- }
52
- get controlledPromise() {
53
- return this._res;
54
- }
55
- update() {
56
- var _a, _b;
57
- (_b = (_a = this._rpcWorker.process) == null ? void 0 : _a.send) == null ? void 0 : _b.call(_a, {
58
- type: rpc_exports.RpcGMCallTypes.CALL,
59
- id: this._rpcWorker.id,
60
- args: [
61
- void 0,
62
- "update"
63
- ]
64
- });
65
- }
66
- exit() {
67
- var _a;
68
- (_a = this._rpcWorker) == null ? void 0 : _a.terminate();
69
- }
70
- };
71
- __name(_DevWorker, "DevWorker");
72
- var DevWorker = _DevWorker;
73
-
74
- // src/dev-worker/createDevWorker.ts
75
- function removeLogFile() {
76
- return __async(this, null, function* () {
77
- try {
78
- const logDir = path2.resolve(process.cwd(), ".mf/typesGenerate.log");
79
- yield fse.remove(logDir);
80
- } catch (err) {
81
- console.error("removeLogFile error", "forkDevWorker", err);
82
- }
83
- });
84
- }
85
- __name(removeLogFile, "removeLogFile");
86
- function createDevWorker(options) {
87
- removeLogFile();
88
- return new DevWorker(__spreadValues({}, options));
89
- }
90
- __name(createDevWorker, "createDevWorker");
91
-
92
- // src/plugins/DevPlugin.ts
93
- import { normalizeOptions, TEMP_DIR as BasicTempDir } from "@module-federation/sdk";
94
-
95
- // src/plugins/utils.ts
96
- import path3 from "path";
97
- function isDev() {
98
- return process.env["NODE_ENV"] === "development";
99
- }
100
- __name(isDev, "isDev");
101
- function isPrd() {
102
- return process.env["NODE_ENV"] === "production";
103
- }
104
- __name(isPrd, "isPrd");
105
- function getCompilerOutputDir(compiler) {
106
- try {
107
- return path3.relative(compiler.context, compiler.outputPath || compiler.options.output.path);
108
- } catch (err) {
109
- return "";
110
- }
111
- }
112
- __name(getCompilerOutputDir, "getCompilerOutputDir");
113
-
114
- // src/plugins/DevPlugin.ts
115
- var PROCESS_EXIT_CODE;
116
- (function(PROCESS_EXIT_CODE2) {
117
- PROCESS_EXIT_CODE2[PROCESS_EXIT_CODE2["SUCCESS"] = 0] = "SUCCESS";
118
- PROCESS_EXIT_CODE2[PROCESS_EXIT_CODE2["FAILURE"] = 1] = "FAILURE";
119
- })(PROCESS_EXIT_CODE || (PROCESS_EXIT_CODE = {}));
120
- function ensureTempDir(filePath) {
121
- try {
122
- const dir = path4.dirname(filePath);
123
- fs.ensureDirSync(dir);
124
- } catch (_err) {
125
- }
126
- }
127
- __name(ensureTempDir, "ensureTempDir");
128
- var _DevPlugin = class _DevPlugin {
129
- constructor(options, dtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise) {
130
- __publicField(this, "name", "MFDevPlugin");
131
- __publicField(this, "_options");
132
- __publicField(this, "_devWorker");
133
- __publicField(this, "dtsOptions");
134
- __publicField(this, "generateTypesPromise");
135
- __publicField(this, "fetchRemoteTypeUrlsPromise");
136
- this._options = options;
137
- this.generateTypesPromise = generateTypesPromise;
138
- this.dtsOptions = dtsOptions;
139
- this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
140
- }
141
- static ensureLiveReloadEntry(options, filePath) {
142
- ensureTempDir(filePath);
143
- const liveReloadEntry = fs.readFileSync(path4.join(__dirname, "./iife/launch-web-client.js")).toString("utf-8");
144
- const liveReloadEntryWithOptions = liveReloadEntry.replace(WEB_CLIENT_OPTIONS_IDENTIFIER, JSON.stringify(options));
145
- fs.writeFileSync(filePath, liveReloadEntryWithOptions);
146
- }
147
- _stopWhenSIGTERMOrSIGINT() {
148
- process.on("SIGTERM", () => {
149
- logger.info(`${this._options.name} Process(${process.pid}) SIGTERM, mf server will exit...`);
150
- this._exit(0);
151
- });
152
- process.on("SIGINT", () => {
153
- logger.info(`${this._options.name} Process(${process.pid}) SIGINT, mf server will exit...`);
154
- this._exit(0);
155
- });
156
- }
157
- _handleUnexpectedExit() {
158
- process.on("unhandledRejection", (error) => {
159
- logger.error(error);
160
- logger.error(`Process(${process.pid}) unhandledRejection, mf server will exit...`);
161
- this._exit(1);
162
- });
163
- process.on("uncaughtException", (error) => {
164
- logger.error(error);
165
- logger.error(`Process(${process.pid}) uncaughtException, mf server will exit...`);
166
- this._exit(1);
167
- });
168
- }
169
- _exit(exitCode = 0) {
170
- var _a;
171
- (_a = this._devWorker) == null ? void 0 : _a.exit();
172
- process.exit(exitCode);
173
- }
174
- _afterEmit() {
175
- var _a;
176
- (_a = this._devWorker) == null ? void 0 : _a.update();
177
- }
178
- apply(compiler) {
179
- var _a;
180
- const { _options: { name, dev, dts } } = this;
181
- const normalizedDev = normalizeOptions(true, {
182
- disableLiveReload: true,
183
- disableHotTypesReload: false,
184
- disableDynamicRemoteTypeHints: false
185
- }, "mfOptions.dev")(dev);
186
- if (!isDev() || normalizedDev === false) {
187
- return;
188
- }
189
- new compiler.webpack.DefinePlugin({
190
- FEDERATION_IPV4: JSON.stringify(getIPV4())
191
- }).apply(compiler);
192
- if (normalizedDev.disableHotTypesReload && normalizedDev.disableLiveReload && normalizedDev.disableDynamicRemoteTypeHints) {
193
- return;
194
- }
195
- if (!name) {
196
- throw new Error("name is required if you want to enable dev server!");
197
- }
198
- if (!normalizedDev.disableDynamicRemoteTypeHints) {
199
- if (!this._options.runtimePlugins) {
200
- this._options.runtimePlugins = [];
201
- }
202
- this._options.runtimePlugins.push(path4.resolve(__dirname, "dynamic-remote-type-hints-plugin.js"));
203
- }
204
- if (!normalizedDev.disableLiveReload) {
205
- const TEMP_DIR = path4.join(`${process.cwd()}/node_modules`, BasicTempDir);
206
- const filepath = path4.join(TEMP_DIR, `live-reload.js`);
207
- if (typeof compiler.options.entry === "object") {
208
- _DevPlugin.ensureLiveReloadEntry({
209
- name
210
- }, filepath);
211
- Object.keys(compiler.options.entry).forEach((entry) => {
212
- const normalizedEntry = compiler.options.entry[entry];
213
- if (typeof normalizedEntry === "object" && Array.isArray(normalizedEntry.import)) {
214
- normalizedEntry.import.unshift(filepath);
215
- }
216
- });
217
- }
218
- }
219
- const defaultGenerateTypes = {
220
- compileInChildProcess: true
221
- };
222
- const defaultConsumeTypes = {
223
- consumeAPITypes: true
224
- };
225
- const normalizedDtsOptions = normalizeOptions(isTSProject(dts, compiler.context), {
226
- // remote types dist(.dev-server) not be used currently, so no need to set extractThirdParty etc
227
- generateTypes: defaultGenerateTypes,
228
- consumeTypes: defaultConsumeTypes,
229
- extraOptions: {},
230
- displayErrorInTerminal: (_a = this.dtsOptions) == null ? void 0 : _a.displayErrorInTerminal
231
- }, "mfOptions.dts")(dts);
232
- const normalizedGenerateTypes = normalizeOptions(Boolean(normalizedDtsOptions), defaultGenerateTypes, "mfOptions.dts.generateTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.generateTypes);
233
- const remote = normalizedGenerateTypes === false ? void 0 : __spreadProps(__spreadValues({
234
- implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
235
- context: compiler.context,
236
- outputDir: getCompilerOutputDir(compiler),
237
- moduleFederationConfig: __spreadValues({}, this._options),
238
- hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || "@mf-types"
239
- }, normalizedGenerateTypes), {
240
- typesFolder: `.dev-server`
241
- });
242
- const normalizedConsumeTypes = normalizeOptions(Boolean(normalizedDtsOptions), defaultConsumeTypes, "mfOptions.dts.consumeTypes")(normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.consumeTypes);
243
- const host = normalizedConsumeTypes === false ? void 0 : __spreadValues({
244
- implementation: normalizedDtsOptions === false ? void 0 : normalizedDtsOptions.implementation,
245
- context: compiler.context,
246
- moduleFederationConfig: this._options,
247
- typesFolder: normalizedConsumeTypes.typesFolder || "@mf-types",
248
- abortOnError: false
249
- }, normalizedConsumeTypes);
250
- const extraOptions = normalizedDtsOptions ? normalizedDtsOptions.extraOptions || {} : {};
251
- if (!remote && !host && normalizedDev.disableLiveReload) {
252
- return;
253
- }
254
- if (remote && !(remote == null ? void 0 : remote.tsConfigPath) && typeof normalizedDtsOptions === "object" && normalizedDtsOptions.tsConfigPath) {
255
- remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
256
- }
257
- Promise.all([
258
- this.generateTypesPromise,
259
- this.fetchRemoteTypeUrlsPromise
260
- ]).then(([_, remoteTypeUrls]) => {
261
- this._devWorker = createDevWorker({
262
- name,
263
- remote,
264
- host: __spreadProps(__spreadValues({
265
- moduleFederationConfig: {}
266
- }, host), {
267
- remoteTypeUrls
268
- }),
269
- extraOptions,
270
- disableLiveReload: normalizedDev.disableHotTypesReload,
271
- disableHotTypesReload: normalizedDev.disableHotTypesReload
272
- });
273
- });
274
- this._stopWhenSIGTERMOrSIGINT();
275
- this._handleUnexpectedExit();
276
- compiler.hooks.afterEmit.tap(this.name, this._afterEmit.bind(this));
277
- }
278
- };
279
- __name(_DevPlugin, "DevPlugin");
280
- var DevPlugin = _DevPlugin;
281
-
282
- // src/plugins/DtsPlugin.ts
283
- import { normalizeOptions as normalizeOptions4 } from "@module-federation/sdk";
284
-
285
- // src/plugins/ConsumeTypesPlugin.ts
286
- import { infrastructureLogger as logger2 } from "@module-federation/sdk";
287
- import { normalizeOptions as normalizeOptions2 } from "@module-federation/sdk";
288
- var DEFAULT_CONSUME_TYPES = {
289
- abortOnError: false,
290
- consumeAPITypes: true,
291
- typesOnBuild: false
292
- };
293
- var normalizeConsumeTypesOptions = /* @__PURE__ */ __name(({ context, dtsOptions, pluginOptions }) => {
294
- const normalizedConsumeTypes = normalizeOptions2(true, DEFAULT_CONSUME_TYPES, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
295
- if (!normalizedConsumeTypes) {
296
- return;
297
- }
298
- const dtsManagerOptions = {
299
- host: __spreadValues({
300
- implementation: dtsOptions.implementation,
301
- context,
302
- moduleFederationConfig: pluginOptions
303
- }, normalizedConsumeTypes),
304
- extraOptions: dtsOptions.extraOptions || {},
305
- displayErrorInTerminal: dtsOptions.displayErrorInTerminal
306
- };
307
- validateOptions(dtsManagerOptions.host);
308
- return dtsManagerOptions;
309
- }, "normalizeConsumeTypesOptions");
310
- var consumeTypesAPI = /* @__PURE__ */ __name((dtsManagerOptions, cb) => __async(void 0, null, function* () {
311
- const fetchRemoteTypeUrlsPromise = typeof dtsManagerOptions.host.remoteTypeUrls === "function" ? dtsManagerOptions.host.remoteTypeUrls() : Promise.resolve(dtsManagerOptions.host.remoteTypeUrls);
312
- return fetchRemoteTypeUrlsPromise.then((remoteTypeUrls) => {
313
- consumeTypes(__spreadProps(__spreadValues({}, dtsManagerOptions), {
314
- host: __spreadProps(__spreadValues({}, dtsManagerOptions.host), {
315
- remoteTypeUrls
316
- })
317
- })).then(() => {
318
- typeof cb === "function" && cb(remoteTypeUrls);
319
- }).catch(() => {
320
- typeof cb === "function" && cb(remoteTypeUrls);
321
- });
322
- });
323
- }), "consumeTypesAPI");
324
- var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
325
- constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsResolve) {
326
- __publicField(this, "pluginOptions");
327
- __publicField(this, "dtsOptions");
328
- __publicField(this, "callback");
329
- __publicField(this, "fetchRemoteTypeUrlsResolve");
330
- this.pluginOptions = pluginOptions;
331
- this.dtsOptions = dtsOptions;
332
- this.fetchRemoteTypeUrlsResolve = fetchRemoteTypeUrlsResolve;
333
- }
334
- apply(compiler) {
335
- const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
336
- const dtsManagerOptions = normalizeConsumeTypesOptions({
337
- context: compiler.context,
338
- dtsOptions,
339
- pluginOptions
340
- });
341
- if (!dtsManagerOptions) {
342
- fetchRemoteTypeUrlsResolve(void 0);
343
- return;
344
- }
345
- if (isPrd() && !dtsManagerOptions.host.typesOnBuild) {
346
- fetchRemoteTypeUrlsResolve(void 0);
347
- return;
348
- }
349
- logger2.debug("start fetching remote types...");
350
- const promise = consumeTypesAPI(dtsManagerOptions, fetchRemoteTypeUrlsResolve);
351
- compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
352
- compilation.hooks.processAssets.tapPromise({
353
- name: "mf:generateTypes",
354
- stage: (
355
- // @ts-expect-error use runtime variable in case peer dep not installed , it should execute before generate types
356
- compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 1
357
- )
358
- }, () => __async(this, null, function* () {
359
- yield promise;
360
- logger2.debug("fetch remote types success!");
361
- }));
362
- });
363
- }
364
- };
365
- __name(_ConsumeTypesPlugin, "ConsumeTypesPlugin");
366
- var ConsumeTypesPlugin = _ConsumeTypesPlugin;
367
-
368
- // src/plugins/GenerateTypesPlugin.ts
369
- import fs2 from "fs";
370
- import path5 from "path";
371
- import { logger as logger3, normalizeOptions as normalizeOptions3 } from "@module-federation/sdk";
372
- var DEFAULT_GENERATE_TYPES = {
373
- generateAPITypes: true,
374
- compileInChildProcess: true,
375
- abortOnError: false,
376
- extractThirdParty: false,
377
- extractRemoteTypes: false
378
- };
379
- var normalizeGenerateTypesOptions = /* @__PURE__ */ __name(({ context, outputDir, dtsOptions, pluginOptions }) => {
380
- const normalizedGenerateTypes = normalizeOptions3(true, DEFAULT_GENERATE_TYPES, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
381
- if (!normalizedGenerateTypes) {
382
- return;
383
- }
384
- const normalizedConsumeTypes = normalizeOptions3(true, {}, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
385
- const finalOptions = {
386
- remote: __spreadValues({
387
- implementation: dtsOptions.implementation,
388
- context,
389
- outputDir,
390
- moduleFederationConfig: pluginOptions
391
- }, normalizedGenerateTypes),
392
- host: normalizedConsumeTypes === false ? void 0 : __spreadProps(__spreadValues({
393
- context,
394
- moduleFederationConfig: pluginOptions
395
- }, normalizedConsumeTypes), {
396
- // generateTypes only use host basic config, eg: typeFolders
397
- remoteTypeUrls: typeof (normalizedConsumeTypes == null ? void 0 : normalizedConsumeTypes.remoteTypeUrls) === "object" ? normalizedConsumeTypes == null ? void 0 : normalizedConsumeTypes.remoteTypeUrls : void 0
398
- }),
399
- extraOptions: dtsOptions.extraOptions || {},
400
- displayErrorInTerminal: dtsOptions.displayErrorInTerminal
401
- };
402
- if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
403
- finalOptions.remote.tsConfigPath = dtsOptions.tsConfigPath;
404
- }
405
- validateOptions(finalOptions.remote);
406
- return finalOptions;
407
- }, "normalizeGenerateTypesOptions");
408
- var getGenerateTypesFn = /* @__PURE__ */ __name((dtsManagerOptions) => {
409
- let fn = generateTypes;
410
- if (dtsManagerOptions.remote.compileInChildProcess) {
411
- fn = generateTypesInChildProcess;
412
- }
413
- return fn;
414
- }, "getGenerateTypesFn");
415
- var generateTypesAPI = /* @__PURE__ */ __name(({ dtsManagerOptions }) => {
416
- const fn = getGenerateTypesFn(dtsManagerOptions);
417
- return fn(dtsManagerOptions);
418
- }, "generateTypesAPI");
419
- var _GenerateTypesPlugin = class _GenerateTypesPlugin {
420
- constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsPromise, callback) {
421
- __publicField(this, "pluginOptions");
422
- __publicField(this, "dtsOptions");
423
- __publicField(this, "fetchRemoteTypeUrlsPromise");
424
- __publicField(this, "callback");
425
- this.pluginOptions = pluginOptions;
426
- this.dtsOptions = dtsOptions;
427
- this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
428
- this.callback = callback;
429
- }
430
- apply(compiler) {
431
- const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsPromise, callback } = this;
432
- const outputDir = getCompilerOutputDir(compiler);
433
- const context = compiler.context;
434
- const dtsManagerOptions = normalizeGenerateTypesOptions({
435
- context,
436
- outputDir,
437
- dtsOptions,
438
- pluginOptions
439
- });
440
- if (!dtsManagerOptions) {
441
- callback();
442
- return;
443
- }
444
- const isProd = !isDev();
445
- const emitTypesFiles = /* @__PURE__ */ __name((compilation) => __async(this, null, function* () {
446
- try {
447
- const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(dtsManagerOptions.remote);
448
- if (isProd && zipName && compilation.getAsset(zipName)) {
449
- callback();
450
- return;
451
- }
452
- logger3.debug("start generating types...");
453
- yield generateTypesAPI({
454
- dtsManagerOptions
455
- });
456
- logger3.debug("generate types success!");
457
- if (isProd) {
458
- if (zipTypesPath && !compilation.getAsset(zipName) && fs2.existsSync(zipTypesPath)) {
459
- compilation.emitAsset(zipName, new compiler.webpack.sources.RawSource(fs2.readFileSync(zipTypesPath), false));
460
- }
461
- if (apiTypesPath && !compilation.getAsset(apiFileName) && fs2.existsSync(apiTypesPath)) {
462
- compilation.emitAsset(apiFileName, new compiler.webpack.sources.RawSource(fs2.readFileSync(apiTypesPath), false));
463
- }
464
- callback();
465
- } else {
466
- const isEEXIST = /* @__PURE__ */ __name((err) => {
467
- return err.code == "EEXIST";
468
- }, "isEEXIST");
469
- if (zipTypesPath && fs2.existsSync(zipTypesPath)) {
470
- const zipContent = fs2.readFileSync(zipTypesPath);
471
- const zipOutputPath = path5.join(compiler.outputPath, zipName);
472
- yield new Promise((resolve2, reject) => {
473
- compiler.outputFileSystem.mkdir(
474
- path5.dirname(zipOutputPath),
475
- {
476
- recursive: true
477
- },
478
- // @ts-ignore type fixed in https://github.com/webpack/webpack/releases/tag/v5.91.0
479
- (err) => {
480
- if (err && !isEEXIST(err)) {
481
- reject(err);
482
- } else {
483
- compiler.outputFileSystem.writeFile(
484
- zipOutputPath,
485
- // @ts-ignore
486
- zipContent,
487
- (writeErr) => {
488
- if (writeErr && !isEEXIST(writeErr)) {
489
- reject(writeErr);
490
- } else {
491
- resolve2();
492
- }
493
- }
494
- );
495
- }
496
- }
497
- );
498
- });
499
- }
500
- if (apiTypesPath && fs2.existsSync(apiTypesPath)) {
501
- const apiContent = fs2.readFileSync(apiTypesPath);
502
- const apiOutputPath = path5.join(compiler.outputPath, apiFileName);
503
- yield new Promise((resolve2, reject) => {
504
- compiler.outputFileSystem.mkdir(
505
- path5.dirname(apiOutputPath),
506
- {
507
- recursive: true
508
- },
509
- // @ts-ignore type fixed in https://github.com/webpack/webpack/releases/tag/v5.91.0
510
- (err) => {
511
- if (err && !isEEXIST(err)) {
512
- reject(err);
513
- } else {
514
- compiler.outputFileSystem.writeFile(
515
- apiOutputPath,
516
- // @ts-ignore
517
- apiContent,
518
- (writeErr) => {
519
- if (writeErr && !isEEXIST(writeErr)) {
520
- reject(writeErr);
521
- } else {
522
- resolve2();
523
- }
524
- }
525
- );
526
- }
527
- }
528
- );
529
- });
530
- }
531
- callback();
532
- }
533
- } catch (err) {
534
- callback();
535
- if (dtsManagerOptions.displayErrorInTerminal) {
536
- console.error(err);
537
- }
538
- logger3.debug("generate types fail!");
539
- }
540
- }), "emitTypesFiles");
541
- compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
542
- compilation.hooks.processAssets.tapPromise({
543
- name: "mf:generateTypes",
544
- stage: (
545
- // @ts-expect-error use runtime variable in case peer dep not installed
546
- compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
547
- )
548
- }, () => __async(this, null, function* () {
549
- yield fetchRemoteTypeUrlsPromise;
550
- const emitTypesFilesPromise = emitTypesFiles(compilation);
551
- if (isProd) {
552
- yield emitTypesFilesPromise;
553
- }
554
- }));
555
- });
556
- }
557
- };
558
- __name(_GenerateTypesPlugin, "GenerateTypesPlugin");
559
- var GenerateTypesPlugin = _GenerateTypesPlugin;
560
-
561
- // src/plugins/DtsPlugin.ts
562
- var normalizeDtsOptions = /* @__PURE__ */ __name((options, context, defaultOptions) => {
563
- return normalizeOptions4(isTSProject(options.dts, context), {
564
- generateTypes: (defaultOptions == null ? void 0 : defaultOptions.defaultGenerateOptions) || DEFAULT_GENERATE_TYPES,
565
- consumeTypes: (defaultOptions == null ? void 0 : defaultOptions.defaultConsumeOptions) || DEFAULT_CONSUME_TYPES,
566
- extraOptions: {},
567
- displayErrorInTerminal: true
568
- }, "mfOptions.dts")(options.dts);
569
- }, "normalizeDtsOptions");
570
- var excludeDts = /* @__PURE__ */ __name((filepath) => {
571
- if (typeof filepath !== "string") {
572
- return false;
573
- }
574
- const [_p, query] = filepath.split("?");
575
- if (query && query.startsWith("exclude-mf-dts")) {
576
- return true;
577
- }
578
- return false;
579
- }, "excludeDts");
580
- var _DtsPlugin = class _DtsPlugin {
581
- constructor(options) {
582
- __publicField(this, "options");
583
- __publicField(this, "clonedOptions");
584
- this.options = options;
585
- this.clonedOptions = __spreadValues({}, options);
586
- }
587
- apply(compiler) {
588
- const { options, clonedOptions } = this;
589
- if (options.exposes && typeof options.exposes === "object") {
590
- const cleanedExposes = {};
591
- Object.entries(options.exposes).forEach(([key, value]) => {
592
- if (typeof value === "string") {
593
- const [filepath, _query] = value.split("?");
594
- if (excludeDts(value)) {
595
- return;
596
- }
597
- cleanedExposes[key] = filepath;
598
- } else {
599
- if (typeof value === "object" && Array.isArray(value.import) && value.import.some((v) => excludeDts(v))) {
600
- return;
601
- }
602
- cleanedExposes[key] = value;
603
- }
604
- });
605
- clonedOptions.exposes = cleanedExposes;
606
- }
607
- const normalizedDtsOptions = normalizeDtsOptions(clonedOptions, compiler.context);
608
- if (typeof normalizedDtsOptions !== "object") {
609
- return;
610
- }
611
- let fetchRemoteTypeUrlsResolve;
612
- const fetchRemoteTypeUrlsPromise = new Promise((resolve2) => {
613
- fetchRemoteTypeUrlsResolve = resolve2;
614
- });
615
- let generateTypesPromiseResolve;
616
- const generateTypesPromise = new Promise((resolve2) => {
617
- generateTypesPromiseResolve = resolve2;
618
- });
619
- new DevPlugin(clonedOptions, normalizedDtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise).apply(compiler);
620
- new GenerateTypesPlugin(clonedOptions, normalizedDtsOptions, fetchRemoteTypeUrlsPromise, generateTypesPromiseResolve).apply(compiler);
621
- new ConsumeTypesPlugin(clonedOptions, normalizedDtsOptions, fetchRemoteTypeUrlsResolve).apply(compiler);
622
- }
623
- addRuntimePlugins() {
624
- const { options, clonedOptions } = this;
625
- if (!clonedOptions.runtimePlugins) {
626
- return;
627
- }
628
- if (!options.runtimePlugins) {
629
- options.runtimePlugins = [];
630
- }
631
- clonedOptions.runtimePlugins.forEach((plugin) => {
632
- options.runtimePlugins.includes(plugin) || options.runtimePlugins.push(plugin);
633
- });
634
- }
635
- };
636
- __name(_DtsPlugin, "DtsPlugin");
637
- var DtsPlugin = _DtsPlugin;
638
- export {
639
- DtsPlugin,
640
- consumeTypesAPI,
641
- generateTypesAPI,
642
- isTSProject,
643
- normalizeConsumeTypesOptions,
644
- normalizeDtsOptions,
645
- normalizeGenerateTypesOptions
646
- };
@@ -1,36 +0,0 @@
1
- import {
2
- Broker,
3
- fileLog
4
- } from "./chunk-WWV5RWOP.js";
5
- import {
6
- __async,
7
- __name
8
- } from "./chunk-647HGGGS.js";
9
-
10
- // src/server/broker/startBroker.ts
11
- var broker;
12
- function getBroker() {
13
- return broker;
14
- }
15
- __name(getBroker, "getBroker");
16
- function startBroker() {
17
- return __async(this, null, function* () {
18
- var _a;
19
- if (getBroker()) {
20
- return;
21
- }
22
- broker = new Broker();
23
- yield broker.start();
24
- (_a = process.send) == null ? void 0 : _a.call(process, "ready");
25
- });
26
- }
27
- __name(startBroker, "startBroker");
28
- process.on("message", (message) => {
29
- if (message === "start") {
30
- fileLog(`startBroker... ${process.pid}`, "StartBroker", "info");
31
- startBroker();
32
- }
33
- });
34
- export {
35
- getBroker
36
- };
@@ -1,15 +0,0 @@
1
- import { D as DTSManagerOptions } from './DTSManagerOptions-QVchWb0x.js';
2
- import '@module-federation/sdk';
3
-
4
- interface DevWorkerOptions extends DTSManagerOptions {
5
- name: string;
6
- disableLiveReload?: boolean;
7
- disableHotTypesReload?: boolean;
8
- }
9
-
10
- interface Options extends DevWorkerOptions {
11
- name: string;
12
- }
13
- declare function forkDevWorker(options: Options, action?: string): Promise<void>;
14
-
15
- export { forkDevWorker };