From 39778530f291f66611b6ce8e44e273732122cd37 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:15:03 +0900 Subject: [PATCH 1/4] test: fix symlink test init on windows --- src/tests/symlink.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tests/symlink.rs b/src/tests/symlink.rs index 7589b560..e3ca508d 100644 --- a/src/tests/symlink.rs +++ b/src/tests/symlink.rs @@ -33,9 +33,7 @@ fn init(dirname: &Path, temp_path: &Path) -> io::Result<()> { fs::create_dir(temp_path)?; symlink(dirname.join("../lib/index.js"), temp_path.join("test"), FileType::File)?; symlink(dirname.join("../lib"), temp_path.join("test2"), FileType::Dir)?; - fs::remove_file(temp_path.join("test"))?; - fs::remove_file(temp_path.join("test2"))?; - fs::remove_dir(temp_path) + fs::remove_dir_all(temp_path) } fn create_symlinks(dirname: &Path, temp_path: &Path) -> io::Result<()> { From fbec2217cbae453aca922eb5f8f7bd962bec7a91 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:20:44 +0900 Subject: [PATCH 2/4] test: skip two tests on Windows --- src/tests/symlink.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/symlink.rs b/src/tests/symlink.rs index e3ca508d..83ae265b 100644 --- a/src/tests/symlink.rs +++ b/src/tests/symlink.rs @@ -82,7 +82,9 @@ fn test() -> io::Result<()> { #[rustfmt::skip] let pass = [ ("with a symlink to a file", temp_path.clone(), "./index.js"), + #[cfg(not (windows))] // https://github.com/oxc-project/oxc-resolver/issues/308 ("with a relative symlink to a file", temp_path.clone(), "./node.relative.js"), + #[cfg(not (windows))] // https://github.com/oxc-project/oxc-resolver/issues/308 ("with a relative symlink to a symlink to a file", temp_path.clone(), "./node.relative.sym.js"), ("with a symlink to a directory 1", temp_path.clone(), "./lib/index.js"), ("with a symlink to a directory 2", temp_path.clone(), "./this/lib/index.js"), From dfda374c5114d3a0316dd94b8c716b2e182b542b Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:34:50 +0900 Subject: [PATCH 3/4] test: fix relative symlink file tests --- src/tests/symlink.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tests/symlink.rs b/src/tests/symlink.rs index 83ae265b..c771181c 100644 --- a/src/tests/symlink.rs +++ b/src/tests/symlink.rs @@ -1,5 +1,7 @@ use std::{fs, io, path::Path}; +use normalize_path::NormalizePath; + use crate::{ResolveOptions, Resolver}; #[derive(Debug, Clone, Copy)] @@ -21,8 +23,10 @@ fn symlink, Q: AsRef>( #[cfg(target_family = "windows")] match file_type { - FileType::File => std::os::windows::fs::symlink_file(original, link), - FileType::Dir => std::os::windows::fs::symlink_dir(original, link), + // NOTE: original path should use `\` instead of `/` for relative paths + // otherwise the symlink will be broken and the test will fail with InvalidFilename error + FileType::File => std::os::windows::fs::symlink_file(original.as_ref().normalize(), link), + FileType::Dir => std::os::windows::fs::symlink_dir(original.as_ref().normalize(), link), } } @@ -46,9 +50,9 @@ fn create_symlinks(dirname: &Path, temp_path: &Path) -> io::Result<()> { symlink(dirname.join("../lib").canonicalize().unwrap(), temp_path.join("lib"), FileType::Dir)?; symlink(dirname.join("..").canonicalize().unwrap(), temp_path.join("this"), FileType::Dir)?; symlink(temp_path.join("this"), temp_path.join("that"), FileType::Dir)?; - symlink(Path::new("../../lib/index.js"), temp_path.join("node.relative.js"), FileType::File)?; + symlink(Path::new("../../lib/index.js").normalize(), temp_path.join("node.relative.js"), FileType::File)?; symlink( - Path::new("./node.relative.js"), + Path::new("./node.relative.js").normalize(), temp_path.join("node.relative.sym.js"), FileType::File, )?; @@ -82,9 +86,7 @@ fn test() -> io::Result<()> { #[rustfmt::skip] let pass = [ ("with a symlink to a file", temp_path.clone(), "./index.js"), - #[cfg(not (windows))] // https://github.com/oxc-project/oxc-resolver/issues/308 ("with a relative symlink to a file", temp_path.clone(), "./node.relative.js"), - #[cfg(not (windows))] // https://github.com/oxc-project/oxc-resolver/issues/308 ("with a relative symlink to a symlink to a file", temp_path.clone(), "./node.relative.sym.js"), ("with a symlink to a directory 1", temp_path.clone(), "./lib/index.js"), ("with a symlink to a directory 2", temp_path.clone(), "./this/lib/index.js"), From fb2c1eaa03f17fd2b4832f55a290a2329277933a Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:36:34 +0900 Subject: [PATCH 4/4] chore: reduce diff --- src/tests/symlink.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/symlink.rs b/src/tests/symlink.rs index c771181c..c9399a2e 100644 --- a/src/tests/symlink.rs +++ b/src/tests/symlink.rs @@ -50,9 +50,9 @@ fn create_symlinks(dirname: &Path, temp_path: &Path) -> io::Result<()> { symlink(dirname.join("../lib").canonicalize().unwrap(), temp_path.join("lib"), FileType::Dir)?; symlink(dirname.join("..").canonicalize().unwrap(), temp_path.join("this"), FileType::Dir)?; symlink(temp_path.join("this"), temp_path.join("that"), FileType::Dir)?; - symlink(Path::new("../../lib/index.js").normalize(), temp_path.join("node.relative.js"), FileType::File)?; + symlink(Path::new("../../lib/index.js"), temp_path.join("node.relative.js"), FileType::File)?; symlink( - Path::new("./node.relative.js").normalize(), + Path::new("./node.relative.js"), temp_path.join("node.relative.sym.js"), FileType::File, )?;