@module-federation/dts-plugin 0.3.0 → 0.3.2

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @module-federation/dts-plugin
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 0de1c83: fix: do not collect node internal utils
8
+ - 85ae159: feat: support rspack ssr
9
+ - Updated dependencies [0de1c83]
10
+ - @module-federation/third-party-dts-extractor@0.3.2
11
+ - @module-federation/sdk@0.3.2
12
+ - @module-federation/managers@0.3.2
13
+
14
+ ## 0.3.1
15
+
16
+ ### Patch Changes
17
+
18
+ - 0a9adaf: chore: remove useless log
19
+ - @module-federation/sdk@0.3.1
20
+ - @module-federation/managers@0.3.1
21
+ - @module-federation/third-party-dts-extractor@0.3.1
22
+
3
23
  ## 0.3.0
4
24
 
5
25
  ### Minor Changes
package/dist/core.js CHANGED
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
24
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -229,9 +241,6 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
229
241
  }
230
242
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
231
243
  } catch (err) {
232
- if (isDebugMode()) {
233
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
234
- }
235
244
  throw err;
236
245
  }
237
246
  }), "compileTs");
@@ -1741,7 +1750,6 @@ function getEffectiveRootDir(parsedCommandLine) {
1741
1750
  }
1742
1751
  __name(getEffectiveRootDir, "getEffectiveRootDir");
1743
1752
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
1744
- var _a3;
1745
1753
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1746
1754
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
1747
1755
  if (readResult.error) {
@@ -1760,9 +1768,11 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1760
1768
  };
1761
1769
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
1762
1770
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
1763
- (_a3 = rawTsConfigJson.compilerOptions) == null ? true : delete _a3.paths;
1771
+ const _a3 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a3, restCompilerOptions = __objRest(_a3, ["paths", "baseUrl"]);
1772
+ rawTsConfigJson.compilerOptions = restCompilerOptions;
1764
1773
  const filesToCompile = [
1765
1774
  ...Object.values(mapComponentsToExpose),
1775
+ ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts")),
1766
1776
  ...additionalFilesToCompile
1767
1777
  ];
1768
1778
  rawTsConfigJson.include = [];
@@ -25,6 +25,18 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
25
25
  return require.apply(this, arguments);
26
26
  throw Error('Dynamic require of "' + x + '" is not supported');
27
27
  });
28
+ var __objRest = (source, exclude) => {
29
+ var target = {};
30
+ for (var prop in source)
31
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
32
+ target[prop] = source[prop];
33
+ if (source != null && __getOwnPropSymbols)
34
+ for (var prop of __getOwnPropSymbols(source)) {
35
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
36
+ target[prop] = source[prop];
37
+ }
38
+ return target;
39
+ };
28
40
  var __export = (target, all) => {
29
41
  for (var name in all)
30
42
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -205,6 +217,7 @@ export {
205
217
  __spreadProps,
206
218
  __name,
207
219
  __require,
220
+ __objRest,
208
221
  __export,
209
222
  __publicField,
210
223
  __async,
@@ -7,7 +7,7 @@ import {
7
7
  getFreePort,
8
8
  getIPV4,
9
9
  getIdentifier
10
- } from "./chunk-HKRTV6ZH.js";
10
+ } from "./chunk-MY3H5SQO.js";
11
11
  import {
12
12
  AddPublisherAction,
13
13
  AddSubscriberAction,
@@ -21,157 +21,126 @@ import {
21
21
  UpdatePublisherAction,
22
22
  __async,
23
23
  __name,
24
+ __objRest,
24
25
  __publicField,
25
26
  __require,
26
27
  __spreadProps,
27
28
  __spreadValues
28
- } from "./chunk-6DND574L.js";
29
+ } from "./chunk-4CSLH7II.js";
29
30
 
30
31
  // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
31
- import { ensureDirSync, writeFileSync, existsSync as existsSync2 } from "fs-extra";
32
+ import { ensureDirSync, writeFileSync, existsSync } from "fs-extra";
32
33
  import crypto from "crypto";
33
- import { stat, readdir, writeFile, rm as rm3, readFile } from "fs/promises";
34
- import { dirname as dirname2, join as join3, normalize, relative, resolve as resolve3, sep, extname as extname2, isAbsolute } from "path";
35
- import { ThirdPartyExtractor as ThirdPartyExtractor2 } from "@module-federation/third-party-dts-extractor";
34
+ import { stat, readdir, writeFile, rm, readFile } from "fs/promises";
35
+ import { dirname, join, normalize, relative, resolve, sep, extname, isAbsolute } from "path";
36
+ import { ThirdPartyExtractor } from "@module-federation/third-party-dts-extractor";
36
37
  import { exec } from "child_process";
37
38
  import util from "util";
38
39
  import { TEMP_DIR } from "@module-federation/sdk";
39
-
40
- // packages/dts-plugin/src/core/lib/utils.ts
41
- import fs3 from "fs";
42
- import path3 from "path";
43
- import axios from "axios";
44
- import http from "http";
45
- import https from "https";
46
- import ansiColors2 from "ansi-colors";
47
-
48
- // packages/dts-plugin/src/core/configurations/remotePlugin.ts
49
- import { existsSync } from "fs";
50
- import { dirname, join, resolve, extname } from "path";
51
- import { utils } from "@module-federation/managers";
52
- import typescript from "typescript";
53
- var defaultOptions = {
54
- tsConfigPath: "./tsconfig.json",
55
- typesFolder: "@mf-types",
56
- compiledTypesFolder: "compiled-types",
57
- hostRemoteTypesFolder: "@mf-types",
58
- deleteTypesFolder: true,
59
- additionalFilesToCompile: [],
60
- compilerInstance: "tsc",
61
- compileInChildProcess: false,
62
- implementation: "",
63
- generateAPITypes: false,
64
- context: process.cwd(),
65
- abortOnError: true,
66
- extractRemoteTypes: false,
67
- extractThirdParty: false
68
- };
69
- function getEffectiveRootDir(parsedCommandLine) {
70
- const compilerOptions = parsedCommandLine.options;
71
- if (compilerOptions.rootDir) {
72
- return compilerOptions.rootDir;
73
- }
74
- const files = parsedCommandLine.fileNames;
75
- if (files.length > 0) {
76
- const commonRoot = files.map((file) => dirname(file)).reduce((commonPath, fileDir) => {
77
- while (!fileDir.startsWith(commonPath)) {
78
- commonPath = dirname(commonPath);
79
- }
80
- return commonPath;
81
- }, files[0]);
82
- return commonRoot;
83
- }
84
- throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
40
+ var STARTS_WITH_SLASH = /^\//;
41
+ var DEFINITION_FILE_EXTENSION = ".d.ts";
42
+ var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
43
+ var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
44
+ var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => join(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
45
+ function writeTempTsConfig(tsConfig, context, name) {
46
+ const createHash = /* @__PURE__ */ __name((contents) => {
47
+ return crypto.createHash("md5").update(contents).digest("hex");
48
+ }, "createHash");
49
+ const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
50
+ const tempTsConfigJsonPath = resolve(context, "node_modules", TEMP_DIR, `tsconfig.${hash}.json`);
51
+ ensureDirSync(dirname(tempTsConfigJsonPath));
52
+ writeFileSync(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
53
+ return tempTsConfigJsonPath;
85
54
  }
86
- __name(getEffectiveRootDir, "getEffectiveRootDir");
87
- var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
88
- var _a2;
89
- const resolvedTsConfigPath = resolve(context, tsConfigPath);
90
- const readResult = typescript.readConfigFile(resolvedTsConfigPath, typescript.sys.readFile);
91
- if (readResult.error) {
92
- throw new Error(readResult.error.messageText.toString());
55
+ __name(writeTempTsConfig, "writeTempTsConfig");
56
+ var removeExt = /* @__PURE__ */ __name((f) => {
57
+ const ext = extname(f);
58
+ const regexPattern = new RegExp(`\\${ext}$`);
59
+ return f.replace(regexPattern, "");
60
+ }, "removeExt");
61
+ function getExposeKey(options) {
62
+ const { filePath, rootDir, outDir, mapExposeToEntry } = options;
63
+ const relativeFilePath = removeExt(relative(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
64
+ return mapExposeToEntry[relativeFilePath];
65
+ }
66
+ __name(getExposeKey, "getExposeKey");
67
+ var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
68
+ const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
69
+ if (!existsSync(filePath)) {
70
+ return;
93
71
  }
94
- const rawTsConfigJson = readResult.config;
95
- const configContent = typescript.parseJsonConfigFileContent(rawTsConfigJson, typescript.sys, dirname(resolvedTsConfigPath));
96
- const rootDir = getEffectiveRootDir(configContent);
97
- const outDir = resolve(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
98
- const defaultCompilerOptions = {
99
- rootDir,
100
- emitDeclarationOnly: true,
101
- noEmit: false,
102
- declaration: true,
103
- outDir
104
- };
105
- rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
106
- rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
107
- (_a2 = rawTsConfigJson.compilerOptions) == null ? true : delete _a2.paths;
108
- const filesToCompile = [
109
- ...Object.values(mapComponentsToExpose),
110
- ...additionalFilesToCompile
111
- ];
112
- rawTsConfigJson.include = [];
113
- rawTsConfigJson.files = filesToCompile;
114
- rawTsConfigJson.exclude = [];
115
- "references" in rawTsConfigJson && delete rawTsConfigJson.references;
116
- rawTsConfigJson.extends = resolvedTsConfigPath;
117
- return rawTsConfigJson;
118
- }, "readTsConfig");
119
- var TS_EXTENSIONS = [
120
- "ts",
121
- "tsx",
122
- "vue",
123
- "svelte"
124
- ];
125
- var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
126
- if (extname(exposedPath)) {
127
- return resolve(context, exposedPath);
72
+ const stats = yield stat(filePath);
73
+ if (stats.isDirectory()) {
74
+ const files = yield readdir(filePath);
75
+ yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
76
+ filePath: join(filePath, file)
77
+ }))));
78
+ } else if (filePath.endsWith(".d.ts")) {
79
+ const exposeKey = getExposeKey({
80
+ filePath,
81
+ rootDir,
82
+ outDir,
83
+ mapExposeToEntry
84
+ });
85
+ if (exposeKey) {
86
+ const sourceEntry = exposeKey === "." ? "index" : exposeKey;
87
+ const mfeTypeEntry = join(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
88
+ const mfeTypeEntryDirectory = dirname(mfeTypeEntry);
89
+ const relativePathToOutput = relative(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(sep).join("/");
90
+ ensureDirSync(mfeTypeEntryDirectory);
91
+ yield writeFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
92
+ export { default } from './${relativePathToOutput}';`);
93
+ }
94
+ const content = yield readFile(filePath, "utf8");
95
+ cb(content);
128
96
  }
129
- for (const extension of TS_EXTENSIONS) {
130
- const exposedPathWithExtension = resolve(context, `${exposedPath}.${extension}`);
131
- if (existsSync(exposedPathWithExtension)) {
132
- return exposedPathWithExtension;
97
+ }), "processTypesFile");
98
+ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
99
+ if (!Object.keys(mapComponentsToExpose).length) {
100
+ return;
101
+ }
102
+ const { compilerOptions } = tsConfig;
103
+ const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
104
+ try {
105
+ const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
106
+ const thirdPartyExtractor = new ThirdPartyExtractor(resolve(mfTypePath, "node_modules"), remoteOptions.context);
107
+ const execPromise = util.promisify(exec);
108
+ const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
109
+ try {
110
+ yield execPromise(cmd);
111
+ } catch (err) {
112
+ throw new Error(`compile TS failed, the original command is '${cmd}'`);
113
+ }
114
+ const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
115
+ const normalizedFileName = normalize(filename);
116
+ let relativeFileName = "";
117
+ if (isAbsolute(normalizedFileName)) {
118
+ relativeFileName = relative(tsConfig.compilerOptions.rootDir, normalizedFileName);
119
+ } else {
120
+ relativeFileName = relative(tsConfig.compilerOptions.rootDir, resolve(remoteOptions.context, normalizedFileName));
121
+ }
122
+ return [
123
+ removeExt(relativeFileName),
124
+ exposed
125
+ ];
126
+ }));
127
+ const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
128
+ yield processTypesFile({
129
+ outDir: compilerOptions.outDir,
130
+ filePath: compilerOptions.outDir,
131
+ rootDir: compilerOptions.rootDir,
132
+ mfTypePath,
133
+ cb,
134
+ mapExposeToEntry
135
+ });
136
+ if (remoteOptions.extractThirdParty) {
137
+ yield thirdPartyExtractor.copyDts();
133
138
  }
139
+ yield rm(tempTsConfigJsonPath);
140
+ } catch (err) {
141
+ throw err;
134
142
  }
135
- return void 0;
136
- }, "resolveWithExtension");
137
- var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
138
- const parsedOptions = utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
139
- exposePath: Array.isArray(item) ? item[0] : item,
140
- key
141
- }), (item, key) => ({
142
- exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
143
- key
144
- }));
145
- return parsedOptions.reduce((accumulator, item) => {
146
- const { exposePath, key } = item[1];
147
- accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(join(exposePath, "index"), remoteOptions.context) || exposePath;
148
- return accumulator;
149
- }, {});
150
- }, "resolveExposes");
151
- var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
152
- validateOptions(options);
153
- const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
154
- const mapComponentsToExpose = resolveExposes(remoteOptions);
155
- const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
156
- return {
157
- tsConfig,
158
- mapComponentsToExpose,
159
- remoteOptions
160
- };
161
- }, "retrieveRemoteConfig");
162
-
163
- // packages/dts-plugin/src/core/lib/DTSManager.ts
164
- import ansiColors from "ansi-colors";
165
- import path2 from "path";
166
- import { rm as rm2 } from "fs/promises";
167
- import fs2 from "fs";
168
- import { MANIFEST_EXT, inferAutoPublicPath } from "@module-federation/sdk";
169
- import { ThirdPartyExtractor } from "@module-federation/third-party-dts-extractor";
170
-
171
- // packages/dts-plugin/src/core/lib/archiveHandler.ts
172
- import AdmZip from "adm-zip";
173
- import { resolve as resolve2, join as join2 } from "path";
174
- import { rm } from "fs/promises";
143
+ }), "compileTs");
175
144
 
176
145
  // packages/dts-plugin/src/server/DevServer.ts
177
146
  import WebSocket from "isomorphic-ws";
@@ -575,59 +544,141 @@ function createKoaServer(options) {
575
544
  __name(createKoaServer, "createKoaServer");
576
545
 
577
546
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
578
- var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => join2(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
579
- var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
580
- const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
581
- const zip = new AdmZip();
582
- zip.addLocalFolder(mfTypesPath);
583
- return zip.writeZipPromise(retrieveTypesZipPath(mfTypesPath, remoteOptions));
584
- }), "createTypesArchive");
585
- var downloadErrorLogger = /* @__PURE__ */ __name((destinationFolder, fileToDownload) => (reason) => {
586
- throw __spreadProps(__spreadValues({}, reason), {
587
- message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`
588
- });
589
- }, "downloadErrorLogger");
590
- var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, destinationFolder) => {
591
- return resolve2(hostOptions.context, hostOptions.typesFolder, destinationFolder);
592
- }, "retrieveTypesArchiveDestinationPath");
593
- var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
594
- let retries = 0;
595
- return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
596
- const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
597
- while (retries++ < hostOptions.maxRetries) {
598
- try {
599
- const url = fileToDownload;
600
- const response = yield axiosGet(url, {
601
- responseType: "arraybuffer"
602
- }).catch(downloadErrorLogger(destinationFolder, url));
603
- try {
604
- if (hostOptions.deleteTypesFolder) {
605
- yield rm(destinationPath, {
606
- recursive: true,
607
- force: true
608
- });
609
- }
610
- } catch (error) {
611
- fileLog(`Unable to remove types folder, ${error}`, "downloadTypesArchive", "error");
612
- }
613
- const zip = new AdmZip(Buffer.from(response.data));
614
- zip.extractAllTo(destinationPath, true);
615
- return [
616
- destinationFolder,
617
- destinationPath
618
- ];
619
- } catch (error) {
620
- fileLog(`Error during types archive download: ${(error == null ? void 0 : error.message) || "unknown error"}`, "downloadTypesArchive", "error");
621
- if (retries >= hostOptions.maxRetries) {
622
- if (hostOptions.abortOnError !== false) {
623
- throw error;
624
- }
625
- return void 0;
626
- }
547
+ import AdmZip from "adm-zip";
548
+ import { resolve as resolve3, join as join3 } from "path";
549
+ import { rm as rm3 } from "fs/promises";
550
+
551
+ // packages/dts-plugin/src/core/lib/utils.ts
552
+ import fs3 from "fs";
553
+ import path3 from "path";
554
+ import axios from "axios";
555
+ import http from "http";
556
+ import https from "https";
557
+ import ansiColors2 from "ansi-colors";
558
+
559
+ // packages/dts-plugin/src/core/configurations/remotePlugin.ts
560
+ import { existsSync as existsSync2 } from "fs";
561
+ import { dirname as dirname2, join as join2, resolve as resolve2, extname as extname2 } from "path";
562
+ import { utils } from "@module-federation/managers";
563
+ import typescript from "typescript";
564
+ var defaultOptions = {
565
+ tsConfigPath: "./tsconfig.json",
566
+ typesFolder: "@mf-types",
567
+ compiledTypesFolder: "compiled-types",
568
+ hostRemoteTypesFolder: "@mf-types",
569
+ deleteTypesFolder: true,
570
+ additionalFilesToCompile: [],
571
+ compilerInstance: "tsc",
572
+ compileInChildProcess: false,
573
+ implementation: "",
574
+ generateAPITypes: false,
575
+ context: process.cwd(),
576
+ abortOnError: true,
577
+ extractRemoteTypes: false,
578
+ extractThirdParty: false
579
+ };
580
+ function getEffectiveRootDir(parsedCommandLine) {
581
+ const compilerOptions = parsedCommandLine.options;
582
+ if (compilerOptions.rootDir) {
583
+ return compilerOptions.rootDir;
584
+ }
585
+ const files = parsedCommandLine.fileNames;
586
+ if (files.length > 0) {
587
+ const commonRoot = files.map((file) => dirname2(file)).reduce((commonPath, fileDir) => {
588
+ while (!fileDir.startsWith(commonPath)) {
589
+ commonPath = dirname2(commonPath);
627
590
  }
591
+ return commonPath;
592
+ }, files[0]);
593
+ return commonRoot;
594
+ }
595
+ throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
596
+ }
597
+ __name(getEffectiveRootDir, "getEffectiveRootDir");
598
+ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
599
+ const resolvedTsConfigPath = resolve2(context, tsConfigPath);
600
+ const readResult = typescript.readConfigFile(resolvedTsConfigPath, typescript.sys.readFile);
601
+ if (readResult.error) {
602
+ throw new Error(readResult.error.messageText.toString());
603
+ }
604
+ const rawTsConfigJson = readResult.config;
605
+ const configContent = typescript.parseJsonConfigFileContent(rawTsConfigJson, typescript.sys, dirname2(resolvedTsConfigPath));
606
+ const rootDir = getEffectiveRootDir(configContent);
607
+ const outDir = resolve2(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
608
+ const defaultCompilerOptions = {
609
+ rootDir,
610
+ emitDeclarationOnly: true,
611
+ noEmit: false,
612
+ declaration: true,
613
+ outDir
614
+ };
615
+ rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
616
+ rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
617
+ const _a2 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a2, restCompilerOptions = __objRest(_a2, ["paths", "baseUrl"]);
618
+ rawTsConfigJson.compilerOptions = restCompilerOptions;
619
+ const filesToCompile = [
620
+ ...Object.values(mapComponentsToExpose),
621
+ ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts")),
622
+ ...additionalFilesToCompile
623
+ ];
624
+ rawTsConfigJson.include = [];
625
+ rawTsConfigJson.files = filesToCompile;
626
+ rawTsConfigJson.exclude = [];
627
+ "references" in rawTsConfigJson && delete rawTsConfigJson.references;
628
+ rawTsConfigJson.extends = resolvedTsConfigPath;
629
+ return rawTsConfigJson;
630
+ }, "readTsConfig");
631
+ var TS_EXTENSIONS = [
632
+ "ts",
633
+ "tsx",
634
+ "vue",
635
+ "svelte"
636
+ ];
637
+ var resolveWithExtension = /* @__PURE__ */ __name((exposedPath, context) => {
638
+ if (extname2(exposedPath)) {
639
+ return resolve2(context, exposedPath);
640
+ }
641
+ for (const extension of TS_EXTENSIONS) {
642
+ const exposedPathWithExtension = resolve2(context, `${exposedPath}.${extension}`);
643
+ if (existsSync2(exposedPathWithExtension)) {
644
+ return exposedPathWithExtension;
628
645
  }
629
- });
630
- }, "downloadTypesArchive");
646
+ }
647
+ return void 0;
648
+ }, "resolveWithExtension");
649
+ var resolveExposes = /* @__PURE__ */ __name((remoteOptions) => {
650
+ const parsedOptions = utils.parseOptions(remoteOptions.moduleFederationConfig.exposes || {}, (item, key) => ({
651
+ exposePath: Array.isArray(item) ? item[0] : item,
652
+ key
653
+ }), (item, key) => ({
654
+ exposePath: Array.isArray(item.import) ? item.import[0] : item.import[0],
655
+ key
656
+ }));
657
+ return parsedOptions.reduce((accumulator, item) => {
658
+ const { exposePath, key } = item[1];
659
+ accumulator[key] = resolveWithExtension(exposePath, remoteOptions.context) || resolveWithExtension(join2(exposePath, "index"), remoteOptions.context) || exposePath;
660
+ return accumulator;
661
+ }, {});
662
+ }, "resolveExposes");
663
+ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
664
+ validateOptions(options);
665
+ const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
666
+ const mapComponentsToExpose = resolveExposes(remoteOptions);
667
+ const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
668
+ return {
669
+ tsConfig,
670
+ mapComponentsToExpose,
671
+ remoteOptions
672
+ };
673
+ }, "retrieveRemoteConfig");
674
+
675
+ // packages/dts-plugin/src/core/lib/DTSManager.ts
676
+ import ansiColors from "ansi-colors";
677
+ import path2 from "path";
678
+ import { rm as rm2 } from "fs/promises";
679
+ import fs2 from "fs";
680
+ import { MANIFEST_EXT, inferAutoPublicPath } from "@module-federation/sdk";
681
+ import { ThirdPartyExtractor as ThirdPartyExtractor2 } from "@module-federation/third-party-dts-extractor";
631
682
 
632
683
  // packages/dts-plugin/src/core/configurations/hostPlugin.ts
633
684
  import { parseEntry, ENCODE_NAME_PREFIX, decodeName } from "@module-federation/sdk";
@@ -900,7 +951,7 @@ var DTSManager = (_a = class {
900
951
  const apiTypeFileName = path2.join(hostOptions.context, hostOptions.typesFolder, HOST_API_TYPES_FILE_NAME);
901
952
  try {
902
953
  const existedFile = fs2.readFileSync(apiTypeFileName, "utf-8");
903
- const existedImports = new ThirdPartyExtractor("").collectTypeImports(existedFile);
954
+ const existedImports = new ThirdPartyExtractor2("").collectTypeImports(existedFile);
904
955
  existedImports.forEach((existedImport) => {
905
956
  const alias = existedImport.split("./").slice(1).join("./").replace("/apis.d.ts", "");
906
957
  this.loadedRemoteAPIAlias.add(alias);
@@ -1168,114 +1219,60 @@ function axiosGet(url, config) {
1168
1219
  }
1169
1220
  __name(axiosGet, "axiosGet");
1170
1221
 
1171
- // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
1172
- var STARTS_WITH_SLASH = /^\//;
1173
- var DEFINITION_FILE_EXTENSION = ".d.ts";
1174
- var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
1175
- var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => normalize(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
1176
- var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => join3(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
1177
- function writeTempTsConfig(tsConfig, context, name) {
1178
- const createHash = /* @__PURE__ */ __name((contents) => {
1179
- return crypto.createHash("md5").update(contents).digest("hex");
1180
- }, "createHash");
1181
- const hash = createHash(`${JSON.stringify(tsConfig)}${name}`);
1182
- const tempTsConfigJsonPath = resolve3(context, "node_modules", TEMP_DIR, `tsconfig.${hash}.json`);
1183
- ensureDirSync(dirname2(tempTsConfigJsonPath));
1184
- writeFileSync(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
1185
- return tempTsConfigJsonPath;
1186
- }
1187
- __name(writeTempTsConfig, "writeTempTsConfig");
1188
- var removeExt = /* @__PURE__ */ __name((f) => {
1189
- const ext = extname2(f);
1190
- const regexPattern = new RegExp(`\\${ext}$`);
1191
- return f.replace(regexPattern, "");
1192
- }, "removeExt");
1193
- function getExposeKey(options) {
1194
- const { filePath, rootDir, outDir, mapExposeToEntry } = options;
1195
- const relativeFilePath = removeExt(relative(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
1196
- return mapExposeToEntry[relativeFilePath];
1197
- }
1198
- __name(getExposeKey, "getExposeKey");
1199
- var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
1200
- const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
1201
- if (!existsSync2(filePath)) {
1202
- return;
1203
- }
1204
- const stats = yield stat(filePath);
1205
- if (stats.isDirectory()) {
1206
- const files = yield readdir(filePath);
1207
- yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
1208
- filePath: join3(filePath, file)
1209
- }))));
1210
- } else if (filePath.endsWith(".d.ts")) {
1211
- const exposeKey = getExposeKey({
1212
- filePath,
1213
- rootDir,
1214
- outDir,
1215
- mapExposeToEntry
1216
- });
1217
- if (exposeKey) {
1218
- const sourceEntry = exposeKey === "." ? "index" : exposeKey;
1219
- const mfeTypeEntry = join3(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
1220
- const mfeTypeEntryDirectory = dirname2(mfeTypeEntry);
1221
- const relativePathToOutput = relative(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(sep).join("/");
1222
- ensureDirSync(mfeTypeEntryDirectory);
1223
- yield writeFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
1224
- export { default } from './${relativePathToOutput}';`);
1225
- }
1226
- const content = yield readFile(filePath, "utf8");
1227
- cb(content);
1228
- }
1229
- }), "processTypesFile");
1230
- var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
1231
- if (!Object.keys(mapComponentsToExpose).length) {
1232
- return;
1233
- }
1234
- const { compilerOptions } = tsConfig;
1235
- const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context, remoteOptions.moduleFederationConfig.name || "mf");
1236
- try {
1237
- const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
1238
- const thirdPartyExtractor = new ThirdPartyExtractor2(resolve3(mfTypePath, "node_modules"), remoteOptions.context);
1239
- const execPromise = util.promisify(exec);
1240
- const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
1241
- try {
1242
- yield execPromise(cmd);
1243
- } catch (err) {
1244
- throw new Error(`compile TS failed, the original command is '${cmd}'`);
1245
- }
1246
- const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
1247
- const normalizedFileName = normalize(filename);
1248
- let relativeFileName = "";
1249
- if (isAbsolute(normalizedFileName)) {
1250
- relativeFileName = relative(tsConfig.compilerOptions.rootDir, normalizedFileName);
1251
- } else {
1252
- relativeFileName = relative(tsConfig.compilerOptions.rootDir, resolve3(remoteOptions.context, normalizedFileName));
1222
+ // packages/dts-plugin/src/core/lib/archiveHandler.ts
1223
+ var retrieveTypesZipPath = /* @__PURE__ */ __name((mfTypesPath, remoteOptions) => join3(mfTypesPath.replace(remoteOptions.typesFolder, ""), `${remoteOptions.typesFolder}.zip`), "retrieveTypesZipPath");
1224
+ var createTypesArchive = /* @__PURE__ */ __name((tsConfig, remoteOptions) => __async(void 0, null, function* () {
1225
+ const mfTypesPath = retrieveMfTypesPath(tsConfig, remoteOptions);
1226
+ const zip = new AdmZip();
1227
+ zip.addLocalFolder(mfTypesPath);
1228
+ return zip.writeZipPromise(retrieveTypesZipPath(mfTypesPath, remoteOptions));
1229
+ }), "createTypesArchive");
1230
+ var downloadErrorLogger = /* @__PURE__ */ __name((destinationFolder, fileToDownload) => (reason) => {
1231
+ throw __spreadProps(__spreadValues({}, reason), {
1232
+ message: `Network error: Unable to download federated mocks for '${destinationFolder}' from '${fileToDownload}' because '${reason.message}'`
1233
+ });
1234
+ }, "downloadErrorLogger");
1235
+ var retrieveTypesArchiveDestinationPath = /* @__PURE__ */ __name((hostOptions, destinationFolder) => {
1236
+ return resolve3(hostOptions.context, hostOptions.typesFolder, destinationFolder);
1237
+ }, "retrieveTypesArchiveDestinationPath");
1238
+ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1239
+ let retries = 0;
1240
+ return (_0) => __async(void 0, [_0], function* ([destinationFolder, fileToDownload]) {
1241
+ const destinationPath = retrieveTypesArchiveDestinationPath(hostOptions, destinationFolder);
1242
+ while (retries++ < hostOptions.maxRetries) {
1243
+ try {
1244
+ const url = fileToDownload;
1245
+ const response = yield axiosGet(url, {
1246
+ responseType: "arraybuffer"
1247
+ }).catch(downloadErrorLogger(destinationFolder, url));
1248
+ try {
1249
+ if (hostOptions.deleteTypesFolder) {
1250
+ yield rm3(destinationPath, {
1251
+ recursive: true,
1252
+ force: true
1253
+ });
1254
+ }
1255
+ } catch (error) {
1256
+ fileLog(`Unable to remove types folder, ${error}`, "downloadTypesArchive", "error");
1257
+ }
1258
+ const zip = new AdmZip(Buffer.from(response.data));
1259
+ zip.extractAllTo(destinationPath, true);
1260
+ return [
1261
+ destinationFolder,
1262
+ destinationPath
1263
+ ];
1264
+ } catch (error) {
1265
+ fileLog(`Error during types archive download: ${(error == null ? void 0 : error.message) || "unknown error"}`, "downloadTypesArchive", "error");
1266
+ if (retries >= hostOptions.maxRetries) {
1267
+ if (hostOptions.abortOnError !== false) {
1268
+ throw error;
1269
+ }
1270
+ return void 0;
1271
+ }
1253
1272
  }
1254
- return [
1255
- removeExt(relativeFileName),
1256
- exposed
1257
- ];
1258
- }));
1259
- const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
1260
- yield processTypesFile({
1261
- outDir: compilerOptions.outDir,
1262
- filePath: compilerOptions.outDir,
1263
- rootDir: compilerOptions.rootDir,
1264
- mfTypePath,
1265
- cb,
1266
- mapExposeToEntry
1267
- });
1268
- if (remoteOptions.extractThirdParty) {
1269
- yield thirdPartyExtractor.copyDts();
1270
1273
  }
1271
- yield rm3(tempTsConfigJsonPath);
1272
- } catch (err) {
1273
- if (isDebugMode()) {
1274
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
1275
- }
1276
- throw err;
1277
- }
1278
- }), "compileTs");
1274
+ });
1275
+ }, "downloadTypesArchive");
1279
1276
 
1280
1277
  // packages/dts-plugin/src/core/lib/generateTypes.ts
1281
1278
  function generateTypes(options) {
@@ -4,7 +4,7 @@ import {
4
4
  exposeRpc,
5
5
  getDTSManagerConstructor,
6
6
  isDebugMode
7
- } from "./chunk-SFEGBRA3.js";
7
+ } from "./chunk-I4MF3J7G.js";
8
8
  import {
9
9
  __async,
10
10
  __export,
@@ -12,7 +12,7 @@ import {
12
12
  __publicField,
13
13
  __spreadProps,
14
14
  __spreadValues
15
- } from "./chunk-6DND574L.js";
15
+ } from "./chunk-4CSLH7II.js";
16
16
 
17
17
  // packages/dts-plugin/src/core/lib/DtsWorker.ts
18
18
  import path from "path";
@@ -8,7 +8,7 @@ import {
8
8
  __async,
9
9
  __name,
10
10
  __publicField
11
- } from "./chunk-6DND574L.js";
11
+ } from "./chunk-4CSLH7II.js";
12
12
 
13
13
  // packages/dts-plugin/src/server/utils/log.ts
14
14
  import { logger } from "@module-federation/sdk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __name
3
- } from "./chunk-6DND574L.js";
3
+ } from "./chunk-4CSLH7II.js";
4
4
 
5
5
  // packages/dts-plugin/src/dev-worker/utils.ts
6
6
  var DEFAULT_LOCAL_IPS = [
package/dist/esm/core.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  consumeTypes,
4
4
  generateTypesInChildProcess,
5
5
  rpc_exports
6
- } from "./chunk-DEW2PNCR.js";
6
+ } from "./chunk-IW3CXUPB.js";
7
7
  import {
8
8
  DTSManager,
9
9
  HOST_API_TYPES_FILE_NAME,
@@ -19,9 +19,9 @@ import {
19
19
  retrieveTypesAssetsInfo,
20
20
  retrieveTypesZipPath,
21
21
  validateOptions
22
- } from "./chunk-SFEGBRA3.js";
23
- import "./chunk-HKRTV6ZH.js";
24
- import "./chunk-6DND574L.js";
22
+ } from "./chunk-I4MF3J7G.js";
23
+ import "./chunk-MY3H5SQO.js";
24
+ import "./chunk-4CSLH7II.js";
25
25
  export {
26
26
  DTSManager,
27
27
  DtsWorker,
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  getIpFromEntry
3
- } from "./chunk-XKCIYRDL.js";
3
+ } from "./chunk-QAUALHAU.js";
4
4
  import {
5
5
  AddDynamicRemoteAction,
6
6
  DEFAULT_WEB_SOCKET_PORT,
7
7
  FetchTypesAction,
8
8
  WEB_SOCKET_CONNECT_MAGIC_ID,
9
9
  __name
10
- } from "./chunk-6DND574L.js";
10
+ } from "./chunk-4CSLH7II.js";
11
11
 
12
12
  // packages/dts-plugin/src/server/createWebsocket.ts
13
13
  import WebSocket from "isomorphic-ws";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  rpc_exports
3
- } from "./chunk-DEW2PNCR.js";
3
+ } from "./chunk-IW3CXUPB.js";
4
4
  import {
5
5
  ModuleFederationDevServer,
6
6
  createKoaServer,
@@ -9,21 +9,21 @@ import {
9
9
  retrieveMfTypesPath,
10
10
  retrieveRemoteConfig,
11
11
  retrieveTypesZipPath
12
- } from "./chunk-SFEGBRA3.js";
12
+ } from "./chunk-I4MF3J7G.js";
13
13
  import {
14
14
  fileLog,
15
15
  getIPV4
16
- } from "./chunk-HKRTV6ZH.js";
16
+ } from "./chunk-MY3H5SQO.js";
17
17
  import {
18
18
  getIpFromEntry
19
- } from "./chunk-XKCIYRDL.js";
19
+ } from "./chunk-QAUALHAU.js";
20
20
  import {
21
21
  DEFAULT_TAR_NAME,
22
22
  UpdateKind,
23
23
  UpdateMode,
24
24
  __async,
25
25
  __name
26
- } from "./chunk-6DND574L.js";
26
+ } from "./chunk-4CSLH7II.js";
27
27
 
28
28
  // packages/dts-plugin/src/dev-worker/forkDevWorker.ts
29
29
  import { decodeName } from "@module-federation/sdk";
@@ -2,12 +2,12 @@ import {
2
2
  RpcGMCallTypes,
3
3
  exposeRpc,
4
4
  generateTypes
5
- } from "./chunk-SFEGBRA3.js";
6
- import "./chunk-HKRTV6ZH.js";
5
+ } from "./chunk-I4MF3J7G.js";
6
+ import "./chunk-MY3H5SQO.js";
7
7
  import {
8
8
  __async,
9
9
  __name
10
- } from "./chunk-6DND574L.js";
10
+ } from "./chunk-4CSLH7II.js";
11
11
 
12
12
  // packages/dts-plugin/src/core/lib/forkGenerateDts.ts
13
13
  function forkGenerateDts(options) {
package/dist/esm/index.js CHANGED
@@ -2,17 +2,17 @@ import {
2
2
  consumeTypes,
3
3
  generateTypesInChildProcess,
4
4
  rpc_exports
5
- } from "./chunk-DEW2PNCR.js";
5
+ } from "./chunk-IW3CXUPB.js";
6
6
  import {
7
7
  cloneDeepOptions,
8
8
  generateTypes,
9
9
  isTSProject,
10
10
  retrieveTypesAssetsInfo,
11
11
  validateOptions
12
- } from "./chunk-SFEGBRA3.js";
12
+ } from "./chunk-I4MF3J7G.js";
13
13
  import {
14
14
  getIPV4
15
- } from "./chunk-HKRTV6ZH.js";
15
+ } from "./chunk-MY3H5SQO.js";
16
16
  import {
17
17
  WEB_CLIENT_OPTIONS_IDENTIFIER,
18
18
  __async,
@@ -20,7 +20,7 @@ import {
20
20
  __publicField,
21
21
  __spreadProps,
22
22
  __spreadValues
23
- } from "./chunk-6DND574L.js";
23
+ } from "./chunk-4CSLH7II.js";
24
24
 
25
25
  // packages/dts-plugin/src/plugins/DevPlugin.ts
26
26
  import fs from "fs-extra";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  Broker,
3
3
  fileLog
4
- } from "./chunk-HKRTV6ZH.js";
4
+ } from "./chunk-MY3H5SQO.js";
5
5
  import {
6
6
  __async,
7
7
  __name
8
- } from "./chunk-6DND574L.js";
8
+ } from "./chunk-4CSLH7II.js";
9
9
 
10
10
  // packages/dts-plugin/src/server/broker/startBroker.ts
11
11
  var broker;
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
24
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -210,9 +222,6 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
210
222
  }
211
223
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
212
224
  } catch (err) {
213
- if (isDebugMode()) {
214
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
215
- }
216
225
  throw err;
217
226
  }
218
227
  }), "compileTs");
@@ -2197,7 +2206,6 @@ function getEffectiveRootDir(parsedCommandLine) {
2197
2206
  }
2198
2207
  __name(getEffectiveRootDir, "getEffectiveRootDir");
2199
2208
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
2200
- var _a3;
2201
2209
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
2202
2210
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
2203
2211
  if (readResult.error) {
@@ -2216,9 +2224,11 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
2216
2224
  };
2217
2225
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
2218
2226
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
2219
- (_a3 = rawTsConfigJson.compilerOptions) == null ? true : delete _a3.paths;
2227
+ const _a3 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a3, restCompilerOptions = __objRest(_a3, ["paths", "baseUrl"]);
2228
+ rawTsConfigJson.compilerOptions = restCompilerOptions;
2220
2229
  const filesToCompile = [
2221
2230
  ...Object.values(mapComponentsToExpose),
2231
+ ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts")),
2222
2232
  ...additionalFilesToCompile
2223
2233
  ];
2224
2234
  rawTsConfigJson.include = [];
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
24
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -189,7 +201,6 @@ function getEffectiveRootDir(parsedCommandLine) {
189
201
  }
190
202
  __name(getEffectiveRootDir, "getEffectiveRootDir");
191
203
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
192
- var _a2;
193
204
  const resolvedTsConfigPath = (0, import_path.resolve)(context, tsConfigPath);
194
205
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
195
206
  if (readResult.error) {
@@ -208,9 +219,11 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
208
219
  };
209
220
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
210
221
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
211
- (_a2 = rawTsConfigJson.compilerOptions) == null ? true : delete _a2.paths;
222
+ const _a2 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a2, restCompilerOptions = __objRest(_a2, ["paths", "baseUrl"]);
223
+ rawTsConfigJson.compilerOptions = restCompilerOptions;
212
224
  const filesToCompile = [
213
225
  ...Object.values(mapComponentsToExpose),
226
+ ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts")),
214
227
  ...additionalFilesToCompile
215
228
  ];
216
229
  rawTsConfigJson.include = [];
@@ -387,9 +400,6 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
387
400
  }
388
401
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
389
402
  } catch (err) {
390
- if (isDebugMode()) {
391
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
392
- }
393
403
  throw err;
394
404
  }
395
405
  }), "compileTs");
package/dist/index.js CHANGED
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
24
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -223,9 +235,6 @@ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteO
223
235
  }
224
236
  yield (0, import_promises.rm)(tempTsConfigJsonPath);
225
237
  } catch (err) {
226
- if (isDebugMode()) {
227
- console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
228
- }
229
238
  throw err;
230
239
  }
231
240
  }), "compileTs");
@@ -1764,7 +1773,6 @@ function getEffectiveRootDir(parsedCommandLine) {
1764
1773
  }
1765
1774
  __name(getEffectiveRootDir, "getEffectiveRootDir");
1766
1775
  var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
1767
- var _a4;
1768
1776
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1769
1777
  const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
1770
1778
  if (readResult.error) {
@@ -1783,9 +1791,11 @@ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiled
1783
1791
  };
1784
1792
  rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
1785
1793
  rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
1786
- (_a4 = rawTsConfigJson.compilerOptions) == null ? true : delete _a4.paths;
1794
+ const _a4 = rawTsConfigJson.compilerOptions || {}, { paths, baseUrl } = _a4, restCompilerOptions = __objRest(_a4, ["paths", "baseUrl"]);
1795
+ rawTsConfigJson.compilerOptions = restCompilerOptions;
1787
1796
  const filesToCompile = [
1788
1797
  ...Object.values(mapComponentsToExpose),
1798
+ ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts")),
1789
1799
  ...additionalFilesToCompile
1790
1800
  ];
1791
1801
  rawTsConfigJson.include = [];
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/dts-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/dts-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "author": "hanric <hanric.zhang@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -55,9 +55,9 @@
55
55
  "log4js": "6.9.1",
56
56
  "node-schedule": "2.1.1",
57
57
  "ws": "8.17.1",
58
- "@module-federation/sdk": "0.3.0",
59
- "@module-federation/managers": "0.3.0",
60
- "@module-federation/third-party-dts-extractor": "0.3.0"
58
+ "@module-federation/sdk": "0.3.2",
59
+ "@module-federation/managers": "0.3.2",
60
+ "@module-federation/third-party-dts-extractor": "0.3.2"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/ws": "8.5.10",
@@ -66,7 +66,7 @@
66
66
  "vue": "^3.4.29",
67
67
  "@vue/tsconfig": "^0.5.1",
68
68
  "vue-tsc": "^2.0.26",
69
- "@module-federation/runtime": "0.3.0"
69
+ "@module-federation/runtime": "0.3.2"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "typescript": "^4.9.0 || ^5.0.0",