Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(enhanced): adjust add federation init process #2035

Merged
merged 31 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
de0b37f
chore: re define prefetch types
nyqykk Jan 19, 2024
a6eacc5
chore: add changeset
nyqykk Jan 19, 2024
3f7db85
fix: change to optional params
nyqykk Jan 19, 2024
f35d5ce
chore: add params for preload hook
nyqykk Jan 22, 2024
8fffc14
fix: fix hook type
nyqykk Jan 22, 2024
0789af7
chore: remove inject runtime template into global require
nyqykk Jan 23, 2024
3fc3886
chore: remove useless code
nyqykk Jan 24, 2024
bc4925e
feat: add plugin params to find the remote
nyqykk Jan 26, 2024
56930d9
chore(enhanced): adjust add federation init process
nyqykk Jan 26, 2024
5d39de2
Merge branch 'main' into chore/prefetch-type
nyqykk Jan 26, 2024
8b31bd5
fix(enhanced): create entry with runtime arguments
ScriptedAlchemy Feb 1, 2024
c994d4b
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 2, 2024
8b45b2c
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 23, 2024
2ef0547
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 23, 2024
e66211b
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 23, 2024
fa4ae69
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 24, 2024
ce2a046
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 27, 2024
ae655d7
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Feb 27, 2024
6707d33
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Mar 5, 2024
7917fa1
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Mar 9, 2024
74f2396
chore: resolve conflict
nyqykk Mar 15, 2024
c0faca1
fix: fix stats define
nyqykk Mar 15, 2024
32d158d
chore: remove useless define
nyqykk Mar 15, 2024
9f88ef9
Merge branch 'main' into chore/prefetch-type
zhoushaw Mar 18, 2024
cf6f365
Merge branch 'main' into chore/prefetch-type
nyqykk Mar 18, 2024
a6a393b
chore: compat old version
nyqykk Mar 18, 2024
4fe1443
Merge branch 'chore/prefetch-type' of github.com:module-federation/un…
nyqykk Mar 18, 2024
97691e1
chore: revert add entry in container plugin
nyqykk Mar 18, 2024
5963b34
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Mar 25, 2024
555591f
feat(enhanced): use chunk integration to initalize federation runtime…
ScriptedAlchemy Mar 25, 2024
0a02b45
Merge branch 'main' into chore/prefetch-type
ScriptedAlchemy Mar 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-kids-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': patch
---

Support multiple runtime chunks, single runtime chunks in reference hoisting
5 changes: 5 additions & 0 deletions .changeset/fifty-swans-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/node': minor
---

entry tracking and improved hot reloading for node
7 changes: 7 additions & 0 deletions .changeset/happy-crabs-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@module-federation/enhanced': patch
'@module-federation/runtime': patch
'@module-federation/sdk': patch
---

chore: adjust add federation init process
5 changes: 5 additions & 0 deletions .changeset/moody-brooms-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/sdk': patch
---

Remove log of container exports in sdk
6 changes: 6 additions & 0 deletions .changeset/smooth-turkeys-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@module-federation/runtime': patch
'@module-federation/sdk': patch
---

chore: redefine prefetch types
7 changes: 7 additions & 0 deletions .changeset/stupid-mangos-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@module-federation/nextjs-mf': minor
'@module-federation/enhanced': minor
'@module-federation/sdk': patch
---

use chunk integration to initalize federation runtime and plugins in runtime bootstrap
11 changes: 7 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ jobs:
- name: Run Affected Test
run: npx nx affected -t test --parallel=3 --exclude='*,!tag:package'

- name: E2E Test for 3000-home
run: pnpm run app:next:dev & echo "done" && sleep 20 && npx nx run-many --target=test:e2e --projects=3000-home && lsof -ti tcp:3000,3001,3002 | xargs kill
- name: E2E Test for Next.js
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

- name: E2E Test for 3001-shop
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
# - name: E2E Test for 3001-shop
# 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

- name: E2E Test for ModernJS
run: npx nx run-many --target=test:e2e --projects=modernjs --parallel=1 && lsof -ti tcp:8080 | xargs kill

# - name: E2E Test for 3002-checkout
# run: pnpm run app:next:dev & echo "done" && sleep 15 && npx nx run-many --target=test:e2e --projects=3002-checkout && lsof -ti tcp:3000,3001,3002 | xargs kill
Expand Down
4 changes: 4 additions & 0 deletions apps/3000-home/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export default defineConfig({
projectId: 'sa6wfn',
e2e: nxE2EPreset(__filename, { cypressDir: 'cypress' }),
defaultCommandTimeout: 20000,
retries: {
runMode: 2,
openMode: 1,
},
});
11 changes: 8 additions & 3 deletions apps/3000-home/cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('3000-home/', () => {
});

describe('Routing checks', () => {
xit('check that clicking back and forwards in client side routeing still renders the content correctly', () => {
it('check that clicking back and forwards in client side routeing still renders the content correctly', () => {
cy.visit('/');
cy.visit('/shop');
cy.visit('/');
Expand All @@ -51,7 +51,11 @@ describe('3000-home/', () => {
});

describe('3000-home/checkout', () => {
beforeEach(() => cy.visit('/checkout'));
beforeEach(() => {
cy.visit('/checkout');
cy.visit('/');
cy.visit('/checkout');
});

describe('Welcome message', () => {
it('should display welcome message', () => {
Expand Down Expand Up @@ -102,7 +106,8 @@ describe('3000-home/', () => {
cy.request(src).its('status').should('eq', 200);
});
});
xit('should check that shop-webpack-png images are not 404 between route clicks', () => {
it('should check that shop-webpack-png images are not 404 between route clicks', () => {
cy.visit('/');
cy.visit('/shop');
cy.url().should('include', '/shop');
getH1().contains('Shop Page');
Expand Down
1 change: 1 addition & 0 deletions apps/3000-home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tapable": "2.2.1",
"terser-webpack-plugin": "5.3.10",
"typescript": "5.3.3",
"upath": "2.0.1",
"url": "0.11.3",
"util": "0.12.5",
"webpack-sources": "3.2.3"
Expand Down
4 changes: 3 additions & 1 deletion apps/3000-home/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function MyApp(props) {
}
};
// handle first route hit.
React.useMemo(() => handleRouteChange(asPath), [asPath]);
React.useEffect(() => {
handleRouteChange(asPath);
}, [asPath]);

//handle route change
React.useEffect(() => {
Expand Down
18 changes: 11 additions & 7 deletions apps/3000-home/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import {

class MyDocument extends Document {
static async getInitialProps(ctx) {
if (ctx.pathname) {
if (!ctx.pathname.endsWith('_error')) {
await revalidate().then((shouldUpdate) => {
if (shouldUpdate) {
console.log('should HMR', shouldUpdate);
}
});
}
}

const initialProps = await Document.getInitialProps(ctx);

const chunks = await flushChunks();
ctx?.res?.on('finish', () => {
revalidate().then((shouldUpdate) => {
if (shouldUpdate) {
console.log('should HMR', shouldUpdate);
}
});
});

return {
...initialProps,
Expand Down
4 changes: 4 additions & 0 deletions apps/3001-shop/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ import { defineConfig } from 'cypress';
export default defineConfig({
e2e: nxE2EPreset(__filename, { cypressDir: 'cypress' }),
defaultCommandTimeout: 10000,
retries: {
runMode: 2,
openMode: 1,
},
});
3 changes: 0 additions & 3 deletions apps/3001-shop/cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { getH1, getH3 } from '../support/app.po';
describe('3001-shop/', () => {
beforeEach(() => {
cy.visit('/');
cy.visit('/shop');
cy.visit('/checkout');
cy.visit('/');
});

describe('Welcome message', () => {
Expand Down
1 change: 1 addition & 0 deletions apps/3001-shop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"tapable": "2.2.1",
"terser-webpack-plugin": "5.3.10",
"typescript": "5.3.3",
"upath": "2.0.1",
"url": "0.11.3",
"util": "0.12.5",
"webpack-sources": "3.2.3"
Expand Down
4 changes: 3 additions & 1 deletion apps/3001-shop/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function MyApp({ Component, pageProps }) {
}
};
// handle first route hit.
React.useMemo(() => handleRouteChange(asPath), [asPath]);
React.useEffect(() => {
handleRouteChange(asPath);
}, [asPath]);

//handle route change
React.useEffect(() => {
Expand Down
21 changes: 9 additions & 12 deletions apps/3001-shop/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ import {

class MyDocument extends Document {
static async getInitialProps(ctx) {
await revalidate().then((shouldUpdate) => {
if (shouldUpdate) {
ctx.res.writeHead(307, { Location: ctx.req.url });
ctx.res.end();
if (ctx.pathname) {
if (!ctx.pathname.endsWith('_error')) {
await revalidate().then((shouldUpdate) => {
if (shouldUpdate) {
console.log('should HMR', shouldUpdate);
}
});
}
});
}

const initialProps = await Document.getInitialProps(ctx);
const chunks = await flushChunks();
ctx?.res?.on('finish', () => {
// revalidate().then((shouldUpdate) => {
// if (shouldUpdate) {
// console.log('should HMR', shouldUpdate);
// }
// });
});

return {
...initialProps,
Expand Down
4 changes: 4 additions & 0 deletions apps/3002-checkout/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ import { defineConfig } from 'cypress';
export default defineConfig({
e2e: nxE2EPreset(__filename, { cypressDir: 'cypress' }),
defaultCommandTimeout: 15000,
retries: {
runMode: 2,
openMode: 1,
},
});
2 changes: 1 addition & 1 deletion apps/3002-checkout/cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('3002-checkout/', () => {
cy.request(src).its('status').should('eq', 200);
});
});
xit('should check that shop-webpack-png images are not 404 between route clicks', () => {
it('should check that shop-webpack-png images are not 404 between route clicks', () => {
cy.visit('/shop');
cy.url().should('include', '/shop');
getH1().contains('Shop Page');
Expand Down
7 changes: 4 additions & 3 deletions apps/3002-checkout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"styled-jsx": "5.1.2",
"tapable": "2.2.1",
"terser-webpack-plugin": "5.3.10",
"typescript": "5.3.3",
"upath": "2.0.1",
"url": "0.11.3",
"util": "0.12.5",
"webpack-sources": "3.2.3",
"typescript": "5.3.3"
"webpack-sources": "3.2.3"
},
"devDependencies": {
"@module-federation/nextjs-mf": "workspace:*",
"@module-federation/sdk": "workspace:*",
"@module-federation/runtime": "workspace:*",
"@module-federation/sdk": "workspace:*",
"@module-federation/utilities": "workspace:*"
},
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion apps/3002-checkout/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ function MyApp({ Component, pageProps }) {
}
};
// handle first route hit.
React.useMemo(() => handleRouteChange(asPath), [asPath]);
React.useEffect(() => {
handleRouteChange(asPath);
}, [asPath]);

//handle route change
React.useEffect(() => {
Expand Down
17 changes: 10 additions & 7 deletions apps/3002-checkout/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {

class MyDocument extends Document {
static async getInitialProps(ctx) {
if (ctx.pathname) {
if (!ctx.pathname.endsWith('_error')) {
await revalidate().then((shouldUpdate) => {
if (shouldUpdate) {
console.log('should HMR', shouldUpdate);
}
});
}
}

const initialProps = await Document.getInitialProps(ctx);
const chunks = await flushChunks();
ctx?.res?.on('finish', () => {
revalidate().then((shouldUpdate) => {
if (shouldUpdate) {
console.log('should HMR', shouldUpdate);
}
});
});

return {
...initialProps,
Expand Down
6 changes: 3 additions & 3 deletions apps/modernjs/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"commands": [
{
"command": "cd apps/modernjs; pnpm run dev",
"forwardAllArgs": true
"forwardAllArgs": false
}
]
}
Expand Down Expand Up @@ -61,11 +61,11 @@
"parallel": true,
"commands": [
{
"command": "lsof -i :8080 || nx run modernjs:serve && echo 'done'",
"command": "lsof -i :8080 || nx run modernjs:serve & echo 'done'",
"forwardAllArgs": false
},
{
"command": "sleep 4 && nx run modernjs:e2e",
"command": "sleep 20 && nx run modernjs:e2e",
"forwardAllArgs": true
}
]
Expand Down
10 changes: 3 additions & 7 deletions apps/node-host/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@

import express from 'express';
import * as path from 'path';

import node_local_remote from 'node_local_remote/test';
const remoteMsg = import('node_remote/test').then((m) => {
console.log('\x1b[32m%s\x1b[0m', m.default || m);
return m.default || m;
});
console.log('\x1b[32m%s\x1b[0m', node_local_remote);

const app = express();

app.use('/assets', express.static(path.join(__dirname, 'assets')));

app.get('/api', async (req, res) => {
const localRemoteMsg = import('node_local_remote/test').then((m) => {
console.log('\x1b[32m%s\x1b[0m', m.default || m);
return m.default || m;
});

res.send({
message: 'Welcome to node-host!',
remotes: {
node_remote: await remoteMsg,
node_local_remote: await localRemoteMsg,
node_local_remote,
},
});
});
Expand Down
1 change: 0 additions & 1 deletion apps/node-remote/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = composePlugins(withNx(), (config) => {
exposes: {
'./test': './src/expose.js',
},
experiments: {},
}),
);
return config;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"app:manifest:dev": "nx run-many --target=serve --parallel=5 -p 3008-webpack-host,3009-webpack-provider,3010-rspack-provider,3011-rspack-manifest-provider,3012-rspack-js-entry-provider",
"commitlint": "commitlint --edit",
"prepare": "husky install",
"changeset": "changeset"
"changeset": "changeset",
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:package'"
},
"dependencies": {
"adm-zip": "0.5.10",
Expand All @@ -65,6 +66,7 @@
"unplugin": "1.9.0"
},
"devDependencies": {
"terser-webpack-plugin": "^5.3.10",
"@antora/cli": "3.1.5",
"@antora/lunr-extension": "1.0.0-alpha.8",
"@antora/site-generator": "3.1.7",
Expand Down
6 changes: 5 additions & 1 deletion packages/enhanced/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { readFileSync } from 'fs';
import { readFileSync, rmdirSync, existsSync } from 'fs';
import path from 'path';

// Reading the SWC compilation config and remove the "exclude"
Expand All @@ -8,6 +8,10 @@ const { exclude: _, ...swcJestConfig } = JSON.parse(
readFileSync(`${__dirname}/.swcrc`, 'utf-8'),
);

if (existsSync(__dirname + '/test/js')) {
rmdirSync(__dirname + '/test/js', { recursive: true });
}

// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
if (swcJestConfig.swcrc === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
static deserialize(context: ObjectDeserializerContext): ContainerEntryModule {
const { read } = context;
const obj = new ContainerEntryModule(read(), read(), read(), read());
//@ts-ignore

Check warning on line 82 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
obj.deserialize(context);
return obj;
}
Expand Down Expand Up @@ -119,7 +119,7 @@
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
* @returns {void}
*/
// @ts-ignore typeof webpack/lib !== typeof webpack/types

Check warning on line 122 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
override needBuild(
context: NeedBuildContext,
callback: (
Expand All @@ -138,7 +138,7 @@
* @param {function(WebpackError): void} callback callback function
* @returns {void}
*/
// @ts-ignore typeof webpack/lib !== typeof webpack/types

Check warning on line 141 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
override build(
options: WebpackOptions,
compilation: Compilation,
Expand All @@ -152,7 +152,7 @@
topLevelDeclarations: new Set(['moduleMap', 'get', 'init']),
};
this.buildMeta.exportsType = 'namespace';
//@ts-ignore

Check warning on line 155 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
this.clearDependenciesAndBlocks();

for (const [name, options] of this._exposes) {
Expand All @@ -170,15 +170,15 @@
name,
index: idx++,
};
//@ts-ignore

Check warning on line 173 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
block.addDependency(dep);
}
//@ts-ignore

Check warning on line 176 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
this.addBlock(block);
}
//@ts-ignore

Check warning on line 179 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
this.addDependency(
//@ts-ignore

Check warning on line 181 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
new StaticExportsDependency(
['get', 'init'],
false,
Expand All @@ -186,10 +186,9 @@
);

this.addDependency(
// @ts-ignore

Check warning on line 189 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
new EntryDependency(this._injectRuntimeEntry),
);

callback();
}

Expand All @@ -197,7 +196,7 @@
* @param {CodeGenerationContext} context context for code generation
* @returns {CodeGenerationResult} result
*/
//@ts-ignore

Check warning on line 199 in packages/enhanced/src/lib/container/ContainerEntryModule.ts

View workflow job for this annotation

GitHub Actions / main

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
override codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }) {
const sources = new Map();
const runtimeRequirements = new Set([
Expand Down
Loading
Loading