Skip to content

Commit f6381e6

Browse files
ogonkov2heal1
andauthored
feat(dts-plugin): add family option (#3977)
Co-authored-by: Hanric <[email protected]>
1 parent 14937d7 commit f6381e6

File tree

9 files changed

+41
-4
lines changed

9 files changed

+41
-4
lines changed

.changeset/odd-walls-crash.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 `family` option to DTS plugin

apps/website-new/docs/en/configure/dts.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ interface DtsHostOptions {
148148
deleteTypesFolder?: boolean;
149149
maxRetries?: number;
150150
consumeAPITypes?: boolean;
151+
family?: 4 | 6;
151152
}
152153
```
153154

@@ -278,6 +279,14 @@ export default createModuleFederationConfig({
278279
});
279280
```
280281

282+
#### family
283+
284+
- Type: `4 | 6`
285+
- Required: No
286+
- Default value: 4
287+
288+
Configure the IP version family that will be used for network operations.
289+
281290
### tsConfigPath
282291

283292
- Type: `string`

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+
family: 4,
4647
typesOnBuild: false,
4748
});
4849

@@ -71,6 +72,7 @@ describe('hostPlugin', () => {
7172
runtimePkgs: [],
7273
remoteTypeUrls: {},
7374
timeout: 60000,
75+
family: 4,
7476
typesOnBuild: false,
7577
};
7678

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const defaultOptions = {
2020
remoteTypeUrls: {},
2121
timeout: 60000,
2222
typesOnBuild: false,
23+
family: 4,
2324
} satisfies Partial<HostOptions>;
2425

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

packages/dts-plugin/src/core/lib/DTSManager.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ class DTSManager {
220220
return remoteInfo as Required<RemoteInfo>;
221221
}
222222
const url = remoteInfo.url;
223-
const res = await axiosGet(url, { timeout: hostOptions.timeout });
223+
const res = await axiosGet(url, {
224+
timeout: hostOptions.timeout,
225+
family: hostOptions.family,
226+
});
224227
const manifestJson = res.data as unknown as Manifest;
225228
if (!manifestJson.metaData.types.zip) {
226229
throw new Error(`Can not get ${remoteInfo.name}'s types archive url!`);
@@ -294,7 +297,10 @@ class DTSManager {
294297
}
295298
try {
296299
const url = apiTypeUrl;
297-
const res = await axiosGet(url, { timeout: hostOptions.timeout });
300+
const res = await axiosGet(url, {
301+
timeout: hostOptions.timeout,
302+
family: hostOptions.family,
303+
});
298304
let apiTypeFile = res.data as string;
299305
apiTypeFile = apiTypeFile.replaceAll(
300306
REMOTE_ALIAS_IDENTIFIER,

packages/dts-plugin/src/core/lib/archiveHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const downloadTypesArchive = (hostOptions: Required<HostOptions>) => {
6464
const response = await axiosGet(url, {
6565
responseType: 'arraybuffer',
6666
timeout: hostOptions.timeout,
67+
family: hostOptions.family,
6768
}).catch(downloadErrorLogger(destinationFolder, url));
6869
if (
6970
typeof response.headers?.['content-type'] === 'string' &&

packages/dts-plugin/src/core/lib/utils.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ it('axiosGet should use agents with family set to 4', async () => {
1717

1818
httpSpy.mockRestore();
1919
});
20+
21+
it('axiosGet should allow to use agents with family set to 6', async () => {
22+
const httpSpy = vi.spyOn(http, 'Agent');
23+
24+
await axiosGet('http://localhost', { family: 6 });
25+
26+
expect(httpSpy).toHaveBeenCalledWith({ family: 6 });
27+
28+
httpSpy.mockRestore();
29+
});

packages/dts-plugin/src/core/lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ const getEnvHeaders = (): Record<string, string> => {
151151
};
152152

153153
export async function axiosGet(url: string, config?: AxiosRequestConfig) {
154-
const httpAgent = new http.Agent({ family: 4 });
155-
const httpsAgent = new https.Agent({ family: 4 });
154+
const httpAgent = new http.Agent({ family: config?.family ?? 4 });
155+
const httpsAgent = new https.Agent({ family: config?.family ?? 4 });
156156
return axios.get(url, {
157157
httpAgent,
158158
httpsAgent,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export interface DtsHostOptions {
156156
runtimePkgs?: string[];
157157
remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
158158
timeout?: number;
159+
/** The family of IP, used for network requests */
160+
family?: 4 | 6;
159161
typesOnBuild?: boolean;
160162
}
161163

0 commit comments

Comments
 (0)