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

feat: deprecate beforeConfig hook #6703

Merged
merged 2 commits into from
Jan 7, 2025
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
8 changes: 8 additions & 0 deletions .changeset/long-cycles-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@modern-js/app-tools': patch
'@modern-js/main-doc': patch
---

feat: deprecate beforeConfig hook

feat: 废弃 beforeConfig Hook
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,6 @@ In this chapter, all available Hooks are listed, and you can use the correspondi

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

### `beforeConfig`

- Functionality: Running tasks before the config process
- Execution phase: Before the config process
- Hook model: `AsyncWorkflow`
- Type: `AsyncWorkflow<void, void>`
- Example:

```ts
import type { CliPlugin } from '@modern-js/core';

export const myPlugin = (): CliPlugin => ({
setup(api) {
return {
beforeConfig: () => {
// do something
},
};
},
});
```

### `config`

- Functionality: Collect configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,6 @@ Modern.js 工程体系中包含三类插件:CLI、Runtime、Server,每一类

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

### `beforeConfig`

- 功能:运行收集配置前的任务
- 执行阶段:收集配置前
- Hook 模型:`AsyncWorkflow`
- 类型:`AsyncWorkflow<void, void>`
- 使用示例:

```ts
import type { CliPlugin } from '@modern-js/core';

export const myPlugin = (): CliPlugin => ({
setup(api) {
return {
beforeConfig: () => {
// do something
},
};
},
});
```

### `config`

- 功能:收集配置
Expand Down
5 changes: 1 addition & 4 deletions packages/solutions/app-tools/src/compat/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export function getHookRunners(
/**
* app tools hooks
*/
beforeConfig: async () => {
return hooks.onBeforeConfig.call();
},
afterPrepare: async () => {
return hooks.onAfterPrepare.call();
},
Expand Down Expand Up @@ -202,7 +199,7 @@ export function handleSetupResult(
const fn = setupResult[key];
if (typeof fn === 'function') {
const newAPI = transformHookRunner(key);
if (api[newAPI]) {
if (newAPI && api[newAPI]) {
api[newAPI](async (...params: any) => {
const { isMultiple, params: transformParams } = transformHookParams(
key,
Expand Down
5 changes: 4 additions & 1 deletion packages/solutions/app-tools/src/compat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { getModifyHtmlPartials } from '../plugins/analyze/getHtmlTemplate';
export function transformHookRunner(hookRunnerName: string) {
switch (hookRunnerName) {
case 'beforeConfig':
return 'onBeforeConfig';
console.error(
'The `beforeConfig` hook has been deprecated. Please define your code directly in the setup function instead.',
);
return undefined;
case 'prepare':
return 'onPrepare';
case 'afterPrepare':
Expand Down
2 changes: 0 additions & 2 deletions packages/solutions/app-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import type { AppTools, AppToolsOptions, CliPluginFuture } from './types';
import type {
AddRuntimeExportsFn,
AfterPrepareFn,
BeforeConfigFn,
BeforeGenerateRoutesFn,
BeforePrintInstructionsFn,
CheckEntryPointFn,
Expand Down Expand Up @@ -88,7 +87,6 @@ export const appTools = (
'@modern-js/plugin-polyfill',
],
registryHooks: {
onBeforeConfig: createAsyncHook<BeforeConfigFn>(),
onAfterPrepare: createAsyncHook<AfterPrepareFn>(),
deploy: createAsyncHook<DeplpoyFn>(),
_internalRuntimePlugins: createAsyncHook<InternalRuntimePluginsFn>(),
Expand Down
3 changes: 0 additions & 3 deletions packages/solutions/app-tools/src/types/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import type { AppToolsNormalizedConfig, AppToolsUserConfig } from './config';
import type { RuntimePlugin } from './hooks';
import type { Bundler } from './utils';

export type BeforeConfigFn = () => Promise<void> | void;
export type AfterPrepareFn = () => Promise<void> | void;
export type InternalRuntimePluginsFn = TransformFunction<{
entrypoint: Entrypoint;
Expand Down Expand Up @@ -64,7 +63,6 @@ export type RegisterBuildPlatformFn = () =>
export type AddRuntimeExportsFn = () => Promise<void> | void;

export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
onBeforeConfig: PluginHookTap<BeforeConfigFn>;
onAfterPrepare: PluginHookTap<AfterPrepareFn>;
deploy: PluginHookTap<DeplpoyFn>;

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

export interface AppToolsExtendHooks
extends Record<string, PluginHook<(...args: any[]) => any>> {
onBeforeConfig: AsyncHook<BeforeConfigFn>;
onAfterPrepare: AsyncHook<AfterPrepareFn>;
deploy: AsyncHook<DeplpoyFn>;
_internalRuntimePlugins: AsyncHook<InternalRuntimePluginsFn>;
Expand Down
Loading