Skip to content

Conversation

gustavo-shigueo
Copy link
Collaborator

@gustavo-shigueo gustavo-shigueo commented Apr 5, 2025

I'm copying the original cli PR into a new one for a couple of reasons:

  • The thread on the old one is VERY long and is getting hard to follow
  • Whoever is using the account that opened that PR (if anyone) probably doesn't wanna receive notifications about it

Closes #133
Closes #54
Closes #408

Todo

  • Find a way to only run ts-rs tests through this CLI
    • Done by gating the generation of tests
      • Added a feature flag called export to ts-rs that re-enables test generation.
      • This feature is always enabled when using this CLI
  • Explore a way of generating an index.ts file to reexport all the generated types
    • During export, generate a metadata file to list all types and where they are exported to
      • In the CLI, use the metadata file to create the index.ts file
      • Gate the generation of this file behind a feature flag named generate-metadata
  • A configuration file so the user doesn't have to pass the flags every time
    • Add config flag to pass the path to the file?
    • Add init subcommand to help create the config file
  • Discuss other features of the CLI
  • When we consider it ready, it would be interesting to also make it available through cargo binstall

Feature wishlist

Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

cli/src/args.rs Outdated
Comment on lines 31 to 34
/// Generates only a single index.ts file in your --output-directory that
/// contains all exported types
#[arg(long = "merge")]
pub merge_files: bool,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the combination of #316 and #399 has made this flag obsolete, as the user can create a const and use it on all export_to attributes to get the same effect

@gustavo-shigueo
Copy link
Collaborator Author

The implementation of the CLI is a breaking change for anyone who uses --no-default-features to disable serde-compat as that will also disable the new export feature, preventing the test functions that export the types from being generated

@gustavo-shigueo gustavo-shigueo added CLI This issue/PR is related to or requires the implementation of the CLI tool breaking change This PR will change the public API in some way labels Apr 5, 2025
@gustavo-shigueo gustavo-shigueo requested a review from NyxCode April 5, 2025 21:58
@gustavo-shigueo
Copy link
Collaborator Author

Hey @NyxCode, I merged #334 into the CLI and added a command to generate a default config file. I also removed the --merge flag, as I believe that #316 already does that well enough, especially when combined with #399.

What do you think of the current state of the CLI? Are there other features you want to include?

@gustavo-shigueo

This comment has been minimized.

@NyxCode

This comment has been minimized.

@gustavo-shigueo

This comment has been minimized.

Comment on lines 124 to 128
no_warnings: self.no_warnings || other.no_warnings,
esm_imports: self.esm_imports || other.esm_imports,
format: self.format || other.format,
generate_index_ts: self.generate_index_ts || other.generate_index_ts,
no_capture: self.no_capture || other.no_capture,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this isn't proper behavior for merging booleans when it comes to CLI vs Config file. I think the CLI should override the config file, but if the config file has no_warnings=true and the CLI has --no-warnings=false the config file would win due to the OR operator. Maybe the flags should be Option<bool> so the merging would look like self.no_warnings.or(other.no_warnings), then, instead of if args.no_warnings { /*...*/ }, we'd have if args.no_warnings == Some(true) { /*...*/ } (or is_some_and(|x| x) or unwrap_or(false), etc)

@CriusNyx
Copy link

Is there some work that I could contribute to this to help this PR get merged? I'm needing a way to generate barrel files (those index.ts files that reexport everything).

PS: NyxCode. Nice name. :3

@gustavo-shigueo
Copy link
Collaborator Author

gustavo-shigueo commented Jun 22, 2025

Hello @CriusNyx , I'm not quite sure if/when this might be merged, as there are a few possible concerns about it:

All that being said, you can install it with the following command:
cargo install --git https://github.com/Aleph-Alpha/ts-rs --branch feat/cli ts-rs-cli and then use a ts-rs export --index to achieve the behavior you need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This PR will change the public API in some way CLI This issue/PR is related to or requires the implementation of the CLI tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add index.ts with export for all bindings. How to handle naming conflicts Feature request: export all types from a single entry point

3 participants