@module-federation/dts-plugin 0.2.6 → 0.2.8

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.
@@ -79,104 +79,140 @@ module.exports = __toCommonJS(forkDevWorker_exports);
79
79
  var import_fs2 = require("fs");
80
80
  var import_path5 = require("path");
81
81
  var import_managers2 = require("@module-federation/managers");
82
- var import_typescript2 = __toESM(require("typescript"));
82
+ var import_typescript = __toESM(require("typescript"));
83
83
 
84
84
  // packages/dts-plugin/src/core/lib/utils.ts
85
85
  var import_axios = __toESM(require("axios"));
86
86
  var import_http2 = __toESM(require("http"));
87
87
  var import_https = __toESM(require("https"));
88
- var import_ansi_colors3 = __toESM(require("ansi-colors"));
88
+ var import_ansi_colors2 = __toESM(require("ansi-colors"));
89
89
 
90
90
  // packages/dts-plugin/src/core/lib/DTSManager.ts
91
- var import_ansi_colors2 = __toESM(require("ansi-colors"));
91
+ var import_ansi_colors = __toESM(require("ansi-colors"));
92
92
  var import_path4 = __toESM(require("path"));
93
- var import_promises2 = require("fs/promises");
93
+ var import_promises3 = require("fs/promises");
94
94
  var import_fs = __toESM(require("fs"));
95
- var import_sdk4 = require("@module-federation/sdk");
95
+ var import_sdk5 = require("@module-federation/sdk");
96
96
  var import_lodash = __toESM(require("lodash.clonedeepwith"));
97
97
  var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
98
98
 
99
99
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
100
100
  var import_adm_zip = __toESM(require("adm-zip"));
101
101
  var import_path3 = require("path");
102
- var import_promises = require("fs/promises");
102
+ var import_promises2 = require("fs/promises");
103
103
 
104
104
  // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
105
- var import_ansi_colors = __toESM(require("ansi-colors"));
105
+ var import_fs_extra = require("fs-extra");
106
+ var import_promises = require("fs/promises");
107
+ var import_crypto = require("crypto");
106
108
  var import_path = require("path");
107
- var import_typescript = __toESM(require("typescript"));
108
109
  var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
110
+ var import_child_process = require("child_process");
111
+ var import_util = __toESM(require("util"));
112
+ var import_sdk = require("@module-federation/sdk");
109
113
  var STARTS_WITH_SLASH = /^\//;
110
114
  var DEFINITION_FILE_EXTENSION = ".d.ts";
111
- var reportCompileDiagnostic = /* @__PURE__ */ __name((diagnostic) => {
112
- const { line } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
113
- console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
114
- console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
115
- }, "reportCompileDiagnostic");
116
- var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
117
- var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
115
+ var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
116
+ var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
118
117
  var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
119
- var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
120
- const host = import_typescript.default.createCompilerHost(tsConfig);
121
- const originalWriteFile = host.writeFile;
122
- const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => [
123
- (0, import_path.normalize)(filename),
124
- exposed
125
- ]));
126
- const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
127
- host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
128
- originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
129
- for (const sourceFile of sourceFiles || []) {
130
- let sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
131
- if (sourceEntry === ".") {
132
- sourceEntry = "index";
133
- }
134
- if (sourceEntry) {
135
- const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
136
- const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
137
- const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filepath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
138
- originalWriteFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
139
- export { default } from './${relativePathToOutput}';`, writeOrderByteMark);
118
+ function writeTempTsConfig(tsConfig, context) {
119
+ const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${(0, import_crypto.randomUUID)()}.json`);
120
+ (0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
121
+ (0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
122
+ return tempTsConfigJsonPath;
123
+ }
124
+ __name(writeTempTsConfig, "writeTempTsConfig");
125
+ var removeExt = /* @__PURE__ */ __name((f) => {
126
+ const ext = (0, import_path.extname)(f);
127
+ const regexPattern = new RegExp(`\\${ext}$`);
128
+ return f.replace(regexPattern, "");
129
+ }, "removeExt");
130
+ function getExposeKey(options) {
131
+ const { filePath, rootDir, outDir, mapExposeToEntry } = options;
132
+ const relativeFilePath = removeExt((0, import_path.relative)(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
133
+ return mapExposeToEntry[relativeFilePath];
134
+ }
135
+ __name(getExposeKey, "getExposeKey");
136
+ var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
137
+ const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
138
+ if (!(0, import_fs_extra.existsSync)(filePath)) {
139
+ return;
140
+ }
141
+ const stats = yield (0, import_promises.stat)(filePath);
142
+ if (stats.isDirectory()) {
143
+ const files = yield (0, import_promises.readdir)(filePath);
144
+ yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
145
+ filePath: (0, import_path.join)(filePath, file)
146
+ }))));
147
+ } else if (filePath.endsWith(".d.ts")) {
148
+ const exposeKey = getExposeKey({
149
+ filePath,
150
+ rootDir,
151
+ outDir,
152
+ mapExposeToEntry
153
+ });
154
+ if (exposeKey) {
155
+ const sourceEntry = exposeKey === "." ? "index" : exposeKey;
156
+ const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
157
+ const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
158
+ const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
159
+ (0, import_fs_extra.ensureDirSync)(mfeTypeEntryDirectory);
160
+ yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
161
+ export { default } from './${relativePathToOutput}';`);
162
+ }
163
+ const content = yield (0, import_promises.readFile)(filePath, "utf8");
164
+ cb(content);
165
+ }
166
+ }), "processTypesFile");
167
+ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
168
+ if (!Object.keys(mapComponentsToExpose).length) {
169
+ return;
170
+ }
171
+ const { compilerOptions } = tsConfig;
172
+ const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
173
+ try {
174
+ const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
175
+ const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
176
+ const execPromise = import_util.default.promisify(import_child_process.exec);
177
+ const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
178
+ try {
179
+ yield execPromise(cmd);
180
+ } catch (err) {
181
+ throw new Error(`compile TS failed, the original command is '${cmd}'`);
182
+ }
183
+ const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
184
+ const normalizedFileName = (0, import_path.normalize)(filename);
185
+ let relativeFileName = "";
186
+ if ((0, import_path.isAbsolute)(normalizedFileName)) {
187
+ relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
188
+ } else {
189
+ relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
140
190
  }
191
+ return [
192
+ removeExt(relativeFileName),
193
+ exposed
194
+ ];
195
+ }));
196
+ const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
197
+ yield processTypesFile({
198
+ outDir: compilerOptions.outDir,
199
+ filePath: compilerOptions.outDir,
200
+ rootDir: compilerOptions.rootDir,
201
+ mfTypePath,
202
+ cb,
203
+ mapExposeToEntry
204
+ });
205
+ if (remoteOptions.extractThirdParty) {
206
+ yield thirdPartyExtractor.copyDts();
141
207
  }
142
- cb(text);
143
- };
144
- return host;
145
- }, "createHost");
146
- var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
147
- const vueTypescript = require("vue-tsc");
148
- return vueTypescript.createProgram(programOptions);
149
- }, "createVueTscProgram");
150
- var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
151
- switch (remoteOptions.compilerInstance) {
152
- case "vue-tsc":
153
- return createVueTscProgram(programOptions);
154
- case "tsc":
155
- default:
156
- return import_typescript.default.createProgram(programOptions);
157
- }
158
- }, "createProgram");
159
- var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
160
- const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
161
- const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
162
- const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
163
- const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
164
- const filesToCompile = [
165
- ...Object.values(mapComponentsToExpose),
166
- ...remoteOptions.additionalFilesToCompile
167
- ];
168
- const programOptions = {
169
- rootNames: filesToCompile,
170
- host: tsHost,
171
- options: tsConfig
172
- };
173
- const tsProgram = createProgram(remoteOptions, programOptions);
174
- const { diagnostics = [] } = tsProgram.emit();
175
- diagnostics.forEach(reportCompileDiagnostic);
176
- if (remoteOptions.extractThirdParty) {
177
- thirdPartyExtractor.copyDts();
208
+ yield (0, import_promises.rm)(tempTsConfigJsonPath);
209
+ } catch (err) {
210
+ if (isDebugMode()) {
211
+ console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
212
+ }
213
+ throw err;
178
214
  }
179
- }, "compileTs");
215
+ }), "compileTs");
180
216
 
181
217
  // packages/dts-plugin/src/server/message/Message.ts
182
218
  var _Message = class _Message {
@@ -250,7 +286,7 @@ var FetchTypesAPI = _FetchTypesAPI;
250
286
 
251
287
  // packages/dts-plugin/src/server/utils/index.ts
252
288
  var import_net = __toESM(require("net"));
253
- var import_sdk2 = require("@module-federation/sdk");
289
+ var import_sdk3 = require("@module-federation/sdk");
254
290
 
255
291
  // packages/dts-plugin/src/server/utils/logTransform.ts
256
292
  var import_chalk = __toESM(require("chalk"));
@@ -289,7 +325,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
289
325
  var BrokerExitLog = _BrokerExitLog;
290
326
 
291
327
  // packages/dts-plugin/src/server/utils/log.ts
292
- var import_sdk = require("@module-federation/sdk");
328
+ var import_sdk2 = require("@module-federation/sdk");
293
329
  var log4js = __toESM(require("log4js"));
294
330
  var import_chalk2 = __toESM(require("chalk"));
295
331
 
@@ -374,7 +410,7 @@ var getIPV4 = /* @__PURE__ */ __name(() => {
374
410
  // packages/dts-plugin/src/server/utils/index.ts
375
411
  function getIdentifier(options) {
376
412
  const { ip, name } = options;
377
- return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
413
+ return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
378
414
  }
379
415
  __name(getIdentifier, "getIdentifier");
380
416
  function fib(n) {
@@ -1190,11 +1226,11 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
1190
1226
  var Broker = _Broker;
1191
1227
 
1192
1228
  // packages/dts-plugin/src/server/broker/createBroker.ts
1193
- var import_child_process = require("child_process");
1229
+ var import_child_process2 = require("child_process");
1194
1230
  var import_path2 = __toESM(require("path"));
1195
1231
  function createBroker() {
1196
1232
  const startBrokerPath = import_path2.default.resolve(__dirname, "./start-broker.js");
1197
- const sub = (0, import_child_process.fork)(startBrokerPath, [], {
1233
+ const sub = (0, import_child_process2.fork)(startBrokerPath, [], {
1198
1234
  detached: true,
1199
1235
  stdio: "ignore",
1200
1236
  env: process.env
@@ -1562,7 +1598,7 @@ __name(_ModuleFederationDevServer, "ModuleFederationDevServer");
1562
1598
  var ModuleFederationDevServer = _ModuleFederationDevServer;
1563
1599
 
1564
1600
  // packages/dts-plugin/src/server/createKoaServer.ts
1565
- var import_fs_extra = __toESM(require("fs-extra"));
1601
+ var import_fs_extra2 = __toESM(require("fs-extra"));
1566
1602
  var import_koa = __toESM(require("koa"));
1567
1603
  function createKoaServer(options) {
1568
1604
  return __async(this, null, function* () {
@@ -1572,7 +1608,7 @@ function createKoaServer(options) {
1572
1608
  app.use((ctx, next) => __async(this, null, function* () {
1573
1609
  if (ctx.path === `/${DEFAULT_TAR_NAME}`) {
1574
1610
  ctx.status = 200;
1575
- ctx.body = import_fs_extra.default.createReadStream(typeTarPath);
1611
+ ctx.body = import_fs_extra2.default.createReadStream(typeTarPath);
1576
1612
  ctx.response.type = "application/x-gzip";
1577
1613
  } else {
1578
1614
  yield next();
@@ -1615,7 +1651,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1615
1651
  }).catch(downloadErrorLogger(destinationFolder, url));
1616
1652
  try {
1617
1653
  if (hostOptions.deleteTypesFolder) {
1618
- yield (0, import_promises.rm)(destinationPath, {
1654
+ yield (0, import_promises2.rm)(destinationPath, {
1619
1655
  recursive: true,
1620
1656
  force: true
1621
1657
  });
@@ -1643,7 +1679,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1643
1679
  }, "downloadTypesArchive");
1644
1680
 
1645
1681
  // packages/dts-plugin/src/core/configurations/hostPlugin.ts
1646
- var import_sdk3 = require("@module-federation/sdk");
1682
+ var import_sdk4 = require("@module-federation/sdk");
1647
1683
  var import_managers = require("@module-federation/managers");
1648
1684
  var defaultOptions = {
1649
1685
  typesFolder: "@mf-types",
@@ -1670,10 +1706,10 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
1670
1706
  var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
1671
1707
  const { hostOptions, remoteAlias, remote } = options;
1672
1708
  let decodedRemote = remote;
1673
- if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
1674
- decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
1709
+ if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
1710
+ decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
1675
1711
  }
1676
- const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
1712
+ const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
1677
1713
  const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
1678
1714
  const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
1679
1715
  return {
@@ -1795,12 +1831,12 @@ var DTSManager = (_a = class {
1795
1831
  if (!Object.keys(mapComponentsToExpose).length) {
1796
1832
  return;
1797
1833
  }
1798
- this.extractRemoteTypes({
1834
+ yield this.extractRemoteTypes({
1799
1835
  remoteOptions,
1800
1836
  tsConfig,
1801
1837
  mapComponentsToExpose
1802
1838
  });
1803
- compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
1839
+ yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
1804
1840
  yield createTypesArchive(tsConfig, remoteOptions);
1805
1841
  let apiTypesPath = "";
1806
1842
  if (remoteOptions.generateAPITypes) {
@@ -1810,7 +1846,7 @@ var DTSManager = (_a = class {
1810
1846
  }
1811
1847
  try {
1812
1848
  if (remoteOptions.deleteTypesFolder) {
1813
- yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
1849
+ yield (0, import_promises3.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
1814
1850
  recursive: true,
1815
1851
  force: true
1816
1852
  });
@@ -1820,10 +1856,10 @@ var DTSManager = (_a = class {
1820
1856
  console.error(err);
1821
1857
  }
1822
1858
  }
1823
- console.log(import_ansi_colors2.default.green("Federated types created correctly"));
1859
+ console.log(import_ansi_colors.default.green("Federated types created correctly"));
1824
1860
  } catch (error2) {
1825
1861
  if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
1826
- console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${error2}`));
1862
+ console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
1827
1863
  } else {
1828
1864
  throw error2;
1829
1865
  }
@@ -1833,7 +1869,7 @@ var DTSManager = (_a = class {
1833
1869
  requestRemoteManifest(remoteInfo) {
1834
1870
  return __async(this, null, function* () {
1835
1871
  try {
1836
- if (!remoteInfo.url.includes(import_sdk4.MANIFEST_EXT)) {
1872
+ if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
1837
1873
  return remoteInfo;
1838
1874
  }
1839
1875
  const url = remoteInfo.url;
@@ -1860,7 +1896,7 @@ var DTSManager = (_a = class {
1860
1896
  }
1861
1897
  }
1862
1898
  if (publicPath === "auto") {
1863
- publicPath = (0, import_sdk4.inferAutoPublicPath)(remoteInfo.url);
1899
+ publicPath = (0, import_sdk5.inferAutoPublicPath)(remoteInfo.url);
1864
1900
  }
1865
1901
  remoteInfo.zipUrl = new URL(import_path4.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
1866
1902
  if (!manifestJson.metaData.types.api) {
@@ -1995,7 +2031,7 @@ var DTSManager = (_a = class {
1995
2031
  })));
1996
2032
  this.consumeAPITypes(hostOptions);
1997
2033
  }
1998
- console.log(import_ansi_colors2.default.green("Federated types extraction completed"));
2034
+ console.log(import_ansi_colors.default.green("Federated types extraction completed"));
1999
2035
  } catch (err) {
2000
2036
  if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
2001
2037
  fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
@@ -2016,7 +2052,7 @@ var DTSManager = (_a = class {
2016
2052
  if (!this.options.remote) {
2017
2053
  return;
2018
2054
  }
2019
- this.generateTypes();
2055
+ yield this.generateTypes();
2020
2056
  } else {
2021
2057
  const { remoteAliasMap } = this;
2022
2058
  if (!this.options.host) {
@@ -2120,20 +2156,56 @@ var defaultOptions2 = {
2120
2156
  extractRemoteTypes: false,
2121
2157
  extractThirdParty: false
2122
2158
  };
2123
- var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context }) => {
2159
+ function getEffectiveRootDir(parsedCommandLine) {
2160
+ const compilerOptions = parsedCommandLine.options;
2161
+ if (compilerOptions.rootDir) {
2162
+ return compilerOptions.rootDir;
2163
+ }
2164
+ const files = parsedCommandLine.fileNames;
2165
+ if (files.length > 0) {
2166
+ const commonRoot = files.map((file) => (0, import_path5.dirname)(file)).reduce((commonPath, fileDir) => {
2167
+ while (!fileDir.startsWith(commonPath)) {
2168
+ commonPath = (0, import_path5.dirname)(commonPath);
2169
+ }
2170
+ return commonPath;
2171
+ }, files[0]);
2172
+ return commonRoot;
2173
+ }
2174
+ throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
2175
+ }
2176
+ __name(getEffectiveRootDir, "getEffectiveRootDir");
2177
+ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
2124
2178
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
2125
- const readResult = import_typescript2.default.readConfigFile(resolvedTsConfigPath, import_typescript2.default.sys.readFile);
2179
+ const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
2126
2180
  if (readResult.error) {
2127
2181
  throw new Error(readResult.error.messageText.toString());
2128
2182
  }
2129
- const configContent = import_typescript2.default.parseJsonConfigFileContent(readResult.config, import_typescript2.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
2183
+ const rawTsConfigJson = readResult.config;
2184
+ const configContent = import_typescript.default.parseJsonConfigFileContent(rawTsConfigJson, import_typescript.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
2185
+ const rootDir = getEffectiveRootDir(configContent);
2130
2186
  const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
2131
- return __spreadProps(__spreadValues({}, configContent.options), {
2187
+ const defaultCompilerOptions = {
2188
+ rootDir,
2132
2189
  emitDeclarationOnly: true,
2133
2190
  noEmit: false,
2134
2191
  declaration: true,
2135
2192
  outDir
2136
- });
2193
+ };
2194
+ rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
2195
+ rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
2196
+ const filesToCompile = [
2197
+ ...Object.values(mapComponentsToExpose),
2198
+ ...additionalFilesToCompile
2199
+ ];
2200
+ rawTsConfigJson.include = [];
2201
+ rawTsConfigJson.files = filesToCompile;
2202
+ rawTsConfigJson.exclude = [];
2203
+ "references" in rawTsConfigJson && delete rawTsConfigJson.references;
2204
+ const extendsPath = rawTsConfigJson.extends;
2205
+ if (extendsPath && extendsPath.startsWith(".")) {
2206
+ rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
2207
+ }
2208
+ return rawTsConfigJson;
2137
2209
  }, "readTsConfig");
2138
2210
  var TS_EXTENSIONS = [
2139
2211
  "ts",
@@ -2171,7 +2243,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
2171
2243
  validateOptions(options);
2172
2244
  const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
2173
2245
  const mapComponentsToExpose = resolveExposes(remoteOptions);
2174
- const tsConfig = readTsConfig(remoteOptions);
2246
+ const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
2175
2247
  return {
2176
2248
  tsConfig,
2177
2249
  mapComponentsToExpose,
@@ -2345,7 +2417,7 @@ __name(wrapRpc, "wrapRpc");
2345
2417
  // packages/dts-plugin/src/core/rpc/rpc-worker.ts
2346
2418
  var child_process = __toESM(require("child_process"));
2347
2419
  var process3 = __toESM(require("process"));
2348
- var import_crypto = require("crypto");
2420
+ var import_crypto2 = require("crypto");
2349
2421
  var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
2350
2422
  function createRpcWorker(modulePath, data, memoryLimit, once) {
2351
2423
  const options = {
@@ -2366,7 +2438,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
2366
2438
  ];
2367
2439
  }
2368
2440
  let childProcess, remoteMethod;
2369
- const id = (0, import_crypto.randomUUID)();
2441
+ const id = (0, import_crypto2.randomUUID)();
2370
2442
  const worker = {
2371
2443
  connect(...args) {
2372
2444
  if (childProcess && !childProcess.connected) {
@@ -2417,7 +2489,7 @@ function getRpcWorkerData() {
2417
2489
  __name(getRpcWorkerData, "getRpcWorkerData");
2418
2490
 
2419
2491
  // packages/dts-plugin/src/dev-worker/forkDevWorker.ts
2420
- var import_sdk5 = require("@module-federation/sdk");
2492
+ var import_sdk6 = require("@module-federation/sdk");
2421
2493
 
2422
2494
  // packages/dts-plugin/src/dev-worker/utils.ts
2423
2495
  var DEFAULT_LOCAL_IPS = [
@@ -2448,7 +2520,7 @@ function getLocalRemoteNames(options, encodeNameIdentifier) {
2448
2520
  const { mapRemotesToDownload } = retrieveHostConfig(options);
2449
2521
  return Object.keys(mapRemotesToDownload).reduce((sum, remoteModuleName) => {
2450
2522
  const remoteInfo = mapRemotesToDownload[remoteModuleName];
2451
- const name = encodeNameIdentifier ? (0, import_sdk5.decodeName)(remoteInfo.name, encodeNameIdentifier) : remoteInfo.name;
2523
+ const name = encodeNameIdentifier ? (0, import_sdk6.decodeName)(remoteInfo.name, encodeNameIdentifier) : remoteInfo.name;
2452
2524
  const ip = getIpFromEntry(remoteInfo.url, getIPV4());
2453
2525
  if (!ip) {
2454
2526
  return sum;
@@ -1,4 +1,4 @@
1
- import { m as DtsWorkerOptions } from './DtsWorker-7113d2b0.js';
1
+ import { m as DtsWorkerOptions } from './DtsWorker-90454949.js';
2
2
  import 'child_process';
3
3
  import './DTSManagerOptions-c0728719.js';
4
4
  import '@module-federation/sdk';
@@ -1,4 +1,4 @@
1
- import { m as DtsWorkerOptions } from './DtsWorker-7113d2b0.js';
1
+ import { m as DtsWorkerOptions } from './DtsWorker-90454949.js';
2
2
  import 'child_process';
3
3
  import './DTSManagerOptions-c0728719.js';
4
4
  import '@module-federation/sdk';