Skip to content

Commit

Permalink
Fix convert_path_to_posix for mixed paths (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Nicklas <[email protected]>
  • Loading branch information
devbrains-com and jantimon authored Dec 17, 2024
1 parent 02b9c80 commit 859db1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/perfect-countries-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"yak-swc": patch
---

Improve cross-os hashes to be more consistent.
11 changes: 11 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ jobs:
with:
node-version: 20

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Enable caching
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/yak-swc

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
Expand Down
1 change: 1 addition & 0 deletions packages/yak-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"scripts": {
"build": "cargo build --release --target=wasm32-wasi",
"prepublishOnly": "npm run build",
"prettier": "cargo fmt --all",
"test": "cargo test",
"test:snapshots": "cd yak_swc && UPDATE=1 cargo test"
},
Expand Down
10 changes: 9 additions & 1 deletion packages/yak-swc/relative_posix_path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn relative_posix_path(base_path: &str, filename: &str) -> String {
/// - "/foo/bar" -> "/foo/bar"
fn convert_path_to_posix(path: &str) -> String {
lazy_static! {
static ref PATH_REPLACEMENT_REGEX: Regex = Regex::new(r":\\|\\").unwrap();
static ref PATH_REPLACEMENT_REGEX: Regex = Regex::new(r":\\|\\|:/").unwrap();
}

PATH_REPLACEMENT_REGEX.replace_all(path, "/").to_string()
Expand All @@ -56,6 +56,14 @@ mod tests {
);
}

#[test]
fn test_relative_path_windows_forward_slash() {
assert_eq!(
relative_posix_path(r"E:\foo", "E:/foo/bar/file.tsx"),
"bar/file.tsx"
);
}

#[test]
fn test_convert_unix_path() {
assert_eq!(convert_path_to_posix(r"/foo/bar"), "/foo/bar");
Expand Down

0 comments on commit 859db1c

Please sign in to comment.