Skip to content

Commit

Permalink
perf: try directory first in node_modules (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Dec 12, 2024
1 parent 032f1da commit 139bd72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ watch *args='':
watch-check:
just watch "'cargo check; cargo clippy'"

watch-example *args='':
just watch "cargo run --example resolver -- {{args}}"

# Run the example in `parser`, `formatter`, `linter`
example *args='':
cargo run --example resolver -- {{args}}
Expand Down
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,21 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
// Try as file or directory for all other cases
// b. LOAD_AS_FILE(DIR/X)
// c. LOAD_AS_DIRECTORY(DIR/X)

let cached_path = cached_path.normalize_with(specifier, &self.cache);
if let Some(path) = self.load_as_file_or_directory(&cached_path, specifier, ctx)? {

// Perf: try the directory first for package specifiers.
if cached_path.is_dir(&self.cache.fs, ctx) {
if let Some(path) = self.load_as_directory(&cached_path, ctx)? {
return Ok(Some(path));
}
}
if self.options.resolve_to_context {
return Ok(cached_path
.is_dir(&self.cache.fs, ctx)
.then(|| cached_path.clone()));
}
if let Some(path) = self.load_as_file(&cached_path, ctx)? {
return Ok(Some(path));
}
}
Expand Down

0 comments on commit 139bd72

Please sign in to comment.