mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat: print Listening on
messages on stderr instead of stdout (#25491)
Fixes https://github.com/denoland/deno/issues/25114 --------- Signed-off-by: Leo Kettmeir <crowlkats@toaxl.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: crowlkats <crowlkats@toaxl.com> Co-authored-by: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com>
This commit is contained in:
parent
af2d992ecd
commit
597f2d8d4d
6 changed files with 30 additions and 44 deletions
|
@ -646,7 +646,7 @@ function serve(arg1, arg2) {
|
|||
options.onListen(listener.addr);
|
||||
} else {
|
||||
// deno-lint-ignore no-console
|
||||
console.log(`Listening on ${path}`);
|
||||
console.error(`Listening on ${path}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -695,7 +695,7 @@ function serve(arg1, arg2) {
|
|||
const host = formatHostName(addr.hostname);
|
||||
|
||||
// deno-lint-ignore no-console
|
||||
console.log(`Listening on ${scheme}${host}:${addr.port}/`);
|
||||
console.error(`Listening on ${scheme}${host}:${addr.port}/`);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -871,7 +871,7 @@ function registerDeclarativeServer(exports) {
|
|||
const host = formatHostName(hostname);
|
||||
|
||||
// deno-lint-ignore no-console
|
||||
console.debug(
|
||||
console.error(
|
||||
`%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`,
|
||||
"color: green",
|
||||
"color: inherit",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// Remove Intl.v8BreakIterator because it is a non-standard API.
|
||||
delete Intl.v8BreakIterator;
|
||||
|
||||
import * as internalConsole from "ext:deno_console/01_console.js";
|
||||
import { core, internals, primordials } from "ext:core/mod.js";
|
||||
const ops = core.ops;
|
||||
import {
|
||||
|
@ -578,36 +579,19 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
|||
|
||||
if (mode === executionModes.serve) {
|
||||
if (serveIsMain && serveWorkerCount) {
|
||||
// deno-lint-ignore no-console
|
||||
const origLog = console.log;
|
||||
// deno-lint-ignore no-console
|
||||
const origError = console.error;
|
||||
const prefix = `[serve-worker-0 ]`;
|
||||
// deno-lint-ignore no-console
|
||||
console.log = (...args) => {
|
||||
return origLog(prefix, ...new primordials.SafeArrayIterator(args));
|
||||
};
|
||||
// deno-lint-ignore no-console
|
||||
console.error = (...args) => {
|
||||
return origError(prefix, ...new primordials.SafeArrayIterator(args));
|
||||
};
|
||||
// deno-lint-ignore no-global-assign
|
||||
console = new internalConsole.Console((msg, level) =>
|
||||
core.print("[serve-worker-0 ] " + msg, level > 1)
|
||||
);
|
||||
} else if (serveWorkerCount !== null) {
|
||||
// deno-lint-ignore no-console
|
||||
const origLog = console.log;
|
||||
// deno-lint-ignore no-console
|
||||
const origError = console.error;
|
||||
const base = `serve-worker-${serveWorkerCount + 1}`;
|
||||
// 15 = "serve-worker-nn".length, assuming
|
||||
// serveWorkerCount < 100
|
||||
const prefix = `[${StringPrototypePadEnd(base, 15, " ")}]`;
|
||||
// deno-lint-ignore no-console
|
||||
console.log = (...args) => {
|
||||
return origLog(prefix, ...new primordials.SafeArrayIterator(args));
|
||||
};
|
||||
// deno-lint-ignore no-console
|
||||
console.error = (...args) => {
|
||||
return origError(prefix, ...new primordials.SafeArrayIterator(args));
|
||||
};
|
||||
// deno-lint-ignore no-global-assign
|
||||
console = new internalConsole.Console((msg, level) =>
|
||||
core.print(`${prefix} ` + msg, level > 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,11 +61,13 @@ impl ServeClientBuilder {
|
|||
fn new() -> Self {
|
||||
Self(
|
||||
util::deno_cmd()
|
||||
.env("NO_COLOR", "1")
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("serve")
|
||||
.arg("--port")
|
||||
.arg("0")
|
||||
.stdout_piped(),
|
||||
.stdout_piped()
|
||||
.stderr_piped(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
@ -106,12 +108,12 @@ impl ServeClient {
|
|||
fn output(self) -> String {
|
||||
let mut child = self.child.borrow_mut();
|
||||
child.kill().unwrap();
|
||||
let mut stdout = child.stdout.take().unwrap();
|
||||
let mut stderr = child.stderr.take().unwrap();
|
||||
child.wait().unwrap();
|
||||
|
||||
let mut output_buf = self.output_buf.borrow_mut();
|
||||
|
||||
stdout.read_to_end(&mut output_buf).unwrap();
|
||||
stderr.read_to_end(&mut output_buf).unwrap();
|
||||
|
||||
String::from_utf8(std::mem::take(&mut *output_buf)).unwrap()
|
||||
}
|
||||
|
@ -128,7 +130,7 @@ impl ServeClient {
|
|||
let mut buffer = self.output_buf.borrow_mut();
|
||||
let mut temp_buf = [0u8; 64];
|
||||
let mut child = self.child.borrow_mut();
|
||||
let stdout = child.stdout.as_mut().unwrap();
|
||||
let stderr = child.stderr.as_mut().unwrap();
|
||||
let port_regex = regex::bytes::Regex::new(r":(\d+)").unwrap();
|
||||
|
||||
let start = std::time::Instant::now();
|
||||
|
@ -141,7 +143,7 @@ impl ServeClient {
|
|||
String::from_utf8_lossy(&buffer)
|
||||
);
|
||||
}
|
||||
let read = stdout.read(&mut temp_buf).unwrap();
|
||||
let read = stderr.read(&mut temp_buf).unwrap();
|
||||
buffer.extend_from_slice(&temp_buf[..read]);
|
||||
if let Some(p) = port_regex
|
||||
.captures(&buffer)
|
||||
|
|
|
@ -1359,16 +1359,16 @@ async fn test_watch_serve() {
|
|||
.piped_output()
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
||||
let (mut _stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
||||
|
||||
wait_contains("Listening on", &mut stdout_lines).await;
|
||||
wait_contains("Listening on", &mut stderr_lines).await;
|
||||
// Note that we start serving very quickly, so we specifically want to wait for this message
|
||||
wait_contains(r#"Watching paths: [""#, &mut stderr_lines).await;
|
||||
|
||||
file_to_watch.write(file_content);
|
||||
|
||||
wait_contains("serving", &mut stderr_lines).await;
|
||||
wait_contains("Listening on", &mut stdout_lines).await;
|
||||
wait_contains("Listening on", &mut stderr_lines).await;
|
||||
|
||||
check_alive_then_kill(child);
|
||||
}
|
||||
|
|
4
tests/testdata/serve/parallel.ts
vendored
4
tests/testdata/serve/parallel.ts
vendored
|
@ -1,7 +1,7 @@
|
|||
console.log("starting serve");
|
||||
console.error("starting serve");
|
||||
export default {
|
||||
fetch(_req: Request) {
|
||||
console.log("serving request");
|
||||
console.error("serving request");
|
||||
return new Response("deno serve parallel");
|
||||
},
|
||||
};
|
||||
|
|
|
@ -792,8 +792,8 @@ Deno.test(
|
|||
async function httpServerDefaultOnListenCallback() {
|
||||
const ac = new AbortController();
|
||||
|
||||
const consoleLog = console.log;
|
||||
console.log = (msg) => {
|
||||
const consoleError = console.error;
|
||||
console.error = (msg) => {
|
||||
try {
|
||||
const match = msg.match(
|
||||
/Listening on http:\/\/(localhost|0\.0\.0\.0):(\d+)\//,
|
||||
|
@ -818,7 +818,7 @@ Deno.test(
|
|||
|
||||
await server.finished;
|
||||
} finally {
|
||||
console.log = consoleLog;
|
||||
console.error = consoleError;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -875,8 +875,8 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
|
|||
const ac = new AbortController();
|
||||
let url = "";
|
||||
|
||||
const consoleLog = console.log;
|
||||
console.log = (msg) => {
|
||||
const consoleError = console.error;
|
||||
console.error = (msg) => {
|
||||
try {
|
||||
const match = msg.match(/Listening on (http:\/\/(.*?):(\d+)\/)/);
|
||||
assert(!!match, `Didn't match ${msg}`);
|
||||
|
@ -897,7 +897,7 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
|
|||
assert(new URL(url), `Not a valid URL "${url}"`);
|
||||
await server.shutdown();
|
||||
} finally {
|
||||
console.log = consoleLog;
|
||||
console.error = consoleError;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue