From 9354f85e799509a945cc52f5fbdd9d1d6e87b371 Mon Sep 17 00:00:00 2001 From: ryu <114303361+ryuapp@users.noreply.github.com> Date: Sun, 28 Sep 2025 22:26:16 +0900 Subject: [PATCH] fix(cli): avoid including Deno API when using `deno bundle` --- cli/_prompt_select.ts | 4 ++-- cli/prompt_secret.ts | 15 +++++++-------- cli/unstable_prompt_multiple_select.ts | 4 +--- cli/unstable_prompt_select.ts | 4 +--- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cli/_prompt_select.ts b/cli/_prompt_select.ts index 0fc000f79c57..8090f0753b07 100644 --- a/cli/_prompt_select.ts +++ b/cli/_prompt_select.ts @@ -7,8 +7,6 @@ const SAFE_PADDING = 4; const MORE_CONTENT_BEFORE_INDICATOR = "..."; const MORE_CONTENT_AFTER_INDICATOR = "..."; -const input = Deno.stdin; -const output = Deno.stdout; const encoder = new TextEncoder(); const decoder = new TextDecoder(); @@ -40,6 +38,8 @@ export function handlePromptSelect( inputStr(): void; }) => boolean | "return", ) { + const input = Deno.stdin; + const output = Deno.stdout; const indexedValues = values.map((value, absoluteIndex) => ({ value, absoluteIndex, diff --git a/cli/prompt_secret.ts b/cli/prompt_secret.ts index d16df7f309d3..2e69bedfdd5d 100644 --- a/cli/prompt_secret.ts +++ b/cli/prompt_secret.ts @@ -1,7 +1,6 @@ // Copyright 2018-2025 the Deno authors. MIT license. -const input = Deno.stdin; -const output = Deno.stdout; +import { isWindows } from "@std/internal/os"; const encoder = new TextEncoder(); const decoder = new TextDecoder(); const LF = "\n".charCodeAt(0); // ^J - Enter on Linux @@ -12,9 +11,7 @@ const CLR = encoder.encode("\r\u001b[K"); // Clear the current line const MOVE_LINE_UP = encoder.encode("\r\u001b[1F"); // Move to previous line // The `cbreak` option is not supported on Windows -const setRawOptions = Deno.build.os === "windows" - ? undefined - : { cbreak: true }; +const setRawOptions = isWindows ? undefined : { cbreak: true }; /** Options for {@linkcode promptSecret}. */ export type PromptSecretOptions = { @@ -47,6 +44,8 @@ export function promptSecret( message = "Secret", options?: PromptSecretOptions, ): string | null { + const input = Deno.stdin; + const output = Deno.stdout; const { mask = "*", clear } = options ?? {}; if (!input.isTerminal()) { @@ -90,7 +89,7 @@ export function promptSecret( output.writeSync(encoder.encode(message)); - Deno.stdin.setRaw(true, setRawOptions); + input.setRaw(true, setRawOptions); try { return readLineFromStdinSync(callback); } finally { @@ -99,7 +98,7 @@ export function promptSecret( } else { output.writeSync(encoder.encode("\n")); } - Deno.stdin.setRaw(false); + input.setRaw(false); } } @@ -112,7 +111,7 @@ function readLineFromStdinSync(callback?: (n: number) => void): string { const buf = []; while (true) { - const n = input.readSync(c); + const n = Deno.stdin.readSync(c); if (n === null || n === 0) { break; } diff --git a/cli/unstable_prompt_multiple_select.ts b/cli/unstable_prompt_multiple_select.ts index 31ba291e135a..159884b03ab5 100644 --- a/cli/unstable_prompt_multiple_select.ts +++ b/cli/unstable_prompt_multiple_select.ts @@ -45,8 +45,6 @@ const DELETE = "\u007F"; const CHECKED = "◉"; const UNCHECKED = "◯"; -const input = Deno.stdin; - /** * Shows the given message and waits for the user's input. Returns the user's selected value as string. * @@ -105,7 +103,7 @@ export function promptMultipleSelect( values: PromptEntry[], options: PromptMultipleSelectOptions = {}, ): PromptEntry[] | null { - if (!input.isTerminal()) return null; + if (!Deno.stdin.isTerminal()) return null; const selectedAbsoluteIndexes = new Set(); diff --git a/cli/unstable_prompt_select.ts b/cli/unstable_prompt_select.ts index 2e954c217b44..590a247344c1 100644 --- a/cli/unstable_prompt_select.ts +++ b/cli/unstable_prompt_select.ts @@ -41,8 +41,6 @@ const ARROW_DOWN = "\u001B[B"; const CR = "\r"; const DELETE = "\u007F"; -const input = Deno.stdin; - /** * Shows the given message and waits for the user's input. Returns the user's selected value as string. * @@ -104,7 +102,7 @@ export function promptSelect( values: PromptEntry[], options: PromptSelectOptions = {}, ): PromptEntry | null { - if (!input.isTerminal()) return null; + if (!Deno.stdin.isTerminal()) return null; let selectedIndex = 0;