-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proof-of-concept of type overrides using the CLI #334
base: cli
Are you sure you want to change the base?
Conversation
[overrides] | ||
u64 = "number" | ||
i64 = "number" | ||
u128 = "number" | ||
i128 = "number" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- A user creates a
ts-rs.toml
config file in their project
for (rust, ts) in &cfg.overrides { | ||
let env = format!("TS_RS_INTERNAL_OVERRIDE_{rust}"); | ||
cargo_invocation.env(env, ts); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The CLI reads the config file, and sets an environment variable for each override
fn name() -> String { | ||
$crate::get_override(stringify!($ty)) | ||
.unwrap_or($l) | ||
.to_owned() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- In
ts-rs
, we read the environment variable (cached!), and use it instead
I am in no way sure that this is the right way to implement this. Besides the implementation (are environment variables really the right choice here?), these overrides would apply to the whole dependency chain. That might be the right behavior, but I'm not sure. |
cli/src/config.rs
Outdated
} | ||
|
||
fn load_from_file() -> Result<Self> { | ||
// TODO: from where do we actually load the config? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a CLI flag like --config <PATH>
and ./ts-rs.toml
or maybe ./ts-rs/config.toml
should be a default location if the flag isn't provided
I like this implementation, and I'm not sure there even is another option to get
I think this is the right behavior. If, for example, the user wants |
Hey @NyxCode! Is there anything else you'd like to do before merging this into the cli branch? |
This PR implements a POC of how we could implement type overrides using the CLI.