You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(spec): pre-compile JSON schema validators at build time (#5039)
The `@jsii/spec` package currently compiles JSON schemas into validators at runtime using `ajv`. 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 `ajv` completely will solve this.
```
TypeError: ajv_1.default is not a constructor
at loadAssemblyFromFile (node_modules\@jsii\spec\lib\assembly-utils.js:139:15)
```
This change pre-compiles the validators during the build process using [Ajv's standalone code generation feature](https://ajv.js.org/standalone.html). The generated JavaScript code is a self-contained validator that doesn't require the `ajv` library at runtime. This approach has two benefits: it eliminates the schema compilation overhead at runtime, and it allows us to move `ajv` from a runtime dependency to a dev dependency, reducing the package's footprint.
While making these changes, I also noticed that `fs-extra` was only used in tests for convenience methods like `readJsonSync` and `removeSync`. Since Node.js 14+ provides `fs.rmSync` with recursive support, and JSON parsing is trivial with `JSON.parse(fs.readFileSync(...))`, the `fs-extra` dependency 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].
[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
0 commit comments