Repository navigation
feat: minify a precompiled check - #235
Conversation
`schema-utils precompile --minify` and `precompile(schema, { minify: true })`
drop the error objects a check never reports, write the `equal` and
`ucs2length` helpers into the check instead of loading them from
`schema-utils`, keep the `absolutePath` regex in one constant, and minify
with terser, an optional peer dependency.
For webpack's options the check goes from 983 KB to 438 KB and loads in
13ms instead of 21ms, the same as webpack's own tooling/precompile-schemas.js
output, while still counting characters the way `validate` does.
Without --minify the output is byte-identical, so checks generated with
4.6/4.7 stay up to date.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
+ Coverage 97.17% 97.21% +0.03%
==========================================
Files 13 13
Lines 1204 1220 +16
Branches 465 472 +7
==========================================
+ Hits 1170 1186 +16
Misses 32 32
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 34 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe precompile API and CLI now support a Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ee8e9462-fa2b-4ee7-8706-ae4b63d0659e
⛔ Files ignored due to path filters: 1
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing: 8
.changeset/precompile-minify.mdREADME.mddeclarations/precompile.d.tspackage.jsonsrc/cli.jssrc/precompile.jstest/helpers/precompiled.jstest/precompile.test.js
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
The regex removing error objects also matched a schema string or pattern
that only looked like one, such as `\{instancePathx,keyword:y,`, and
changed what it matched. It now needs the assignment and the exact shape
ajv writes. webpack's minified options check is byte-identical.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
Use webpack's own JavaScript minifier (webpack 5.112.0 or later, an optional peer) instead of terser, so --minify needs nothing beyond webpack itself. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Just letting you know that the new peer dependency breaks builds that already use a webpack 5.x version older than 5.112. Strictly speaking, this is a breaking change: we should have declared 5.0.0 as a peer dependency. |
Summary
A check from
schema-utils precompileis loaded every time the tool that ships it starts. For webpack's own options it comes out at 983 KB and takes ~21 ms to load. webpack'stooling/precompile-schemas.jsproduces 423 KB that loads in ~13 ms, so webpack can't switch toschema-utils precompilewithout slowing every start.--minify(orprecompile(schema, { minify: true })) closes that gap:equalanducs2length. Both are small and self-contained, and loading them throughschema-utils/dist/runtimecosts ~1.3 ms, more than a check takes to run.uristill comes from the runtime.absolutePathregex once with ajv'sgen.scopeValue, instead of writing it out at every use (56 places for webpack) and creating a new RegExp on every call.minify, with a clear error when it's missing. ES module checks are minified as modules.Measurements
webpack's
WebpackOptions.json, median of 21 fresh Node 22 processes:precompile(current)precompile --minifyThe remaining ~15 KB is
ucs2length. webpack's check uses.lengthforminLength, which accepts a single emoji forminLength: 2wherevalidaterejects it. That's the unsafe direction for a check, so the minified check keeps counting characters the wayvalidatedoes.Compatibility
Without
--minify, the output is byte-identical to 4.7. Checks already committed, such as minimizer-webpack-plugin's, stay up to date under--check. All of the changes above apply only with--minify.Tests
requires, and the regex written once;enumobjects andabsolutePath;--minifywrites the minified check, and--checkwith--minifypasses on it, while--checkwithout--minifyreports it out of date.npm run lintand the full suite (1043 tests) pass. Coverage is 100% statements incli.jsand 99% inprecompile.js.Generated by Claude Code
Summary by CodeRabbit
--minifyoption to precompilation, also available through theprecompileAPI. It generates smaller checks that load faster while preserving validation behavior.