From 4570d9e3de8a7a7a06309c99851910d64cedd127 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 9 Apr 2024 16:27:38 -0300 Subject: [PATCH 01/44] CLI initial concept --- Cargo.toml | 2 +- cli/Cargo.toml | 9 ++++ cli/src/main.rs | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 cli/Cargo.toml create mode 100644 cli/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index df5d7896..85309d7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["macros", "ts-rs", "example"] +members = ["macros", "ts-rs", "example", "cli"] resolver = "2" diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 00000000..c098d6ce --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "cargo-ts" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4", features = ["derive"]} diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 00000000..6bb7d10b --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,118 @@ +use std::path::PathBuf; + +use clap::Parser; + +#[derive(Parser, Debug)] +struct Args { + /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR + #[arg(long, short)] + output_directory: PathBuf, + + /// Disables serde compatibility + #[arg(long)] + disable_serde: bool, + + /// Disables warnings caused by using serde attributes that ts-rs cannot process + #[arg(long)] + no_warnings: bool, + + /// Adds the ".js" extension to import paths + #[arg(long)] + esm_imports: bool, + + /// Formats the generated TypeScript files + #[arg(long)] + format: bool, + + /// Enables chrono compatibility + #[arg(long)] + chrono: bool, + + /// Enables bigdecimal compatibility + #[arg(long)] + bigdecimal: bool, + + /// Enables uuid compatibility + #[arg(long)] + uuid: bool, + + /// Enables bson compatibility + #[arg(long)] + bson: bool, + + /// Enables bytes compatibility + #[arg(long)] + bytes: bool, + + /// Enables url compatibility + #[arg(long)] + url: bool, + + /// Enables indexmap compatibility + #[arg(long)] + indexmap: bool, + + /// Enables ordered-float compatibility + #[arg(long)] + ordered_float: bool, + + /// Enables heapless compatibility + #[arg(long)] + heapless: bool, + + /// Enables semver compatibility + #[arg(long)] + semver: bool, + + /// Enables serde_json compatibility + #[arg(long)] + serde_json: bool, +} + +macro_rules! feature { + ($cargo_invocation: expr, $args: expr, { $($field: ident => $feature: literal),* $(,)? }) => { + $( + if $args.$field { + $cargo_invocation + .arg("--feature") + .arg(format!("ts-rs/{}", $feature)); + } + )* + }; +} + +fn main() { + let args = Args::parse(); + + println!("{args:?}"); + + let mut cargo_invocation = std::process::Command::new("cargo"); + + cargo_invocation + .arg("test") + .arg("export_bindings_") + .env("TS_RS_EXPORT_DIR", args.output_directory); + + if args.disable_serde { + cargo_invocation.arg("--no-default-features"); + } + + feature!(cargo_invocation, args, { + no_warnings => "no-serde-warnings", + esm_imports => "import-esm", + format => "format", + chrono => "chrono-impl", + bigdecimal => "bigdecimal-impl", + uuid => "uuid-impl", + bson => "bson-impl", + bytes => "bytes-impl", + url => "url-impl", + indexmap => "indexmap-impl", + ordered_float => "ordered-float-impl", + heapless => "heapless-impl", + semver => "semver-impl", + serde_json => "serde-json-impl" + }); + + cargo_invocation.spawn().unwrap().wait().unwrap(); +} From 7c151804630705086b3495616b9a15fe4431acd7 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 9 Apr 2024 16:59:59 -0300 Subject: [PATCH 02/44] Add --add-features flag, fix feature! macro and bson-uuid-impl --- cli/src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 6bb7d10b..0dd4a50b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -5,9 +5,13 @@ use clap::Parser; #[derive(Parser, Debug)] struct Args { /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR - #[arg(long, short)] + #[arg(long, short, default_value = "./bindings")] output_directory: PathBuf, + /// Enables all of ts-rs's feature flags + #[arg(long)] + all_features: bool, + /// Disables serde compatibility #[arg(long)] disable_serde: bool, @@ -36,9 +40,9 @@ struct Args { #[arg(long)] uuid: bool, - /// Enables bson compatibility + /// Enables bson-uuid compatibility #[arg(long)] - bson: bool, + bson_uuid: bool, /// Enables bytes compatibility #[arg(long)] @@ -72,9 +76,9 @@ struct Args { macro_rules! feature { ($cargo_invocation: expr, $args: expr, { $($field: ident => $feature: literal),* $(,)? }) => { $( - if $args.$field { + if $args.$field || $args.all_features { $cargo_invocation - .arg("--feature") + .arg("--features") .arg(format!("ts-rs/{}", $feature)); } )* @@ -84,7 +88,9 @@ macro_rules! feature { fn main() { let args = Args::parse(); - println!("{args:?}"); + if args.disable_serde && args.all_features { + panic!(r#""--disable-serde" and "--all-features" are not compatible"#) + } let mut cargo_invocation = std::process::Command::new("cargo"); @@ -104,7 +110,7 @@ fn main() { chrono => "chrono-impl", bigdecimal => "bigdecimal-impl", uuid => "uuid-impl", - bson => "bson-impl", + bson_uuid => "bson-uuid-impl", bytes => "bytes-impl", url => "url-impl", indexmap => "indexmap-impl", From 1518c18f9bf6f1a7c10b074299faba81f5339e30 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 10 Apr 2024 11:20:50 -0300 Subject: [PATCH 03/44] Remove *-impl features from CLI --- cli/src/main.rs | 73 +------------------------------------------------ 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 0dd4a50b..d5b03223 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -8,14 +8,6 @@ struct Args { #[arg(long, short, default_value = "./bindings")] output_directory: PathBuf, - /// Enables all of ts-rs's feature flags - #[arg(long)] - all_features: bool, - - /// Disables serde compatibility - #[arg(long)] - disable_serde: bool, - /// Disables warnings caused by using serde attributes that ts-rs cannot process #[arg(long)] no_warnings: bool, @@ -27,56 +19,12 @@ struct Args { /// Formats the generated TypeScript files #[arg(long)] format: bool, - - /// Enables chrono compatibility - #[arg(long)] - chrono: bool, - - /// Enables bigdecimal compatibility - #[arg(long)] - bigdecimal: bool, - - /// Enables uuid compatibility - #[arg(long)] - uuid: bool, - - /// Enables bson-uuid compatibility - #[arg(long)] - bson_uuid: bool, - - /// Enables bytes compatibility - #[arg(long)] - bytes: bool, - - /// Enables url compatibility - #[arg(long)] - url: bool, - - /// Enables indexmap compatibility - #[arg(long)] - indexmap: bool, - - /// Enables ordered-float compatibility - #[arg(long)] - ordered_float: bool, - - /// Enables heapless compatibility - #[arg(long)] - heapless: bool, - - /// Enables semver compatibility - #[arg(long)] - semver: bool, - - /// Enables serde_json compatibility - #[arg(long)] - serde_json: bool, } macro_rules! feature { ($cargo_invocation: expr, $args: expr, { $($field: ident => $feature: literal),* $(,)? }) => { $( - if $args.$field || $args.all_features { + if $args.$field { $cargo_invocation .arg("--features") .arg(format!("ts-rs/{}", $feature)); @@ -88,10 +36,6 @@ macro_rules! feature { fn main() { let args = Args::parse(); - if args.disable_serde && args.all_features { - panic!(r#""--disable-serde" and "--all-features" are not compatible"#) - } - let mut cargo_invocation = std::process::Command::new("cargo"); cargo_invocation @@ -99,25 +43,10 @@ fn main() { .arg("export_bindings_") .env("TS_RS_EXPORT_DIR", args.output_directory); - if args.disable_serde { - cargo_invocation.arg("--no-default-features"); - } - feature!(cargo_invocation, args, { no_warnings => "no-serde-warnings", esm_imports => "import-esm", format => "format", - chrono => "chrono-impl", - bigdecimal => "bigdecimal-impl", - uuid => "uuid-impl", - bson_uuid => "bson-uuid-impl", - bytes => "bytes-impl", - url => "url-impl", - indexmap => "indexmap-impl", - ordered_float => "ordered-float-impl", - heapless => "heapless-impl", - semver => "semver-impl", - serde_json => "serde-json-impl" }); cargo_invocation.spawn().unwrap().wait().unwrap(); From 257d04e8d7d1addcf7e81e72f4108273cbbb40fd Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 10 Apr 2024 14:17:38 -0300 Subject: [PATCH 04/44] Gate test generation behind cargo feature --- cli/src/main.rs | 2 ++ macros/Cargo.toml | 1 + macros/src/lib.rs | 5 ++--- ts-rs/Cargo.toml | 1 + ts-rs/tests/path_bug.rs | 4 ++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index d5b03223..52c8c03a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -41,6 +41,8 @@ fn main() { cargo_invocation .arg("test") .arg("export_bindings_") + .arg("--features") + .arg("ts-rs/export") .env("TS_RS_EXPORT_DIR", args.output_directory); feature!(cargo_invocation, args, { diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 7373256d..9144abf4 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/Aleph-Alpha/ts-rs" [features] serde-compat = ["termcolor"] no-serde-warnings = [] +export = [] [lib] proc-macro = true diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 8ec15668..6055a2a1 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -35,9 +35,8 @@ struct DerivedTS { impl DerivedTS { fn into_impl(mut self, rust_ty: Ident, generics: Generics) -> TokenStream { - let export = self - .export - .then(|| self.generate_export_test(&rust_ty, &generics)); + let allow_export = cfg!(feature = "export") && self.export; + let export = allow_export.then(|| self.generate_export_test(&rust_ty, &generics)); let output_path_fn = { let path = match self.export_to.as_deref() { diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index a4687ba8..d58fc93d 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -34,6 +34,7 @@ semver-impl = ["semver"] serde-json-impl = ["serde_json"] no-serde-warnings = ["ts-rs-macros/no-serde-warnings"] import-esm = [] +export = ["ts-rs-macros/export"] [dev-dependencies] serde = { version = "1.0", features = ["derive"] } diff --git a/ts-rs/tests/path_bug.rs b/ts-rs/tests/path_bug.rs index 12ade1bf..4c48c6ba 100644 --- a/ts-rs/tests/path_bug.rs +++ b/ts-rs/tests/path_bug.rs @@ -2,7 +2,7 @@ use ts_rs::TS; #[derive(TS)] -#[ts(export, export_to = "path_bug/aaa/")] +#[ts(export_to = "path_bug/aaa/")] struct Foo { bar: Bar, } @@ -15,7 +15,7 @@ struct Bar { #[test] fn path_bug() { - export_bindings_foo(); + Foo::export_all().unwrap(); assert!(Foo::default_output_path().unwrap().is_file()); assert!(Bar::default_output_path().unwrap().is_file()); From 27669f17f5d364667a837b9bb1db659e438d98a5 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 10 Apr 2024 14:20:15 -0300 Subject: [PATCH 05/44] Update Github action --- .github/workflows/test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13944ed3..deff1a7c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,12 +14,12 @@ jobs: - name: dependencies e2e test working-directory: e2e/dependencies/consumer run: | - cargo t + cargo t --features ts-rs/export tsc bindings/* --noEmit --noUnusedLocals --strict - name: dependencies e2e test with default export env working-directory: e2e/dependencies/consumer run: | - TS_RS_EXPORT_DIR=custom-bindings cargo t + TS_RS_EXPORT_DIR=custom-bindings cargo t --features ts-rs/export shopt -s globstar tsc custom-bindings/**/*.ts --noEmit --noUnusedLocals --strict e2e-workspace: @@ -35,14 +35,14 @@ jobs: - name: workspace e2e test working-directory: e2e/workspace run: | - cargo t + cargo t --features ts-rs/export shopt -s globstar tsc parent/bindings/**/*.ts --noEmit --noUnusedLocals --strict rm -rf parent/bindings - name: workspace e2e with default export env working-directory: e2e/workspace run: | - TS_RS_EXPORT_DIR=custom-bindings cargo t + TS_RS_EXPORT_DIR=custom-bindings cargo t --features ts-rs/export shopt -s globstar tsc parent/custom-bindings/**/*.ts --noEmit --noUnusedLocals --strict rm -rf parent/custom-bindings @@ -59,12 +59,12 @@ jobs: - name: example e2e test working-directory: example run: | - cargo t + cargo t --features ts-rs/export tsc bindings/* --noEmit - name: example e2e with default export env working-directory: example run: | - TS_RS_EXPORT_DIR=custom-bindings cargo t + TS_RS_EXPORT_DIR=custom-bindings cargo t --features ts-rs/export shopt -s globstar tsc custom-bindings/**/*.ts --noEmit --noUnusedLocals --strict @@ -113,7 +113,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Test run: | - TS_RS_EXPORT_DIR=output cargo test --no-default-features + TS_RS_EXPORT_DIR=output cargo test --no-default-features --features ts-rs/export shopt -s globstar tsc ts-rs/output/**/*.ts --noEmit --noUnusedLocals --strict rm -rf ts-rs/output @@ -130,7 +130,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Test run: | - cargo test --no-default-features + cargo test --no-default-features --features ts-rs/export shopt -s globstar tsc ts-rs/bindings/**/*.ts --noEmit --noUnusedLocals rm -rf ts-rs/bindings From ca3eb2387493a23f46840a4ea9a09369e6f003fe Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 10 Apr 2024 15:00:27 -0300 Subject: [PATCH 06/44] Make the --output-directory flag an Option instead of having a default value, this way, it'll obey the user's environment variable if it isn't passed into the CLI --- cli/src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 52c8c03a..ce989acd 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -5,8 +5,8 @@ use clap::Parser; #[derive(Parser, Debug)] struct Args { /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR - #[arg(long, short, default_value = "./bindings")] - output_directory: PathBuf, + #[arg(long, short)] + output_directory: Option, /// Disables warnings caused by using serde attributes that ts-rs cannot process #[arg(long)] @@ -42,8 +42,11 @@ fn main() { .arg("test") .arg("export_bindings_") .arg("--features") - .arg("ts-rs/export") - .env("TS_RS_EXPORT_DIR", args.output_directory); + .arg("ts-rs/export"); + + if let Some(ref output_directory) = args.output_directory { + cargo_invocation.env("TS_RS_EXPORT_DIR", output_directory); + } feature!(cargo_invocation, args, { no_warnings => "no-serde-warnings", From 7914bea69b1094541e762e5a5906927abeceadd6 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 10:05:10 -0300 Subject: [PATCH 07/44] Initial draft on generating index.ts --- cli/Cargo.toml | 1 + cli/src/main.rs | 56 +++++++++++++++++++++++++++++++++++++-------- ts-rs/src/export.rs | 15 +++++++++++- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c098d6ce..1236df2a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"]} +color-eyre = "0.6" diff --git a/cli/src/main.rs b/cli/src/main.rs index ce989acd..eaace031 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,12 +1,15 @@ -use std::path::PathBuf; +use std::{io::Write, path::PathBuf}; use clap::Parser; +use color_eyre::Result; + +mod path; #[derive(Parser, Debug)] struct Args { /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR - #[arg(long, short)] - output_directory: Option, + #[arg(long, short, default_value = "./bindings")] + output_directory: PathBuf, /// Disables warnings caused by using serde attributes that ts-rs cannot process #[arg(long)] @@ -19,6 +22,9 @@ struct Args { /// Formats the generated TypeScript files #[arg(long)] format: bool, + + #[arg(long = "index")] + generate_index_ts: bool, } macro_rules! feature { @@ -33,20 +39,24 @@ macro_rules! feature { }; } -fn main() { +fn main() -> Result<()> { + color_eyre::install()?; + let args = Args::parse(); let mut cargo_invocation = std::process::Command::new("cargo"); + let metadata_path = args.output_directory.join("ts_rs.meta"); + if metadata_path.exists() { + std::fs::remove_file(&metadata_path)?; + } + cargo_invocation .arg("test") .arg("export_bindings_") .arg("--features") - .arg("ts-rs/export"); - - if let Some(ref output_directory) = args.output_directory { - cargo_invocation.env("TS_RS_EXPORT_DIR", output_directory); - } + .arg("ts-rs/export") + .env("TS_RS_EXPORT_DIR", path::absolute(&args.output_directory)?); feature!(cargo_invocation, args, { no_warnings => "no-serde-warnings", @@ -54,5 +64,31 @@ fn main() { format => "format", }); - cargo_invocation.spawn().unwrap().wait().unwrap(); + cargo_invocation.spawn()?.wait()?; + + if args.generate_index_ts { + let metadata = std::fs::read_to_string(&metadata_path)? + .lines() + .map(ToOwned::to_owned) + .collect::>(); + + let index_path = args.output_directory.join("index.ts"); + + if index_path.exists() { + std::fs::remove_file(&index_path)?; + } + + let mut index = std::fs::OpenOptions::new() + .create(true) + .append(true) + .open(index_path)?; + + for file in metadata.iter() { + index.write_fmt(format_args!("export * from {file:?};\n"))?; + } + } + + std::fs::remove_file(&metadata_path)?; + + Ok(()) } diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 07d35dfc..80b38f95 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -135,14 +135,27 @@ pub(crate) fn export_to>( if let Some(parent) = path.as_ref().parent() { std::fs::create_dir_all(parent)?; } + let lock = FILE_LOCK.lock().unwrap(); { // Manually write to file & call `sync_data`. Otherwise, calling `fs::read(path)` // immediately after `T::export()` might result in an empty file. use std::io::Write; - let mut file = File::create(path)?; + let mut file = File::create(&path)?; file.write_all(buffer.as_bytes())?; file.sync_data()?; + + let bytes = path::absolute(path.as_ref())? + .to_string_lossy() + .bytes() + .chain([b'\n']) + .collect::>(); + std::fs::OpenOptions::new() + .read(true) + .append(true) + .create(true) + .open(default_out_dir().join("ts_rs.meta"))? + .write_all(&bytes)?; } drop(lock); From 58df89d63512d8114236872f9529da6a994161f5 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 10:09:09 -0300 Subject: [PATCH 08/44] Add missing file --- cli/src/path.rs | 30 +++++++++++++++++ example/bindings/ts_rs.meta | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 cli/src/path.rs create mode 100644 example/bindings/ts_rs.meta diff --git a/cli/src/path.rs b/cli/src/path.rs new file mode 100644 index 00000000..1b8f9fcb --- /dev/null +++ b/cli/src/path.rs @@ -0,0 +1,30 @@ +use std::path::{Component as C, Path, PathBuf}; + +use color_eyre::{eyre::OptionExt, Result}; + +pub fn absolute>(path: T) -> Result { + let path = path.as_ref(); + + if path.is_absolute() { + return Ok(path.to_owned()); + } + + let path = std::env::current_dir()?.join(path); + + let mut out = Vec::new(); + for comp in path.components() { + match comp { + C::CurDir => (), + C::ParentDir => { + out.pop().ok_or_eyre("Invalid path")?; + } + comp => out.push(comp), + } + } + + Ok(if !out.is_empty() { + out.iter().collect() + } else { + PathBuf::from(".") + }) +} diff --git a/example/bindings/ts_rs.meta b/example/bindings/ts_rs.meta new file mode 100644 index 00000000..70af8c8b --- /dev/null +++ b/example/bindings/ts_rs.meta @@ -0,0 +1,66 @@ +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexStruct.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Vehicle.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Gender.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\InlineComplexEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Gender.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Vehicle.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexStruct.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\InlineComplexEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Gender.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexStruct.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Vehicle.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\InlineComplexEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts +C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts From 67f9631ba28d53274d99734cf0df4f7fd5ea6d57 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 10:11:22 -0300 Subject: [PATCH 09/44] Update Github action --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index deff1a7c..980ec1a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: working-directory: e2e/dependencies/consumer run: | cargo t --features ts-rs/export - tsc bindings/* --noEmit --noUnusedLocals --strict + tsc bindings/*.ts --noEmit --noUnusedLocals --strict - name: dependencies e2e test with default export env working-directory: e2e/dependencies/consumer run: | @@ -60,7 +60,7 @@ jobs: working-directory: example run: | cargo t --features ts-rs/export - tsc bindings/* --noEmit + tsc bindings/*.ts --noEmit - name: example e2e with default export env working-directory: example run: | From f092001ae4fbd9e7d657e11b723be36f2e880ffa Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 10:20:28 -0300 Subject: [PATCH 10/44] Check for empty index and emit codegen warning --- cli/src/main.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index eaace031..d3f8e288 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -78,13 +78,18 @@ fn main() -> Result<()> { std::fs::remove_file(&index_path)?; } - let mut index = std::fs::OpenOptions::new() - .create(true) - .append(true) - .open(index_path)?; - - for file in metadata.iter() { - index.write_fmt(format_args!("export * from {file:?};\n"))?; + if !metadata.is_empty() { + let mut index = std::fs::OpenOptions::new() + .create(true) + .append(true) + .open(index_path)?; + + index.write_all( + b"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n" + )?; + for file in metadata.iter() { + index.write_fmt(format_args!("export * from {file:?};\n"))?; + } } } From 7192a8baba52c083414f1ca88638a39473592ed8 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 10:34:54 -0300 Subject: [PATCH 11/44] Save relative paths in netadata file --- ts-rs/src/export.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 80b38f95..6823f027 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -4,6 +4,7 @@ use std::{ collections::BTreeMap, fmt::Write, fs::File, + io::Read, path::{Component, Path, PathBuf}, sync::Mutex, }; @@ -145,17 +146,17 @@ pub(crate) fn export_to>( file.write_all(buffer.as_bytes())?; file.sync_data()?; - let bytes = path::absolute(path.as_ref())? - .to_string_lossy() - .bytes() - .chain([b'\n']) - .collect::>(); + let relative_path = T::output_path() + .ok_or_else(std::any::type_name::) + .map_err(ExportError::CannotBeExported)? + .to_string_lossy(); + std::fs::OpenOptions::new() .read(true) .append(true) .create(true) .open(default_out_dir().join("ts_rs.meta"))? - .write_all(&bytes)?; + .write_fmt(format_args!("./{relative_path}\n"))?; } drop(lock); From 2b09065f8fca8d464aeb8bf2df103422f2507b7a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 10:35:14 -0300 Subject: [PATCH 12/44] Remove unused import --- ts-rs/src/export.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 6823f027..677815eb 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -4,7 +4,6 @@ use std::{ collections::BTreeMap, fmt::Write, fs::File, - io::Read, path::{Component, Path, PathBuf}, sync::Mutex, }; From d18bf796009bc20801b7f6c5ceaffd9dd97ba599 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 14:56:25 -0300 Subject: [PATCH 13/44] Remove unused read file access --- ts-rs/src/export.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 677815eb..4141f632 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -151,7 +151,6 @@ pub(crate) fn export_to>( .to_string_lossy(); std::fs::OpenOptions::new() - .read(true) .append(true) .create(true) .open(default_out_dir().join("ts_rs.meta"))? From af0d6d3cf2a77b185cb5ac6bf4a6ebdf09616154 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 15:18:51 -0300 Subject: [PATCH 14/44] Add naming collision warning --- cli/src/main.rs | 34 ++++++++++++++++++++++++++++++++-- ts-rs/src/export.rs | 4 +++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index d3f8e288..236a7e4a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -70,7 +70,22 @@ fn main() -> Result<()> { let metadata = std::fs::read_to_string(&metadata_path)? .lines() .map(ToOwned::to_owned) - .collect::>(); + .collect::>() + .into_iter() + .fold( + std::collections::HashMap::<_, Vec<_>>::default(), + |mut acc, cur| { + let (type_name, path) = cur.split_once(',').unwrap(); + + let type_name = type_name.to_owned(); + let path = std::path::Path::new(path).to_owned(); + acc.entry(type_name) + .and_modify(|v| v.push(path.clone())) + .or_insert(vec![path]); + + acc + }, + ); let index_path = args.output_directory.join("index.ts"); @@ -79,6 +94,20 @@ fn main() -> Result<()> { } if !metadata.is_empty() { + metadata + .iter() + .filter(|x| x.1.len() > 1) + .for_each(|(ty, paths)| { + eprintln!( + r#"Warning: Multiple types named "{ty}" exported to different paths:"# + ); + for path in paths { + eprintln!(" - {:?}", path.to_string_lossy().to_string()); + } + + eprintln!(); + }); + let mut index = std::fs::OpenOptions::new() .create(true) .append(true) @@ -87,7 +116,8 @@ fn main() -> Result<()> { index.write_all( b"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n" )?; - for file in metadata.iter() { + + for file in metadata.iter().map(|x| &x.1[0]) { index.write_fmt(format_args!("export * from {file:?};\n"))?; } } diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 4141f632..28e48a16 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -150,11 +150,13 @@ pub(crate) fn export_to>( .map_err(ExportError::CannotBeExported)? .to_string_lossy(); + let type_name = T::ident(); + std::fs::OpenOptions::new() .append(true) .create(true) .open(default_out_dir().join("ts_rs.meta"))? - .write_fmt(format_args!("./{relative_path}\n"))?; + .write_fmt(format_args!("{type_name},./{relative_path}\n"))?; } drop(lock); From 41cf0347701eb49e4dcd091c7c4ba52072370ac1 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 15:22:07 -0300 Subject: [PATCH 15/44] Add imports --- cli/src/main.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 236a7e4a..0d295be2 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,4 +1,9 @@ -use std::{io::Write, path::PathBuf}; +use std::{ + collections::{HashMap, HashSet}, + fs, + io::Write, + path::{Path, PathBuf}, +}; use clap::Parser; use color_eyre::Result; @@ -48,7 +53,7 @@ fn main() -> Result<()> { let metadata_path = args.output_directory.join("ts_rs.meta"); if metadata_path.exists() { - std::fs::remove_file(&metadata_path)?; + fs::remove_file(&metadata_path)?; } cargo_invocation @@ -67,30 +72,27 @@ fn main() -> Result<()> { cargo_invocation.spawn()?.wait()?; if args.generate_index_ts { - let metadata = std::fs::read_to_string(&metadata_path)? + let metadata = fs::read_to_string(&metadata_path)? .lines() .map(ToOwned::to_owned) - .collect::>() + .collect::>() .into_iter() - .fold( - std::collections::HashMap::<_, Vec<_>>::default(), - |mut acc, cur| { - let (type_name, path) = cur.split_once(',').unwrap(); + .fold(HashMap::<_, Vec<_>>::default(), |mut acc, cur| { + let (type_name, path) = cur.split_once(',').unwrap(); - let type_name = type_name.to_owned(); - let path = std::path::Path::new(path).to_owned(); - acc.entry(type_name) - .and_modify(|v| v.push(path.clone())) - .or_insert(vec![path]); + let type_name = type_name.to_owned(); + let path = Path::new(path).to_owned(); + acc.entry(type_name) + .and_modify(|v| v.push(path.clone())) + .or_insert(vec![path]); - acc - }, - ); + acc + }); let index_path = args.output_directory.join("index.ts"); if index_path.exists() { - std::fs::remove_file(&index_path)?; + fs::remove_file(&index_path)?; } if !metadata.is_empty() { @@ -108,7 +110,7 @@ fn main() -> Result<()> { eprintln!(); }); - let mut index = std::fs::OpenOptions::new() + let mut index = fs::OpenOptions::new() .create(true) .append(true) .open(index_path)?; @@ -123,7 +125,7 @@ fn main() -> Result<()> { } } - std::fs::remove_file(&metadata_path)?; + fs::remove_file(&metadata_path)?; Ok(()) } From 2ea928f9ec518dc8a8a5ed599301d8dead9b5b1e Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 15:58:44 -0300 Subject: [PATCH 16/44] MAke warnings colorful --- cli/Cargo.toml | 1 + cli/src/main.rs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1236df2a..0b903e23 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"]} color-eyre = "0.6" +# colored = "2" diff --git a/cli/src/main.rs b/cli/src/main.rs index 0d295be2..ce278041 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,7 +6,7 @@ use std::{ }; use clap::Parser; -use color_eyre::Result; +use color_eyre::{owo_colors::OwoColorize, Result}; mod path; @@ -101,10 +101,12 @@ fn main() -> Result<()> { .filter(|x| x.1.len() > 1) .for_each(|(ty, paths)| { eprintln!( - r#"Warning: Multiple types named "{ty}" exported to different paths:"# + "{} Multiple types named {ty:?} exported to different paths:", + "Warning:".yellow().bold() ); + for path in paths { - eprintln!(" - {:?}", path.to_string_lossy().to_string()); + eprintln!(" {} {}", "-".blue().bold(), path.to_string_lossy().bold()); } eprintln!(); From 9557f9f515a38304d1a9ab5347ef49f4b126b36d Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 16:01:23 -0300 Subject: [PATCH 17/44] Also highlight type names --- cli/src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index ce278041..ce6ba890 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -101,8 +101,9 @@ fn main() -> Result<()> { .filter(|x| x.1.len() > 1) .for_each(|(ty, paths)| { eprintln!( - "{} Multiple types named {ty:?} exported to different paths:", - "Warning:".yellow().bold() + "{} Multiple types named \"{}\" exported to different paths:", + "Warning:".yellow().bold(), + ty.green() ); for path in paths { From 4ec1679a5e8c497fc9a437dbc3eb6a567ff7ac91 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 16:06:28 -0300 Subject: [PATCH 18/44] Make type names bold --- cli/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index ce6ba890..c701e0d4 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -101,9 +101,9 @@ fn main() -> Result<()> { .filter(|x| x.1.len() > 1) .for_each(|(ty, paths)| { eprintln!( - "{} Multiple types named \"{}\" exported to different paths:", + "{} Multiple types named \"{}\" exported to different paths", "Warning:".yellow().bold(), - ty.green() + ty.green().bold() ); for path in paths { From 9c4524963de3b27a94fde7c59d3f65d21acf5312 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 16:07:52 -0300 Subject: [PATCH 19/44] Remove commented dependency --- cli/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 0b903e23..1236df2a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -8,4 +8,3 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"]} color-eyre = "0.6" -# colored = "2" From 98b0c014005cbd116fb395921a26d62fcea25fa1 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 16:30:01 -0300 Subject: [PATCH 20/44] Print Rust type name in collision warning --- cli/src/main.rs | 26 +++++++++++++++++--------- ts-rs/src/export.rs | 7 +++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index c701e0d4..f140beb0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -78,13 +78,14 @@ fn main() -> Result<()> { .collect::>() .into_iter() .fold(HashMap::<_, Vec<_>>::default(), |mut acc, cur| { - let (type_name, path) = cur.split_once(',').unwrap(); + let columns = cur.splitn(3, ',').collect::>(); - let type_name = type_name.to_owned(); - let path = Path::new(path).to_owned(); - acc.entry(type_name) - .and_modify(|v| v.push(path.clone())) - .or_insert(vec![path]); + let type_ts_name = columns[0].to_owned(); + let type_rs_name = columns[1].to_owned(); + let path = Path::new(columns[2]).to_owned(); + acc.entry(type_ts_name) + .and_modify(|v| v.push((type_rs_name.clone(), path.clone()))) + .or_insert(vec![(type_rs_name, path)]); acc }); @@ -101,13 +102,20 @@ fn main() -> Result<()> { .filter(|x| x.1.len() > 1) .for_each(|(ty, paths)| { eprintln!( - "{} Multiple types named \"{}\" exported to different paths", + "{} Multiple types being exported with the name \"{}\"", "Warning:".yellow().bold(), ty.green().bold() ); - for path in paths { - eprintln!(" {} {}", "-".blue().bold(), path.to_string_lossy().bold()); + for (ty_rs, path) in paths { + eprintln!( + " {} {} {}", + "-".blue().bold(), + "Type:".bold(), + ty_rs.cyan(), + ); + eprintln!(" {} {}", "Path:".bold(), path.to_string_lossy()); + eprintln!(); } eprintln!(); diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 28e48a16..e7a7ee32 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -150,13 +150,16 @@ pub(crate) fn export_to>( .map_err(ExportError::CannotBeExported)? .to_string_lossy(); - let type_name = T::ident(); + let type_ts_name = T::ident(); + let type_rs_name = std::any::type_name::().split('<').next().unwrap(); std::fs::OpenOptions::new() .append(true) .create(true) .open(default_out_dir().join("ts_rs.meta"))? - .write_fmt(format_args!("{type_name},./{relative_path}\n"))?; + .write_fmt(format_args!( + "{type_ts_name},{type_rs_name},./{relative_path}\n" + ))?; } drop(lock); From b80f988a95cbab7a57dad7c1f5627e69dd3370cc Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 16:54:55 -0300 Subject: [PATCH 21/44] Capture cargo test stderr and stdout --- cli/src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cli/src/main.rs b/cli/src/main.rs index f140beb0..54d0596a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -3,6 +3,7 @@ use std::{ fs, io::Write, path::{Path, PathBuf}, + process::Stdio, }; use clap::Parser; @@ -28,8 +29,14 @@ struct Args { #[arg(long)] format: bool, + /// Generates an index.ts file in your --output-directory that re-exports all + /// types generated by ts-rs #[arg(long = "index")] generate_index_ts: bool, + + /// Do not capture `cargo test`'s output, and pass --nocapture to the test binary + #[arg(long)] + no_capture: bool, } macro_rules! feature { @@ -61,6 +68,16 @@ fn main() -> Result<()> { .arg("export_bindings_") .arg("--features") .arg("ts-rs/export") + .stdout(if args.no_capture { + Stdio::inherit() + } else { + Stdio::piped() + }) + .stderr(if args.no_capture { + Stdio::inherit() + } else { + Stdio::piped() + }) .env("TS_RS_EXPORT_DIR", path::absolute(&args.output_directory)?); feature!(cargo_invocation, args, { @@ -69,6 +86,10 @@ fn main() -> Result<()> { format => "format", }); + if args.no_capture { + cargo_invocation.arg("--").arg("--nocapture"); + } + cargo_invocation.spawn()?.wait()?; if args.generate_index_ts { From 363f7c8e91b36c48b4cc8e012871243807c9075b Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 17:28:01 -0300 Subject: [PATCH 22/44] Refactor CLI code --- cli/src/main.rs | 123 +++++++----------------------------------------- 1 file changed, 18 insertions(+), 105 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 54d0596a..9dd41e6b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -2,111 +2,45 @@ use std::{ collections::{HashMap, HashSet}, fs, io::Write, - path::{Path, PathBuf}, - process::Stdio, }; +use cargo::invoke_cargo; use clap::Parser; -use color_eyre::{owo_colors::OwoColorize, Result}; +use color_eyre::Result; +mod args; +mod cargo; +mod metadata; mod path; -#[derive(Parser, Debug)] -struct Args { - /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR - #[arg(long, short, default_value = "./bindings")] - output_directory: PathBuf, +use args::Args; +use metadata::{name_collision_warning, Metadata}; - /// Disables warnings caused by using serde attributes that ts-rs cannot process - #[arg(long)] - no_warnings: bool, - - /// Adds the ".js" extension to import paths - #[arg(long)] - esm_imports: bool, - - /// Formats the generated TypeScript files - #[arg(long)] - format: bool, - - /// Generates an index.ts file in your --output-directory that re-exports all - /// types generated by ts-rs - #[arg(long = "index")] - generate_index_ts: bool, - - /// Do not capture `cargo test`'s output, and pass --nocapture to the test binary - #[arg(long)] - no_capture: bool, -} - -macro_rules! feature { - ($cargo_invocation: expr, $args: expr, { $($field: ident => $feature: literal),* $(,)? }) => { - $( - if $args.$field { - $cargo_invocation - .arg("--features") - .arg(format!("ts-rs/{}", $feature)); - } - )* - }; -} +const NOTE: &[u8; 109] = b"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n"; fn main() -> Result<()> { color_eyre::install()?; let args = Args::parse(); - let mut cargo_invocation = std::process::Command::new("cargo"); - let metadata_path = args.output_directory.join("ts_rs.meta"); if metadata_path.exists() { fs::remove_file(&metadata_path)?; } - cargo_invocation - .arg("test") - .arg("export_bindings_") - .arg("--features") - .arg("ts-rs/export") - .stdout(if args.no_capture { - Stdio::inherit() - } else { - Stdio::piped() - }) - .stderr(if args.no_capture { - Stdio::inherit() - } else { - Stdio::piped() - }) - .env("TS_RS_EXPORT_DIR", path::absolute(&args.output_directory)?); - - feature!(cargo_invocation, args, { - no_warnings => "no-serde-warnings", - esm_imports => "import-esm", - format => "format", - }); - - if args.no_capture { - cargo_invocation.arg("--").arg("--nocapture"); - } - - cargo_invocation.spawn()?.wait()?; + invoke_cargo(&args)?; if args.generate_index_ts { - let metadata = fs::read_to_string(&metadata_path)? + let metadata_content = fs::read_to_string(&metadata_path)?; + let metadata = metadata_content .lines() - .map(ToOwned::to_owned) .collect::>() .into_iter() .fold(HashMap::<_, Vec<_>>::default(), |mut acc, cur| { - let columns = cur.splitn(3, ',').collect::>(); + let (key, value) = cur.split_once(',').unwrap(); - let type_ts_name = columns[0].to_owned(); - let type_rs_name = columns[1].to_owned(); - let path = Path::new(columns[2]).to_owned(); - acc.entry(type_ts_name) - .and_modify(|v| v.push((type_rs_name.clone(), path.clone()))) - .or_insert(vec![(type_rs_name, path)]); + let value = Metadata::try_from(value).unwrap(); + acc.entry(key).or_default().push(value); acc }); @@ -121,38 +55,17 @@ fn main() -> Result<()> { metadata .iter() .filter(|x| x.1.len() > 1) - .for_each(|(ty, paths)| { - eprintln!( - "{} Multiple types being exported with the name \"{}\"", - "Warning:".yellow().bold(), - ty.green().bold() - ); - - for (ty_rs, path) in paths { - eprintln!( - " {} {} {}", - "-".blue().bold(), - "Type:".bold(), - ty_rs.cyan(), - ); - eprintln!(" {} {}", "Path:".bold(), path.to_string_lossy()); - eprintln!(); - } - - eprintln!(); - }); + .for_each(|(&ty, meta)| name_collision_warning(ty, meta)); let mut index = fs::OpenOptions::new() .create(true) .append(true) .open(index_path)?; - index.write_all( - b"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n" - )?; + index.write_all(NOTE)?; - for file in metadata.iter().map(|x| &x.1[0]) { - index.write_fmt(format_args!("export * from {file:?};\n"))?; + for file in metadata.iter().map(|x| &x.1[0].export_path) { + index.write_fmt(format_args!("\nexport * from {file:?};"))?; } } } From 7894b4b00e6d2bfe98ca6a8c176a183ba5f50a11 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 17:29:13 -0300 Subject: [PATCH 23/44] Commit untracked files --- cli/src/args.rs | 31 +++++++++++++++++++++++++++ cli/src/cargo.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ cli/src/metadata.rs | 50 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 cli/src/args.rs create mode 100644 cli/src/cargo.rs create mode 100644 cli/src/metadata.rs diff --git a/cli/src/args.rs b/cli/src/args.rs new file mode 100644 index 00000000..0201d51b --- /dev/null +++ b/cli/src/args.rs @@ -0,0 +1,31 @@ +use std::path::PathBuf; + +use clap::Parser; + +#[derive(Parser, Debug)] +pub(super) struct Args { + /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR + #[arg(long, short, default_value = "./bindings")] + pub output_directory: PathBuf, + + /// Disables warnings caused by using serde attributes that ts-rs cannot process + #[arg(long)] + pub no_warnings: bool, + + /// Adds the ".js" extension to import paths + #[arg(long)] + pub esm_imports: bool, + + /// Formats the generated TypeScript files + #[arg(long)] + pub format: bool, + + /// Generates an index.ts file in your --output-directory that re-exports all + /// types generated by ts-rs + #[arg(long = "index")] + pub generate_index_ts: bool, + + /// Do not capture `cargo test`'s output, and pass --nocapture to the test binary + #[arg(long)] + pub no_capture: bool, +} diff --git a/cli/src/cargo.rs b/cli/src/cargo.rs new file mode 100644 index 00000000..98014630 --- /dev/null +++ b/cli/src/cargo.rs @@ -0,0 +1,52 @@ +use std::process::{Command, Stdio}; + +use color_eyre::Result; + +use crate::{args::Args, path}; + +macro_rules! feature { + ($cargo_invocation: expr, $args: expr, { $($field: ident => $feature: literal),* $(,)? }) => { + $( + if $args.$field { + $cargo_invocation + .arg("--features") + .arg(format!("ts-rs/{}", $feature)); + } + )* + }; +} + +pub(super) fn invoke_cargo(args: &Args) -> Result<()> { + let mut cargo_invocation = Command::new("cargo"); + + cargo_invocation + .arg("test") + .arg("export_bindings_") + .arg("--features") + .arg("ts-rs/export") + .stdout(if args.no_capture { + Stdio::inherit() + } else { + Stdio::piped() + }) + .stderr(if args.no_capture { + Stdio::inherit() + } else { + Stdio::piped() + }) + .env("TS_RS_EXPORT_DIR", path::absolute(&args.output_directory)?); + + feature!(cargo_invocation, args, { + no_warnings => "no-serde-warnings", + esm_imports => "import-esm", + format => "format", + }); + + if args.no_capture { + cargo_invocation.arg("--").arg("--nocapture"); + } + + cargo_invocation.spawn()?.wait()?; + + Ok(()) +} diff --git a/cli/src/metadata.rs b/cli/src/metadata.rs new file mode 100644 index 00000000..b35e5637 --- /dev/null +++ b/cli/src/metadata.rs @@ -0,0 +1,50 @@ +use std::path::Path; + +use color_eyre::{eyre::OptionExt, owo_colors::OwoColorize}; + +#[derive(Clone)] +pub(super) struct Metadata<'a> { + pub rust_name: &'a str, + pub export_path: &'a Path, +} + +impl<'a> TryFrom<&'a str> for Metadata<'a> { + type Error = color_eyre::eyre::Error; + + fn try_from(value: &'a str) -> Result { + let (rust_name, export_path) = + value.split_once(',').ok_or_eyre("Invalid metadata entry")?; + + Ok(Self { + rust_name, + export_path: Path::new(export_path), + }) + } +} + +pub(super) fn name_collision_warning(ts_type: &str, metadata: &[Metadata]) { + eprintln!( + "{} Multiple types being exported with the name \"{}\"", + "Warning:".yellow().bold(), + ts_type.green().bold() + ); + + for entry in metadata { + eprintln!( + " {} {} {}", + "-".blue().bold(), + "Type:".bold(), + entry.rust_name.cyan(), + ); + + eprintln!( + " {} {}", + "Path:".bold(), + entry.export_path.to_string_lossy() + ); + + eprintln!(); + } + + eprintln!(); +} From 65524d5760a1ef17017ae66ac3dec00fdddf186f Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 17:43:44 -0300 Subject: [PATCH 24/44] Export all files, not just the first metadata entry --- cli/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 9dd41e6b..076c495b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -64,7 +64,11 @@ fn main() -> Result<()> { index.write_all(NOTE)?; - for file in metadata.iter().map(|x| &x.1[0].export_path) { + for file in metadata + .into_iter() + .flat_map(|x| x.1) + .map(|x| x.export_path) + { index.write_fmt(format_args!("\nexport * from {file:?};"))?; } } From 7560098a4e42e3b98a3e37c12a38bf836dfc622e Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 17:50:27 -0300 Subject: [PATCH 25/44] Delete metadata file --- example/bindings/ts_rs.meta | 66 ------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 example/bindings/ts_rs.meta diff --git a/example/bindings/ts_rs.meta b/example/bindings/ts_rs.meta deleted file mode 100644 index 70af8c8b..00000000 --- a/example/bindings/ts_rs.meta +++ /dev/null @@ -1,66 +0,0 @@ -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexStruct.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Vehicle.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Gender.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\InlineComplexEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Gender.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Vehicle.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexStruct.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\InlineComplexEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Gender.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexStruct.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Vehicle.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\InlineComplexEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\ComplexEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Series.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\SimpleEnum.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\Point.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\User.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts -C:\Users\Administrator\Desktop\Projetos\ts-rs\example\bindings\UserRole.ts From 770d6ea72ff4163af89696109d01257d6873c437 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 17:50:53 -0300 Subject: [PATCH 26/44] Add metadata file to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 99930030..d90b7f98 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Cargo.lock /.idea *.ts -/ts-rs/tests-out \ No newline at end of file +/ts-rs/tests-out +ts_rs.meta From e52085c5b8194514774422f44986659bf45a5b53 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 12 Apr 2024 17:55:53 -0300 Subject: [PATCH 27/44] Enable clippy pedantic and nursery --- cli/src/args.rs | 3 ++- cli/src/cargo.rs | 2 +- cli/src/main.rs | 11 ++++------- cli/src/metadata.rs | 4 ++-- cli/src/path.rs | 6 +++--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index 0201d51b..7bafd61c 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -3,7 +3,8 @@ use std::path::PathBuf; use clap::Parser; #[derive(Parser, Debug)] -pub(super) struct Args { +#[allow(clippy::struct_excessive_bools)] +pub struct Args { /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR #[arg(long, short, default_value = "./bindings")] pub output_directory: PathBuf, diff --git a/cli/src/cargo.rs b/cli/src/cargo.rs index 98014630..ddef9a41 100644 --- a/cli/src/cargo.rs +++ b/cli/src/cargo.rs @@ -16,7 +16,7 @@ macro_rules! feature { }; } -pub(super) fn invoke_cargo(args: &Args) -> Result<()> { +pub fn invoke(args: &Args) -> Result<()> { let mut cargo_invocation = Command::new("cargo"); cargo_invocation diff --git a/cli/src/main.rs b/cli/src/main.rs index 076c495b..25e297ac 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,10 +1,11 @@ +#![warn(clippy::pedantic, clippy::nursery)] + use std::{ collections::{HashMap, HashSet}, fs, io::Write, }; -use cargo::invoke_cargo; use clap::Parser; use color_eyre::Result; @@ -28,7 +29,7 @@ fn main() -> Result<()> { fs::remove_file(&metadata_path)?; } - invoke_cargo(&args)?; + cargo::invoke(&args)?; if args.generate_index_ts { let metadata_content = fs::read_to_string(&metadata_path)?; @@ -64,11 +65,7 @@ fn main() -> Result<()> { index.write_all(NOTE)?; - for file in metadata - .into_iter() - .flat_map(|x| x.1) - .map(|x| x.export_path) - { + for file in metadata.iter().flat_map(|x| x.1).map(|x| x.export_path) { index.write_fmt(format_args!("\nexport * from {file:?};"))?; } } diff --git a/cli/src/metadata.rs b/cli/src/metadata.rs index b35e5637..3087ba49 100644 --- a/cli/src/metadata.rs +++ b/cli/src/metadata.rs @@ -3,7 +3,7 @@ use std::path::Path; use color_eyre::{eyre::OptionExt, owo_colors::OwoColorize}; #[derive(Clone)] -pub(super) struct Metadata<'a> { +pub struct Metadata<'a> { pub rust_name: &'a str, pub export_path: &'a Path, } @@ -22,7 +22,7 @@ impl<'a> TryFrom<&'a str> for Metadata<'a> { } } -pub(super) fn name_collision_warning(ts_type: &str, metadata: &[Metadata]) { +pub fn name_collision_warning(ts_type: &str, metadata: &[Metadata]) { eprintln!( "{} Multiple types being exported with the name \"{}\"", "Warning:".yellow().bold(), diff --git a/cli/src/path.rs b/cli/src/path.rs index 1b8f9fcb..257a7145 100644 --- a/cli/src/path.rs +++ b/cli/src/path.rs @@ -22,9 +22,9 @@ pub fn absolute>(path: T) -> Result { } } - Ok(if !out.is_empty() { - out.iter().collect() - } else { + Ok(if out.is_empty() { PathBuf::from(".") + } else { + out.iter().collect() }) } From 275b15dd3cac3caab342f999b8bb89a63b082b16 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 15 Apr 2024 08:15:36 -0300 Subject: [PATCH 28/44] Merge branch 'main' into cli --- .github/workflows/test.yml | 21 +- .gitignore | 1 - CHANGELOG.md | 2 + Cargo.lock | 1747 +++++++++++++++++ Cargo.toml | 1 + e2e/dependencies/consumer/Cargo.lock | 138 ++ e2e/dependencies/dependency1/Cargo.lock | 130 ++ e2e/workspace/Cargo.lock | 146 ++ macros/src/attr/field.rs | 72 +- macros/src/types/enum.rs | 47 +- macros/src/types/named.rs | 49 +- macros/src/types/newtype.rs | 19 +- macros/src/types/tuple.rs | 24 +- ts-rs/Cargo.toml | 1 + ts-rs/src/lib.rs | 3 +- ts-rs/tests/{ => integration}/arrays.rs | 0 ts-rs/tests/{ => integration}/bound.rs | 0 ts-rs/tests/{ => integration}/chrono.rs | 0 .../{ => integration}/concrete_generic.rs | 0 ts-rs/tests/{ => integration}/docs.rs | 0 .../{ => integration}/enum_flattening.rs | 0 .../enum_flattening_nested.rs | 0 .../enum_struct_rename_all.rs | 0 .../enum_variant_annotation.rs | 0 .../{ => integration}/export_manually.rs | 0 ts-rs/tests/{ => integration}/field_rename.rs | 0 ts-rs/tests/{ => integration}/flatten.rs | 0 .../tests/{ => integration}/generic_fields.rs | 0 .../generic_without_import.rs | 0 ts-rs/tests/{ => integration}/generics.rs | 0 ts-rs/tests/{ => integration}/hashmap.rs | 0 ts-rs/tests/{ => integration}/hashset.rs | 0 ts-rs/tests/{ => integration}/imports.rs | 0 ts-rs/tests/{ => integration}/indexmap.rs | 0 ts-rs/tests/integration/infer_as.rs | 15 + .../issue_168.rs} | 0 .../issue_232.rs} | 0 .../{issue-70.rs => integration/issue_70.rs} | 0 .../{issue-80.rs => integration/issue_80.rs} | 0 .../tests/{ => integration}/leading_colon.rs | 0 ts-rs/tests/{ => integration}/lifetimes.rs | 0 ts-rs/tests/{ => integration}/list.rs | 0 ts-rs/tests/integration/main.rs | 60 + ts-rs/tests/{ => integration}/nested.rs | 0 .../tests/{ => integration}/optional_field.rs | 0 ts-rs/tests/{ => integration}/path_bug.rs | 0 ts-rs/tests/{ => integration}/ranges.rs | 0 ts-rs/tests/{ => integration}/raw_idents.rs | 0 .../{ => integration}/recursion_limit.rs | 0 ts-rs/tests/{ => integration}/references.rs | 0 .../{ => integration}/self_referential.rs | 0 ts-rs/tests/{ => integration}/semver.rs | 0 ts-rs/tests/{ => integration}/serde_json.rs | 0 .../serde_skip_with_default.rs} | 0 ts-rs/tests/{ => integration}/serde_with.rs | 0 ts-rs/tests/{ => integration}/simple.rs | 0 ts-rs/tests/{ => integration}/skip.rs | 0 ts-rs/tests/{ => integration}/slices.rs | 0 .../tests/{ => integration}/struct_rename.rs | 0 ts-rs/tests/{ => integration}/struct_tag.rs | 0 .../{ => integration}/top_level_type_as.rs | 0 .../top_level_type_override.rs | 0 ts-rs/tests/{ => integration}/tuple.rs | 0 ts-rs/tests/{ => integration}/type_as.rs | 0 .../tests/{ => integration}/type_override.rs | 0 ts-rs/tests/{ => integration}/union.rs | 0 .../union_named_serde_skip.rs | 0 ts-rs/tests/{ => integration}/union_rename.rs | 0 ts-rs/tests/{ => integration}/union_serde.rs | 0 .../union_unnamed_serde_skip.rs | 0 .../{ => integration}/union_with_data.rs | 0 .../union_with_internal_tag.rs | 0 ts-rs/tests/{ => integration}/unit.rs | 0 ts-rs/tests/{ => integration}/unsized.rs | 0 74 files changed, 2365 insertions(+), 111 deletions(-) create mode 100644 Cargo.lock create mode 100644 e2e/dependencies/consumer/Cargo.lock create mode 100644 e2e/dependencies/dependency1/Cargo.lock create mode 100644 e2e/workspace/Cargo.lock rename ts-rs/tests/{ => integration}/arrays.rs (100%) rename ts-rs/tests/{ => integration}/bound.rs (100%) rename ts-rs/tests/{ => integration}/chrono.rs (100%) rename ts-rs/tests/{ => integration}/concrete_generic.rs (100%) rename ts-rs/tests/{ => integration}/docs.rs (100%) rename ts-rs/tests/{ => integration}/enum_flattening.rs (100%) rename ts-rs/tests/{ => integration}/enum_flattening_nested.rs (100%) rename ts-rs/tests/{ => integration}/enum_struct_rename_all.rs (100%) rename ts-rs/tests/{ => integration}/enum_variant_annotation.rs (100%) rename ts-rs/tests/{ => integration}/export_manually.rs (100%) rename ts-rs/tests/{ => integration}/field_rename.rs (100%) rename ts-rs/tests/{ => integration}/flatten.rs (100%) rename ts-rs/tests/{ => integration}/generic_fields.rs (100%) rename ts-rs/tests/{ => integration}/generic_without_import.rs (100%) rename ts-rs/tests/{ => integration}/generics.rs (100%) rename ts-rs/tests/{ => integration}/hashmap.rs (100%) rename ts-rs/tests/{ => integration}/hashset.rs (100%) rename ts-rs/tests/{ => integration}/imports.rs (100%) rename ts-rs/tests/{ => integration}/indexmap.rs (100%) create mode 100644 ts-rs/tests/integration/infer_as.rs rename ts-rs/tests/{issue-168.rs => integration/issue_168.rs} (100%) rename ts-rs/tests/{issue-232.rs => integration/issue_232.rs} (100%) rename ts-rs/tests/{issue-70.rs => integration/issue_70.rs} (100%) rename ts-rs/tests/{issue-80.rs => integration/issue_80.rs} (100%) rename ts-rs/tests/{ => integration}/leading_colon.rs (100%) rename ts-rs/tests/{ => integration}/lifetimes.rs (100%) rename ts-rs/tests/{ => integration}/list.rs (100%) create mode 100644 ts-rs/tests/integration/main.rs rename ts-rs/tests/{ => integration}/nested.rs (100%) rename ts-rs/tests/{ => integration}/optional_field.rs (100%) rename ts-rs/tests/{ => integration}/path_bug.rs (100%) rename ts-rs/tests/{ => integration}/ranges.rs (100%) rename ts-rs/tests/{ => integration}/raw_idents.rs (100%) rename ts-rs/tests/{ => integration}/recursion_limit.rs (100%) rename ts-rs/tests/{ => integration}/references.rs (100%) rename ts-rs/tests/{ => integration}/self_referential.rs (100%) rename ts-rs/tests/{ => integration}/semver.rs (100%) rename ts-rs/tests/{ => integration}/serde_json.rs (100%) rename ts-rs/tests/{serde-skip-with-default.rs => integration/serde_skip_with_default.rs} (100%) rename ts-rs/tests/{ => integration}/serde_with.rs (100%) rename ts-rs/tests/{ => integration}/simple.rs (100%) rename ts-rs/tests/{ => integration}/skip.rs (100%) rename ts-rs/tests/{ => integration}/slices.rs (100%) rename ts-rs/tests/{ => integration}/struct_rename.rs (100%) rename ts-rs/tests/{ => integration}/struct_tag.rs (100%) rename ts-rs/tests/{ => integration}/top_level_type_as.rs (100%) rename ts-rs/tests/{ => integration}/top_level_type_override.rs (100%) rename ts-rs/tests/{ => integration}/tuple.rs (100%) rename ts-rs/tests/{ => integration}/type_as.rs (100%) rename ts-rs/tests/{ => integration}/type_override.rs (100%) rename ts-rs/tests/{ => integration}/union.rs (100%) rename ts-rs/tests/{ => integration}/union_named_serde_skip.rs (100%) rename ts-rs/tests/{ => integration}/union_rename.rs (100%) rename ts-rs/tests/{ => integration}/union_serde.rs (100%) rename ts-rs/tests/{ => integration}/union_unnamed_serde_skip.rs (100%) rename ts-rs/tests/{ => integration}/union_with_data.rs (100%) rename ts-rs/tests/{ => integration}/union_with_internal_tag.rs (100%) rename ts-rs/tests/{ => integration}/unit.rs (100%) rename ts-rs/tests/{ => integration}/unsized.rs (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 980ec1a1..4d9989fa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 @@ -28,7 +29,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 @@ -52,7 +54,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 @@ -74,7 +77,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 @@ -90,7 +94,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 @@ -107,7 +112,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 @@ -124,7 +130,8 @@ jobs: 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: actions-rs/toolchain@v1 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - uses: Swatinem/rust-cache@v2 diff --git a/.gitignore b/.gitignore index d90b7f98..217af8fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ target/ -Cargo.lock /.idea *.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d01ea0..8fc39e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,12 @@ - Add support for `#[ts(type = "..")]` directly on structs and enums ([#286](https://github.com/Aleph-Alpha/ts-rs/pull/286)) - Add support for `#[ts(as = "..")]` directly on structs and enums ([#288](https://github.com/Aleph-Alpha/ts-rs/pull/288)) - Add support for `#[ts(rename_all = "SCREAMING-KEBAB-CASE")]` ([#298](https://github.com/Aleph-Alpha/ts-rs/pull/298)) +- Support `_` in `#[ts(type = "..")]` to refer to the type of the field ([#299](https://github.com/Aleph-Alpha/ts-rs/pull/299)) ### Fixes - Fix `#[ts(rename_all_fields = "...")]` on enums containing tuple or unit variants ([#287](https://github.com/Aleph-Alpha/ts-rs/pull/287)) +- Fix "overflow evaluating the requirement" and "reached the recursion limit" errors in some cases ([#293](https://github.com/Aleph-Alpha/ts-rs/pull/293)) # 8.1.0 diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..5310ff96 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1747 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "ast_node" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e3e06ec6ac7d893a0db7127d91063ad7d9da8988f8a1a256f03729e6eec026" +dependencies = [ + "proc-macro2", + "quote", + "swc_macros_common", + "syn 2.0.48", +] + +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "better_scoped_tls" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "794edcc9b3fb07bb4aecaa11f093fd45663b4feadb782d68303a2268bc2701de" +dependencies = [ + "scoped-tls", +] + +[[package]] +name = "bigdecimal" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "bson" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce21468c1c9c154a85696bb25c20582511438edb6ad67f846ba1378ffdd80222" +dependencies = [ + "ahash", + "base64", + "bitvec", + "hex", + "indexmap", + "js-sys", + "once_cell", + "rand", + "serde", + "serde_bytes", + "serde_json", + "time", + "uuid", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +dependencies = [ + "allocator-api2", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cargo-ts" +version = "0.1.0" +dependencies = [ + "clap", + "color-eyre", +] + +[[package]] +name = "cc" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "color-eyre" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + +[[package]] +name = "data-url" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" + +[[package]] +name = "deno_ast" +version = "0.35.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c45813a2b6c658e5bc5a2f8336460f2b1c1c61a7adaf5e861df16ae3f3c76ca1" +dependencies = [ + "deno_media_type", + "deno_terminal", + "dprint-swc-ext", + "once_cell", + "percent-encoding", + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "swc_eq_ignore_macros", + "text_lines", + "unicode-width", + "url", +] + +[[package]] +name = "deno_media_type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a798670c20308e5770cc0775de821424ff9e85665b602928509c8c70430b3ee0" +dependencies = [ + "data-url", + "serde", + "url", +] + +[[package]] +name = "deno_terminal" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e6337d4e7f375f8b986409a76fbeecfa4bd8a1343e63355729ae4befa058eaf" +dependencies = [ + "once_cell", + "termcolor", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "dprint-core" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317f9cd1da390ab12e1858b3a71c7d6c8e8ad633454cb0b73ce5589964d9c177" +dependencies = [ + "anyhow", + "bumpalo", + "hashbrown", + "indexmap", + "rustc-hash", + "serde", + "unicode-width", +] + +[[package]] +name = "dprint-core-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1675ad2b358481f3cc46202040d64ac7a36c4ade414a696df32e0e45421a6e9f" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "dprint-plugin-typescript" +version = "0.90.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f180a70c7fae19cf6296a70d0850748e72d5162400491cde0aa424b22fd81212" +dependencies = [ + "anyhow", + "deno_ast", + "dprint-core", + "dprint-core-macros", + "percent-encoding", + "rustc-hash", + "serde", +] + +[[package]] +name = "dprint-swc-ext" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bad772f9e49af3a613fcddf1671d1e2e877e0a6d94f2b7162bfea4ac8140bee" +dependencies = [ + "allocator-api2", + "bumpalo", + "num-bigint", + "rustc-hash", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "text_lines", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "example" +version = "0.1.0" +dependencies = [ + "chrono", + "serde", + "ts-rs", + "uuid", +] + +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "from_variant" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a0b11eeb173ce52f84ebd943d42e58813a2ebb78a6a3ff0a243b71c5199cd7b" +dependencies = [ + "proc-macro2", + "swc_macros_common", + "syn 2.0.48", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "spin", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hstr" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0f5356d62012374578cd3a5c013d6586de3efbca3b53379fc1edfbb95c9db14" +dependencies = [ + "hashbrown", + "new_debug_unreachable", + "once_cell", + "phf", + "rustc-hash", + "triomphe", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "is-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a85abdc13717906baccb5a1e435556ce0df215f242892f721dff62bf25288f" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "js-sys" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "ordered-float" +version = "3.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +dependencies = [ + "num-traits", +] + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "serde_json" +version = "1.0.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "stacker" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" +dependencies = [ + "cc", + "cfg-if", + "libc", + "psm", + "winapi", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "string_enum" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b650ea2087d32854a0f20b837fc56ec987a1cb4f758c9757e1171ee9812da63" +dependencies = [ + "proc-macro2", + "quote", + "swc_macros_common", + "syn 2.0.48", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "swc_atoms" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04d9d1941a7d24fc503efa29c53f88dd61e6a15cc371947a75cca3b48d564b5b" +dependencies = [ + "hstr", + "once_cell", + "rustc-hash", + "serde", +] + +[[package]] +name = "swc_common" +version = "0.33.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f91d53367db183e55ecaa090c9a2b6e62ddbd1258aa2ac6c6925772eec9e2b" +dependencies = [ + "ast_node", + "better_scoped_tls", + "cfg-if", + "either", + "from_variant", + "new_debug_unreachable", + "num-bigint", + "once_cell", + "rustc-hash", + "serde", + "siphasher", + "swc_atoms", + "swc_eq_ignore_macros", + "swc_visit", + "tracing", + "unicode-width", + "url", +] + +[[package]] +name = "swc_ecma_ast" +version = "0.112.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bcd97ee367b48444f90416ea56e71d761600f816bcae9df4f99293d1fa36bd5" +dependencies = [ + "bitflags", + "is-macro", + "num-bigint", + "phf", + "scoped-tls", + "serde", + "string_enum", + "swc_atoms", + "swc_common", + "unicode-id-start", +] + +[[package]] +name = "swc_ecma_parser" +version = "0.143.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fc7ab256f83a9491b37a510dd1cba9d81bb306faf3cff1dacdbc897fa4869f" +dependencies = [ + "either", + "new_debug_unreachable", + "num-bigint", + "num-traits", + "phf", + "serde", + "smallvec", + "smartstring", + "stacker", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "tracing", + "typed-arena", +] + +[[package]] +name = "swc_eq_ignore_macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "swc_macros_common" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50176cfc1cbc8bb22f41c6fe9d1ec53fbe057001219b5954961b8ad0f336fce9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "swc_visit" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f5b3e8d1269a7cb95358fed3412645d9c15aa0eb1f4ca003a25a38ef2f30f1b" +dependencies = [ + "either", + "swc_visit_macros", +] + +[[package]] +name = "swc_visit_macros" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33fc817055fe127b4285dc85058596768bfde7537ae37da82c67815557f03e33" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "swc_macros_common", + "syn 2.0.48", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "text_lines" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd5828de7deaa782e1dd713006ae96b3bee32d3279b79eb67ecf8072c059bcf" +dependencies = [ + "serde", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +dependencies = [ + "deranged", + "itoa", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +dependencies = [ + "time-core", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" +dependencies = [ + "serde", + "stable_deref_trait", +] + +[[package]] +name = "ts-rs" +version = "8.1.0" +dependencies = [ + "bigdecimal", + "bson", + "bytes", + "chrono", + "dprint-plugin-typescript", + "heapless", + "indexmap", + "ordered-float", + "semver", + "serde", + "serde_json", + "thiserror", + "ts-rs-macros", + "url", + "uuid", +] + +[[package]] +name = "ts-rs-macros" +version = "8.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "termcolor", +] + +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-id-start" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f73150333cb58412db36f2aca8f2875b013049705cc77b94ded70a1ab1f5da" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "uuid" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.48", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] diff --git a/Cargo.toml b/Cargo.toml index 85309d7b..2269bbc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,4 @@ [workspace] members = ["macros", "ts-rs", "example", "cli"] resolver = "2" + diff --git a/e2e/dependencies/consumer/Cargo.lock b/e2e/dependencies/consumer/Cargo.lock new file mode 100644 index 00000000..50bbf2e8 --- /dev/null +++ b/e2e/dependencies/consumer/Cargo.lock @@ -0,0 +1,138 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + +[[package]] +name = "consumer" +version = "0.1.0" +dependencies = [ + "dependency1", + "ts-rs", +] + +[[package]] +name = "dependency1" +version = "0.1.0" +dependencies = [ + "ts-rs", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ts-rs" +version = "7.1.1" +dependencies = [ + "thiserror", + "ts-rs-macros", +] + +[[package]] +name = "ts-rs-macros" +version = "7.1.1" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", + "termcolor", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/e2e/dependencies/dependency1/Cargo.lock b/e2e/dependencies/dependency1/Cargo.lock new file mode 100644 index 00000000..94449e50 --- /dev/null +++ b/e2e/dependencies/dependency1/Cargo.lock @@ -0,0 +1,130 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + +[[package]] +name = "dependency1" +version = "0.1.0" +dependencies = [ + "ts-rs", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ts-rs" +version = "7.1.1" +dependencies = [ + "thiserror", + "ts-rs-macros", +] + +[[package]] +name = "ts-rs-macros" +version = "7.1.1" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", + "termcolor", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/e2e/workspace/Cargo.lock b/e2e/workspace/Cargo.lock new file mode 100644 index 00000000..c8251b93 --- /dev/null +++ b/e2e/workspace/Cargo.lock @@ -0,0 +1,146 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + +[[package]] +name = "crate1" +version = "0.1.0" +dependencies = [ + "ts-rs", +] + +[[package]] +name = "crate2" +version = "0.1.0" +dependencies = [ + "ts-rs", +] + +[[package]] +name = "parent" +version = "0.1.0" +dependencies = [ + "crate1", + "crate2", + "ts-rs", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ts-rs" +version = "7.1.1" +dependencies = [ + "thiserror", + "ts-rs-macros", +] + +[[package]] +name = "ts-rs-macros" +version = "7.1.1" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", + "termcolor", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/macros/src/attr/field.rs b/macros/src/attr/field.rs index 4dc4d2aa..1417777a 100644 --- a/macros/src/attr/field.rs +++ b/macros/src/attr/field.rs @@ -1,11 +1,15 @@ -use syn::{Attribute, Field, Ident, Result, Type}; +use syn::{ + AngleBracketedGenericArguments, Attribute, Field, GenericArgument, Ident, PathArguments, + Result, ReturnType, Type, TypeArray, TypeGroup, TypeParen, TypePath, TypePtr, TypeReference, + TypeSlice, TypeTuple, +}; use super::{parse_assign_from_str, parse_assign_str, Attr, Serde}; use crate::utils::{parse_attrs, parse_docs}; #[derive(Default)] pub struct FieldAttr { - pub type_as: Option, + type_as: Option, pub type_override: Option, pub rename: Option, pub inline: bool, @@ -41,6 +45,15 @@ impl FieldAttr { Ok(result) } + + pub fn type_as(&self, original_type: &Type) -> Type { + if let Some(mut ty) = self.type_as.clone() { + replace_underscore(&mut ty, original_type); + ty + } else { + original_type.clone() + } + } } impl Attr for FieldAttr { @@ -202,3 +215,58 @@ impl_parse! { }, } } + +fn replace_underscore(ty: &mut Type, with: &Type) { + match ty { + Type::Infer(_) => *ty = with.clone(), + Type::Array(TypeArray { elem, .. }) + | Type::Group(TypeGroup { elem, .. }) + | Type::Paren(TypeParen { elem, .. }) + | Type::Ptr(TypePtr { elem, .. }) + | Type::Reference(TypeReference { elem, .. }) + | Type::Slice(TypeSlice { elem, .. }) => { + replace_underscore(elem, with); + } + Type::Tuple(TypeTuple { elems, .. }) => { + for elem in elems { + replace_underscore(elem, with); + } + } + Type::Path(TypePath { path, qself: None }) => { + for segment in &mut path.segments { + match &mut segment.arguments { + PathArguments::None => (), + PathArguments::AngleBracketed(a) => { + replace_underscore_in_angle_bracketed(a, with); + } + PathArguments::Parenthesized(p) => { + for input in &mut p.inputs { + replace_underscore(input, with); + } + if let ReturnType::Type(_, output) = &mut p.output { + replace_underscore(output, with); + } + } + } + } + } + _ => (), + } +} + +fn replace_underscore_in_angle_bracketed(args: &mut AngleBracketedGenericArguments, with: &Type) { + for arg in &mut args.args { + match arg { + GenericArgument::Type(ty) => { + replace_underscore(ty, with); + } + GenericArgument::AssocType(assoc_ty) => { + replace_underscore(&mut assoc_ty.ty, with); + for g in &mut assoc_ty.generics { + replace_underscore_in_angle_bracketed(g, with); + } + } + _ => (), + } + } +} diff --git a/macros/src/types/enum.rs b/macros/src/types/enum.rs index 6dcc0f4e..3e85a925 100644 --- a/macros/src/types/enum.rs +++ b/macros/src/types/enum.rs @@ -135,30 +135,16 @@ fn format_variant( field_attr.assert_validity(field)?; - let FieldAttr { - type_as, - type_override, - skip, - .. - } = field_attr; - - if skip { + if field_attr.skip { quote!(format!("{{ \"{}\": \"{}\" }}", #tag, #name)) } else { - let ty = match (type_override, type_as) { - (Some(_), Some(_)) => { - unreachable!("This has been handled by assert_validity") - } - (Some(type_override), None) => quote! { #type_override }, - (None, Some(type_as)) => { - quote!(<#type_as as #crate_rename::TS>::name()) - } - (None, None) => { - let ty = &unnamed.unnamed[0].ty; + let ty = match field_attr.type_override { + Some(type_override) => quote!(#type_override), + None => { + let ty = field_attr.type_as(&field.ty); quote!(<#ty as #crate_rename::TS>::name()) } }; - quote!(format!("{{ \"{}\": \"{}\", \"{}\": {} }}", #tag, #name, #content, #ty)) } } @@ -191,26 +177,13 @@ fn format_variant( field_attr.assert_validity(field)?; - let FieldAttr { - type_as, - skip, - type_override, - .. - } = field_attr; - - if skip { + if field_attr.skip { quote!(format!("{{ \"{}\": \"{}\" }}", #tag, #name)) } else { - let ty = match (type_override, type_as) { - (Some(_), Some(_)) => { - unreachable!("This has been handled by assert_validity") - } - (Some(type_override), None) => quote! { #type_override }, - (None, Some(type_as)) => { - quote!(<#type_as as #crate_rename::TS>::name()) - } - (None, None) => { - let ty = &unnamed.unnamed[0].ty; + let ty = match field_attr.type_override { + Some(type_override) => quote! { #type_override }, + None => { + let ty = field_attr.type_as(&field.ty); quote!(<#ty as #crate_rename::TS>::name()) } }; diff --git a/macros/src/types/named.rs b/macros/src/types/named.rs index 3573c5bb..3457b7a1 100644 --- a/macros/src/types/named.rs +++ b/macros/src/types/named.rs @@ -92,27 +92,13 @@ fn format_field( field_attr.assert_validity(field)?; - let FieldAttr { - type_as, - type_override, - rename, - inline, - skip, - optional, - flatten, - docs, - - #[cfg(feature = "serde-compat")] - using_serde_with: _, - } = field_attr; - - if skip { + if field_attr.skip { return Ok(()); } - let parsed_ty = type_as.as_ref().unwrap_or(&field.ty).clone(); + let parsed_ty = field_attr.type_as(&field.ty); - let (ty, optional_annotation) = match optional { + let (ty, optional_annotation) = match field_attr.optional { Optional { optional: true, nullable, @@ -128,24 +114,27 @@ fn format_field( } => (&parsed_ty, ""), }; - if flatten { + if field_attr.flatten { flattened_fields.push(quote!(<#ty as #crate_rename::TS>::inline_flattened())); dependencies.append_from(ty); return Ok(()); } - let formatted_ty = type_override.map(|t| quote!(#t)).unwrap_or_else(|| { - if inline { - dependencies.append_from(ty); - quote!(<#ty as #crate_rename::TS>::inline()) - } else { - dependencies.push(ty); - quote!(<#ty as #crate_rename::TS>::name()) - } - }); + let formatted_ty = field_attr + .type_override + .map(|t| quote!(#t)) + .unwrap_or_else(|| { + if field_attr.inline { + dependencies.append_from(ty); + quote!(<#ty as #crate_rename::TS>::inline()) + } else { + dependencies.push(ty); + quote!(<#ty as #crate_rename::TS>::name()) + } + }); let field_name = to_ts_ident(field.ident.as_ref().unwrap()); - let name = match (rename, rename_all) { + let name = match (field_attr.rename, rename_all) { (Some(rn), _) => rn, (None, Some(rn)) => rn.apply(&field_name), (None, None) => field_name, @@ -153,9 +142,9 @@ fn format_field( let valid_name = raw_name_to_ts_field(name); // Start every doc string with a newline, because when other characters are in front, it is not "understood" by VSCode - let docs = match docs.is_empty() { + let docs = match field_attr.docs.is_empty() { true => "".to_string(), - false => format!("\n{}", &docs), + false => format!("\n{}", &field_attr.docs), }; formatted_fields.push(quote! { diff --git a/macros/src/types/newtype.rs b/macros/src/types/newtype.rs index e993386f..c48b9556 100644 --- a/macros/src/types/newtype.rs +++ b/macros/src/types/newtype.rs @@ -13,34 +13,25 @@ pub(crate) fn newtype(attr: &StructAttr, name: &str, fields: &FieldsUnnamed) -> let field_attr = FieldAttr::from_attrs(&inner.attrs)?; field_attr.assert_validity(inner)?; - let FieldAttr { - type_as, - type_override, - inline, - skip, - docs: _, - .. - } = field_attr; - let crate_rename = attr.crate_rename(); - if skip { + if field_attr.skip { return super::unit::null(attr, name); } - let inner_ty = type_as.as_ref().unwrap_or(&inner.ty).clone(); + let inner_ty = field_attr.type_as(&inner.ty); let mut dependencies = Dependencies::new(crate_rename.clone()); - match (&type_override, inline) { + match (&field_attr.type_override, field_attr.inline) { (Some(_), _) => (), (None, true) => dependencies.append_from(&inner_ty), (None, false) => dependencies.push(&inner_ty), }; - let inline_def = match type_override { + let inline_def = match field_attr.type_override { Some(ref o) => quote!(#o.to_owned()), - None if inline => quote!(<#inner_ty as #crate_rename::TS>::inline()), + None if field_attr.inline => quote!(<#inner_ty as #crate_rename::TS>::inline()), None => quote!(<#inner_ty as #crate_rename::TS>::name()), }; diff --git a/macros/src/types/tuple.rs b/macros/src/types/tuple.rs index 9b41b812..0b8571a6 100644 --- a/macros/src/types/tuple.rs +++ b/macros/src/types/tuple.rs @@ -49,33 +49,19 @@ fn format_field( let field_attr = FieldAttr::from_attrs(&field.attrs)?; field_attr.assert_validity(field)?; - let FieldAttr { - type_as, - type_override, - rename: _, - inline, - skip, - optional: _, - flatten: _, - docs: _, - - #[cfg(feature = "serde-compat")] - using_serde_with: _, - } = field_attr; - - if skip { + if field_attr.skip { return Ok(()); } - let ty = type_as.as_ref().unwrap_or(&field.ty).clone(); + let ty = field_attr.type_as(&field.ty); - formatted_fields.push(match type_override { + formatted_fields.push(match field_attr.type_override { Some(ref o) => quote!(#o.to_owned()), - None if inline => quote!(<#ty as #crate_rename::TS>::inline()), + None if field_attr.inline => quote!(<#ty as #crate_rename::TS>::inline()), None => quote!(<#ty as #crate_rename::TS>::name()), }); - match (inline, type_override) { + match (field_attr.inline, field_attr.type_override) { (_, Some(_)) => (), (false, _) => dependencies.push(&ty), (true, _) => dependencies.append_from(&ty), diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index d58fc93d..9a4eaa0d 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -58,3 +58,4 @@ thiserror = "1" indexmap = { version = "2", optional = true } ordered-float = { version = ">= 3, < 5", optional = true } serde_json = { version = "1", optional = true } + diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 0954e697..5eb7d0e3 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -287,7 +287,8 @@ pub mod typelist; /// /// - **`#[ts(as = "..")]`** /// Overrides the type of the annotated field, using the provided Rust type instead. -/// This is useful when there's a type for which you cannot derive `TS`. +/// This is useful when there's a type for which you cannot derive `TS`. +/// `_` may be used to refer to the type of the field, e.g `#[ts(as = "Option<_>")]`. ///

/// /// - **`#[ts(rename = "..")]`** diff --git a/ts-rs/tests/arrays.rs b/ts-rs/tests/integration/arrays.rs similarity index 100% rename from ts-rs/tests/arrays.rs rename to ts-rs/tests/integration/arrays.rs diff --git a/ts-rs/tests/bound.rs b/ts-rs/tests/integration/bound.rs similarity index 100% rename from ts-rs/tests/bound.rs rename to ts-rs/tests/integration/bound.rs diff --git a/ts-rs/tests/chrono.rs b/ts-rs/tests/integration/chrono.rs similarity index 100% rename from ts-rs/tests/chrono.rs rename to ts-rs/tests/integration/chrono.rs diff --git a/ts-rs/tests/concrete_generic.rs b/ts-rs/tests/integration/concrete_generic.rs similarity index 100% rename from ts-rs/tests/concrete_generic.rs rename to ts-rs/tests/integration/concrete_generic.rs diff --git a/ts-rs/tests/docs.rs b/ts-rs/tests/integration/docs.rs similarity index 100% rename from ts-rs/tests/docs.rs rename to ts-rs/tests/integration/docs.rs diff --git a/ts-rs/tests/enum_flattening.rs b/ts-rs/tests/integration/enum_flattening.rs similarity index 100% rename from ts-rs/tests/enum_flattening.rs rename to ts-rs/tests/integration/enum_flattening.rs diff --git a/ts-rs/tests/enum_flattening_nested.rs b/ts-rs/tests/integration/enum_flattening_nested.rs similarity index 100% rename from ts-rs/tests/enum_flattening_nested.rs rename to ts-rs/tests/integration/enum_flattening_nested.rs diff --git a/ts-rs/tests/enum_struct_rename_all.rs b/ts-rs/tests/integration/enum_struct_rename_all.rs similarity index 100% rename from ts-rs/tests/enum_struct_rename_all.rs rename to ts-rs/tests/integration/enum_struct_rename_all.rs diff --git a/ts-rs/tests/enum_variant_annotation.rs b/ts-rs/tests/integration/enum_variant_annotation.rs similarity index 100% rename from ts-rs/tests/enum_variant_annotation.rs rename to ts-rs/tests/integration/enum_variant_annotation.rs diff --git a/ts-rs/tests/export_manually.rs b/ts-rs/tests/integration/export_manually.rs similarity index 100% rename from ts-rs/tests/export_manually.rs rename to ts-rs/tests/integration/export_manually.rs diff --git a/ts-rs/tests/field_rename.rs b/ts-rs/tests/integration/field_rename.rs similarity index 100% rename from ts-rs/tests/field_rename.rs rename to ts-rs/tests/integration/field_rename.rs diff --git a/ts-rs/tests/flatten.rs b/ts-rs/tests/integration/flatten.rs similarity index 100% rename from ts-rs/tests/flatten.rs rename to ts-rs/tests/integration/flatten.rs diff --git a/ts-rs/tests/generic_fields.rs b/ts-rs/tests/integration/generic_fields.rs similarity index 100% rename from ts-rs/tests/generic_fields.rs rename to ts-rs/tests/integration/generic_fields.rs diff --git a/ts-rs/tests/generic_without_import.rs b/ts-rs/tests/integration/generic_without_import.rs similarity index 100% rename from ts-rs/tests/generic_without_import.rs rename to ts-rs/tests/integration/generic_without_import.rs diff --git a/ts-rs/tests/generics.rs b/ts-rs/tests/integration/generics.rs similarity index 100% rename from ts-rs/tests/generics.rs rename to ts-rs/tests/integration/generics.rs diff --git a/ts-rs/tests/hashmap.rs b/ts-rs/tests/integration/hashmap.rs similarity index 100% rename from ts-rs/tests/hashmap.rs rename to ts-rs/tests/integration/hashmap.rs diff --git a/ts-rs/tests/hashset.rs b/ts-rs/tests/integration/hashset.rs similarity index 100% rename from ts-rs/tests/hashset.rs rename to ts-rs/tests/integration/hashset.rs diff --git a/ts-rs/tests/imports.rs b/ts-rs/tests/integration/imports.rs similarity index 100% rename from ts-rs/tests/imports.rs rename to ts-rs/tests/integration/imports.rs diff --git a/ts-rs/tests/indexmap.rs b/ts-rs/tests/integration/indexmap.rs similarity index 100% rename from ts-rs/tests/indexmap.rs rename to ts-rs/tests/integration/indexmap.rs diff --git a/ts-rs/tests/integration/infer_as.rs b/ts-rs/tests/integration/infer_as.rs new file mode 100644 index 00000000..459aaacd --- /dev/null +++ b/ts-rs/tests/integration/infer_as.rs @@ -0,0 +1,15 @@ +#![allow(dead_code)] + +use ts_rs::TS; + +#[derive(TS)] +#[ts(export)] +struct Foo { + #[ts(optional, as = "Option<_>")] + my_optional_bool: bool, +} + +#[test] +fn test() { + assert_eq!(Foo::inline(), "{ my_optional_bool?: boolean, }"); +} diff --git a/ts-rs/tests/issue-168.rs b/ts-rs/tests/integration/issue_168.rs similarity index 100% rename from ts-rs/tests/issue-168.rs rename to ts-rs/tests/integration/issue_168.rs diff --git a/ts-rs/tests/issue-232.rs b/ts-rs/tests/integration/issue_232.rs similarity index 100% rename from ts-rs/tests/issue-232.rs rename to ts-rs/tests/integration/issue_232.rs diff --git a/ts-rs/tests/issue-70.rs b/ts-rs/tests/integration/issue_70.rs similarity index 100% rename from ts-rs/tests/issue-70.rs rename to ts-rs/tests/integration/issue_70.rs diff --git a/ts-rs/tests/issue-80.rs b/ts-rs/tests/integration/issue_80.rs similarity index 100% rename from ts-rs/tests/issue-80.rs rename to ts-rs/tests/integration/issue_80.rs diff --git a/ts-rs/tests/leading_colon.rs b/ts-rs/tests/integration/leading_colon.rs similarity index 100% rename from ts-rs/tests/leading_colon.rs rename to ts-rs/tests/integration/leading_colon.rs diff --git a/ts-rs/tests/lifetimes.rs b/ts-rs/tests/integration/lifetimes.rs similarity index 100% rename from ts-rs/tests/lifetimes.rs rename to ts-rs/tests/integration/lifetimes.rs diff --git a/ts-rs/tests/list.rs b/ts-rs/tests/integration/list.rs similarity index 100% rename from ts-rs/tests/list.rs rename to ts-rs/tests/integration/list.rs diff --git a/ts-rs/tests/integration/main.rs b/ts-rs/tests/integration/main.rs new file mode 100644 index 00000000..ed541a58 --- /dev/null +++ b/ts-rs/tests/integration/main.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused)] + +mod arrays; +mod bound; +mod chrono; +mod concrete_generic; +mod docs; +mod enum_flattening; +mod enum_flattening_nested; +mod enum_struct_rename_all; +mod enum_variant_annotation; +mod export_manually; +mod field_rename; +mod flatten; +mod generic_fields; +mod generic_without_import; +mod generics; +mod hashmap; +mod hashset; +mod imports; +mod indexmap; +mod infer_as; +mod issue_168; +mod issue_232; +mod issue_70; +mod issue_80; +mod leading_colon; +mod lifetimes; +mod list; +mod nested; +mod optional_field; +mod path_bug; +mod ranges; +mod raw_idents; +mod recursion_limit; +mod references; +mod self_referential; +mod semver; +mod serde_json; +mod serde_skip_with_default; +mod serde_with; +mod simple; +mod skip; +mod slices; +mod struct_rename; +mod struct_tag; +mod top_level_type_as; +mod top_level_type_override; +mod tuple; +mod type_as; +mod type_override; +mod union; +mod union_named_serde_skip; +mod union_rename; +mod union_serde; +mod union_unnamed_serde_skip; +mod union_with_data; +mod union_with_internal_tag; +mod unit; +mod r#unsized; diff --git a/ts-rs/tests/nested.rs b/ts-rs/tests/integration/nested.rs similarity index 100% rename from ts-rs/tests/nested.rs rename to ts-rs/tests/integration/nested.rs diff --git a/ts-rs/tests/optional_field.rs b/ts-rs/tests/integration/optional_field.rs similarity index 100% rename from ts-rs/tests/optional_field.rs rename to ts-rs/tests/integration/optional_field.rs diff --git a/ts-rs/tests/path_bug.rs b/ts-rs/tests/integration/path_bug.rs similarity index 100% rename from ts-rs/tests/path_bug.rs rename to ts-rs/tests/integration/path_bug.rs diff --git a/ts-rs/tests/ranges.rs b/ts-rs/tests/integration/ranges.rs similarity index 100% rename from ts-rs/tests/ranges.rs rename to ts-rs/tests/integration/ranges.rs diff --git a/ts-rs/tests/raw_idents.rs b/ts-rs/tests/integration/raw_idents.rs similarity index 100% rename from ts-rs/tests/raw_idents.rs rename to ts-rs/tests/integration/raw_idents.rs diff --git a/ts-rs/tests/recursion_limit.rs b/ts-rs/tests/integration/recursion_limit.rs similarity index 100% rename from ts-rs/tests/recursion_limit.rs rename to ts-rs/tests/integration/recursion_limit.rs diff --git a/ts-rs/tests/references.rs b/ts-rs/tests/integration/references.rs similarity index 100% rename from ts-rs/tests/references.rs rename to ts-rs/tests/integration/references.rs diff --git a/ts-rs/tests/self_referential.rs b/ts-rs/tests/integration/self_referential.rs similarity index 100% rename from ts-rs/tests/self_referential.rs rename to ts-rs/tests/integration/self_referential.rs diff --git a/ts-rs/tests/semver.rs b/ts-rs/tests/integration/semver.rs similarity index 100% rename from ts-rs/tests/semver.rs rename to ts-rs/tests/integration/semver.rs diff --git a/ts-rs/tests/serde_json.rs b/ts-rs/tests/integration/serde_json.rs similarity index 100% rename from ts-rs/tests/serde_json.rs rename to ts-rs/tests/integration/serde_json.rs diff --git a/ts-rs/tests/serde-skip-with-default.rs b/ts-rs/tests/integration/serde_skip_with_default.rs similarity index 100% rename from ts-rs/tests/serde-skip-with-default.rs rename to ts-rs/tests/integration/serde_skip_with_default.rs diff --git a/ts-rs/tests/serde_with.rs b/ts-rs/tests/integration/serde_with.rs similarity index 100% rename from ts-rs/tests/serde_with.rs rename to ts-rs/tests/integration/serde_with.rs diff --git a/ts-rs/tests/simple.rs b/ts-rs/tests/integration/simple.rs similarity index 100% rename from ts-rs/tests/simple.rs rename to ts-rs/tests/integration/simple.rs diff --git a/ts-rs/tests/skip.rs b/ts-rs/tests/integration/skip.rs similarity index 100% rename from ts-rs/tests/skip.rs rename to ts-rs/tests/integration/skip.rs diff --git a/ts-rs/tests/slices.rs b/ts-rs/tests/integration/slices.rs similarity index 100% rename from ts-rs/tests/slices.rs rename to ts-rs/tests/integration/slices.rs diff --git a/ts-rs/tests/struct_rename.rs b/ts-rs/tests/integration/struct_rename.rs similarity index 100% rename from ts-rs/tests/struct_rename.rs rename to ts-rs/tests/integration/struct_rename.rs diff --git a/ts-rs/tests/struct_tag.rs b/ts-rs/tests/integration/struct_tag.rs similarity index 100% rename from ts-rs/tests/struct_tag.rs rename to ts-rs/tests/integration/struct_tag.rs diff --git a/ts-rs/tests/top_level_type_as.rs b/ts-rs/tests/integration/top_level_type_as.rs similarity index 100% rename from ts-rs/tests/top_level_type_as.rs rename to ts-rs/tests/integration/top_level_type_as.rs diff --git a/ts-rs/tests/top_level_type_override.rs b/ts-rs/tests/integration/top_level_type_override.rs similarity index 100% rename from ts-rs/tests/top_level_type_override.rs rename to ts-rs/tests/integration/top_level_type_override.rs diff --git a/ts-rs/tests/tuple.rs b/ts-rs/tests/integration/tuple.rs similarity index 100% rename from ts-rs/tests/tuple.rs rename to ts-rs/tests/integration/tuple.rs diff --git a/ts-rs/tests/type_as.rs b/ts-rs/tests/integration/type_as.rs similarity index 100% rename from ts-rs/tests/type_as.rs rename to ts-rs/tests/integration/type_as.rs diff --git a/ts-rs/tests/type_override.rs b/ts-rs/tests/integration/type_override.rs similarity index 100% rename from ts-rs/tests/type_override.rs rename to ts-rs/tests/integration/type_override.rs diff --git a/ts-rs/tests/union.rs b/ts-rs/tests/integration/union.rs similarity index 100% rename from ts-rs/tests/union.rs rename to ts-rs/tests/integration/union.rs diff --git a/ts-rs/tests/union_named_serde_skip.rs b/ts-rs/tests/integration/union_named_serde_skip.rs similarity index 100% rename from ts-rs/tests/union_named_serde_skip.rs rename to ts-rs/tests/integration/union_named_serde_skip.rs diff --git a/ts-rs/tests/union_rename.rs b/ts-rs/tests/integration/union_rename.rs similarity index 100% rename from ts-rs/tests/union_rename.rs rename to ts-rs/tests/integration/union_rename.rs diff --git a/ts-rs/tests/union_serde.rs b/ts-rs/tests/integration/union_serde.rs similarity index 100% rename from ts-rs/tests/union_serde.rs rename to ts-rs/tests/integration/union_serde.rs diff --git a/ts-rs/tests/union_unnamed_serde_skip.rs b/ts-rs/tests/integration/union_unnamed_serde_skip.rs similarity index 100% rename from ts-rs/tests/union_unnamed_serde_skip.rs rename to ts-rs/tests/integration/union_unnamed_serde_skip.rs diff --git a/ts-rs/tests/union_with_data.rs b/ts-rs/tests/integration/union_with_data.rs similarity index 100% rename from ts-rs/tests/union_with_data.rs rename to ts-rs/tests/integration/union_with_data.rs diff --git a/ts-rs/tests/union_with_internal_tag.rs b/ts-rs/tests/integration/union_with_internal_tag.rs similarity index 100% rename from ts-rs/tests/union_with_internal_tag.rs rename to ts-rs/tests/integration/union_with_internal_tag.rs diff --git a/ts-rs/tests/unit.rs b/ts-rs/tests/integration/unit.rs similarity index 100% rename from ts-rs/tests/unit.rs rename to ts-rs/tests/integration/unit.rs diff --git a/ts-rs/tests/unsized.rs b/ts-rs/tests/integration/unsized.rs similarity index 100% rename from ts-rs/tests/unsized.rs rename to ts-rs/tests/integration/unsized.rs From b1b5cbe15e5f382054c0a2476f030e6c2de071c1 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 09:03:25 -0300 Subject: [PATCH 29/44] Clippy warning in test --- ts-rs/tests/integration/recursion_limit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ts-rs/tests/integration/recursion_limit.rs b/ts-rs/tests/integration/recursion_limit.rs index 1f0f98ae..fdafb5ab 100644 --- a/ts-rs/tests/integration/recursion_limit.rs +++ b/ts-rs/tests/integration/recursion_limit.rs @@ -1,3 +1,5 @@ +#![allow(clippy::upper_case_acronyms)] + use std::any::TypeId; use ts_rs::{ From 6790173badde19c196d201413dc4beb3e5f0bd3d Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 09:03:57 -0300 Subject: [PATCH 30/44] Remove duplicated infer_as test file --- ts-rs/tests/infer_as.rs | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 ts-rs/tests/infer_as.rs diff --git a/ts-rs/tests/infer_as.rs b/ts-rs/tests/infer_as.rs deleted file mode 100644 index 459aaacd..00000000 --- a/ts-rs/tests/infer_as.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(dead_code)] - -use ts_rs::TS; - -#[derive(TS)] -#[ts(export)] -struct Foo { - #[ts(optional, as = "Option<_>")] - my_optional_bool: bool, -} - -#[test] -fn test() { - assert_eq!(Foo::inline(), "{ my_optional_bool?: boolean, }"); -} From 50bfc35f7c70f52bbb4fef48164fecc45044126a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 09:04:21 -0300 Subject: [PATCH 31/44] Add error message about naming collisions --- cli/src/main.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 25e297ac..46bdb888 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -7,7 +7,7 @@ use std::{ }; use clap::Parser; -use color_eyre::Result; +use color_eyre::{owo_colors::OwoColorize, Result}; mod args; mod cargo; @@ -53,20 +53,28 @@ fn main() -> Result<()> { } if !metadata.is_empty() { - metadata - .iter() - .filter(|x| x.1.len() > 1) - .for_each(|(&ty, meta)| name_collision_warning(ty, meta)); + let mut naming_collisions = metadata.iter().filter(|x| x.1.len() > 1).peekable(); - let mut index = fs::OpenOptions::new() - .create(true) - .append(true) - .open(index_path)?; + let has_collisions = naming_collisions.peek().is_some(); - index.write_all(NOTE)?; + naming_collisions.for_each(|(&ty, meta)| name_collision_warning(ty, meta)); - for file in metadata.iter().flat_map(|x| x.1).map(|x| x.export_path) { - index.write_fmt(format_args!("\nexport * from {file:?};"))?; + if has_collisions { + eprintln!( + "{} due to the naming collisions listed above, generating an index.ts file is not possible", + "Error:".red().bold() + ); + } else { + let mut index = fs::OpenOptions::new() + .create(true) + .append(true) + .open(index_path)?; + + index.write_all(NOTE)?; + + for file in metadata.iter().flat_map(|x| x.1).map(|x| x.export_path) { + index.write_fmt(format_args!("\nexport * from {file:?};"))?; + } } } } From 88fc1401e630564bf1b8aa0772e69921eb32950a Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 09:37:49 -0300 Subject: [PATCH 32/44] Gate metadata file behind feature --- cli/src/cargo.rs | 2 ++ ts-rs/Cargo.toml | 1 + ts-rs/src/export.rs | 32 +++++++++++++++++--------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cli/src/cargo.rs b/cli/src/cargo.rs index ddef9a41..602d3a54 100644 --- a/cli/src/cargo.rs +++ b/cli/src/cargo.rs @@ -24,6 +24,8 @@ pub fn invoke(args: &Args) -> Result<()> { .arg("export_bindings_") .arg("--features") .arg("ts-rs/export") + .arg("--features") + .arg("ts-rs/generate-metadata") .stdout(if args.no_capture { Stdio::inherit() } else { diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index 9a4eaa0d..3bb6d575 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -35,6 +35,7 @@ serde-json-impl = ["serde_json"] no-serde-warnings = ["ts-rs-macros/no-serde-warnings"] import-esm = [] export = ["ts-rs-macros/export"] +generate-metadata = [] [dev-dependencies] serde = { version = "1.0", features = ["derive"] } diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index e7a7ee32..b1bd66fc 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -145,21 +145,23 @@ pub(crate) fn export_to>( file.write_all(buffer.as_bytes())?; file.sync_data()?; - let relative_path = T::output_path() - .ok_or_else(std::any::type_name::) - .map_err(ExportError::CannotBeExported)? - .to_string_lossy(); - - let type_ts_name = T::ident(); - let type_rs_name = std::any::type_name::().split('<').next().unwrap(); - - std::fs::OpenOptions::new() - .append(true) - .create(true) - .open(default_out_dir().join("ts_rs.meta"))? - .write_fmt(format_args!( - "{type_ts_name},{type_rs_name},./{relative_path}\n" - ))?; + if cfg!(feature = "generate-metadata") { + let relative_path = T::output_path() + .ok_or_else(std::any::type_name::) + .map_err(ExportError::CannotBeExported)? + .to_string_lossy(); + + let type_ts_name = T::ident(); + let type_rs_name = std::any::type_name::().split('<').next().unwrap(); + + std::fs::OpenOptions::new() + .append(true) + .create(true) + .open(default_out_dir().join("ts_rs.meta"))? + .write_fmt(format_args!( + "{type_ts_name},{type_rs_name},./{relative_path}\n" + ))?; + } } drop(lock); From 66c94dd9f2639b23b067c8c9ecbf8f0fa612d101 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 09:55:29 -0300 Subject: [PATCH 33/44] No longer capture stderr as that would silence serde warnings --- cli/src/cargo.rs | 7 ++----- ts-rs/tests/integration/infer_as.rs | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cli/src/cargo.rs b/cli/src/cargo.rs index 602d3a54..a9695f24 100644 --- a/cli/src/cargo.rs +++ b/cli/src/cargo.rs @@ -31,11 +31,6 @@ pub fn invoke(args: &Args) -> Result<()> { } else { Stdio::piped() }) - .stderr(if args.no_capture { - Stdio::inherit() - } else { - Stdio::piped() - }) .env("TS_RS_EXPORT_DIR", path::absolute(&args.output_directory)?); feature!(cargo_invocation, args, { @@ -46,6 +41,8 @@ pub fn invoke(args: &Args) -> Result<()> { if args.no_capture { cargo_invocation.arg("--").arg("--nocapture"); + } else { + cargo_invocation.arg("--quiet"); } cargo_invocation.spawn()?.wait()?; diff --git a/ts-rs/tests/integration/infer_as.rs b/ts-rs/tests/integration/infer_as.rs index 459aaacd..a546ffe3 100644 --- a/ts-rs/tests/integration/infer_as.rs +++ b/ts-rs/tests/integration/infer_as.rs @@ -2,9 +2,10 @@ use ts_rs::TS; -#[derive(TS)] +#[derive(TS, serde::Serialize)] #[ts(export)] struct Foo { + #[serde(skip_serializing_if = "std::ops::Not::not")] #[ts(optional, as = "Option<_>")] my_optional_bool: bool, } From 1461d3f1f51eb2b57ca7b1c8a309de94c67cf598 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 09:56:36 -0300 Subject: [PATCH 34/44] Remove changes to infer_as test --- ts-rs/tests/integration/infer_as.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ts-rs/tests/integration/infer_as.rs b/ts-rs/tests/integration/infer_as.rs index a546ffe3..459aaacd 100644 --- a/ts-rs/tests/integration/infer_as.rs +++ b/ts-rs/tests/integration/infer_as.rs @@ -2,10 +2,9 @@ use ts_rs::TS; -#[derive(TS, serde::Serialize)] +#[derive(TS)] #[ts(export)] struct Foo { - #[serde(skip_serializing_if = "std::ops::Not::not")] #[ts(optional, as = "Option<_>")] my_optional_bool: bool, } From b6c5c651d357448416d73009c9041cee7f9b7a9b Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 10:04:37 -0300 Subject: [PATCH 35/44] Make --output-directory required --- cli/src/args.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index 7bafd61c..5a4e3012 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -6,7 +6,7 @@ use clap::Parser; #[allow(clippy::struct_excessive_bools)] pub struct Args { /// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR - #[arg(long, short, default_value = "./bindings")] + #[arg(long, short)] pub output_directory: PathBuf, /// Disables warnings caused by using serde attributes that ts-rs cannot process @@ -27,6 +27,6 @@ pub struct Args { pub generate_index_ts: bool, /// Do not capture `cargo test`'s output, and pass --nocapture to the test binary - #[arg(long)] + #[arg(long = "nocapture")] pub no_capture: bool, } From c8a6b141a75ce6becba99df5ca39f0b6e4744b0b Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 17 Apr 2024 11:45:28 -0300 Subject: [PATCH 36/44] Make casing consistent --- macros/src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/src/utils.rs b/macros/src/utils.rs index 51511d3d..ae10acc5 100644 --- a/macros/src/utils.rs +++ b/macros/src/utils.rs @@ -200,7 +200,7 @@ mod warning { let mut buffer = writer.buffer(); buffer.set_color(&yellow_bold)?; - write!(&mut buffer, "warning")?; + write!(&mut buffer, "Warning")?; buffer.set_color(&white_bold)?; writeln!(&mut buffer, ": {}", title)?; From fcaa80ff48998b3ed047148c7f5e90c525c5190b Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 18 Apr 2024 09:28:52 -0300 Subject: [PATCH 37/44] Merge branch 'main' into cli --- CHANGELOG.md | 1 + macros/src/attr/field.rs | 8 ++++-- macros/src/lib.rs | 15 +++++----- ts-rs/tests/integration/infer_as.rs | 16 ++++++++++- ts-rs/tests/integration/issue_308.rs | 33 ++++++++++++++++++++++ ts-rs/tests/integration/main.rs | 1 + ts-rs/tests/integration/recursion_limit.rs | 1 + 7 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 ts-rs/tests/integration/issue_308.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc39e2f..fb011913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Fix `#[ts(rename_all_fields = "...")]` on enums containing tuple or unit variants ([#287](https://github.com/Aleph-Alpha/ts-rs/pull/287)) - Fix "overflow evaluating the requirement" and "reached the recursion limit" errors in some cases ([#293](https://github.com/Aleph-Alpha/ts-rs/pull/293)) +- Fix ambiguity causing "multiple applicable items in scope" errors in some cases ([#309](https://github.com/Aleph-Alpha/ts-rs/pull/309)) # 8.1.0 diff --git a/macros/src/attr/field.rs b/macros/src/attr/field.rs index 1417777a..dd8552c0 100644 --- a/macros/src/attr/field.rs +++ b/macros/src/attr/field.rs @@ -1,5 +1,5 @@ use syn::{ - AngleBracketedGenericArguments, Attribute, Field, GenericArgument, Ident, PathArguments, + AngleBracketedGenericArguments, Attribute, Field, GenericArgument, Ident, PathArguments, QSelf, Result, ReturnType, Type, TypeArray, TypeGroup, TypeParen, TypePath, TypePtr, TypeReference, TypeSlice, TypeTuple, }; @@ -232,7 +232,11 @@ fn replace_underscore(ty: &mut Type, with: &Type) { replace_underscore(elem, with); } } - Type::Path(TypePath { path, qself: None }) => { + Type::Path(TypePath { path, qself }) => { + if let Some(QSelf { ty, .. }) = qself { + replace_underscore(ty, with); + } + for segment in &mut path.segments { match &mut segment.arguments { PathArguments::None => (), diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 6055a2a1..f247d5ee 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -144,7 +144,7 @@ impl DerivedTS { .type_params() .filter(|ty| !self.concrete.contains_key(&ty.ident)) .map(|ty| ty.ident.clone()); - + let name = quote![::name()]; quote! { #( #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)] @@ -157,10 +157,10 @@ impl DerivedTS { impl #crate_rename::TS for #generics { type WithoutGenerics = #generics; fn name() -> String { stringify!(#generics).to_owned() } - fn inline() -> String { panic!("{} cannot be inlined", Self::name()) } - fn inline_flattened() -> String { panic!("{} cannot be flattened", Self::name()) } - fn decl() -> String { panic!("{} cannot be declared", Self::name()) } - fn decl_concrete() -> String { panic!("{} cannot be declared", Self::name()) } + fn inline() -> String { panic!("{} cannot be inlined", #name) } + fn inline_flattened() -> String { panic!("{} cannot be flattened", #name) } + fn decl() -> String { panic!("{} cannot be declared", #name) } + fn decl_concrete() -> String { panic!("{} cannot be declared", #name) } } )* } @@ -218,12 +218,13 @@ impl DerivedTS { fn generate_inline_fn(&self) -> TokenStream { let inline = &self.inline; + let crate_rename = &self.crate_rename; let inline_flattened = self.inline_flattened.as_ref().map_or_else( || { quote! { fn inline_flattened() -> String { - panic!("{} cannot be flattened", Self::name()) + panic!("{} cannot be flattened", ::name()) } } }, @@ -279,7 +280,7 @@ impl DerivedTS { }); quote! { fn decl_concrete() -> String { - format!("type {} = {};", #name, Self::inline()) + format!("type {} = {};", #name, ::inline()) } fn decl() -> String { #generic_types diff --git a/ts-rs/tests/integration/infer_as.rs b/ts-rs/tests/integration/infer_as.rs index 459aaacd..09fa4c58 100644 --- a/ts-rs/tests/integration/infer_as.rs +++ b/ts-rs/tests/integration/infer_as.rs @@ -2,14 +2,28 @@ use ts_rs::TS; +trait Bar { + type Baz; +} + +impl Bar for String { + type Baz = i32; +} + #[derive(TS)] #[ts(export)] struct Foo { #[ts(optional, as = "Option<_>")] my_optional_bool: bool, + + #[ts(as = "<_ as Bar>::Baz")] + q_self: String, } #[test] fn test() { - assert_eq!(Foo::inline(), "{ my_optional_bool?: boolean, }"); + assert_eq!( + Foo::inline(), + "{ my_optional_bool?: boolean, q_self: number, }" + ); } diff --git a/ts-rs/tests/integration/issue_308.rs b/ts-rs/tests/integration/issue_308.rs new file mode 100644 index 00000000..6e2faf5b --- /dev/null +++ b/ts-rs/tests/integration/issue_308.rs @@ -0,0 +1,33 @@ +use std::path::{Path, PathBuf}; + +use ts_rs::{typelist::TypeList, Dependency, ExportError, TS}; + +#[rustfmt::skip] +trait Malicious { + type WithoutGenerics: TS + ?Sized; + const DOCS: Option<&'static str> = None; + + fn ident() -> String { unimplemented!() } + fn decl() -> String { unimplemented!() } + fn decl_concrete() -> String { unimplemented!() } + fn name() -> String { unimplemented!() } + fn inline() -> String { unimplemented!() } + fn inline_flattened() -> String { unimplemented!() } + fn dependency_types() -> impl TypeList {} + fn generics() -> impl TypeList {} + fn dependencies() -> Vec { unimplemented!() } + fn export() -> Result<(), ExportError> { unimplemented!() } + fn export_all() -> Result<(), ExportError> { unimplemented!() } + fn export_all_to(out_dir: impl AsRef) -> Result<(), ExportError> { unimplemented!() } + fn export_to_string() -> Result { unimplemented!() } + fn output_path() -> Option<&'static Path> { unimplemented!() } + fn default_output_path() -> Option { unimplemented!() } +} + +impl Malicious for T { + type WithoutGenerics = (); +} + +#[derive(TS)] +#[ts(export, export_to = "issue_308/")] +struct MyStruct(A, B); diff --git a/ts-rs/tests/integration/main.rs b/ts-rs/tests/integration/main.rs index ed541a58..62bbeab0 100644 --- a/ts-rs/tests/integration/main.rs +++ b/ts-rs/tests/integration/main.rs @@ -22,6 +22,7 @@ mod indexmap; mod infer_as; mod issue_168; mod issue_232; +mod issue_308; mod issue_70; mod issue_80; mod leading_colon; diff --git a/ts-rs/tests/integration/recursion_limit.rs b/ts-rs/tests/integration/recursion_limit.rs index fdafb5ab..b4867684 100644 --- a/ts-rs/tests/integration/recursion_limit.rs +++ b/ts-rs/tests/integration/recursion_limit.rs @@ -8,6 +8,7 @@ use ts_rs::{ }; #[rustfmt::skip] +#[allow(clippy::all)] #[derive(Debug, ts_rs::TS)] #[ts(export, export_to = "very_big_types/")] pub enum Iso4217CurrencyCode { From c930c0f92944c6ab0f3b70b7dc20aff617ae9603 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 22 Apr 2024 15:09:29 -0300 Subject: [PATCH 38/44] Avoid extra collection allocation --- cli/src/main.rs | 63 ++++++++++++++++++++++----------------------- cli/src/metadata.rs | 6 ++--- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 46bdb888..9b4f5095 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -33,48 +33,47 @@ fn main() -> Result<()> { if args.generate_index_ts { let metadata_content = fs::read_to_string(&metadata_path)?; - let metadata = metadata_content - .lines() - .collect::>() - .into_iter() - .fold(HashMap::<_, Vec<_>>::default(), |mut acc, cur| { - let (key, value) = cur.split_once(',').unwrap(); + let metadata = + metadata_content + .lines() + .fold(HashMap::<_, HashSet<_>>::default(), |mut acc, cur| { + let (key, value) = cur.split_once(',').unwrap(); - let value = Metadata::try_from(value).unwrap(); - acc.entry(key).or_default().push(value); + let value = Metadata::try_from(value).unwrap(); + acc.entry(key).or_default().insert(value); - acc - }); + acc + }); - let index_path = args.output_directory.join("index.ts"); + let mut naming_collisions = metadata.iter().filter(|x| x.1.len() > 1).peekable(); - if index_path.exists() { - fs::remove_file(&index_path)?; + if naming_collisions.peek().is_some() { + naming_collisions.for_each(|(&ty, meta)| name_collision_warning(ty, meta)); + + eprintln!( + "{} due to the naming collisions listed above, generating an index.ts file is not possible", + "Error:".red().bold() + ); + + return Ok(()); } if !metadata.is_empty() { - let mut naming_collisions = metadata.iter().filter(|x| x.1.len() > 1).peekable(); + let index_path = args.output_directory.join("index.ts"); - let has_collisions = naming_collisions.peek().is_some(); + if index_path.exists() { + fs::remove_file(&index_path)?; + } - naming_collisions.for_each(|(&ty, meta)| name_collision_warning(ty, meta)); + let mut index = fs::OpenOptions::new() + .create(true) + .append(true) + .open(index_path)?; + + index.write_all(NOTE)?; - if has_collisions { - eprintln!( - "{} due to the naming collisions listed above, generating an index.ts file is not possible", - "Error:".red().bold() - ); - } else { - let mut index = fs::OpenOptions::new() - .create(true) - .append(true) - .open(index_path)?; - - index.write_all(NOTE)?; - - for file in metadata.iter().flat_map(|x| x.1).map(|x| x.export_path) { - index.write_fmt(format_args!("\nexport * from {file:?};"))?; - } + for file in metadata.iter().flat_map(|x| x.1).map(|x| x.export_path) { + index.write_fmt(format_args!("\nexport * from {file:?};"))?; } } } diff --git a/cli/src/metadata.rs b/cli/src/metadata.rs index 3087ba49..87eeb1ba 100644 --- a/cli/src/metadata.rs +++ b/cli/src/metadata.rs @@ -1,8 +1,8 @@ -use std::path::Path; +use std::{collections::HashSet, path::Path}; use color_eyre::{eyre::OptionExt, owo_colors::OwoColorize}; -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq, Hash)] pub struct Metadata<'a> { pub rust_name: &'a str, pub export_path: &'a Path, @@ -22,7 +22,7 @@ impl<'a> TryFrom<&'a str> for Metadata<'a> { } } -pub fn name_collision_warning(ts_type: &str, metadata: &[Metadata]) { +pub fn name_collision_warning(ts_type: &str, metadata: &HashSet) { eprintln!( "{} Multiple types being exported with the name \"{}\"", "Warning:".yellow().bold(), From 9b19079832782eefd3618127795953c52ab46075 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 23 Apr 2024 10:18:05 -0300 Subject: [PATCH 39/44] Improve parsing of Metadata --- cli/src/args.rs | 11 ++++++++ cli/src/main.rs | 36 +++++++------------------ cli/src/metadata.rs | 66 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 78 insertions(+), 35 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index 5a4e3012..700346f6 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -2,6 +2,8 @@ use std::path::PathBuf; use clap::Parser; +use crate::metadata::FILE_NAME; + #[derive(Parser, Debug)] #[allow(clippy::struct_excessive_bools)] pub struct Args { @@ -30,3 +32,12 @@ pub struct Args { #[arg(long = "nocapture")] pub no_capture: bool, } + +// Args is in scope for the entirety of the main function, so this will only +// be executed when the program is finished running. This helps prevent us +// from forgetting to do cleanup if some code branch early returns from main +impl Drop for Args { + fn drop(&mut self) { + _ = std::fs::remove_file(self.output_directory.join(FILE_NAME)); + } +} diff --git a/cli/src/main.rs b/cli/src/main.rs index 9b4f5095..65bcee2a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,10 +1,6 @@ #![warn(clippy::pedantic, clippy::nursery)] -use std::{ - collections::{HashMap, HashSet}, - fs, - io::Write, -}; +use std::{fs, io::Write}; use clap::Parser; use color_eyre::{owo_colors::OwoColorize, Result}; @@ -15,7 +11,7 @@ mod metadata; mod path; use args::Args; -use metadata::{name_collision_warning, Metadata}; +use metadata::{Metadata, FILE_NAME}; const NOTE: &[u8; 109] = b"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n"; @@ -24,31 +20,19 @@ fn main() -> Result<()> { let args = Args::parse(); - let metadata_path = args.output_directory.join("ts_rs.meta"); + let metadata_path = args.output_directory.join(FILE_NAME); if metadata_path.exists() { fs::remove_file(&metadata_path)?; } cargo::invoke(&args)?; - if args.generate_index_ts { - let metadata_content = fs::read_to_string(&metadata_path)?; - let metadata = - metadata_content - .lines() - .fold(HashMap::<_, HashSet<_>>::default(), |mut acc, cur| { - let (key, value) = cur.split_once(',').unwrap(); - - let value = Metadata::try_from(value).unwrap(); - acc.entry(key).or_default().insert(value); - - acc - }); + let metadata_content = fs::read_to_string(&metadata_path)?; + let metadata = Metadata::new(&metadata_content)?; - let mut naming_collisions = metadata.iter().filter(|x| x.1.len() > 1).peekable(); - - if naming_collisions.peek().is_some() { - naming_collisions.for_each(|(&ty, meta)| name_collision_warning(ty, meta)); + if args.generate_index_ts { + if metadata.has_naming_collisions() { + metadata.report_naming_collisions(); eprintln!( "{} due to the naming collisions listed above, generating an index.ts file is not possible", @@ -72,13 +56,11 @@ fn main() -> Result<()> { index.write_all(NOTE)?; - for file in metadata.iter().flat_map(|x| x.1).map(|x| x.export_path) { + for file in metadata.export_paths() { index.write_fmt(format_args!("\nexport * from {file:?};"))?; } } } - fs::remove_file(&metadata_path)?; - Ok(()) } diff --git a/cli/src/metadata.rs b/cli/src/metadata.rs index 87eeb1ba..efc70e51 100644 --- a/cli/src/metadata.rs +++ b/cli/src/metadata.rs @@ -1,15 +1,65 @@ -use std::{collections::HashSet, path::Path}; +use std::{ + collections::{HashMap, HashSet}, + path::Path, +}; -use color_eyre::{eyre::OptionExt, owo_colors::OwoColorize}; +use color_eyre::{ + eyre::{Error, OptionExt}, + owo_colors::OwoColorize, + Result, +}; + +pub const FILE_NAME: &str = "ts_rs.meta"; -#[derive(Clone, PartialEq, Eq, Hash)] pub struct Metadata<'a> { - pub rust_name: &'a str, - pub export_path: &'a Path, + entries: std::collections::HashMap<&'a str, HashSet>>, +} + +impl<'a> Metadata<'a> { + pub fn new(content: &'a str) -> Result { + Ok(Self { + entries: content.lines().try_fold( + HashMap::<&str, HashSet<_>>::default(), + |mut acc, cur| { + let (key, value) = cur.split_once(',').ok_or_eyre("Invalid metadata file")?; + let value = Entry::try_from(value)?; + + acc.entry(key).or_default().insert(value); + + Ok::<_, Error>(acc) + }, + )?, + }) + } + + pub fn is_empty(&self) -> bool { + self.entries.is_empty() + } + + pub fn has_naming_collisions(&self) -> bool { + self.entries.values().any(|x| x.len() > 1) + } + + pub fn report_naming_collisions(&self) { + self.entries + .iter() + .filter(|(_, x)| x.len() > 1) + .for_each(|(ty, entry)| name_collision_warning(ty, entry)); + } + + pub fn export_paths(&self) -> impl Iterator { + self.entries.values().flatten().map(|x| x.export_path) + } +} + +#[derive(PartialEq, Eq, Hash)] +struct Entry<'a> { + rust_name: &'a str, + export_path: &'a Path, } -impl<'a> TryFrom<&'a str> for Metadata<'a> { - type Error = color_eyre::eyre::Error; +impl<'a> TryFrom<&'a str> for Entry<'a> { + type Error = Error; fn try_from(value: &'a str) -> Result { let (rust_name, export_path) = @@ -22,7 +72,7 @@ impl<'a> TryFrom<&'a str> for Metadata<'a> { } } -pub fn name_collision_warning(ts_type: &str, metadata: &HashSet) { +fn name_collision_warning(ts_type: &str, metadata: &HashSet) { eprintln!( "{} Multiple types being exported with the name \"{}\"", "Warning:".yellow().bold(), From 8ff6688fbcaa832a863546522c434074c61303dc Mon Sep 17 00:00:00 2001 From: Gustavo Date: Tue, 23 Apr 2024 10:21:47 -0300 Subject: [PATCH 40/44] Replace new with try_from for clarity --- cli/src/main.rs | 2 +- cli/src/metadata.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 65bcee2a..680f989a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -28,7 +28,7 @@ fn main() -> Result<()> { cargo::invoke(&args)?; let metadata_content = fs::read_to_string(&metadata_path)?; - let metadata = Metadata::new(&metadata_content)?; + let metadata = Metadata::try_from(&*metadata_content)?; if args.generate_index_ts { if metadata.has_naming_collisions() { diff --git a/cli/src/metadata.rs b/cli/src/metadata.rs index efc70e51..e04cc2bf 100644 --- a/cli/src/metadata.rs +++ b/cli/src/metadata.rs @@ -15,10 +15,12 @@ pub struct Metadata<'a> { entries: std::collections::HashMap<&'a str, HashSet>>, } -impl<'a> Metadata<'a> { - pub fn new(content: &'a str) -> Result { +impl<'a> TryFrom<&'a str> for Metadata<'a> { + type Error = Error; + + fn try_from(value: &'a str) -> Result { Ok(Self { - entries: content.lines().try_fold( + entries: value.lines().try_fold( HashMap::<&str, HashSet<_>>::default(), |mut acc, cur| { let (key, value) = cur.split_once(',').ok_or_eyre("Invalid metadata file")?; @@ -31,7 +33,9 @@ impl<'a> Metadata<'a> { )?, }) } +} +impl<'a> Metadata<'a> { pub fn is_empty(&self) -> bool { self.entries.is_empty() } From f229f92574f4834c0e18fe65c870a99e2a34c4cf Mon Sep 17 00:00:00 2001 From: escritorio-gustavo <131818645+escritorio-gustavo@users.noreply.github.com> Date: Thu, 9 May 2024 15:25:32 -0300 Subject: [PATCH 41/44] Add option to export all types to a single file --- cli/src/args.rs | 5 +++ cli/src/main.rs | 85 ++++++++++++++++++++++++++++++++++++------------- cli/src/path.rs | 30 +++++++++++++++++ 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index 700346f6..86cde5f8 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -28,6 +28,11 @@ pub struct Args { #[arg(long = "index")] pub generate_index_ts: bool, + /// Generates only a single index.ts file in your --output-directory that + /// contains all exported types + #[arg(long = "merge")] + pub merge_files: bool, + /// Do not capture `cargo test`'s output, and pass --nocapture to the test binary #[arg(long = "nocapture")] pub no_capture: bool, diff --git a/cli/src/main.rs b/cli/src/main.rs index 680f989a..005684c5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,6 +1,9 @@ #![warn(clippy::pedantic, clippy::nursery)] -use std::{fs, io::Write}; +use std::{ + fs::{self, OpenOptions}, + io::{Read, Write}, +}; use clap::Parser; use color_eyre::{owo_colors::OwoColorize, Result}; @@ -13,6 +16,7 @@ mod path; use args::Args; use metadata::{Metadata, FILE_NAME}; +const BLANK_LINE: [u8; 2] = [b'\n', b'\n']; const NOTE: &[u8; 109] = b"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n"; fn main() -> Result<()> { @@ -25,41 +29,78 @@ fn main() -> Result<()> { fs::remove_file(&metadata_path)?; } + if args.merge_files && args.generate_index_ts { + eprintln!( + "{} --index is not compatible with --merge", + "Error:".red().bold() + ); + + return Ok(()); + } + cargo::invoke(&args)?; let metadata_content = fs::read_to_string(&metadata_path)?; let metadata = Metadata::try_from(&*metadata_content)?; - if args.generate_index_ts { - if metadata.has_naming_collisions() { - metadata.report_naming_collisions(); + let demand_unique_names = args.merge_files || args.generate_index_ts; + + if !demand_unique_names || metadata.is_empty() { + return Ok(()); + } + + if metadata.has_naming_collisions() { + metadata.report_naming_collisions(); + + eprintln!( + "{} due to the naming collisions listed above, generating an index.ts file is not possible", + "Error:".red().bold() + ); + + return Ok(()); + } - eprintln!( - "{} due to the naming collisions listed above, generating an index.ts file is not possible", - "Error:".red().bold() - ); + let index_path = args.output_directory.join("index.ts"); - return Ok(()); + if index_path.exists() { + fs::remove_file(&index_path)?; + } + + let mut index = OpenOptions::new() + .create(true) + .append(true) + .open(index_path)?; + + index.write_all(NOTE)?; + + if args.generate_index_ts { + for path in metadata.export_paths() { + index.write_fmt(format_args!("\nexport * from {path:?};"))?; } - if !metadata.is_empty() { - let index_path = args.output_directory.join("index.ts"); + return Ok(()); + } + + if args.merge_files { + for path in metadata.export_paths() { + let path = path::absolute(args.output_directory.join(path))?; + let mut file = OpenOptions::new().read(true).open(&path)?; - if index_path.exists() { - fs::remove_file(&index_path)?; - } + let mut buf = Vec::with_capacity(file.metadata()?.len().try_into()?); + file.read_to_end(&mut buf)?; - let mut index = fs::OpenOptions::new() - .create(true) - .append(true) - .open(index_path)?; + let Some((i, _)) = buf.windows(2).enumerate().find(|(_, w)| w == &BLANK_LINE) else { + continue; + }; - index.write_all(NOTE)?; + index.write_all(&buf[i + 1..])?; - for file in metadata.export_paths() { - index.write_fmt(format_args!("\nexport * from {file:?};"))?; - } + fs::remove_file(path)?; } + + path::remove_empty_subdirectories(&args.output_directory)?; + + return Ok(()); } Ok(()) diff --git a/cli/src/path.rs b/cli/src/path.rs index 257a7145..2b1d224e 100644 --- a/cli/src/path.rs +++ b/cli/src/path.rs @@ -28,3 +28,33 @@ pub fn absolute>(path: T) -> Result { out.iter().collect() }) } + +pub fn remove_empty_subdirectories>(path: T) -> Result<()> { + let path = path.as_ref(); + + for entry in path.read_dir()? { + let entry = entry?; + + let path = entry.path(); + + if !path.is_dir() { + continue; + } + + remove_empty_subdirectories(&path)?; + if let Err(e) = fs::remove_dir(path) { + // The other possible error kinds are either not available + // in stable rust (DirectoryNotEmpty), not possible due + // to the logic of this function (NotFound) or both (NotADirectory) + // + // The correct check would be `!matches!(e.kind(), ErrorKind::DirectoryNotEmpty)` + // as that is the only error we actually WANT to ignore... the others, + // although impossible, should be returned if they somehow happen + if matches!(e.kind(), ErrorKind::PermissionDenied) { + return Err(e.into()); + } + } + } + + Ok(()) +} From c9b29aa3315df0ecad984313d7e02059bd79b6d2 Mon Sep 17 00:00:00 2001 From: escritorio-gustavo <131818645+escritorio-gustavo@users.noreply.github.com> Date: Thu, 9 May 2024 15:28:26 -0300 Subject: [PATCH 42/44] Missing imports --- cli/src/path.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/src/path.rs b/cli/src/path.rs index 2b1d224e..23087163 100644 --- a/cli/src/path.rs +++ b/cli/src/path.rs @@ -1,4 +1,8 @@ -use std::path::{Component as C, Path, PathBuf}; ++use std::{ + fs, + io::ErrorKind, + path::{Component as C, Path, PathBuf}, +}; use color_eyre::{eyre::OptionExt, Result}; From 89430eb1678df311896ed7f4c09897acb270bfe4 Mon Sep 17 00:00:00 2001 From: escritorio-gustavo <131818645+escritorio-gustavo@users.noreply.github.com> Date: Thu, 9 May 2024 15:28:59 -0300 Subject: [PATCH 43/44] Fix Syntax Error --- cli/src/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/path.rs b/cli/src/path.rs index 23087163..6e4255e3 100644 --- a/cli/src/path.rs +++ b/cli/src/path.rs @@ -1,4 +1,4 @@ -+use std::{ +use std::{ fs, io::ErrorKind, path::{Component as C, Path, PathBuf}, From 5abdda9dc966b159505cc0cc0307b3d608506a0f Mon Sep 17 00:00:00 2001 From: gustavo-shigueo Date: Thu, 10 Oct 2024 08:59:30 -0300 Subject: [PATCH 44/44] Fix lockfile --- Cargo.lock | 218 ++++++++++++++++++++++++++++------------------------- 1 file changed, 116 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba6295df..90636dd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.22.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -72,9 +72,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -87,36 +87,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -134,20 +134,20 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -166,9 +166,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "better_scoped_tls" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794edcc9b3fb07bb4aecaa11f093fd45663b4feadb782d68303a2268bc2701de" +checksum = "297b153aa5e573b5863108a6ddc9d5c968bd0b20e75cc614ee9821d2f45679c7" dependencies = [ "scoped-tls", ] @@ -266,9 +266,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.21" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -302,9 +302,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.10" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6b81fb3c84f5563d509c59b5a48d935f689e993afa90fe39047f05adef9142" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -312,9 +312,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.10" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca6706fd5224857d9ac5eb9355f6683563cc0541c7cd9d014043b57cbec78ac" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -324,21 +324,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.8" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.79", ] [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "color-eyre" @@ -369,9 +369,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "core-foundation-sys" @@ -446,7 +446,7 @@ checksum = "f3ab0dd2bedc109d25f0d21afb09b7d329f6c6fa83b095daf31d2d967e091548" dependencies = [ "anyhow", "bumpalo", - "hashbrown", + "hashbrown 0.14.5", "indexmap", "rustc-hash", "serde", @@ -544,7 +544,7 @@ checksum = "32016f1242eb82af5474752d00fd8ebcd9004bd69b462b1c91de833972d08ed4" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -566,9 +566,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "hash32" @@ -589,6 +589,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "heapless" version = "0.8.0" @@ -617,7 +623,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dae404c0c5d4e95d4858876ab02eecd6a196bb8caa42050dfa809938833fc412" dependencies = [ - "hashbrown", + "hashbrown 0.14.5", "new_debug_unreachable", "once_cell", "phf", @@ -666,12 +672,12 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.0", "serde", ] @@ -684,14 +690,14 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" @@ -701,9 +707,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "0cb94a0ffd3f3ee755c20f7d8752f45cac88605a4dcf808abcff72873296ec7b" dependencies = [ "wasm-bindgen", ] @@ -716,9 +722,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" @@ -790,24 +796,24 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "ordered-float" -version = "4.2.2" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a91171844676f8c7990ce64959210cd2eaef32c2612c50f9fae9f8aaa6065a6" +checksum = "44d501f1a72f71d3c063a6bbc8f7271fa73aa09fe5d6283b6571e2ed176a2537" dependencies = [ "num-traits", ] @@ -854,7 +860,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -889,9 +895,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -952,9 +958,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -964,9 +970,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -975,9 +981,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustc-demangle" @@ -1035,7 +1041,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1115,7 +1121,7 @@ dependencies = [ "cfg-if", "libc", "psm", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1133,7 +1139,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1227,18 +1233,18 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "swc_macros_common" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f486687bfb7b5c560868f69ed2d458b880cebc9babebcb67e49f31b55c5bf847" +checksum = "27e18fbfe83811ffae2bb23727e45829a0d19c6870bced7c0f545cc99ad248dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1261,7 +1267,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1277,9 +1283,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -1312,22 +1318,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1338,7 +1344,6 @@ checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" dependencies = [ "cfg-if", "once_cell", - "syn 2.0.77", ] [[package]] @@ -1416,7 +1421,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1452,9 +1457,9 @@ dependencies = [ [[package]] name = "triomphe" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6631e42e10b40c0690bf92f404ebcfe6e1fdb480391d15f17cc8e96eeed5369" +checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85" dependencies = [ "serde", "stable_deref_trait", @@ -1490,7 +1495,7 @@ version = "10.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "termcolor", ] @@ -1502,9 +1507,9 @@ checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-id-start" @@ -1529,9 +1534,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "url" @@ -1581,9 +1586,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "ef073ced962d62984fb38a36e5fdc1a2b23c9e0e1fa0689bb97afa4202ef6887" dependencies = [ "cfg-if", "once_cell", @@ -1592,24 +1597,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "c4bfab14ef75323f4eb75fa52ee0a3fb59611977fd3240da19b2cf36ff85030e" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "a7bec9830f60924d9ceb3ef99d55c155be8afa76954edffbb5936ff4509474e7" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1617,22 +1622,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "4c74f6e152a76a2ad448e223b0fc0b6b5747649c3d769cc6bf45737bf97d0ed6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "a42f6c679374623f295a8623adfe63d9284091245c3504bde47c17a3ce2777d9" [[package]] name = "winapi-util" @@ -1640,7 +1645,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1652,6 +1657,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.59.0" @@ -1752,5 +1766,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ]