Skip to content

fix: resolve alias-imported and computed constants in Zod check arguments - #183

Merged
tazo90 merged 2 commits into
tazo90:mainfrom
thelgason:fix/resolve-imported-zod-constants
Sep 16, 2026
Merged

tazo90 merged 2 commits into
tazo90:mainfrom
thelgason:fix/resolve-imported-zod-constants

Conversation

@thelgason

@thelgason thelgason commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

Zod check arguments that are not plain literals were silently dropped from the output. The Zod symbol resolver only followed relative imports, so any @/*-aliased constant stopped at the import boundary; constants with computed initializers (1024 * 1024 * 2, template literals) were never indexed; and min/max/describe/… discarded an unresolved argument without a diagnostic, unlike z.enum.

This routes non-relative imports through the existing resolveTypeScriptModule (so paths aliases follow the project's own tsconfig), indexes computed const initializers, adds a small static evaluator (literals, + - * /, template literals, as const, identifiers chased through imports and re-exports, depth- and cycle-guarded), and emits a new unresolved-zod-argument warning wherever an argument still cannot be reduced. Output for literal arguments is unchanged; all sample-app specs are identical to main.

Two side effects worth knowing: resolutions landing in node_modules are discarded, so a package entry point is never parsed as a schema source; and relative resolution now prefers foo.ts over a sibling foo/ directory (the old existsSync(base) check matched the directory first). The new diagnostic is a warning, like unresolved-zod-enum, so projects running --fail-on warning with genuinely dynamic check arguments will start failing there.

Type of Change

  • feat: New feature
  • 🐛 fix: Bug fix
  • 📝 docs: Documentation update
  • ♻️ refactor: Code refactoring
  • perf: Performance improvement
  • 💥 Breaking change (add ! after type, e.g., feat!:)

Checklist

  • pnpm check passes
  • Tested locally (pnpm test and pnpm build when relevant)
  • Documentation updated (if needed)

@thelgason
thelgason marked this pull request as draft September 14, 2026 13:29
@thelgason
thelgason force-pushed the fix/resolve-imported-zod-constants branch from 9a36147 to 055ca53 Compare September 14, 2026 13:46
…l resolver

Only relative imports were followed, so a constant imported as `@/constants/limits`
was unreachable and every check built from it silently lost its value. Non-relative
imports now go through TypeScript module resolution, the same path the schema and
drizzle processors already use, so `paths` aliases follow the project's own config;
anything landing in node_modules stays unresolved.

`const` initializers that are arithmetic, template literals, or aliases of another
constant are evaluated as well. The path guard now covers a single resolution path
rather than a whole file, so sibling expressions naming the same constant both
resolve.
… stay unknown

`.max(IMPORTED_LIMIT)`, `.min()`, `.length()` and friends only understood numeric
literals and same-file constants, and `.describe()` only understood a plain string,
so an imported limit or a template-literal description vanished from the emitted
schema without a word.

Every check argument now goes through the shared static evaluator, and anything
that cannot be reduced to a value reports `unresolved-zod-argument` with the
method, the symbol it names, and the line.
@thelgason
thelgason force-pushed the fix/resolve-imported-zod-constants branch from 055ca53 to d47091d Compare September 14, 2026 13:55
@thelgason
thelgason marked this pull request as ready for review September 14, 2026 14:05

@tazo90 tazo90 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix @thelgason, LGTM 👍

@tazo90
tazo90 merged commit 6090418 into tazo90:main Sep 16, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants