Skip to content

feat: implement rslib with TypeScript declaration generation #3883

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"diffEditor.wordWrap": "on",
"editor.rename.enablePreview": false,
"nxConsole.generateAiAgentRules": true
"nxConsole.generateAiAgentRules": true,
"eslint.validate": ["json"]
}
2 changes: 1 addition & 1 deletion apps/rslib-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@module-federation/rsbuild-plugin": "workspace:*",
"@module-federation/storybook-addon": "workspace:*",
"@rsbuild/plugin-react": "^1.0.6",
"@rslib/core": "0.2.0",
"@rslib/core": "0.10.4",
"@types/react": "^18.3.11",
"http-server": "^14.1.1",
"react": "^18.3.1",
Expand Down
54 changes: 48 additions & 6 deletions apps/rslib-module/project.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
{
"name": "rslib-module",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/rslib-module/src",
"sourceRoot": "apps/rslib-module/src",
"projectType": "library",
"tags": ["type:app"],
"targets": {
"build": {
"executor": "nx:run-commands",
"executor": "../../tools/rslib-plugin:build",
"outputs": ["{projectRoot}/dist"],
"options": {
"commands": ["npm run build --prefix apps/rslib-module"]
"configFile": "rslib.config.ts",
"mode": "production"
},
"configurations": {
"development": {
"mode": "development"
},
"watch": {
"watch": true
}
}
},
"dev": {
"executor": "../../tools/rslib-plugin:dev",
"options": {
"configFile": "rslib.config.ts",
"mode": "mf-dev",
"port": 3001,
"open": false
},
"dependsOn": [
{
"target": "build",
"dependencies": true
}
]
},
"serve": {
"executor": "nx:run-commands",
"options": {
Expand All @@ -23,10 +48,11 @@
}
]
},
"dev": {
"executor": "nx:run-commands",
"build-watch": {
"executor": "../../tools/rslib-plugin:dev",
"options": {
"commands": ["npm run dev --prefix apps/rslib-module"]
"configFile": "rslib.config.ts",
"mode": "watch"
},
"dependsOn": [
{
Expand All @@ -35,6 +61,22 @@
}
]
},
"test": {
"executor": "../../tools/rslib-plugin:build",
"options": {
"configFile": "rslib.config.ts",
"mode": "development",
"verbose": true
}
},
"test:watch": {
"executor": "../../tools/rslib-plugin:build",
"options": {
"configFile": "rslib.config.ts",
"mode": "development",
"watch": true
}
},
"storybook": {
"executor": "nx:run-commands",
"options": {
Expand Down
31 changes: 23 additions & 8 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"cache": true
},
"lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/.eslintignore",
"{workspaceRoot}/eslint.config.js"
],
"cache": true
},
"test": {
Expand Down Expand Up @@ -48,23 +53,30 @@
},
"@module-federation/3002-checkout:build:production": {
"cache": false
},
"@nx/js:tsc": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["production", "^production"]
},
"@nx/vite:test": {
"cache": true,
"inputs": ["default", "^production"]
}
},
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"production": [
"default",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/vitest.config.[jt]s",
"!{projectRoot}/.storybook/**/*",
"!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)",
"!{projectRoot}/src/test-setup.[jt]s",
"!{projectRoot}/tsconfig.storybook.json"
"!{projectRoot}/test-setup.[jt]s",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/eslint.config.js"
],
"sharedGlobals": ["{workspaceRoot}/babel.config.json"]
"sharedGlobals": []
},
"workspaceLayout": {
"appsDir": "apps",
Expand Down Expand Up @@ -106,5 +118,8 @@
},
"useInferencePlugins": false,
"defaultBase": "main",
"nxCloudAccessToken": "NTVlZTRhOWItMGRjYy00YmJjLTllNzAtNDFkNzRhNzdjZDkwfHJlYWQtd3JpdGU="
"nxCloudAccessToken": "NTVlZTRhOWItMGRjYy00YmJjLTllNzAtNDFkNzRhNzdjZDkwfHJlYWQtd3JpdGU=",
"cli": {
"tui": false
}
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"@nx/module-federation": "21.0.3",
"@nx/next": "21.0.3",
"@nx/node": "21.0.3",
"@nx/plugin": "21.0.3",
"@nx/react": "21.0.3",
"@nx/rollup": "21.0.3",
"@nx/rspack": "21.0.3",
Expand All @@ -127,6 +128,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
"@rollup/plugin-alias": "5.1.1",
"@rollup/plugin-replace": "6.0.1",
"@rslib/core": "^0.10.4",
"@rspack/core": "1.3.9",
"@rspack/dev-server": "1.1.1",
"@semantic-release/changelog": "^6.0.3",
Expand Down Expand Up @@ -198,6 +200,8 @@
"jest-environment-node": "29.7.0",
"jiti": "2.4.2",
"js-yaml": "4.1.0",
"jsdom": "~22.1.0",
"jsonc-eslint-parser": "^2.1.0",
"kill-port": "^2.0.1",
"mime-types": "2.1.35",
"msw": "^1.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/bridge/vue3-bridge/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"src/remoteApp.tsx",
"src/create.ts"
],
"exclude": ["../../runtime-core/dist/**/*"],
"references": [{ "path": "./tsconfig.node.json" }]
}
3 changes: 2 additions & 1 deletion packages/chrome-devtools/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"types": ["chrome"]
},
"include": ["src", "shared", "modern.config.ts"]
"include": ["src", "shared", "modern.config.ts"],
"exclude": ["../runtime-core/dist/**/*"]
}
3 changes: 2 additions & 1 deletion packages/chrome-devtools/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./tsconfig.base.json",
"include": ["src", "stories"]
"include": ["src", "stories"],
"exclude": ["../runtime-core/dist/**/*"]
}
6 changes: 6 additions & 0 deletions packages/error-codes/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
}
]
}
},
"echo": {
"executor": "../../tools/rslib-plugin:echo",
"options": {
"textToEcho": "Hello World"
}
}
}
}
27 changes: 14 additions & 13 deletions packages/runtime-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.14.0",
"type": "module",
"author": "zhouxiao <codingzx@gmail.com>",
"main": "./dist/index.cjs.cjs",
"module": "./dist/index.esm.js",
"types": "./dist/index.cjs.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -17,37 +17,38 @@
},
"files": [
"dist/",
"src/",
"README.md"
],
"exports": {
".": {
"import": {
"types": "./dist/index.esm.d.ts",
"default": "./dist/index.esm.js"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.cjs.d.ts",
"default": "./dist/index.cjs.cjs"
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
}
},
"./types": {
"import": {
"types": "./dist/types.esm.d.ts",
"default": "./dist/types.esm.js"
"types": "./dist/types.d.ts",
"default": "./dist/types.js"
},
"require": {
"types": "./dist/types.cjs.d.ts",
"default": "./dist/types.cjs.cjs"
"types": "./dist/types.d.ts",
"default": "./dist/types.cjs"
}
}
},
"typesVersions": {
"*": {
".": [
"./dist/index.cjs.d.ts"
"./dist/index.d.ts"
],
"types": [
"./dist/types.cjs.d.ts"
"./dist/types.d.ts"
]
}
},
Expand Down
30 changes: 30 additions & 0 deletions packages/runtime-core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
"tags": ["type:pkg"],
"targets": {
"build": {
"executor": "../../tools/rslib-plugin:build",
"outputs": ["{workspaceRoot}/packages/runtime-core/dist"],
"options": {
"configFile": "rslib.config.ts",
"outputPath": "packages/runtime-core/dist",
"mode": "production",
"verbose": true
},
"dependsOn": [
{
"target": "build",
"dependencies": true
}
]
},
"build:rollup": {
"executor": "@nx/rollup:rollup",
"outputs": ["{workspaceRoot}/packages/runtime-core/dist"],
"options": {
Expand Down Expand Up @@ -78,6 +94,20 @@
}
]
}
},
"test:rslib": {
"executor": "nx:run-commands",
"options": {
"command": "rslib build --mode development",
"cwd": "packages/runtime-core"
}
},
"test:watch": {
"executor": "nx:run-commands",
"options": {
"command": "rslib build --mode development --watch",
"cwd": "packages/runtime-core"
}
}
}
}
45 changes: 45 additions & 0 deletions packages/runtime-core/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { defineConfig } from '@rslib/core';
import pkg from './package.json';

const FEDERATION_DEBUG = process.env.FEDERATION_DEBUG || '';

export default defineConfig({
source: {
entry: {
index: './src/index.ts',
types: './src/types.ts',
helpers: './src/helpers.ts',
core: './src/core.ts',
global: './src/global.ts',
},
define: {
__VERSION__: JSON.stringify(pkg.version),
FEDERATION_DEBUG: JSON.stringify(FEDERATION_DEBUG),
FEDERATION_ALLOW_NEW_FUNCTION: JSON.stringify(
process.env.FEDERATION_ALLOW_NEW_FUNCTION || false,
),
},
tsconfigPath: './tsconfig.lib.json',
},
output: {
target: 'node',
format: ['esm', 'cjs'],
distPath: {
root: './dist',
},
},
lib: [
{
format: 'esm',
dts: {
bundle: false,
distPath: './dist',
},
},
{
format: 'cjs',
},
],
bundle: false,
external: ['@module-federation/sdk', '@module-federation/error-codes'],
});
9 changes: 8 additions & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ export {
getGlobalSnapshot,
getInfoWithoutType,
} from './global';
export type { UserOptions, FederationRuntimePlugin } from './type';
export type {
UserOptions,
FederationRuntimePlugin,
Shared,
Remote,
RemoteEntryInitOptions,
SharedConfig,
} from './type';
export { assert } from './utils/logger';
export { registerGlobalPlugins } from './global';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getResourceUrl,
isBrowserEnv,
} from '@module-federation/sdk';

import {
EntryAssets,
FederationRuntimePlugin,
Expand Down
Loading
Loading