@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.
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @module-federation/dts-plugin
2
2
 
3
+ ## 0.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - f3d13c2: fix(dts-plugin): ensure dts file path if it has deep path
8
+ - @module-federation/sdk@0.2.8
9
+ - @module-federation/managers@0.2.8
10
+ - @module-federation/third-party-dts-extractor@0.2.8
11
+
12
+ ## 0.2.7
13
+
14
+ ### Patch Changes
15
+
16
+ - b00ef13: fix(dts-plugin): support compile vue@3 dts
17
+ - Updated dependencies [b00ef13]
18
+ - @module-federation/third-party-dts-extractor@0.2.7
19
+ - @module-federation/sdk@0.2.7
20
+ - @module-federation/managers@0.2.7
21
+
3
22
  ## 0.2.6
4
23
 
5
24
  ### Patch Changes
@@ -1,9 +1,17 @@
1
1
  import { ChildProcess } from 'child_process';
2
2
  import { a as RemoteOptions, D as DTSManagerOptions, R as RemoteInfo, H as HostOptions } from './DTSManagerOptions-c0728719.js';
3
- import typescript from 'typescript';
3
+ import ts from 'typescript';
4
+
5
+ interface TsConfigJson {
6
+ extends?: string;
7
+ compilerOptions?: ts.CompilerOptions;
8
+ exclude?: string[];
9
+ include?: string[];
10
+ files?: string[];
11
+ }
4
12
 
5
13
  declare const retrieveRemoteConfig: (options: RemoteOptions) => {
6
- tsConfig: typescript.CompilerOptions;
14
+ tsConfig: TsConfigJson;
7
15
  mapComponentsToExpose: Record<string, string>;
8
16
  remoteOptions: Required<RemoteOptions>;
9
17
  };
@@ -97,4 +105,4 @@ declare class DtsWorker {
97
105
  exit(): void;
98
106
  }
99
107
 
100
- export { DTSManager as D, HOST_API_TYPES_FILE_NAME as H, RpcRemoteMethod as R, UpdateMode as U, RpcCallMessage as a, RpcGMCallTypes as b, RpcMessage as c, RpcMethod as d, RpcRejectMessage as e, RpcResolveMessage as f, RpcWorker as g, createRpcWorker as h, getRpcWorkerData as i, DtsWorker as j, REMOTE_ALIAS_IDENTIFIER as k, REMOTE_API_TYPES_FILE_NAME as l, DtsWorkerOptions as m, retrieveRemoteConfig as r };
108
+ export { DTSManager as D, HOST_API_TYPES_FILE_NAME as H, RpcRemoteMethod as R, TsConfigJson as T, UpdateMode as U, RpcCallMessage as a, RpcGMCallTypes as b, RpcMessage as c, RpcMethod as d, RpcRejectMessage as e, RpcResolveMessage as f, RpcWorker as g, createRpcWorker as h, getRpcWorkerData as i, DtsWorker as j, REMOTE_ALIAS_IDENTIFIER as k, REMOTE_API_TYPES_FILE_NAME as l, DtsWorkerOptions as m, retrieveRemoteConfig as r };
package/dist/core.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { D as DTSManager, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-7113d2b0.js';
2
- export { j as DtsWorker, H as HOST_API_TYPES_FILE_NAME, k as REMOTE_ALIAS_IDENTIFIER, l as REMOTE_API_TYPES_FILE_NAME, U as UpdateMode, r as retrieveRemoteConfig } from './DtsWorker-7113d2b0.js';
1
+ import { D as DTSManager, T as TsConfigJson, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-90454949.js';
2
+ export { j as DtsWorker, H as HOST_API_TYPES_FILE_NAME, k as REMOTE_ALIAS_IDENTIFIER, l as REMOTE_API_TYPES_FILE_NAME, U as UpdateMode, r as retrieveRemoteConfig } from './DtsWorker-90454949.js';
3
3
  import { H as HostOptions, R as RemoteInfo, a as RemoteOptions, D as DTSManagerOptions } from './DTSManagerOptions-c0728719.js';
4
4
  import { moduleFederationPlugin } from '@module-federation/sdk';
5
- import typescript from 'typescript';
6
5
  import { ChildProcess } from 'child_process';
6
+ import 'typescript';
7
7
 
8
8
  declare const retrieveHostConfig: (options: HostOptions) => {
9
9
  hostOptions: Required<HostOptions>;
@@ -20,8 +20,8 @@ declare function retrieveTypesAssetsInfo(options: RemoteOptions): {
20
20
  };
21
21
  declare const isTSProject: (dtsOptions: moduleFederationPlugin.ModuleFederationPluginOptions["dts"], context?: string) => boolean;
22
22
 
23
- declare const retrieveMfTypesPath: (tsConfig: typescript.CompilerOptions, remoteOptions: Required<RemoteOptions>) => string;
24
- declare const retrieveOriginalOutDir: (tsConfig: typescript.CompilerOptions, remoteOptions: Required<RemoteOptions>) => string;
23
+ declare const retrieveMfTypesPath: (tsConfig: TsConfigJson, remoteOptions: Required<RemoteOptions>) => string;
24
+ declare const retrieveOriginalOutDir: (tsConfig: TsConfigJson, remoteOptions: Required<RemoteOptions>) => string;
25
25
 
26
26
  declare const retrieveTypesZipPath: (mfTypesPath: string, remoteOptions: Required<RemoteOptions>) => string;
27
27
 
package/dist/core.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { D as DTSManager, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-7113d2b0.js';
2
- export { j as DtsWorker, H as HOST_API_TYPES_FILE_NAME, k as REMOTE_ALIAS_IDENTIFIER, l as REMOTE_API_TYPES_FILE_NAME, U as UpdateMode, r as retrieveRemoteConfig } from './DtsWorker-7113d2b0.js';
1
+ import { D as DTSManager, T as TsConfigJson, R as RpcRemoteMethod, a as RpcCallMessage, b as RpcGMCallTypes, c as RpcMessage, d as RpcMethod, e as RpcRejectMessage, f as RpcResolveMessage, g as RpcWorker, h as createRpcWorker, i as getRpcWorkerData } from './DtsWorker-90454949.js';
2
+ export { j as DtsWorker, H as HOST_API_TYPES_FILE_NAME, k as REMOTE_ALIAS_IDENTIFIER, l as REMOTE_API_TYPES_FILE_NAME, U as UpdateMode, r as retrieveRemoteConfig } from './DtsWorker-90454949.js';
3
3
  import { H as HostOptions, R as RemoteInfo, a as RemoteOptions, D as DTSManagerOptions } from './DTSManagerOptions-c0728719.js';
4
4
  import { moduleFederationPlugin } from '@module-federation/sdk';
5
- import typescript from 'typescript';
6
5
  import { ChildProcess } from 'child_process';
6
+ import 'typescript';
7
7
 
8
8
  declare const retrieveHostConfig: (options: HostOptions) => {
9
9
  hostOptions: Required<HostOptions>;
@@ -20,8 +20,8 @@ declare function retrieveTypesAssetsInfo(options: RemoteOptions): {
20
20
  };
21
21
  declare const isTSProject: (dtsOptions: moduleFederationPlugin.ModuleFederationPluginOptions["dts"], context?: string) => boolean;
22
22
 
23
- declare const retrieveMfTypesPath: (tsConfig: typescript.CompilerOptions, remoteOptions: Required<RemoteOptions>) => string;
24
- declare const retrieveOriginalOutDir: (tsConfig: typescript.CompilerOptions, remoteOptions: Required<RemoteOptions>) => string;
23
+ declare const retrieveMfTypesPath: (tsConfig: TsConfigJson, remoteOptions: Required<RemoteOptions>) => string;
24
+ declare const retrieveOriginalOutDir: (tsConfig: TsConfigJson, remoteOptions: Required<RemoteOptions>) => string;
25
25
 
26
26
  declare const retrieveTypesZipPath: (mfTypesPath: string, remoteOptions: Required<RemoteOptions>) => string;
27
27
 
package/dist/core.js CHANGED
@@ -97,7 +97,7 @@ module.exports = __toCommonJS(core_exports);
97
97
  var import_fs3 = require("fs");
98
98
  var import_path5 = require("path");
99
99
  var import_managers2 = require("@module-federation/managers");
100
- var import_typescript2 = __toESM(require("typescript"));
100
+ var import_typescript = __toESM(require("typescript"));
101
101
 
102
102
  // packages/dts-plugin/src/core/lib/utils.ts
103
103
  var import_fs2 = __toESM(require("fs"));
@@ -105,98 +105,134 @@ var import_path4 = __toESM(require("path"));
105
105
  var import_axios = __toESM(require("axios"));
106
106
  var import_http2 = __toESM(require("http"));
107
107
  var import_https = __toESM(require("https"));
108
- var import_ansi_colors3 = __toESM(require("ansi-colors"));
108
+ var import_ansi_colors2 = __toESM(require("ansi-colors"));
109
109
 
110
110
  // packages/dts-plugin/src/core/lib/DTSManager.ts
111
- var import_ansi_colors2 = __toESM(require("ansi-colors"));
111
+ var import_ansi_colors = __toESM(require("ansi-colors"));
112
112
  var import_path3 = __toESM(require("path"));
113
- var import_promises2 = require("fs/promises");
113
+ var import_promises3 = require("fs/promises");
114
114
  var import_fs = __toESM(require("fs"));
115
- var import_sdk4 = require("@module-federation/sdk");
115
+ var import_sdk5 = require("@module-federation/sdk");
116
116
  var import_lodash = __toESM(require("lodash.clonedeepwith"));
117
117
  var import_third_party_dts_extractor2 = require("@module-federation/third-party-dts-extractor");
118
118
 
119
119
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
120
120
  var import_adm_zip = __toESM(require("adm-zip"));
121
121
  var import_path2 = require("path");
122
- var import_promises = require("fs/promises");
122
+ var import_promises2 = require("fs/promises");
123
123
 
124
124
  // packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
125
- var import_ansi_colors = __toESM(require("ansi-colors"));
125
+ var import_fs_extra = require("fs-extra");
126
+ var import_promises = require("fs/promises");
127
+ var import_crypto = require("crypto");
126
128
  var import_path = require("path");
127
- var import_typescript = __toESM(require("typescript"));
128
129
  var import_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
130
+ var import_child_process = require("child_process");
131
+ var import_util = __toESM(require("util"));
132
+ var import_sdk = require("@module-federation/sdk");
129
133
  var STARTS_WITH_SLASH = /^\//;
130
134
  var DEFINITION_FILE_EXTENSION = ".d.ts";
131
- var reportCompileDiagnostic = /* @__PURE__ */ __name((diagnostic) => {
132
- const { line } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
133
- console.error(import_ansi_colors.default.red(`TS Error ${diagnostic.code}':' ${import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, import_typescript.default.sys.newLine)}`));
134
- console.error(import_ansi_colors.default.red(` at ${diagnostic.file.fileName}:${line + 1} typescript.sys.newLine`));
135
- }, "reportCompileDiagnostic");
136
- var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
137
- var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
135
+ var retrieveMfTypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "")), "retrieveMfTypesPath");
136
+ var retrieveOriginalOutDir = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.normalize)(tsConfig.compilerOptions.outDir.replace(remoteOptions.compiledTypesFolder, "").replace(remoteOptions.typesFolder, "")), "retrieveOriginalOutDir");
138
137
  var retrieveMfAPITypesPath = /* @__PURE__ */ __name((tsConfig, remoteOptions) => (0, import_path.join)(retrieveOriginalOutDir(tsConfig, remoteOptions), `${remoteOptions.typesFolder}.d.ts`), "retrieveMfAPITypesPath");
139
- var createHost = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions, cb) => {
140
- const host = import_typescript.default.createCompilerHost(tsConfig);
141
- const originalWriteFile = host.writeFile;
142
- const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => [
143
- (0, import_path.normalize)(filename),
144
- exposed
145
- ]));
146
- const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
147
- host.writeFile = (filepath, text, writeOrderByteMark, onError, sourceFiles, data) => {
148
- originalWriteFile(filepath, text, writeOrderByteMark, onError, sourceFiles, data);
149
- for (const sourceFile of sourceFiles || []) {
150
- let sourceEntry = mapExposeToEntry[(0, import_path.normalize)(sourceFile.fileName)];
151
- if (sourceEntry === ".") {
152
- sourceEntry = "index";
153
- }
154
- if (sourceEntry) {
155
- const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
156
- const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
157
- const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filepath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
158
- originalWriteFile(mfeTypeEntry, `export * from './${relativePathToOutput}';
159
- export { default } from './${relativePathToOutput}';`, writeOrderByteMark);
138
+ function writeTempTsConfig(tsConfig, context) {
139
+ const tempTsConfigJsonPath = (0, import_path.resolve)(context, "node_modules", import_sdk.TEMP_DIR, `tsconfig.${(0, import_crypto.randomUUID)()}.json`);
140
+ (0, import_fs_extra.ensureDirSync)((0, import_path.dirname)(tempTsConfigJsonPath));
141
+ (0, import_fs_extra.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(tsConfig, null, 2));
142
+ return tempTsConfigJsonPath;
143
+ }
144
+ __name(writeTempTsConfig, "writeTempTsConfig");
145
+ var removeExt = /* @__PURE__ */ __name((f) => {
146
+ const ext = (0, import_path.extname)(f);
147
+ const regexPattern = new RegExp(`\\${ext}$`);
148
+ return f.replace(regexPattern, "");
149
+ }, "removeExt");
150
+ function getExposeKey(options) {
151
+ const { filePath, rootDir, outDir, mapExposeToEntry } = options;
152
+ const relativeFilePath = removeExt((0, import_path.relative)(outDir, filePath.replace(new RegExp(`\\.d.ts$`), "")));
153
+ return mapExposeToEntry[relativeFilePath];
154
+ }
155
+ __name(getExposeKey, "getExposeKey");
156
+ var processTypesFile = /* @__PURE__ */ __name((options) => __async(void 0, null, function* () {
157
+ const { outDir, filePath, rootDir, cb, mapExposeToEntry, mfTypePath } = options;
158
+ if (!(0, import_fs_extra.existsSync)(filePath)) {
159
+ return;
160
+ }
161
+ const stats = yield (0, import_promises.stat)(filePath);
162
+ if (stats.isDirectory()) {
163
+ const files = yield (0, import_promises.readdir)(filePath);
164
+ yield Promise.all(files.map((file) => processTypesFile(__spreadProps(__spreadValues({}, options), {
165
+ filePath: (0, import_path.join)(filePath, file)
166
+ }))));
167
+ } else if (filePath.endsWith(".d.ts")) {
168
+ const exposeKey = getExposeKey({
169
+ filePath,
170
+ rootDir,
171
+ outDir,
172
+ mapExposeToEntry
173
+ });
174
+ if (exposeKey) {
175
+ const sourceEntry = exposeKey === "." ? "index" : exposeKey;
176
+ const mfeTypeEntry = (0, import_path.join)(mfTypePath, `${sourceEntry}${DEFINITION_FILE_EXTENSION}`);
177
+ const mfeTypeEntryDirectory = (0, import_path.dirname)(mfeTypeEntry);
178
+ const relativePathToOutput = (0, import_path.relative)(mfeTypeEntryDirectory, filePath).replace(DEFINITION_FILE_EXTENSION, "").replace(STARTS_WITH_SLASH, "").split(import_path.sep).join("/");
179
+ (0, import_fs_extra.ensureDirSync)(mfeTypeEntryDirectory);
180
+ yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
181
+ export { default } from './${relativePathToOutput}';`);
182
+ }
183
+ const content = yield (0, import_promises.readFile)(filePath, "utf8");
184
+ cb(content);
185
+ }
186
+ }), "processTypesFile");
187
+ var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
188
+ if (!Object.keys(mapComponentsToExpose).length) {
189
+ return;
190
+ }
191
+ const { compilerOptions } = tsConfig;
192
+ const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
193
+ try {
194
+ const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
195
+ const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
196
+ const execPromise = import_util.default.promisify(import_child_process.exec);
197
+ const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
198
+ try {
199
+ yield execPromise(cmd);
200
+ } catch (err) {
201
+ throw new Error(`compile TS failed, the original command is '${cmd}'`);
202
+ }
203
+ const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
204
+ const normalizedFileName = (0, import_path.normalize)(filename);
205
+ let relativeFileName = "";
206
+ if ((0, import_path.isAbsolute)(normalizedFileName)) {
207
+ relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
208
+ } else {
209
+ relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
160
210
  }
211
+ return [
212
+ removeExt(relativeFileName),
213
+ exposed
214
+ ];
215
+ }));
216
+ const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
217
+ yield processTypesFile({
218
+ outDir: compilerOptions.outDir,
219
+ filePath: compilerOptions.outDir,
220
+ rootDir: compilerOptions.rootDir,
221
+ mfTypePath,
222
+ cb,
223
+ mapExposeToEntry
224
+ });
225
+ if (remoteOptions.extractThirdParty) {
226
+ yield thirdPartyExtractor.copyDts();
161
227
  }
162
- cb(text);
163
- };
164
- return host;
165
- }, "createHost");
166
- var createVueTscProgram = /* @__PURE__ */ __name((programOptions) => {
167
- const vueTypescript = require("vue-tsc");
168
- return vueTypescript.createProgram(programOptions);
169
- }, "createVueTscProgram");
170
- var createProgram = /* @__PURE__ */ __name((remoteOptions, programOptions) => {
171
- switch (remoteOptions.compilerInstance) {
172
- case "vue-tsc":
173
- return createVueTscProgram(programOptions);
174
- case "tsc":
175
- default:
176
- return import_typescript.default.createProgram(programOptions);
177
- }
178
- }, "createProgram");
179
- var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => {
180
- const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
181
- const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
182
- const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
183
- const tsHost = createHost(mapComponentsToExpose, tsConfig, remoteOptions, cb);
184
- const filesToCompile = [
185
- ...Object.values(mapComponentsToExpose),
186
- ...remoteOptions.additionalFilesToCompile
187
- ];
188
- const programOptions = {
189
- rootNames: filesToCompile,
190
- host: tsHost,
191
- options: tsConfig
192
- };
193
- const tsProgram = createProgram(remoteOptions, programOptions);
194
- const { diagnostics = [] } = tsProgram.emit();
195
- diagnostics.forEach(reportCompileDiagnostic);
196
- if (remoteOptions.extractThirdParty) {
197
- thirdPartyExtractor.copyDts();
228
+ yield (0, import_promises.rm)(tempTsConfigJsonPath);
229
+ } catch (err) {
230
+ if (isDebugMode()) {
231
+ console.log("tsconfig: ", JSON.stringify(tsConfig, null, 2));
232
+ }
233
+ throw err;
198
234
  }
199
- }, "compileTs");
235
+ }), "compileTs");
200
236
 
201
237
  // packages/dts-plugin/src/server/message/Message.ts
202
238
  var _Message = class _Message {
@@ -269,7 +305,7 @@ __name(_FetchTypesAPI, "FetchTypesAPI");
269
305
  var FetchTypesAPI = _FetchTypesAPI;
270
306
 
271
307
  // packages/dts-plugin/src/server/utils/index.ts
272
- var import_sdk2 = require("@module-federation/sdk");
308
+ var import_sdk3 = require("@module-federation/sdk");
273
309
 
274
310
  // packages/dts-plugin/src/server/utils/logTransform.ts
275
311
  var import_chalk = __toESM(require("chalk"));
@@ -308,7 +344,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
308
344
  var BrokerExitLog = _BrokerExitLog;
309
345
 
310
346
  // packages/dts-plugin/src/server/utils/log.ts
311
- var import_sdk = require("@module-federation/sdk");
347
+ var import_sdk2 = require("@module-federation/sdk");
312
348
  var log4js = __toESM(require("log4js"));
313
349
  var import_chalk2 = __toESM(require("chalk"));
314
350
 
@@ -363,7 +399,7 @@ __name(error, "error");
363
399
  // packages/dts-plugin/src/server/utils/index.ts
364
400
  function getIdentifier(options) {
365
401
  const { ip, name } = options;
366
- return `mf ${import_sdk2.SEPARATOR}${name}${ip ? `${import_sdk2.SEPARATOR}${ip}` : ""}`;
402
+ return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
367
403
  }
368
404
  __name(getIdentifier, "getIdentifier");
369
405
 
@@ -1075,7 +1111,7 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
1075
1111
  var Broker = _Broker;
1076
1112
 
1077
1113
  // packages/dts-plugin/src/server/createKoaServer.ts
1078
- var import_fs_extra = __toESM(require("fs-extra"));
1114
+ var import_fs_extra2 = __toESM(require("fs-extra"));
1079
1115
  var import_koa = __toESM(require("koa"));
1080
1116
 
1081
1117
  // packages/dts-plugin/src/core/lib/archiveHandler.ts
@@ -1106,7 +1142,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1106
1142
  }).catch(downloadErrorLogger(destinationFolder, url));
1107
1143
  try {
1108
1144
  if (hostOptions.deleteTypesFolder) {
1109
- yield (0, import_promises.rm)(destinationPath, {
1145
+ yield (0, import_promises2.rm)(destinationPath, {
1110
1146
  recursive: true,
1111
1147
  force: true
1112
1148
  });
@@ -1134,7 +1170,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
1134
1170
  }, "downloadTypesArchive");
1135
1171
 
1136
1172
  // packages/dts-plugin/src/core/configurations/hostPlugin.ts
1137
- var import_sdk3 = require("@module-federation/sdk");
1173
+ var import_sdk4 = require("@module-federation/sdk");
1138
1174
  var import_managers = require("@module-federation/managers");
1139
1175
  var defaultOptions = {
1140
1176
  typesFolder: "@mf-types",
@@ -1161,10 +1197,10 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
1161
1197
  var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
1162
1198
  const { hostOptions, remoteAlias, remote } = options;
1163
1199
  let decodedRemote = remote;
1164
- if (decodedRemote.startsWith(import_sdk3.ENCODE_NAME_PREFIX)) {
1165
- decodedRemote = (0, import_sdk3.decodeName)(decodedRemote, import_sdk3.ENCODE_NAME_PREFIX);
1200
+ if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
1201
+ decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
1166
1202
  }
1167
- const parsedInfo = (0, import_sdk3.parseEntry)(decodedRemote, void 0, "@");
1203
+ const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
1168
1204
  const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
1169
1205
  const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
1170
1206
  return {
@@ -1286,12 +1322,12 @@ var DTSManager = (_a = class {
1286
1322
  if (!Object.keys(mapComponentsToExpose).length) {
1287
1323
  return;
1288
1324
  }
1289
- this.extractRemoteTypes({
1325
+ yield this.extractRemoteTypes({
1290
1326
  remoteOptions,
1291
1327
  tsConfig,
1292
1328
  mapComponentsToExpose
1293
1329
  });
1294
- compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
1330
+ yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
1295
1331
  yield createTypesArchive(tsConfig, remoteOptions);
1296
1332
  let apiTypesPath = "";
1297
1333
  if (remoteOptions.generateAPITypes) {
@@ -1301,7 +1337,7 @@ var DTSManager = (_a = class {
1301
1337
  }
1302
1338
  try {
1303
1339
  if (remoteOptions.deleteTypesFolder) {
1304
- yield (0, import_promises2.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
1340
+ yield (0, import_promises3.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
1305
1341
  recursive: true,
1306
1342
  force: true
1307
1343
  });
@@ -1311,10 +1347,10 @@ var DTSManager = (_a = class {
1311
1347
  console.error(err);
1312
1348
  }
1313
1349
  }
1314
- console.log(import_ansi_colors2.default.green("Federated types created correctly"));
1350
+ console.log(import_ansi_colors.default.green("Federated types created correctly"));
1315
1351
  } catch (error2) {
1316
1352
  if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
1317
- console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${error2}`));
1353
+ console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
1318
1354
  } else {
1319
1355
  throw error2;
1320
1356
  }
@@ -1324,7 +1360,7 @@ var DTSManager = (_a = class {
1324
1360
  requestRemoteManifest(remoteInfo) {
1325
1361
  return __async(this, null, function* () {
1326
1362
  try {
1327
- if (!remoteInfo.url.includes(import_sdk4.MANIFEST_EXT)) {
1363
+ if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
1328
1364
  return remoteInfo;
1329
1365
  }
1330
1366
  const url = remoteInfo.url;
@@ -1351,7 +1387,7 @@ var DTSManager = (_a = class {
1351
1387
  }
1352
1388
  }
1353
1389
  if (publicPath === "auto") {
1354
- publicPath = (0, import_sdk4.inferAutoPublicPath)(remoteInfo.url);
1390
+ publicPath = (0, import_sdk5.inferAutoPublicPath)(remoteInfo.url);
1355
1391
  }
1356
1392
  remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
1357
1393
  if (!manifestJson.metaData.types.api) {
@@ -1486,7 +1522,7 @@ var DTSManager = (_a = class {
1486
1522
  })));
1487
1523
  this.consumeAPITypes(hostOptions);
1488
1524
  }
1489
- console.log(import_ansi_colors2.default.green("Federated types extraction completed"));
1525
+ console.log(import_ansi_colors.default.green("Federated types extraction completed"));
1490
1526
  } catch (err) {
1491
1527
  if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
1492
1528
  fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
@@ -1507,7 +1543,7 @@ var DTSManager = (_a = class {
1507
1543
  if (!this.options.remote) {
1508
1544
  return;
1509
1545
  }
1510
- this.generateTypes();
1546
+ yield this.generateTypes();
1511
1547
  } else {
1512
1548
  const { remoteAliasMap } = this;
1513
1549
  if (!this.options.host) {
@@ -1599,7 +1635,7 @@ function retrieveTypesAssetsInfo(options) {
1599
1635
  apiFileName: import_path4.default.basename(apiTypesPath)
1600
1636
  };
1601
1637
  } catch (err) {
1602
- console.error(import_ansi_colors3.default.red(`Unable to compile federated types, ${err}`));
1638
+ console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${err}`));
1603
1639
  return {
1604
1640
  apiTypesPath: "",
1605
1641
  zipTypesPath: "",
@@ -1665,20 +1701,56 @@ var defaultOptions2 = {
1665
1701
  extractRemoteTypes: false,
1666
1702
  extractThirdParty: false
1667
1703
  };
1668
- var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context }) => {
1704
+ function getEffectiveRootDir(parsedCommandLine) {
1705
+ const compilerOptions = parsedCommandLine.options;
1706
+ if (compilerOptions.rootDir) {
1707
+ return compilerOptions.rootDir;
1708
+ }
1709
+ const files = parsedCommandLine.fileNames;
1710
+ if (files.length > 0) {
1711
+ const commonRoot = files.map((file) => (0, import_path5.dirname)(file)).reduce((commonPath, fileDir) => {
1712
+ while (!fileDir.startsWith(commonPath)) {
1713
+ commonPath = (0, import_path5.dirname)(commonPath);
1714
+ }
1715
+ return commonPath;
1716
+ }, files[0]);
1717
+ return commonRoot;
1718
+ }
1719
+ throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
1720
+ }
1721
+ __name(getEffectiveRootDir, "getEffectiveRootDir");
1722
+ var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
1669
1723
  const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
1670
- const readResult = import_typescript2.default.readConfigFile(resolvedTsConfigPath, import_typescript2.default.sys.readFile);
1724
+ const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
1671
1725
  if (readResult.error) {
1672
1726
  throw new Error(readResult.error.messageText.toString());
1673
1727
  }
1674
- const configContent = import_typescript2.default.parseJsonConfigFileContent(readResult.config, import_typescript2.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
1728
+ const rawTsConfigJson = readResult.config;
1729
+ const configContent = import_typescript.default.parseJsonConfigFileContent(rawTsConfigJson, import_typescript.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
1730
+ const rootDir = getEffectiveRootDir(configContent);
1675
1731
  const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
1676
- return __spreadProps(__spreadValues({}, configContent.options), {
1732
+ const defaultCompilerOptions = {
1733
+ rootDir,
1677
1734
  emitDeclarationOnly: true,
1678
1735
  noEmit: false,
1679
1736
  declaration: true,
1680
1737
  outDir
1681
- });
1738
+ };
1739
+ rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
1740
+ rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
1741
+ const filesToCompile = [
1742
+ ...Object.values(mapComponentsToExpose),
1743
+ ...additionalFilesToCompile
1744
+ ];
1745
+ rawTsConfigJson.include = [];
1746
+ rawTsConfigJson.files = filesToCompile;
1747
+ rawTsConfigJson.exclude = [];
1748
+ "references" in rawTsConfigJson && delete rawTsConfigJson.references;
1749
+ const extendsPath = rawTsConfigJson.extends;
1750
+ if (extendsPath && extendsPath.startsWith(".")) {
1751
+ rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
1752
+ }
1753
+ return rawTsConfigJson;
1682
1754
  }, "readTsConfig");
1683
1755
  var TS_EXTENSIONS = [
1684
1756
  "ts",
@@ -1716,7 +1788,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
1716
1788
  validateOptions(options);
1717
1789
  const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
1718
1790
  const mapComponentsToExpose = resolveExposes(remoteOptions);
1719
- const tsConfig = readTsConfig(remoteOptions);
1791
+ const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
1720
1792
  return {
1721
1793
  tsConfig,
1722
1794
  mapComponentsToExpose,
@@ -1902,7 +1974,7 @@ __name(wrapRpc, "wrapRpc");
1902
1974
  // packages/dts-plugin/src/core/rpc/rpc-worker.ts
1903
1975
  var child_process = __toESM(require("child_process"));
1904
1976
  var process3 = __toESM(require("process"));
1905
- var import_crypto = require("crypto");
1977
+ var import_crypto2 = require("crypto");
1906
1978
  var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
1907
1979
  function createRpcWorker(modulePath, data, memoryLimit, once) {
1908
1980
  const options = {
@@ -1923,7 +1995,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
1923
1995
  ];
1924
1996
  }
1925
1997
  let childProcess, remoteMethod;
1926
- const id = (0, import_crypto.randomUUID)();
1998
+ const id = (0, import_crypto2.randomUUID)();
1927
1999
  const worker = {
1928
2000
  connect(...args) {
1929
2001
  if (childProcess && !childProcess.connected) {