-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(transforms/module): replace canonicalization with clean to not mess up symlinks #11585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
5e458f9
09f0105
e070d00
5fb410a
152d817
1dbd3eb
3c0467f
f6353f5
18cf53e
d81aaf3
9e5fc33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| swc_ecma_transforms_module: patch | ||
| swc: patch | ||
| --- | ||
|
|
||
| fix(transforms/module): replace `canonicalize()` with `path_clean` to avoid resolving symlinks during module resolution |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ use dashmap::DashMap; | |
| use either::Either; | ||
| use indexmap::IndexMap; | ||
| use once_cell::sync::Lazy; | ||
| #[cfg(feature = "module")] | ||
| use path_clean::PathClean; | ||
| use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use swc_atoms::Atom; | ||
|
|
@@ -1612,9 +1614,24 @@ impl ModuleConfig { | |
| return None; | ||
| } | ||
|
|
||
| // Normalize the base path without resolving symlinks. | ||
| // Using `.clean()` instead of `.canonicalize()` keeps symlinked | ||
| // paths intact, which is required for correct relative-path | ||
| // computation in `diff_paths` (both base and target must live | ||
| // in the same "path space"). | ||
| // | ||
| // https://github.com/swc-project/swc/issues/8265 | ||
| // https://github.com/swc-project/swc/issues/11584 | ||
| let base = match base { | ||
| FileName::Real(v) if !skip_resolver => { | ||
| FileName::Real(v.canonicalize().unwrap_or_else(|_| v.to_path_buf())) | ||
| let cleaned = if v.is_absolute() { | ||
| v.clean() | ||
| } else { | ||
| env::current_dir() | ||
| .map(|cwd| cwd.join(v).clean()) | ||
| .unwrap_or_else(|_| v.to_path_buf()) | ||
|
||
| }; | ||
| FileName::Real(cleaned) | ||
| } | ||
| _ => base.clone(), | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| use std::{ | ||
| borrow::Cow, | ||
| env::current_dir, | ||
| fs::canonicalize, | ||
| io, | ||
| path::{Component, Path, PathBuf}, | ||
| sync::Arc, | ||
|
|
@@ -254,13 +253,15 @@ where | |
| } | ||
| }; | ||
|
|
||
| // Bazel uses symlink | ||
| // Clean the resolved path to normalize `.` and `..` components | ||
| // without resolving symlinks. Previously this used `canonicalize()` | ||
| // which resolved symlinks, breaking setups where symlinked source | ||
| // files need imports resolved relative to the symlink location. | ||
| // | ||
| // https://github.com/swc-project/swc/issues/8265 | ||
| if let FileName::Real(resolved) = &target.filename { | ||
| if let Ok(orig) = canonicalize(resolved) { | ||
| target.filename = FileName::Real(orig); | ||
| } | ||
| // https://github.com/swc-project/swc/issues/11584 | ||
| if let FileName::Real(resolved) = &mut target.filename { | ||
| *resolved = resolved.clean(); | ||
perbergland marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On Windows, replacing canonicalization with Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| let Resolution { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.