Aleph-Alpha / ts-rs

Generate TypeScript bindings from Rust types
MIT License
1.08k stars 107 forks source link

Make `#[ts(export_to = "...")]` relative to `TS_RS_EXPORT_DIR` #250

Closed escritorio-gustavo closed 6 months ago

escritorio-gustavo commented 7 months ago

As discussed in #245, when using both TS_RS_EXPORT_DIR and #[ts(export_to = "...")], the export_to path should be relative to TS_RS_EXPORT_DIR instead of the project's Cargo.toml

escritorio-gustavo commented 7 months ago

This is so annoying, docs.rs passes on my computer, but not on ci

escritorio-gustavo commented 7 months ago

That's weird, changing the order of the tests changed which one failed

NyxCode commented 7 months ago

I don't quite understand what's going on, but it seems like TS_RS_EXPORT_DIR is not respected.

in export_type, we call output_path, but that doen't take TS_RS_EXPORT_DIr into account at all.

NyxCode commented 7 months ago

Running TS_RS_EXPORT_DIR=./custom cargo test -- export_bindings still puts everything in tests-out

escritorio-gustavo commented 7 months ago

I finished moving std::env::var outside of the macro. The only downside to this is that T::EXPORT_TO doesn't actually correspond to the exported path anymore, due to the lack of TS_RS_EXPORT_DIR, but this should reduce the amount of compilation going on in the user's machine

escritorio-gustavo commented 7 months ago

I could add a method that returns the proper path to remedy this

escritorio-gustavo commented 7 months ago

The reason I was thinking about adding it to TS is because of the tests that read the exported file, all of them have a bunch of weird stuff to handle TS_RS_EXPORT_DIR

NyxCode commented 7 months ago

Yeah, that's a good point. If you think it makes sense, go for it!

escritorio-gustavo commented 7 months ago

I agree that the function that returns the path should never be overwritten. Maybe a pub fn would be better than a new TS method then?

Making output_path public would probably do the trick