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);
|
options.onListen(listener.addr);
|
||||||
} else {
|
} else {
|
||||||
// deno-lint-ignore no-console
|
// 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);
|
const host = formatHostName(addr.hostname);
|
||||||
|
|
||||||
// deno-lint-ignore no-console
|
// 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);
|
const host = formatHostName(hostname);
|
||||||
|
|
||||||
// deno-lint-ignore no-console
|
// deno-lint-ignore no-console
|
||||||
console.debug(
|
console.error(
|
||||||
`%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`,
|
`%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`,
|
||||||
"color: green",
|
"color: green",
|
||||||
"color: inherit",
|
"color: inherit",
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// Remove Intl.v8BreakIterator because it is a non-standard API.
|
// Remove Intl.v8BreakIterator because it is a non-standard API.
|
||||||
delete Intl.v8BreakIterator;
|
delete Intl.v8BreakIterator;
|
||||||
|
|
||||||
|
import * as internalConsole from "ext:deno_console/01_console.js";
|
||||||
import { core, internals, primordials } from "ext:core/mod.js";
|
import { core, internals, primordials } from "ext:core/mod.js";
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
import {
|
import {
|
||||||
|
@ -578,36 +579,19 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
||||||
|
|
||||||
if (mode === executionModes.serve) {
|
if (mode === executionModes.serve) {
|
||||||
if (serveIsMain && serveWorkerCount) {
|
if (serveIsMain && serveWorkerCount) {
|
||||||
// deno-lint-ignore no-console
|
// deno-lint-ignore no-global-assign
|
||||||
const origLog = console.log;
|
console = new internalConsole.Console((msg, level) =>
|
||||||
// deno-lint-ignore no-console
|
core.print("[serve-worker-0 ] " + msg, level > 1)
|
||||||
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));
|
|
||||||
};
|
|
||||||
} else if (serveWorkerCount !== null) {
|
} 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}`;
|
const base = `serve-worker-${serveWorkerCount + 1}`;
|
||||||
// 15 = "serve-worker-nn".length, assuming
|
// 15 = "serve-worker-nn".length, assuming
|
||||||
// serveWorkerCount < 100
|
// serveWorkerCount < 100
|
||||||
const prefix = `[${StringPrototypePadEnd(base, 15, " ")}]`;
|
const prefix = `[${StringPrototypePadEnd(base, 15, " ")}]`;
|
||||||
// deno-lint-ignore no-console
|
// deno-lint-ignore no-global-assign
|
||||||
console.log = (...args) => {
|
console = new internalConsole.Console((msg, level) =>
|
||||||
return origLog(prefix, ...new primordials.SafeArrayIterator(args));
|
core.print(`${prefix} ` + msg, level > 1)
|
||||||
};
|
);
|
||||||
// deno-lint-ignore no-console
|
|
||||||
console.error = (...args) => {
|
|
||||||
return origError(prefix, ...new primordials.SafeArrayIterator(args));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,13 @@ impl ServeClientBuilder {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self(
|
Self(
|
||||||
util::deno_cmd()
|
util::deno_cmd()
|
||||||
|
.env("NO_COLOR", "1")
|
||||||
.current_dir(util::testdata_path())
|
.current_dir(util::testdata_path())
|
||||||
.arg("serve")
|
.arg("serve")
|
||||||
.arg("--port")
|
.arg("--port")
|
||||||
.arg("0")
|
.arg("0")
|
||||||
.stdout_piped(),
|
.stdout_piped()
|
||||||
|
.stderr_piped(),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -106,12 +108,12 @@ impl ServeClient {
|
||||||
fn output(self) -> String {
|
fn output(self) -> String {
|
||||||
let mut child = self.child.borrow_mut();
|
let mut child = self.child.borrow_mut();
|
||||||
child.kill().unwrap();
|
child.kill().unwrap();
|
||||||
let mut stdout = child.stdout.take().unwrap();
|
let mut stderr = child.stderr.take().unwrap();
|
||||||
child.wait().unwrap();
|
child.wait().unwrap();
|
||||||
|
|
||||||
let mut output_buf = self.output_buf.borrow_mut();
|
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()
|
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 buffer = self.output_buf.borrow_mut();
|
||||||
let mut temp_buf = [0u8; 64];
|
let mut temp_buf = [0u8; 64];
|
||||||
let mut child = self.child.borrow_mut();
|
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 port_regex = regex::bytes::Regex::new(r":(\d+)").unwrap();
|
||||||
|
|
||||||
let start = std::time::Instant::now();
|
let start = std::time::Instant::now();
|
||||||
|
@ -141,7 +143,7 @@ impl ServeClient {
|
||||||
String::from_utf8_lossy(&buffer)
|
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]);
|
buffer.extend_from_slice(&temp_buf[..read]);
|
||||||
if let Some(p) = port_regex
|
if let Some(p) = port_regex
|
||||||
.captures(&buffer)
|
.captures(&buffer)
|
||||||
|
|
|
@ -1359,16 +1359,16 @@ async fn test_watch_serve() {
|
||||||
.piped_output()
|
.piped_output()
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.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
|
// 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;
|
wait_contains(r#"Watching paths: [""#, &mut stderr_lines).await;
|
||||||
|
|
||||||
file_to_watch.write(file_content);
|
file_to_watch.write(file_content);
|
||||||
|
|
||||||
wait_contains("serving", &mut stderr_lines).await;
|
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);
|
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 {
|
export default {
|
||||||
fetch(_req: Request) {
|
fetch(_req: Request) {
|
||||||
console.log("serving request");
|
console.error("serving request");
|
||||||
return new Response("deno serve parallel");
|
return new Response("deno serve parallel");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -792,8 +792,8 @@ Deno.test(
|
||||||
async function httpServerDefaultOnListenCallback() {
|
async function httpServerDefaultOnListenCallback() {
|
||||||
const ac = new AbortController();
|
const ac = new AbortController();
|
||||||
|
|
||||||
const consoleLog = console.log;
|
const consoleError = console.error;
|
||||||
console.log = (msg) => {
|
console.error = (msg) => {
|
||||||
try {
|
try {
|
||||||
const match = msg.match(
|
const match = msg.match(
|
||||||
/Listening on http:\/\/(localhost|0\.0\.0\.0):(\d+)\//,
|
/Listening on http:\/\/(localhost|0\.0\.0\.0):(\d+)\//,
|
||||||
|
@ -818,7 +818,7 @@ Deno.test(
|
||||||
|
|
||||||
await server.finished;
|
await server.finished;
|
||||||
} finally {
|
} finally {
|
||||||
console.log = consoleLog;
|
console.error = consoleError;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -875,8 +875,8 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
|
||||||
const ac = new AbortController();
|
const ac = new AbortController();
|
||||||
let url = "";
|
let url = "";
|
||||||
|
|
||||||
const consoleLog = console.log;
|
const consoleError = console.error;
|
||||||
console.log = (msg) => {
|
console.error = (msg) => {
|
||||||
try {
|
try {
|
||||||
const match = msg.match(/Listening on (http:\/\/(.*?):(\d+)\/)/);
|
const match = msg.match(/Listening on (http:\/\/(.*?):(\d+)\/)/);
|
||||||
assert(!!match, `Didn't match ${msg}`);
|
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}"`);
|
assert(new URL(url), `Not a valid URL "${url}"`);
|
||||||
await server.shutdown();
|
await server.shutdown();
|
||||||
} finally {
|
} finally {
|
||||||
console.log = consoleLog;
|
console.error = consoleError;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue