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

feat: enhance type capabilities #2185

Merged
merged 63 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5b8ad94
feat: add dev server
2heal1 Mar 11, 2024
17c50a3
chore: sink native-federation-typescript capability into dts-kit
2heal1 Mar 13, 2024
3ad737b
feat: add rpc call
2heal1 Mar 13, 2024
fa505f9
feat: support re-export remote types & generate/consume api types
2heal1 Mar 18, 2024
c6c9e9a
fix(dts-kit): correct context
2heal1 Mar 18, 2024
bbb7579
feat: add basic usage example(no live type reload)
2heal1 Mar 19, 2024
31afbaf
feat: add dev kit
2heal1 Mar 20, 2024
60b089d
chore: update native-federation-typescript test cases
2heal1 Mar 20, 2024
fce9073
chore: test hot types reload
2heal1 Mar 20, 2024
e4ec576
chore: support js entry hot types reload
2heal1 Mar 21, 2024
44734b4
feat: support consume manifest types field
2heal1 Mar 21, 2024
bc0dc23
fix: ignore compiler types
2heal1 Mar 21, 2024
c27fd7a
fix: unit test
2heal1 Mar 21, 2024
9a1d0ae
chore: solve merge conflict
2heal1 Mar 21, 2024
c0a7ec6
chore: update version
2heal1 Mar 21, 2024
04b02ed
chore: update snapshot
2heal1 Mar 21, 2024
1b879d6
chore: add default value
2heal1 Mar 21, 2024
c140fe7
chore: use constant
2heal1 Mar 21, 2024
d435dfa
chore: update manifest/snapshot
2heal1 Mar 22, 2024
22ed25d
chore: no deep clone
2heal1 Mar 22, 2024
8b97cd8
chore: update schema
2heal1 Mar 24, 2024
19a2375
chore: support extra options
2heal1 Mar 24, 2024
548092b
chore: remove UnSerializationOptions
2heal1 Mar 24, 2024
64002cc
chore: fix unit test
2heal1 Mar 24, 2024
2c7eba1
chore: correct live reload path
2heal1 Mar 24, 2024
25e9904
chore: only register type plugin once
2heal1 Mar 24, 2024
42a483b
chore: increase timeout
2heal1 Mar 24, 2024
1afbcdf
chore: only register type plugin once
2heal1 Mar 24, 2024
a231711
chore: prevent function duplicate call
2heal1 Mar 25, 2024
6ea7b0f
fix: fetch existed manifest
2heal1 Mar 25, 2024
c2d92b6
fix: use implemantation constructor
2heal1 Mar 25, 2024
690d32f
fix: fix some errors
2heal1 Mar 25, 2024
c430e6c
chore: export constant
2heal1 Mar 25, 2024
b1f4b29
chore: infer project type
2heal1 Mar 26, 2024
b7b8ef9
feat: add disableConsumeTypes option
2heal1 Mar 26, 2024
6d6f3b4
fix: params error
2heal1 Mar 26, 2024
efe89eb
chore: dev plugin should load first
2heal1 Mar 26, 2024
71976ea
chore: update readme & add test cases
2heal1 Mar 27, 2024
1b48ba6
chore: add ts demo script
2heal1 Mar 27, 2024
76ada81
chore: solve merge conflict
2heal1 Mar 27, 2024
5ebdda2
fix: lint error
2heal1 Mar 27, 2024
52b55a8
fix: natifve federation typescript error
2heal1 Mar 27, 2024
4f5d14b
feat: support extract third party dts
2heal1 Mar 27, 2024
30b28f7
chore: remove test variable
2heal1 Mar 28, 2024
0d9a6c9
chore: add test & changeset
2heal1 Mar 28, 2024
136dd76
fix: lint error
2heal1 Mar 28, 2024
300151c
Merge branch 'main' into feat/dev-server
2heal1 Mar 29, 2024
4b5ed2d
fix: cr
2heal1 Apr 1, 2024
335bd2a
fix: native-federation-typescript test
2heal1 Apr 1, 2024
30c1538
chore: nextjs project can not enable dts by default
2heal1 Apr 1, 2024
fdb9cf8
fix: enable dts in browser by default
2heal1 Apr 1, 2024
70443a3
chore: update changeset
2heal1 Apr 1, 2024
ae03ef5
chore: update changeset
2heal1 Apr 1, 2024
b2bab31
fix: apply compiler
2heal1 Apr 1, 2024
d42cc56
chore: reduce pkgs
2heal1 Apr 1, 2024
975047c
chore: ignore typescript pkg
2heal1 Apr 1, 2024
1b5105c
fix: style lint
2heal1 Apr 1, 2024
b857737
chore: add timeout
2heal1 Apr 2, 2024
1cf1ada
chore: add timeout
2heal1 Apr 2, 2024
34260fd
chore: update types field
2heal1 Apr 2, 2024
8cbea6d
fix(manifest): build error
2heal1 Apr 2, 2024
a9660e6
chore: rm dist after test
2heal1 Apr 2, 2024
6a253fb
Merge branch 'main' into feat/dev-server
zhoushaw Apr 2, 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
8 changes: 7 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
"@module-federation/sdk",
"@module-federation/runtime-tools",
"@module-federation/managers",
"@module-federation/manifest"
"@module-federation/manifest",
"@module-federation/dev-server",
"@module-federation/dev-kit",
"@module-federation/dev-plugin",
"@module-federation/dts-kit",
"@module-federation/third-party-dts-extractor",
"@module-federation/native-federation-typescript"
]
],
"ignorePatterns": ["^alpha|^beta"],
Expand Down
14 changes: 14 additions & 0 deletions .changeset/late-mice-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@module-federation/native-federation-typescript': patch
'@module-federation/third-party-dts-extractor': patch
'@module-federation/enhanced-rspack': patch
'@module-federation/dev-plugin': patch
'@module-federation/dev-server': patch
'@module-federation/enhanced': patch
'@module-federation/manifest': patch
'@module-federation/dev-kit': patch
'@module-federation/dts-kit': patch
'@module-federation/sdk': patch
---

feat: enhance type capability
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ apps/**/dist
!packages/enhanced/test/configCases/**/**/node_modules
packages/enhanced/test/js
.ignored
/.mf
4 changes: 3 additions & 1 deletion apps/3000-home/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const nextConfig = {
},
webpack(config, options) {
const { isServer } = options;

config.watchOptions = {
ignored: ['**/node_modules/**', '**/@mf-types/**'],
};
// used for testing build output snapshots
const remotes = {
checkout: `checkout@http://localhost:3002/_next/static/${
Expand Down
4 changes: 3 additions & 1 deletion apps/3001-shop/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const nextConfig = {
},
webpack(config, options) {
const { isServer } = options;

config.watchOptions = {
ignored: ['**/node_modules/**', '**/@mf-types/**'],
};
config.plugins.push(
new NextFederationPlugin({
name: 'shop',
Expand Down
3 changes: 3 additions & 0 deletions apps/3002-checkout/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const nextConfig = {
},
webpack(config, options) {
const { isServer } = options;
config.watchOptions = {
ignored: ['**/node_modules/**', '**/@mf-types/**'],
};
config.plugins.push(
new NextFederationPlugin({
name: 'checkout',
Expand Down
24 changes: 24 additions & 0 deletions apps/react-ts-host/@mf-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type {
PackageType as PackageType_0,
RemoteKeys as RemoteKeys_0,
} from './react_ts_nested_remote/apis.d.ts';
declare module '@module-federation/runtime' {
type RemoteKeys = RemoteKeys_0;
type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y;
export function loadRemote<T extends RemoteKeys, Y>(
packageName: T,
): Promise<PackageType<T, Y>>;
export function loadRemote<T extends string, Y>(
packageName: T,
): Promise<PackageType<T, Y>>;
}
declare module '@module-federation/runtime-tools' {
type RemoteKeys = RemoteKeys_0;
type PackageType<T, Y = any> = T extends RemoteKeys_0 ? PackageType_0<T> : Y;
export function loadRemote<T extends RemoteKeys, Y>(
packageName: T,
): Promise<PackageType<T, Y>>;
export function loadRemote<T extends string, Y>(
packageName: T,
): Promise<PackageType<T, Y>>;
}
2 changes: 0 additions & 2 deletions apps/react-ts-host/@mf-types/react-ts-remote/Module.d.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './compiled-types/nx-welcome';
export { default } from './compiled-types/nx-welcome';
8 changes: 8 additions & 0 deletions apps/react-ts-host/@mf-types/react_ts_nested_remote/apis.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type RemoteKeys =
| 'react_ts_nested_remote/Module'
| 'react_ts_nested_remote/utils';
type PackageType<T> = T extends 'react_ts_nested_remote/utils'
? typeof import('react_ts_nested_remote/utils')
: T extends 'react_ts_nested_remote/Module'
? typeof import('react_ts_nested_remote/Module')
: any;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import RemoteModule from 'react_ts_remote/Module';
export default RemoteModule;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function add(a: number, b: number, c: number): number;
export declare function sub(a: number, b: number, c: number): number;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './compiled-types/utils';
export { default } from './compiled-types/utils';
2 changes: 0 additions & 2 deletions apps/react-ts-host/@mf-types/react_ts_remote/Module.d.ts

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions apps/react-ts-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.0",
"private": true,
"devDependencies": {
"@module-federation/core": "workspace:*",
"@module-federation/typescript": "workspace:*",
"@module-federation/enhanced": "workspace:*",
"@module-federation/core": "workspace:*",
"@module-federation/runtime": "workspace:*",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11",
"react-refresh": "0.14.0"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/react-ts-host/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "swc",
"compiler": "babel",
"outputPath": "apps/react-ts-host/dist",
"index": "apps/react-ts-host/src/index.html",
"baseHref": "/",
Expand Down
1 change: 0 additions & 1 deletion apps/react-ts-host/remotes.d.ts

This file was deleted.

16 changes: 12 additions & 4 deletions apps/react-ts-host/src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as React from 'react';
import NxWelcome from './nx-welcome';
import { Link, Route, Routes } from 'react-router-dom';
import { loadRemote } from '@module-federation/runtime';
import useDynamicModule from './useDynamicRemote';

const ReactTsRemote = React.lazy(() => import('react_ts_remote/Module'));
const ReactTsRemote = React.lazy(() => import('react_ts_nested_remote/Module'));

loadRemote('react_ts_nested_remote/utils').then((utils) => {
console.log(utils.add(1, 2, 3) + utils.sub(1, 2, 3));
});

const DynamicReactTsRemote = React.lazy(() =>
useDynamicModule({
name: 'react_ts_remote',
url: 'http://localhost:3004/remoteEntry.js',
name: 'react_ts_nested_remote',
url: 'http://localhost:3005/remoteEntry.js',
modulePath: './Module',
}),
);
Expand All @@ -29,7 +34,10 @@ export function App() {
</ul>
<Routes>
<Route path="/" element={<NxWelcome title="react-ts-host" />} />
<Route path="/react-ts-remote" element={<ReactTsRemote />} />
<Route
path="/react-ts-remote"
element={<ReactTsRemote title="xxx" />}
/>
<Route
path="/dynamic-react-ts-remote"
element={
Expand Down
26 changes: 5 additions & 21 deletions apps/react-ts-host/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "../../dist/out-tsc",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
"paths": {
"*": ["./@mf-types/*"]
}
},
"files": [
"../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../node_modules/@nx/react/typings/image.d.ts"
],
"exclude": [
"jest.config.ts",
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx"
],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
"exclude": ["dist/**"]
}
11 changes: 6 additions & 5 deletions apps/react-ts-host/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "./",
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
Expand All @@ -10,8 +10,9 @@
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": ["./remotes.d.ts"]
"noFallthroughCasesInSwitch": true,
"paths": {
"*": ["./@mf-types/*"]
}
}
}
64 changes: 8 additions & 56 deletions apps/react-ts-host/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
const { registerPluginTSTranspiler } = require('nx/src/utils/nx-plugin.js');

registerPluginTSTranspiler();
const { withModuleFederation } = require('@nx/react/module-federation');
const { FederatedTypesPlugin } = require('@module-federation/typescript');
const { ModuleFederationPlugin } = require('@module-federation/enhanced');
const { composePlugins, withNx } = require('@nx/webpack');
const { withReact } = require('@nx/react');
process.env.FEDERATION_DEBUG = true;

module.exports = composePlugins(
withNx(),
withReact(),
async (config, context) => {
// prevent cyclic updates
config.watchOptions = {
ignored: ['**/node_modules/**', '**/@mf-types/**'],
};
const baseConfig = {
name: 'react_ts_host',
filename: 'remoteEntry.js',
remotes: {
react_ts_remote: 'react_ts_remote@http://localhost:3004/remoteEntry.js',
react_ts_nested_remote:
// 'react_ts_nested_remote@http://localhost:3005/remoteEntry.js',
'react_ts_nested_remote@http://localhost:3005/mf-manifest.json',
},
};
config.plugins.push(new ModuleFederationPlugin(baseConfig));

config.plugins.push(
new FederatedTypesPlugin({
federationConfig: {
...baseConfig,
filename: 'remoteEntry.js',
},
}),
);

config.optimization.runtimeChunk = false;
config.plugins.forEach((p) => {
if (p.constructor.name === 'ModuleFederationPlugin') {
Expand All @@ -50,50 +46,6 @@ module.exports = composePlugins(
runtimeChunk: false,
minimize: false,
};
// const mf = await withModuleFederation(defaultConfig);
return config;

// const mf = await withModuleFederation(defaultConfig);

// /** @type {import('webpack').Configuration} */
// const parsedConfig = mf(config, context);

// const remotes = baseConfig.remotes.reduce((remotes, remote) => {
// const [name, url] = remote;
// remotes[name] = url;
// return remotes;
// }, {});

// parsedConfig.plugins.forEach((plugin) => {
// if (plugin.constructor.name === 'ModuleFederationPlugin') {
// //Temporary workaround - https://github.com/nrwl/nx/issues/16983
// plugin._options.library = undefined;
// }
// });

// parsedConfig.plugins.push(
// new FederatedTypesPlugin({
// federationConfig: {
// ...baseConfig,
// filename: 'remoteEntry.js',
// remotes,
// },
// }),
// );

// parsedConfig.infrastructureLogging = {
// level: 'verbose',
// colors: true,
// };

// //Temporary workaround - https://github.com/nrwl/nx/issues/16983
// parsedConfig.experiments = { outputModule: false };

// parsedConfig.output = {
// ...parsedConfig.output,
// scriptType: 'text/javascript',
// };

// return parsedConfig;
},
);
11 changes: 11 additions & 0 deletions apps/react-ts-nested-remote/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
16 changes: 16 additions & 0 deletions apps/react-ts-nested-remote/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used by:
# 1. autoprefixer to adjust CSS to support the below specified browsers
# 2. babel preset-env to adjust included polyfills
#
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
#
# If you need to support different browsers in production, you may tweak the list below.

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major version
last 2 iOS major versions
Firefox ESR
not IE 9-11 # For IE 9-11 support, remove 'not'.
18 changes: 18 additions & 0 deletions apps/react-ts-nested-remote/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "node_modules/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Loading
Loading