-
Notifications
You must be signed in to change notification settings - Fork 35
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(core): add configuration validation using typia #730
Conversation
✅ Deploy Preview for rslib ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -56,7 +56,9 @@ | |||
"rslib": "npm:@rslib/core@0.4.0", | |||
"rslog": "^1.2.3", | |||
"tsconfck": "3.1.4", | |||
"typescript": "^5.7.3" | |||
"typescript": "^5.7.3", | |||
"typia": "^7.6.2", |
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.
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.
It indeed has too many dependencies, but it is tree-shakable and we are using it as devDependencies
.
The bundle size of Rslib is increased from 106.8 kB to 2484.4 kB. But the size change mainly produced by the validation functions generated by typia
:
![image](https://private-user-images.githubusercontent.com/40660121/409809212-3d4d41cc-8c3c-4aa3-8c31-a9f9b1de7c78.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMTgyMzcsIm5iZiI6MTczOTIxNzkzNywicGF0aCI6Ii80MDY2MDEyMS80MDk4MDkyMTItM2Q0ZDQxY2MtOGMzYy00YWEzLThjMzEtYTlmOWIxZGU3Yzc4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDIwMDUzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThhNTc4YzEwZjQ5NGRmZGYyOWNlZjg5NTVmYTg3OTIwM2RiMDE0YjYzMTc2YTE5ZmZmNTg3MGQwYzlkZmQ3NjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.h_4D_wPIYBBKZ1G3HeICMsmC-RrtHX3u1bk1woIPO1s)
As you can see, the src/validate.ts
has 2.33 MB in stats. And we can make validation opt-in and lazy loaded.
For end users, no additional dependencies need to be installed, and the bundle size of @rslib/core
increases by only approximately 2.5 MB.
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.
If we make the validation opt-in, how can users enable the validation?
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.
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.
If we make the validation opt-in, how can users enable the validation?
Maybe through a environment variable?
// rslib.config.js
process.env['RSLIB_CONFIG_VALIDATION'] = true
export default {}
Or maybe a strictDefineConfig
API?
import {strictDefineConfig} from '@rslib/core'
export default strictDefineConfig({})
But I would prefer enabling by default. And opt-out using environment variables.
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.
If it's opt-in, I don't think most users will actively enable it...
If it's opt-out, the performance overhead doesn't seem worth it, we can write code to do some validation manually.
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.
Sure, I'm closing this PR. Thank you for your review
Important
Note that this is currently just a POC implementation.
Summary
Add a validation to
loadConfig
to make sure that the configuration is correct when loaded.I'm using
typia
andtypia-rspack-plugin
to make validation.Related Links
Checklist