Skip to content

Commit 34f9498

Browse files
adamdharringtonScriptedAlchemyilteoood
authored
fix(dts-plugin): let dts_plugin handle remote paths instead of abs URLs (#2478)
Co-authored-by: Zack Jackson <[email protected]> Co-authored-by: Matteo Pietro Dazzi <[email protected]>
1 parent 685c607 commit 34f9498

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.changeset/late-numbers-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
dts-plugin can now support remotes using relative path references: 'app@/mf-manifest.json'

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,28 @@ describe('hostPlugin', () => {
118118
},
119119
});
120120
});
121+
122+
it('correctly resolve remotes with relative reference in place of absolute url', () => {
123+
const subpathModuleFederationConfig = {
124+
...moduleFederationConfig,
125+
remotes: {
126+
moduleFederationTypescript: '/subpatha/mf-manifest.json',
127+
},
128+
};
129+
130+
const { mapRemotesToDownload } = retrieveHostConfig({
131+
moduleFederationConfig: subpathModuleFederationConfig,
132+
});
133+
134+
expect(mapRemotesToDownload).toStrictEqual({
135+
moduleFederationTypescript: {
136+
alias: 'moduleFederationTypescript',
137+
apiTypeUrl: '/subpatha/@mf-types.d.ts',
138+
name: '/subpatha/mf-manifest.json',
139+
url: '/subpatha/mf-manifest.json',
140+
zipUrl: '/subpatha/@mf-types.zip',
141+
},
142+
});
143+
});
121144
});
122145
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const defaultOptions = {
1515
} satisfies Partial<HostOptions>;
1616

1717
const buildZipUrl = (hostOptions: Required<HostOptions>, url: string) => {
18-
const remoteUrl = new URL(url);
18+
const remoteUrl = new URL(url, 'file:');
1919

2020
const pathnameWithoutEntry = remoteUrl.pathname
2121
.split('/')
2222
.slice(0, -1)
2323
.join('/');
2424
remoteUrl.pathname = `${pathnameWithoutEntry}/${hostOptions.remoteTypesFolder}.zip`;
2525

26-
return remoteUrl.href;
26+
return remoteUrl.protocol === 'file:' ? remoteUrl.pathname : remoteUrl.href;
2727
};
2828

2929
const buildApiTypeUrl = (zipUrl?: string) => {

0 commit comments

Comments
 (0)