-
Notifications
You must be signed in to change notification settings - Fork 99
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
cli/src/main.rs
Outdated
struct Cleanup<'a>(&'a Config); | ||
impl<'a> Drop for Cleanup<'a> { | ||
fn drop(&mut self) { | ||
_ = fs::remove_file(self.0.output_directory.join(FILE_NAME)); | ||
} | ||
} | ||
|
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.
Is there a specific reason for Cleanup
to be its own struct rather than having impl Drop for Config
as it was with Args
?
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 was, though I can't completely recall.
Maybe I moved it from Args
into Cleanup
to be able to destructure Args
, though we may be able to move that back into Config
if you prefer that.
Definetely like the idea of using a Drop
impl like that, nice idea!
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 was, though I can't completely recall.
Just found it, turns out that ´Deserialize´ moves data out of Config
which isn't allowed if Config
implements Drop
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 figured out a way past it, I changed the code to go back to using Args
and changed Config
so that it'll only be used to read the config file
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.
On a completely unrelated note, I never realized just how slow my home computer is until I ran cargo test
and the recursion_limit
tests took over 3 minutes to run xD
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 |
This PR implements a POC of how we could implement type overrides using the CLI.