-
Notifications
You must be signed in to change notification settings - Fork 111
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
feat: Allow multiple types to set #[ts(export_to = "...")]
to the same file
#316
Conversation
…not generate an import statement
#[ts(export_to = "...")]
to the same file
#[ts(export_to = "...")]
to the same file#[ts(export_to = "...")]
to the same file
+1, looking forward to this! |
Hey @arslnb! This feature is pretty much done, but I'd still like to make sure it doesn't break anything. If you have any projects that would benefit from this, would mind testing out this branch and checking if your resulting TypeScript is correct? |
Hey @NyxCode! Can you check this one out when you have some time? |
The sorting seems to be fixed, but I still see the header generated comment twice. Not a big deal, I'm just sharing what I see ;) |
Slightly improved this by getting the last |
Did this happen with the version from crates.io? The docs feature was made with |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
ts-rs/src/export.rs
Outdated
let file_len = file.metadata()?.len() as usize; | ||
let file_len = file.metadata()?.len(); | ||
|
||
let mut original_contents = String::with_capacity(file_len); | ||
let mut original_contents = String::with_capacity(file_len as usize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change does nothing, it was leftover from when I was testing something else
I can confirm the double header issue is fixed :] |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@NyxCode I think this PR should be ready for merging, do you have anything you'd like to be changed here beforehand? |
This should now be fixed too |
Oh this would be neat. For example I got a ton of types, Though I understand that might be beyond what this is attempting to do, A great feature nonetheless :) |
There is the To use it, create a file at: [env]
TS_RS_EXPORT_DIR = { value = "<PATH_RELATIVE_TO_CARGO_TOML>", relative = true } Development history of
If you mean "export everything to the same file", then yeah, it is kinda out of the scope of this PR. It could be possible to have a different environment variable for it, but the CLI being developed in #304 accomplishes this and checks for naming collisions better than would be possible here |
Any idea when this will be officially released? I know I can use a pointer to a github commit, but still ;) |
I think this feature will go into version 10 due to some breaking changes in other PRs, but I have to check with @NyxCode about that |
Goal
Allow for multiple types to be exported to the same file by editing the target file when it is encountered by the second time
Closes #59
Changes
Created a
HashMap
mapping file paths to a set of type identifiers and using it to decide whether or not the file should be created from scratch or editedChecklist