Skip to content

Commit 5a72b9c

Browse files
committed
fix: include path in MF2 remote public path (#1114)
* fix: include path in remote public path * chore: changeset
1 parent 1b21ee4 commit 5a72b9c

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Fix handling of MF2 remote assets paths in ResolverPlugin

packages/repack/src/modules/FederationRuntimePlugins/ResolverPlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const createScriptLocator = async (
2020
};
2121

2222
const getPublicPath = (url: string) => {
23-
const [protocol, rest] = url.split('://');
24-
return protocol + '://' + rest.split('/')[0];
23+
return url.split('/').slice(0, -1).join('/');
2524
};
2625

2726
const getAssetPath = (url: string) => {

packages/repack/src/modules/FederationRuntimePlugins/__tests__/ResolverPlugin.test.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('RepackResolverPlugin', () => {
6767
);
6868

6969
expect(script.locator.url).toBe(
70-
'https://example-manifest.com/remoteEntry.js'
70+
'https://example-manifest.com/remote1/remoteEntry.js'
7171
);
7272
});
7373

@@ -86,7 +86,9 @@ describe('RepackResolverPlugin', () => {
8686
'https://example-entry.com/remoteEntry.js'
8787
);
8888

89-
expect(script.locator.url).toBe('https://example-entry.com/remoteEntry.js');
89+
expect(script.locator.url).toBe(
90+
'https://example-entry.com/remote1/remoteEntry.js'
91+
);
9092
});
9193

9294
it('should allow custom configuration when used in runtime with a config object', async () => {
@@ -152,11 +154,11 @@ describe('RepackResolverPlugin', () => {
152154
'chunk1',
153155
'remote1',
154156
webpackRequireMock,
155-
'https://example-entry.com/remote1/assets/nested/chunk1.js'
157+
'https://example-entry.com/remote1/assets/chunk1.js'
156158
);
157159

158160
expect(script.locator.url).toBe(
159-
'https://example-manifest.com/remote1/assets/nested/chunk1.js'
161+
'https://example-manifest.com/remote1/chunk1.js'
160162
);
161163
expect(script.locator.headers).toEqual({ authorization: 'Bearer token' });
162164
expect(script.locator.fetch).toBe(true);
@@ -184,18 +186,37 @@ describe('RepackResolverPlugin', () => {
184186
it('should rebase the URL from reference URL to entry URL', async () => {
185187
const plugin = RepackResolverPlugin();
186188
// trigger the plugin to register the resolver
187-
plugin.afterResolve!({ remoteInfo: mockRemoteInfo } as any);
189+
plugin.afterResolve!({
190+
remoteInfo: {
191+
name: 'remote1',
192+
entry: 'https://example.com/ios/remote1/entry.container.js.bundle',
193+
version: 'https://example-manifest.com/remote1/mf-manifest.json',
194+
},
195+
} as any);
188196

189197
// manually resolve the script to verify the result
190-
const script = await ScriptManager.shared.resolveScript(
198+
const script1 = await ScriptManager.shared.resolveScript(
199+
'remote1',
200+
undefined,
201+
webpackRequireMock,
202+
'https://example.com/ios/remote1/entry.container.js.bundle'
203+
);
204+
205+
// container entry is expected to be at the same level as manifest
206+
expect(script1.locator.url).toBe(
207+
'https://example-manifest.com/remote1/entry.container.js.bundle'
208+
);
209+
210+
const script2 = await ScriptManager.shared.resolveScript(
191211
'asset',
192212
'remote1',
193213
webpackRequireMock,
194-
'https://example-entry.com/remote1/subdir/asset.js'
214+
'http://localhost:8081/ios/remote1/asset.js'
195215
);
196216

197-
expect(script.locator.url).toBe(
198-
'https://example-manifest.com/remote1/subdir/asset.js'
217+
// all other assets are expected to be at the same level as manifest
218+
expect(script2.locator.url).toBe(
219+
'https://example-manifest.com/remote1/asset.js'
199220
);
200221
});
201222
});

0 commit comments

Comments
 (0)