Skip to content
Merged
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/odd-walls-crash.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 `family` option to DTS plugin
9 changes: 9 additions & 0 deletions apps/website-new/docs/en/configure/dts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ interface DtsHostOptions {
deleteTypesFolder?: boolean;
maxRetries?: number;
consumeAPITypes?: boolean;
family?: 4 | 6;
}
```

Expand Down Expand Up @@ -278,6 +279,14 @@ export default createModuleFederationConfig({
});
```

#### family

- Type: `4 | 6`
- Required: No
- Default value: 4

Configure the IP version family that will be used for network operations.

### tsConfigPath

- Type: `string`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('hostPlugin', () => {
runtimePkgs: [],
remoteTypeUrls: {},
timeout: 60000,
family: 4,
typesOnBuild: false,
});

Expand Down Expand Up @@ -71,6 +72,7 @@ describe('hostPlugin', () => {
runtimePkgs: [],
remoteTypeUrls: {},
timeout: 60000,
family: 4,
typesOnBuild: false,
};

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 @@ -20,6 +20,7 @@ const defaultOptions = {
remoteTypeUrls: {},
timeout: 60000,
typesOnBuild: false,
family: 4,
} satisfies Partial<HostOptions>;

const buildZipUrl = (hostOptions: Required<HostOptions>, url: string) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/dts-plugin/src/core/lib/DTSManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ class DTSManager {
return remoteInfo as Required<RemoteInfo>;
}
const url = remoteInfo.url;
const res = await axiosGet(url, { timeout: hostOptions.timeout });
const res = await axiosGet(url, {
timeout: hostOptions.timeout,
family: hostOptions.family,
});
const manifestJson = res.data as unknown as Manifest;
if (!manifestJson.metaData.types.zip) {
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
Expand Down Expand Up @@ -294,7 +297,10 @@ class DTSManager {
}
try {
const url = apiTypeUrl;
const res = await axiosGet(url, { timeout: hostOptions.timeout });
const res = await axiosGet(url, {
timeout: hostOptions.timeout,
family: hostOptions.family,
});
let apiTypeFile = res.data as string;
apiTypeFile = apiTypeFile.replaceAll(
REMOTE_ALIAS_IDENTIFIER,
Expand Down
1 change: 1 addition & 0 deletions packages/dts-plugin/src/core/lib/archiveHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const downloadTypesArchive = (hostOptions: Required<HostOptions>) => {
const response = await axiosGet(url, {
responseType: 'arraybuffer',
timeout: hostOptions.timeout,
family: hostOptions.family,
}).catch(downloadErrorLogger(destinationFolder, url));
if (
typeof response.headers?.['content-type'] === 'string' &&
Expand Down
10 changes: 10 additions & 0 deletions packages/dts-plugin/src/core/lib/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ it('axiosGet should use agents with family set to 4', async () => {

httpSpy.mockRestore();
});

it('axiosGet should allow to use agents with family set to 6', async () => {
const httpSpy = vi.spyOn(http, 'Agent');

await axiosGet('http://localhost', { family: 6 });

expect(httpSpy).toHaveBeenCalledWith({ family: 6 });

httpSpy.mockRestore();
});
4 changes: 2 additions & 2 deletions packages/dts-plugin/src/core/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ const getEnvHeaders = (): Record<string, string> => {
};

export async function axiosGet(url: string, config?: AxiosRequestConfig) {
const httpAgent = new http.Agent({ family: 4 });
const httpsAgent = new https.Agent({ family: 4 });
const httpAgent = new http.Agent({ family: config?.family ?? 4 });
const httpsAgent = new https.Agent({ family: config?.family ?? 4 });
return axios.get(url, {
httpAgent,
httpsAgent,
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ export interface DtsHostOptions {
runtimePkgs?: string[];
remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
timeout?: number;
/** The family of IP, used for network requests */
family?: 4 | 6;
typesOnBuild?: boolean;
}

Expand Down