这是indexloc提供的服务,不要输入任何密码
Skip to content
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
14 changes: 2 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,29 +882,19 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {

let cached_path = cached_path.normalize_with(specifier, self.cache.as_ref());

// Perf: try the directory first for package specifiers.
if self.options.resolve_to_context {
return Ok(self.cache.is_dir(&cached_path, ctx).then(|| cached_path.clone()));
}

// `is_file` could be false because no extensions are considered yet,
// so we need to try `load_as_file` first when `specifier` does not end with a slash which indicates a dir instead.
if !specifier.ends_with('/')
&& let Some(path) = self.load_as_file(&cached_path, ctx)?
{
return Ok(Some(path));
}

// Perf: try LOAD_AS_DIRECTORY first. No modern package manager creates `node_modules/X.js`.
if self.cache.is_dir(&cached_path, ctx) {
if let Some(path) = self.load_browser_field_or_alias(&cached_path, ctx)? {
return Ok(Some(path));
}
if let Some(path) = self.load_as_directory(&cached_path, ctx)? {
return Ok(Some(path));
}
}

if let Some(path) = self.load_as_directory(&cached_path, ctx)? {
} else if let Some(path) = self.load_as_file(&cached_path, ctx)? {
return Ok(Some(path));
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,6 @@ fn resolve_hash_as_module() {
assert_eq!(resolution, Err(ResolveError::NotFound("#a".into())));
}

#[test]
fn prefer_file_over_dir() {
let f = super::fixture_root().join("prefer-file-over-dir");
let resolver = Resolver::default();
let data = [
("one level package name", f.clone(), "bar", f.join("node_modules/bar.js")),
("scoped level package name", f.clone(), "@foo/bar", f.join("node_modules/@foo/bar.js")),
];
for (comment, path, request, expected) in data {
let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path());
assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}");
}
}

#[test]
fn resolve_edge_cases() {
let f = super::fixture();
Expand Down