Skip to content

Commit b58b295

Browse files
authored
fix(cli): improve Node compatibility by removing top-level Deno API usage (#6837)
1 parent aea9257 commit b58b295

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

cli/_prompt_select.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const SAFE_PADDING = 4;
77
const MORE_CONTENT_BEFORE_INDICATOR = "...";
88
const MORE_CONTENT_AFTER_INDICATOR = "...";
99

10-
const input = Deno.stdin;
11-
const output = Deno.stdout;
1210
const encoder = new TextEncoder();
1311
const decoder = new TextDecoder();
1412

@@ -40,6 +38,8 @@ export function handlePromptSelect<V>(
4038
inputStr(): void;
4139
}) => boolean | "return",
4240
) {
41+
const input = Deno.stdin;
42+
const output = Deno.stdout;
4343
const indexedValues = values.map((value, absoluteIndex) => ({
4444
value,
4545
absoluteIndex,

cli/prompt_secret.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

3-
const input = Deno.stdin;
4-
const output = Deno.stdout;
3+
import { isWindows } from "@std/internal/os";
54
const encoder = new TextEncoder();
65
const decoder = new TextDecoder();
76
const LF = "\n".charCodeAt(0); // ^J - Enter on Linux
@@ -12,9 +11,7 @@ const CLR = encoder.encode("\r\u001b[K"); // Clear the current line
1211
const MOVE_LINE_UP = encoder.encode("\r\u001b[1F"); // Move to previous line
1312

1413
// The `cbreak` option is not supported on Windows
15-
const setRawOptions = Deno.build.os === "windows"
16-
? undefined
17-
: { cbreak: true };
14+
const setRawOptions = isWindows ? undefined : { cbreak: true };
1815

1916
/** Options for {@linkcode promptSecret}. */
2017
export type PromptSecretOptions = {
@@ -47,6 +44,8 @@ export function promptSecret(
4744
message = "Secret",
4845
options?: PromptSecretOptions,
4946
): string | null {
47+
const input = Deno.stdin;
48+
const output = Deno.stdout;
5049
const { mask = "*", clear } = options ?? {};
5150

5251
if (!input.isTerminal()) {
@@ -90,7 +89,7 @@ export function promptSecret(
9089

9190
output.writeSync(encoder.encode(message));
9291

93-
Deno.stdin.setRaw(true, setRawOptions);
92+
input.setRaw(true, setRawOptions);
9493
try {
9594
return readLineFromStdinSync(callback);
9695
} finally {
@@ -99,7 +98,7 @@ export function promptSecret(
9998
} else {
10099
output.writeSync(encoder.encode("\n"));
101100
}
102-
Deno.stdin.setRaw(false);
101+
input.setRaw(false);
103102
}
104103
}
105104

@@ -112,7 +111,7 @@ function readLineFromStdinSync(callback?: (n: number) => void): string {
112111
const buf = [];
113112

114113
while (true) {
115-
const n = input.readSync(c);
114+
const n = Deno.stdin.readSync(c);
116115
if (n === null || n === 0) {
117116
break;
118117
}

cli/unstable_prompt_multiple_select.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const DELETE = "\u007F";
4545
const CHECKED = "◉";
4646
const UNCHECKED = "◯";
4747

48-
const input = Deno.stdin;
49-
5048
/**
5149
* Shows the given message and waits for the user's input. Returns the user's selected value as string.
5250
*
@@ -105,7 +103,7 @@ export function promptMultipleSelect<V = undefined>(
105103
values: PromptEntry<V>[],
106104
options: PromptMultipleSelectOptions = {},
107105
): PromptEntry<V>[] | null {
108-
if (!input.isTerminal()) return null;
106+
if (!Deno.stdin.isTerminal()) return null;
109107

110108
const selectedAbsoluteIndexes = new Set<number>();
111109

cli/unstable_prompt_select.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const ARROW_DOWN = "\u001B[B";
4141
const CR = "\r";
4242
const DELETE = "\u007F";
4343

44-
const input = Deno.stdin;
45-
4644
/**
4745
* Shows the given message and waits for the user's input. Returns the user's selected value as string.
4846
*
@@ -104,7 +102,7 @@ export function promptSelect<V = undefined>(
104102
values: PromptEntry<V>[],
105103
options: PromptSelectOptions = {},
106104
): PromptEntry<V> | null {
107-
if (!input.isTerminal()) return null;
105+
if (!Deno.stdin.isTerminal()) return null;
108106

109107
let selectedIndex = 0;
110108

0 commit comments

Comments
 (0)