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
1 change: 0 additions & 1 deletion fixtures/symlink-with-nested-node_modules/.gitignore

This file was deleted.

This file was deleted.

Empty file.
Empty file.
15 changes: 2 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,9 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
) -> Result<Resolution, ResolveError> {
ctx.with_fully_specified(self.options.fully_specified);

let cached_path = if self.options.symlinks {
self.load_realpath(&self.cache.value(path))?
} else {
path.to_path_buf()
};

let cached_path = self.cache.value(&cached_path);
let cached_path = self.cache.value(path);
let cached_path = self.require(&cached_path, specifier, ctx)?;

let path = if self.options.symlinks {
self.load_realpath(&cached_path)?
} else {
cached_path.to_path_buf()
};
let path = self.load_realpath(&cached_path)?;

let package_json = self.find_package_json_for_a_package(&cached_path, ctx)?;
if let Some(package_json) = &package_json {
Expand Down
5 changes: 3 additions & 2 deletions src/tests/package_json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tests for `Resolution::package_json`.

use crate::{ResolveError, Resolver};
use crate::Resolver;

#[test]
fn test() {
Expand Down Expand Up @@ -68,8 +68,9 @@ fn package_json_with_symlinks_true() {
fn test_corrupted_package_json() {
use std::path::Path;

use crate::{ResolveError, ResolveOptions, ResolverGeneric};

use super::memory_fs::MemoryFS;
use crate::{ResolveOptions, ResolverGeneric};

// Test scenarios for various corrupted package.json files
let scenarios = [
Expand Down
16 changes: 0 additions & 16 deletions src/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,6 @@ fn resolve_dot() {
}
}

#[test]
fn symlink_with_nested_node_modules() {
let f = super::fixture_root().join("symlink-with-nested-node_modules");

let resolver = Resolver::default();
let resolved_path =
resolver.resolve(f.join("bar/node_modules/foo"), "dep").map(|r| r.full_path());
assert_eq!(resolved_path, Ok(f.join("foo/node_modules/dep/index.js")));

let resolver = Resolver::new(ResolveOptions { symlinks: false, ..ResolveOptions::default() });
assert_eq!(
resolver.resolve(f.join("bar/node_modules/foo"), "dep"),
Err(ResolveError::NotFound("dep".into()))
);
}

#[test]
fn abnormal_relative() {
let f = super::fixture_root().join("abnormal-relative-with-node_modules");
Expand Down
5 changes: 3 additions & 2 deletions src/tests/symlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn test() {
fn test_unsupported_targets() {
use crate::ResolveError;

let Some(SymlinkFixturePaths { root: _, temp_path }) =
let Some(SymlinkFixturePaths { root, temp_path }) =
prepare_symlinks("temp.test_unsupported_targets").unwrap()
else {
return;
Expand All @@ -200,9 +200,10 @@ fn test_unsupported_targets() {
// from `FsCachedPath::find_package_json` when trying to canonicalize the full path of `package.json`.
// * Otherwise, a `ResolveError::NotFound` will be returned.
let dos_device_temp_path = get_dos_device_path(&temp_path).unwrap();
let dos_device_root = get_dos_device_path(&root).unwrap();
assert_eq!(
resolver_with_symlinks.resolve(&dos_device_temp_path, "./index.js"),
Err(ResolveError::PathNotSupported(dos_device_temp_path))
Err(ResolveError::PathNotSupported(dos_device_root))
);
}

Expand Down