Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ deno_core = { version = "0.222.0" }
deno_console = { version = "0.121.0" }
deno_crypto = { version = "0.135.0" }
deno_fetch = { version = "0.145.0" }
deno_fs = "0.31.0"
deno_fs = { version = "0.31.0", features = ["sync_fs"] }
deno_config = "=0.3.1"
deno_io = "0.31.0"
deno_graph = "=0.55.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ anyhow = { workspace = true }
bytes = { version = "1.2.1" }
cityhash = { version = "0.1.1" }
deno_ast = { workspace = true }
deno_fs = { workspace = true, features = ["sync_fs"] }
deno_fs.workspace = true
deno_io = { workspace = true }
deno_core = { workspace = true }
deno_console = { workspace = true }
Expand Down Expand Up @@ -69,7 +69,7 @@ sb_node = { version = "0.1.0", path = "../node" }
anyhow = { workspace = true }
bytes = { version = "1.2.1" }
deno_ast = { workspace = true }
deno_fs = { workspace = true, features = ["sync_fs"] }
deno_fs.workspace = true
deno_io = { workspace = true }
deno_core = { workspace = true }
deno_console = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tokio::sync::oneshot::Receiver;

impl WorkerHandler for Worker {
fn handle_error(&self, error: Error) -> Result<WorkerEvents, Error> {
println!("{}", error);
log::error!("{}", error);
Ok(WorkerEvents::BootFailure(BootFailureEvent {
msg: error.to_string(),
}))
Expand Down
4 changes: 4 additions & 0 deletions crates/base/test_cases/npm/folder1/folder2/numbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const numbers = {
"Uno": 1,
"Dos": 2
}
1 change: 1 addition & 0 deletions crates/base/test_cases/npm/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const hello = "";
4 changes: 3 additions & 1 deletion crates/base/test_cases/npm/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import isEven from "npm:is-even";
import { serve } from "https://deno.land/std@0.131.0/http/server.ts"
import { hello } from "./hello.js";
import { numbers } from "./folder1/folder2/numbers.ts"

serve(async (req: Request) => {
return new Response(
JSON.stringify({ is_even: isEven(10) }),
JSON.stringify({ is_even: isEven(10), hello, numbers }),
{ status: 200, headers: { "Content-Type": "application/json" } },
)
})
5 changes: 4 additions & 1 deletion crates/base/tests/user_worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ async fn test_user_imports_npm() {

let body_bytes = hyper::body::to_bytes(res.into_body()).await.unwrap();

assert_eq!(body_bytes, r#"{"is_even":true}"#);
assert_eq!(
body_bytes,
r#"{"is_even":true,"hello":"","numbers":{"Uno":1,"Dos":2}}"#
);
}
23 changes: 21 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use clap::builder::FalseyValueParser;
use clap::{arg, crate_version, value_parser, ArgAction, Command};
use deno_core::url::Url;
use sb_graph::emitter::EmitterFactory;
use sb_graph::generate_binary_eszip;
use sb_graph::import_map::load_import_map;
use sb_graph::{extract_from_file, generate_binary_eszip};
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
Expand Down Expand Up @@ -58,7 +58,12 @@ fn cli() -> Command {
.arg(arg!(--"output" <DIR> "Path to output eszip file").default_value("bin.eszip"))
.arg(arg!(--"entrypoint" <Path> "Path to entrypoint to bundle as an eszip").required(true))
.arg(arg!(--"import-map" <Path> "Path to import map file"))
)
).subcommand(
Command::new("unbundle")
.about("Unbundles an .eszip file into the specified directory")
.arg(arg!(--"output" <DIR> "Path to extract the ESZIP content").default_value("./"))
.arg(arg!(--"eszip" <DIR> "Path of eszip to extract").required(true))
)
}

//async fn exit_with_code(result: Result<(), Error>) {
Expand Down Expand Up @@ -162,6 +167,20 @@ fn main() -> Result<(), anyhow::Error> {
let mut file = File::create(output_path.as_str()).unwrap();
file.write_all(&bin).unwrap();
}
Some(("unbundle", sub_matches)) => {
let output_path = sub_matches.get_one::<String>("output").cloned().unwrap();
let eszip_path = sub_matches.get_one::<String>("eszip").cloned().unwrap();

let output_path = PathBuf::from(output_path.as_str());
let eszip_path = PathBuf::from(eszip_path.as_str());

extract_from_file(eszip_path, output_path.clone()).await;

println!(
"Eszip extracted successfully inside path {}",
output_path.to_str().unwrap()
);
}
_ => {
// unrecognized command
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cpu_timer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl CPUTimer {

#[cfg(not(target_os = "linux"))]
pub fn start(_: u64, _: u64, _: CPUAlarmVal) -> Result<Self, Error> {
println!("CPU timer: not enabled (need Linux)");
log::error!("CPU timer: not enabled (need Linux)");
Ok(Self {})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ winapi = "=0.3.9"
# https://github.com/dalek-cryptography/x25519-dalek/pull/89
x25519-dalek = "2.0.0-pre.1"
x509-parser = "0.15.0"
log.workspace = true
4 changes: 2 additions & 2 deletions crates/node/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ fn is_managed_key(scope: &mut v8::HandleScope, key: v8::Local<v8::Name>) -> bool

fn current_mode(scope: &mut v8::HandleScope) -> Mode {
let Some(v8_string) = v8::StackTrace::current_script_name_or_source_url(scope) else {
println!("current_script_name_or_source_url, Using Deno");
log::debug!("current_script_name_or_source_url, Using SB");
return Mode::Deno;
};
let op_state = deno_core::JsRuntime::op_state_from(scope);
let op_state = op_state.borrow();
let Some(node_resolver) = op_state.try_borrow::<Rc<NodeResolver>>() else {
println!("Node resolver not available, using Deno");
log::debug!("Node resolver not available, using SB");
return Mode::Deno;
};
let mut buffer = [MaybeUninit::uninit(); 2048];
Expand Down
1 change: 0 additions & 1 deletion crates/node/ops/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ pub async fn op_http2_client_get_response_body_chunk(
return Ok((Some(data.to_vec()), false));
}
DataOrTrailers::Trailers(trailers) => {
println!("{trailers:?}");
if let Some(trailers_tx) = RcRef::map(&resource, |r| &r.trailers_tx)
.borrow_mut()
.await
Expand Down
3 changes: 2 additions & 1 deletion crates/npm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ percent-encoding = "=2.3.0"
hex = "0.4"
base64.workspace = true
bincode = "=1.3.3"
thiserror.workspace = true
thiserror.workspace = true
log.workspace = true
5 changes: 3 additions & 2 deletions crates/npm/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use deno_core::futures::StreamExt;
use deno_npm::registry::NpmRegistryApi;
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
use deno_semver::package::PackageReq;
use log::debug;
use sb_core::util::sync::AtomicFlag;

use super::CliNpmRegistryApi;
Expand Down Expand Up @@ -91,7 +92,7 @@ impl PackageJsonDepsInstaller {
.resolve_pkg_id_from_pkg_req(req)
.is_ok()
}) {
println!("All package.json deps resolvable. Skipping top level install.");
debug!("All package.json deps resolvable. Skipping top level install.");
return Ok(()); // everything is already resolvable
}

Expand All @@ -104,7 +105,7 @@ impl PackageJsonDepsInstaller {
.resolve_package_req_as_pending_with_info(req, &info);
if let Err(err) = result {
if inner.npm_registry_api.mark_force_reload() {
println!("Failed to resolve package. Retrying. Error: {err:#}");
debug!("Failed to resolve package. Retrying. Error: {err:#}");
// re-initialize
reqs_with_info_futures = inner.reqs_with_info_futures(&package_reqs);
} else {
Expand Down
3 changes: 2 additions & 1 deletion crates/npm/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use deno_core::url::Url;
use deno_npm::registry::NpmPackageInfo;
use deno_npm::registry::NpmRegistryApi;
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
use log::debug;
use once_cell::sync::Lazy;
use sb_core::cache::CacheSetting;
use sb_core::cache::CACHE_PERM;
Expand Down Expand Up @@ -288,7 +289,7 @@ impl CliNpmRegistryApiInner {
&self,
name: &str,
) -> Result<Option<NpmPackageInfo>, AnyError> {
println!("Downloading load_package_info_from_registry_inner");
debug!("Downloading load_package_info_from_registry_inner");
if *self.cache.cache_setting() == CacheSetting::Only {
return Err(custom_error(
"NotCached",
Expand Down
7 changes: 4 additions & 3 deletions crates/npm/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use sb_core::util::sync::TaskQueue;

use super::registry::CliNpmRegistryApi;
use deno_lockfile::Lockfile;
use log::debug;

/// Handles updating and storing npm resolution in memory where the underlying
/// snapshot can be updated concurrently. Additionally handles updating the lockfile
Expand Down Expand Up @@ -292,7 +293,7 @@ async fn add_package_reqs_to_snapshot(
.iter()
.all(|req| snapshot.package_reqs().contains_key(req))
{
println!("Snapshot already up to date. Skipping pending resolution.");
debug!("Snapshot already up to date. Skipping pending resolution.");
snapshot
} else {
let pending_resolver = get_npm_pending_resolver(api);
Expand All @@ -303,8 +304,8 @@ async fn add_package_reqs_to_snapshot(
match result {
Ok(snapshot) => snapshot,
Err(NpmResolutionError::Resolution(err)) if api.mark_force_reload() => {
println!("{err:#}");
println!("npm resolution failed. Trying again...");
log::error!("{err:#}");
log::warn!("npm resolution failed. Trying again...");

// try again
let snapshot = get_new_snapshot();
Expand Down
21 changes: 20 additions & 1 deletion crates/sb_core/util/path.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use deno_ast::ModuleSpecifier;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

/// Gets if the provided character is not supported on all
/// kinds of file systems.
Expand Down Expand Up @@ -41,3 +41,22 @@ pub fn root_url_to_safe_local_dirname(root: &ModuleSpecifier) -> PathBuf {

result
}

pub fn find_lowest_path(paths: &Vec<String>) -> Option<String> {
let mut lowest_path: Option<(&str, usize)> = None;

for path_str in paths {
// Extract the path part from the URL
let path = Path::new(path_str);

// Count the components
let component_count = path.components().count();

// Update the lowest path if this one has fewer components
if lowest_path.is_none() || component_count < lowest_path.unwrap().1 {
lowest_path = Some((path_str, component_count));
}
}

lowest_path.map(|(path, _)| path.to_string())
}
1 change: 0 additions & 1 deletion crates/sb_graph/graph_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ impl NpmResolver for CliGraphResolver {
Ok(nv) => NpmPackageReqResolution::Ok(nv),
Err(err) => {
if self.npm_registry_api.mark_force_reload() {
println!("Restarting npm specifier resolution to check for new registry information. Error: {:#}", err);
NpmPackageReqResolution::ReloadRegistryInfo(err.into())
} else {
NpmPackageReqResolution::Err(err.into())
Expand Down
Loading