@module-federation/dts-plugin 0.11.1 → 0.11.3

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.d.ts CHANGED
@@ -1,10 +1,52 @@
1
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
2
  import { WebpackPluginInstance, Compiler } from 'webpack';
3
+ import { D as DTSManagerOptions } from './DTSManagerOptions-c74c59ed.js';
4
+ export { i as isTSProject } from './utils-0ec746b7.js';
5
+ import './DTSManager-81645796.js';
6
+ import 'typescript';
3
7
 
8
+ declare const normalizeDtsOptions: (options: moduleFederationPlugin.ModuleFederationPluginOptions, context: string, defaultOptions?: {
9
+ defaultGenerateOptions?: moduleFederationPlugin.DtsRemoteOptions;
10
+ defaultConsumeOptions?: moduleFederationPlugin.DtsHostOptions;
11
+ }) => false | moduleFederationPlugin.PluginDtsOptions;
4
12
  declare class DtsPlugin implements WebpackPluginInstance {
5
13
  options: moduleFederationPlugin.ModuleFederationPluginOptions;
6
14
  constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
7
15
  apply(compiler: Compiler): void;
8
16
  }
9
17
 
10
- export { DtsPlugin };
18
+ declare const normalizeConsumeTypesOptions: ({ context, dtsOptions, pluginOptions, }: {
19
+ context?: string;
20
+ dtsOptions: moduleFederationPlugin.PluginDtsOptions;
21
+ pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
22
+ }) => {
23
+ host: {
24
+ typesFolder?: string;
25
+ abortOnError?: boolean;
26
+ remoteTypesFolder?: string;
27
+ deleteTypesFolder?: boolean;
28
+ maxRetries?: number;
29
+ consumeAPITypes?: boolean;
30
+ runtimePkgs?: string[];
31
+ remoteTypeUrls?: (() => Promise<moduleFederationPlugin.RemoteTypeUrls>) | moduleFederationPlugin.RemoteTypeUrls;
32
+ timeout?: number;
33
+ implementation: string;
34
+ context: string;
35
+ moduleFederationConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
36
+ };
37
+ extraOptions: Record<string, any>;
38
+ displayErrorInTerminal: boolean;
39
+ };
40
+ declare const consumeTypesAPI: (dtsManagerOptions: DTSManagerOptions, cb?: (options: moduleFederationPlugin.RemoteTypeUrls) => void) => Promise<void>;
41
+
42
+ declare const normalizeGenerateTypesOptions: ({ context, outputDir, dtsOptions, pluginOptions, }: {
43
+ context?: string;
44
+ outputDir?: string;
45
+ dtsOptions: moduleFederationPlugin.PluginDtsOptions;
46
+ pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
47
+ }) => DTSManagerOptions;
48
+ declare const generateTypesAPI: ({ dtsManagerOptions, }: {
49
+ dtsManagerOptions: DTSManagerOptions;
50
+ }) => Promise<void>;
51
+
52
+ export { DtsPlugin, consumeTypesAPI, generateTypesAPI, normalizeConsumeTypesOptions, normalizeDtsOptions, normalizeGenerateTypesOptions };
package/dist/index.js CHANGED
@@ -83,7 +83,13 @@ var __async = (__this, __arguments, generator) => {
83
83
  // packages/dts-plugin/src/index.ts
84
84
  var src_exports = {};
85
85
  __export(src_exports, {
86
- DtsPlugin: () => DtsPlugin
86
+ DtsPlugin: () => DtsPlugin,
87
+ consumeTypesAPI: () => consumeTypesAPI,
88
+ generateTypesAPI: () => generateTypesAPI,
89
+ isTSProject: () => isTSProject,
90
+ normalizeConsumeTypesOptions: () => normalizeConsumeTypesOptions,
91
+ normalizeDtsOptions: () => normalizeDtsOptions,
92
+ normalizeGenerateTypesOptions: () => normalizeGenerateTypesOptions
87
93
  });
88
94
  module.exports = __toCommonJS(src_exports);
89
95
 
@@ -366,7 +372,7 @@ var log4js = __toESM(require("log4js"));
366
372
  // packages/dts-plugin/src/server/constant.ts
367
373
  var DEFAULT_WEB_SOCKET_PORT = 16322;
368
374
  var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
369
- var MF_SERVER_IDENTIFIER = "Module Federation Dev Server";
375
+ var MF_SERVER_IDENTIFIER = "Module Federation DTS";
370
376
  var WEB_CLIENT_OPTIONS_IDENTIFIER = "__WEB_CLIENT_OPTIONS__";
371
377
  var UpdateMode;
372
378
  (function(UpdateMode2) {
@@ -1206,6 +1212,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1206
1212
  } catch (error2) {
1207
1213
  fileLog(`Error during types archive download: ${(error2 == null ? void 0 : error2.message) || "unknown error"}`, "downloadTypesArchive", "error");
1208
1214
  if (retries >= hostOptions.maxRetries) {
1215
+ logger.error(`Failed to download ${fileToDownload}, you can set FEDERATION_DEBUG=true to see detail message.`);
1209
1216
  if (hostOptions.abortOnError !== false) {
1210
1217
  throw error2;
1211
1218
  }
@@ -1275,6 +1282,7 @@ var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
1275
1282
  };
1276
1283
  }, "retrieveRemoteInfo");
1277
1284
  var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
1285
+ var _a3;
1278
1286
  const parsedOptions = import_managers.utils.parseOptions(hostOptions.moduleFederationConfig.remotes || {}, (item, key) => ({
1279
1287
  remote: Array.isArray(item) ? item[0] : item,
1280
1288
  key
@@ -1282,15 +1290,38 @@ var resolveRemotes = /* @__PURE__ */ __name((hostOptions) => {
1282
1290
  remote: Array.isArray(item.external) ? item.external[0] : item.external,
1283
1291
  key
1284
1292
  }));
1293
+ const remoteTypeUrls = (_a3 = hostOptions.remoteTypeUrls) != null ? _a3 : {};
1294
+ if (typeof remoteTypeUrls !== "object") {
1295
+ throw new Error("remoteTypeUrls must be consumed before resolveRemotes");
1296
+ }
1297
+ const remoteInfos = Object.keys(remoteTypeUrls).reduce((sum, remoteName) => {
1298
+ const { zip, api, alias } = remoteTypeUrls[remoteName];
1299
+ sum[alias] = {
1300
+ name: remoteName,
1301
+ url: "",
1302
+ zipUrl: zip,
1303
+ apiTypeUrl: api,
1304
+ alias: alias || remoteName
1305
+ };
1306
+ return sum;
1307
+ }, {});
1285
1308
  return parsedOptions.reduce((accumulator, item) => {
1286
1309
  const { key, remote } = item[1];
1287
- accumulator[key] = retrieveRemoteInfo({
1310
+ const res = retrieveRemoteInfo({
1288
1311
  hostOptions,
1289
1312
  remoteAlias: key,
1290
1313
  remote
1291
1314
  });
1315
+ if (accumulator[key]) {
1316
+ accumulator[key] = __spreadProps(__spreadValues({}, accumulator[key]), {
1317
+ url: res.url,
1318
+ apiTypeUrl: accumulator[key].apiTypeUrl || res.apiTypeUrl
1319
+ });
1320
+ return accumulator;
1321
+ }
1322
+ accumulator[key] = res;
1292
1323
  return accumulator;
1293
- }, {});
1324
+ }, remoteInfos);
1294
1325
  }, "resolveRemotes");
1295
1326
  var retrieveHostConfig = /* @__PURE__ */ __name((options) => {
1296
1327
  validateOptions(options);
@@ -2549,52 +2580,68 @@ var import_sdk11 = require("@module-federation/sdk");
2549
2580
  // packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
2550
2581
  var import_sdk8 = require("@module-federation/sdk");
2551
2582
  var import_sdk9 = require("@module-federation/sdk");
2583
+ var DEFAULT_CONSUME_TYPES = {
2584
+ abortOnError: false,
2585
+ consumeAPITypes: true
2586
+ };
2587
+ var normalizeConsumeTypesOptions = /* @__PURE__ */ __name(({ context, dtsOptions, pluginOptions }) => {
2588
+ const normalizedConsumeTypes = (0, import_sdk9.normalizeOptions)(true, DEFAULT_CONSUME_TYPES, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
2589
+ if (!normalizedConsumeTypes) {
2590
+ return;
2591
+ }
2592
+ const dtsManagerOptions = {
2593
+ host: __spreadValues({
2594
+ implementation: dtsOptions.implementation,
2595
+ context,
2596
+ moduleFederationConfig: pluginOptions
2597
+ }, normalizedConsumeTypes),
2598
+ extraOptions: dtsOptions.extraOptions || {},
2599
+ displayErrorInTerminal: dtsOptions.displayErrorInTerminal
2600
+ };
2601
+ validateOptions(dtsManagerOptions.host);
2602
+ return dtsManagerOptions;
2603
+ }, "normalizeConsumeTypesOptions");
2604
+ var consumeTypesAPI = /* @__PURE__ */ __name((dtsManagerOptions, cb) => __async(void 0, null, function* () {
2605
+ const fetchRemoteTypeUrlsPromise = typeof dtsManagerOptions.host.remoteTypeUrls === "function" ? dtsManagerOptions.host.remoteTypeUrls() : Promise.resolve(dtsManagerOptions.host.remoteTypeUrls);
2606
+ return fetchRemoteTypeUrlsPromise.then((remoteTypeUrls) => {
2607
+ consumeTypes(__spreadProps(__spreadValues({}, dtsManagerOptions), {
2608
+ host: __spreadProps(__spreadValues({}, dtsManagerOptions.host), {
2609
+ remoteTypeUrls
2610
+ })
2611
+ })).then(() => {
2612
+ typeof cb === "function" && cb(remoteTypeUrls);
2613
+ }).catch(() => {
2614
+ typeof cb === "function" && cb(remoteTypeUrls);
2615
+ });
2616
+ });
2617
+ }), "consumeTypesAPI");
2552
2618
  var _ConsumeTypesPlugin = class _ConsumeTypesPlugin {
2553
- constructor(pluginOptions, dtsOptions, defaultOptions3, fetchRemoteTypeUrlsResolve) {
2619
+ constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsResolve) {
2554
2620
  __publicField(this, "pluginOptions");
2555
2621
  __publicField(this, "dtsOptions");
2556
- __publicField(this, "defaultOptions");
2557
2622
  __publicField(this, "callback");
2558
2623
  __publicField(this, "fetchRemoteTypeUrlsResolve");
2559
2624
  this.pluginOptions = pluginOptions;
2560
2625
  this.dtsOptions = dtsOptions;
2561
- this.defaultOptions = defaultOptions3;
2562
2626
  this.fetchRemoteTypeUrlsResolve = fetchRemoteTypeUrlsResolve;
2563
2627
  }
2564
2628
  apply(compiler) {
2565
- const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
2629
+ const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
2566
2630
  if (isPrd()) {
2567
2631
  fetchRemoteTypeUrlsResolve(void 0);
2568
2632
  return;
2569
2633
  }
2570
- const normalizedConsumeTypes = (0, import_sdk9.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
2571
- if (!normalizedConsumeTypes) {
2634
+ const dtsManagerOptions = normalizeConsumeTypesOptions({
2635
+ context: compiler.context,
2636
+ dtsOptions,
2637
+ pluginOptions
2638
+ });
2639
+ if (!dtsManagerOptions) {
2572
2640
  fetchRemoteTypeUrlsResolve(void 0);
2573
2641
  return;
2574
2642
  }
2575
- const finalOptions = {
2576
- host: __spreadValues({
2577
- implementation: dtsOptions.implementation,
2578
- context: compiler.context,
2579
- moduleFederationConfig: pluginOptions
2580
- }, normalizedConsumeTypes),
2581
- extraOptions: dtsOptions.extraOptions || {},
2582
- displayErrorInTerminal: dtsOptions.displayErrorInTerminal
2583
- };
2584
- validateOptions(finalOptions.host);
2585
- const fetchRemoteTypeUrlsPromise = typeof normalizedConsumeTypes.remoteTypeUrls === "function" ? normalizedConsumeTypes.remoteTypeUrls() : Promise.resolve(normalizedConsumeTypes.remoteTypeUrls);
2586
2643
  import_sdk8.logger.debug("start fetching remote types...");
2587
- const promise = fetchRemoteTypeUrlsPromise.then((remoteTypeUrls) => {
2588
- consumeTypes(__spreadProps(__spreadValues({}, finalOptions), {
2589
- host: __spreadProps(__spreadValues({}, finalOptions.host), {
2590
- remoteTypeUrls
2591
- })
2592
- })).then(() => {
2593
- fetchRemoteTypeUrlsResolve(remoteTypeUrls);
2594
- }).catch(() => {
2595
- fetchRemoteTypeUrlsResolve(remoteTypeUrls);
2596
- });
2597
- });
2644
+ const promise = consumeTypesAPI(dtsManagerOptions, fetchRemoteTypeUrlsResolve);
2598
2645
  compiler.hooks.thisCompilation.tap("mf:generateTypes", (compilation) => {
2599
2646
  compilation.hooks.processAssets.tapPromise({
2600
2647
  name: "mf:generateTypes",
@@ -2616,70 +2663,89 @@ var ConsumeTypesPlugin = _ConsumeTypesPlugin;
2616
2663
  var import_fs4 = __toESM(require("fs"));
2617
2664
  var import_path10 = __toESM(require("path"));
2618
2665
  var import_sdk10 = require("@module-federation/sdk");
2666
+ var DEFAULT_GENERATE_TYPES = {
2667
+ generateAPITypes: true,
2668
+ compileInChildProcess: true,
2669
+ abortOnError: false,
2670
+ extractThirdParty: false,
2671
+ extractRemoteTypes: false
2672
+ };
2673
+ var normalizeGenerateTypesOptions = /* @__PURE__ */ __name(({ context, outputDir, dtsOptions, pluginOptions }) => {
2674
+ const normalizedGenerateTypes = (0, import_sdk10.normalizeOptions)(true, DEFAULT_GENERATE_TYPES, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
2675
+ if (!normalizedGenerateTypes) {
2676
+ return;
2677
+ }
2678
+ const normalizedConsumeTypes = (0, import_sdk10.normalizeOptions)(true, {}, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
2679
+ const finalOptions = {
2680
+ remote: __spreadValues({
2681
+ implementation: dtsOptions.implementation,
2682
+ context,
2683
+ outputDir,
2684
+ moduleFederationConfig: pluginOptions
2685
+ }, normalizedGenerateTypes),
2686
+ host: normalizedConsumeTypes === false ? void 0 : __spreadValues({
2687
+ context,
2688
+ moduleFederationConfig: pluginOptions
2689
+ }, normalizedGenerateTypes),
2690
+ extraOptions: dtsOptions.extraOptions || {},
2691
+ displayErrorInTerminal: dtsOptions.displayErrorInTerminal
2692
+ };
2693
+ if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
2694
+ finalOptions.remote.tsConfigPath = dtsOptions.tsConfigPath;
2695
+ }
2696
+ validateOptions(finalOptions.remote);
2697
+ return finalOptions;
2698
+ }, "normalizeGenerateTypesOptions");
2699
+ var getGenerateTypesFn = /* @__PURE__ */ __name((dtsManagerOptions) => {
2700
+ let fn = generateTypes;
2701
+ if (dtsManagerOptions.remote.compileInChildProcess) {
2702
+ fn = generateTypesInChildProcess;
2703
+ }
2704
+ return fn;
2705
+ }, "getGenerateTypesFn");
2706
+ var generateTypesAPI = /* @__PURE__ */ __name(({ dtsManagerOptions }) => {
2707
+ const fn = getGenerateTypesFn(dtsManagerOptions);
2708
+ return fn(dtsManagerOptions);
2709
+ }, "generateTypesAPI");
2619
2710
  var _GenerateTypesPlugin = class _GenerateTypesPlugin {
2620
- constructor(pluginOptions, dtsOptions, defaultOptions3, fetchRemoteTypeUrlsPromise, callback) {
2711
+ constructor(pluginOptions, dtsOptions, fetchRemoteTypeUrlsPromise, callback) {
2621
2712
  __publicField(this, "pluginOptions");
2622
2713
  __publicField(this, "dtsOptions");
2623
- __publicField(this, "defaultOptions");
2624
2714
  __publicField(this, "fetchRemoteTypeUrlsPromise");
2625
2715
  __publicField(this, "callback");
2626
2716
  this.pluginOptions = pluginOptions;
2627
2717
  this.dtsOptions = dtsOptions;
2628
- this.defaultOptions = defaultOptions3;
2629
2718
  this.fetchRemoteTypeUrlsPromise = fetchRemoteTypeUrlsPromise;
2630
2719
  this.callback = callback;
2631
2720
  }
2632
2721
  apply(compiler) {
2633
- const { dtsOptions, defaultOptions: defaultOptions3, pluginOptions, fetchRemoteTypeUrlsPromise, callback } = this;
2634
- const normalizedGenerateTypes = (0, import_sdk10.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.generateTypes")(dtsOptions.generateTypes);
2635
- if (!normalizedGenerateTypes) {
2722
+ const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsPromise, callback } = this;
2723
+ const outputDir = getCompilerOutputDir(compiler);
2724
+ const context = compiler.context;
2725
+ const dtsManagerOptions = normalizeGenerateTypesOptions({
2726
+ context,
2727
+ outputDir,
2728
+ dtsOptions,
2729
+ pluginOptions
2730
+ });
2731
+ if (!dtsManagerOptions) {
2636
2732
  callback();
2637
2733
  return;
2638
2734
  }
2639
- const normalizedConsumeTypes = (0, import_sdk10.normalizeOptions)(true, defaultOptions3, "mfOptions.dts.consumeTypes")(dtsOptions.consumeTypes);
2640
- const finalOptions = {
2641
- remote: __spreadValues({
2642
- implementation: dtsOptions.implementation,
2643
- context: compiler.context,
2644
- outputDir: getCompilerOutputDir(compiler),
2645
- moduleFederationConfig: pluginOptions
2646
- }, normalizedGenerateTypes),
2647
- host: normalizedConsumeTypes === false ? void 0 : __spreadValues({
2648
- context: compiler.context,
2649
- moduleFederationConfig: pluginOptions
2650
- }, normalizedGenerateTypes),
2651
- extraOptions: dtsOptions.extraOptions || {},
2652
- displayErrorInTerminal: dtsOptions.displayErrorInTerminal
2653
- };
2654
- if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
2655
- finalOptions.remote.tsConfigPath = dtsOptions.tsConfigPath;
2656
- }
2657
- validateOptions(finalOptions.remote);
2658
2735
  const isProd = !isDev();
2659
- const getGenerateTypesFn = /* @__PURE__ */ __name(() => {
2660
- let fn = generateTypes;
2661
- let res;
2662
- if (finalOptions.remote.compileInChildProcess) {
2663
- fn = generateTypesInChildProcess;
2664
- }
2665
- if (isProd) {
2666
- res = fn(finalOptions);
2667
- return () => res;
2668
- }
2669
- return fn;
2670
- }, "getGenerateTypesFn");
2671
- const generateTypesFn = getGenerateTypesFn();
2672
2736
  const emitTypesFiles = /* @__PURE__ */ __name((compilation) => __async(this, null, function* () {
2673
2737
  try {
2674
- const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(finalOptions.remote);
2738
+ const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(dtsManagerOptions.remote);
2675
2739
  if (isProd && zipName && compilation.getAsset(zipName)) {
2676
2740
  callback();
2677
2741
  return;
2678
2742
  }
2679
2743
  import_sdk10.logger.debug("start generating types...");
2680
- yield generateTypesFn(finalOptions);
2744
+ yield generateTypesAPI({
2745
+ dtsManagerOptions
2746
+ });
2681
2747
  import_sdk10.logger.debug("generate types success!");
2682
- const config = finalOptions.remote.moduleFederationConfig;
2748
+ const config = dtsManagerOptions.remote.moduleFederationConfig;
2683
2749
  let zipPrefix = "";
2684
2750
  if (typeof config.manifest === "object" && config.manifest.filePath) {
2685
2751
  zipPrefix = config.manifest.filePath;
@@ -2706,45 +2772,69 @@ var _GenerateTypesPlugin = class _GenerateTypesPlugin {
2706
2772
  const zipContent = import_fs4.default.readFileSync(zipTypesPath);
2707
2773
  const zipOutputPath = import_path10.default.join(compiler.outputPath, zipPrefix, zipName);
2708
2774
  yield new Promise((resolve5, reject) => {
2709
- compiler.outputFileSystem.mkdir(import_path10.default.dirname(zipOutputPath), (err) => {
2710
- if (err && !isEEXIST(err)) {
2711
- reject(err);
2712
- } else {
2713
- compiler.outputFileSystem.writeFile(zipOutputPath, zipContent, (writeErr) => {
2714
- if (writeErr && !isEEXIST(writeErr)) {
2715
- reject(writeErr);
2716
- } else {
2717
- resolve5();
2718
- }
2719
- });
2775
+ compiler.outputFileSystem.mkdir(
2776
+ import_path10.default.dirname(zipOutputPath),
2777
+ {
2778
+ recursive: true
2779
+ },
2780
+ // @ts-ignore type fixed in https://github.com/webpack/webpack/releases/tag/v5.91.0
2781
+ (err) => {
2782
+ if (err && !isEEXIST(err)) {
2783
+ reject(err);
2784
+ } else {
2785
+ compiler.outputFileSystem.writeFile(
2786
+ zipOutputPath,
2787
+ // @ts-ignore
2788
+ zipContent,
2789
+ (writeErr) => {
2790
+ if (writeErr && !isEEXIST(writeErr)) {
2791
+ reject(writeErr);
2792
+ } else {
2793
+ resolve5();
2794
+ }
2795
+ }
2796
+ );
2797
+ }
2720
2798
  }
2721
- });
2799
+ );
2722
2800
  });
2723
2801
  }
2724
2802
  if (apiTypesPath) {
2725
2803
  const apiContent = import_fs4.default.readFileSync(apiTypesPath);
2726
2804
  const apiOutputPath = import_path10.default.join(compiler.outputPath, zipPrefix, apiFileName);
2727
2805
  yield new Promise((resolve5, reject) => {
2728
- compiler.outputFileSystem.mkdir(import_path10.default.dirname(apiOutputPath), (err) => {
2729
- if (err && !isEEXIST(err)) {
2730
- reject(err);
2731
- } else {
2732
- compiler.outputFileSystem.writeFile(apiOutputPath, apiContent, (writeErr) => {
2733
- if (writeErr && !isEEXIST(writeErr)) {
2734
- reject(writeErr);
2735
- } else {
2736
- resolve5();
2737
- }
2738
- });
2806
+ compiler.outputFileSystem.mkdir(
2807
+ import_path10.default.dirname(apiOutputPath),
2808
+ {
2809
+ recursive: true
2810
+ },
2811
+ // @ts-ignore type fixed in https://github.com/webpack/webpack/releases/tag/v5.91.0
2812
+ (err) => {
2813
+ if (err && !isEEXIST(err)) {
2814
+ reject(err);
2815
+ } else {
2816
+ compiler.outputFileSystem.writeFile(
2817
+ apiOutputPath,
2818
+ // @ts-ignore
2819
+ apiContent,
2820
+ (writeErr) => {
2821
+ if (writeErr && !isEEXIST(writeErr)) {
2822
+ reject(writeErr);
2823
+ } else {
2824
+ resolve5();
2825
+ }
2826
+ }
2827
+ );
2828
+ }
2739
2829
  }
2740
- });
2830
+ );
2741
2831
  });
2742
2832
  }
2743
2833
  callback();
2744
2834
  }
2745
2835
  } catch (err) {
2746
2836
  callback();
2747
- if (finalOptions.displayErrorInTerminal) {
2837
+ if (dtsManagerOptions.displayErrorInTerminal) {
2748
2838
  console.error("Error in mf:generateTypes processAssets hook:", err);
2749
2839
  }
2750
2840
  import_sdk10.logger.debug("generate types fail!");
@@ -2771,6 +2861,14 @@ __name(_GenerateTypesPlugin, "GenerateTypesPlugin");
2771
2861
  var GenerateTypesPlugin = _GenerateTypesPlugin;
2772
2862
 
2773
2863
  // packages/dts-plugin/src/plugins/DtsPlugin.ts
2864
+ var normalizeDtsOptions = /* @__PURE__ */ __name((options, context, defaultOptions3) => {
2865
+ return (0, import_sdk11.normalizeOptions)(isTSProject(options.dts, context), {
2866
+ generateTypes: (defaultOptions3 == null ? void 0 : defaultOptions3.defaultGenerateOptions) || DEFAULT_GENERATE_TYPES,
2867
+ consumeTypes: (defaultOptions3 == null ? void 0 : defaultOptions3.defaultConsumeOptions) || DEFAULT_CONSUME_TYPES,
2868
+ extraOptions: {},
2869
+ displayErrorInTerminal: true
2870
+ }, "mfOptions.dts")(options.dts);
2871
+ }, "normalizeDtsOptions");
2774
2872
  var _DtsPlugin = class _DtsPlugin {
2775
2873
  constructor(options) {
2776
2874
  __publicField(this, "options");
@@ -2778,23 +2876,7 @@ var _DtsPlugin = class _DtsPlugin {
2778
2876
  }
2779
2877
  apply(compiler) {
2780
2878
  const { options } = this;
2781
- const defaultGenerateTypes = {
2782
- generateAPITypes: true,
2783
- compileInChildProcess: true,
2784
- abortOnError: false,
2785
- extractThirdParty: false,
2786
- extractRemoteTypes: false
2787
- };
2788
- const defaultConsumeTypes = {
2789
- abortOnError: false,
2790
- consumeAPITypes: true
2791
- };
2792
- const normalizedDtsOptions = (0, import_sdk11.normalizeOptions)(isTSProject(options.dts, compiler.context), {
2793
- generateTypes: defaultGenerateTypes,
2794
- consumeTypes: defaultConsumeTypes,
2795
- extraOptions: {},
2796
- displayErrorInTerminal: true
2797
- }, "mfOptions.dts")(options.dts);
2879
+ const normalizedDtsOptions = normalizeDtsOptions(options, compiler.context);
2798
2880
  if (typeof normalizedDtsOptions !== "object") {
2799
2881
  return;
2800
2882
  }
@@ -2807,13 +2889,19 @@ var _DtsPlugin = class _DtsPlugin {
2807
2889
  generateTypesPromiseResolve = resolve5;
2808
2890
  });
2809
2891
  new DevPlugin(options, normalizedDtsOptions, generateTypesPromise, fetchRemoteTypeUrlsPromise).apply(compiler);
2810
- new GenerateTypesPlugin(options, normalizedDtsOptions, defaultGenerateTypes, fetchRemoteTypeUrlsPromise, generateTypesPromiseResolve).apply(compiler);
2811
- new ConsumeTypesPlugin(options, normalizedDtsOptions, defaultConsumeTypes, fetchRemoteTypeUrlsResolve).apply(compiler);
2892
+ new GenerateTypesPlugin(options, normalizedDtsOptions, fetchRemoteTypeUrlsPromise, generateTypesPromiseResolve).apply(compiler);
2893
+ new ConsumeTypesPlugin(options, normalizedDtsOptions, fetchRemoteTypeUrlsResolve).apply(compiler);
2812
2894
  }
2813
2895
  };
2814
2896
  __name(_DtsPlugin, "DtsPlugin");
2815
2897
  var DtsPlugin = _DtsPlugin;
2816
2898
  // Annotate the CommonJS export names for ESM import in node:
2817
2899
  0 && (module.exports = {
2818
- DtsPlugin
2900
+ DtsPlugin,
2901
+ consumeTypesAPI,
2902
+ generateTypesAPI,
2903
+ isTSProject,
2904
+ normalizeConsumeTypesOptions,
2905
+ normalizeDtsOptions,
2906
+ normalizeGenerateTypesOptions
2819
2907
  });
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/dts-plugin",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -73,7 +73,7 @@
73
73
  "vue": "^3.4.29",
74
74
  "@vue/tsconfig": "^0.5.1",
75
75
  "vue-tsc": "^2.0.26",
76
- "rimraf": "~3.0.2"
76
+ "rimraf": "~6.0.1"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "typescript": "^4.9.0 || ^5.0.0",
@@ -65,7 +65,7 @@ var import_http = require("http");
65
65
  // packages/dts-plugin/src/server/constant.ts
66
66
  var DEFAULT_WEB_SOCKET_PORT = 16322;
67
67
  var WEB_SOCKET_CONNECT_MAGIC_ID = "1hpzW-zo2z-o8io-gfmV1-2cb1d82";
68
- var MF_SERVER_IDENTIFIER = "Module Federation Dev Server";
68
+ var MF_SERVER_IDENTIFIER = "Module Federation DTS";
69
69
  var UpdateMode;
70
70
  (function(UpdateMode2) {
71
71
  UpdateMode2["POSITIVE"] = "POSITIVE";
@@ -0,0 +1,16 @@
1
+ import { moduleFederationPlugin } from '@module-federation/sdk';
2
+ import { H as HostOptions, a as RemoteOptions } from './DTSManagerOptions-c74c59ed.js';
3
+ import { D as DTSManager } from './DTSManager-81645796.js';
4
+
5
+ declare function getDTSManagerConstructor(implementation?: string): typeof DTSManager;
6
+ declare const validateOptions: (options: HostOptions) => void;
7
+ declare function retrieveTypesAssetsInfo(options: RemoteOptions): {
8
+ zipPrefix: string;
9
+ apiTypesPath: string;
10
+ zipTypesPath: string;
11
+ zipName: string;
12
+ apiFileName: string;
13
+ };
14
+ declare const isTSProject: (dtsOptions: moduleFederationPlugin.ModuleFederationPluginOptions["dts"], context?: string) => boolean;
15
+
16
+ export { getDTSManagerConstructor as g, isTSProject as i, retrieveTypesAssetsInfo as r, validateOptions as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/dts-plugin",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -60,10 +60,10 @@
60
60
  "log4js": "6.9.1",
61
61
  "node-schedule": "2.1.1",
62
62
  "ws": "8.18.0",
63
- "@module-federation/sdk": "0.11.1",
64
- "@module-federation/managers": "0.11.1",
65
- "@module-federation/third-party-dts-extractor": "0.11.1",
66
- "@module-federation/error-codes": "0.11.1"
63
+ "@module-federation/sdk": "0.11.3",
64
+ "@module-federation/managers": "0.11.3",
65
+ "@module-federation/third-party-dts-extractor": "0.11.3",
66
+ "@module-federation/error-codes": "0.11.3"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/ws": "8.5.12",
@@ -72,8 +72,8 @@
72
72
  "vue": "^3.4.29",
73
73
  "@vue/tsconfig": "^0.5.1",
74
74
  "vue-tsc": "^2.0.26",
75
- "rimraf": "~3.0.2",
76
- "@module-federation/runtime": "0.11.1"
75
+ "rimraf": "~6.0.1",
76
+ "@module-federation/runtime": "0.11.3"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "typescript": "^4.9.0 || ^5.0.0",