Skip to content

Commit 56eaf91

Browse files
authored
feat: rename hooks function types and export them (#5144)
1 parent e3f406e commit 56eaf91

File tree

7 files changed

+23
-18
lines changed

7 files changed

+23
-18
lines changed

packages/core/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export type {
135135
PostCSSPlugin,
136136
PreviewOptions,
137137
PreconnectOption,
138+
ProcessAssetsDescriptor,
139+
ProcessAssetsHook,
140+
ProcessAssetsHandler,
138141
ProxyBypass,
139142
ProxyConfig,
140143
ProxyFilter,
@@ -144,6 +147,8 @@ export type {
144147
PublicDirOptions,
145148
ProgressBarConfig,
146149
RequestHandler,
150+
ResolveHook,
151+
ResolveHandler,
147152
ResolvedCreateRsbuildOptions,
148153
RsbuildConfig,
149154
RsbuildContext,
@@ -176,7 +181,7 @@ export type {
176181
TransformContext,
177182
TransformDescriptor,
178183
ToolsConfig,
179-
TransformFn,
184+
TransformHook,
180185
TransformHandler,
181186
TransformImport,
182187
WatchFiles,

packages/core/src/initPlugins.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import type {
1414
NormalizedEnvironmentConfig,
1515
PluginManager,
1616
ProcessAssetsDescriptor,
17-
ProcessAssetsFn,
1817
ProcessAssetsHandler,
18+
ProcessAssetsHook,
1919
ProcessAssetsStage,
20-
ResolveFn,
2120
ResolveHandler,
21+
ResolveHook,
2222
RsbuildPluginAPI,
23-
TransformFn,
2423
TransformHandler,
24+
TransformHook,
2525
} from './types';
2626

2727
export function getHTMLPathByEntry(
@@ -250,7 +250,7 @@ export function initPluginAPI({
250250
chain.plugin(pluginName).use(RsbuildCorePlugin);
251251
});
252252

253-
const getTransformFn: (environment?: string) => TransformFn =
253+
const getTransformHook: (environment?: string) => TransformHook =
254254
(environment) => (descriptor, handler) => {
255255
const id = `rsbuild-transform-${transformId++}`;
256256

@@ -309,12 +309,12 @@ export function initPluginAPI({
309309
});
310310
};
311311

312-
const setProcessAssets: (environment?: string) => ProcessAssetsFn =
312+
const setProcessAssets: (environment?: string) => ProcessAssetsHook =
313313
(environment) => (descriptor, handler) => {
314314
processAssetsFns.push({ environment, descriptor, handler });
315315
};
316316

317-
const setResolve: (environment?: string) => ResolveFn =
317+
const setResolve: (environment?: string) => ResolveHook =
318318
(environment) => (handler) => {
319319
resolveFns.push({ environment, handler });
320320
};
@@ -335,7 +335,7 @@ export function initPluginAPI({
335335
return (environment?: string) => ({
336336
context: publicContext,
337337
expose,
338-
transform: getTransformFn(environment),
338+
transform: getTransformHook(environment),
339339
useExposed,
340340
processAssets: setProcessAssets(environment),
341341
resolve: setResolve(environment),

packages/core/src/types/plugin.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export type TransformDescriptor = {
373373
with?: Record<string, Rspack.RuleSetCondition>;
374374
};
375375

376-
export type TransformFn = (
376+
export type TransformHook = (
377377
descriptor: TransformDescriptor,
378378
handler: TransformHandler,
379379
) => void;
@@ -450,9 +450,9 @@ export type ResolveHandler = (context: {
450450
compilation: Rspack.Compilation;
451451
}) => Promise<void> | void;
452452

453-
export type ResolveFn = (handler: ResolveHandler) => void;
453+
export type ResolveHook = (handler: ResolveHandler) => void;
454454

455-
export type ProcessAssetsFn = (
455+
export type ProcessAssetsHook = (
456456
descriptor: ProcessAssetsDescriptor,
457457
handler: ProcessAssetsHandler,
458458
) => void;
@@ -607,19 +607,19 @@ export type RsbuildPluginAPI = Readonly<{
607607
* Modify assets before emitting, the same as Rspack's
608608
* [compilation.hooks.processAssets](https://rspack.dev/api/plugin-api/compilation-hooks#processassets) hook.
609609
*/
610-
processAssets: ProcessAssetsFn;
610+
processAssets: ProcessAssetsHook;
611611
/**
612612
* Intercept and modify module request information before module resolution begins.
613613
* The same as Rspack's [normalModuleFactory.hooks.resolve](https://rspack.dev/api/plugin-api/normal-module-factory-hooks#resolve) hook.
614614
*/
615-
resolve: ResolveFn;
615+
resolve: ResolveHook;
616616
/**
617617
* A simplified wrapper around Rspack loaders, `api.transform` lets you
618618
* easily transform the code of specific modules during the build process.
619619
* You can match files by module path, query, or other conditions, and
620620
* apply custom transformations to their contents.
621621
*/
622-
transform: TransformFn;
622+
transform: TransformHook;
623623
/**
624624
* Get the properties or methods exposed by other plugins.
625625
*/

website/docs/en/api/javascript-api/types.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ const rspackConfig: Rspack.Configuration = {};
164164
- ModifyRsbuildConfigFn
165165
- ModifyBundlerChainFn
166166
- ModifyRspackConfigFn
167-
- TransformFn,
167+
- TransformHook,
168168
- TransformHandler
169169
- more...

website/docs/en/plugins/dev/core.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ Intercept and modify module request information before module resolution begins.
346346
- **Type:**
347347

348348
```ts
349-
function ResolveFn(handler: ResolveHandler): void;
349+
function ResolveHook(handler: ResolveHandler): void;
350350
```
351351

352352
### Example

website/docs/zh/api/javascript-api/types.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ const rspackConfig: Rspack.Configuration = {};
164164
- ModifyRsbuildConfigFn
165165
- ModifyBundlerChainFn
166166
- ModifyRspackConfigFn
167-
- TransformFn,
167+
- TransformHook,
168168
- TransformHandler
169169
- more...

website/docs/zh/plugins/dev/core.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ api.transform(
344344
- **类型:**
345345

346346
```ts
347-
function ResolveFn(handler: ResolveHandler): void;
347+
function ResolveHook(handler: ResolveHandler): void;
348348
```
349349

350350
### 示例

0 commit comments

Comments
 (0)