@module-federation/dts-plugin 2.6.0 → 2.8.0
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/{Broker-CaenCqdn.js → Broker-C-uWF8l5.js} +42 -23
- package/dist/CHANGELOG.md +31 -0
- package/dist/{DtsWorker-Dtem3-FM.d.ts → DtsWorker-SBLpkK-D.d.ts} +21 -9
- package/dist/{constant-BwEkyidO.d.ts → constant-C0QI9ddQ.d.ts} +1 -1
- package/dist/{consumeTypes-DuDkcp8N.js → consumeTypes-DhrUgkUW.js} +1 -1
- package/dist/core.d.ts +2 -2
- package/dist/core.js +3 -3
- package/dist/dynamic-remote-type-hints-plugin.d.ts +1 -0
- package/dist/esm/{Broker-Cmbh_XVO.mjs → Broker-BfFUcTHm.mjs} +42 -22
- package/dist/esm/{consumeTypes-CUv-A3UY.mjs → consumeTypes-WKYNaS9i.mjs} +1 -1
- package/dist/esm/core.mjs +3 -3
- package/dist/esm/{expose-rpc-BiwGpqZ3.mjs → expose-rpc-B0rqtOKP.mjs} +240 -27
- package/dist/esm/fork-dev-worker.mjs +3 -3
- package/dist/esm/fork-generate-dts.mjs +2 -2
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/start-broker.mjs +1 -1
- package/dist/{expose-rpc-BNzQqY2X.js → expose-rpc-jaGpsAVL.js} +240 -29
- package/dist/fork-dev-worker.d.ts +1 -1
- package/dist/fork-dev-worker.js +3 -3
- package/dist/fork-generate-dts.d.ts +1 -1
- package/dist/fork-generate-dts.js +2 -2
- package/dist/index.d.ts +9 -24
- package/dist/index.js +3 -3
- package/dist/start-broker.js +1 -1
- package/package.json +12 -13
|
@@ -12,8 +12,6 @@ os = require_Action.__toESM(os);
|
|
|
12
12
|
let isomorphic_ws = require("isomorphic-ws");
|
|
13
13
|
isomorphic_ws = require_Action.__toESM(isomorphic_ws);
|
|
14
14
|
let http = require("http");
|
|
15
|
-
let node_schedule = require("node-schedule");
|
|
16
|
-
node_schedule = require_Action.__toESM(node_schedule);
|
|
17
15
|
|
|
18
16
|
//#region src/server/message/API/API.ts
|
|
19
17
|
let APIKind = /* @__PURE__ */ function(APIKind) {
|
|
@@ -256,6 +254,46 @@ let UpdateKind = /* @__PURE__ */ function(UpdateKind) {
|
|
|
256
254
|
|
|
257
255
|
//#endregion
|
|
258
256
|
//#region src/server/broker/Broker.ts
|
|
257
|
+
const CLEANUP_HOURS = [
|
|
258
|
+
0,
|
|
259
|
+
3,
|
|
260
|
+
6,
|
|
261
|
+
9,
|
|
262
|
+
12,
|
|
263
|
+
15,
|
|
264
|
+
18
|
|
265
|
+
];
|
|
266
|
+
function getNextCleanupDelay(now = /* @__PURE__ */ new Date()) {
|
|
267
|
+
for (const hour of CLEANUP_HOURS) {
|
|
268
|
+
const candidate = new Date(now);
|
|
269
|
+
candidate.setHours(hour, 0, 0, 0);
|
|
270
|
+
if (candidate.getTime() > now.getTime()) return candidate.getTime() - now.getTime();
|
|
271
|
+
}
|
|
272
|
+
const nextDay = new Date(now);
|
|
273
|
+
nextDay.setDate(nextDay.getDate() + 1);
|
|
274
|
+
nextDay.setHours(CLEANUP_HOURS[0], 0, 0, 0);
|
|
275
|
+
return nextDay.getTime() - now.getTime();
|
|
276
|
+
}
|
|
277
|
+
function scheduleCleanup(callback, testIntervalMs = 0) {
|
|
278
|
+
let timeout;
|
|
279
|
+
let cancelled = false;
|
|
280
|
+
const scheduleNext = () => {
|
|
281
|
+
const delay = testIntervalMs > 0 ? testIntervalMs : getNextCleanupDelay();
|
|
282
|
+
timeout = setTimeout(() => {
|
|
283
|
+
if (cancelled) return;
|
|
284
|
+
callback();
|
|
285
|
+
scheduleNext();
|
|
286
|
+
}, delay);
|
|
287
|
+
};
|
|
288
|
+
scheduleNext();
|
|
289
|
+
return { cancel() {
|
|
290
|
+
cancelled = true;
|
|
291
|
+
if (timeout) {
|
|
292
|
+
clearTimeout(timeout);
|
|
293
|
+
timeout = void 0;
|
|
294
|
+
}
|
|
295
|
+
} };
|
|
296
|
+
}
|
|
259
297
|
var Broker = class Broker {
|
|
260
298
|
static {
|
|
261
299
|
this.WEB_SOCKET_CONNECT_MAGIC_ID = require_Action.WEB_SOCKET_CONNECT_MAGIC_ID;
|
|
@@ -646,32 +684,13 @@ var Broker = class Broker {
|
|
|
646
684
|
});
|
|
647
685
|
}
|
|
648
686
|
_setSchedule() {
|
|
649
|
-
const rule = new node_schedule.default.RecurrenceRule();
|
|
650
|
-
if (Number(process.env["FEDERATION_SERVER_TEST"])) {
|
|
651
|
-
const interval = Number(process.env["FEDERATION_SERVER_TEST"]) / 1e3;
|
|
652
|
-
const second = [];
|
|
653
|
-
for (let i = 0; i < 60; i = i + interval) second.push(i);
|
|
654
|
-
rule.second = second;
|
|
655
|
-
} else {
|
|
656
|
-
rule.second = 0;
|
|
657
|
-
rule.hour = [
|
|
658
|
-
0,
|
|
659
|
-
3,
|
|
660
|
-
6,
|
|
661
|
-
9,
|
|
662
|
-
12,
|
|
663
|
-
15,
|
|
664
|
-
18
|
|
665
|
-
];
|
|
666
|
-
rule.minute = 0;
|
|
667
|
-
}
|
|
668
687
|
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
669
|
-
this._scheduleJob =
|
|
688
|
+
this._scheduleJob = scheduleCleanup(() => {
|
|
670
689
|
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
671
690
|
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
672
691
|
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : Broker.DEFAULT_WAITING_TIME)) this._clearTmpSubScriberRelation(identifier);
|
|
673
692
|
});
|
|
674
|
-
});
|
|
693
|
+
}, serverTest);
|
|
675
694
|
}
|
|
676
695
|
_clearSchedule() {
|
|
677
696
|
if (!this._scheduleJob) return;
|
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @module-federation/dts-plugin
|
|
2
2
|
|
|
3
|
+
## 2.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 681e5d2: feat(dts-plugin): support ts 7 for federated type generation while keeping existing ts versions supported
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 6ee67dc: Reduce installed and bundled size by replacing general-purpose cache, path, version, package lookup, scheduling, fetch, and error fallback dependencies with focused built-in utilities.
|
|
12
|
+
- Updated dependencies [ea490ae]
|
|
13
|
+
- Updated dependencies [6ee67dc]
|
|
14
|
+
- @module-federation/sdk@2.8.0
|
|
15
|
+
- @module-federation/managers@2.8.0
|
|
16
|
+
- @module-federation/third-party-dts-extractor@2.8.0
|
|
17
|
+
- @module-federation/error-codes@2.8.0
|
|
18
|
+
|
|
19
|
+
## 2.7.0
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- a7351f3: chore(dts-plugin): drop `ansi-colors` dependency in favor of inline ANSI escape for the single red error message.
|
|
24
|
+
- Updated dependencies [dcc640b]
|
|
25
|
+
- Updated dependencies [2add9ef]
|
|
26
|
+
- Updated dependencies [9958086]
|
|
27
|
+
- Updated dependencies [a5f123a]
|
|
28
|
+
- Updated dependencies [8ec950c]
|
|
29
|
+
- @module-federation/sdk@2.7.0
|
|
30
|
+
- @module-federation/third-party-dts-extractor@2.7.0
|
|
31
|
+
- @module-federation/managers@2.7.0
|
|
32
|
+
- @module-federation/error-codes@2.7.0
|
|
33
|
+
|
|
3
34
|
## 2.6.0
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { moduleFederationPlugin } from "@module-federation/sdk";
|
|
2
|
-
import ts from "typescript";
|
|
3
2
|
import { ChildProcess } from "child_process";
|
|
4
3
|
|
|
5
4
|
//#region \0rolldown/runtime.js
|
|
@@ -14,18 +13,31 @@ interface RemoteOptions extends moduleFederationPlugin.DtsRemoteOptions {
|
|
|
14
13
|
}
|
|
15
14
|
//#endregion
|
|
16
15
|
//#region src/core/interfaces/TsConfigJson.d.ts
|
|
16
|
+
type TsConfigCompilerOptions = Record<string, any> & {
|
|
17
|
+
rootDir?: string;
|
|
18
|
+
outDir?: string;
|
|
19
|
+
declarationDir?: string;
|
|
20
|
+
tsBuildInfoFile?: string;
|
|
21
|
+
incremental?: boolean;
|
|
22
|
+
paths?: Record<string, string[]>;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
};
|
|
17
25
|
interface TsConfigJson {
|
|
18
26
|
extends?: string;
|
|
19
|
-
compilerOptions?:
|
|
27
|
+
compilerOptions?: TsConfigCompilerOptions;
|
|
20
28
|
exclude?: string[];
|
|
21
29
|
include?: string[];
|
|
22
30
|
files?: string[];
|
|
31
|
+
references?: Array<{
|
|
32
|
+
path: string;
|
|
33
|
+
}>;
|
|
34
|
+
[key: string]: any;
|
|
23
35
|
}
|
|
24
36
|
//#endregion
|
|
25
37
|
//#region src/core/configurations/remotePlugin.d.ts
|
|
26
38
|
declare const retrieveRemoteConfig: (options: RemoteOptions) => {
|
|
27
39
|
tsConfig: TsConfigJson;
|
|
28
|
-
mapComponentsToExpose:
|
|
40
|
+
mapComponentsToExpose: any;
|
|
29
41
|
remoteOptions: Required<RemoteOptions>;
|
|
30
42
|
};
|
|
31
43
|
//#endregion
|
|
@@ -78,12 +90,12 @@ declare class DTSManager {
|
|
|
78
90
|
extractRemoteTypes(options: ReturnType<typeof retrieveRemoteConfig>): Promise<void>;
|
|
79
91
|
generateTypes(): Promise<void>;
|
|
80
92
|
requestRemoteManifest(remoteInfo: RemoteInfo, hostOptions: Required<HostOptions>): Promise<Required<RemoteInfo>>;
|
|
81
|
-
consumeTargetRemotes(hostOptions: Required<HostOptions>, remoteInfo: Required<RemoteInfo>): Promise<[string, string]>;
|
|
82
|
-
downloadAPITypes(remoteInfo: Required<RemoteInfo>, destinationPath: string, hostOptions: Required<HostOptions>): Promise<boolean>;
|
|
93
|
+
consumeTargetRemotes(hostOptions: Required<HostOptions>, remoteInfo: Required<RemoteInfo>): Promise<[string, string] | undefined>;
|
|
94
|
+
downloadAPITypes(remoteInfo: Required<RemoteInfo>, destinationPath: string, hostOptions: Required<HostOptions>): Promise<boolean | undefined>;
|
|
83
95
|
consumeAPITypes(hostOptions: Required<HostOptions>): void;
|
|
84
96
|
consumeArchiveTypes(options: HostOptions): Promise<{
|
|
85
97
|
hostOptions: Required<HostOptions>;
|
|
86
|
-
downloadPromisesResult: PromiseSettledResult<[string, string]>[];
|
|
98
|
+
downloadPromisesResult: PromiseSettledResult<[string, string] | undefined>[];
|
|
87
99
|
}>;
|
|
88
100
|
consumeTypes(): Promise<void>;
|
|
89
101
|
updateTypes(options: UpdateTypesOptions): Promise<void>;
|
|
@@ -143,9 +155,9 @@ declare function getRpcWorkerData(): unknown;
|
|
|
143
155
|
//#endregion
|
|
144
156
|
//#region src/core/rpc/rpc-error.d.ts
|
|
145
157
|
declare class RpcExitError extends Error {
|
|
146
|
-
readonly code?: string | number | null;
|
|
147
|
-
readonly signal?: string | null;
|
|
148
|
-
constructor(message: string, code?: string | number | null, signal?: string | null);
|
|
158
|
+
readonly code?: string | number | null | undefined;
|
|
159
|
+
readonly signal?: string | null | undefined;
|
|
160
|
+
constructor(message: string, code?: string | number | null | undefined, signal?: string | null | undefined);
|
|
149
161
|
}
|
|
150
162
|
declare namespace index_d_exports {
|
|
151
163
|
export { RpcCallMessage, RpcExitError, RpcGMCallTypes, RpcMessage, RpcMethod, RpcRejectMessage, RpcRemoteMethod, RpcResolveMessage, RpcWorker, createRpcWorker, exposeRpc, getRpcWorkerData, wrapRpc };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as DTSManagerOptions, i as DTSManager, l as TsConfigJson, o as HostOptions, s as RemoteInfo, u as RemoteOptions } from "./DtsWorker-
|
|
1
|
+
import { a as DTSManagerOptions, i as DTSManager, l as TsConfigJson, o as HostOptions, s as RemoteInfo, u as RemoteOptions } from "./DtsWorker-SBLpkK-D.js";
|
|
2
2
|
import { moduleFederationPlugin } from "@module-federation/sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/core/configurations/hostPlugin.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
2
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
2
|
+
const require_expose_rpc = require('./expose-rpc-jaGpsAVL.js');
|
|
3
3
|
let url = require("url");
|
|
4
4
|
let path = require("path");
|
|
5
5
|
path = require_Action.__toESM(path);
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as DTSManagerOptions, c as retrieveRemoteConfig, i as DTSManager, o as HostOptions, r as index_d_exports, t as DtsWorker, u as RemoteOptions } from "./DtsWorker-
|
|
2
|
-
import { a as generateTypesInChildProcess, c as retrieveMfTypesPath, d as isTSProject, f as retrieveTypesAssetsInfo, i as consumeTypes, l as retrieveOriginalOutDir, m as retrieveHostConfig, n as REMOTE_ALIAS_IDENTIFIER, o as generateTypes, p as validateOptions, r as REMOTE_API_TYPES_FILE_NAME, s as retrieveTypesZipPath, t as HOST_API_TYPES_FILE_NAME, u as getDTSManagerConstructor } from "./constant-
|
|
1
|
+
import { a as DTSManagerOptions, c as retrieveRemoteConfig, i as DTSManager, o as HostOptions, r as index_d_exports, t as DtsWorker, u as RemoteOptions } from "./DtsWorker-SBLpkK-D.js";
|
|
2
|
+
import { a as generateTypesInChildProcess, c as retrieveMfTypesPath, d as isTSProject, f as retrieveTypesAssetsInfo, i as consumeTypes, l as retrieveOriginalOutDir, m as retrieveHostConfig, n as REMOTE_ALIAS_IDENTIFIER, o as generateTypes, p as validateOptions, r as REMOTE_API_TYPES_FILE_NAME, s as retrieveTypesZipPath, t as HOST_API_TYPES_FILE_NAME, u as getDTSManagerConstructor } from "./constant-C0QI9ddQ.js";
|
|
3
3
|
export { DTSManager, type DTSManagerOptions, DtsWorker, HOST_API_TYPES_FILE_NAME, type HostOptions, REMOTE_ALIAS_IDENTIFIER, REMOTE_API_TYPES_FILE_NAME, type RemoteOptions, consumeTypes, generateTypes, generateTypesInChildProcess, getDTSManagerConstructor, isTSProject, retrieveHostConfig, retrieveMfTypesPath, retrieveOriginalOutDir, retrieveRemoteConfig, retrieveTypesAssetsInfo, retrieveTypesZipPath, index_d_exports as rpc, validateOptions };
|
package/dist/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('./Broker-
|
|
3
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
4
|
-
const require_consumeTypes = require('./consumeTypes-
|
|
2
|
+
require('./Broker-C-uWF8l5.js');
|
|
3
|
+
const require_expose_rpc = require('./expose-rpc-jaGpsAVL.js');
|
|
4
|
+
const require_consumeTypes = require('./consumeTypes-DhrUgkUW.js');
|
|
5
5
|
|
|
6
6
|
exports.DTSManager = require_expose_rpc.DTSManager;
|
|
7
7
|
exports.DtsWorker = require_consumeTypes.DtsWorker;
|
|
@@ -338,6 +338,7 @@ declare class RemoteHandler {
|
|
|
338
338
|
registerRemotes(remotes: Remote[], options?: {
|
|
339
339
|
force?: boolean;
|
|
340
340
|
}): void;
|
|
341
|
+
initRawContainer(name: string, url: string, container: RemoteEntryExports): Module$1;
|
|
341
342
|
getRemoteModuleAndOptions(options: {
|
|
342
343
|
id: string;
|
|
343
344
|
}): Promise<{
|
|
@@ -7,7 +7,6 @@ import net from "net";
|
|
|
7
7
|
import os from "os";
|
|
8
8
|
import WebSocket from "isomorphic-ws";
|
|
9
9
|
import { createServer } from "http";
|
|
10
|
-
import schedule from "node-schedule";
|
|
11
10
|
|
|
12
11
|
//#region src/server/message/API/API.ts
|
|
13
12
|
let APIKind = /* @__PURE__ */ function(APIKind) {
|
|
@@ -250,6 +249,46 @@ let UpdateKind = /* @__PURE__ */ function(UpdateKind) {
|
|
|
250
249
|
|
|
251
250
|
//#endregion
|
|
252
251
|
//#region src/server/broker/Broker.ts
|
|
252
|
+
const CLEANUP_HOURS = [
|
|
253
|
+
0,
|
|
254
|
+
3,
|
|
255
|
+
6,
|
|
256
|
+
9,
|
|
257
|
+
12,
|
|
258
|
+
15,
|
|
259
|
+
18
|
|
260
|
+
];
|
|
261
|
+
function getNextCleanupDelay(now = /* @__PURE__ */ new Date()) {
|
|
262
|
+
for (const hour of CLEANUP_HOURS) {
|
|
263
|
+
const candidate = new Date(now);
|
|
264
|
+
candidate.setHours(hour, 0, 0, 0);
|
|
265
|
+
if (candidate.getTime() > now.getTime()) return candidate.getTime() - now.getTime();
|
|
266
|
+
}
|
|
267
|
+
const nextDay = new Date(now);
|
|
268
|
+
nextDay.setDate(nextDay.getDate() + 1);
|
|
269
|
+
nextDay.setHours(CLEANUP_HOURS[0], 0, 0, 0);
|
|
270
|
+
return nextDay.getTime() - now.getTime();
|
|
271
|
+
}
|
|
272
|
+
function scheduleCleanup(callback, testIntervalMs = 0) {
|
|
273
|
+
let timeout;
|
|
274
|
+
let cancelled = false;
|
|
275
|
+
const scheduleNext = () => {
|
|
276
|
+
const delay = testIntervalMs > 0 ? testIntervalMs : getNextCleanupDelay();
|
|
277
|
+
timeout = setTimeout(() => {
|
|
278
|
+
if (cancelled) return;
|
|
279
|
+
callback();
|
|
280
|
+
scheduleNext();
|
|
281
|
+
}, delay);
|
|
282
|
+
};
|
|
283
|
+
scheduleNext();
|
|
284
|
+
return { cancel() {
|
|
285
|
+
cancelled = true;
|
|
286
|
+
if (timeout) {
|
|
287
|
+
clearTimeout(timeout);
|
|
288
|
+
timeout = void 0;
|
|
289
|
+
}
|
|
290
|
+
} };
|
|
291
|
+
}
|
|
253
292
|
var Broker = class Broker {
|
|
254
293
|
static {
|
|
255
294
|
this.WEB_SOCKET_CONNECT_MAGIC_ID = WEB_SOCKET_CONNECT_MAGIC_ID;
|
|
@@ -640,32 +679,13 @@ var Broker = class Broker {
|
|
|
640
679
|
});
|
|
641
680
|
}
|
|
642
681
|
_setSchedule() {
|
|
643
|
-
const rule = new schedule.RecurrenceRule();
|
|
644
|
-
if (Number(process.env["FEDERATION_SERVER_TEST"])) {
|
|
645
|
-
const interval = Number(process.env["FEDERATION_SERVER_TEST"]) / 1e3;
|
|
646
|
-
const second = [];
|
|
647
|
-
for (let i = 0; i < 60; i = i + interval) second.push(i);
|
|
648
|
-
rule.second = second;
|
|
649
|
-
} else {
|
|
650
|
-
rule.second = 0;
|
|
651
|
-
rule.hour = [
|
|
652
|
-
0,
|
|
653
|
-
3,
|
|
654
|
-
6,
|
|
655
|
-
9,
|
|
656
|
-
12,
|
|
657
|
-
15,
|
|
658
|
-
18
|
|
659
|
-
];
|
|
660
|
-
rule.minute = 0;
|
|
661
|
-
}
|
|
662
682
|
const serverTest = Number(process.env["FEDERATION_SERVER_TEST"]);
|
|
663
|
-
this._scheduleJob =
|
|
683
|
+
this._scheduleJob = scheduleCleanup(() => {
|
|
664
684
|
this._tmpSubscriberShelter.forEach((tmpSubscriber, identifier) => {
|
|
665
685
|
fileLog(` _clearTmpSubScriberRelation ${identifier}, ${Date.now() - tmpSubscriber.timestamp >= (process.env["GARFISH_MODULE_SERVER_TEST"] ? serverTest : Broker.DEFAULT_WAITING_TIME)}`, "Broker", "info");
|
|
666
686
|
if (Date.now() - tmpSubscriber.timestamp >= (process.env["FEDERATION_SERVER_TEST"] ? serverTest : Broker.DEFAULT_WAITING_TIME)) this._clearTmpSubScriberRelation(identifier);
|
|
667
687
|
});
|
|
668
|
-
});
|
|
688
|
+
}, serverTest);
|
|
669
689
|
}
|
|
670
690
|
_clearSchedule() {
|
|
671
691
|
if (!this._scheduleJob) return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as cloneDeepOptions, n as RpcGMCallTypes, o as getDTSManagerConstructor, s as isDebugMode, t as exposeRpc, x as __exportAll } from "./expose-rpc-
|
|
1
|
+
import { a as cloneDeepOptions, n as RpcGMCallTypes, o as getDTSManagerConstructor, s as isDebugMode, t as exposeRpc, x as __exportAll } from "./expose-rpc-B0rqtOKP.mjs";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { randomUUID } from "crypto";
|
package/dist/esm/core.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as retrieveMfTypesPath, c as isTSProject, d as DTSManager, f as HOST_API_TYPES_FILE_NAME, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, l as retrieveTypesAssetsInfo, m as REMOTE_API_TYPES_FILE_NAME, o as getDTSManagerConstructor, p as REMOTE_ALIAS_IDENTIFIER, r as generateTypes, u as validateOptions, v as retrieveOriginalOutDir } from "./expose-rpc-
|
|
2
|
-
import "./Broker-
|
|
3
|
-
import { i as rpc_exports, n as generateTypesInChildProcess, r as DtsWorker, t as consumeTypes } from "./consumeTypes-
|
|
1
|
+
import { _ as retrieveMfTypesPath, c as isTSProject, d as DTSManager, f as HOST_API_TYPES_FILE_NAME, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, l as retrieveTypesAssetsInfo, m as REMOTE_API_TYPES_FILE_NAME, o as getDTSManagerConstructor, p as REMOTE_ALIAS_IDENTIFIER, r as generateTypes, u as validateOptions, v as retrieveOriginalOutDir } from "./expose-rpc-B0rqtOKP.mjs";
|
|
2
|
+
import "./Broker-BfFUcTHm.mjs";
|
|
3
|
+
import { i as rpc_exports, n as generateTypesInChildProcess, r as DtsWorker, t as consumeTypes } from "./consumeTypes-WKYNaS9i.mjs";
|
|
4
4
|
|
|
5
5
|
export { DTSManager, DtsWorker, HOST_API_TYPES_FILE_NAME, REMOTE_ALIAS_IDENTIFIER, REMOTE_API_TYPES_FILE_NAME, consumeTypes, generateTypes, generateTypesInChildProcess, getDTSManagerConstructor, isTSProject, retrieveHostConfig, retrieveMfTypesPath, retrieveOriginalOutDir, retrieveRemoteConfig, retrieveTypesAssetsInfo, retrieveTypesZipPath, rpc_exports as rpc, validateOptions };
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { a as MF_SERVER_IDENTIFIER, n as ActionKind, o as UpdateMode, r as DEFAULT_TAR_NAME, t as Action } from "./Action-DNNg2YDh.mjs";
|
|
2
|
-
import { a as getIdentifier, c as logger$1, i as getFreePort, l as LogKind, n as UpdateKind, o as getIPV4, r as fib, s as fileLog, t as Broker, u as APIKind } from "./Broker-
|
|
2
|
+
import { a as getIdentifier, c as logger$1, i as getFreePort, l as LogKind, n as UpdateKind, o as getIPV4, r as fib, s as fileLog, t as Broker, u as APIKind } from "./Broker-BfFUcTHm.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import fs, { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
4
|
+
import fs, { existsSync, mkdirSync, realpathSync, rmSync, writeFileSync } from "fs";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import path, { dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
|
|
7
7
|
import { cp, mkdir, readFile, readdir, rm, stat, writeFile } from "fs/promises";
|
|
8
|
+
import crypto from "crypto";
|
|
9
|
+
import { execFile, execFileSync, fork } from "child_process";
|
|
8
10
|
import { utils } from "@module-federation/managers";
|
|
9
|
-
import typescript from "typescript";
|
|
10
11
|
import { ENCODE_NAME_PREFIX, MANIFEST_EXT, TEMP_DIR, decodeName, getProcessEnv, inferAutoPublicPath, parseEntry } from "@module-federation/sdk";
|
|
11
|
-
import
|
|
12
|
+
import { styleText } from "node:util";
|
|
12
13
|
import { Agent } from "undici";
|
|
13
14
|
import { ThirdPartyExtractor } from "@module-federation/third-party-dts-extractor";
|
|
14
15
|
import AdmZip from "adm-zip";
|
|
15
|
-
import crypto from "crypto";
|
|
16
16
|
import { TYPE_001, typeDescMap } from "@module-federation/error-codes";
|
|
17
17
|
import { logAndReport } from "@module-federation/error-codes/node";
|
|
18
|
-
import { execFile, fork } from "child_process";
|
|
19
18
|
import util from "util";
|
|
20
19
|
import WebSocket from "isomorphic-ws";
|
|
21
20
|
import http from "http";
|
|
21
|
+
import { createRequire as createRequire$1 } from "module";
|
|
22
22
|
import process$1 from "process";
|
|
23
23
|
|
|
24
24
|
//#region \0rolldown/runtime.js
|
|
@@ -438,6 +438,49 @@ async function createHttpServer(options) {
|
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/core/lib/typeScriptResolver.ts
|
|
443
|
+
const parseMajorVersion = (version) => {
|
|
444
|
+
const major = Number.parseInt(version.split(".")[0], 10);
|
|
445
|
+
return Number.isNaN(major) ? 0 : major;
|
|
446
|
+
};
|
|
447
|
+
const isMissingTypeScriptPackage = (error) => typeof error === "object" && error !== null && "code" in error && error.code === "MODULE_NOT_FOUND" && "message" in error && typeof error.message === "string" && error.message.includes("typescript/package.json");
|
|
448
|
+
const resolveTypeScriptPackage = (context = process.cwd()) => {
|
|
449
|
+
const candidateContexts = [...new Set([context, process.cwd()])];
|
|
450
|
+
let missingTypeScriptError;
|
|
451
|
+
for (const candidateContext of candidateContexts) {
|
|
452
|
+
const requireFromContext = createRequire$1(resolve(candidateContext, "package.json"));
|
|
453
|
+
try {
|
|
454
|
+
return {
|
|
455
|
+
packageJsonPath: requireFromContext.resolve("typescript/package.json"),
|
|
456
|
+
packageJson: requireFromContext("typescript/package.json"),
|
|
457
|
+
requireFromContext
|
|
458
|
+
};
|
|
459
|
+
} catch (error) {
|
|
460
|
+
if (!isMissingTypeScriptPackage(error)) throw error;
|
|
461
|
+
missingTypeScriptError = error;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
throw missingTypeScriptError;
|
|
465
|
+
};
|
|
466
|
+
const getTypeScriptPackageInfo = (context = process.cwd()) => {
|
|
467
|
+
const { packageJsonPath, packageJson } = resolveTypeScriptPackage(context);
|
|
468
|
+
const version = packageJson.version || "0.0.0";
|
|
469
|
+
const packageRoot = dirname(packageJsonPath);
|
|
470
|
+
const bin = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.["tsc"] ?? "./bin/tsc";
|
|
471
|
+
return {
|
|
472
|
+
packageJsonPath,
|
|
473
|
+
packageRoot,
|
|
474
|
+
version,
|
|
475
|
+
majorVersion: parseMajorVersion(version),
|
|
476
|
+
tscBinPath: resolve(packageRoot, bin)
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
const requireTypeScript = (context = process.cwd()) => {
|
|
480
|
+
const { requireFromContext } = resolveTypeScriptPackage(context);
|
|
481
|
+
return requireFromContext("typescript");
|
|
482
|
+
};
|
|
483
|
+
|
|
441
484
|
//#endregion
|
|
442
485
|
//#region src/core/lib/typeScriptCompiler.ts
|
|
443
486
|
const STARTS_WITH_SLASH = /^\//;
|
|
@@ -546,6 +589,40 @@ const formatCommandForDisplay = (executable, args) => {
|
|
|
546
589
|
};
|
|
547
590
|
return [executable, ...args].map(formatArg).join(" ");
|
|
548
591
|
};
|
|
592
|
+
const getTypeScriptContext$1 = (remoteOptions) => {
|
|
593
|
+
const dtsOptions = remoteOptions.moduleFederationConfig.dts;
|
|
594
|
+
return typeof dtsOptions !== "boolean" && dtsOptions?.cwd ? dtsOptions.cwd : remoteOptions.context;
|
|
595
|
+
};
|
|
596
|
+
const resolveCompilerCommand = (remoteOptions, tempTsConfigJsonPath) => {
|
|
597
|
+
const compilerArgs = splitCommandArgs(remoteOptions.compilerInstance);
|
|
598
|
+
const resolvedCompilerArgs = compilerArgs.length > 0 ? compilerArgs : [remoteOptions.compilerInstance];
|
|
599
|
+
if (resolvedCompilerArgs[0] === "tsc") {
|
|
600
|
+
const args = [
|
|
601
|
+
getTypeScriptPackageInfo(getTypeScriptContext$1(remoteOptions)).tscBinPath,
|
|
602
|
+
...resolvedCompilerArgs.slice(1),
|
|
603
|
+
"--project",
|
|
604
|
+
tempTsConfigJsonPath
|
|
605
|
+
];
|
|
606
|
+
return {
|
|
607
|
+
executable: process.execPath,
|
|
608
|
+
args,
|
|
609
|
+
displayCommand: formatCommandForDisplay(process.execPath, args),
|
|
610
|
+
shell: false
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
const executable = resolvePackageManagerExecutable();
|
|
614
|
+
const args = [
|
|
615
|
+
...resolvedCompilerArgs,
|
|
616
|
+
"--project",
|
|
617
|
+
tempTsConfigJsonPath
|
|
618
|
+
];
|
|
619
|
+
return {
|
|
620
|
+
executable,
|
|
621
|
+
args,
|
|
622
|
+
displayCommand: formatCommandForDisplay(executable, args),
|
|
623
|
+
shell: process.platform === "win32"
|
|
624
|
+
};
|
|
625
|
+
};
|
|
549
626
|
const compileTs = async (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
550
627
|
if (!Object.keys(mapComponentsToExpose).length) return;
|
|
551
628
|
const { compilerOptions } = tsConfig;
|
|
@@ -559,24 +636,17 @@ const compileTs = async (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
|
559
636
|
exclude: typeof remoteOptions.extractThirdParty === "object" ? remoteOptions.extractThirdParty.exclude : void 0
|
|
560
637
|
});
|
|
561
638
|
const execPromise = util.promisify(execFile);
|
|
562
|
-
const
|
|
563
|
-
const compilerArgs = splitCommandArgs(remoteOptions.compilerInstance);
|
|
564
|
-
const cmdArgs = [
|
|
565
|
-
...compilerArgs.length > 0 ? compilerArgs : [remoteOptions.compilerInstance],
|
|
566
|
-
"--project",
|
|
567
|
-
tempTsConfigJsonPath
|
|
568
|
-
];
|
|
569
|
-
const cmd = formatCommandForDisplay(pmExecutable, cmdArgs);
|
|
639
|
+
const compilerCommand = resolveCompilerCommand(remoteOptions, tempTsConfigJsonPath);
|
|
570
640
|
try {
|
|
571
|
-
await execPromise(
|
|
572
|
-
cwd:
|
|
573
|
-
shell:
|
|
641
|
+
await execPromise(compilerCommand.executable, compilerCommand.args, {
|
|
642
|
+
cwd: getTypeScriptContext$1(remoteOptions),
|
|
643
|
+
shell: compilerCommand.shell
|
|
574
644
|
});
|
|
575
645
|
} catch (err) {
|
|
576
646
|
if (compilerOptions.tsBuildInfoFile) try {
|
|
577
647
|
await rm(compilerOptions.tsBuildInfoFile);
|
|
578
648
|
} catch (e) {}
|
|
579
|
-
logAndReport(TYPE_001, typeDescMap, { cmd }, (msg) => {
|
|
649
|
+
logAndReport(TYPE_001, typeDescMap, { cmd: compilerCommand.displayCommand }, (msg) => {
|
|
580
650
|
throw new Error(msg);
|
|
581
651
|
}, void 0);
|
|
582
652
|
}
|
|
@@ -1089,7 +1159,7 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1089
1159
|
apiFileName: path.basename(apiTypesPath)
|
|
1090
1160
|
};
|
|
1091
1161
|
} catch (err) {
|
|
1092
|
-
console.error(
|
|
1162
|
+
console.error(styleText("red", `Unable to compile federated types, ${err}`));
|
|
1093
1163
|
return {
|
|
1094
1164
|
apiTypesPath: "",
|
|
1095
1165
|
zipTypesPath: "",
|
|
@@ -1234,16 +1304,158 @@ function getEffectiveRootDir(parsedCommandLine) {
|
|
|
1234
1304
|
}
|
|
1235
1305
|
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
1236
1306
|
}
|
|
1237
|
-
const getDependentFiles = (rootFiles, configContent, rootDir) => {
|
|
1238
|
-
const dependentFiles = typescript.createProgram(rootFiles, configContent.options).getSourceFiles().map((file) => file.fileName).filter((file) => !file.endsWith(".d.ts") && file.
|
|
1307
|
+
const getDependentFiles = (rootFiles, configContent, rootDir, typescript) => {
|
|
1308
|
+
const dependentFiles = typescript.createProgram(rootFiles, configContent.options).getSourceFiles().map((file) => file.fileName).filter((file) => !file.endsWith(".d.ts") && isFileWithinRootDir(file, rootDir)).map((file) => normalizeFileToRootDir(file, rootDir));
|
|
1239
1309
|
return dependentFiles.length ? dependentFiles : rootFiles;
|
|
1240
1310
|
};
|
|
1241
|
-
const
|
|
1311
|
+
const normalizeForComparison = (value) => {
|
|
1312
|
+
try {
|
|
1313
|
+
return normalize(realpathSync.native(value));
|
|
1314
|
+
} catch {
|
|
1315
|
+
return normalize(value);
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
const isFileWithinRootDir = (file, rootDir) => {
|
|
1319
|
+
const normalizedFile = normalizeForComparison(file);
|
|
1320
|
+
const normalizedRootDir = normalizeForComparison(rootDir);
|
|
1321
|
+
return normalizedFile === normalizedRootDir || normalizedFile.startsWith(normalizedRootDir.endsWith(sep) ? normalizedRootDir : `${normalizedRootDir}${sep}`);
|
|
1322
|
+
};
|
|
1323
|
+
const normalizeFileToRootDir = (file, rootDir) => {
|
|
1324
|
+
const normalizedFile = normalizeForComparison(file);
|
|
1325
|
+
const normalizedRootDir = normalizeForComparison(rootDir);
|
|
1326
|
+
if (normalizedFile === normalizedRootDir || normalizedFile.startsWith(normalizedRootDir.endsWith(sep) ? normalizedRootDir : `${normalizedRootDir}${sep}`)) return normalize(join(rootDir, relative(normalizedRootDir, normalizedFile)));
|
|
1327
|
+
return normalize(file);
|
|
1328
|
+
};
|
|
1329
|
+
const getTypeScriptContext = ({ context, moduleFederationConfig }) => {
|
|
1330
|
+
const dtsOptions = moduleFederationConfig.dts;
|
|
1331
|
+
return typeof dtsOptions !== "boolean" && dtsOptions?.cwd ? dtsOptions.cwd : context;
|
|
1332
|
+
};
|
|
1333
|
+
const resolveFromConfigDir = (value, configDir) => {
|
|
1334
|
+
if (typeof value !== "string") return value;
|
|
1335
|
+
return isAbsolute(value) ? normalize(value) : resolve(configDir, value);
|
|
1336
|
+
};
|
|
1337
|
+
const normalizeCompilerOptions = (compilerOptions = {}, configDir) => {
|
|
1338
|
+
const normalizedOptions = { ...compilerOptions };
|
|
1339
|
+
for (const pathOption of [
|
|
1340
|
+
"rootDir",
|
|
1341
|
+
"outDir",
|
|
1342
|
+
"declarationDir",
|
|
1343
|
+
"tsBuildInfoFile"
|
|
1344
|
+
]) if (typeof normalizedOptions[pathOption] === "string") normalizedOptions[pathOption] = resolveFromConfigDir(normalizedOptions[pathOption], configDir);
|
|
1345
|
+
if (normalizedOptions["moduleResolution"] === "node" || normalizedOptions["moduleResolution"] === "node10") normalizedOptions["moduleResolution"] = "bundler";
|
|
1346
|
+
return normalizedOptions;
|
|
1347
|
+
};
|
|
1348
|
+
const parseShowConfigOutput = (stdout, resolvedTsConfigPath) => {
|
|
1349
|
+
const configDir = dirname(resolvedTsConfigPath);
|
|
1350
|
+
const shownConfig = JSON.parse(stdout);
|
|
1351
|
+
const compilerOptions = normalizeCompilerOptions(shownConfig.compilerOptions, configDir);
|
|
1352
|
+
const fileNames = (shownConfig.files || []).map((file) => resolveFromConfigDir(file, configDir));
|
|
1353
|
+
const projectReferences = (shownConfig.references || []).map((reference) => ({
|
|
1354
|
+
...reference,
|
|
1355
|
+
path: resolveFromConfigDir(reference.path, configDir),
|
|
1356
|
+
originalPath: reference.path
|
|
1357
|
+
}));
|
|
1358
|
+
return {
|
|
1359
|
+
rawTsConfigJson: {
|
|
1360
|
+
...shownConfig,
|
|
1361
|
+
compilerOptions
|
|
1362
|
+
},
|
|
1363
|
+
configContent: {
|
|
1364
|
+
options: compilerOptions,
|
|
1365
|
+
fileNames,
|
|
1366
|
+
projectReferences
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
};
|
|
1370
|
+
const readTsConfigWithTsc = (resolvedTsConfigPath, typeScriptContext) => {
|
|
1371
|
+
const typeScriptPackageInfo = getTypeScriptPackageInfo(typeScriptContext);
|
|
1372
|
+
return parseShowConfigOutput(execFileSync(process.execPath, [
|
|
1373
|
+
typeScriptPackageInfo.tscBinPath,
|
|
1374
|
+
"--showConfig",
|
|
1375
|
+
"--project",
|
|
1376
|
+
resolvedTsConfigPath
|
|
1377
|
+
], {
|
|
1378
|
+
cwd: typeScriptContext,
|
|
1379
|
+
encoding: "utf8",
|
|
1380
|
+
stdio: [
|
|
1381
|
+
"ignore",
|
|
1382
|
+
"pipe",
|
|
1383
|
+
"pipe"
|
|
1384
|
+
]
|
|
1385
|
+
}), resolvedTsConfigPath);
|
|
1386
|
+
};
|
|
1387
|
+
const writeListFilesTsConfig = (rootFiles, resolvedTsConfigPath, context, compilerOptions) => {
|
|
1388
|
+
const tempTsConfigJsonPath = resolve(context, "node_modules", TEMP_DIR, `tsconfig.list-files.${crypto.createHash("md5").update(`${JSON.stringify(rootFiles)}${resolvedTsConfigPath}${Date.now()}`).digest("hex")}.json`);
|
|
1389
|
+
mkdirSync(dirname(tempTsConfigJsonPath), { recursive: true });
|
|
1390
|
+
const listFilesConfig = compilerOptions ? {
|
|
1391
|
+
compilerOptions,
|
|
1392
|
+
files: rootFiles.map((file) => isAbsolute(file) ? file : resolve(context, file))
|
|
1393
|
+
} : {
|
|
1394
|
+
extends: resolvedTsConfigPath,
|
|
1395
|
+
files: rootFiles.map((file) => isAbsolute(file) ? file : resolve(context, file))
|
|
1396
|
+
};
|
|
1397
|
+
writeFileSync(tempTsConfigJsonPath, JSON.stringify(listFilesConfig, null, 2));
|
|
1398
|
+
return tempTsConfigJsonPath;
|
|
1399
|
+
};
|
|
1400
|
+
const formatCompilerError = (error) => {
|
|
1401
|
+
const readOutput = (value) => {
|
|
1402
|
+
if (Buffer.isBuffer(value)) return value.toString("utf8");
|
|
1403
|
+
return typeof value === "string" ? value : "";
|
|
1404
|
+
};
|
|
1405
|
+
if (typeof error === "object" && error !== null) {
|
|
1406
|
+
const processError = error;
|
|
1407
|
+
const stderr = readOutput(processError.stderr).trim();
|
|
1408
|
+
if (stderr) return stderr.split(/\r?\n/)[0];
|
|
1409
|
+
const stdout = readOutput(processError.stdout).trim();
|
|
1410
|
+
if (stdout) return stdout.split(/\r?\n/)[0];
|
|
1411
|
+
if (typeof processError.message === "string") return processError.message;
|
|
1412
|
+
}
|
|
1413
|
+
return String(error);
|
|
1414
|
+
};
|
|
1415
|
+
const getDependentFilesWithTsc = (rootFiles, rootDir, resolvedTsConfigPath, compilerOptions, context, typeScriptContext) => {
|
|
1416
|
+
if (!rootFiles.length) return [];
|
|
1417
|
+
const typeScriptPackageInfo = getTypeScriptPackageInfo(typeScriptContext);
|
|
1418
|
+
const listFilesTsConfigPath = writeListFilesTsConfig(rootFiles, resolvedTsConfigPath, context, compilerOptions);
|
|
1419
|
+
try {
|
|
1420
|
+
const dependentFiles = execFileSync(process.execPath, [
|
|
1421
|
+
typeScriptPackageInfo.tscBinPath,
|
|
1422
|
+
"--listFilesOnly",
|
|
1423
|
+
"--project",
|
|
1424
|
+
listFilesTsConfigPath
|
|
1425
|
+
], {
|
|
1426
|
+
cwd: typeScriptContext,
|
|
1427
|
+
encoding: "utf8",
|
|
1428
|
+
stdio: [
|
|
1429
|
+
"ignore",
|
|
1430
|
+
"pipe",
|
|
1431
|
+
"pipe"
|
|
1432
|
+
]
|
|
1433
|
+
}).split(/\r?\n/).map((file) => file.trim()).filter(Boolean).map((file) => isAbsolute(file) ? file : resolve(context, file)).filter((file) => !file.endsWith(".d.ts") && isFileWithinRootDir(file, rootDir)).map((file) => normalizeFileToRootDir(file, rootDir));
|
|
1434
|
+
return dependentFiles.length ? dependentFiles : rootFiles;
|
|
1435
|
+
} catch (error) {
|
|
1436
|
+
logger$1.warn(`Failed to collect TypeScript dependency files with "tsc --listFilesOnly"; falling back to exposed files only. ${formatCompilerError(error)}`);
|
|
1437
|
+
return rootFiles;
|
|
1438
|
+
} finally {
|
|
1439
|
+
rmSync(listFilesTsConfigPath, { force: true });
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
const readTsConfig = (remoteOptions, mapComponentsToExpose) => {
|
|
1443
|
+
const { tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir } = remoteOptions;
|
|
1242
1444
|
const resolvedTsConfigPath = resolve(context, tsConfigPath);
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1445
|
+
const typeScriptContext = getTypeScriptContext(remoteOptions);
|
|
1446
|
+
const typeScriptPackageInfo = getTypeScriptPackageInfo(typeScriptContext);
|
|
1447
|
+
let rawTsConfigJson;
|
|
1448
|
+
let configContent;
|
|
1449
|
+
let typescript;
|
|
1450
|
+
if (typeScriptPackageInfo.majorVersion === 7) ({rawTsConfigJson, configContent} = readTsConfigWithTsc(resolvedTsConfigPath, typeScriptContext));
|
|
1451
|
+
else {
|
|
1452
|
+
typescript = requireTypeScript(typeScriptContext);
|
|
1453
|
+
const readResult = typescript.readConfigFile(resolvedTsConfigPath, typescript.sys.readFile);
|
|
1454
|
+
if (readResult.error) throw new Error(readResult.error.messageText.toString());
|
|
1455
|
+
rawTsConfigJson = readResult.config || {};
|
|
1456
|
+
configContent = typescript.parseJsonConfigFileContent(rawTsConfigJson, typescript.sys, dirname(resolvedTsConfigPath));
|
|
1457
|
+
configContent.projectReferences = configContent.projectReferences || [];
|
|
1458
|
+
}
|
|
1247
1459
|
const rootDir = getEffectiveRootDir(configContent);
|
|
1248
1460
|
const outDir = resolve(context, outputDir || configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1249
1461
|
const defaultCompilerOptions = {
|
|
@@ -1264,7 +1476,8 @@ const readTsConfig = ({ tsConfigPath, typesFolder, compiledTypesFolder, context,
|
|
|
1264
1476
|
rawTsConfigJson.compilerOptions = restCompilerOptions;
|
|
1265
1477
|
const outDirWithoutTypesFolder = resolve(context, outputDir || configContent.options.outDir || "dist");
|
|
1266
1478
|
const excludeExtensions = [".mdx", ".md"];
|
|
1267
|
-
const
|
|
1479
|
+
const rootFiles = [...Object.values(mapComponentsToExpose), ...additionalFilesToCompile].filter((filename) => !excludeExtensions.some((ext) => filename.endsWith(ext)));
|
|
1480
|
+
const filesToCompile = [...typescript ? getDependentFiles(rootFiles, configContent, rootDir, typescript) : getDependentFilesWithTsc(rootFiles, rootDir, resolvedTsConfigPath, configContent.options, context, typeScriptContext), ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts") && !filename.startsWith(outDirWithoutTypesFolder))];
|
|
1268
1481
|
rawTsConfigJson.include = [];
|
|
1269
1482
|
rawTsConfigJson.files = [...new Set(filesToCompile)];
|
|
1270
1483
|
rawTsConfigJson.exclude = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ as retrieveMfTypesPath, b as ModuleFederationDevServer, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, n as RpcGMCallTypes, o as getDTSManagerConstructor, t as exposeRpc, y as createHttpServer } from "./expose-rpc-
|
|
1
|
+
import { _ as retrieveMfTypesPath, b as ModuleFederationDevServer, g as retrieveTypesZipPath, h as retrieveHostConfig, i as retrieveRemoteConfig, n as RpcGMCallTypes, o as getDTSManagerConstructor, t as exposeRpc, y as createHttpServer } from "./expose-rpc-B0rqtOKP.mjs";
|
|
2
2
|
import { o as UpdateMode, r as DEFAULT_TAR_NAME } from "./Action-DNNg2YDh.mjs";
|
|
3
|
-
import { n as UpdateKind, o as getIPV4, s as fileLog } from "./Broker-
|
|
4
|
-
import "./consumeTypes-
|
|
3
|
+
import { n as UpdateKind, o as getIPV4, s as fileLog } from "./Broker-BfFUcTHm.mjs";
|
|
4
|
+
import "./consumeTypes-WKYNaS9i.mjs";
|
|
5
5
|
import "./core.mjs";
|
|
6
6
|
import { t as getIpFromEntry } from "./utils-CkPvDGOy.mjs";
|
|
7
7
|
import { decodeName } from "@module-federation/sdk";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as RpcGMCallTypes, r as generateTypes, t as exposeRpc } from "./expose-rpc-
|
|
2
|
-
import "./Broker-
|
|
1
|
+
import { n as RpcGMCallTypes, r as generateTypes, t as exposeRpc } from "./expose-rpc-B0rqtOKP.mjs";
|
|
2
|
+
import "./Broker-BfFUcTHm.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/core/lib/forkGenerateDts.ts
|
|
5
5
|
async function forkGenerateDts(options) {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as cloneDeepOptions, c as isTSProject, l as retrieveTypesAssetsInfo, n as RpcGMCallTypes, r as generateTypes, u as validateOptions } from "./expose-rpc-
|
|
1
|
+
import { a as cloneDeepOptions, c as isTSProject, l as retrieveTypesAssetsInfo, n as RpcGMCallTypes, r as generateTypes, u as validateOptions } from "./expose-rpc-B0rqtOKP.mjs";
|
|
2
2
|
import { s as WEB_CLIENT_OPTIONS_IDENTIFIER } from "./Action-DNNg2YDh.mjs";
|
|
3
|
-
import { c as logger$1, o as getIPV4 } from "./Broker-
|
|
4
|
-
import { a as createRpcWorker, n as generateTypesInChildProcess, t as consumeTypes } from "./consumeTypes-
|
|
3
|
+
import { c as logger$1, o as getIPV4 } from "./Broker-BfFUcTHm.mjs";
|
|
4
|
+
import { a as createRpcWorker, n as generateTypesInChildProcess, t as consumeTypes } from "./consumeTypes-WKYNaS9i.mjs";
|
|
5
5
|
import "./core.mjs";
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
2
|
-
const require_Broker = require('./Broker-
|
|
2
|
+
const require_Broker = require('./Broker-C-uWF8l5.js');
|
|
3
3
|
let fs = require("fs");
|
|
4
4
|
fs = require_Action.__toESM(fs);
|
|
5
5
|
let url = require("url");
|
|
6
6
|
let path = require("path");
|
|
7
7
|
path = require_Action.__toESM(path);
|
|
8
8
|
let fs_promises = require("fs/promises");
|
|
9
|
+
let crypto = require("crypto");
|
|
10
|
+
crypto = require_Action.__toESM(crypto);
|
|
11
|
+
let child_process = require("child_process");
|
|
9
12
|
let _module_federation_managers = require("@module-federation/managers");
|
|
10
|
-
let typescript = require("typescript");
|
|
11
|
-
typescript = require_Action.__toESM(typescript);
|
|
12
13
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
13
|
-
let
|
|
14
|
-
ansi_colors = require_Action.__toESM(ansi_colors);
|
|
14
|
+
let node_util = require("node:util");
|
|
15
15
|
let undici = require("undici");
|
|
16
16
|
let _module_federation_third_party_dts_extractor = require("@module-federation/third-party-dts-extractor");
|
|
17
17
|
let adm_zip = require("adm-zip");
|
|
18
18
|
adm_zip = require_Action.__toESM(adm_zip);
|
|
19
|
-
let crypto = require("crypto");
|
|
20
|
-
crypto = require_Action.__toESM(crypto);
|
|
21
19
|
let _module_federation_error_codes = require("@module-federation/error-codes");
|
|
22
20
|
let _module_federation_error_codes_node = require("@module-federation/error-codes/node");
|
|
23
|
-
let child_process = require("child_process");
|
|
24
21
|
let util = require("util");
|
|
25
22
|
util = require_Action.__toESM(util);
|
|
26
23
|
let isomorphic_ws = require("isomorphic-ws");
|
|
27
24
|
isomorphic_ws = require_Action.__toESM(isomorphic_ws);
|
|
28
25
|
let http = require("http");
|
|
29
26
|
http = require_Action.__toESM(http);
|
|
27
|
+
let module$1 = require("module");
|
|
30
28
|
let process$1 = require("process");
|
|
31
29
|
process$1 = require_Action.__toESM(process$1);
|
|
32
30
|
|
|
@@ -429,6 +427,49 @@ async function createHttpServer(options) {
|
|
|
429
427
|
};
|
|
430
428
|
}
|
|
431
429
|
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/core/lib/typeScriptResolver.ts
|
|
432
|
+
const parseMajorVersion = (version) => {
|
|
433
|
+
const major = Number.parseInt(version.split(".")[0], 10);
|
|
434
|
+
return Number.isNaN(major) ? 0 : major;
|
|
435
|
+
};
|
|
436
|
+
const isMissingTypeScriptPackage = (error) => typeof error === "object" && error !== null && "code" in error && error.code === "MODULE_NOT_FOUND" && "message" in error && typeof error.message === "string" && error.message.includes("typescript/package.json");
|
|
437
|
+
const resolveTypeScriptPackage = (context = process.cwd()) => {
|
|
438
|
+
const candidateContexts = [...new Set([context, process.cwd()])];
|
|
439
|
+
let missingTypeScriptError;
|
|
440
|
+
for (const candidateContext of candidateContexts) {
|
|
441
|
+
const requireFromContext = (0, module$1.createRequire)((0, path.resolve)(candidateContext, "package.json"));
|
|
442
|
+
try {
|
|
443
|
+
return {
|
|
444
|
+
packageJsonPath: requireFromContext.resolve("typescript/package.json"),
|
|
445
|
+
packageJson: requireFromContext("typescript/package.json"),
|
|
446
|
+
requireFromContext
|
|
447
|
+
};
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (!isMissingTypeScriptPackage(error)) throw error;
|
|
450
|
+
missingTypeScriptError = error;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
throw missingTypeScriptError;
|
|
454
|
+
};
|
|
455
|
+
const getTypeScriptPackageInfo = (context = process.cwd()) => {
|
|
456
|
+
const { packageJsonPath, packageJson } = resolveTypeScriptPackage(context);
|
|
457
|
+
const version = packageJson.version || "0.0.0";
|
|
458
|
+
const packageRoot = (0, path.dirname)(packageJsonPath);
|
|
459
|
+
const bin = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.["tsc"] ?? "./bin/tsc";
|
|
460
|
+
return {
|
|
461
|
+
packageJsonPath,
|
|
462
|
+
packageRoot,
|
|
463
|
+
version,
|
|
464
|
+
majorVersion: parseMajorVersion(version),
|
|
465
|
+
tscBinPath: (0, path.resolve)(packageRoot, bin)
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
const requireTypeScript = (context = process.cwd()) => {
|
|
469
|
+
const { requireFromContext } = resolveTypeScriptPackage(context);
|
|
470
|
+
return requireFromContext("typescript");
|
|
471
|
+
};
|
|
472
|
+
|
|
432
473
|
//#endregion
|
|
433
474
|
//#region src/core/lib/typeScriptCompiler.ts
|
|
434
475
|
const STARTS_WITH_SLASH = /^\//;
|
|
@@ -537,6 +578,40 @@ const formatCommandForDisplay = (executable, args) => {
|
|
|
537
578
|
};
|
|
538
579
|
return [executable, ...args].map(formatArg).join(" ");
|
|
539
580
|
};
|
|
581
|
+
const getTypeScriptContext$1 = (remoteOptions) => {
|
|
582
|
+
const dtsOptions = remoteOptions.moduleFederationConfig.dts;
|
|
583
|
+
return typeof dtsOptions !== "boolean" && dtsOptions?.cwd ? dtsOptions.cwd : remoteOptions.context;
|
|
584
|
+
};
|
|
585
|
+
const resolveCompilerCommand = (remoteOptions, tempTsConfigJsonPath) => {
|
|
586
|
+
const compilerArgs = splitCommandArgs(remoteOptions.compilerInstance);
|
|
587
|
+
const resolvedCompilerArgs = compilerArgs.length > 0 ? compilerArgs : [remoteOptions.compilerInstance];
|
|
588
|
+
if (resolvedCompilerArgs[0] === "tsc") {
|
|
589
|
+
const args = [
|
|
590
|
+
getTypeScriptPackageInfo(getTypeScriptContext$1(remoteOptions)).tscBinPath,
|
|
591
|
+
...resolvedCompilerArgs.slice(1),
|
|
592
|
+
"--project",
|
|
593
|
+
tempTsConfigJsonPath
|
|
594
|
+
];
|
|
595
|
+
return {
|
|
596
|
+
executable: process.execPath,
|
|
597
|
+
args,
|
|
598
|
+
displayCommand: formatCommandForDisplay(process.execPath, args),
|
|
599
|
+
shell: false
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
const executable = resolvePackageManagerExecutable();
|
|
603
|
+
const args = [
|
|
604
|
+
...resolvedCompilerArgs,
|
|
605
|
+
"--project",
|
|
606
|
+
tempTsConfigJsonPath
|
|
607
|
+
];
|
|
608
|
+
return {
|
|
609
|
+
executable,
|
|
610
|
+
args,
|
|
611
|
+
displayCommand: formatCommandForDisplay(executable, args),
|
|
612
|
+
shell: process.platform === "win32"
|
|
613
|
+
};
|
|
614
|
+
};
|
|
540
615
|
const compileTs = async (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
541
616
|
if (!Object.keys(mapComponentsToExpose).length) return;
|
|
542
617
|
const { compilerOptions } = tsConfig;
|
|
@@ -550,24 +625,17 @@ const compileTs = async (mapComponentsToExpose, tsConfig, remoteOptions) => {
|
|
|
550
625
|
exclude: typeof remoteOptions.extractThirdParty === "object" ? remoteOptions.extractThirdParty.exclude : void 0
|
|
551
626
|
});
|
|
552
627
|
const execPromise = util.default.promisify(child_process.execFile);
|
|
553
|
-
const
|
|
554
|
-
const compilerArgs = splitCommandArgs(remoteOptions.compilerInstance);
|
|
555
|
-
const cmdArgs = [
|
|
556
|
-
...compilerArgs.length > 0 ? compilerArgs : [remoteOptions.compilerInstance],
|
|
557
|
-
"--project",
|
|
558
|
-
tempTsConfigJsonPath
|
|
559
|
-
];
|
|
560
|
-
const cmd = formatCommandForDisplay(pmExecutable, cmdArgs);
|
|
628
|
+
const compilerCommand = resolveCompilerCommand(remoteOptions, tempTsConfigJsonPath);
|
|
561
629
|
try {
|
|
562
|
-
await execPromise(
|
|
563
|
-
cwd:
|
|
564
|
-
shell:
|
|
630
|
+
await execPromise(compilerCommand.executable, compilerCommand.args, {
|
|
631
|
+
cwd: getTypeScriptContext$1(remoteOptions),
|
|
632
|
+
shell: compilerCommand.shell
|
|
565
633
|
});
|
|
566
634
|
} catch (err) {
|
|
567
635
|
if (compilerOptions.tsBuildInfoFile) try {
|
|
568
636
|
await (0, fs_promises.rm)(compilerOptions.tsBuildInfoFile);
|
|
569
637
|
} catch (e) {}
|
|
570
|
-
(0, _module_federation_error_codes_node.logAndReport)(_module_federation_error_codes.TYPE_001, _module_federation_error_codes.typeDescMap, { cmd }, (msg) => {
|
|
638
|
+
(0, _module_federation_error_codes_node.logAndReport)(_module_federation_error_codes.TYPE_001, _module_federation_error_codes.typeDescMap, { cmd: compilerCommand.displayCommand }, (msg) => {
|
|
571
639
|
throw new Error(msg);
|
|
572
640
|
}, void 0);
|
|
573
641
|
}
|
|
@@ -1080,7 +1148,7 @@ function retrieveTypesAssetsInfo(options) {
|
|
|
1080
1148
|
apiFileName: path.default.basename(apiTypesPath)
|
|
1081
1149
|
};
|
|
1082
1150
|
} catch (err) {
|
|
1083
|
-
console.error(
|
|
1151
|
+
console.error((0, node_util.styleText)("red", `Unable to compile federated types, ${err}`));
|
|
1084
1152
|
return {
|
|
1085
1153
|
apiTypesPath: "",
|
|
1086
1154
|
zipTypesPath: "",
|
|
@@ -1225,16 +1293,158 @@ function getEffectiveRootDir(parsedCommandLine) {
|
|
|
1225
1293
|
}
|
|
1226
1294
|
throw new Error("Can not get effective rootDir, please set compilerOptions.rootDir !");
|
|
1227
1295
|
}
|
|
1228
|
-
const getDependentFiles = (rootFiles, configContent, rootDir) => {
|
|
1229
|
-
const dependentFiles = typescript.
|
|
1296
|
+
const getDependentFiles = (rootFiles, configContent, rootDir, typescript) => {
|
|
1297
|
+
const dependentFiles = typescript.createProgram(rootFiles, configContent.options).getSourceFiles().map((file) => file.fileName).filter((file) => !file.endsWith(".d.ts") && isFileWithinRootDir(file, rootDir)).map((file) => normalizeFileToRootDir(file, rootDir));
|
|
1230
1298
|
return dependentFiles.length ? dependentFiles : rootFiles;
|
|
1231
1299
|
};
|
|
1232
|
-
const
|
|
1300
|
+
const normalizeForComparison = (value) => {
|
|
1301
|
+
try {
|
|
1302
|
+
return (0, path.normalize)(fs.realpathSync.native(value));
|
|
1303
|
+
} catch {
|
|
1304
|
+
return (0, path.normalize)(value);
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
const isFileWithinRootDir = (file, rootDir) => {
|
|
1308
|
+
const normalizedFile = normalizeForComparison(file);
|
|
1309
|
+
const normalizedRootDir = normalizeForComparison(rootDir);
|
|
1310
|
+
return normalizedFile === normalizedRootDir || normalizedFile.startsWith(normalizedRootDir.endsWith(path.sep) ? normalizedRootDir : `${normalizedRootDir}${path.sep}`);
|
|
1311
|
+
};
|
|
1312
|
+
const normalizeFileToRootDir = (file, rootDir) => {
|
|
1313
|
+
const normalizedFile = normalizeForComparison(file);
|
|
1314
|
+
const normalizedRootDir = normalizeForComparison(rootDir);
|
|
1315
|
+
if (normalizedFile === normalizedRootDir || normalizedFile.startsWith(normalizedRootDir.endsWith(path.sep) ? normalizedRootDir : `${normalizedRootDir}${path.sep}`)) return (0, path.normalize)((0, path.join)(rootDir, (0, path.relative)(normalizedRootDir, normalizedFile)));
|
|
1316
|
+
return (0, path.normalize)(file);
|
|
1317
|
+
};
|
|
1318
|
+
const getTypeScriptContext = ({ context, moduleFederationConfig }) => {
|
|
1319
|
+
const dtsOptions = moduleFederationConfig.dts;
|
|
1320
|
+
return typeof dtsOptions !== "boolean" && dtsOptions?.cwd ? dtsOptions.cwd : context;
|
|
1321
|
+
};
|
|
1322
|
+
const resolveFromConfigDir = (value, configDir) => {
|
|
1323
|
+
if (typeof value !== "string") return value;
|
|
1324
|
+
return (0, path.isAbsolute)(value) ? (0, path.normalize)(value) : (0, path.resolve)(configDir, value);
|
|
1325
|
+
};
|
|
1326
|
+
const normalizeCompilerOptions = (compilerOptions = {}, configDir) => {
|
|
1327
|
+
const normalizedOptions = { ...compilerOptions };
|
|
1328
|
+
for (const pathOption of [
|
|
1329
|
+
"rootDir",
|
|
1330
|
+
"outDir",
|
|
1331
|
+
"declarationDir",
|
|
1332
|
+
"tsBuildInfoFile"
|
|
1333
|
+
]) if (typeof normalizedOptions[pathOption] === "string") normalizedOptions[pathOption] = resolveFromConfigDir(normalizedOptions[pathOption], configDir);
|
|
1334
|
+
if (normalizedOptions["moduleResolution"] === "node" || normalizedOptions["moduleResolution"] === "node10") normalizedOptions["moduleResolution"] = "bundler";
|
|
1335
|
+
return normalizedOptions;
|
|
1336
|
+
};
|
|
1337
|
+
const parseShowConfigOutput = (stdout, resolvedTsConfigPath) => {
|
|
1338
|
+
const configDir = (0, path.dirname)(resolvedTsConfigPath);
|
|
1339
|
+
const shownConfig = JSON.parse(stdout);
|
|
1340
|
+
const compilerOptions = normalizeCompilerOptions(shownConfig.compilerOptions, configDir);
|
|
1341
|
+
const fileNames = (shownConfig.files || []).map((file) => resolveFromConfigDir(file, configDir));
|
|
1342
|
+
const projectReferences = (shownConfig.references || []).map((reference) => ({
|
|
1343
|
+
...reference,
|
|
1344
|
+
path: resolveFromConfigDir(reference.path, configDir),
|
|
1345
|
+
originalPath: reference.path
|
|
1346
|
+
}));
|
|
1347
|
+
return {
|
|
1348
|
+
rawTsConfigJson: {
|
|
1349
|
+
...shownConfig,
|
|
1350
|
+
compilerOptions
|
|
1351
|
+
},
|
|
1352
|
+
configContent: {
|
|
1353
|
+
options: compilerOptions,
|
|
1354
|
+
fileNames,
|
|
1355
|
+
projectReferences
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
};
|
|
1359
|
+
const readTsConfigWithTsc = (resolvedTsConfigPath, typeScriptContext) => {
|
|
1360
|
+
const typeScriptPackageInfo = getTypeScriptPackageInfo(typeScriptContext);
|
|
1361
|
+
return parseShowConfigOutput((0, child_process.execFileSync)(process.execPath, [
|
|
1362
|
+
typeScriptPackageInfo.tscBinPath,
|
|
1363
|
+
"--showConfig",
|
|
1364
|
+
"--project",
|
|
1365
|
+
resolvedTsConfigPath
|
|
1366
|
+
], {
|
|
1367
|
+
cwd: typeScriptContext,
|
|
1368
|
+
encoding: "utf8",
|
|
1369
|
+
stdio: [
|
|
1370
|
+
"ignore",
|
|
1371
|
+
"pipe",
|
|
1372
|
+
"pipe"
|
|
1373
|
+
]
|
|
1374
|
+
}), resolvedTsConfigPath);
|
|
1375
|
+
};
|
|
1376
|
+
const writeListFilesTsConfig = (rootFiles, resolvedTsConfigPath, context, compilerOptions) => {
|
|
1377
|
+
const tempTsConfigJsonPath = (0, path.resolve)(context, "node_modules", _module_federation_sdk.TEMP_DIR, `tsconfig.list-files.${crypto.default.createHash("md5").update(`${JSON.stringify(rootFiles)}${resolvedTsConfigPath}${Date.now()}`).digest("hex")}.json`);
|
|
1378
|
+
(0, fs.mkdirSync)((0, path.dirname)(tempTsConfigJsonPath), { recursive: true });
|
|
1379
|
+
const listFilesConfig = compilerOptions ? {
|
|
1380
|
+
compilerOptions,
|
|
1381
|
+
files: rootFiles.map((file) => (0, path.isAbsolute)(file) ? file : (0, path.resolve)(context, file))
|
|
1382
|
+
} : {
|
|
1383
|
+
extends: resolvedTsConfigPath,
|
|
1384
|
+
files: rootFiles.map((file) => (0, path.isAbsolute)(file) ? file : (0, path.resolve)(context, file))
|
|
1385
|
+
};
|
|
1386
|
+
(0, fs.writeFileSync)(tempTsConfigJsonPath, JSON.stringify(listFilesConfig, null, 2));
|
|
1387
|
+
return tempTsConfigJsonPath;
|
|
1388
|
+
};
|
|
1389
|
+
const formatCompilerError = (error) => {
|
|
1390
|
+
const readOutput = (value) => {
|
|
1391
|
+
if (Buffer.isBuffer(value)) return value.toString("utf8");
|
|
1392
|
+
return typeof value === "string" ? value : "";
|
|
1393
|
+
};
|
|
1394
|
+
if (typeof error === "object" && error !== null) {
|
|
1395
|
+
const processError = error;
|
|
1396
|
+
const stderr = readOutput(processError.stderr).trim();
|
|
1397
|
+
if (stderr) return stderr.split(/\r?\n/)[0];
|
|
1398
|
+
const stdout = readOutput(processError.stdout).trim();
|
|
1399
|
+
if (stdout) return stdout.split(/\r?\n/)[0];
|
|
1400
|
+
if (typeof processError.message === "string") return processError.message;
|
|
1401
|
+
}
|
|
1402
|
+
return String(error);
|
|
1403
|
+
};
|
|
1404
|
+
const getDependentFilesWithTsc = (rootFiles, rootDir, resolvedTsConfigPath, compilerOptions, context, typeScriptContext) => {
|
|
1405
|
+
if (!rootFiles.length) return [];
|
|
1406
|
+
const typeScriptPackageInfo = getTypeScriptPackageInfo(typeScriptContext);
|
|
1407
|
+
const listFilesTsConfigPath = writeListFilesTsConfig(rootFiles, resolvedTsConfigPath, context, compilerOptions);
|
|
1408
|
+
try {
|
|
1409
|
+
const dependentFiles = (0, child_process.execFileSync)(process.execPath, [
|
|
1410
|
+
typeScriptPackageInfo.tscBinPath,
|
|
1411
|
+
"--listFilesOnly",
|
|
1412
|
+
"--project",
|
|
1413
|
+
listFilesTsConfigPath
|
|
1414
|
+
], {
|
|
1415
|
+
cwd: typeScriptContext,
|
|
1416
|
+
encoding: "utf8",
|
|
1417
|
+
stdio: [
|
|
1418
|
+
"ignore",
|
|
1419
|
+
"pipe",
|
|
1420
|
+
"pipe"
|
|
1421
|
+
]
|
|
1422
|
+
}).split(/\r?\n/).map((file) => file.trim()).filter(Boolean).map((file) => (0, path.isAbsolute)(file) ? file : (0, path.resolve)(context, file)).filter((file) => !file.endsWith(".d.ts") && isFileWithinRootDir(file, rootDir)).map((file) => normalizeFileToRootDir(file, rootDir));
|
|
1423
|
+
return dependentFiles.length ? dependentFiles : rootFiles;
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
require_Broker.logger.warn(`Failed to collect TypeScript dependency files with "tsc --listFilesOnly"; falling back to exposed files only. ${formatCompilerError(error)}`);
|
|
1426
|
+
return rootFiles;
|
|
1427
|
+
} finally {
|
|
1428
|
+
(0, fs.rmSync)(listFilesTsConfigPath, { force: true });
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
const readTsConfig = (remoteOptions, mapComponentsToExpose) => {
|
|
1432
|
+
const { tsConfigPath, typesFolder, compiledTypesFolder, context, additionalFilesToCompile, outputDir } = remoteOptions;
|
|
1233
1433
|
const resolvedTsConfigPath = (0, path.resolve)(context, tsConfigPath);
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1434
|
+
const typeScriptContext = getTypeScriptContext(remoteOptions);
|
|
1435
|
+
const typeScriptPackageInfo = getTypeScriptPackageInfo(typeScriptContext);
|
|
1436
|
+
let rawTsConfigJson;
|
|
1437
|
+
let configContent;
|
|
1438
|
+
let typescript;
|
|
1439
|
+
if (typeScriptPackageInfo.majorVersion === 7) ({rawTsConfigJson, configContent} = readTsConfigWithTsc(resolvedTsConfigPath, typeScriptContext));
|
|
1440
|
+
else {
|
|
1441
|
+
typescript = requireTypeScript(typeScriptContext);
|
|
1442
|
+
const readResult = typescript.readConfigFile(resolvedTsConfigPath, typescript.sys.readFile);
|
|
1443
|
+
if (readResult.error) throw new Error(readResult.error.messageText.toString());
|
|
1444
|
+
rawTsConfigJson = readResult.config || {};
|
|
1445
|
+
configContent = typescript.parseJsonConfigFileContent(rawTsConfigJson, typescript.sys, (0, path.dirname)(resolvedTsConfigPath));
|
|
1446
|
+
configContent.projectReferences = configContent.projectReferences || [];
|
|
1447
|
+
}
|
|
1238
1448
|
const rootDir = getEffectiveRootDir(configContent);
|
|
1239
1449
|
const outDir = (0, path.resolve)(context, outputDir || configContent.options.outDir || "dist", typesFolder, compiledTypesFolder);
|
|
1240
1450
|
const defaultCompilerOptions = {
|
|
@@ -1255,7 +1465,8 @@ const readTsConfig = ({ tsConfigPath, typesFolder, compiledTypesFolder, context,
|
|
|
1255
1465
|
rawTsConfigJson.compilerOptions = restCompilerOptions;
|
|
1256
1466
|
const outDirWithoutTypesFolder = (0, path.resolve)(context, outputDir || configContent.options.outDir || "dist");
|
|
1257
1467
|
const excludeExtensions = [".mdx", ".md"];
|
|
1258
|
-
const
|
|
1468
|
+
const rootFiles = [...Object.values(mapComponentsToExpose), ...additionalFilesToCompile].filter((filename) => !excludeExtensions.some((ext) => filename.endsWith(ext)));
|
|
1469
|
+
const filesToCompile = [...typescript ? getDependentFiles(rootFiles, configContent, rootDir, typescript) : getDependentFilesWithTsc(rootFiles, rootDir, resolvedTsConfigPath, configContent.options, context, typeScriptContext), ...configContent.fileNames.filter((filename) => filename.endsWith(".d.ts") && !filename.startsWith(outDirWithoutTypesFolder))];
|
|
1259
1470
|
rawTsConfigJson.include = [];
|
|
1260
1471
|
rawTsConfigJson.files = [...new Set(filesToCompile)];
|
|
1261
1472
|
rawTsConfigJson.exclude = [];
|
package/dist/fork-dev-worker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
3
|
-
const require_Broker = require('./Broker-
|
|
4
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
5
|
-
require('./consumeTypes-
|
|
3
|
+
const require_Broker = require('./Broker-C-uWF8l5.js');
|
|
4
|
+
const require_expose_rpc = require('./expose-rpc-jaGpsAVL.js');
|
|
5
|
+
require('./consumeTypes-DhrUgkUW.js');
|
|
6
6
|
require('./core.js');
|
|
7
7
|
const require_utils = require('./utils-7KqCZHbb.js');
|
|
8
8
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('./Broker-
|
|
3
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
2
|
+
require('./Broker-C-uWF8l5.js');
|
|
3
|
+
const require_expose_rpc = require('./expose-rpc-jaGpsAVL.js');
|
|
4
4
|
|
|
5
5
|
//#region src/core/lib/forkGenerateDts.ts
|
|
6
6
|
async function forkGenerateDts(options) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { a as DTSManagerOptions } from "./DtsWorker-
|
|
2
|
-
import { d as isTSProject } from "./constant-
|
|
1
|
+
import { a as DTSManagerOptions } from "./DtsWorker-SBLpkK-D.js";
|
|
2
|
+
import { d as isTSProject } from "./constant-C0QI9ddQ.js";
|
|
3
3
|
import { moduleFederationPlugin } from "@module-federation/sdk";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/DtsPlugin.d.ts
|
|
6
6
|
declare const normalizeDtsOptions: (options: moduleFederationPlugin.ModuleFederationPluginOptions, context: string, defaultOptions?: {
|
|
7
7
|
defaultGenerateOptions?: moduleFederationPlugin.DtsRemoteOptions;
|
|
8
8
|
defaultConsumeOptions?: moduleFederationPlugin.DtsHostOptions;
|
|
9
|
-
}) =>
|
|
9
|
+
}) => any;
|
|
10
10
|
declare class DtsPlugin implements WebpackPluginInstance {
|
|
11
11
|
options: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
12
12
|
clonedOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
@@ -25,26 +25,11 @@ declare const normalizeConsumeTypesOptions: ({
|
|
|
25
25
|
dtsOptions: moduleFederationPlugin.PluginDtsOptions;
|
|
26
26
|
pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
27
27
|
}) => {
|
|
28
|
-
host:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
maxRetries?: number;
|
|
34
|
-
consumeAPITypes?: boolean;
|
|
35
|
-
runtimePkgs?: string[];
|
|
36
|
-
remoteTypeUrls?: (() => Promise<moduleFederationPlugin.RemoteTypeUrls>) | moduleFederationPlugin.RemoteTypeUrls;
|
|
37
|
-
timeout?: number;
|
|
38
|
-
family?: 0 | 4 | 6;
|
|
39
|
-
typesOnBuild?: boolean;
|
|
40
|
-
implementation: string;
|
|
41
|
-
context: string;
|
|
42
|
-
moduleFederationConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
43
|
-
};
|
|
44
|
-
extraOptions: Record<string, any>;
|
|
45
|
-
displayErrorInTerminal: boolean;
|
|
46
|
-
};
|
|
47
|
-
declare const consumeTypesAPI: (dtsManagerOptions: DTSManagerOptions, cb?: (options: moduleFederationPlugin.RemoteTypeUrls) => void) => Promise<void>;
|
|
28
|
+
host: any;
|
|
29
|
+
extraOptions: any;
|
|
30
|
+
displayErrorInTerminal: any;
|
|
31
|
+
} | undefined;
|
|
32
|
+
declare const consumeTypesAPI: (dtsManagerOptions: DTSManagerOptions, cb?: (options: moduleFederationPlugin.RemoteTypeUrls) => void) => Promise<any>;
|
|
48
33
|
//#endregion
|
|
49
34
|
//#region src/plugins/GenerateTypesPlugin.d.ts
|
|
50
35
|
declare const normalizeGenerateTypesOptions: ({
|
|
@@ -57,7 +42,7 @@ declare const normalizeGenerateTypesOptions: ({
|
|
|
57
42
|
outputDir?: string;
|
|
58
43
|
dtsOptions: moduleFederationPlugin.PluginDtsOptions;
|
|
59
44
|
pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
60
|
-
}) => DTSManagerOptions;
|
|
45
|
+
}) => DTSManagerOptions | undefined;
|
|
61
46
|
declare const generateTypesAPI: ({
|
|
62
47
|
dtsManagerOptions
|
|
63
48
|
}: {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_Action = require('./Action-CzhPMw2i.js');
|
|
3
|
-
const require_Broker = require('./Broker-
|
|
4
|
-
const require_expose_rpc = require('./expose-rpc-
|
|
5
|
-
const require_consumeTypes = require('./consumeTypes-
|
|
3
|
+
const require_Broker = require('./Broker-C-uWF8l5.js');
|
|
4
|
+
const require_expose_rpc = require('./expose-rpc-jaGpsAVL.js');
|
|
5
|
+
const require_consumeTypes = require('./consumeTypes-DhrUgkUW.js');
|
|
6
6
|
require('./core.js');
|
|
7
7
|
let fs = require("fs");
|
|
8
8
|
fs = require_Action.__toESM(fs);
|
package/dist/start-broker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/dts-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -66,30 +66,29 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"adm-zip": "0.5.10",
|
|
69
|
-
"ansi-colors": "4.1.3",
|
|
70
69
|
"isomorphic-ws": "5.0.0",
|
|
71
70
|
"undici": "7.28.0",
|
|
72
|
-
"node-schedule": "2.1.1",
|
|
73
71
|
"ws": "8.21.0",
|
|
74
|
-
"@module-federation/error-codes": "2.
|
|
75
|
-
"@module-federation/
|
|
76
|
-
"@module-federation/
|
|
77
|
-
"@module-federation/
|
|
72
|
+
"@module-federation/error-codes": "2.8.0",
|
|
73
|
+
"@module-federation/managers": "2.8.0",
|
|
74
|
+
"@module-federation/third-party-dts-extractor": "2.8.0",
|
|
75
|
+
"@module-federation/sdk": "2.8.0"
|
|
78
76
|
},
|
|
79
77
|
"devDependencies": {
|
|
80
|
-
"@
|
|
78
|
+
"@rstest/core": "^0.10.6",
|
|
81
79
|
"@types/ws": "8.5.12",
|
|
82
80
|
"@vue/tsconfig": "^0.7.0",
|
|
81
|
+
"directory-tree": "3.5.2",
|
|
83
82
|
"rimraf": "~6.0.1",
|
|
83
|
+
"typescript": "6.0.3",
|
|
84
|
+
"typescript-7": "npm:typescript@7.0.2",
|
|
84
85
|
"vue": "^3.5.13",
|
|
85
86
|
"vue-tsc": "^2.2.10",
|
|
86
|
-
"directory-tree": "3.5.2",
|
|
87
|
-
"vitest": "1.6.0",
|
|
88
87
|
"webpack": "^5.104.1",
|
|
89
|
-
"@module-federation/runtime": "2.
|
|
88
|
+
"@module-federation/runtime": "2.8.0"
|
|
90
89
|
},
|
|
91
90
|
"peerDependencies": {
|
|
92
|
-
"typescript": "^4.9.0 || ^5.0.0",
|
|
91
|
+
"typescript": "^4.9.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
93
92
|
"vue-tsc": ">=1.0.24"
|
|
94
93
|
},
|
|
95
94
|
"peerDependenciesMeta": {
|
|
@@ -100,7 +99,7 @@
|
|
|
100
99
|
"scripts": {
|
|
101
100
|
"build": "tsdown --config ./tsdown.config.ts && sleep 1 && cp *.md ./dist",
|
|
102
101
|
"test": "node -e \"require('fs').rmSync('dist-test',{recursive:true,force:true,maxRetries:20,retryDelay:50})\" && pnpm run test-impl",
|
|
103
|
-
"test-impl": "pnpm exec
|
|
102
|
+
"test-impl": "pnpm exec rstest --passWithNoTests",
|
|
104
103
|
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
105
104
|
"build-debug": "FEDERATION_DEBUG=true pnpm run build",
|
|
106
105
|
"pre-release": "pnpm run test && pnpm run build"
|