Skip to content

Commit

Permalink
fix(rolldown_fs): canonicalize polyfill on wasi platform (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Jun 24, 2024
1 parent 4e7dff8 commit 2530866
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/reusable-wasi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ jobs:
with:
submodules: true # Pull submodules for additional files

- name: Prepare pnpm install
# Node.js wasi runtime has bug with `std::fs::read_link`
run: |
touch .npmrc
echo "node-linker=hoisted" >> .npmrc
- name: Setup Node
uses: ./.github/actions/setup-node

Expand Down
29 changes: 28 additions & 1 deletion crates/rolldown_fs/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ impl OxcResolverFileSystem for OsFileSystem {
}

fn canonicalize(&self, path: &Path) -> io::Result<PathBuf> {
dunce::canonicalize(path)
#[cfg(not(target_os = "wasi"))]
{
dunce::canonicalize(path)
}
#[cfg(target_os = "wasi")]
{
let meta = std::fs::symlink_metadata(path)?;
if meta.file_type().is_symlink() {
let link = std::fs::read_link(path)?;
let mut path_buf = path.to_path_buf();
path_buf.pop();
for segment in link.iter() {
match segment.to_str() {
Some("..") => {
path_buf.pop();
}
Some(".") | None => {}
Some(seg) => {
// Need to trim the extra \0 introduces by rust std rust-lang/rust#123727
path_buf.push(seg.trim_end_matches('\0'));
}
}
}
Ok(path_buf)
} else {
Ok(path.to_path_buf())
}
}
}
}

0 comments on commit 2530866

Please sign in to comment.