diff --git a/.changeset/red-sloths-happen.md b/.changeset/red-sloths-happen.md new file mode 100644 index 000000000000..0dabe2d952c9 --- /dev/null +++ b/.changeset/red-sloths-happen.md @@ -0,0 +1,6 @@ +--- +'@modern-js/app-tools': patch +'@modern-js/plugin-v2': patch +--- + +fix: addWatchFiles hook not work diff --git a/packages/solutions/app-tools/src/new/compat/hooks.ts b/packages/solutions/app-tools/src/new/compat/hooks.ts index 63598030c027..398d1d0bd7d4 100644 --- a/packages/solutions/app-tools/src/new/compat/hooks.ts +++ b/packages/solutions/app-tools/src/new/compat/hooks.ts @@ -108,7 +108,7 @@ export function getHookRunners( prepare: async () => { return hooks.onPrepare.call(); }, - filedChange: async (params: { + fileChange: async (params: { filename: string; eventType: 'add' | 'change' | 'unlink'; isPrivate: boolean; diff --git a/packages/solutions/app-tools/src/new/compat/utils.ts b/packages/solutions/app-tools/src/new/compat/utils.ts index 6a2d46f25c60..6e5879013dfc 100644 --- a/packages/solutions/app-tools/src/new/compat/utils.ts +++ b/packages/solutions/app-tools/src/new/compat/utils.ts @@ -19,7 +19,7 @@ export function transformHookRunner(hookRunnerName: string) { return 'addCommand'; case 'watchFiles': return 'addWatchFiles'; - case 'filedChange': + case 'fileChange': return 'onFileChanged'; case 'beforeCreateCompiler': return 'onBeforeCreateCompiler'; diff --git a/packages/solutions/app-tools/src/utils/restart.ts b/packages/solutions/app-tools/src/utils/restart.ts index 93d583867679..747936e240ff 100644 --- a/packages/solutions/app-tools/src/utils/restart.ts +++ b/packages/solutions/app-tools/src/utils/restart.ts @@ -1,12 +1,7 @@ import type { ToRunners } from '@modern-js/core'; import { cli } from '@modern-js/plugin-v2/cli'; -import { - chalk, - clearConsole, - getFullArgv, - logger, - program, -} from '@modern-js/utils'; +import { chalk, clearConsole, getFullArgv, logger } from '@modern-js/utils'; +import { program } from '@modern-js/utils/commander'; import type { AppToolsHooks } from '../types/hooks'; export async function restart( diff --git a/packages/toolkit/plugin-v2/src/cli/api.ts b/packages/toolkit/plugin-v2/src/cli/api.ts index 510b4df2a9ad..79922afdf652 100644 --- a/packages/toolkit/plugin-v2/src/cli/api.ts +++ b/packages/toolkit/plugin-v2/src/cli/api.ts @@ -95,7 +95,7 @@ export function initPluginAPI({ addCommand: hooks.addCommand.tap, onPrepare: hooks.onPrepare.tap, - onWatchFiles: hooks.addWatchFiles.tap, + addWatchFiles: hooks.addWatchFiles.tap, onFileChanged: hooks.onFileChanged.tap, onBeforeRestart: hooks.onBeforeRestart.tap, onBeforeCreateCompiler: hooks.onBeforeCreateCompiler.tap, diff --git a/packages/toolkit/plugin-v2/src/types/cli/api.ts b/packages/toolkit/plugin-v2/src/types/cli/api.ts index c3eedf22e3e0..b860843505a1 100644 --- a/packages/toolkit/plugin-v2/src/types/cli/api.ts +++ b/packages/toolkit/plugin-v2/src/types/cli/api.ts @@ -66,7 +66,7 @@ export type CLIPluginAPI = Readonly<{ addCommand: PluginHookTap; onPrepare: PluginHookTap; - onWatchFiles: PluginHookTap; + addWatchFiles: PluginHookTap; onFileChanged: PluginHookTap; onBeforeRestart: PluginHookTap; onBeforeCreateCompiler: PluginHookTap;