Skip to content

Commit 60c474f

Browse files
committed
test: add test case resolve from global cache
1 parent 293ef38 commit 60c474f

6 files changed

Lines changed: 176 additions & 82 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ criterion = { version = "4.3.0", package = "codspeed-criterion-compat", default-
107107
"async_tokio",
108108
] }
109109

110-
normalize-path = { version = "0.2.1" }
111-
rayon = { version = "1.11.0" }
112-
regex = "1.12.2"
113-
vfs = "0.12.2" # for testing with in memory file system
110+
fluent-asserter = "0.1.9"
111+
normalize-path = { version = "0.2.1" }
112+
rayon = { version = "1.11.0" }
113+
regex = "1.12.2"
114+
vfs = "0.12.2" # for testing with in memory file system
114115

115116
[features]
116117
default = ["yarn_pnp"]

examples/resolver.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,30 @@ async fn main() {
2525
extension_alias: vec![(".js".into(), vec![".ts".into(), ".js".into()])],
2626
// ESM
2727
condition_names: vec!["node".into(), "import".into()],
28+
enable_pnp: true,
2829
// CJS
2930
// condition_names: vec!["node".into(), "require".into()],
3031
..ResolveOptions::default()
3132
};
3233
let mut ctx = Default::default();
3334

34-
match Resolver::new(options)
35+
let resolver = Resolver::new(options.clone());
36+
37+
match resolver
3538
.resolve_with_context(path, &specifier, &mut ctx)
3639
.await
3740
{
3841
Err(error) => println!("Error: {error}"),
3942
Ok(resolution) => println!("Resolved: {:?}", resolution.full_path()),
4043
};
4144

42-
let mut sorted_file_deps = ctx.file_dependencies.iter().collect::<Vec<_>>();
43-
sorted_file_deps.sort();
44-
println!("file_deps: {:#?}", sorted_file_deps);
45+
let global_cache_path = PathBuf::from("/Users/bytedance/.yarn/berry/cache/@rspress-core-npm-2.0.3-c87d0adf5b-10c0.zip/node_modules/@rspress/core/dist/runtime/index.js");
4546

46-
let mut sorted_missing = ctx.missing_dependencies.iter().collect::<Vec<_>>();
47-
sorted_missing.sort();
48-
println!("missing_deps: {:#?}", sorted_missing);
47+
match resolver
48+
.resolve_with_context(&global_cache_path, "react-router-dom", &mut ctx)
49+
.await
50+
{
51+
Err(error) => println!("Error: {error}"),
52+
Ok(resolution) => println!("Resolved: {:?}", resolution.full_path()),
53+
};
4954
}

0 commit comments

Comments
 (0)