-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat: add validation for readOptions with zod #826
feat: add validation for readOptions with zod #826
Conversation
Codecov Report
@@ Coverage Diff @@
## main #826 +/- ##
==========================================
+ Coverage 91.61% 92.18% +0.56%
==========================================
Files 84 84
Lines 4161 4220 +59
Branches 248 261 +13
==========================================
+ Hits 3812 3890 +78
+ Misses 349 330 -19
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Looks like adding zod breaks migration script, not sure how to deal with this 😿 |
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.
Great stuff! Really excited about this - it's a nice and clean solution that removes a bunch of type assertions. 🔥
Left some comments, but I'm not super picky on any of them. What do you think?
@@ -7656,4 +7659,3 @@ packages: | |||
|
|||
/[email protected]: | |||
resolution: {integrity: sha512-wvWkphh5WQsJbVk1tbx1l1Ly4yg+XecD+Mq280uBGt9wa5BKSWf4Mhp6GmrkPixhMxmabYY7RbzlwVP32pbGCg==} | |||
dev: true |
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.
[Comment] Haha, nice to see zod already included!
src/bin/index.ts
Outdated
@@ -50,7 +51,9 @@ export async function bin(args: string[]) { | |||
return 1; | |||
} | |||
|
|||
const { code, options } = await { create, initialize, migrate }[mode](args); | |||
const { code, options, zodError } = await { create, initialize, migrate }[ |
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.
[Style] As a total non-blocking aside, I went back and forth between making an object like const runners = { create, ... }
in the root of the file or in the function. It might look cleaner here? Not a blocker whichever way you prefer 😄 just raising that I'm not picky.
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 making a separate variable might make it a little bit more readable.
}, | ||
}); | ||
}); | ||
}); |
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.
[Praise] 💯 love it! No notes!
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.
Looking great! I think the only blocking request on my end is on the prompts.outro
. Otherwise everything is either praise or a nitpick. Nice! 🔥
src/bin/index.test.ts
Outdated
mockInitialize.mockResolvedValue({ | ||
code: 2, | ||
options: {}, | ||
zodError: !validationResult.success ? validationResult.error : null, |
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.
[Cleanup] Nitpicking: no need for a runtime check, we can use a type assertion:
zodError: !validationResult.success ? validationResult.error : null, | |
zodError: (validationResult as z.SafeParseError<{ email: string }>).error, |
A little more code, but IMO more true to what the code is trying to do.
src/bin/index.ts
Outdated
|
||
if (zodError) { | ||
const validationError = fromZodError(zodError); | ||
prompts.outro(chalk.red(validationError)); |
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.
prompts.outro
[Bug] The terminal output looks a little buggy with two outros:
┌ Welcome to create-typescript-app ! 🎉
│
│ ⚠️ This template is early stage, opinionated, and not endorsed by the TypeScript team. ⚠️
│ ⚠️ If any tooling it sets displeases you, you can always remove that portion manually. ⚠️
│
● Tip: to run again with the same input values, use: npx create-typescript-app --mode create --base everything --email wat
│
│
└ Validation error: Invalid email at "email"
└ Operation cancelled. Exiting - maybe another time? 👋
How about switching to a logLine
? I think the ideal would be a blank line around the validatione rror:
┌ Welcome to create-typescript-app ! 🎉
│
│ ⚠️ This template is early stage, opinionated, and not endorsed by the TypeScript team. ⚠️
│ ⚠️ If any tooling it sets displeases you, you can always remove that portion manually. ⚠️
│
● Tip: to run again with the same input values, use: npx create-typescript-app --mode create --base everything --email wat
│
│ Validation error: Invalid email at "email"
│
└ Operation cancelled. Exiting - maybe another time? 👋
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.
Super! This is great - really happy about the reduction of assertions in the codebase. Thanks! ✨
🎉 This is included in version v1.29.40 🎉 The release is available on: Cheers! 📦🚀 |
PR Checklist
status: accepting prs
Overview
Removed type assertions and replaced them with zod validation.