Skip to content
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

bug: Fix issue with absolute paths #323

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ jobs:
tsc output/**/*.ts --noEmit --noUnusedLocals --strict
rm -rf output

test-absolute-export-env:
name: Test ts-rs with absolute TS_RS_EXPORT_DIR
runs-on: ubuntu-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
run: |
TS_RS_EXPORT_DIR=$(pwd)/output cargo test --no-default-features
shopt -s globstar
tsc output/**/*.ts --noEmit --noUnusedLocals --strict
rm -rf output

test-no-features:
name: Test ts-rs with --no-default-features
runs-on: ubuntu-latest
Expand Down
8 changes: 1 addition & 7 deletions ts-rs/src/export/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ use super::ExportError as E;

const ERROR_MESSAGE: &str = r#"The path provided with `#[ts(export_to = "..")]` is not valid"#;
pub fn absolute<T: AsRef<Path>>(path: T) -> Result<PathBuf, E> {
let path = path.as_ref();

if path.is_absolute() {
return Ok(path.to_owned());
}

let path = std::env::current_dir()?.join(path);
let path = std::env::current_dir()?.join(path.as_ref());

let mut out = Vec::new();
for comp in path.components() {
Expand Down
2 changes: 1 addition & 1 deletion ts-rs/tests/integration/issue_317.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct VariantId(u32);
#[ts(export_to = "issue_317/")]
struct VariantOverview {
id: u32,
name: String
name: String,
}

#[derive(TS)]
Expand Down
2 changes: 1 addition & 1 deletion ts-rs/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod infer_as;
mod issue_168;
mod issue_232;
mod issue_308;
mod issue_317;
mod issue_70;
mod issue_80;
mod leading_colon;
Expand Down Expand Up @@ -59,4 +60,3 @@ mod union_with_data;
mod union_with_internal_tag;
mod unit;
mod r#unsized;
mod issue_317;