Skip to content

Commit 1485fcf

Browse files
ksv902heal1
andauthored
feat(dts-plugin): added flag to fetch types (#3840)
Co-authored-by: Hanric <hanric.zhang@gmail.com>
1 parent 1fd6f65 commit 1485fcf

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

.changeset/large-actors-fly.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/dts-plugin': minor
3+
'@module-federation/sdk': minor
4+
---
5+
6+
added flag to fetch types from remote when building in production.

packages/dts-plugin/src/core/configurations/hostPlugin.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('hostPlugin', () => {
4343
runtimePkgs: [],
4444
remoteTypeUrls: {},
4545
timeout: 60000,
46+
typesOnBuild: false,
4647
});
4748

4849
expect(mapRemotesToDownload).toStrictEqual({
@@ -70,6 +71,7 @@ describe('hostPlugin', () => {
7071
runtimePkgs: [],
7172
remoteTypeUrls: {},
7273
timeout: 60000,
74+
typesOnBuild: false,
7375
};
7476

7577
const { hostOptions, mapRemotesToDownload } =

packages/dts-plugin/src/core/configurations/hostPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const defaultOptions = {
1919
runtimePkgs: [],
2020
remoteTypeUrls: {},
2121
timeout: 60000,
22+
typesOnBuild: false,
2223
} satisfies Partial<HostOptions>;
2324

2425
const buildZipUrl = (hostOptions: Required<HostOptions>, url: string) => {

packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { Compiler, WebpackPluginInstance } from 'webpack';
1515
export const DEFAULT_CONSUME_TYPES = {
1616
abortOnError: false,
1717
consumeAPITypes: true,
18+
typesOnBuild: false,
1819
};
1920

2021
export const normalizeConsumeTypesOptions = ({
@@ -99,11 +100,6 @@ export class ConsumeTypesPlugin implements WebpackPluginInstance {
99100
apply(compiler: Compiler) {
100101
const { dtsOptions, pluginOptions, fetchRemoteTypeUrlsResolve } = this;
101102

102-
if (isPrd()) {
103-
fetchRemoteTypeUrlsResolve(undefined);
104-
return;
105-
}
106-
107103
const dtsManagerOptions = normalizeConsumeTypesOptions({
108104
context: compiler.context,
109105
dtsOptions,
@@ -115,6 +111,11 @@ export class ConsumeTypesPlugin implements WebpackPluginInstance {
115111
return;
116112
}
117113

114+
if (isPrd() && !dtsManagerOptions.host.typesOnBuild) {
115+
fetchRemoteTypeUrlsResolve(undefined);
116+
return;
117+
}
118+
118119
logger.debug('start fetching remote types...');
119120
const promise = consumeTypesAPI(
120121
dtsManagerOptions,

packages/sdk/src/types/plugins/ModuleFederationPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export interface DtsHostOptions {
156156
runtimePkgs?: string[];
157157
remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
158158
timeout?: number;
159+
typesOnBuild?: boolean;
159160
}
160161

161162
export interface DtsRemoteOptions {

0 commit comments

Comments
 (0)