fix(spec): pre-compile JSON schema validators at build time#5039
Merged
mergify[bot] merged 1 commit intomainfrom Feb 12, 2026
Merged
fix(spec): pre-compile JSON schema validators at build time#5039mergify[bot] merged 1 commit intomainfrom
mergify[bot] merged 1 commit intomainfrom
Conversation
rix0rrr
approved these changes
Feb 12, 2026
Move ajv from runtime to dev dependency by generating standalone validation code during the build process. This eliminates the need to compile schemas at runtime, improving startup performance. Also removes fs-extra dependency in favor of Node.js built-in fs module.
274f1f1 to
3bcdd82
Compare
Contributor
|
Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it! |
Contributor
|
Merging (with squash)... |
Contributor
Merge Queue StatusRule:
This pull request spent 7 seconds in the queue, with no time running CI. Required conditions to merge
|
mergify bot
pushed a commit
that referenced
this pull request
Feb 16, 2026
In #5039 we implemented Ajv Standalone validators and moved `ajv` from a runtime dependency to a dev dependency in `@jsii/spec`. However, the generated validators [still require ajv runtime utilities](https://ajv.js.org/standalone.html#requirement-at-runtime), causing the package to fail when used. This change fixes the issue by using esbuild to bundle the generated validator code at build time, inlining all ajv runtime dependencies directly into `lib/validators.js`. The result is a fully self-contained validators file that works without ajv installed at runtime. Manually verified that the package works correctly after this change. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
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.
The
@jsii/specpackage currently compiles JSON schemas into validators at runtime usingajv. This happens every time the validators are called, which adds unnecessary overhead during jsii compilation and when loading assemblies.Every now and then we are also seeing users getting the following error. While I am not entirely clear on what is causing it (maybe some confused dependency tree?), getting rid of
ajvcompletely will solve this.This change pre-compiles the validators during the build process using Ajv's standalone code generation feature. The generated JavaScript code is a self-contained validator that doesn't require the
ajvlibrary at runtime. This approach has two benefits: it eliminates the schema compilation overhead at runtime, and it allows us to moveajvfrom a runtime dependency to a dev dependency, reducing the package's footprint.While making these changes, I also noticed that
fs-extrawas only used in tests for convenience methods likereadJsonSyncandremoveSync. Since Node.js 14+ providesfs.rmSyncwith recursive support, and JSON parsing is trivial withJSON.parse(fs.readFileSync(...)), thefs-extradependency is no longer needed and has been removed entirely.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.