Skip to content

Commit 5fd59c6

Browse files
authored
feat: deprecate beforeConfig hook (#6703)
1 parent 473b7b8 commit 5fd59c6

File tree

7 files changed

+13
-54
lines changed

7 files changed

+13
-54
lines changed

.changeset/long-cycles-admire.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@modern-js/app-tools': patch
3+
'@modern-js/main-doc': patch
4+
---
5+
6+
feat: deprecate beforeConfig hook
7+
8+
feat: 废弃 beforeConfig Hook

packages/document/main-doc/docs/en/plugin/plugin-system/hook-list.mdx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,6 @@ In this chapter, all available Hooks are listed, and you can use the correspondi
1212

1313
The following are the common CLI Hooks that can be used in both Modern.js Framework and Modern.js Module.
1414

15-
### `beforeConfig`
16-
17-
- Functionality: Running tasks before the config process
18-
- Execution phase: Before the config process
19-
- Hook model: `AsyncWorkflow`
20-
- Type: `AsyncWorkflow<void, void>`
21-
- Example:
22-
23-
```ts
24-
import type { CliPlugin } from '@modern-js/core';
25-
26-
export const myPlugin = (): CliPlugin => ({
27-
setup(api) {
28-
return {
29-
beforeConfig: () => {
30-
// do something
31-
},
32-
};
33-
},
34-
});
35-
```
36-
3715
### `config`
3816

3917
- Functionality: Collect configuration

packages/document/main-doc/docs/zh/plugin/plugin-system/hook-list.mdx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,6 @@ Modern.js 工程体系中包含三类插件:CLI、Runtime、Server,每一类
1212

1313
以下是通用的 CLI Hooks,可以在 Modern.js Framework 以及 Modern.js Module 中使用。
1414

15-
### `beforeConfig`
16-
17-
- 功能:运行收集配置前的任务
18-
- 执行阶段:收集配置前
19-
- Hook 模型:`AsyncWorkflow`
20-
- 类型:`AsyncWorkflow<void, void>`
21-
- 使用示例:
22-
23-
```ts
24-
import type { CliPlugin } from '@modern-js/core';
25-
26-
export const myPlugin = (): CliPlugin => ({
27-
setup(api) {
28-
return {
29-
beforeConfig: () => {
30-
// do something
31-
},
32-
};
33-
},
34-
});
35-
```
36-
3715
### `config`
3816

3917
- 功能:收集配置

packages/solutions/app-tools/src/compat/hooks.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export function getHookRunners(
2828
/**
2929
* app tools hooks
3030
*/
31-
beforeConfig: async () => {
32-
return hooks.onBeforeConfig.call();
33-
},
3431
afterPrepare: async () => {
3532
return hooks.onAfterPrepare.call();
3633
},
@@ -202,7 +199,7 @@ export function handleSetupResult(
202199
const fn = setupResult[key];
203200
if (typeof fn === 'function') {
204201
const newAPI = transformHookRunner(key);
205-
if (api[newAPI]) {
202+
if (newAPI && api[newAPI]) {
206203
api[newAPI](async (...params: any) => {
207204
const { isMultiple, params: transformParams } = transformHookParams(
208205
key,

packages/solutions/app-tools/src/compat/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { getModifyHtmlPartials } from '../plugins/analyze/getHtmlTemplate';
66
export function transformHookRunner(hookRunnerName: string) {
77
switch (hookRunnerName) {
88
case 'beforeConfig':
9-
return 'onBeforeConfig';
9+
console.error(
10+
'The `beforeConfig` hook has been deprecated. Please define your code directly in the setup function instead.',
11+
);
12+
return undefined;
1013
case 'prepare':
1114
return 'onPrepare';
1215
case 'afterPrepare':

packages/solutions/app-tools/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import type { AppTools, AppToolsOptions, CliPluginFuture } from './types';
3131
import type {
3232
AddRuntimeExportsFn,
3333
AfterPrepareFn,
34-
BeforeConfigFn,
3534
BeforeGenerateRoutesFn,
3635
BeforePrintInstructionsFn,
3736
CheckEntryPointFn,
@@ -88,7 +87,6 @@ export const appTools = (
8887
'@modern-js/plugin-polyfill',
8988
],
9089
registryHooks: {
91-
onBeforeConfig: createAsyncHook<BeforeConfigFn>(),
9290
onAfterPrepare: createAsyncHook<AfterPrepareFn>(),
9391
deploy: createAsyncHook<DeplpoyFn>(),
9492
_internalRuntimePlugins: createAsyncHook<InternalRuntimePluginsFn>(),

packages/solutions/app-tools/src/types/new.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
2525
import type { RuntimePlugin } from './hooks';
2626
import type { Bundler } from './utils';
2727

28-
export type BeforeConfigFn = () => Promise<void> | void;
2928
export type AfterPrepareFn = () => Promise<void> | void;
3029
export type InternalRuntimePluginsFn = TransformFunction<{
3130
entrypoint: Entrypoint;
@@ -64,7 +63,6 @@ export type RegisterBuildPlatformFn = () =>
6463
export type AddRuntimeExportsFn = () => Promise<void> | void;
6564

6665
export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
67-
onBeforeConfig: PluginHookTap<BeforeConfigFn>;
6866
onAfterPrepare: PluginHookTap<AfterPrepareFn>;
6967
deploy: PluginHookTap<DeplpoyFn>;
7068

@@ -116,7 +114,6 @@ export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
116114

117115
export interface AppToolsExtendHooks
118116
extends Record<string, PluginHook<(...args: any[]) => any>> {
119-
onBeforeConfig: AsyncHook<BeforeConfigFn>;
120117
onAfterPrepare: AsyncHook<AfterPrepareFn>;
121118
deploy: AsyncHook<DeplpoyFn>;
122119
_internalRuntimePlugins: AsyncHook<InternalRuntimePluginsFn>;

0 commit comments

Comments
 (0)