summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2023-11-15 14:10:12 +0900
committerGitHub <noreply@github.com>2023-11-15 14:10:12 +0900
commitc67de43ff3221ae5554398095261d684b6d41dda (patch)
tree7ffe8fddeb575b3203787745845ab99acb883cff
parent4913274a6508a5e5ad6c8babf2e90a4a84bf98ec (diff)
fix(runtime): fix Deno.noColor when stdout is not tty (#21208)
-rw-r--r--cli/tests/unit/tty_color_test.ts11
-rw-r--r--runtime/js/99_main.js6
-rw-r--r--runtime/ops/bootstrap.rs9
3 files changed, 22 insertions, 4 deletions
diff --git a/cli/tests/unit/tty_color_test.ts b/cli/tests/unit/tty_color_test.ts
index 747d92dcc..3adc16b23 100644
--- a/cli/tests/unit/tty_color_test.ts
+++ b/cli/tests/unit/tty_color_test.ts
@@ -13,3 +13,14 @@ Deno.test(
assertEquals(output, "1\n");
},
);
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function denoNoColorIsNotAffectedByNonTty() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(Deno.noColor)"],
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "false\n");
+ },
+);
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 06a7d605d..76a279bbd 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -241,7 +241,7 @@ function opMainModule() {
const opArgs = memoizeLazy(() => ops.op_bootstrap_args());
const opPid = memoizeLazy(() => ops.op_bootstrap_pid());
const opPpid = memoizeLazy(() => ops.op_ppid());
-setNoColorFn(() => ops.op_bootstrap_no_color());
+setNoColorFn(() => ops.op_bootstrap_no_color() || !ops.op_bootstrap_is_tty());
function formatException(error) {
if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, error)) {
@@ -530,7 +530,7 @@ function bootstrapMainRuntime(runtimeOptions) {
ObjectDefineProperties(finalDenoNs, {
pid: util.getterOnly(opPid),
ppid: util.getterOnly(opPpid),
- noColor: util.getterOnly(getNoColor),
+ noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
args: util.getterOnly(opArgs),
mainModule: util.getterOnly(opMainModule),
});
@@ -666,7 +666,7 @@ function bootstrapWorkerRuntime(
}
ObjectDefineProperties(finalDenoNs, {
pid: util.getterOnly(opPid),
- noColor: util.getterOnly(getNoColor),
+ noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
args: util.getterOnly(opArgs),
});
// Setup `Deno` global - we're actually overriding already
diff --git a/runtime/ops/bootstrap.rs b/runtime/ops/bootstrap.rs
index 1b86a7509..72e31a1d6 100644
--- a/runtime/ops/bootstrap.rs
+++ b/runtime/ops/bootstrap.rs
@@ -15,6 +15,7 @@ deno_core::extension!(
op_bootstrap_language,
op_bootstrap_log_level,
op_bootstrap_no_color,
+ op_bootstrap_is_tty,
],
);
@@ -57,5 +58,11 @@ pub fn op_bootstrap_log_level(state: &mut OpState) -> i32 {
#[op2(fast)]
pub fn op_bootstrap_no_color(state: &mut OpState) -> bool {
let options = state.borrow::<BootstrapOptions>();
- options.no_color || !options.is_tty
+ options.no_color
+}
+
+#[op2(fast)]
+pub fn op_bootstrap_is_tty(state: &mut OpState) -> bool {
+ let options = state.borrow::<BootstrapOptions>();
+ options.is_tty
}