Skip to content

feat(dts-plugin): added flag to fetch types #3840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/large-actors-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/dts-plugin': minor
'@module-federation/sdk': minor
---

added flag to fetch types from remote when building in production.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('hostPlugin', () => {
runtimePkgs: [],
remoteTypeUrls: {},
timeout: 60000,
typesOnBuild: false,
});

expect(mapRemotesToDownload).toStrictEqual({
Expand Down Expand Up @@ -70,6 +71,7 @@ describe('hostPlugin', () => {
runtimePkgs: [],
remoteTypeUrls: {},
timeout: 60000,
typesOnBuild: false,
};

const { hostOptions, mapRemotesToDownload } =
Expand Down
1 change: 1 addition & 0 deletions packages/dts-plugin/src/core/configurations/hostPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const defaultOptions = {
runtimePkgs: [],
remoteTypeUrls: {},
timeout: 60000,
typesOnBuild: false,
} satisfies Partial<HostOptions>;

const buildZipUrl = (hostOptions: Required<HostOptions>, url: string) => {
Expand Down
11 changes: 6 additions & 5 deletions packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { Compiler, WebpackPluginInstance } from 'webpack';
export const DEFAULT_CONSUME_TYPES = {
abortOnError: false,
consumeAPITypes: true,
typesOnBuild: false,
};

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

if (isPrd()) {
fetchRemoteTypeUrlsResolve(undefined);
return;
}

const dtsManagerOptions = normalizeConsumeTypesOptions({
context: compiler.context,
dtsOptions,
Expand All @@ -115,6 +111,11 @@ export class ConsumeTypesPlugin implements WebpackPluginInstance {
return;
}

if (isPrd() && !dtsManagerOptions.host.typesOnBuild) {
fetchRemoteTypeUrlsResolve(undefined);
return;
}

logger.debug('start fetching remote types...');
const promise = consumeTypesAPI(
dtsManagerOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export interface DtsHostOptions {
runtimePkgs?: string[];
remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
timeout?: number;
typesOnBuild?: boolean;
}

export interface DtsRemoteOptions {
Expand Down