From 25434df9ddf3f06afd9be03545e0a9cffec8e552 Mon Sep 17 00:00:00 2001 From: gustavo-shigueo Date: Wed, 24 Jul 2024 19:59:43 -0300 Subject: [PATCH] Attempt to fix duplicated NOTE --- ts-rs/src/export.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index d2f4b216..00183c38 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -165,7 +165,7 @@ fn export_and_merge(path: PathBuf, type_name: String, generated_type: String) -> let buffer = merge(original_contents, generated_type); - file.seek(SeekFrom::Start(NOTE.len() as u64))?; + file.seek(SeekFrom::Start(0))?; file.write_all(buffer.as_bytes())?; file.sync_all()?; @@ -195,10 +195,12 @@ fn merge(original_contents: String, new_contents: String) -> String { .collect::>(); let import_len = imports.iter().map(|&x| x.len()).sum::() + imports.len(); - let capacity = import_len + original_decls.len() + new_decl.len() + 2; + let capacity = NOTE.len() + import_len + original_decls.len() + new_decl.len() + 2; let mut buffer = String::with_capacity(capacity); + buffer.push_str(NOTE); + for import in imports { buffer.push_str(import); buffer.push('\n')