diff --git a/Cargo.lock b/Cargo.lock index ed92417..cc6d86b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -396,6 +396,19 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -459,6 +472,18 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "ident_case" version = "1.0.1" @@ -491,6 +516,17 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_ci" version = "1.2.0" @@ -701,9 +737,11 @@ dependencies = [ "clap", "ignore", "json-strip-comments", + "log", "miette", "oxc", "package-json", + "pretty_env_logger", "serde", "serde_json", "static_assertions", @@ -1143,6 +1181,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "pretty_env_logger" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" +dependencies = [ + "env_logger", + "log", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -1185,6 +1233,18 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + [[package]] name = "regex-automata" version = "0.4.7" @@ -1404,6 +1464,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "terminal_size" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index c64207f..4c2ea0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,11 @@ anyhow = { version = "1.0.89" } clap = { version = "4.5.20", features = ["cargo"] } ignore = { version = "0.4.23" } json-strip-comments = { version = "1.0.4" } +log = { version = "0.4.22" } miette = { version = "7.2.0", features = ["fancy"] } oxc = { version = "0.31.0", features = ["full"] } package-json = { version = "0.4.0" } +pretty_env_logger = { version = "0.5.0" } serde = { version = "1.0.210" } serde_json = { version = "1.0.128" } static_assertions = { version = "1.1.0" } diff --git a/Justfile b/Justfile index 93f6982..1198be3 100644 --- a/Justfile +++ b/Justfile @@ -16,6 +16,12 @@ oxbuild *ARGS: build: cargo build +# Create a release build and copy it to ~/.bin +oxbuild-local: + cargo build --release --bin oxbuild + rm ~/.bin/oxbuild + cp target/release/oxbuild ~/.bin/oxbuild + # Alias for `cargo test` test: cargo test diff --git a/README.md b/README.md index 2750d4a..cb4f745 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,13 @@ Assuming you are in your project's root directory and your source code is all in oxbuild ``` +If `oxbuild` is behaving in an unexpected way, please run it with debug logs and +create a new issue on GitHub. + +```sh +RUST_LOG=debug oxbuild +``` + ### TSConfig Support Oxbuild will respect `rootDir` and `outDir` settings in your `tsconfig.json`. diff --git a/src/cli.rs b/src/cli.rs index 1dc1301..c803d0b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -77,6 +77,7 @@ impl CliOptions { } else { Root::new_inferred()? }; + debug!("Root directory: '{}'", root.display()); let config = root.resolve_file( matches.get_one::("config"), diff --git a/src/main.rs b/src/main.rs index aa58dab..3e46515 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,9 @@ mod walk; use std::{thread, time::Instant}; +extern crate pretty_env_logger; +#[macro_use] +extern crate log; use miette::Result; use crate::{ @@ -16,6 +19,7 @@ use crate::{ #[allow(clippy::print_stdout)] fn main() -> Result<()> { + pretty_env_logger::init(); let matches = cli(); let opts = CliOptions::new(matches).and_then(OxbuildOptions::new)?; let num_threads = opts.num_threads.get(); diff --git a/src/options.rs b/src/options.rs index 73143bf..2746ccc 100644 --- a/src/options.rs +++ b/src/options.rs @@ -5,6 +5,7 @@ use std::{ path::PathBuf, }; +use log::{debug, trace}; use miette::{IntoDiagnostic, Report, Result, WrapErr}; // use package_json::{PackageJson, PackageJsonManager}; use serde::Deserialize; @@ -43,6 +44,7 @@ impl OxbuildOptions { let tsconfig = root .resolve_file(tsconfig.as_ref(), ["tsconfig.json"])? .map(|tsconfig_path| { + debug!("Reading tsconfig at '{}'", tsconfig_path.display()); fs::read_to_string(&tsconfig_path) .into_diagnostic() .with_context(|| { @@ -60,10 +62,16 @@ impl OxbuildOptions { let co = tsconfig.as_ref().and_then(TsConfig::compiler_options); let src = if let Some(root_dir) = co.and_then(|co| co.root_dir.as_ref()) { + debug!( + "Resolving rootDir from tsconfig.json: '{}'", + root_dir.display() + ); root.resolve(root_dir) } else { + debug!("Using default src directory"); let src = root.join("src").to_path_buf(); if !src.exists() { + trace!("Creating src directory at '{}'", src.display()); return Err(Report::msg("src directory does not exist. Please explicitly provide a path to your source files.".to_string())); } src @@ -74,28 +82,37 @@ impl OxbuildOptions { src.display() ))); } + trace!("src directory: '{}'", src.display()); let dist = if let Some(out_dir) = co.and_then(|co| co.out_dir.as_ref()) { + debug!( + "Resolving outDir from tsconfig.json: '{}'", + out_dir.display() + ); root.resolve(out_dir) } else { + debug!("Using default dist directory"); let dist = root.join("dist").to_path_buf(); if !dist.exists() { + trace!("Creating dist directory at '{}'", dist.display()); fs::create_dir(&dist).into_diagnostic()?; } // TODO: clean dist dir? dist }; assert!(dist.is_dir()); // FIXME: handle errors + trace!("dist directory: '{}'", dist.display()); // let strip_internal = co.and_then(|co| co.) // no tsconfig means they're using JavaScript. We can't emit .d.ts files in that case. let isolated_declarations = co.and_then(|co| { - co.isolated_declarations - .unwrap_or(false) - .then(|| DeclarationsOptions { + co.isolated_declarations.unwrap_or(false).then(|| { + debug!("Enabling .d.ts emit"); + DeclarationsOptions { strip_internal: co.strip_internal.unwrap_or(false), - }) + } + }) }); Ok(Self { diff --git a/src/reporter.rs b/src/reporter.rs index 94af2b9..425bd16 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -10,6 +10,7 @@ pub struct Reporter { impl Reporter { pub fn new() -> (Self, DiagnosticSender) { + trace!("Creating diagnostics reporter"); let inner = DiagnosticService::default(); let sender = inner.sender().clone(); (Self { inner }, sender) diff --git a/src/walk.rs b/src/walk.rs index 2080818..d833c0b 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -31,6 +31,7 @@ impl WalkerBuilder { } pub fn walk(&mut self, nthreads: usize) { + debug!("Starting walker with {} threads", nthreads); let inner = ignore::WalkBuilder::new(&self.options.src) // TODO: use ignore to respect tsconfig include/exclude .ignore(false) @@ -69,6 +70,7 @@ impl Walker { #[must_use] fn compile(&self, path: &Path) -> Option { + trace!("Compiling '{}'", path.display()); let source_text = match fs::read_to_string(path) { Ok(text) => text, Err(e) => {