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
78fn 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