Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/node/polyfills/internal/util/inspect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,14 @@ function styleText(format, text, options) {
stream,
);
}
// Node's util.styleText returns the text unchanged when the target stream
// is not a TTY, so callers can pass any writable and only get color when
// the destination would render it.
if (
stream !== undefined && stream !== null && !stream.isTTY
) {
return text;
}
}

const formatArray = ArrayIsArray(format) ? format : [format];
Expand Down
3 changes: 2 additions & 1 deletion libs/npm_installer/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ fn peer_dep_diagnostics_to_display_tree(
// now output it
let mut root_node = DisplayTreeNode {
text: format!(
"{} The following peer dependency issues were found:",
"{} The following peer dependency issues were found.\n\
To resolve, pin the affected package(s) under \"overrides\" in your package.json (https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides):",
colors::yellow("Warning")
),
children: Vec::new(),
Expand Down
3 changes: 2 additions & 1 deletion tests/specs/install/peer_dep_specific_constraint/install.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Download http://localhost:4260/@denotest%2fadd
Download http://localhost:4260/@denotest%2fpeer-dep-specific-constraint
Warning The following peer dependency issues were found:
Warning The following peer dependency issues were found.
To resolve, pin the affected package(s) under "overrides" in your package.json (https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides):
└─┬ @denotest/peer-dep-specific-constraint@1.0.0
└── peer @denotest/add@0.5: resolved to 1.0.0

Expand Down
25 changes: 25 additions & 0 deletions tests/unit_node/util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,31 @@ Deno.test("[util] styleText() with array of formats", () => {
assertEquals(colored, "\x1b[31m\x1b[32merror\x1b[39m\x1b[39m");
});

Deno.test("[util] styleText() respects stream.isTTY", () => {
const streamTTY = { write() {}, isTTY: true };
const streamNoTTY = { write() {}, isTTY: false };

assertEquals(
util.styleText("bgYellow", "TTY", { stream: streamTTY }),
"\x1b[43mTTY\x1b[49m",
);
assertEquals(
util.styleText("bgYellow", "No TTY", { stream: streamNoTTY }),
"No TTY",
);
});

Deno.test("[util] styleText() with validateStream: false bypasses isTTY check", () => {
const streamNoTTY = { write() {}, isTTY: false };
assertEquals(
util.styleText("bgYellow", "forced", {
stream: streamNoTTY,
validateStream: false,
}),
"\x1b[43mforced\x1b[49m",
);
});

Deno.test("[util] stripVTControlCharacters() removes OSC 8 hyperlinks", () => {
// OSC 8 hyperlink with ESC \ (ST) terminator
const input =
Expand Down