diff --git a/Cargo.lock b/Cargo.lock index dabb592..5b16c0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] @@ -95,9 +95,9 @@ checksum = "7330592adf847ee2e3513587b4db2db410a0d751378654e7e993d9adcbe5c795" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -334,7 +334,7 @@ checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if", "crossbeam-utils", - "hashbrown", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -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" @@ -436,9 +449,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" @@ -465,6 +478,24 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + +[[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" @@ -489,12 +520,23 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.0", +] + +[[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]] @@ -541,9 +583,9 @@ checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "linux-raw-sys" @@ -610,7 +652,7 @@ checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -680,18 +722,18 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "outref" @@ -707,7 +749,7 @@ checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" [[package]] name = "oxbuild" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "clap", @@ -715,9 +757,11 @@ dependencies = [ "glob", "ignore", "json-strip-comments", + "log", "miette", "oxc", "package-json", + "pretty_env_logger", "serde", "serde_json", "static_assertions", @@ -796,7 +840,7 @@ checksum = "a2b1072cb32335b47745c9ea9d614a6d5d36ba9f528fce1da428d5f7e20c3ed1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1141,7 +1185,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1159,11 +1203,21 @@ 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" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -1194,18 +1248,18 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -1215,9 +1269,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -1226,9 +1280,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "ropey" @@ -1321,7 +1375,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1423,15 +1477,24 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", "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" @@ -1470,7 +1533,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index bc57cd4..aeb69de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxbuild" -version = "0.1.4" +version = "0.1.5" description = "Ultra-fast typescript compiler" authors = ["Don Isaac "] license = "MIT" @@ -22,9 +22,11 @@ compact_str = { version = "0.8.0" } glob = { version = "0.3.1" } 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" } @@ -53,9 +55,10 @@ opt-level = 1 # defaults: https://doc.rust-lang.org/cargo/reference/profiles.html#release [profile.release] codegen-units = 4 -strip = "symbols" +debug = false # set to `true` for debugging +strip = "symbols" # set to `false` for debugging lto = "thin" -panic = "abort" +panic = "abort" # set to `unwind` for backtraces # The profile that 'cargo dist' will build with [profile.dist] 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 3421bd5..04bc480 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -76,6 +76,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 b76f5af..d2e8b27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,9 @@ mod workspace; use std::{thread, time::Instant}; +extern crate pretty_env_logger; +#[macro_use] +extern crate log; use miette::Result; use crate::{ @@ -18,6 +21,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 6aead6f..2c1c6e4 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,8 +62,13 @@ 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() { return Err(Report::msg("src directory does not exist. Please explicitly provide a path to your source files.".to_string())); @@ -74,28 +81,38 @@ 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()) { - root.resolve(out_dir) + debug!( + "Resolving outDir from tsconfig.json: '{}'", + out_dir.display() + ); + root.join(out_dir) } else { - let dist = root.join("dist").to_path_buf(); - if !dist.exists() { - fs::create_dir(&dist).into_diagnostic()?; - } - // TODO: clean dist dir? - dist + debug!("Using default dist directory"); + root.join("dist").to_path_buf() }; + // TODO: clean dist dir? + if !dist.exists() { + trace!("Creating dist directory at '{}'", dist.display()); + fs::create_dir_all(&dist).into_diagnostic()?; + } assert!(dist.is_dir()); // FIXME: handle errors - - // let strip_internal = co.and_then(|co| co.) + let dist = dist + .canonicalize() + .into_diagnostic() + .wrap_err("Failed to canonicalize dist directory")?; + trace!("dist directory: '{}'", dist.display()); // 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 { @@ -109,6 +126,7 @@ impl OxbuildOptions { } #[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] struct TsConfig { // TODO: tsconfig extends compiler_options: Option, 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) => {