Skip to content

Commit

Permalink
feat: move modifyServerRoutes hook to plugin v2
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Feb 7, 2025
1 parent 38cc78b commit be25cfb
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .changeset/rotten-numbers-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@modern-js/app-tools': patch
'@modern-js/plugin-v2': patch
---

feat: move modifyServerRoutes hook to plugin v2

feat: 将 modifyServerRoutes 钩子函数移动到 plugin v2 中
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 @@ -39,7 +39,6 @@ import type {
GenerateEntryCodeFn,
ModifyEntrypointsFn,
ModifyFileSystemRoutesFn,
ModifyServerRoutesFn,
RegisterBuildPlatformFn,
RegisterDevFn,
} from './types/new';
Expand Down Expand Up @@ -91,7 +90,6 @@ export const appTools = (
checkEntryPoint: createAsyncHook<CheckEntryPointFn>(),
modifyEntrypoints: createAsyncHook<ModifyEntrypointsFn>(),
modifyFileSystemRoutes: createAsyncHook<ModifyFileSystemRoutesFn>(),
modifyServerRoutes: createAsyncHook<ModifyServerRoutesFn>(),
generateEntryCode: createAsyncHook<GenerateEntryCodeFn>(),
onBeforeGenerateRoutes: createAsyncHook<BeforeGenerateRoutesFn>(),
onBeforePrintInstructions: createAsyncHook<BeforePrintInstructionsFn>(),
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 @@ -36,7 +36,6 @@ export type ModifyFileSystemRoutesFn = TransformFunction<{
entrypoint: Entrypoint;
routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
}>;
export type ModifyServerRoutesFn = TransformFunction<{ routes: ServerRoute[] }>;
export type DeplpoyFn = () => Promise<void> | void;
export type GenerateEntryCodeFn = (params: {
entrypoints: Entrypoint[];
Expand All @@ -61,7 +60,6 @@ export interface AppToolsExtendAPI<B extends Bundler = 'webpack'> {
checkEntryPoint: PluginHookTap<CheckEntryPointFn>;
modifyEntrypoints: PluginHookTap<ModifyEntrypointsFn>;
modifyFileSystemRoutes: PluginHookTap<ModifyFileSystemRoutesFn>;
modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;

generateEntryCode: PluginHookTap<GenerateEntryCodeFn>;
onBeforeGenerateRoutes: PluginHookTap<BeforeGenerateRoutesFn>;
Expand Down Expand Up @@ -109,7 +107,6 @@ export interface AppToolsExtendHooks
checkEntryPoint: AsyncHook<CheckEntryPointFn>;
modifyEntrypoints: AsyncHook<ModifyEntrypointsFn>;
modifyFileSystemRoutes: AsyncHook<ModifyFileSystemRoutesFn>;
modifyServerRoutes: AsyncHook<ModifyServerRoutesFn>;
generateEntryCode: AsyncHook<GenerateEntryCodeFn>;
onBeforeGenerateRoutes: AsyncHook<BeforeGenerateRoutesFn>;
/**
Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/plugin-v2/src/cli/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { merge } from '@modern-js/utils/lodash';
import { modifyBundlerChain } from '@rsbuild/core/dist-types/configChain';
import type { PluginHook } from '../types';
import type {
AllKeysForCLIPluginExtendsAPI,
Expand Down Expand Up @@ -116,6 +117,7 @@ export function initPluginAPI<Extends extends CLIPluginExtends>({
onBeforeExit: hooks.onBeforeExit.tap,
_internalRuntimePlugins: hooks._internalRuntimePlugins.tap,
_internalServerPlugins: hooks._internalServerPlugins.tap,
modifyServerRoutes: hooks.modifyServerRoutes.tap,
...extendsPluginApi,
};

Expand Down
3 changes: 3 additions & 0 deletions packages/toolkit/plugin-v2/src/cli/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
ModifyResolvedConfigFn,
ModifyRsbuildConfigFn,
ModifyRspackConfigFn,
ModifyServerRoutesFn,
ModifyWebpackChainFn,
ModifyWebpackConfigFn,
OnAfterDeployFn,
Expand Down Expand Up @@ -60,6 +61,7 @@ export type {
OnPrepareFn,
InternalRuntimePluginsFn,
InternalServerPluginsFn,
ModifyServerRoutesFn,
RuntimePluginConfig,
ServerPluginConfig,
};
Expand Down Expand Up @@ -118,6 +120,7 @@ export function initHooks<
onBeforeExit: createAsyncHook<OnBeforeExitFn>(),
_internalRuntimePlugins: createAsyncHook<InternalRuntimePluginsFn>(),
_internalServerPlugins: createAsyncHook<InternalServerPluginsFn>(),
modifyServerRoutes: createAsyncHook<ModifyServerRoutesFn>(),
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/toolkit/plugin-v2/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export {
type OnPrepareFn,
type InternalRuntimePluginsFn,
type InternalServerPluginsFn,
type ModifyServerRoutesFn,
type RuntimePluginConfig,
type ServerPluginConfig,
} from './hooks';
Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/plugin-v2/src/types/cli/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
ModifyResolvedConfigFn,
ModifyRsbuildConfigFn,
ModifyRspackConfigFn,
ModifyServerRoutesFn,
ModifyWebpackChainFn,
ModifyWebpackConfigFn,
OnAfterDeployFn,
Expand Down Expand Up @@ -110,6 +111,7 @@ export type CLIPluginAPI<Extends extends CLIPluginExtends> = Readonly<
onBeforeExit: PluginHookTap<OnBeforeExitFn>;
_internalRuntimePlugins: PluginHookTap<InternalRuntimePluginsFn>;
_internalServerPlugins: PluginHookTap<InternalServerPluginsFn>;
modifyServerRoutes: PluginHookTap<ModifyServerRoutesFn>;
} & CLIPluginExtendsAPI<Extends>
>;

Expand Down
6 changes: 5 additions & 1 deletion packages/toolkit/plugin-v2/src/types/cli/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { ServerPlugin as ServerPluginConfig } from '@modern-js/types';
import type {
ServerPlugin as ServerPluginConfig,
ServerRoute,
} from '@modern-js/types';
import type { WebpackConfig } from '@modern-js/uni-builder';
import type { Command } from '@modern-js/utils/commander';
import type {
Expand Down Expand Up @@ -125,3 +128,4 @@ export type InternalRuntimePluginsFn = TransformFunction<{
export type InternalServerPluginsFn = TransformFunction<{
plugins: ServerPluginConfig[];
}>;
export type ModifyServerRoutesFn = TransformFunction<{ routes: ServerRoute[] }>;

0 comments on commit be25cfb

Please sign in to comment.