-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: compilers factory (transient ajv dependency) #2862
Conversation
Just an update:
Feedback is appreciated 👍 EDIT 2:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
test/schema-special-usage.test.js
Outdated
|
||
const buildValidatorAJV7 = require('@fastify/ajv-compiler-7') | ||
|
||
test('Ajv 7 usage instead of the bundle one', t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that probably would be great to have a more descriptive changelog for this change. What do you think?
Any updates on this PR? |
I must write docs per Moreover, I have some trouble with ci - that is working on my laptop 😕 |
It fails on node 16!.. checking |
The error:
|
"@fastify/proxy-addr": "^3.0.0", | ||
"abstract-logging": "^2.0.0", | ||
"ajv": "^6.12.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still needed for the compiled options runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the build/build-validation.js
script?
Is not it created with dev dependencies on a local env?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result still depends on ajv at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm missing something here:
the configValidator.js
script is built from the build-validation.js
to avoid the ajv loading when the user creates a new fastify instance.
The build-validation.js
script is executed offline and without any automation and it is not executed when the user install the fastify
module.
For these reasons I thought that move ajv
to the devDependency was fine
Where am I wrong on this workflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated script has a runtime dependency on some utilities within Ajv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to bother you but I can't find any ajv
reference excepts in /test
and build-validation.js
I have run rm -rf node_modules/ && npm install --production
and run a server with input parameters and it works
const fastify = require('./')({ keepAliveTimeout: 'not integer' })
fastify.listen(8080)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok. However we had fastify/light-my-request#115 (comment) in the past. Can you check if it'd also be the same for Ajv@8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, i have checked: the output of the 4.4.0
that has the issue produce the validate.js
that contains this line:
...
const func0 = require("ajv/dist/compile/equal").
...
While the output of the build-validation.js
has not this statement
Tests are green, cc @fastify/typescript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work. Thank you for taking this on and sticking with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Anybody object on this landing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Unfortunately this broke typescript support on pnpm and yarn. |
For For |
Fix ref #3084 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR is the follow up of #2755
and closes #2742
and include a new fastify repo: fastify/ajv-compiler#1
Introducing the
ajv-compilers
dependency and documenting thecompilersFactory
option let the user change theajv@x
version that fastify will use.By default, it will be
ajv@6
to avoid breaking changes infastify@3
and we can dispose of anajv-compilers
version that includesajv@7
to be ready for any issue.TODO:
compilersFactory.buildValidator
(factory function that returns a factory) andcompilersFactory.buildSerializer
(factory function):fastify/lib/schema-controller.js
Lines 19 to 25 in 95bb213
ajv@7
as well - so the user will be able to set this option infastify@3
:compilersFactory
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
cc @inigo-garcia I more than happy if you could help me to push this PR