@module-federation/dts-plugin 0.2.5 → 0.2.7
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 +19 -0
- package/dist/{DtsWorker-7113d2b0.d.ts → DtsWorker-90454949.d.ts} +11 -3
- package/dist/core.d.mts +5 -5
- package/dist/core.d.ts +5 -5
- package/dist/core.js +167 -99
- package/dist/esm/{chunk-CRKFI32N.js → chunk-ZLQBXHXA.js} +161 -93
- package/dist/esm/core.js +1 -1
- package/dist/esm/fork-dev-worker.js +1 -1
- package/dist/esm/fork-generate-dts.js +1 -1
- package/dist/esm/index.js +5 -6
- package/dist/esm/start-broker.js +1 -1
- package/dist/fork-dev-worker.js +171 -103
- package/dist/fork-generate-dts.d.mts +1 -1
- package/dist/fork-generate-dts.d.ts +1 -1
- package/dist/fork-generate-dts.js +164 -96
- package/dist/index.js +186 -119
- package/dist/package.json +6 -3
- package/dist/start-broker.js +11 -11
- package/package.json +9 -6
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @module-federation/dts-plugin
|
|
2
2
|
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b00ef13: fix(dts-plugin): support compile vue@3 dts
|
|
8
|
+
- Updated dependencies [b00ef13]
|
|
9
|
+
- @module-federation/third-party-dts-extractor@0.2.7
|
|
10
|
+
- @module-federation/sdk@0.2.7
|
|
11
|
+
- @module-federation/managers@0.2.7
|
|
12
|
+
|
|
13
|
+
## 0.2.6
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [91bf689]
|
|
18
|
+
- @module-federation/sdk@0.2.6
|
|
19
|
+
- @module-federation/managers@0.2.6
|
|
20
|
+
- @module-federation/third-party-dts-extractor@0.2.6
|
|
21
|
+
|
|
3
22
|
## 0.2.5
|
|
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
|
|
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:
|
|
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-
|
|
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-
|
|
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:
|
|
24
|
-
declare const retrieveOriginalOutDir: (tsConfig:
|
|
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-
|
|
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-
|
|
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:
|
|
24
|
-
declare const retrieveOriginalOutDir: (tsConfig:
|
|
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
|
|
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,130 @@ 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
|
|
108
|
+
var import_ansi_colors2 = __toESM(require("ansi-colors"));
|
|
109
109
|
|
|
110
110
|
// packages/dts-plugin/src/core/lib/DTSManager.ts
|
|
111
|
-
var
|
|
111
|
+
var import_ansi_colors = __toESM(require("ansi-colors"));
|
|
112
112
|
var import_path3 = __toESM(require("path"));
|
|
113
|
-
var
|
|
113
|
+
var import_promises3 = require("fs/promises");
|
|
114
114
|
var import_fs = __toESM(require("fs"));
|
|
115
|
-
var
|
|
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
|
|
122
|
+
var import_promises2 = require("fs/promises");
|
|
123
123
|
|
|
124
124
|
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
|
|
125
|
-
var
|
|
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
|
|
132
|
-
|
|
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
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
+
yield (0, import_promises.writeFile)(mfeTypeEntry, `export * from './${relativePathToOutput}';
|
|
180
|
+
export { default } from './${relativePathToOutput}';`);
|
|
181
|
+
}
|
|
182
|
+
const content = yield (0, import_promises.readFile)(filePath, "utf8");
|
|
183
|
+
cb(content);
|
|
184
|
+
}
|
|
185
|
+
}), "processTypesFile");
|
|
186
|
+
var compileTs = /* @__PURE__ */ __name((mapComponentsToExpose, tsConfig, remoteOptions) => __async(void 0, null, function* () {
|
|
187
|
+
if (!Object.keys(mapComponentsToExpose).length) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const { compilerOptions } = tsConfig;
|
|
191
|
+
const tempTsConfigJsonPath = writeTempTsConfig(tsConfig, remoteOptions.context);
|
|
192
|
+
try {
|
|
193
|
+
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
|
|
194
|
+
const thirdPartyExtractor = new import_third_party_dts_extractor.ThirdPartyExtractor((0, import_path.resolve)(mfTypePath, "node_modules"), remoteOptions.context);
|
|
195
|
+
const execPromise = import_util.default.promisify(import_child_process.exec);
|
|
196
|
+
const cmd = `npx ${remoteOptions.compilerInstance} --project ${tempTsConfigJsonPath}`;
|
|
197
|
+
try {
|
|
198
|
+
yield execPromise(cmd);
|
|
199
|
+
} catch (err) {
|
|
200
|
+
throw new Error(`compile TS failed, the original command is '${cmd}'`);
|
|
201
|
+
}
|
|
202
|
+
const mapExposeToEntry = Object.fromEntries(Object.entries(mapComponentsToExpose).map(([exposed, filename]) => {
|
|
203
|
+
const normalizedFileName = (0, import_path.normalize)(filename);
|
|
204
|
+
let relativeFileName = "";
|
|
205
|
+
if ((0, import_path.isAbsolute)(normalizedFileName)) {
|
|
206
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, normalizedFileName);
|
|
207
|
+
} else {
|
|
208
|
+
relativeFileName = (0, import_path.relative)(tsConfig.compilerOptions.rootDir, (0, import_path.resolve)(remoteOptions.context, normalizedFileName));
|
|
160
209
|
}
|
|
210
|
+
return [
|
|
211
|
+
removeExt(relativeFileName),
|
|
212
|
+
exposed
|
|
213
|
+
];
|
|
214
|
+
}));
|
|
215
|
+
const cb = remoteOptions.extractThirdParty ? thirdPartyExtractor.collectPkgs.bind(thirdPartyExtractor) : () => void 0;
|
|
216
|
+
yield processTypesFile({
|
|
217
|
+
outDir: compilerOptions.outDir,
|
|
218
|
+
filePath: compilerOptions.outDir,
|
|
219
|
+
rootDir: compilerOptions.rootDir,
|
|
220
|
+
mfTypePath,
|
|
221
|
+
cb,
|
|
222
|
+
mapExposeToEntry
|
|
223
|
+
});
|
|
224
|
+
if (remoteOptions.extractThirdParty) {
|
|
225
|
+
yield thirdPartyExtractor.copyDts();
|
|
161
226
|
}
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
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();
|
|
227
|
+
yield (0, import_promises.rm)(tempTsConfigJsonPath);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
throw err;
|
|
198
230
|
}
|
|
199
|
-
}, "compileTs");
|
|
231
|
+
}), "compileTs");
|
|
200
232
|
|
|
201
233
|
// packages/dts-plugin/src/server/message/Message.ts
|
|
202
234
|
var _Message = class _Message {
|
|
@@ -269,7 +301,7 @@ __name(_FetchTypesAPI, "FetchTypesAPI");
|
|
|
269
301
|
var FetchTypesAPI = _FetchTypesAPI;
|
|
270
302
|
|
|
271
303
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
272
|
-
var
|
|
304
|
+
var import_sdk3 = require("@module-federation/sdk");
|
|
273
305
|
|
|
274
306
|
// packages/dts-plugin/src/server/utils/logTransform.ts
|
|
275
307
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -308,7 +340,7 @@ __name(_BrokerExitLog, "BrokerExitLog");
|
|
|
308
340
|
var BrokerExitLog = _BrokerExitLog;
|
|
309
341
|
|
|
310
342
|
// packages/dts-plugin/src/server/utils/log.ts
|
|
311
|
-
var
|
|
343
|
+
var import_sdk2 = require("@module-federation/sdk");
|
|
312
344
|
var log4js = __toESM(require("log4js"));
|
|
313
345
|
var import_chalk2 = __toESM(require("chalk"));
|
|
314
346
|
|
|
@@ -363,7 +395,7 @@ __name(error, "error");
|
|
|
363
395
|
// packages/dts-plugin/src/server/utils/index.ts
|
|
364
396
|
function getIdentifier(options) {
|
|
365
397
|
const { ip, name } = options;
|
|
366
|
-
return `mf ${
|
|
398
|
+
return `mf ${import_sdk3.SEPARATOR}${name}${ip ? `${import_sdk3.SEPARATOR}${ip}` : ""}`;
|
|
367
399
|
}
|
|
368
400
|
__name(getIdentifier, "getIdentifier");
|
|
369
401
|
|
|
@@ -1075,7 +1107,7 @@ __publicField(_Broker, "DEFAULT_WAITING_TIME", 1.5 * 60 * 60 * 1e3);
|
|
|
1075
1107
|
var Broker = _Broker;
|
|
1076
1108
|
|
|
1077
1109
|
// packages/dts-plugin/src/server/createKoaServer.ts
|
|
1078
|
-
var
|
|
1110
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
1079
1111
|
var import_koa = __toESM(require("koa"));
|
|
1080
1112
|
|
|
1081
1113
|
// packages/dts-plugin/src/core/lib/archiveHandler.ts
|
|
@@ -1106,7 +1138,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1106
1138
|
}).catch(downloadErrorLogger(destinationFolder, url));
|
|
1107
1139
|
try {
|
|
1108
1140
|
if (hostOptions.deleteTypesFolder) {
|
|
1109
|
-
yield (0,
|
|
1141
|
+
yield (0, import_promises2.rm)(destinationPath, {
|
|
1110
1142
|
recursive: true,
|
|
1111
1143
|
force: true
|
|
1112
1144
|
});
|
|
@@ -1134,7 +1166,7 @@ var downloadTypesArchive = /* @__PURE__ */ __name((hostOptions) => {
|
|
|
1134
1166
|
}, "downloadTypesArchive");
|
|
1135
1167
|
|
|
1136
1168
|
// packages/dts-plugin/src/core/configurations/hostPlugin.ts
|
|
1137
|
-
var
|
|
1169
|
+
var import_sdk4 = require("@module-federation/sdk");
|
|
1138
1170
|
var import_managers = require("@module-federation/managers");
|
|
1139
1171
|
var defaultOptions = {
|
|
1140
1172
|
typesFolder: "@mf-types",
|
|
@@ -1161,10 +1193,10 @@ var buildApiTypeUrl = /* @__PURE__ */ __name((zipUrl) => {
|
|
|
1161
1193
|
var retrieveRemoteInfo = /* @__PURE__ */ __name((options) => {
|
|
1162
1194
|
const { hostOptions, remoteAlias, remote } = options;
|
|
1163
1195
|
let decodedRemote = remote;
|
|
1164
|
-
if (decodedRemote.startsWith(
|
|
1165
|
-
decodedRemote = (0,
|
|
1196
|
+
if (decodedRemote.startsWith(import_sdk4.ENCODE_NAME_PREFIX)) {
|
|
1197
|
+
decodedRemote = (0, import_sdk4.decodeName)(decodedRemote, import_sdk4.ENCODE_NAME_PREFIX);
|
|
1166
1198
|
}
|
|
1167
|
-
const parsedInfo = (0,
|
|
1199
|
+
const parsedInfo = (0, import_sdk4.parseEntry)(decodedRemote, void 0, "@");
|
|
1168
1200
|
const url = "entry" in parsedInfo ? parsedInfo.entry : parsedInfo.name === decodedRemote ? decodedRemote : "";
|
|
1169
1201
|
const zipUrl = url ? buildZipUrl(hostOptions, url) : "";
|
|
1170
1202
|
return {
|
|
@@ -1291,7 +1323,7 @@ var DTSManager = (_a = class {
|
|
|
1291
1323
|
tsConfig,
|
|
1292
1324
|
mapComponentsToExpose
|
|
1293
1325
|
});
|
|
1294
|
-
compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1326
|
+
yield compileTs(mapComponentsToExpose, tsConfig, remoteOptions);
|
|
1295
1327
|
yield createTypesArchive(tsConfig, remoteOptions);
|
|
1296
1328
|
let apiTypesPath = "";
|
|
1297
1329
|
if (remoteOptions.generateAPITypes) {
|
|
@@ -1301,7 +1333,7 @@ var DTSManager = (_a = class {
|
|
|
1301
1333
|
}
|
|
1302
1334
|
try {
|
|
1303
1335
|
if (remoteOptions.deleteTypesFolder) {
|
|
1304
|
-
yield (0,
|
|
1336
|
+
yield (0, import_promises3.rm)(retrieveMfTypesPath(tsConfig, remoteOptions), {
|
|
1305
1337
|
recursive: true,
|
|
1306
1338
|
force: true
|
|
1307
1339
|
});
|
|
@@ -1311,10 +1343,10 @@ var DTSManager = (_a = class {
|
|
|
1311
1343
|
console.error(err);
|
|
1312
1344
|
}
|
|
1313
1345
|
}
|
|
1314
|
-
console.log(
|
|
1346
|
+
console.log(import_ansi_colors.default.green("Federated types created correctly"));
|
|
1315
1347
|
} catch (error2) {
|
|
1316
1348
|
if (((_a3 = this.options.remote) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1317
|
-
console.error(
|
|
1349
|
+
console.error(import_ansi_colors.default.red(`Unable to compile federated types, ${error2}`));
|
|
1318
1350
|
} else {
|
|
1319
1351
|
throw error2;
|
|
1320
1352
|
}
|
|
@@ -1324,7 +1356,7 @@ var DTSManager = (_a = class {
|
|
|
1324
1356
|
requestRemoteManifest(remoteInfo) {
|
|
1325
1357
|
return __async(this, null, function* () {
|
|
1326
1358
|
try {
|
|
1327
|
-
if (!remoteInfo.url.includes(
|
|
1359
|
+
if (!remoteInfo.url.includes(import_sdk5.MANIFEST_EXT)) {
|
|
1328
1360
|
return remoteInfo;
|
|
1329
1361
|
}
|
|
1330
1362
|
const url = remoteInfo.url;
|
|
@@ -1351,7 +1383,7 @@ var DTSManager = (_a = class {
|
|
|
1351
1383
|
}
|
|
1352
1384
|
}
|
|
1353
1385
|
if (publicPath === "auto") {
|
|
1354
|
-
publicPath = (0,
|
|
1386
|
+
publicPath = (0, import_sdk5.inferAutoPublicPath)(remoteInfo.url);
|
|
1355
1387
|
}
|
|
1356
1388
|
remoteInfo.zipUrl = new URL(import_path3.default.join(addProtocol(publicPath), manifestJson.metaData.types.zip)).href;
|
|
1357
1389
|
if (!manifestJson.metaData.types.api) {
|
|
@@ -1486,7 +1518,7 @@ var DTSManager = (_a = class {
|
|
|
1486
1518
|
})));
|
|
1487
1519
|
this.consumeAPITypes(hostOptions);
|
|
1488
1520
|
}
|
|
1489
|
-
console.log(
|
|
1521
|
+
console.log(import_ansi_colors.default.green("Federated types extraction completed"));
|
|
1490
1522
|
} catch (err) {
|
|
1491
1523
|
if (((_a3 = this.options.host) == null ? void 0 : _a3.abortOnError) === false) {
|
|
1492
1524
|
fileLog(`Unable to consume federated types, ${err}`, "consumeTypes", "error");
|
|
@@ -1507,7 +1539,7 @@ var DTSManager = (_a = class {
|
|
|
1507
1539
|
if (!this.options.remote) {
|
|
1508
1540
|
return;
|
|
1509
1541
|
}
|
|
1510
|
-
this.generateTypes();
|
|
1542
|
+
yield this.generateTypes();
|
|
1511
1543
|
} else {
|
|
1512
1544
|
const { remoteAliasMap } = this;
|
|
1513
1545
|
if (!this.options.host) {
|
|
@@ -1599,7 +1631,7 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1599
1631
|
apiFileName: import_path4.default.basename(apiTypesPath)
|
|
1600
1632
|
};
|
|
1601
1633
|
} catch (err) {
|
|
1602
|
-
console.error(
|
|
1634
|
+
console.error(import_ansi_colors2.default.red(`Unable to compile federated types, ${err}`));
|
|
1603
1635
|
return {
|
|
1604
1636
|
apiTypesPath: "",
|
|
1605
1637
|
zipTypesPath: "",
|
|
@@ -1665,20 +1697,56 @@ var defaultOptions2 = {
|
|
|
1665
1697
|
extractRemoteTypes: false,
|
|
1666
1698
|
extractThirdParty: false
|
|
1667
1699
|
};
|
|
1668
|
-
|
|
1700
|
+
function getEffectiveRootDir(parsedCommandLine) {
|
|
1701
|
+
const compilerOptions = parsedCommandLine.options;
|
|
1702
|
+
if (compilerOptions.rootDir) {
|
|
1703
|
+
return compilerOptions.rootDir;
|
|
1704
|
+
}
|
|
1705
|
+
const files = parsedCommandLine.fileNames;
|
|
1706
|
+
if (files.length > 0) {
|
|
1707
|
+
const commonRoot = files.map((file) => (0, import_path5.dirname)(file)).reduce((commonPath, fileDir) => {
|
|
1708
|
+
while (!fileDir.startsWith(commonPath)) {
|
|
1709
|
+
commonPath = (0, import_path5.dirname)(commonPath);
|
|
1710
|
+
}
|
|
1711
|
+
return commonPath;
|
|
1712
|
+
}, files[0]);
|
|
1713
|
+
return commonRoot;
|
|
1714
|
+
}
|
|
1715
|
+
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
1716
|
+
}
|
|
1717
|
+
__name(getEffectiveRootDir, "getEffectiveRootDir");
|
|
1718
|
+
var readTsConfig = /* @__PURE__ */ __name(({ tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile }, mapComponentsToExpose) => {
|
|
1669
1719
|
const resolvedTsConfigPath = (0, import_path5.resolve)(context, tsConfigPath);
|
|
1670
|
-
const readResult =
|
|
1720
|
+
const readResult = import_typescript.default.readConfigFile(resolvedTsConfigPath, import_typescript.default.sys.readFile);
|
|
1671
1721
|
if (readResult.error) {
|
|
1672
1722
|
throw new Error(readResult.error.messageText.toString());
|
|
1673
1723
|
}
|
|
1674
|
-
const
|
|
1724
|
+
const rawTsConfigJson = readResult.config;
|
|
1725
|
+
const configContent = import_typescript.default.parseJsonConfigFileContent(rawTsConfigJson, import_typescript.default.sys, (0, import_path5.dirname)(resolvedTsConfigPath));
|
|
1726
|
+
const rootDir = getEffectiveRootDir(configContent);
|
|
1675
1727
|
const outDir = (0, import_path5.resolve)(context, configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1676
|
-
|
|
1728
|
+
const defaultCompilerOptions = {
|
|
1729
|
+
rootDir,
|
|
1677
1730
|
emitDeclarationOnly: true,
|
|
1678
1731
|
noEmit: false,
|
|
1679
1732
|
declaration: true,
|
|
1680
1733
|
outDir
|
|
1681
|
-
}
|
|
1734
|
+
};
|
|
1735
|
+
rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {};
|
|
1736
|
+
rawTsConfigJson.compilerOptions = __spreadValues(__spreadValues({}, rawTsConfigJson.compilerOptions), defaultCompilerOptions);
|
|
1737
|
+
const filesToCompile = [
|
|
1738
|
+
...Object.values(mapComponentsToExpose),
|
|
1739
|
+
...additionalFilesToCompile
|
|
1740
|
+
];
|
|
1741
|
+
rawTsConfigJson.include = [];
|
|
1742
|
+
rawTsConfigJson.files = filesToCompile;
|
|
1743
|
+
rawTsConfigJson.exclude = [];
|
|
1744
|
+
"references" in rawTsConfigJson && delete rawTsConfigJson.references;
|
|
1745
|
+
const extendsPath = rawTsConfigJson.extends;
|
|
1746
|
+
if (extendsPath && extendsPath.startsWith(".")) {
|
|
1747
|
+
rawTsConfigJson.extends = (0, import_path5.resolve)(context, extendsPath);
|
|
1748
|
+
}
|
|
1749
|
+
return rawTsConfigJson;
|
|
1682
1750
|
}, "readTsConfig");
|
|
1683
1751
|
var TS_EXTENSIONS = [
|
|
1684
1752
|
"ts",
|
|
@@ -1716,7 +1784,7 @@ var retrieveRemoteConfig = /* @__PURE__ */ __name((options) => {
|
|
|
1716
1784
|
validateOptions(options);
|
|
1717
1785
|
const remoteOptions = __spreadValues(__spreadValues({}, defaultOptions2), options);
|
|
1718
1786
|
const mapComponentsToExpose = resolveExposes(remoteOptions);
|
|
1719
|
-
const tsConfig = readTsConfig(remoteOptions);
|
|
1787
|
+
const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose);
|
|
1720
1788
|
return {
|
|
1721
1789
|
tsConfig,
|
|
1722
1790
|
mapComponentsToExpose,
|
|
@@ -1902,7 +1970,7 @@ __name(wrapRpc, "wrapRpc");
|
|
|
1902
1970
|
// packages/dts-plugin/src/core/rpc/rpc-worker.ts
|
|
1903
1971
|
var child_process = __toESM(require("child_process"));
|
|
1904
1972
|
var process3 = __toESM(require("process"));
|
|
1905
|
-
var
|
|
1973
|
+
var import_crypto2 = require("crypto");
|
|
1906
1974
|
var FEDERATION_WORKER_DATA_ENV_KEY = "VMOK_WORKER_DATA_ENV";
|
|
1907
1975
|
function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
1908
1976
|
const options = {
|
|
@@ -1923,7 +1991,7 @@ function createRpcWorker(modulePath, data, memoryLimit, once) {
|
|
|
1923
1991
|
];
|
|
1924
1992
|
}
|
|
1925
1993
|
let childProcess, remoteMethod;
|
|
1926
|
-
const id = (0,
|
|
1994
|
+
const id = (0, import_crypto2.randomUUID)();
|
|
1927
1995
|
const worker = {
|
|
1928
1996
|
connect(...args) {
|
|
1929
1997
|
if (childProcess && !childProcess.connected) {
|