From 7fd7c6cebfcad34ae7021ebee28f97b1f28ef3f3 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Sat, 2 Dec 2023 14:19:22 +0800 Subject: [PATCH] feat(server): allow disabling built-in shortcuts (#15218) --- packages/vite/src/node/shortcuts.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/shortcuts.ts b/packages/vite/src/node/shortcuts.ts index 9a8dac1c457983..51584c66d48021 100644 --- a/packages/vite/src/node/shortcuts.ts +++ b/packages/vite/src/node/shortcuts.ts @@ -14,6 +14,7 @@ export type BindCLIShortcutsOptions = { /** * Custom shortcuts to run when a key is pressed. These shortcuts take priority * over the default shortcuts if they have the same keys (except the `h` key). + * To disable a default shortcut, define the same key but with `action: undefined`. */ customShortcuts?: CLIShortcut[] } @@ -21,7 +22,7 @@ export type BindCLIShortcutsOptions = { export type CLIShortcut = { key: string description: string - action(server: Server): void | Promise + action?(server: Server): void | Promise } export function bindCLIShortcuts( @@ -66,6 +67,8 @@ export function bindCLIShortcuts( if (loggedKeys.has(shortcut.key)) continue loggedKeys.add(shortcut.key) + if (shortcut.action == null) continue + server.config.logger.info( colors.dim(' press ') + colors.bold(`${shortcut.key} + enter`) + @@ -77,7 +80,7 @@ export function bindCLIShortcuts( } const shortcut = shortcuts.find((shortcut) => shortcut.key === input) - if (!shortcut) return + if (!shortcut || shortcut.action == null) return actionRunning = true await shortcut.action(server)