Repository navigation
feat: zodResolver reads a schema imported from another module - #13
Closed
mertcanaltin wants to merge 2 commits into
Closed
mertcanaltin wants to merge 2 commits into
mertcanaltin wants to merge 2 commits into
Conversation
This was referenced Nov 14, 2026
# Conflicts: # src/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #12; the diff here is the one commit on top of it.
#12 reads a schema declared in the file of the
zodResolvercall. In a corpus of 150 public files that is 80 of 156 calls; 64 import the schema by name from another module (import { loginSchema } from '@/lib/validations/auth'). This reads those.The module is read as text and never run, so the build takes no side effect from it: it is resolved with the build's own resolver over the scanned sources (relative paths, tsconfig and jsconfig
paths, the usual@/and~/), parsed, and the exported constant is cut out with the constants it is made of, under the same rule as in #12: zod under one name, nothing but zod and constants of that module, no function. The plan, the check against zod and the replaced call are #12's. In the file of the call the schema's name leaves the import; where the file still infers a type from it, it stays as a type, and a statement left with only types becomesimport type, so the module is not loaded for them.Kept as written: a schema module that takes parts from another module, builds the schema with a function, or is not a file of the project; and an imported schema the file also uses as a value.
Measured, Next.js 16.4.6, the five-field form of #12 with its schema in
lib/schema.jsimported through@/lib/schema, scripts beyond the home page, gzip 9: 43,450 to 15,039 B under Turbopack. Under webpack it needs #9 (the source scan has to finish before the first file is rewritten): with #9 merged in, 37,288 to 15,562 B; without it the call stays and the page is 37,288 B.Tests: three more cases in
test/zod-resolver.test.js(11 in all): an imported schema with a type import beside it; two calls on two exports, one written asexport { a as b }, with an inferred type kept; three shapes that must keep the call.npm test: 258 tests, 256 pass, 2 skipped.Not covered: a schema re-exported through an index file, a default export, and a module that splits a schema over several files.