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

types: fix plugins type mismatch #2875

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 2 deletions e2e/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { URL } from 'node:url';
import type {
CreateRsbuildOptions,
RsbuildConfig,
RsbuildPlugin,
RsbuildPlugins,
} from '@rsbuild/core';
import { pluginSwc } from '@rsbuild/plugin-swc';
Expand Down Expand Up @@ -135,7 +134,7 @@ export async function dev({
plugins,
...options
}: CreateRsbuildOptions & {
plugins?: RsbuildPlugin[];
plugins?: RsbuildPlugins;
}) {
process.env.NODE_ENV = 'development';

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
"vue": "2.x"
},
"overrides": {
"esbuild": "~0.19.0"
"esbuild": "~0.19.0",
"@rsbuild/core": "link:packages/core",
"@rsbuild/plugin-less": "link:packages/plugin-less",
"@rsbuild/plugin-sass": "link:packages/plugin-sass",
"@rsbuild/plugin-react": "link:packages/plugin-react"
}
}
}
4 changes: 2 additions & 2 deletions packages/compat/webpack/tests/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateRsbuildOptions, RsbuildPlugin } from '@rsbuild/core';
import type { CreateRsbuildOptions, RsbuildPlugins } from '@rsbuild/core';
import { createStubRsbuild as createBaseRsbuild } from '@scripts/test-helper';
import { webpackProvider } from '../src/provider';

Expand All @@ -7,7 +7,7 @@ export async function createStubRsbuild({
plugins,
...options
}: CreateRsbuildOptions & {
plugins?: RsbuildPlugin[];
plugins?: RsbuildPlugins;
}) {
rsbuildConfig.provider = webpackProvider;
return createBaseRsbuild({
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ export type RsbuildPlugin = {
remove?: string[];
};

// Support for registering lower version Rsbuild plugins in the new version of
// Rsbuild core without throwing type mismatches. In most cases, Rsbuild core
// only adds new methods or properties to the API object, which means that lower
// version plugins will usually work fine.
type LooseRsbuildPlugin = Omit<RsbuildPlugin, 'setup'> & {
setup: (api: any) => MaybePromise<void>;
};

export type RsbuildPlugins = (
| RsbuildPlugin
| LooseRsbuildPlugin
| Falsy
| Promise<RsbuildPlugin | Falsy>
| Promise<LooseRsbuildPlugin | Falsy>
)[];

export type GetRsbuildConfig = {
Expand Down
Loading
Loading