-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.rs
49 lines (47 loc) · 1.84 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#[cfg(test)]
mod tests {
use oxc_resolver::{ResolveOptions, Resolver};
use std::{env, ffi::OsString, path::Path};
pub fn path_resolve(path: &str) -> String {
let work_cwd = {
match env::var("CARGO_MANIFEST_DIR") {
Ok(_val) => env!("CARGO_MANIFEST_DIR").to_string(),
Err(_) => match std::env::current_exe() {
Ok(val) => val.parent().unwrap().to_str().unwrap().to_string(),
Err(_) => std::env::current_dir()
.unwrap()
.to_str()
.unwrap()
.to_string(),
},
}
};
let os_work_cwd = OsString::from(work_cwd);
Path::new(&os_work_cwd)
.join(path)
.into_os_string()
.into_string()
.unwrap()
}
#[test]
fn test_resolver_inner_package_json() {
let options = ResolveOptions {
alias_fields: vec![vec!["browser".into()]],
..ResolveOptions::default()
};
let fold_path = path_resolve("esbuild-test/src");
let dir = Path::new(fold_path.as_str());
let resolver = Resolver::new(options.clone());
let res = resolver.resolve(dir, "pkg/sub").unwrap();
println!("res-> \n {:#?}", res);
// up case is right
// down case is wrong
let fold_path = path_resolve("esbuild-test/src/node_modules/pkg/sub");
let dir = Path::new(fold_path.as_str());
let resolver = Resolver::new(options);
let res = resolver.resolve(dir, "sub").unwrap();
// line 30 has error but expected require('sub') to be resolved to './sub/sub' sub/bar.js
// because of the browser field in the package.json "./sub/sub": "./sub/bar.js"
println!("res-> \n {:#?}", res);
}
}