fix: support npm:bindings and npm:callsites packages (#24727)

Adds support for `npm:bindings` and `npm:callsites` packages because of
changes in
https://github.com/denoland/deno_core/pull/838.

This `deno_core` bump causes us to stop prepending `file://` scheme for
locations
in stack traces that are for local files.

Fixes https://github.com/denoland/deno/issues/24462 , fixes
https://github.com/denoland/deno/issues/22671 , fixes
https://github.com/denoland/deno/issues/15717 , fixes
https://github.com/denoland/deno/issues/19130 , fixes
https://github.com/WiseLibs/better-sqlite3/issues/1205 , fixes
https://github.com/WiseLibs/better-sqlite3/issues/1034 , fixes
https://github.com/denoland/deno/issues/20936

---------

Co-authored-by: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com>
This commit is contained in:
Bartek Iwańczuk 2024-07-26 08:08:15 +01:00 committed by GitHub
parent f4952f75a8
commit 7776636c2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 101 deletions

28
Cargo.lock generated
View File

@ -1343,9 +1343,9 @@ dependencies = [
[[package]]
name = "deno_core"
version = "0.298.0"
version = "0.299.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54fb4db0174c7130b3a8a90ed6aefb3b42a8acd6b75ea9a5a0c7c4d02993cd61"
checksum = "428488cc6b392a199a159054da754f56a1fdc63ee03f16be2c21cbd22e936e7b"
dependencies = [
"anyhow",
"bincode",
@ -1355,7 +1355,7 @@ dependencies = [
"cooked-waker",
"deno_core_icudata",
"deno_ops",
"deno_unsync",
"deno_unsync 0.4.0",
"futures",
"libc",
"memoffset 0.9.1",
@ -1545,7 +1545,7 @@ dependencies = [
"data-url",
"deno_ast",
"deno_semver",
"deno_unsync",
"deno_unsync 0.3.10",
"encoding_rs",
"futures",
"import_map",
@ -1825,9 +1825,9 @@ dependencies = [
[[package]]
name = "deno_ops"
version = "0.174.0"
version = "0.175.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdacbea7e6c459f0bcb48cdb0c7ce8ca6ece53645385fe98cf38e7242b2c5809"
checksum = "2d2b71759647722be6ae051919b75cb66b3dccafe61b53c75ad5a6fad9d0ee4a"
dependencies = [
"proc-macro-rules",
"proc-macro2",
@ -2005,6 +2005,16 @@ dependencies = [
"tokio",
]
[[package]]
name = "deno_unsync"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03ee1607db298c8f12124b345a52d5f2f504a7504c9d535f1d8f07127b237010"
dependencies = [
"parking_lot 0.12.3",
"tokio",
]
[[package]]
name = "deno_url"
version = "0.162.0"
@ -5962,9 +5972,9 @@ dependencies = [
[[package]]
name = "serde_v8"
version = "0.207.0"
version = "0.208.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a442f2e04f8367eb99982beb6733fb88df666da9379f937552d67ca060de6e80"
checksum = "583f3c71a6f7acc1711ad718a33f6e799bacdc711d297b15bb28533f32264c58"
dependencies = [
"num-bigint",
"serde",
@ -6889,7 +6899,7 @@ dependencies = [
"base64 0.21.7",
"bytes",
"console_static_text",
"deno_unsync",
"deno_unsync 0.3.10",
"denokv_proto",
"fastwebsockets",
"flate2",

View File

@ -45,7 +45,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies]
deno_ast = { version = "=0.40.0", features = ["transpiling"] }
deno_core = { version = "0.298.0" }
deno_core = { version = "0.299.0" }
deno_bench_util = { version = "0.156.0", path = "./bench_util" }
deno_lockfile = "0.20.0"

View File

@ -6,9 +6,8 @@ mod task_queue;
mod value_creator;
pub use async_flag::AsyncFlag;
pub use deno_core::unsync::sync::AtomicFlag;
pub use sync_read_async_write_lock::SyncReadAsyncWriteLock;
pub use task_queue::TaskQueue;
pub use task_queue::TaskQueuePermit;
pub use value_creator::MultiRuntimeAsyncValueCreator;
// todo(dsherret): this being in the unsync module is slightly confusing, but it's Sync
pub use deno_core::unsync::AtomicFlag;

View File

@ -1,8 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
//! This mod provides DenoError to unify errors across Deno.
use deno_core::error::format_file_name;
use deno_core::error::format_frame;
use deno_core::error::JsError;
use deno_core::error::JsStackFrame;
use deno_terminal::colors::cyan;
use deno_terminal::colors::italic_bold;
use deno_terminal::colors::red;
@ -21,96 +20,22 @@ struct IndexedErrorReference<'a> {
index: usize,
}
// Keep in sync with `/core/error.js`.
pub fn format_location(frame: &JsStackFrame) -> String {
let _internal = frame
.file_name
.as_ref()
.map(|f| f.starts_with("ext:"))
.unwrap_or(false);
if frame.is_native {
return cyan("native").to_string();
}
let mut result = String::new();
let file_name = frame.file_name.clone().unwrap_or_default();
if !file_name.is_empty() {
result += &cyan(&format_file_name(&file_name)).to_string();
} else {
if frame.is_eval {
result +=
&(cyan(&frame.eval_origin.as_ref().unwrap()).to_string() + ", ");
}
result += &cyan("<anonymous>").to_string();
}
if let Some(line_number) = frame.line_number {
write!(result, ":{}", yellow(&line_number.to_string())).unwrap();
if let Some(column_number) = frame.column_number {
write!(result, ":{}", yellow(&column_number.to_string())).unwrap();
}
}
result
}
struct AnsiColors;
fn format_frame(frame: &JsStackFrame) -> String {
let _internal = frame
.file_name
.as_ref()
.map(|f| f.starts_with("ext:"))
.unwrap_or(false);
let is_method_call =
!(frame.is_top_level.unwrap_or_default() || frame.is_constructor);
let mut result = String::new();
if frame.is_async {
result += "async ";
}
if frame.is_promise_all {
result += &italic_bold(&format!(
"Promise.all (index {})",
frame.promise_index.unwrap_or_default()
))
.to_string();
return result;
}
if is_method_call {
let mut formatted_method = String::new();
if let Some(function_name) = &frame.function_name {
if let Some(type_name) = &frame.type_name {
if !function_name.starts_with(type_name) {
write!(formatted_method, "{type_name}.").unwrap();
}
}
formatted_method += function_name;
if let Some(method_name) = &frame.method_name {
if !function_name.ends_with(method_name) {
write!(formatted_method, " [as {method_name}]").unwrap();
}
}
} else {
if let Some(type_name) = &frame.type_name {
write!(formatted_method, "{type_name}.").unwrap();
}
if let Some(method_name) = &frame.method_name {
formatted_method += method_name
} else {
formatted_method += "<anonymous>";
impl deno_core::error::ErrorFormat for AnsiColors {
fn fmt_element(
element: deno_core::error::ErrorElement,
s: &str,
) -> std::borrow::Cow<'_, str> {
use deno_core::error::ErrorElement::*;
match element {
Anonymous | NativeFrame | FileName | EvalOrigin => {
cyan(s).to_string().into()
}
LineNumber | ColumnNumber => yellow(s).to_string().into(),
FunctionName | PromiseAll => italic_bold(s).to_string().into(),
}
result += &italic_bold(&formatted_method).to_string();
} else if frame.is_constructor {
result += "new ";
if let Some(function_name) = &frame.function_name {
write!(result, "{}", italic_bold(&function_name)).unwrap();
} else {
result += &cyan("<anonymous>").to_string();
}
} else if let Some(function_name) = &frame.function_name {
result += &italic_bold(&function_name).to_string();
} else {
result += &format_location(frame);
return result;
}
write!(result, " ({})", format_location(frame)).unwrap();
result
}
/// Take an optional source line and associated information to format it into
@ -254,7 +179,7 @@ fn format_js_error_inner(
0,
));
for frame in &js_error.frames {
write!(s, "\n at {}", format_frame(frame)).unwrap();
write!(s, "\n at {}", format_frame::<AnsiColors>(frame)).unwrap();
}
if let Some(cause) = &js_error.cause {
let is_caused_by_circular = circular