Skip to content

Commit

Permalink
Always use forward slash on import paths (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-shigueo authored Aug 9, 2024
1 parent 5cbc740 commit 78591a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,27 @@ jobs:
shopt -s globstar
tsc bindings/**/*.ts --noEmit --noUnusedLocals
rm -rf bindings
test-windows:
name: Test ts-rs with --all-features on Windows
runs-on: windows-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- uses: actions/checkout@v4
- uses: rui314/setup-mold@v1
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Test
working-directory: ts-rs
# Create empty tsconfig and cd into bindings to make tsc
# compile every ts file in the directory
run: |
cargo test --all-features
"{}" | Out-File bindings/tsconfig.json
cd bindings
npm i -g typescript
tsc --noEmit --noUnusedLocals --strict
cd ..
rm -r -fo bindings
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target/
/.idea
*.ts
tsconfig.json

/ts-rs/tests-out
14 changes: 11 additions & 3 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn generate_imports<T: TS + ?Sized + 'static>(

writeln!(
out,
"import type {{ {} }} from {:?};",
r#"import type {{ {} }} from "{}";"#,
&dep.ts_name, rel_path
)?;
}
Expand All @@ -334,11 +334,19 @@ fn generate_imports<T: TS + ?Sized + 'static>(
/// Returns the required import path for importing `import` from the file `from`
fn import_path(from: &Path, import: &Path) -> Result<String, ExportError> {
let rel_path = diff_paths(import, from.parent().unwrap())?;
let path = match rel_path.components().next() {
Some(Component::Normal(_)) => format!("./{}", rel_path.to_string_lossy()),
let str_path = match rel_path.components().next() {
Some(Component::Normal(_)) => {
format!("./{}", rel_path.to_string_lossy())
}
_ => rel_path.to_string_lossy().into(),
};

let path = if cfg!(target_os = "windows") {
str_path.replace('\\', "/")
} else {
str_path
};

let path_without_extension = path.trim_end_matches(".ts");

Ok(if cfg!(feature = "import-esm") {
Expand Down

0 comments on commit 78591a2

Please sign in to comment.