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

feat: Allow multiple types to set #[ts(export_to = "...")] to the same file #316

Merged
merged 36 commits into from
Aug 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dfaa802
Allow for multiple types to be exported to the same file
escritorio-gustavo May 10, 2024
784eecd
Allow for multiple types to be exported to the same file
escritorio-gustavo May 10, 2024
f4f59e9
Merge remote-tracking branch 'refs/remotes/origin/export_same_file'
escritorio-gustavo May 10, 2024
294126c
Prevent duplication
escritorio-gustavo May 10, 2024
7312fa1
If types exported to the same file depend on each other, they should …
escritorio-gustavo May 10, 2024
4dc1c17
Fix import-esm case
escritorio-gustavo May 10, 2024
892b11b
Fix import-esm case
escritorio-gustavo May 10, 2024
27832ee
Change read_exact for seek
escritorio-gustavo May 10, 2024
c7b170e
Remove unneded clone
escritorio-gustavo May 10, 2024
8d32a0e
Merge branch 'main' into export_same_file
escritorio-gustavo May 20, 2024
fbe8e72
Merge branch 'main' into export_same_file
escritorio-gustavo May 20, 2024
939041e
Remove duplicate declaration
escritorio-gustavo May 20, 2024
a3ed6d8
Reduce amount of syscalls and memory allocations
escritorio-gustavo May 22, 2024
121ac37
Replace negated condition with guard clause
escritorio-gustavo May 22, 2024
70a3c12
Merge branch 'main' into export_same_file
escritorio-gustavo Jun 5, 2024
8e3e59f
Fix compiler error
escritorio-gustavo Jun 5, 2024
5f41c0d
Merge branch 'main' into export_same_file
gustavo-shigueo Jul 24, 2024
9db3a90
Merge branch 'main' into export_same_file
gustavo-shigueo Jul 24, 2024
b80240e
Fix double blank line
gustavo-shigueo Jul 24, 2024
4344480
Make test more robust by checking if all exports are in file
gustavo-shigueo Jul 24, 2024
6a962c0
Update CHANGELOG
gustavo-shigueo Jul 24, 2024
a5a3fba
Failure report
gustavo-shigueo Jul 24, 2024
cd37d20
Account for the format feature
gustavo-shigueo Jul 24, 2024
04c1ec4
Make type order deterministic
gustavo-shigueo Jul 24, 2024
9db2c1c
Ignore JSDoc when sorting declarations
gustavo-shigueo Jul 24, 2024
419044f
Only consider type name when sorting declarations
gustavo-shigueo Jul 24, 2024
8a43254
Fix slice index
gustavo-shigueo Jul 24, 2024
bc10807
Get type name without index math
gustavo-shigueo Jul 24, 2024
25434df
Attempt to fix duplicated NOTE
gustavo-shigueo Jul 24, 2024
dedfba5
Guarantee that the type name will be used
gustavo-shigueo Jul 24, 2024
ad1b46e
Fix double header error
gustavo-shigueo Jul 25, 2024
d124d7b
Allocate less space for buffer by having the note from the original f…
gustavo-shigueo Jul 25, 2024
6ec0871
Merge branch 'main' into export_same_file
gustavo-shigueo Jul 25, 2024
a107e97
Merge branch 'main' into export_same_file
gustavo-shigueo Jul 25, 2024
5c889c9
Merge branch 'main' into export_same_file
gustavo-shigueo Jul 25, 2024
5374370
Revert rename to avoid conflicts with other branches
gustavo-shigueo Aug 1, 2024
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
8 changes: 4 additions & 4 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ fn export_and_merge(path: PathBuf, type_name: String, generated_type: String) ->
.write(true)
.open(&path)?;

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);
Copy link
Collaborator

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

file.read_to_string(&mut original_contents)?;

let buffer = merge(original_contents, generated_type);
Expand Down Expand Up @@ -189,9 +189,9 @@ fn merge(original_contents: String, new_contents: String) -> String {
let (new_header, new_decl) = new_contents.split_once("\n\n").expect(HEADER_ERROR_MESSAGE);

let imports = original_header
.trim_start_matches(NOTE)
.lines()
.chain(new_header.trim_start_matches(NOTE).lines())
.skip(1)
.chain(new_header.lines().skip(1))
.collect::<BTreeSet<_>>();

let import_len = imports.iter().map(|&x| x.len()).sum::<usize>() + imports.len();
Expand Down