Skip to content

Commit 88445e7

Browse files
fix(enhanced): support get public path (#2638)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 6838379 commit 88445e7

File tree

18 files changed

+176
-33
lines changed

18 files changed

+176
-33
lines changed

.changeset/cold-rocks-listen.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
'@module-federation/enhanced': patch
4+
'@module-federation/manifest': patch
5+
'@module-federation/sdk': patch
6+
---
7+
8+
Support getPublicPath in compiler plugins

.github/workflows/build-and-test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ jobs:
3737
- name: Check Code Format
3838
run: npx nx format:check
3939

40-
- name: Run Affected Build
41-
run: npx nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache
40+
- name: Update NX Build Cache
41+
run: npx nx run-many --targets=build --exclude='*,!tag:type:pkg'
42+
43+
- name: Run Build for All
44+
run: npx nx run-many --targets=build --exclude='*,!tag:type:pkg' --skip-nx-cache
4245

4346
- name: Run Affected Lint
4447
run: npx nx affected -t lint --parallel=7 --exclude='*,!tag:type:pkg'
4548

4649
- name: Run Affected Test
47-
run: npx nx run-many -t test --parallel=3 --exclude='*,!tag:type:pkg' --skip-nx-cache
50+
run: npx nx affected -t test --parallel=2 --exclude='*,!tag:type:pkg' --skip-nx-cache
4851

4952
# - name: E2E Test for Next.js Dev
5053
# run: |

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ packages/enhanced/test/js
5858
**/.mf
5959
**/.mf/**
6060

61+
/apps/manifest-demo/**/@mf-types/
62+
/apps/manifest-demo/3008-webpack-host/@mf-types/

apps/runtime-demo/3005-runtime-host/@mf-types/index.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import type { PackageType as PackageType_0,RemoteKeys as RemoteKeys_0 } from './remote1/apis.d.ts';
1+
import type { PackageType as PackageType_0,RemoteKeys as RemoteKeys_0 } from './dynamic-remote/apis.d.ts';
2+
import type { PackageType as PackageType_1,RemoteKeys as RemoteKeys_1 } from './remote1/apis.d.ts';
23
declare module "@module-federation/runtime" {
3-
type RemoteKeys = RemoteKeys_0;
4+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
45
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
6+
T extends RemoteKeys_1 ? PackageType_1<T> :
57
Y ;
68
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
79
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
810
}
911
declare module "@module-federation/enhanced/runtime" {
10-
type RemoteKeys = RemoteKeys_0;
12+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
1113
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
14+
T extends RemoteKeys_1 ? PackageType_1<T> :
1215
Y ;
1316
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
1417
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
1518
}
1619
declare module "@module-federation/runtime-tools" {
17-
type RemoteKeys = RemoteKeys_0;
20+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
1821
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
22+
T extends RemoteKeys_1 ? PackageType_1<T> :
1923
Y ;
2024
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
2125
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;

apps/runtime-demo/3005-runtime-host/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@module-federation/runtime": "workspace:*",
88
"@module-federation/typescript": "workspace:*",
99
"@module-federation/enhanced": "workspace:*",
10+
"@module-federation/dts-plugin": "workspace:*",
1011
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
1112
"react-refresh": "0.14.0"
1213
},

apps/runtime-demo/3005-runtime-host/project.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
"baseUrl": "http://127.0.0.1:3005",
100100
"browser": "chrome"
101101
},
102+
"dependsOn": [
103+
{
104+
"target": "build",
105+
"dependencies": true
106+
}
107+
],
102108
"configurations": {
103109
"development": {
104110
"runnerUi": true,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
'./Button': './src/components/Button.tsx',
2323
},
2424
// ...
25-
getPublicPath: `function(currentPath) {return "https:" + window.navigator.cdn_host + "/resource/app/"}`,
25+
getPublicPath: `function() {return "https:" + window.navigator.cdn_host + "/resource/app/"}`,
2626
}),
2727
],
2828
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"lint": "nx run-many --target=lint",
2626
"test": "nx run-many --target=test",
2727
"build": "nx run-many --target=build --parallel=3 --projects=tag:type:pkg",
28-
"build:pkg": "nx run-many --targets=build --projects=tag:type:pkg",
28+
"build:pkg": "nx run-many --targets=build --projects=tag:type:pkg --skip-nx-cache",
2929
"lint-fix": "nx format:write --uncommitted",
3030
"trigger-release": "node -e 'import(\"open\").then(open => open.default(\"https://github.com/module-federation/core/actions/workflows/trigger-release.yml\"))'",
3131
"serve:next": "nx run-many --target=serve --all --parallel=3 -exclude='*,!tag:nextjs'",

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,20 @@ class DTSManager {
201201
return u;
202202
};
203203

204-
let publicPath =
205-
'publicPath' in manifestJson.metaData
206-
? manifestJson.metaData.publicPath
207-
: new Function(manifestJson.metaData.getPublicPath)();
204+
let publicPath;
205+
206+
if ('publicPath' in manifestJson.metaData) {
207+
publicPath = manifestJson.metaData.publicPath;
208+
} else {
209+
const getPublicPath = new Function(manifestJson.metaData.getPublicPath);
210+
211+
if (manifestJson.metaData.getPublicPath.startsWith('function')) {
212+
publicPath = getPublicPath()();
213+
} else {
214+
publicPath = getPublicPath();
215+
}
216+
}
217+
208218
if (publicPath === 'auto') {
209219
publicPath = inferAutoPublicPath(remoteInfo.url);
210220
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ describe('generateTypesInChildProcess', () => {
194194
},
195195
],
196196
});
197+
await new Promise((res) => {
198+
setTimeout(res, 1000);
199+
});
197200
// the child process should be killed after generateTypes
198201
expect(checkProcess()).toEqual(false);
199202
});

0 commit comments

Comments
 (0)