Skip to content

Commit

Permalink
fix: type error when registering Rsbuild plugins (#6018)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jul 30, 2024
1 parent ce9c43a commit f19b9dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-mails-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-js/app-tools': patch
---

fix: type error when registering Rsbuild plugins
1 change: 1 addition & 0 deletions packages/cli/uni-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type {
export type {
UniBuilderConfig,
UniBuilderPlugin,
LooseRsbuildPlugin,
BundlerType,
MetaOptions,
Stats,
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/uni-builder/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
RequestHandler,
NodeEnv,
HtmlTagDescriptor,
RsbuildPlugin,
} from '@rsbuild/core';
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
Expand Down Expand Up @@ -368,7 +369,7 @@ export type SriOptions = {

export type OverridesUniBuilderInstance = {
addPlugins: (
plugins: UniBuilderPlugin[],
plugins: Array<UniBuilderPlugin | LooseRsbuildPlugin>,
options?: {
before?: string;
},
Expand Down Expand Up @@ -419,6 +420,11 @@ export type UniBuilderPlugin = {
remove?: string[];
};

// Support for registering any version Rsbuild plugins
export type LooseRsbuildPlugin = Omit<RsbuildPlugin, 'setup'> & {
setup: (api: any) => Promise<void> | void;
};

export type DistPath = DistPathConfig & {
server?: string;
worker?: string;
Expand Down
7 changes: 5 additions & 2 deletions packages/solutions/app-tools/src/types/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { ServerUserConfig, BffUserConfig } from '@modern-js/server-core';
import type { UniBuilderPlugin } from '@modern-js/uni-builder';
import type {
UniBuilderPlugin,
LooseRsbuildPlugin,
} from '@modern-js/uni-builder';
import type { RsbuildConfig } from '@rsbuild/core';
import type { Bundler } from '../utils';
import type { OutputUserConfig } from './output';
Expand Down Expand Up @@ -41,7 +44,7 @@ export interface AppToolsUserConfig<B extends Bundler> {
tools?: ToolsUserConfig<B>;
security?: SecurityUserConfig;
testing?: TestingUserConfig;
builderPlugins?: UniBuilderPlugin[];
builderPlugins?: Array<LooseRsbuildPlugin | UniBuilderPlugin>;
performance?: PerformanceUserConfig;
devtools?: any;
environments?: RsbuildConfig['environments'];
Expand Down

0 comments on commit f19b9dc

Please sign in to comment.