Skip to content

feat: say why a zodResolver call was left as written, and a scan command - #16

Closed
mertcanaltin wants to merge 2 commits into
feat/zod-resolver-morefrom
feat/zod-report
Closed

mertcanaltin wants to merge 2 commits into
feat/zod-resolver-morefrom
feat/zod-report

Conversation

@mertcanaltin

Copy link
Copy Markdown
Member

Stacked on #15; the diff here is the one commit on top of it.

When the build leaves a zodResolver call as written it said nothing, so a developer who added the plugin and saw no change had no way to learn why, or what to move. Two things:

Every call left as written has a reason, in the build's report beside the validators kept on the runtime. A reason names the schema, the field and the cause, in words about the developer's code:

[unplugin-ata] zodResolver: 2 of 6 calls compiled at build time, 4 left as written with zod
[unplugin-ata] left as written: app/signup/Form.tsx:10 zodResolver(schema): `schema` is not a constant written at the top of the file (a schema made inside a component is built on every render and cannot be read)
[unplugin-ata] left as written: app/profile/Form.tsx:9 zodResolver(tags): tags: an array is not carried yet

planZod now names the field of a refusal, schemaSource says what it could not read (a function, a name from outside, TypeScript syntax, an exported constant), and the import path says which module it could not read and why. The count of compiled validators no longer includes zodResolver calls.

npx @ata-project/unplugin scan [directory] [--json] prints that report for a project without building it and without the plugin in its config: it runs the plugin's own transform over the source files and throws the output away (src/scan.js, also exported as @ata-project/unplugin/scan). Nothing is written; a test compares the directory before and after. It is the way to see what the plugin would do before deciding to install it.

Tests: test/scan.test.js (3): a project of seven calls where one compiles and six do not, each with the reason expected for it (a schema inside a function, a refine, an array under a nested object named by its path, url(), a call with options, and an imported schema kept because another call uses it as a value); that nothing is written; the command with --json and --help. npm test: 262 tests, 260 pass, 2 skipped.

Not covered: the scan gives no sizes, since it does not build. It reads files under the directory with the same skip list as the build's own scan (no node_modules, no dot directories). The reasons are English only.

…rt, and a scan command prints the report without a build
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.

1 participant