10000 fix: references should take higher priority by JounQin · Pull Request #13 · unrs/unrs-resolver · GitHub
[go: up one dir, main page]

Skip to content

fix: references should take higher priority #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: references should take higher priority
  • Loading branch information
JounQin committed Mar 16, 2025
commit cb644e649888bc40e97ee01846ff1f 10000 9039aef316
3 changes: 3 additions & 0 deletions examples/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ fn main() {

let specifier = env::args().nth(2).expect("specifier");

println!("path: {path:?}");
println!("specifier: {specifier}");

let options = ResolveOptions {
alias_fields: vec![vec!["browser".into()]],
alias: vec![("asdf".into(), vec![AliasValue::from("./test.js")])],
Expand Down
6 changes: 3 additions & 3 deletions src/tests/tsconfig_project_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn auto() {
(f.join("app"), "@/index.ts", f.join("app/aliased/index.ts")),
(f.join("app"), "@/../index.ts", f.join("app/index.ts")),
// Test project reference
(f.join("project_a"), "@/index.ts", f.join("app/aliased/index.ts")),
(f.join("project_b/src"), "@/index.ts", f.join("app/aliased/index.ts")),
(f.join("project_a"), "@/index.ts", f.join("project_a/aliased/index.ts")),
(f.join("project_b/src"), "@/index.ts", f.join("project_b/src/aliased/index.ts")),
// Does not have paths alias
(f.join("project_a"), "./index.ts", f.join("project_a/index.ts")),
(f.join("project_c"), "./index.ts", f.join("project_c/index.ts")),
Expand Down Expand Up @@ -161,7 +161,7 @@ fn manual() {
(f.join("app"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
(f.join("app"), "@/../index.ts", Ok(f.join("app/index.ts"))),
// Test project reference
(f.join("project_a"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
(f.join("project_a"), "@/index.ts", Ok(f.join("project_a/aliased/index.ts"))),
(f.join("project_b/src"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
// Does not have paths alias
(f.join("project_a"), "./index.ts", Ok(f.join("project_a/index.ts"))),
Expand Down
3 changes: 2 additions & 1 deletion src/tsconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ impl TsConfig {
pub fn resolve(&self, path: &Path, specifier: &str) -> Vec<PathBuf> {
let mut paths = self.resolve_path_alias(specifier);
for tsconfig in self.references.iter().filter_map(|reference| reference.tsconfig.as_ref()) {
// references takes higher priority
if path.starts_with(tsconfig.base_path()) {
paths = [paths, tsconfig.resolve_path_alias(specifier)].concat();
paths = [tsconfig.resolve_path_alias(specifier), paths].concat();
break;
}
}
Expand Down
Loading
0