Skip to content
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: add nodenext compatiblity #196

Merged
merged 2 commits into from
Feb 15, 2023
Merged

feat: add nodenext compatiblity #196

merged 2 commits into from
Feb 15, 2023

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Feb 15, 2023

The nodenext compatibilty is actually based on
fastify/fastify#4349

@@ -5,8 +5,8 @@ const fp = require("fastify-plugin");
* by setting the relevant response headers.
* @param {object} server - Fastify instance.
*/
async function plugin(server) {
server.addHook("onRequest", async (req, res) => {
async function fastifyDisablecache(server) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed the function to reflect how fastifyPlugin would name it.
See:
https://github.com/fastify/fastify-plugin/blob/master/lib/toCamelCase.js

async function plugin(server) {
server.addHook("onRequest", async (req, res) => {
async function fastifyDisablecache(server) {
server.addHook("onRequest", async (_req, res) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non necessary change, basically _ indicates parameters not used. But not relevant to this PR.

name: "fastify-disablecache"
}
);
module.exports.default = fastifyDisablecache;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastifyPlugin is mutating the function itself. so you can just reassign after called fastifyPlugin once.

I usually tried to keep the order of module.exports, then module.exports.default and last module.exports.fastifyPluginName

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 15, 2023

We could have added unit tests to ensure that the exports are set correctly and typings tests.

@Uzlopak Uzlopak mentioned this pull request Feb 15, 2023
3 tasks
@Fdawgs Fdawgs changed the title add nodenext compatiblity feat: add nodenext compatiblity Feb 15, 2023
@Fdawgs
Copy link
Owner

Fdawgs commented Feb 15, 2023

Thank you so much for this @Uzlopak! Didn't expect you to make a PR, but definitely makes it much easier for me to understand!

@Fdawgs Fdawgs linked an issue Feb 15, 2023 that may be closed by this pull request
3 tasks
@Fdawgs Fdawgs merged commit 5be072f into Fdawgs:main Feb 15, 2023
@Uzlopak Uzlopak deleted the nodenext branch February 15, 2023 11:33
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.

Add TypeScript support
2 participants