-
Notifications
You must be signed in to change notification settings - Fork 2
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
Cleanup of the Netlify CLI #156
Comments
Another suggestion: Some dev dependencies could be dropped too:
|
good issue 🙌 cc @sarahetter another interesting one to look at, but much bigger job, would be moving from express to something like polka (or another fast/light alternative) there's a few modern, lightweight node web servers floating around these days. using one could improve the dev server performance and overall CLI size i imagine |
shameless plug of tinyhttp, in case you need a smoother transition from express, rather than going hardcore with polka |
Seems like this PR is also related, it bumps a lot of deps and shrinks the lockfile heavily |
Moving to polka is quite easy. It's API compatible with express. You just have to be sure to use the version tagged with |
Also wanted to mention since this issue doesn't yet that the package we're talking about here is I wonder if it's necessary for it to depend on both fastify and express? |
depends on how they use it. If they use a lot of different request / response extensions, it's not that easy. If it's just res.send and res.json, then yes I agree it's better to move to Polka |
Hey all! Thanks for all your investigation here. I'm excited about the potential work & cleanup! ✨ For the immediate future hold off on submitting PRs as we're actively scoping out a larger project in the netlify-cli and don't want to have any throw-away work. I'll keep this issue updated when we have more information. |
👋🏼 Thanks so much for looking into this, folks! I've been working on the Netlify CLI lately and this has been helpful. Let me provide a quick update (and get this collated for my own sake):
The ones with no comments I'll be knocking out soon I think. But if anyone here feels like grabbing any of them, by all means please go ahead and just give me a heads up! 🙌🏼 btw if you happen to have any tips about any of these (they're untyped, so we'd love to get rid of them anyway) please let me know 😄:
|
I don't think it's worth moving from express to fastify tbh, it's a standalone framework and isn't meant to be consumed by libraries/tools directly. I'd use either polka or tinyhttp. I could send a PR with migrating to tinyhttp if you'd like |
If you need glob support for chokidar, I can release my chokidar-glob package. You would be the first consumer tho. But all tests pass |
thanks a lot for getting the list together @serhalp 🙏 there's a lot of low hanging fruit on there, easy wins. we should churn those out first and can figure out the larger stuff like express later (though i think you'll have got through most yourself soon) depending on the usage of express inside the CLI, i would agree polka or tinyhttp will probably do nicely
i think we should hold off on this until it has been proven out elsewhere. but you raise a point, we should be doing that very soon as we need to unblock the various projects in need of it |
I noticed a couple of dependencies that could be upgraded to cleanup the graph a bit. E.g. upgrading You can see a list of everything outdated here: https://npmgraph.js.org/?q=netlify-cli#color=outdated |
@talentlessguy Sounds great, I won't decline that offer! 😄 Even better if it happens to remove the untyped |
what logger would be preferred? |
@talentlessguy no opinion! It doesn't need to be backwards compatible... It's just for local convenient pretty request logging. I think we can just pass a 1-2 line middleware instead of using a third-party dep here...? I guess we'll need something like https://www.npmjs.com/package/on-headers. Is that still the way to go these days? |
there's no need for on-headers, it's basically the same to what res.header and req.header do |
can you explain that a bit more?
are you saying instead you'd just have regular middleware and set the headers there? so later middleware could overwrite/remove them is the only difference |
@43081j I think it just calls res.writeHead with headers. Could be replaced with res.writeHead directly as well. i might be wrong because last time I looked at on-headers source was 4-5 years ago |
It seems to override writeHead such that it calls your callback whenever a request calls writeHead. So you could possibly achieve similar with middleware It isn't a wrapper around calling writeHead though. It is a wrapper so when it is called, it calls your logic. Worth having another read of the source to be sure though |
I might be a few years behind in Express patterns, but how else would you log something whenever a request completes? |
@benmccann 😞 Unfortunately most of these (including |
if a request is considered "complete" when the response's head has been written, this pattern is probably still of some use unless you can do it through middleware 👍 @talentlessguy maybe you could take a look at the on-headers source and have a think of how you could achieve the same with polka/tinyhttp. its basically a way to run middleware just before the response is written (like a middleware you force to the end of the stack i suppose, but i could be wrong there) to avoid derailing this thread, let's pick up on discord until we know the answer for sure |
by listening to a request's "finish" event. See tinyhttp's logger as an example: https://github.com/tinyhttp/logger/blob/bdff8eb1522f1efb4e5faa5022eda9eb012754c1/src/index.ts#L71 |
Currently it has 107 direct dependencies, and many more non-direct. It's worth cleaning them up.
Modules that can be replaced with other modules:
chalk
->picocolors
(mainly a size win)find-up
-> empathic, -7 depsdot-prop
-> dlv + dset, might be that only one is neededexeca
-> tinyexecModules that can be removed in favor of 1-3 lines of code:
is-stream
p-filter
:p-map
, probably could be replaced withPromise.all
p-wait-for
:through2-filter
:from2-array
:tempy
->os.tmpdir()
+fs.createFile
/fs.mkdir
hasha
->crypto.createHash('sha512').digest()
PRs:
hasha
: chore(deps): remove hasha netlify/cli#7017The text was updated successfully, but these errors were encountered: