Skip to content

Commit 648353b

Browse files
fix(enhanced): plugin failure when federation runtime is unused (#2324)
Co-authored-by: ScriptedAlchemy <[email protected]> Co-authored-by: 2heal1 <[email protected]>
1 parent f3d159b commit 648353b

File tree

15 files changed

+132
-80
lines changed

15 files changed

+132
-80
lines changed

.changeset/fuzzy-shirts-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
Filter falsey runtime plugins from registerPlugins

.changeset/long-sheep-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
Check that runtime plugins are not undefined or tree shaken out before calling the factory functions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ jobs:
4141
run: npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'
4242

4343
- name: Run Affected Lint
44-
run: npx nx affected -t lint --parallel=7 --exclude='*,!tag:package'
44+
run: npx nx affected -t lint --parallel=7 --exclude='*,!tag:type:pkg'
4545

4646
- name: Run Affected Test
4747
run: npx nx affected -t test --parallel=3 --exclude='*,!tag:type:pkg'
4848

4949
- name: E2E Test for Next.js
50-
run: pnpm run app:next:dev & echo "done" && sleep 50 && npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=2 && lsof -ti tcp:3000,3001,3002 | xargs kill
50+
run: pnpm run app:next:dev & echo "done" && npx wait-on tcp:3000 && npx wait-on tcp:3001 && npx wait-on tcp:3002 && npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=2 && lsof -ti tcp:3000,3001,3002 | xargs kill
5151

5252
# - name: E2E Test for 3001-shop
5353
# run: pnpm run app:next:dev & echo "done" && sleep 20 && npx nx run-many --target=test:e2e --projects=3001-shop && lsof -ti tcp:3000,3001,3002 | xargs kill

.github/workflows/devtools.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: pnpm install
3636

3737
- name: Run Affected Build
38-
run: npx nx build --parallel=10 --exclude='*,!tag:package'
38+
run: npx nx build --parallel=10 --exclude='*,!tag:type:pkg'
3939

4040
- name: Configuration xvfb
4141
shell: bash

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: pnpm install
4949

5050
- name: Build and test Packages
51-
run: npx nx run-many --target=build --exclude='*,!tag:package'
51+
run: npx nx run-many --target=build --exclude='*,!tag:type:pkg'
5252

5353
- name: Release
5454
uses: web-infra-dev/actions@v2

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Thank you for your interest in contributing to Module Federation! Before startin
1010
4. Set up the development environment. Refer to the "Setup Development Environment" section below for guidance.
1111
5. If you've fixed a bug or added code that should be tested, add some tests.
1212
6. Ensure all tests pass. See the "Testing" section below for more information.
13-
7. Run `nx format:write` and `nx affected -t lint --parallel=7 --exclude='*,!tag:package'` to check and fix the code style.
13+
7. Run `nx format:write` and `nx affected -t lint --parallel=7 --exclude='*,!tag:type:pkg'` to check and fix the code style.
1414
8. If you've changed Node.js packages, run `npm run commit` for semantic versioning and commit.
1515
9. Submit the Pull Request, ensuring all CI runs pass.
1616
10. Your Pull Request will be reviewed by the maintainers soon.
@@ -88,7 +88,7 @@ Replace `PROJECT-NAME` with the actual name of the project you want to test. The
8888
To run tests only for the projects affected by recent changes, use:
8989

9090
```sh
91-
npx nx affected -t test --parallel=3 --exclude='*,!tag:package'
91+
npx nx affected -t test --parallel=3 --exclude='*,!tag:type:pkg'
9292
```
9393

9494
This command ensures that only relevant tests are executed, saving time and resources.

apps/3001-shop/pages/shop/index.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ Shop.getInitialProps = async () => {
4949
const timeout = (ms: number) =>
5050
new Promise((resolve) => setTimeout(resolve, ms));
5151

52-
const fetchPromise = fetch('http://swapi.dev/api/planets/1/')
53-
.then((res) => res.json())
54-
.catch((err) => {
55-
if (err instanceof Error) {
56-
err.message = `fetchPromise failed: ${err.message}`;
57-
}
58-
console.error(err);
59-
return Promise.resolve(fallback);
60-
});
61-
6252
const fallback = {
6353
name: 'Luke Skywalker',
6454
height: '172',
@@ -91,7 +81,7 @@ Shop.getInitialProps = async () => {
9181

9282
const timerPromise = timeout(3000).then(() => fallback);
9383

94-
return Promise.race([fetchPromise, timerPromise]);
84+
return Promise.race([timerPromise]);
9585
};
9686

9787
export default Shop;

apps/3002-checkout/pages/checkout/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ Checkout.getInitialProps = async () => {
4747
const timeout = (ms: number) =>
4848
new Promise((resolve) => setTimeout(resolve, ms));
4949

50-
const fetchPromise = fetch('http://swapi.dev/api/planets/1/').then((res) =>
51-
res.json(),
52-
);
53-
5450
// this will resolve after 3 seconds
5551
const timerPromise = timeout(3000).then(() => ({
5652
userId: 1,
@@ -59,6 +55,6 @@ Checkout.getInitialProps = async () => {
5955
completed: false,
6056
}));
6157

62-
return Promise.race([fetchPromise, timerPromise]);
58+
return Promise.race([timerPromise]);
6359
};
6460
export default Checkout;

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"docs": "typedoc",
2525
"lint": "nx run-many --target=lint",
2626
"test": "nx run-many --target=test",
27-
"build": "nx run-many --target=build --parallel=3 --exclude='*,!tag:package'",
27+
"build": "nx run-many --target=build --parallel=3 --exclude='*,!tag:type:pkg'",
2828
"build:pkg": "nx run-many --targets=build --projects=tag:type:pkg",
2929
"lint-fix": "nx format:write --uncommitted",
3030
"trigger-release": "node -e 'import(\"open\").then(open => open.default(\"https://github.com/module-federation/universe/actions/workflows/trigger-release.yml\"))'",
@@ -43,7 +43,7 @@
4343
"commitlint": "commitlint --edit",
4444
"prepare": "husky install",
4545
"changeset": "changeset",
46-
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:package'"
46+
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'"
4747
},
4848
"dependencies": {
4949
"adm-zip": "0.5.10",
@@ -143,6 +143,7 @@
143143
"@types/lodash.get": "4.4.9",
144144
"@types/node": "18.19.26",
145145
"@types/node-fetch": "2.6.11",
146+
"@types/pidusage": "2.0.5",
146147
"@types/react": "18.2.62",
147148
"@types/react-dom": "18.2.19",
148149
"@types/webpack-sources": "3.2.3",
@@ -198,6 +199,7 @@
198199
"open": "^10.0.0",
199200
"openai": "3.3.0",
200201
"pdf-parse": "1.1.1",
202+
"pidusage": "3.0.2",
201203
"postcss-calc": "9.0.1",
202204
"postcss-custom-properties": "13.3.5",
203205
"postcss-import": "15.1.0",
@@ -227,13 +229,12 @@
227229
"vitest": "1.2.2",
228230
"vitest-fetch-mock": "^0.2.2",
229231
"vue-tsc": "1.8.27",
232+
"wait-on": "^7.2.0",
230233
"wast-loader": "^1.11.5",
231234
"webpack": "^5.90.0",
232235
"webpack-virtual-modules": "0.6.1",
233236
"whatwg-fetch": "^3.6.2",
234-
"yargs": "^17.7.2",
235-
"pidusage": "3.0.2",
236-
"@types/pidusage": "2.0.5"
237+
"yargs": "^17.7.2"
237238
},
238239
"config": {
239240
"commitizen": {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ describe('DTSManager advance usage', () => {
9191
await dtsManager.consumeTypes();
9292

9393
const targetFolder = join(projectRoot, hostOptions.typesFolder);
94-
expect(dirTree(targetFolder, { exclude: /node_modules/ })).toMatchObject({
94+
expect(
95+
dirTree(targetFolder, {
96+
exclude: [/node_modules/, /dev-worker/, /plugins/, /server/],
97+
}),
98+
).toMatchObject({
9599
name: '@mf-types-dts-test-consume-types-advance',
96100
children: [
97101
{

0 commit comments

Comments
 (0)