Skip to content

Commit a60c07c

Browse files
chore: add --tsconfig to example (#505)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 6e03810 commit a60c07c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ document-features = { version = "0.2.11", optional = true }
9595
[dev-dependencies]
9696
criterion2 = { version = "3.0.0", default-features = false }
9797
normalize-path = { version = "0.2.1" }
98+
pico-args = "0.5.0"
9899
rayon = { version = "1.10.0" }
99100
vfs = "0.12.1" # for testing with in memory file system
100101

examples/resolver.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
// See documentation at <https://docs.rs/oxc_resolver>
22

3-
use std::{env, path::PathBuf};
3+
use std::path::PathBuf;
44

5-
use oxc_resolver::{AliasValue, ResolveOptions, Resolver};
5+
use oxc_resolver::{AliasValue, ResolveOptions, Resolver, TsconfigOptions, TsconfigReferences};
6+
use pico_args::Arguments;
67

78
fn main() {
8-
let path = PathBuf::from(env::args().nth(1).expect("path"));
9+
let mut args = Arguments::from_env();
10+
11+
let tsconfig_path = args.value_from_str::<&'static str, PathBuf>("--tsconfig").ok();
12+
let path = args.free_from_str::<PathBuf>().expect("path");
13+
let specifier = args.free_from_str::<String>().expect("specifier");
914

1015
assert!(path.is_dir(), "{path:?} must be a directory that will be resolved against.");
1116
assert!(path.is_absolute(), "{path:?} must be an absolute path.",);
1217

13-
let specifier = env::args().nth(2).expect("specifier");
14-
1518
println!("path: {}", path.to_string_lossy());
1619
println!("specifier: {specifier}");
20+
if let Some(path) = &tsconfig_path {
21+
println!("tsconfig: {}", path.to_string_lossy());
22+
}
1723

1824
let options = ResolveOptions {
1925
alias_fields: vec![vec!["browser".into()]],
@@ -24,9 +30,15 @@ fn main() {
2430
condition_names: vec!["node".into(), "import".into()],
2531
// CJS
2632
// condition_names: vec!["node".into(), "require".into()],
33+
tsconfig: tsconfig_path.map(|config_file| TsconfigOptions {
34+
config_file,
35+
references: TsconfigReferences::Auto,
36+
}),
2737
..ResolveOptions::default()
2838
};
2939

40+
println!();
41+
3042
match Resolver::new(options).resolve(path, &specifier) {
3143
Err(error) => println!("Error: {error}"),
3244
Ok(resolution) => {

0 commit comments

Comments
 (0)