-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[chore] use superstruct for config validation #2366
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
Conversation
🦋 Changeset detectedLatest commit: ea21d16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
nice! I like that a couple hundred lines of code have been removed. this looks good to me
a changeset wouldn't be bad since this is a sizable change eventhough it should be transparent to users. sometimes it's helpful to have big changes in the changelog just in case there's a regression so users can find relevant changes more easily
Removed the blank lines and added a changeset. Hopefully the config validation is still readable though, I saw astrojs using zod for theirs but the bundle size is a tad larger and non-treeshake-able. |
Thank you, but I'd prefer that we not add new dependencies, honestly — looking at https://unpkg.com/[email protected]/lib/index.es.js, it really seems like overkill for what we need. And the error messages are less friendly (wtf is a We can DRY the existing code out if it's too verbose — working on a PR. |
Sure, I don't mind if you prefer to improve the existing code instead. Feel free to close this if you believe #2373 is the path forward, no hard feelings :) Though to add to this PR's motivation, I was hoping to use an established library to prevent creating and testing our own mini-library. I don't think superstruct vs our custom config validation gives a big bundle size margin either since we bundle superstruct and it's treeshaken. Re errors, yeah maybe it is a bit cryptic for some, that would be a caveat though we could probably re-write the errors. I'll take a look at #2373 in the meantime and review it. |
It's not just the extra bytes, though they add up quicker than you'd think — It's that every dependency is an additional possible point of failure, and something that we have to keep updated (but which might introduce new problems with those updates), and something that increases the learning curve for anyone working on the codebase (now they have to go away and learn the API for a new library instead of reading the ~100 LOC that define our version of the same functionality) while reducing flexibility (if we need to change something, we have to hope that it's supported by the library, work around it somehow, or do without). Robust projects have as few dependencies as possible! |
Thanks for the clarification. The numbers certainly don't lie, perhaps the library's treeshake-able code wasn't as effective as I thought it was. I don't entirely agree with point of failure and learning curve points though since the library is quite well-built and our own implementation has the same learning curve too. But nonetheless I don't want to force this in if it's undesirable, we could circle back to this if we ever need to, so I'll be closing this. |
Addresses #2267 (comment). Better late than never :)
Use superstruct for config validation. Removes old implementation.
Notes
Do we want a changeset?packages/kit/src/core/config/index.spec.js
topackages/kit/src/core/config/test/index.js
to use the fixtures. I've also removed the hard-coded error message assertions since they're too coupled to the implementation, but lmk if we do want it.packages/kit/src/core/config/options.js
is now the single source of truth, even for the types.Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0