Skip to content

Commit

Permalink
feat: add debug logging (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac authored Oct 8, 2024
1 parent 0e2e7d8 commit 1de9ba4
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 4 deletions.
69 changes: 69 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 6 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl CliOptions {
} else {
Root::new_inferred()?
};
debug!("Root directory: '{}'", root.display());

let config = root.resolve_file(
matches.get_one::<PathBuf>("config"),
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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();
Expand Down
25 changes: 21 additions & 4 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(|| {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -69,6 +70,7 @@ impl Walker {

#[must_use]
fn compile(&self, path: &Path) -> Option<CompiledOutput> {
trace!("Compiling '{}'", path.display());
let source_text = match fs::read_to_string(path) {
Ok(text) => text,
Err(e) => {
Expand Down

0 comments on commit 1de9ba4

Please sign in to comment.