diff --git a/crates/oxc_resolver/src/resolution.rs b/crates/oxc_resolver/src/resolution.rs index 0bae17cc6..f8b49702c 100644 --- a/crates/oxc_resolver/src/resolution.rs +++ b/crates/oxc_resolver/src/resolution.rs @@ -34,8 +34,8 @@ impl Resolution { } /// Returns the full path with query and fragment - pub fn full_path(self) -> PathBuf { - let mut path = self.path.into_os_string(); + pub fn full_path(&self) -> PathBuf { + let mut path = self.path.clone().into_os_string(); if let Some(query) = &self.query { path.push(query); } @@ -56,6 +56,6 @@ fn test() { assert_eq!(resolution.path(), Path::new("foo")); assert_eq!(resolution.query(), Some("?query")); assert_eq!(resolution.fragment(), Some("#fragment")); - assert_eq!(resolution.clone().full_path(), PathBuf::from("foo?query#fragment")); + assert_eq!(resolution.full_path(), PathBuf::from("foo?query#fragment")); assert_eq!(resolution.into_path_buf(), PathBuf::from("foo")); } diff --git a/crates/oxc_resolver/src/tests/alias.rs b/crates/oxc_resolver/src/tests/alias.rs index dc8aa399d..d1c786324 100644 --- a/crates/oxc_resolver/src/tests/alias.rs +++ b/crates/oxc_resolver/src/tests/alias.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; -use crate::{AliasValue, Resolution, ResolveError, ResolveOptions, Resolver, ResolverGeneric}; +use crate::{AliasValue, ResolveError, ResolveOptions, Resolver, ResolverGeneric}; use super::memory_fs::MemoryFS; @@ -91,7 +91,7 @@ fn alias() { ]; for (comment, request, expected) in pass { - let resolved_path = resolver.resolve(f, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(f, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(PathBuf::from(expected)), "{comment} {request}"); } diff --git a/crates/oxc_resolver/src/tests/browser_field.rs b/crates/oxc_resolver/src/tests/browser_field.rs index 3b71ff3be..55fe42bfc 100644 --- a/crates/oxc_resolver/src/tests/browser_field.rs +++ b/crates/oxc_resolver/src/tests/browser_field.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; -use crate::{Resolution, ResolveError, ResolveOptions, Resolver}; +use crate::{ResolveError, ResolveOptions, Resolver}; fn fixture() -> PathBuf { super::fixture().join("browser-module") @@ -59,7 +59,7 @@ fn replace_file() { ]; for (comment, path, request, expected) in data { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } } diff --git a/crates/oxc_resolver/src/tests/exports_field.rs b/crates/oxc_resolver/src/tests/exports_field.rs index b4bcf0ff6..c70530555 100644 --- a/crates/oxc_resolver/src/tests/exports_field.rs +++ b/crates/oxc_resolver/src/tests/exports_field.rs @@ -2,9 +2,7 @@ //! //! The huge exports field test cases are at the bottom of this file. -use crate::{ - ExportsField, PathUtil, Resolution, ResolveContext, ResolveError, ResolveOptions, Resolver, -}; +use crate::{ExportsField, PathUtil, ResolveContext, ResolveError, ResolveOptions, Resolver}; use serde_json::json; use std::path::Path; @@ -51,7 +49,7 @@ fn test() { // * should log the correct info for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } @@ -90,8 +88,7 @@ fn exports_not_browser_field1() { ..ResolveOptions::default() }); - let resolved_path = - resolver.resolve(&f, "exports-field/dist/main.js").map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, "exports-field/dist/main.js").map(|r| r.full_path()); assert_eq!(resolved_path, Ok(f.join("node_modules/exports-field/lib/lib2/main.js"))); } @@ -107,8 +104,7 @@ fn exports_not_browser_field2() { ..ResolveOptions::default() }); - let resolved_path = - resolver.resolve(&f2, "exports-field/dist/main.js").map(Resolution::full_path); + let resolved_path = resolver.resolve(&f2, "exports-field/dist/main.js").map(|r| r.full_path()); assert_eq!(resolved_path, Ok(f2.join("node_modules/exports-field/lib/browser.js"))); } @@ -124,7 +120,7 @@ fn extension_without_fully_specified() { }); let resolved_path = - commonjs_resolver.resolve(&f2, "exports-field/dist/main").map(Resolution::full_path); + commonjs_resolver.resolve(&f2, "exports-field/dist/main").map(|r| r.full_path()); assert_eq!(resolved_path, Ok(f2.join("node_modules/exports-field/lib/lib2/main.js"))); } @@ -151,7 +147,7 @@ fn extension_alias_1_2() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } } @@ -177,7 +173,7 @@ fn extension_alias_3() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } } diff --git a/crates/oxc_resolver/src/tests/extension_alias.rs b/crates/oxc_resolver/src/tests/extension_alias.rs index 7b0968fd4..a01716e3e 100644 --- a/crates/oxc_resolver/src/tests/extension_alias.rs +++ b/crates/oxc_resolver/src/tests/extension_alias.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; -use crate::{Resolution, ResolveError, ResolveOptions, Resolver}; +use crate::{ResolveError, ResolveOptions, Resolver}; fn fixture() -> PathBuf { super::fixture().join("extension-alias") @@ -31,7 +31,7 @@ fn extension_alias() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } @@ -65,7 +65,7 @@ fn not_apply_to_extension_nor_main_files() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); let expected = f.join(expected); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } diff --git a/crates/oxc_resolver/src/tests/extensions.rs b/crates/oxc_resolver/src/tests/extensions.rs index 3983fc792..a5d19686d 100644 --- a/crates/oxc_resolver/src/tests/extensions.rs +++ b/crates/oxc_resolver/src/tests/extensions.rs @@ -27,7 +27,7 @@ fn extensions() { ]; for (comment, request, expected_path) in pass { - let resolved_path = resolver.resolve(&f, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); let expected = f.join(expected_path); assert_eq!(resolved_path, Ok(expected), "{comment} {request} {expected_path}"); } diff --git a/crates/oxc_resolver/src/tests/fallback.rs b/crates/oxc_resolver/src/tests/fallback.rs index 2101b401a..bf8bbfc77 100644 --- a/crates/oxc_resolver/src/tests/fallback.rs +++ b/crates/oxc_resolver/src/tests/fallback.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; -use crate::{AliasValue, Resolution, ResolveError, ResolveOptions, ResolverGeneric}; +use crate::{AliasValue, ResolveError, ResolveOptions, ResolverGeneric}; use super::memory_fs::MemoryFS; @@ -84,7 +84,7 @@ fn fallback() { ]; for (comment, request, expected) in pass { - let resolved_path = resolver.resolve(f, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(f, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(PathBuf::from(expected)), "{comment} {request}"); } diff --git a/crates/oxc_resolver/src/tests/full_specified.rs b/crates/oxc_resolver/src/tests/full_specified.rs index c65f0c292..2289c4fd0 100644 --- a/crates/oxc_resolver/src/tests/full_specified.rs +++ b/crates/oxc_resolver/src/tests/full_specified.rs @@ -26,7 +26,6 @@ fn file_system() -> MemoryFS { #[test] #[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows. fn test() { - use crate::Resolution; let file_system = file_system(); let resolver = ResolverGeneric::::new_with_file_system( @@ -70,7 +69,7 @@ fn test() { ]; for (comment, request, expected) in successful_resolves { - let resolution = resolver.resolve("/a", request).map(Resolution::full_path); + let resolution = resolver.resolve("/a", request).map(|r| r.full_path()); assert_eq!(resolution, Ok(PathBuf::from(expected)), "{comment} {request}"); } } @@ -78,8 +77,6 @@ fn test() { #[test] #[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows. fn resolve_to_context() { - use crate::Resolution; - let file_system = file_system(); let resolver = ResolverGeneric::::new_with_file_system( @@ -108,7 +105,7 @@ fn resolve_to_context() { ]; for (comment, request, expected) in successful_resolves { - let resolution = resolver.resolve("/a", request).map(Resolution::full_path); + let resolution = resolver.resolve("/a", request).map(|r| r.full_path()); assert_eq!(resolution, Ok(PathBuf::from(expected)), "{comment} {request}"); } } diff --git a/crates/oxc_resolver/src/tests/imports_field.rs b/crates/oxc_resolver/src/tests/imports_field.rs index 3dc4bd0ac..fb0152052 100644 --- a/crates/oxc_resolver/src/tests/imports_field.rs +++ b/crates/oxc_resolver/src/tests/imports_field.rs @@ -4,9 +4,7 @@ use serde_json::json; -use crate::{ - MatchObject, PathUtil, Resolution, ResolveContext, ResolveError, ResolveOptions, Resolver, -}; +use crate::{MatchObject, PathUtil, ResolveContext, ResolveError, ResolveOptions, Resolver}; use std::path::Path; #[test] @@ -32,7 +30,7 @@ fn test() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } diff --git a/crates/oxc_resolver/src/tests/resolve.rs b/crates/oxc_resolver/src/tests/resolve.rs index ef9fc8316..fa2b5ab2a 100644 --- a/crates/oxc_resolver/src/tests/resolve.rs +++ b/crates/oxc_resolver/src/tests/resolve.rs @@ -1,6 +1,6 @@ //! -use crate::{Resolution, ResolveOptions, Resolver}; +use crate::{ResolveOptions, Resolver}; #[test] fn resolve() { @@ -43,7 +43,7 @@ fn resolve() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } } @@ -65,7 +65,7 @@ fn prefer_relative() { ]; for (comment, request, expected) in pass { - let resolved_path = resolver.resolve(&f, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {request}"); } } @@ -85,7 +85,7 @@ fn resolve_context() { ]; for (comment, path, request, expected) in data { - let resolved_path = resolver.resolve(&path, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } } diff --git a/crates/oxc_resolver/src/tests/roots.rs b/crates/oxc_resolver/src/tests/roots.rs index f8a384c14..efdfb2583 100644 --- a/crates/oxc_resolver/src/tests/roots.rs +++ b/crates/oxc_resolver/src/tests/roots.rs @@ -2,7 +2,7 @@ use std::{env, path::PathBuf}; -use crate::{AliasValue, Resolution, ResolveError, ResolveOptions, Resolver}; +use crate::{AliasValue, ResolveError, ResolveOptions, Resolver}; fn dirname() -> PathBuf { env::current_dir().unwrap().join("tests/enhanced_resolve/test") @@ -29,7 +29,7 @@ fn roots() { ]; for (comment, request, expected) in pass { - let resolved_path = resolver.resolve(&f, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {request}"); } @@ -52,7 +52,7 @@ fn resolve_to_context() { resolve_to_context: true, ..ResolveOptions::default() }); - let resolved_path = resolver.resolve(&f, "/fixtures/lib").map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, "/fixtures/lib").map(|r| r.full_path()); let expected = f.join("lib"); assert_eq!(resolved_path, Ok(expected)); } @@ -75,7 +75,7 @@ fn prefer_absolute() { ]; for (comment, request, expected) in pass { - let resolved_path = resolver.resolve(&f, &request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, &request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {request}"); } } diff --git a/crates/oxc_resolver/src/tests/scoped_packages.rs b/crates/oxc_resolver/src/tests/scoped_packages.rs index a18d516e6..761cb5b20 100644 --- a/crates/oxc_resolver/src/tests/scoped_packages.rs +++ b/crates/oxc_resolver/src/tests/scoped_packages.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; -use crate::{Resolution, ResolveOptions, Resolver}; +use crate::{ResolveOptions, Resolver}; fn fixture() -> PathBuf { super::fixture().join("scoped") @@ -25,7 +25,7 @@ fn scoped_packages() { ]; for (comment, path, request, expected) in pass { - let resolved_path = resolver.resolve(&f, request).map(Resolution::full_path); + let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); } } diff --git a/crates/oxc_resolver/src/tests/symlink.rs b/crates/oxc_resolver/src/tests/symlink.rs index 145f0501b..a91eb0c98 100644 --- a/crates/oxc_resolver/src/tests/symlink.rs +++ b/crates/oxc_resolver/src/tests/symlink.rs @@ -1,6 +1,6 @@ use std::{env, fs, io, path::Path}; -use crate::{Resolution, ResolveOptions, Resolver}; +use crate::{ResolveOptions, Resolver}; #[derive(Debug, Clone, Copy)] enum FileType { @@ -113,12 +113,12 @@ fn test() -> io::Result<()> { |err| { panic!("{err:?} {comment} {path:?} {request}"); }, - Resolution::full_path, + |r| r.full_path(), ); assert_eq!(filename, root.join("lib/index.js")); let resolved_path = - resolver_without_symlinks.resolve(&path, request).map(Resolution::full_path); + resolver_without_symlinks.resolve(&path, request).map(|r| r.full_path()); assert_eq!(resolved_path, Ok(path.join(request))); }