-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(printRoutes): ensure commonPrefix: false returns uncompressed flat routes #6275
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
base: main
Are you sure you want to change the base?
Conversation
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 the linked issue should be transferred to the find-my-way package, if relevant.
eslint.config.js
Outdated
@@ -13,7 +13,8 @@ module.exports = [ | |||
}), | |||
{ | |||
rules: { | |||
'comma-dangle': ['error', 'never'] | |||
'comma-dangle': ['error', 'never'], | |||
'max-len': ['error', { code: 100 }] |
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.
Why do you add this here?
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.
Why do you add this here?
Thanks for the question! I had originally added this change in a separate PR to address issue #6029 — but it accidentally got included here while rebasing 😅
I’ve removed it from this PR now so the scope stays focused on printRoutes. Thanks for catching it! 🙏
lib/customPrintRoutes.js
Outdated
return router.prettyPrint(opts) | ||
} | ||
|
||
// ✅ fallback to raw list of routes |
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.
Avoid emojis plz, this comment is unnecessary.
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.
Avoid emojis plz, this comment is unnecessary.
Thanks for the review!
I just wanted to clarify that the emoji in the code comment wasn’t added by me — perhaps it was already present or added by mistake during a merge.
Still, I’ll go ahead and clean it up along with the other suggestions you gave. Appreciate the feedback! 💙
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 a file you added.
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 a file you added.
You’re absolutely right — I added the file and must’ve overlooked the comment. Sorry for the confusion. I’ve now removed the emoji and cleaned it up. Thanks again for your feedback!
lib/route.js
Outdated
|
||
|
||
|
||
|
||
|
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.
lib/route.js
Outdated
|
||
|
||
|
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.
ccbb2ee
to
cde73fe
Compare
Thank you for pointing that out! 🙌 |
Can you solve the conflicts you have? |
Sure, I’ll get on it and resolve the conflicts soon. Thanks for the nudge! |
Conflicts have been resolved and the branch is now up to date with main! Let me know if there’s anything else needed 💫 |
test/printRoutes.test.js
Outdated
@@ -0,0 +1,15 @@ | |||
const Fastify = require('fastify') | |||
const t = require('tap') |
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.
Please use node:test
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.
Thanks for the catch! I’ve updated the test to use node:test instead of tap.
app.js
Outdated
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.
What is this file for?
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.
That was just for local testing. I’ve removed it now — thanks for pointing it out!
test/routes-test.js
Outdated
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 doesn't seem to test something in particular, maybe let's focus only on test/pretty-print.test.js
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.
You're right — I’ve deleted this file and moved relevant tests into pretty-print.test.js.
test/printRoutes.test.js
Outdated
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.
Let's maybe add it to https://github.com/fastify/fastify/blob/main/test/pretty-print.test.js
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.
Done! I’ve moved all the tests into pretty-print.test.js and deleted this file.
package.json
Outdated
@@ -210,6 +210,7 @@ | |||
"abstract-logging": "^2.0.1", | |||
"avvio": "^9.0.0", | |||
"fast-json-stringify": "^6.0.0", | |||
"fastify": "^5.4.0", |
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.
That addition was accidental during local testing. I’ve reverted the package.json changes now.
Hey! I’ve made all the changes: switched to node:test removed app.js and routes-test.js moved everything into pretty-print.test.js cleaned up the package.json (thanks for catching that!) Please let me know if I missed anything. I’m still learning and happy to improve this further 💫 |
lib/route.js
Outdated
function noop () { } | ||
module.exports = { buildRouting, validateBodyLimitOption } |
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 seems duplicated
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.
You're right — thanks for catching that! I've removed the duplicated code from lib/route.js in the latest commit. Let me know if there's anything else I should adjust.
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 for the ping and pong, just notice to smaller things to be fixed, after that it should be good to go
test/pretty-print.test.js
Outdated
@@ -364,3 +364,31 @@ test('pretty print - includeMeta, includeHooks', (t, done) => { | |||
done() | |||
}) | |||
}) | |||
// test/printRoutes-commonPrefix.test.js | |||
|
|||
const assert = require('node:assert') |
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.
Let's use the assert
that comes with the TestContext
(the variable passed to the test
callback.
test/pretty-print.test.js
Outdated
@@ -364,3 +364,31 @@ test('pretty print - includeMeta, includeHooks', (t, done) => { | |||
done() | |||
}) | |||
}) | |||
// test/printRoutes-commonPrefix.test.js |
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.
Feel free to remove 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.
Hi @metcoder95 ,
Thank you so much for your kindness and patience with my PRs. This is only my second PR ever, and I feel really lucky to have a mentor like you guiding me through every step.
You’re not just helping me fix code — you’re helping me grow, learn, and believe in myself a little more each day. That means more than words can say.
I’m grateful for your time, your thoughtful reviews, and your kindness. I hope to keep learning and making you proud.
With lots of respect and gratitude,
Riya 💙
Thank you for reviewing my pull request! ✨
This PR fixes the unintuitive behavior of
fastify.printRoutes({ commonPrefix: false })
, which was expected to print routes without any prefix grouping — but still compressed longer prefixes. That was confusing for users (like me 😅).So I’ve added a custom
printRoutes
logic that ensures this flag works as expected — showing all routes in a flat structure with no compression whencommonPrefix: false
.🛠️ Fixes: Issue #6009
This is my third PR to Fastify 💙 and part of my journey toward GSoC 2026. I'm learning deeply and I'm grateful for the opportunity to grow and contribute to such a wonderful project 🌱.
Checklist
npm run test
and all tests passLet me know if anything needs to be changed or improved! 💫