From a96844118c24d870abfe5332547dab99dc53d09c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 27 May 2023 10:33:15 -0400 Subject: fix(compile): inline symlinks as files outside node_modules dir and warn for directories (#19285) If a symlink within the `node_modules` directory lies outside that directory, it will now warn and inline the file. For directories, it will just warn for now. Probably fixes #19251 (I'm still unable to reproduce). --- test_util/src/temp_dir.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test_util/src') diff --git a/test_util/src/temp_dir.rs b/test_util/src/temp_dir.rs index f0f866d88..f66bf1398 100644 --- a/test_util/src/temp_dir.rs +++ b/test_util/src/temp_dir.rs @@ -80,4 +80,40 @@ impl TempDir { pub fn write(&self, path: impl AsRef, text: impl AsRef) { fs::write(self.path().join(path), text.as_ref()).unwrap(); } + + pub fn symlink_dir( + &self, + oldpath: impl AsRef, + newpath: impl AsRef, + ) { + #[cfg(unix)] + { + use std::os::unix::fs::symlink; + symlink(self.path().join(oldpath), self.path().join(newpath)).unwrap(); + } + #[cfg(not(unix))] + { + use std::os::windows::fs::symlink_dir; + symlink_dir(self.path().join(oldpath), self.path().join(newpath)) + .unwrap(); + } + } + + pub fn symlink_file( + &self, + oldpath: impl AsRef, + newpath: impl AsRef, + ) { + #[cfg(unix)] + { + use std::os::unix::fs::symlink; + symlink(self.path().join(oldpath), self.path().join(newpath)).unwrap(); + } + #[cfg(not(unix))] + { + use std::os::windows::fs::symlink_file; + symlink_file(self.path().join(oldpath), self.path().join(newpath)) + .unwrap(); + } + } } -- cgit v1.2.3